You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by fi...@apache.org on 2012/06/01 13:13:43 UTC
svn commit: r1345054 - in /incubator/etch/trunk/binding-cpp/runtime:
include/common/ include/serialization/ src/main/ src/main/serialization/
src/test/ src/test/serialization/
Author: fitzner
Date: Fri Jun 1 11:13:42 2012
New Revision: 1345054
URL: http://svn.apache.org/viewvc?rev=1345054&view=rev
Log:
ETCH-185 Implementation Validators
Byte Validator has been implemented
Change-Id: Ieb93770892b1217945af10906dbf20e05b45b3ef
Added:
incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorByte.h
incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorByte.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorByteTest.cpp
Modified:
incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h
incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt
Modified: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h?rev=1345054&r1=1345053&r2=1345054&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h Fri Jun 1 11:13:42 2012
@@ -40,6 +40,7 @@ enum EtchObjectTypeIds {
EOTID_SOCKET,
EOTID_SERVER_SOCKET,
EOTID_VALIDATOR_BOOLEAN,
+ EOTID_VALIDATOR_BYTE,
EOTID_NATIVE_INT8,
EOTID_NATIVE_INT16,
Added: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorByte.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorByte.h?rev=1345054&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorByte.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorByte.h Fri Jun 1 11:13:42 2012
@@ -0,0 +1,66 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ETCHVALIDATORBYTE_H__
+#define __ETCHVALIDATORBYTE_H__
+#include "serialization/EtchTypeValidator.h"
+#include "common/EtchByte.h"
+#include "common/EtchShort.h"
+#include "common/EtchInt32.h"
+#include "common/EtchLong.h"
+#include "serialization/EtchTypeCodes.h"
+#include "common/EtchNativeArray.h"
+#include "capu/os/NumericLimits.h"
+
+class EtchValidatorByte : public EtchTypeValidator {
+public:
+
+ virtual ~EtchValidatorByte();
+
+ /**
+ * @see EtchValidator
+ */
+ virtual status_t getElementValidator(capu::SmartPointer<EtchValidator> &val);
+
+ /**
+ * @see EtchValidator
+ */
+ virtual capu::bool_t validate(EtchObject* value);
+
+ /**
+ * @see EtchValidator
+ */
+ virtual status_t validateValue(EtchObject* value, EtchObject*& result);
+
+ /**
+ * @see EtchValidator
+ */
+ static status_t Get(capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val);
+
+ static const EtchObjectType TYPE;
+
+protected:
+ EtchValidatorByte(capu::uint32_t ndim);
+
+private:
+ static capu::SmartPointer<EtchValidator> mValidator[MAX_CACHED];
+
+};
+
+#endif /* ETCHVALIDATORBYTE_H */
+
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt?rev=1345054&r1=1345053&r2=1345054&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt Fri Jun 1 11:13:42 2012
@@ -65,6 +65,7 @@ SET(MAIN_INCLUDES
${PROJECT_SOURCE_DIR}/include/serialization/EtchTypeValidator.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchTypeCodes.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorBoolean.h
+ ${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorByte.h
${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
)
@@ -92,6 +93,7 @@ SET(MAIN_SOURCES
transport/EtchPacketizer.cpp
serialization/EtchTypeValidator.cpp
serialization/EtchValidatorBoolean.cpp
+ serialization/EtchValidatorByte.cpp
util/EtchUtil.cpp
)
Added: incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorByte.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorByte.cpp?rev=1345054&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorByte.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorByte.cpp Fri Jun 1 11:13:42 2012
@@ -0,0 +1,125 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "serialization/EtchValidatorByte.h"
+
+capu::SmartPointer<EtchValidator> EtchValidatorByte::mValidator[MAX_CACHED];
+const EtchObjectType EtchValidatorByte::TYPE(EOTID_VALIDATOR_BYTE, NULL);
+
+EtchValidatorByte::EtchValidatorByte(capu::uint32_t ndim)
+: EtchTypeValidator(&EtchValidatorByte::TYPE, &EtchByte::TYPE, &EtchByte::TYPE, ndim) {
+
+}
+
+EtchValidatorByte::~EtchValidatorByte() {
+
+}
+
+capu::bool_t EtchValidatorByte::validate(EtchObject* value) {
+ if (value == NULL)
+ return false;
+ if (mExpectedType == NULL)
+ return false;
+
+ if (value->getObjectType()->equals(mExpectedType))
+ return true;
+
+ if (value->getObjectType()->equals(&EtchShort::TYPE)) {
+ EtchShort *v = (EtchShort *) value;
+ return ((v->get() >= capu::NumericLimitMin<capu::int8_t> ()) && (v->get() <= capu::NumericLimitMax<capu::int8_t> ()));
+ }
+
+ if (value->getObjectType()->equals(&EtchInt32::TYPE)) {
+ EtchInt32 *v = (EtchInt32 *) value;
+ return ((v->get() >= capu::NumericLimitMin<capu::int8_t> ()) && (v->get() <= capu::NumericLimitMax<capu::int8_t> ()));
+ }
+
+ if (value->getObjectType()->equals(&EtchLong::TYPE)) {
+ EtchLong *v = (EtchLong *) value;
+ return ((v->get() >= capu::NumericLimitMin<capu::int8_t> ()) && (v->get() <= capu::NumericLimitMax<capu::int8_t> ()));
+ }
+ //array handling
+ if ((value->getObjectType()->isArray()) && (mExpectedType->isArray())) {
+
+ EtchNativeArray<EtchObject*> *array = (EtchNativeArray<EtchObject*> *) value;
+ const EtchObjectType* type = array->getContentType();
+ const EtchObjectType* type2 = mExpectedType->getObjectComponentType();
+ while ((type->getObjectComponentType() != NULL) && (mExpectedType->getObjectComponentType() != NULL)) {
+ type = type->getObjectComponentType();
+ type2 = type2->getObjectComponentType();
+ }
+
+ //both of them should be pointing null
+ if (type->getObjectComponentType() != type2->getObjectComponentType()) {
+ return false;
+ }
+ return type->equals(type2);
+ }
+
+
+ return false;
+}
+
+status_t EtchValidatorByte::validateValue(EtchObject* value, EtchObject*& result) {
+ if (validate(value)) {
+ if ((value->getObjectType()->equals(&EtchByte::TYPE)) || (mNDims > 0)) {
+ result = value;
+ return ETCH_OK;
+ } else {
+ if (value->getObjectType()->equals(&EtchShort::TYPE)) {
+ EtchShort *v = (EtchShort *) value;
+ result = (EtchObject*) (new EtchByte((capu::int8_t)v->get()));
+ return ETCH_OK;
+ }
+
+ if (value->getObjectType()->equals(&EtchLong::TYPE)) {
+ EtchByte *v = (EtchByte *) value;
+ result = (EtchObject*) (new EtchByte((capu::int8_t)v->get()));
+ return ETCH_OK;
+ }
+
+ if (value->getObjectType()->equals(&EtchInt32::TYPE)) {
+ EtchInt32 *v = (EtchInt32 *) value;
+ result = (EtchObject*) (new EtchByte((capu::int8_t)v->get()));
+ return ETCH_OK;
+ }
+ return ETCH_ERROR;
+ }
+ } else {
+ return ETCH_ERROR;
+ }
+}
+
+status_t EtchValidatorByte::Get(capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
+ if (ndim > MAX_NDIMS) {
+ return ETCH_EINVAL;
+ }
+ if (ndim >= MAX_CACHED) {
+ val = new EtchValidatorByte(ndim);
+ return ETCH_OK;
+ }
+ if (mValidator[ndim].get() == NULL) {
+ mValidator[ndim] = new EtchValidatorByte(ndim);
+ }
+ val = mValidator[ndim];
+ return ETCH_OK;
+}
+
+status_t EtchValidatorByte::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
+ return EtchValidatorByte::Get(mNDims - 1, val);
+}
\ No newline at end of file
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt?rev=1345054&r1=1345053&r2=1345054&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt Fri Jun 1 11:13:42 2012
@@ -49,6 +49,7 @@ add_executable (etch-cpp-test
transport/EtchTcpListenerTest.cpp
transport/EtchPacketizerTest.cpp
serialization/EtchValidatorBooleanTest.cpp
+ serialization/EtchValidatorByteTest.cpp
util/EtchUtilTest.cpp
${GTEST}/src/gtest-all.cc
${GMOCK}/src/gmock-all.cc
Added: incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorByteTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorByteTest.cpp?rev=1345054&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorByteTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorByteTest.cpp Fri Jun 1 11:13:42 2012
@@ -0,0 +1,182 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+#include "serialization/EtchValidatorByte.h"
+#include "capu/util/SmartPointer.h"
+#include "common/EtchString.h"
+
+TEST(EtchValidatorByteTest, createTest) {
+ capu::SmartPointer<EtchValidatorByte> ptr = NULL;
+
+ capu::SmartPointer<EtchValidator> val;
+ EXPECT_TRUE(EtchValidatorByte::Get(0, val) == ETCH_OK);
+ ptr = capu::smartpointer_cast<EtchValidatorByte>(val);
+ EXPECT_TRUE(ptr->getExpectedType()->equals(&EtchByte::TYPE));
+ EXPECT_TRUE(ptr->getNDims() == 0);
+
+ EtchObjectType type1(EOTID_BYTE, NULL);
+ EtchObjectType type2(EOTID_NATIVE_ARRAY, &type1);
+ EtchObjectType type3(EOTID_NATIVE_ARRAY, &type2);
+ EXPECT_TRUE(EtchValidatorByte::Get(2, val) == ETCH_OK);
+ ptr = capu::smartpointer_cast<EtchValidatorByte>(val);
+ EXPECT_TRUE(ptr->getExpectedType()->equals(&type3));
+ EXPECT_TRUE(ptr->getNDims() == 2);
+}
+
+TEST(EtchValidatorByteTest, validateTest) {
+ EtchObject* byte = NULL;
+
+ EtchObject* integer = new EtchInt32(-128);
+ EtchObject* integer2 = new EtchInt32(5);
+ EtchObject* integer3 = new EtchInt32(127);
+ //exceed limit of byte
+ EtchObject* integer4 = new EtchInt32(897);
+ EtchObject* longInteger = new EtchLong(-128);
+ EtchObject* longInteger2 = new EtchLong(5);
+ EtchObject* longInteger3 = new EtchLong(127);
+ //exceed limit of byte
+ EtchObject* longInteger4 = new EtchLong(897);
+ EtchObject* shortInteger = new EtchShort(-128);
+ EtchObject* shortInteger2 = new EtchShort(5);
+ EtchObject* shortInteger3 = new EtchShort(127);
+ //Exceed limit of byte
+ EtchObject* shortInteger4 = new EtchShort(897);
+ EtchObject* str = new EtchString();
+ EtchObject* byte2 = new EtchByte(3);
+ capu::SmartPointer<EtchValidator> ptr = NULL;
+ EXPECT_TRUE(EtchValidatorByte::Get(0, ptr) == ETCH_OK);
+ EXPECT_TRUE((capu::smartpointer_cast<EtchTypeValidator>(ptr))->getNDims() == 0);
+ EXPECT_FALSE(ptr->validate(byte));
+ EXPECT_TRUE(ptr->validate(integer));
+ EXPECT_TRUE(ptr->validate(integer2));
+ EXPECT_TRUE(ptr->validate(integer3));
+ EXPECT_TRUE(ptr->validate(longInteger));
+ EXPECT_TRUE(ptr->validate(longInteger2));
+ EXPECT_TRUE(ptr->validate(longInteger3));
+ EXPECT_TRUE(ptr->validate(shortInteger));
+ EXPECT_TRUE(ptr->validate(shortInteger2));
+ EXPECT_TRUE(ptr->validate(shortInteger3));
+ EXPECT_TRUE(ptr->validate(byte2));
+ EXPECT_FALSE(ptr->validate(integer4));
+ EXPECT_FALSE(ptr->validate(longInteger4));
+ EXPECT_FALSE(ptr->validate(shortInteger4));
+ EXPECT_FALSE(ptr->validate(str));
+
+ delete integer;
+ delete integer2;
+ delete integer3;
+ delete integer4;
+
+ delete longInteger;
+ delete longInteger2;
+ delete longInteger3;
+ delete longInteger4;
+
+ delete shortInteger;
+ delete shortInteger2;
+ delete shortInteger3;
+ delete shortInteger4;
+
+ delete str;
+ delete byte2;
+}
+
+TEST(EtchValidatorByteTest, validateValueTest) {
+ EtchObject* byte = NULL;
+ EtchObject* result;
+ EtchObject* integer = new EtchInt32(-128);
+ EtchObject* integer2 = new EtchInt32(5);
+ EtchObject* integer3 = new EtchInt32(127);
+ EtchObject* byte2 = new EtchByte(3);
+ capu::SmartPointer<EtchValidator> ptr = NULL;
+ EXPECT_TRUE(EtchValidatorByte::Get(0, ptr) == ETCH_OK);
+ EXPECT_TRUE(ptr->validateValue(byte, result) == ETCH_ERROR);
+ EXPECT_TRUE(ptr->validateValue(integer, result) == ETCH_OK);
+ EXPECT_TRUE(((EtchByte*) result)->get() == ((EtchInt32*) integer)->get());
+ delete result;
+ EXPECT_TRUE(ptr->validateValue(integer2, result) == ETCH_OK);
+ EXPECT_TRUE(((EtchByte*) result)->get() == ((EtchInt32*) integer2)->get());
+ delete result;
+ EXPECT_TRUE(ptr->validateValue(integer3, result) == ETCH_OK);
+ EXPECT_TRUE(((EtchByte*) result)->get() == ((EtchInt32*) integer3)->get());
+ delete result;
+ EXPECT_TRUE(ptr->validateValue(byte2, result) == ETCH_OK);
+ EXPECT_TRUE(((EtchByte*) result)->get() == ((EtchByte*) byte2)->get());
+ delete integer;
+ delete integer2;
+ delete integer3;
+ delete byte2;
+}
+
+TEST(EtchValidatorByteTest, elementValidatorTest) {
+ capu::SmartPointer<EtchValidator> ptr = NULL;
+ EXPECT_TRUE(EtchValidatorByte::Get(1, ptr) == ETCH_OK);
+ capu::SmartPointer<EtchValidator> elementValidator;
+ ptr->getElementValidator(elementValidator);
+
+ EtchObject* integer = new EtchInt32(-128);
+ EtchObject* integer2 = new EtchInt32(5);
+ EtchObject* integer3 = new EtchInt32(127);
+ //exceed limit of byte
+ EtchObject* integer4 = new EtchInt32(897);
+ EtchObject* longInteger = new EtchLong(-128);
+ EtchObject* longInteger2 = new EtchLong(5);
+ EtchObject* longInteger3 = new EtchLong(127);
+ //exceed limit of byte
+ EtchObject* longInteger4 = new EtchLong(897);
+ EtchObject* shortInteger = new EtchShort(-128);
+ EtchObject* shortInteger2 = new EtchShort(5);
+ EtchObject* shortInteger3 = new EtchShort(127);
+ //Exceed limit of byte
+ EtchObject* shortInteger4 = new EtchShort(897);
+ EtchObject* str = new EtchString();
+ EtchObject* byte2 = new EtchByte(3);
+
+ EXPECT_TRUE(elementValidator->validate(integer));
+ EXPECT_TRUE(elementValidator->validate(integer2));
+ EXPECT_TRUE(elementValidator->validate(integer3));
+ EXPECT_TRUE(elementValidator->validate(longInteger));
+ EXPECT_TRUE(elementValidator->validate(longInteger2));
+ EXPECT_TRUE(elementValidator->validate(longInteger3));
+ EXPECT_TRUE(elementValidator->validate(shortInteger));
+ EXPECT_TRUE(elementValidator->validate(shortInteger2));
+ EXPECT_TRUE(elementValidator->validate(shortInteger3));
+ EXPECT_TRUE(elementValidator->validate(byte2));
+ EXPECT_FALSE(elementValidator->validate(integer4));
+ EXPECT_FALSE(elementValidator->validate(longInteger4));
+ EXPECT_FALSE(elementValidator->validate(shortInteger4));
+ EXPECT_FALSE(elementValidator->validate(str));
+ delete integer;
+ delete integer2;
+ delete integer3;
+ delete integer4;
+
+ delete longInteger;
+ delete longInteger2;
+ delete longInteger3;
+ delete longInteger4;
+
+ delete shortInteger;
+ delete shortInteger2;
+ delete shortInteger3;
+ delete shortInteger4;
+
+ delete str;
+ delete byte2;
+}