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:20:48 UTC
svn commit: r1345065 - 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:20:47 2012
New Revision: 1345065
URL: http://svn.apache.org/viewvc?rev=1345065&view=rev
Log:
ETCH-185 Implementation Validators
Combo Validator has been implemented
Change-Id: Ib5a0d78eb9c88836ddaef8d75cfc46b58e12e24e
Added:
incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchComboValidator.h
incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchComboValidator.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchComboValidatorTest.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
incubator/etch/trunk/binding-cpp/runtime/src/test/main.cpp
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=1345065&r1=1345064&r2=1345065&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:20:47 2012
@@ -47,6 +47,7 @@ enum EtchObjectTypeIds {
EOTID_VALIDATOR_DOUBLE,
EOTID_VALIDATOR_LONG,
EOTID_VALIDATOR_STRING,
+ EOTID_VALIDATOR_COMBO,
EOTID_NATIVE_INT8,
EOTID_NATIVE_INT16,
Added: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchComboValidator.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchComboValidator.h?rev=1345065&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchComboValidator.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchComboValidator.h Fri Jun 1 11:20:47 2012
@@ -0,0 +1,76 @@
+/* $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 __ETCHCOMBOVALIDATOR_H__
+#define __ETCHCOMBOVALIDATOR_H__
+#include "serialization/EtchValidator.h"
+#include "common/EtchError.h"
+
+class EtchComboValidator : public EtchValidator {
+public:
+
+ /**
+ * Constructs the ComboValidator.
+ *
+ * @param a
+ * @param b
+ */
+ EtchComboValidator(capu::SmartPointer<EtchValidator> a, capu::SmartPointer<EtchValidator> b);
+
+ /**
+ * Destructor
+ */
+ virtual ~EtchComboValidator();
+
+ /**
+ * @see EtchValidator
+ */
+ capu::bool_t validate(EtchObject* value);
+
+ /**
+ * @see EtchValidator
+ */
+ status_t validateValue(EtchObject* value, EtchObject*& result);
+
+ /**
+ * @see EtchValidator
+ */
+ status_t getElementValidator(capu::SmartPointer<EtchValidator> &val);
+
+ /**
+ * return First child validator
+ * @return first child validator
+ */
+ capu::SmartPointer<EtchValidator> getFirst();
+
+ /**
+ * return Second child validator
+ * @return second child validator
+ */
+ capu::SmartPointer<EtchValidator> getSecond();
+ static const EtchObjectType TYPE;
+
+private:
+ capu::SmartPointer<EtchValidator> mFirst;
+ capu::SmartPointer<EtchValidator> mSecond;
+
+};
+
+
+#endif /* ETCHCOMBOVALIDATOR_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=1345065&r1=1345064&r2=1345065&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:20:47 2012
@@ -72,6 +72,7 @@ SET(MAIN_INCLUDES
${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorDouble.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorLong.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorString.h
+ ${PROJECT_SOURCE_DIR}/include/serialization/EtchComboValidator.h
${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
)
@@ -106,6 +107,7 @@ SET(MAIN_SOURCES
serialization/EtchValidatorDouble.cpp
serialization/EtchValidatorLong.cpp
serialization/EtchValidatorString.cpp
+ serialization/EtchComboValidator.cpp
util/EtchUtil.cpp
)
Added: incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchComboValidator.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchComboValidator.cpp?rev=1345065&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchComboValidator.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchComboValidator.cpp Fri Jun 1 11:20:47 2012
@@ -0,0 +1,74 @@
+/* $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/EtchComboValidator.h"
+
+const EtchObjectType EtchComboValidator::TYPE(EOTID_VALIDATOR_COMBO, NULL);
+
+EtchComboValidator::EtchComboValidator(capu::SmartPointer<EtchValidator> a, capu::SmartPointer<EtchValidator> b)
+: EtchValidator(&EtchComboValidator::TYPE), mFirst(a), mSecond(b) {
+
+}
+
+EtchComboValidator::~EtchComboValidator() {
+
+}
+
+capu::SmartPointer<EtchValidator> EtchComboValidator::getFirst() {
+ return mFirst;
+}
+
+capu::SmartPointer<EtchValidator> EtchComboValidator::getSecond() {
+ return mSecond;
+}
+
+capu::bool_t EtchComboValidator::validate(EtchObject* value) {
+ return mFirst->validate(value) || mSecond->validate(value);
+}
+
+status_t EtchComboValidator::validateValue(EtchObject* value, EtchObject*& result) {
+ if (mFirst->validateValue(value, result) == ETCH_OK) {
+ return ETCH_OK;
+ }
+ return mSecond->validateValue(value, result);
+}
+
+status_t EtchComboValidator::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
+ capu::SmartPointer<EtchValidator> na;
+
+ status_t a = mFirst->getElementValidator(na);
+
+ capu::SmartPointer<EtchValidator> nb;
+
+ status_t b = mSecond->getElementValidator(nb);
+
+ if ((a != ETCH_OK) && (b != ETCH_OK))
+ return ETCH_EINVAL;
+
+ if (a != ETCH_OK) {
+ val = nb;
+ return ETCH_OK;
+ }
+ if (b != ETCH_OK) {
+ val = na;
+ return ETCH_OK;
+ }
+
+ val = new EtchComboValidator(na, nb);
+ return ETCH_OK;
+}
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=1345065&r1=1345064&r2=1345065&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:20:47 2012
@@ -56,6 +56,7 @@ add_executable (etch-cpp-test
serialization/EtchValidatorDoubleTest.cpp
serialization/EtchValidatorLongTest.cpp
serialization/EtchValidatorStringTest.cpp
+ serialization/EtchComboValidatorTest.cpp
util/EtchUtilTest.cpp
${GTEST}/src/gtest-all.cc
${GMOCK}/src/gmock-all.cc
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/main.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/main.cpp?rev=1345065&r1=1345064&r2=1345065&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/main.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/main.cpp Fri Jun 1 11:20:47 2012
@@ -26,8 +26,20 @@
#include "gtest/gtest.h"
GTEST_API_ int main(int argc, char **argv) {
- std::cout << "Running etch-cpp tests\n";
-
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
+ std::cout << "Running etch-cpp tests\n";
+
+ bool insideIde = false;
+ if(argc > 1) {
+ insideIde = true;
+ }
+
+ testing::InitGoogleTest(&argc, argv);
+ int result = RUN_ALL_TESTS();
+
+ if(insideIde) {
+ printf("press <enter> to exit.\n");
+ getchar();
+ }
+
+ return result;
}
\ No newline at end of file
Added: incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchComboValidatorTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchComboValidatorTest.cpp?rev=1345065&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchComboValidatorTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchComboValidatorTest.cpp Fri Jun 1 11:20:47 2012
@@ -0,0 +1,238 @@
+/* $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/EtchComboValidator.h"
+#include "serialization/EtchValidatorString.h"
+#include "serialization/EtchValidatorInt.h"
+
+TEST(EtchComboValidatorTest, createTest) {
+ capu::SmartPointer<EtchValidator> ptr;
+ capu::SmartPointer<EtchValidator> ptr2;
+
+ EtchValidatorString::Get(0, ptr);
+ EtchValidatorInt::Get(0, ptr2);
+
+ EtchComboValidator *combo = new EtchComboValidator(ptr, ptr2);
+ EXPECT_TRUE(combo != NULL);
+ delete combo;
+}
+
+TEST(EtchComboValidatorTest, validateTest) {
+ EtchObject* byte = NULL;
+
+ EtchObject* integer = new EtchInt32(capu::NumericLimitMin<capu::int32_t>());
+ EtchObject* integer2 = new EtchInt32(0);
+ EtchObject* integer3 = new EtchInt32(capu::NumericLimitMax<capu::int32_t>());
+ EtchObject* integer4 = new EtchInt32(897);
+
+ EtchObject* longInteger = new EtchLong(capu::NumericLimitMin<capu::int32_t>());
+ EtchObject* longInteger2 = new EtchLong(0);
+ EtchObject* longInteger3 = new EtchLong(capu::NumericLimitMax<capu::int32_t>());
+ EtchObject* longInteger4 = new EtchLong(897);
+ //exceed limits of integer
+ EtchObject* longInteger5 = new EtchLong((capu::int64_t)capu::NumericLimitMax<capu::int32_t>() + (capu::int64_t)2);
+
+ EtchObject* shortInteger = new EtchShort(capu::NumericLimitMin<capu::int16_t>());
+ EtchObject* shortInteger2 = new EtchShort(0);
+ EtchObject* shortInteger3 = new EtchShort(capu::NumericLimitMax<capu::int16_t>());
+ EtchObject* shortInteger4 = new EtchShort();
+
+ //incompatible type
+ EtchObject* str = NULL;
+ EtchObject* str2 = new EtchString("hello");
+ //
+ EtchObject* byte1 = new EtchByte(capu::NumericLimitMax<capu::int8_t>());
+ EtchObject* byte2 = new EtchByte(0);
+ EtchObject* byte3 = new EtchByte(capu::NumericLimitMin<capu::int8_t>());
+ EtchObject* byte4 = new EtchByte(32);
+
+ //create combo validator
+ EtchComboValidator *ptr = NULL;
+ capu::SmartPointer<EtchValidator> ptr1;
+ capu::SmartPointer<EtchValidator> ptr2;
+ EtchValidatorInt::Get(0, ptr1);
+ EtchValidatorString::Get(0, ptr2);
+ ptr = new EtchComboValidator(ptr1, ptr2);
+
+ EXPECT_FALSE(ptr->validate(byte));
+ EXPECT_FALSE(ptr->validate(longInteger5));
+ EXPECT_FALSE(ptr->validate(str)); //STRING VALIDATE
+ EXPECT_TRUE(ptr->validate(str2));
+ EXPECT_TRUE(ptr->validate(integer)); //INT VALIDATE
+ 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(byte1));
+ EXPECT_TRUE(ptr->validate(byte2));
+ EXPECT_TRUE(ptr->validate(byte3));
+ EXPECT_TRUE(ptr->validate(byte4));
+ EXPECT_TRUE(ptr->validate(integer4));
+ EXPECT_TRUE(ptr->validate(longInteger4));
+ EXPECT_TRUE(ptr->validate(shortInteger4));
+ delete ptr;
+
+ delete integer;
+ delete integer2;
+ delete integer3;
+ delete integer4;
+
+ delete longInteger;
+ delete longInteger2;
+ delete longInteger3;
+ delete longInteger4;
+ delete longInteger5;
+
+ delete shortInteger;
+ delete shortInteger2;
+ delete shortInteger3;
+ delete shortInteger4;
+
+ delete str2;
+ delete byte1;
+ delete byte2;
+ delete byte3;
+ delete byte4;
+}
+
+TEST(EtchComboValidatorTest, validateValueTest) {
+
+ EtchObject* byte = NULL;
+ EtchObject* result = NULL;
+ EtchObject* integer = new EtchInt32(-128);
+ EtchObject* integer2 = new EtchInt32(5);
+ EtchObject* integer3 = new EtchInt32(127);
+ EtchObject* byte2 = new EtchByte(3);
+
+ //create combo validator
+ EtchComboValidator *ptr = NULL;
+ capu::SmartPointer<EtchValidator> ptr1;
+ capu::SmartPointer<EtchValidator> ptr2;
+ EtchValidatorInt::Get(0, ptr1);
+ EtchValidatorString::Get(0, ptr2);
+ ptr = new EtchComboValidator(ptr1, ptr2);
+ //INT TESTS
+ EXPECT_TRUE(ptr->validateValue(byte, result) == ETCH_ERROR);
+ EXPECT_TRUE(ptr->validateValue(integer, result) == ETCH_OK);
+ EXPECT_TRUE(((EtchInt32*) result)->get() == ((EtchInt32*) integer)->get());
+ EXPECT_TRUE(ptr->validateValue(integer2, result) == ETCH_OK);
+ EXPECT_TRUE(((EtchInt32*) result)->get() == ((EtchInt32*) integer2)->get());
+ EXPECT_TRUE(ptr->validateValue(integer3, result) == ETCH_OK);
+ EXPECT_TRUE(((EtchInt32*) result)->get() == ((EtchInt32*) integer3)->get());
+ EXPECT_TRUE(ptr->validateValue(byte2, result) == ETCH_OK);
+ EXPECT_TRUE(((EtchInt32*) result)->get() == ((EtchByte*) byte2)->get());
+ delete result;
+ EtchObject* str = NULL;
+ EtchObject* str2 = new EtchString("hello");
+ //STRING TESTS
+ EXPECT_TRUE(ptr->validateValue(str, result) == ETCH_ERROR);
+ EXPECT_TRUE(ptr->validateValue(str2, result) == ETCH_OK);
+ delete result;
+ delete ptr;
+
+ delete byte2;
+ delete integer;
+ delete integer2;
+ delete integer3;
+}
+
+TEST(EtchComboValidatorTest, elementValidatorTest) {
+ //create combo validator
+ EtchComboValidator *ptr = NULL;
+ capu::SmartPointer<EtchValidator> ptr1;
+ capu::SmartPointer<EtchValidator> ptr2;
+ EtchValidatorInt::Get(1, ptr1);
+ EtchValidatorString::Get(1, ptr2);
+ ptr = new EtchComboValidator(ptr1, ptr2);
+ capu::SmartPointer<EtchValidator> element_validator;
+ ptr->getElementValidator(element_validator);
+
+
+ EtchObject* str = NULL;
+ EtchObject* str2 = new EtchString("hello");
+
+ EtchObject* integer = new EtchInt32(capu::NumericLimitMin<capu::int32_t>());
+ EtchObject* integer2 = new EtchInt32(0);
+ EtchObject* integer3 = new EtchInt32(capu::NumericLimitMax<capu::int32_t>());
+ EtchObject* integer4 = new EtchInt32(897);
+
+ EtchObject* longInteger = new EtchLong(capu::NumericLimitMin<capu::int32_t>());
+ EtchObject* longInteger2 = new EtchLong(0);
+ EtchObject* longInteger3 = new EtchLong(capu::NumericLimitMax<capu::int32_t>());
+ EtchObject* longInteger4 = new EtchLong(897);
+ //exceed limits of integer
+ EtchObject* longInteger5 = new EtchLong((capu::int64_t)capu::NumericLimitMax<capu::int32_t>() + (capu::int64_t)2);
+
+ EtchObject* shortInteger = new EtchShort(capu::NumericLimitMin<capu::int16_t>());
+ EtchObject* shortInteger2 = new EtchShort(0);
+ EtchObject* shortInteger3 = new EtchShort(capu::NumericLimitMax<capu::int16_t>());
+ EtchObject* shortInteger4 = new EtchShort();
+
+ EtchObject* byte1 = new EtchByte(capu::NumericLimitMax<capu::int8_t>());
+ EtchObject* byte2 = new EtchByte(0);
+ EtchObject* byte3 = new EtchByte(capu::NumericLimitMin<capu::int8_t>());
+ EtchObject* byte4 = new EtchByte(32);
+ //INT TEST
+ EXPECT_FALSE(element_validator->validate(longInteger5));
+ EXPECT_TRUE(element_validator->validate(integer));
+ EXPECT_TRUE(element_validator->validate(integer2));
+ EXPECT_TRUE(element_validator->validate(integer3));
+ EXPECT_TRUE(element_validator->validate(longInteger));
+ EXPECT_TRUE(element_validator->validate(longInteger2));
+ EXPECT_TRUE(element_validator->validate(longInteger3));
+ EXPECT_TRUE(element_validator->validate(shortInteger));
+ EXPECT_TRUE(element_validator->validate(shortInteger2));
+ EXPECT_TRUE(element_validator->validate(shortInteger3));
+ EXPECT_TRUE(element_validator->validate(byte1));
+ EXPECT_TRUE(element_validator->validate(byte2));
+ EXPECT_TRUE(element_validator->validate(byte3));
+ EXPECT_TRUE(element_validator->validate(byte4));
+ EXPECT_TRUE(element_validator->validate(integer4));
+ EXPECT_TRUE(element_validator->validate(longInteger4));
+ EXPECT_TRUE(element_validator->validate(shortInteger4));
+ //STRING TEST
+ EXPECT_FALSE(element_validator->validate(str));
+ EXPECT_TRUE(element_validator->validate(str2));
+ delete ptr;
+
+ delete integer;
+ delete integer2;
+ delete integer3;
+ delete integer4;
+
+ delete longInteger;
+ delete longInteger2;
+ delete longInteger3;
+ delete longInteger4;
+ delete longInteger5;
+
+ delete shortInteger;
+ delete shortInteger2;
+ delete shortInteger3;
+ delete shortInteger4;
+
+ delete str2;
+ delete byte1;
+ delete byte2;
+ delete byte3;
+ delete byte4;
+}
\ No newline at end of file