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:19:39 UTC
svn commit: r1345064 - 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:19:38 2012
New Revision: 1345064
URL: http://svn.apache.org/viewvc?rev=1345064&view=rev
Log:
ETCH-185 Implementation Validators
String Validator has been implemented
Change-Id: Ib1000436426d5f2578c27bf57ded0b63232f07fd
Added:
incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorString.h
incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorString.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorStringTest.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=1345064&r1=1345063&r2=1345064&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:19:38 2012
@@ -46,6 +46,7 @@ enum EtchObjectTypeIds {
EOTID_VALIDATOR_FLOAT,
EOTID_VALIDATOR_DOUBLE,
EOTID_VALIDATOR_LONG,
+ EOTID_VALIDATOR_STRING,
EOTID_NATIVE_INT8,
EOTID_NATIVE_INT16,
Added: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorString.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorString.h?rev=1345064&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorString.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorString.h Fri Jun 1 11:19:38 2012
@@ -0,0 +1,63 @@
+/* $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 __ETCHVALIDATORSTRING_H__
+#define __ETCHVALIDATORSTRING_H__
+#include "serialization/EtchTypeValidator.h"
+#include "capu/os/Mutex.h"
+#include "common/EtchString.h"
+#include "common/EtchNativeArray.h"
+
+class EtchValidatorString : public EtchTypeValidator {
+public:
+
+ virtual ~EtchValidatorString();
+
+ /**
+ * @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:
+ EtchValidatorString(capu::uint32_t ndim);
+
+private:
+ static capu::SmartPointer<EtchValidator> mValidator[MAX_CACHED];
+
+};
+
+
+#endif /* ETCHVALIDATORSTRING_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=1345064&r1=1345063&r2=1345064&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:19:38 2012
@@ -71,6 +71,7 @@ SET(MAIN_INCLUDES
${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorFloat.h
${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/util/EtchUtil.h
)
@@ -104,6 +105,7 @@ SET(MAIN_SOURCES
serialization/EtchValidatorFloat.cpp
serialization/EtchValidatorDouble.cpp
serialization/EtchValidatorLong.cpp
+ serialization/EtchValidatorString.cpp
util/EtchUtil.cpp
)
Added: incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorString.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorString.cpp?rev=1345064&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorString.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorString.cpp Fri Jun 1 11:19:38 2012
@@ -0,0 +1,86 @@
+/* $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/EtchValidatorString.h"
+
+capu::SmartPointer<EtchValidator> EtchValidatorString::mValidator[MAX_CACHED];
+const EtchObjectType EtchValidatorString::TYPE(EOTID_VALIDATOR_STRING, NULL);
+
+EtchValidatorString::EtchValidatorString(capu::uint32_t ndim)
+: EtchTypeValidator(&EtchValidatorString::TYPE, &EtchString::TYPE, &EtchString::TYPE, ndim) {
+
+}
+
+EtchValidatorString::~EtchValidatorString() {
+
+}
+
+capu::bool_t EtchValidatorString::validate(EtchObject* value) {
+ if (value == NULL)
+ return false;
+ if (mExpectedType == NULL)
+ return false;
+ if (value->getObjectType()->equals(mExpectedType))
+ return true;
+ // handle array
+ 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 EtchValidatorString::validateValue(EtchObject* value, EtchObject*& result) {
+ if (validate(value)) {
+ result = value;
+ return ETCH_OK;
+ } else {
+ return ETCH_ERROR;
+ }
+}
+
+status_t EtchValidatorString::Get(capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
+ if (ndim > MAX_NDIMS) {
+ return ETCH_EINVAL;
+ }
+ if (ndim >= MAX_CACHED) {
+ val = new EtchValidatorString(ndim);
+ return ETCH_OK;
+ }
+ if (mValidator[ndim].get() == NULL) {
+ mValidator[ndim] = new EtchValidatorString(ndim);
+ }
+ val = mValidator[ndim];
+ return ETCH_OK;
+}
+
+status_t EtchValidatorString::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
+ return EtchValidatorString::Get(mNDims - 1, val);
+}
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=1345064&r1=1345063&r2=1345064&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:19:38 2012
@@ -55,6 +55,7 @@ add_executable (etch-cpp-test
serialization/EtchValidatorFloatTest.cpp
serialization/EtchValidatorDoubleTest.cpp
serialization/EtchValidatorLongTest.cpp
+ serialization/EtchValidatorStringTest.cpp
util/EtchUtilTest.cpp
${GTEST}/src/gtest-all.cc
${GMOCK}/src/gmock-all.cc
Added: incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorStringTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorStringTest.cpp?rev=1345064&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorStringTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorStringTest.cpp Fri Jun 1 11:19:38 2012
@@ -0,0 +1,88 @@
+/* $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/EtchValidatorString.h"
+#include "capu/util/SmartPointer.h"
+#include "common/EtchInt32.h"
+
+TEST(EtchValidatorStringTest, createTest) {
+ capu::SmartPointer<EtchValidatorString> ptr = NULL;
+
+ capu::SmartPointer<EtchValidator> val;
+ EXPECT_TRUE(EtchValidatorString::Get(0, val) == ETCH_OK);
+ ptr = capu::smartpointer_cast<EtchValidatorString>(val);
+
+ EXPECT_TRUE(ptr->getExpectedType()->equals(&EtchString::TYPE));
+ EXPECT_TRUE(ptr->getNDims() == 0);
+
+ EtchObjectType type1(EOTID_STRING, NULL);
+ EtchObjectType type2(EOTID_NATIVE_ARRAY, &type1);
+ EtchObjectType type3(EOTID_NATIVE_ARRAY, &type2);
+ EXPECT_TRUE(EtchValidatorString::Get(2, val) == ETCH_OK);
+ ptr = capu::smartpointer_cast<EtchValidatorString>(val);
+ EXPECT_TRUE(ptr->getExpectedType()->equals(&type3));
+ EXPECT_TRUE(ptr->getNDims() == 2);
+
+}
+
+TEST(EtchValidatorStringTest, validateTest) {
+ EtchObject* str = NULL;
+ EtchObject* integer = new EtchInt32(4);
+ EtchObject* str2 = new EtchString("hello");
+ capu::SmartPointer<EtchValidator> ptr = NULL;
+ EXPECT_TRUE(EtchValidatorString::Get(0, ptr) == ETCH_OK);
+ EXPECT_TRUE(((EtchTypeValidator*) ptr.get())->getNDims() == 0);
+ EXPECT_FALSE(ptr->validate(str));
+ EXPECT_FALSE(ptr->validate(integer));
+ EXPECT_TRUE(ptr->validate(str2));
+ delete integer;
+ delete str2;
+}
+
+TEST(EtchValidatorStringTest, validateValueTest) {
+ EtchObject* str = NULL;
+ EtchObject* result;
+ EtchObject* integer = new EtchInt32(4);
+ EtchObject* str2 = new EtchString("hello");
+ capu::SmartPointer<EtchValidator> ptr = NULL;
+ EXPECT_TRUE(EtchValidatorString::Get(0, ptr) == ETCH_OK);
+ EXPECT_TRUE(ptr->validateValue(str, result) == ETCH_ERROR);
+ EXPECT_TRUE(ptr->validateValue(integer, result) == ETCH_ERROR);
+ EXPECT_TRUE(ptr->validateValue(str2, result) == ETCH_OK);
+ EXPECT_TRUE(((EtchString*) result)->equals((EtchString*) str2));
+ delete integer;
+ delete str2;
+}
+
+TEST(EtchValidatorStringTest, elementValidatorTest) {
+ capu::SmartPointer<EtchValidator> ptr = NULL;
+ EXPECT_TRUE(EtchValidatorString::Get(1, ptr) == ETCH_OK);
+ capu::SmartPointer<EtchValidator> elementValidator;
+ ptr->getElementValidator(elementValidator);
+
+ EtchObject* str = NULL;
+ EtchObject* integer = new EtchInt32(4);
+ EtchObject* str2 = new EtchString("hello");
+
+ EXPECT_FALSE(elementValidator->validate(str));
+ EXPECT_FALSE(elementValidator->validate(integer));
+ EXPECT_TRUE(elementValidator->validate(str2));
+ delete integer;
+ delete str2;
+}