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:18:48 UTC

svn commit: r1345062 - 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:18:47 2012
New Revision: 1345062

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

Long Validator has been implemented

Change-Id: Ic31b39b1219b77cafb644d2a5b6ad1cf971cb115

Added:
    incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorLong.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorLong.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorLongTest.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=1345062&r1=1345061&r2=1345062&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:18:47 2012
@@ -45,6 +45,7 @@ enum EtchObjectTypeIds {
   EOTID_VALIDATOR_SHORT,
   EOTID_VALIDATOR_FLOAT,
   EOTID_VALIDATOR_DOUBLE,
+  EOTID_VALIDATOR_LONG,
 
   EOTID_NATIVE_INT8,
   EOTID_NATIVE_INT16,

Added: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorLong.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorLong.h?rev=1345062&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorLong.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorLong.h Fri Jun  1 11:18:47 2012
@@ -0,0 +1,67 @@
+/* $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 __ETCHVALIDATORLONG_H__
+#define __ETCHVALIDATORLONG_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 EtchValidatorLong : public EtchTypeValidator {
+public:
+
+  virtual ~EtchValidatorLong();
+
+  /**
+   * @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:
+  EtchValidatorLong(capu::uint32_t ndim);
+
+private:
+  static capu::SmartPointer<EtchValidator> mValidator[MAX_CACHED];
+
+};
+
+
+#endif /* ETCHVALIDATORLONG_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=1345062&r1=1345061&r2=1345062&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:18:47 2012
@@ -70,6 +70,7 @@ SET(MAIN_INCLUDES
     ${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/serialization/EtchValidatorLong.h
     ${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
     )
 
@@ -102,6 +103,7 @@ SET(MAIN_SOURCES
     serialization/EtchValidatorShort.cpp
     serialization/EtchValidatorFloat.cpp
     serialization/EtchValidatorDouble.cpp
+    serialization/EtchValidatorLong.cpp
     util/EtchUtil.cpp
     )
 

Added: incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorLong.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorLong.cpp?rev=1345062&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorLong.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorLong.cpp Fri Jun  1 11:18:47 2012
@@ -0,0 +1,114 @@
+/* $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/EtchValidatorLong.h"
+
+capu::SmartPointer<EtchValidator> EtchValidatorLong::mValidator[MAX_CACHED];
+const EtchObjectType EtchValidatorLong::TYPE(EOTID_VALIDATOR_LONG, NULL);
+
+EtchValidatorLong::EtchValidatorLong(capu::uint32_t ndim)
+: EtchTypeValidator(&EtchValidatorLong::TYPE, &EtchLong::TYPE, &EtchLong::TYPE, ndim) {
+
+}
+
+EtchValidatorLong::~EtchValidatorLong() {
+
+}
+
+capu::bool_t EtchValidatorLong::validate(EtchObject* value) {
+  if (value == NULL)
+    return false;
+
+  if (mExpectedType == NULL)
+    return false;
+
+  if (value->getObjectType()->equals(mExpectedType))
+    return true;
+
+  if ((value->getObjectType()->equals(&EtchInt32::TYPE)) ||
+          (value->getObjectType()->equals(&EtchShort::TYPE)) ||
+          (value->getObjectType()->equals(&EtchByte::TYPE)))
+    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);
+  }
+}
+
+status_t EtchValidatorLong::validateValue(EtchObject* value, EtchObject*& result) {
+  if (validate(value)) {
+    if ((value->getObjectType()->equals(&EtchLong::TYPE)) || (mNDims > 0)) {
+      result = value;
+      return ETCH_OK;
+    } else {
+      if (value->getObjectType()->equals(&EtchShort::TYPE)) {
+        EtchShort *v = (EtchShort *) value;
+        result = new EtchLong((capu::int64_t)v->get());
+        return ETCH_OK;
+      }
+
+      if (value->getObjectType()->equals(&EtchByte::TYPE)) {
+        EtchByte *v = (EtchByte *) value;
+        result = new EtchLong((capu::int64_t)v->get());
+        return ETCH_OK;
+      }
+
+      if (value->getObjectType()->equals(&EtchInt32::TYPE)) {
+        EtchInt32 *v = (EtchInt32 *) value;
+        result = new EtchLong((capu::int64_t)v->get());
+        return ETCH_OK;
+      }
+      return ETCH_ERROR;
+    }
+  } else {
+    return ETCH_ERROR;
+  }
+}
+
+status_t EtchValidatorLong::Get(capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
+  if (ndim > MAX_NDIMS) {
+    return ETCH_EINVAL;
+  }
+  if (ndim >= MAX_CACHED) {
+    val = new EtchValidatorLong(ndim);
+    return ETCH_OK;
+  }
+  if (mValidator[ndim].get() == NULL) {
+    mValidator[ndim] = new EtchValidatorLong(ndim);
+  }
+  val = mValidator[ndim];
+  return ETCH_OK;
+}
+
+status_t EtchValidatorLong::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
+  return EtchValidatorLong::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=1345062&r1=1345061&r2=1345062&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:18:47 2012
@@ -54,6 +54,7 @@ add_executable (etch-cpp-test
     serialization/EtchValidatorShortTest.cpp
     serialization/EtchValidatorFloatTest.cpp
     serialization/EtchValidatorDoubleTest.cpp
+    serialization/EtchValidatorLongTest.cpp
     util/EtchUtilTest.cpp
     ${GTEST}/src/gtest-all.cc
     ${GMOCK}/src/gmock-all.cc

Added: incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorLongTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorLongTest.cpp?rev=1345062&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorLongTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorLongTest.cpp Fri Jun  1 11:18:47 2012
@@ -0,0 +1,219 @@
+/* $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/EtchValidatorLong.h"
+#include "capu/util/SmartPointer.h"
+#include "common/EtchString.h"
+
+TEST(EtchValidatorLongTest, createTest) {
+  capu::SmartPointer<EtchValidatorLong> ptr = NULL;
+
+  capu::SmartPointer<EtchValidator> val;
+  EXPECT_TRUE(EtchValidatorLong::Get(0, val) == ETCH_OK);
+  ptr = capu::smartpointer_cast<EtchValidatorLong>(val);
+
+  EXPECT_TRUE(ptr->getExpectedType()->equals(&EtchLong::TYPE));
+  EXPECT_TRUE(ptr->getNDims() == 0);
+
+  EtchObjectType type1(EOTID_LONG, NULL);
+  EtchObjectType type2(EOTID_NATIVE_ARRAY, &type1);
+  EtchObjectType type3(EOTID_NATIVE_ARRAY, &type2);
+  EXPECT_TRUE(EtchValidatorLong::Get(2, val) == ETCH_OK);
+  ptr = capu::smartpointer_cast<EtchValidatorLong>(val);
+  EXPECT_TRUE(ptr->getExpectedType()->equals(&type3));
+  EXPECT_TRUE(ptr->getNDims() == 2);
+
+}
+
+TEST(EtchValidatorLongTest, 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 = new EtchString();
+
+  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);
+  capu::SmartPointer<EtchValidator> ptr = NULL;
+  EXPECT_TRUE(EtchValidatorLong::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(longInteger5));
+  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(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 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 str;
+  delete byte1;
+  delete byte2;
+  delete byte3;
+  delete byte4;
+
+}
+
+TEST(EtchValidatorLongTest, 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(EtchValidatorLong::Get(0, ptr) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(byte, result) == ETCH_ERROR);
+  EXPECT_TRUE(ptr->validateValue(integer, result) == ETCH_OK);
+  EXPECT_TRUE(((EtchLong*) result)->get() == ((EtchInt32*) integer)->get());
+  delete result;
+  EXPECT_TRUE(ptr->validateValue(integer2, result) == ETCH_OK);
+  EXPECT_TRUE(((EtchLong*) result)->get() == ((EtchInt32*) integer2)->get());
+  delete result;
+  EXPECT_TRUE(ptr->validateValue(integer3, result) == ETCH_OK);
+  EXPECT_TRUE(((EtchLong*) result)->get() == ((EtchInt32*) integer3)->get());
+  delete result;
+  EXPECT_TRUE(ptr->validateValue(byte2, result) == ETCH_OK);
+  EXPECT_TRUE(((EtchLong*) result)->get() == ((EtchByte*) byte2)->get());
+  delete result;
+  delete integer;
+  delete integer2;
+  delete integer3;
+  delete byte2;
+}
+
+TEST(EtchValidatorLongTest, elementValidatorTest) {
+  capu::SmartPointer<EtchValidator> ptr = NULL;
+  EXPECT_TRUE(EtchValidatorLong::Get(1, ptr) == ETCH_OK);
+  capu::SmartPointer<EtchValidator> elementValidator;
+  ptr->getElementValidator(elementValidator);
+
+  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 = new EtchString();
+
+  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);
+
+  EXPECT_FALSE(elementValidator->validate(str));
+  EXPECT_TRUE(elementValidator->validate(longInteger5));
+  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(byte1));
+  EXPECT_TRUE(elementValidator->validate(byte2));
+  EXPECT_TRUE(elementValidator->validate(byte3));
+  EXPECT_TRUE(elementValidator->validate(byte4));
+  EXPECT_TRUE(elementValidator->validate(integer4));
+  EXPECT_TRUE(elementValidator->validate(longInteger4));
+  EXPECT_TRUE(elementValidator->validate(shortInteger4));
+
+  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 str;
+  delete byte1;
+  delete byte2;
+  delete byte3;
+  delete byte4;
+}
+
+