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:17:33 UTC

svn commit: r1345061 - 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:17:32 2012
New Revision: 1345061

URL: http://svn.apache.org/viewvc?rev=1345061&view=rev
Log:
ETCH-185 Implementation Validators

Double Validator has been implemented by Aaron

Change-Id: I656bfd248492f993215af8d53984173433b26925

Added:
    incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorDouble.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorDouble.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorDoubleTest.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=1345061&r1=1345060&r2=1345061&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:17:32 2012
@@ -44,6 +44,7 @@ enum EtchObjectTypeIds {
   EOTID_VALIDATOR_INT,
   EOTID_VALIDATOR_SHORT,
   EOTID_VALIDATOR_FLOAT,
+  EOTID_VALIDATOR_DOUBLE,
 
   EOTID_NATIVE_INT8,
   EOTID_NATIVE_INT16,

Added: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorDouble.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorDouble.h?rev=1345061&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorDouble.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorDouble.h Fri Jun  1 11:17:32 2012
@@ -0,0 +1,65 @@
+/* $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 __ETCHVALIDATORDOUBLE_H__
+#define __ETCHVALIDATORDOUBLE_H__
+#include "serialization/EtchTypeValidator.h"
+#include "common/EtchFloat.h"
+#include "common/EtchDouble.h"
+#include "serialization/EtchTypeCodes.h"
+#include "capu/os/NumericLimits.h"
+#include "common/EtchNativeArray.h"
+
+class EtchValidatorDouble : public EtchTypeValidator {
+public:
+
+  virtual ~EtchValidatorDouble();
+
+  /**
+   * @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:
+  EtchValidatorDouble(capu::uint32_t ndim);
+
+private:
+  static capu::SmartPointer<EtchValidator> mValidator[MAX_CACHED];
+
+};
+
+
+#endif /* __ETCHVALIDATORDOUBLE_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=1345061&r1=1345060&r2=1345061&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:17:32 2012
@@ -69,6 +69,7 @@ SET(MAIN_INCLUDES
     ${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/serialization/EtchValidatorDouble.h
     ${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
     )
 
@@ -100,6 +101,7 @@ SET(MAIN_SOURCES
     serialization/EtchValidatorInt.cpp
     serialization/EtchValidatorShort.cpp
     serialization/EtchValidatorFloat.cpp
+    serialization/EtchValidatorDouble.cpp
     util/EtchUtil.cpp
     )
 

Added: incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorDouble.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorDouble.cpp?rev=1345061&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorDouble.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorDouble.cpp Fri Jun  1 11:17:32 2012
@@ -0,0 +1,89 @@
+/* $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/EtchValidatorDouble.h"
+
+capu::SmartPointer<EtchValidator> EtchValidatorDouble::mValidator[MAX_CACHED];
+const EtchObjectType EtchValidatorDouble::TYPE(EOTID_VALIDATOR_DOUBLE, NULL);
+
+EtchValidatorDouble::EtchValidatorDouble(capu::uint32_t ndim)
+: EtchTypeValidator(&EtchValidatorDouble::TYPE, &EtchDouble::TYPE, &EtchDouble::TYPE, ndim) {
+
+}
+
+EtchValidatorDouble::~EtchValidatorDouble() {
+
+}
+
+capu::bool_t EtchValidatorDouble::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 EtchValidatorDouble::validateValue(EtchObject* value, EtchObject*& result) {
+  if (validate(value)) {
+    result = value;
+    return ETCH_OK;
+  } else {
+    return ETCH_ERROR;
+  }
+}
+
+status_t EtchValidatorDouble::Get(capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
+  if (ndim > MAX_NDIMS) {
+    return ETCH_EINVAL;
+  }
+  if (ndim >= MAX_CACHED) {
+    val = new EtchValidatorDouble(ndim);
+    return ETCH_OK;
+  }
+  if (mValidator[ndim].get() == NULL) {
+    mValidator[ndim] = new EtchValidatorDouble(ndim);
+  }
+  val = mValidator[ndim];
+  return ETCH_OK;
+}
+
+status_t EtchValidatorDouble::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
+  return EtchValidatorDouble::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=1345061&r1=1345060&r2=1345061&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:17:32 2012
@@ -53,6 +53,7 @@ add_executable (etch-cpp-test
     serialization/EtchValidatorIntTest.cpp
     serialization/EtchValidatorShortTest.cpp
     serialization/EtchValidatorFloatTest.cpp
+    serialization/EtchValidatorDoubleTest.cpp
     util/EtchUtilTest.cpp
     ${GTEST}/src/gtest-all.cc
     ${GMOCK}/src/gmock-all.cc

Added: incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorDoubleTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorDoubleTest.cpp?rev=1345061&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorDoubleTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorDoubleTest.cpp Fri Jun  1 11:17:32 2012
@@ -0,0 +1,131 @@
+/* $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/EtchValidatorDouble.h"
+#include "capu/util/SmartPointer.h"
+#include "common/EtchString.h"
+
+TEST(EtchValidatorDoubleTest, createTest) {
+  capu::SmartPointer<EtchValidatorDouble> ptr = NULL;
+
+  capu::SmartPointer<EtchValidator> val;
+  EXPECT_TRUE(EtchValidatorDouble::Get(0, val) == ETCH_OK);
+  ptr = capu::smartpointer_cast<EtchValidatorDouble>(val);
+
+  EXPECT_TRUE(ptr->getExpectedType()->equals(&EtchDouble::TYPE));
+  EXPECT_TRUE(ptr->getNDims() == 0);
+
+  EtchObjectType type1(EOTID_DOUBLE, NULL);
+  EtchObjectType type2(EOTID_NATIVE_ARRAY, &type1);
+  EtchObjectType type3(EOTID_NATIVE_ARRAY, &type2);
+
+  EXPECT_TRUE(EtchValidatorDouble::Get(2, val) == ETCH_OK);
+  ptr = capu::smartpointer_cast<EtchValidatorDouble>(val);
+  EXPECT_TRUE(ptr->getExpectedType()->equals(&type3));
+  EXPECT_TRUE(ptr->getNDims() == 2);
+}
+
+TEST(EtchValidatorDoubleTest, validateTest) {
+  EtchObject* byte = NULL;
+
+  EtchObject* doubleTmp = new EtchDouble(capu::NumericLimitMax<capu::float_t>());
+  EtchObject* doubleTmp1 = new EtchDouble(0);
+  EtchObject* doubleTmp2 = new EtchDouble(capu::NumericLimitMin<capu::float_t>());
+  EtchObject* doubleTmp3 = new EtchDouble(897.12);
+  //exceed limits of Float
+  EtchObject* doubleTmp4_true = new EtchDouble((capu::double_t)capu::NumericLimitMax<capu::float_t>() + (capu::double_t)2.12);
+  //incompatible type
+  EtchObject* str = new EtchString();
+
+  capu::SmartPointer<EtchValidator> ptr = NULL;
+  EXPECT_TRUE(EtchValidatorDouble::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(doubleTmp));
+  EXPECT_TRUE(ptr->validate(doubleTmp1));
+  EXPECT_TRUE(ptr->validate(doubleTmp2));
+  EXPECT_TRUE(ptr->validate(doubleTmp3));
+  EXPECT_TRUE(ptr->validate(doubleTmp4_true));
+
+  delete doubleTmp;
+  delete doubleTmp1;
+  delete doubleTmp2;
+  delete doubleTmp3;
+  delete doubleTmp4_true;
+
+  delete str;
+}
+
+TEST(EtchValidatorDoubleTest, validateValueTest) {
+  EtchObject* byte = NULL;
+  EtchObject* result;
+  EtchObject* doubleTmp = new EtchDouble(-128.12);
+  EtchObject* doubleTmp2 = new EtchDouble(5.13);
+  EtchObject* doubleTmp3 = new EtchDouble(127.54);
+  capu::SmartPointer<EtchValidator> ptr = NULL;
+  EXPECT_TRUE(EtchValidatorDouble::Get(0, ptr) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(byte, result) == ETCH_ERROR);
+  EXPECT_TRUE(ptr->validateValue(doubleTmp, result) == ETCH_OK);
+  EXPECT_TRUE(((EtchDouble*) result)->get() == ((EtchDouble*) doubleTmp)->get());
+  EXPECT_TRUE(ptr->validateValue(doubleTmp2, result) == ETCH_OK);
+  EXPECT_TRUE(((EtchDouble*) result)->get() == ((EtchDouble*) doubleTmp2)->get());
+  EXPECT_TRUE(ptr->validateValue(doubleTmp3, result) == ETCH_OK);
+  EXPECT_TRUE(((EtchDouble*) result)->get() == ((EtchDouble*) doubleTmp3)->get());
+
+  delete doubleTmp;
+  delete doubleTmp2;
+  delete doubleTmp3;
+}
+
+TEST(EtchValidatorDoubleTest, elementValidatorTest) {
+  capu::SmartPointer<EtchValidator> ptr = NULL;
+  EXPECT_TRUE(EtchValidatorDouble::Get(1, ptr) == ETCH_OK);
+  capu::SmartPointer<EtchValidator> elementValidator;
+  ptr->getElementValidator(elementValidator);
+
+  EtchObject* doubleTmp = new EtchDouble(capu::NumericLimitMax<capu::float_t>());
+  EtchObject* doubleTmp1 = new EtchDouble(0);
+  EtchObject* doubleTmp2 = new EtchDouble(capu::NumericLimitMin<capu::float_t>());
+  EtchObject* doubleTmp3 = new EtchDouble(897.12);
+  //exceed limits of Float
+  EtchObject* doubleTmp4_true = new EtchDouble((capu::double_t)capu::NumericLimitMax<capu::float_t>() + (capu::double_t)2.12);
+
+  //incompatible type
+  EtchObject* str = new EtchString();
+
+  EXPECT_FALSE(elementValidator->validate(str));
+  EXPECT_TRUE(elementValidator->validate(doubleTmp4_true));
+  EXPECT_TRUE(elementValidator->validate(doubleTmp));
+  EXPECT_TRUE(elementValidator->validate(doubleTmp1));
+  EXPECT_TRUE(elementValidator->validate(doubleTmp2));
+  EXPECT_TRUE(elementValidator->validate(doubleTmp3));
+
+  delete doubleTmp;
+  delete doubleTmp1;
+  delete doubleTmp2;
+  delete doubleTmp3;
+  delete doubleTmp4_true;
+
+  delete str;
+}
+
+