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:16:57 UTC
svn commit: r1345060 - 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:16:56 2012
New Revision: 1345060
URL: http://svn.apache.org/viewvc?rev=1345060&view=rev
Log:
ETCH-185 Implementation Validators
Float Validator has been implemented by Aaron
Change-Id: I5236b67eaebd3d589132e5b6698ebdfa2f32054b
Added:
incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorFloat.h
incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorFloat.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorFloatTest.cpp
Modified:
incubator/etch/trunk/binding-cpp/runtime/include/common/EtchObjectType.h
incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeCodes.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=1345060&r1=1345059&r2=1345060&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:16:56 2012
@@ -43,6 +43,7 @@ enum EtchObjectTypeIds {
EOTID_VALIDATOR_BYTE,
EOTID_VALIDATOR_INT,
EOTID_VALIDATOR_SHORT,
+ EOTID_VALIDATOR_FLOAT,
EOTID_NATIVE_INT8,
EOTID_NATIVE_INT16,
Modified: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeCodes.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeCodes.h?rev=1345060&r1=1345059&r2=1345060&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeCodes.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchTypeCodes.h Fri Jun 1 11:16:56 2012
@@ -29,7 +29,6 @@
* Tiny integers are completely encoded within the type byte.
*/
class EtchTypeCode {
-
public:
/**
* A code denoting a null value.
Added: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorFloat.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorFloat.h?rev=1345060&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorFloat.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorFloat.h Fri Jun 1 11:16:56 2012
@@ -0,0 +1,64 @@
+/* $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 __ETCHVALIDATORFLOAT_H__
+#define __ETCHVALIDATORFLOAT_H__
+#include "serialization/EtchTypeValidator.h"
+#include "common/EtchDouble.h"
+#include "common/EtchFloat.h"
+#include "serialization/EtchTypeCodes.h"
+#include "common/EtchNativeArray.h"
+
+class EtchValidatorFloat : public EtchTypeValidator {
+public:
+
+ virtual ~EtchValidatorFloat();
+
+ /**
+ * @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:
+ EtchValidatorFloat(capu::uint32_t ndim);
+
+private:
+ static capu::SmartPointer<EtchValidator> mValidator[MAX_CACHED];
+
+};
+
+
+#endif /* __ETCHVALIDATORFLOAT_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=1345060&r1=1345059&r2=1345060&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:16:56 2012
@@ -68,6 +68,7 @@ SET(MAIN_INCLUDES
${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorByte.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorInt.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorShort.h
+ ${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorFloat.h
${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
)
@@ -98,6 +99,7 @@ SET(MAIN_SOURCES
serialization/EtchValidatorByte.cpp
serialization/EtchValidatorInt.cpp
serialization/EtchValidatorShort.cpp
+ serialization/EtchValidatorFloat.cpp
util/EtchUtil.cpp
)
Added: incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorFloat.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorFloat.cpp?rev=1345060&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorFloat.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorFloat.cpp Fri Jun 1 11:16:56 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 "serialization/EtchValidatorFloat.h"
+
+capu::SmartPointer<EtchValidator> EtchValidatorFloat::mValidator[MAX_CACHED];
+const EtchObjectType EtchValidatorFloat::TYPE(EOTID_VALIDATOR_FLOAT, NULL);
+
+EtchValidatorFloat::EtchValidatorFloat(capu::uint32_t ndim)
+: EtchTypeValidator(&EtchValidatorFloat::TYPE, &EtchFloat::TYPE, &EtchFloat::TYPE, ndim) {
+
+}
+
+EtchValidatorFloat::~EtchValidatorFloat() {
+
+}
+
+capu::bool_t EtchValidatorFloat::validate(EtchObject* value) {
+
+ if (value == NULL)
+ return false;
+ if (mExpectedType == NULL)
+ return false;
+ if (value->getObjectType()->equals(mExpectedType))
+ return true;
+
+ //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 EtchValidatorFloat::validateValue(EtchObject* value, EtchObject*& result) {
+ if (validate(value)) {
+ result = value;
+ return ETCH_OK;
+ } else {
+ return ETCH_ERROR;
+ }
+}
+
+status_t EtchValidatorFloat::Get(capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
+ if (ndim > MAX_NDIMS) {
+ return ETCH_EINVAL;
+ }
+ if (ndim >= MAX_CACHED) {
+ val = new EtchValidatorFloat(ndim);
+ return ETCH_OK;
+ }
+ if (mValidator[ndim].get() == NULL) {
+ mValidator[ndim] = new EtchValidatorFloat(ndim);
+ }
+ val = mValidator[ndim];
+ return ETCH_OK;
+}
+
+status_t EtchValidatorFloat::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
+ return EtchValidatorFloat::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=1345060&r1=1345059&r2=1345060&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:16:56 2012
@@ -52,6 +52,7 @@ add_executable (etch-cpp-test
serialization/EtchValidatorByteTest.cpp
serialization/EtchValidatorIntTest.cpp
serialization/EtchValidatorShortTest.cpp
+ serialization/EtchValidatorFloatTest.cpp
util/EtchUtilTest.cpp
${GTEST}/src/gtest-all.cc
${GMOCK}/src/gmock-all.cc
Added: incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorFloatTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorFloatTest.cpp?rev=1345060&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorFloatTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorFloatTest.cpp Fri Jun 1 11:16:56 2012
@@ -0,0 +1,123 @@
+/* $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/EtchValidatorFloat.h"
+#include "capu/util/SmartPointer.h"
+#include "common/EtchString.h"
+#include "capu/os/NumericLimits.h"
+
+TEST(EtchValidatorFloatTest, createTest) {
+ capu::SmartPointer<EtchValidatorFloat> ptr = NULL;
+
+ capu::SmartPointer<EtchValidator> val;
+ EXPECT_TRUE(EtchValidatorFloat::Get(0, val) == ETCH_OK);
+ ptr = capu::smartpointer_cast<EtchValidatorFloat>(val);
+
+ EXPECT_TRUE(ptr->getExpectedType()->equals(&EtchFloat::TYPE));
+ EXPECT_TRUE(ptr->getNDims() == 0);
+
+ EtchObjectType type1(EOTID_FLOAT, NULL);
+ EtchObjectType type2(EOTID_NATIVE_ARRAY, &type1);
+ EtchObjectType type3(EOTID_NATIVE_ARRAY, &type2);
+
+ EXPECT_TRUE(EtchValidatorFloat::Get(2, val) == ETCH_OK);
+ ptr = capu::smartpointer_cast<EtchValidatorFloat>(val);
+ EXPECT_TRUE(ptr->getExpectedType()->equals(&type3));
+ EXPECT_TRUE(ptr->getNDims() == 2);
+}
+
+TEST(EtchValidatorFloatTest, validateTest) {
+ EtchObject* byte = NULL;
+
+ EtchObject* floatTmp = new EtchFloat(capu::NumericLimitMin<capu::float_t>());
+ EtchObject* floatTmp1 = new EtchFloat(0);
+ EtchObject* floatTmp2 = new EtchFloat(capu::NumericLimitMax<capu::float_t>());
+ EtchObject* floatTmp3 = new EtchFloat(897.12);
+
+ //incompatible type
+ EtchObject* str = new EtchString();
+
+ capu::SmartPointer<EtchValidator> ptr = NULL;
+ EXPECT_TRUE(EtchValidatorFloat::Get(0, ptr) == ETCH_OK);
+ EXPECT_TRUE((capu::smartpointer_cast<EtchTypeValidator>(ptr))->getNDims() == 0);
+
+ EXPECT_FALSE(ptr->validate(byte));
+ EXPECT_FALSE(ptr->validate(str));
+
+ EXPECT_TRUE(ptr->validate(floatTmp));
+ EXPECT_TRUE(ptr->validate(floatTmp1));
+ EXPECT_TRUE(ptr->validate(floatTmp2));
+ EXPECT_TRUE(ptr->validate(floatTmp3));
+
+ delete floatTmp;
+ delete floatTmp1;
+ delete floatTmp2;
+ delete floatTmp3;
+ delete str;
+}
+
+TEST(EtchValidatorFloatTest, validateValueTest) {
+ EtchObject* byte = NULL;
+ EtchObject* result;
+ EtchObject* floatTmp = new EtchFloat(-128.12);
+ EtchObject* floatTmp2 = new EtchFloat(5.13);
+ EtchObject* floatTmp3 = new EtchFloat(127.54);
+ capu::SmartPointer<EtchValidator> ptr = NULL;
+ EXPECT_TRUE(EtchValidatorFloat::Get(0, ptr) == ETCH_OK);
+ EXPECT_TRUE(ptr->validateValue(byte, result) == ETCH_ERROR);
+ EXPECT_TRUE(ptr->validateValue(floatTmp, result) == ETCH_OK);
+ EXPECT_TRUE(((EtchFloat*) result)->get() == ((EtchFloat*) floatTmp)->get());
+ EXPECT_TRUE(ptr->validateValue(floatTmp2, result) == ETCH_OK);
+ EXPECT_TRUE(((EtchFloat*) result)->get() == ((EtchFloat*) floatTmp2)->get());
+ EXPECT_TRUE(ptr->validateValue(floatTmp3, result) == ETCH_OK);
+ EXPECT_TRUE(((EtchFloat*) result)->get() == ((EtchFloat*) floatTmp3)->get());
+ delete floatTmp;
+ delete floatTmp2;
+ delete floatTmp3;
+}
+
+TEST(EtchValidatorFloatTest, elementValidatorTest) {
+ capu::SmartPointer<EtchValidator> ptr = NULL;
+ EXPECT_TRUE(EtchValidatorFloat::Get(1, ptr) == ETCH_OK);
+ capu::SmartPointer<EtchValidator> elementValidator;
+ ptr->getElementValidator(elementValidator);
+
+ EtchObject* floatTmp = new EtchFloat(capu::NumericLimitMin<capu::float_t>());
+ EtchObject* floatTmp1 = new EtchFloat(0);
+ EtchObject* floatTmp2 = new EtchFloat(capu::NumericLimitMax<capu::float_t>());
+ EtchObject* floatTmp3 = new EtchFloat(897.12);
+
+ //incompatible type
+ EtchObject* str = new EtchString();
+
+ EXPECT_FALSE(elementValidator->validate(str));
+ EXPECT_TRUE(elementValidator->validate(floatTmp));
+ EXPECT_TRUE(elementValidator->validate(floatTmp1));
+ EXPECT_TRUE(elementValidator->validate(floatTmp2));
+ EXPECT_TRUE(elementValidator->validate(floatTmp3));
+
+ delete floatTmp;
+ delete floatTmp1;
+ delete floatTmp2;
+ delete floatTmp3;
+
+ delete str;
+}
+
+