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:29:24 UTC

svn commit: r1345071 - in /incubator/etch/trunk/binding-cpp/runtime: include/common/ include/serialization/ src/main/ src/main/common/ src/main/serialization/ src/test/ src/test/serialization/

Author: fitzner
Date: Fri Jun  1 11:29:23 2012
New Revision: 1345071

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

Object Validator has been implemented

Change-Id: I85a85d1a8c4592b499c8abb616bd75bd7d694250

Added:
    incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorObject.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorObject.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorObjectTest.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/main/common/EtchObject.cpp
    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=1345071&r1=1345070&r2=1345071&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:29:23 2012
@@ -48,7 +48,9 @@ enum EtchObjectTypeIds {
   EOTID_VALIDATOR_LONG,
   EOTID_VALIDATOR_STRING,
   EOTID_VALIDATOR_COMBO,
+  EOTID_VALIDATOR_OBJECT,
   EOTID_FIELD,
+  EOTID_OBJECT,
 
   EOTID_NATIVE_INT8,
   EOTID_NATIVE_INT16,

Added: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorObject.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorObject.h?rev=1345071&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorObject.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchValidatorObject.h Fri Jun  1 11:29:23 2012
@@ -0,0 +1,62 @@
+/* $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 __ETCHVALIDATOROBJECT_H__
+#define __ETCHVALIDATOROBJECT_H__
+
+#include "serialization/EtchTypeValidator.h"
+
+class EtchValidatorObject : public EtchTypeValidator {
+public:
+
+  virtual ~EtchValidatorObject();
+
+  /**
+   * @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:
+  EtchValidatorObject(capu::uint32_t ndim);
+
+private:
+  static capu::SmartPointer<EtchValidator> mValidator[MAX_CACHED];
+
+};
+
+
+#endif /* ETCHVALIDATOROBJECT_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=1345071&r1=1345070&r2=1345071&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:29:23 2012
@@ -75,6 +75,7 @@ SET(MAIN_INCLUDES
     ${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorString.h
     ${PROJECT_SOURCE_DIR}/include/serialization/EtchComboValidator.h
     ${PROJECT_SOURCE_DIR}/include/serialization/EtchField.h
+    ${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorObject.h
     ${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
     )
 
@@ -111,6 +112,7 @@ SET(MAIN_SOURCES
     serialization/EtchValidatorString.cpp
     serialization/EtchComboValidator.cpp
     serialization/EtchField.cpp
+    serialization/EtchValidatorObject.cpp
     util/EtchUtil.cpp
     )
 

Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchObject.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchObject.cpp?rev=1345071&r1=1345070&r2=1345071&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchObject.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchObject.cpp Fri Jun  1 11:29:23 2012
@@ -17,6 +17,7 @@
  */
 
 #include "common/EtchObject.h"
+const EtchObjectType EtchObject::TYPE(EOTID_OBJECT, NULL);
 
 EtchObject::EtchObject(const EtchObjectType* type){
   mType = type;
@@ -26,7 +27,7 @@ const EtchObjectType* EtchObject::getObj
   return mType;
 }
 
-EtchObject::~EtchObject(){
+EtchObject::~EtchObject() {
 }
 
 capu::uint64_t EtchObject::getHashCode() const{

Added: incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorObject.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorObject.cpp?rev=1345071&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorObject.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchValidatorObject.cpp Fri Jun  1 11:29:23 2012
@@ -0,0 +1,69 @@
+/* $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/EtchValidatorObject.h"
+
+
+capu::SmartPointer<EtchValidator> EtchValidatorObject::mValidator[MAX_CACHED];
+const EtchObjectType EtchValidatorObject::TYPE(EOTID_VALIDATOR_OBJECT, NULL);
+
+EtchValidatorObject::EtchValidatorObject(capu::uint32_t ndim)
+: EtchTypeValidator(&EtchValidatorObject::TYPE, &EtchObject::TYPE, &EtchObject::TYPE, ndim) {
+  mSubclass = true;
+}
+
+EtchValidatorObject::~EtchValidatorObject() {
+
+}
+
+capu::bool_t EtchValidatorObject::validate(EtchObject* value) {
+  if (value == NULL)
+    return false;
+  if (mExpectedType == NULL)
+    return false;
+  if (value->getObjectType()->equals(mExpectedType))
+    return true;
+  return ((dynamic_cast<EtchObject*> (value) != NULL) && (mSubclass));
+}
+
+status_t EtchValidatorObject::validateValue(EtchObject* value, EtchObject*& result) {
+  if (validate(value)) {
+    result = value;
+    return ETCH_OK;
+  } else {
+    return ETCH_ERROR;
+  }
+}
+
+status_t EtchValidatorObject::Get(capu::uint32_t ndim, capu::SmartPointer<EtchValidator> &val) {
+  if (ndim > MAX_NDIMS)
+    return ETCH_EINVAL;
+  if (ndim >= MAX_CACHED) {
+    val = new EtchValidatorObject(ndim);
+    return ETCH_OK;
+  }
+  if (mValidator[ndim].get() == NULL) {
+    mValidator[ndim] = new EtchValidatorObject(ndim);
+  }
+  val = mValidator[ndim];
+  return ETCH_OK;
+}
+
+status_t EtchValidatorObject::getElementValidator(capu::SmartPointer<EtchValidator> &val) {
+  return EtchValidatorObject::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=1345071&r1=1345070&r2=1345071&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:29:23 2012
@@ -58,6 +58,7 @@ add_executable (etch-cpp-test
     serialization/EtchValidatorStringTest.cpp
     serialization/EtchComboValidatorTest.cpp
     serialization/EtchFieldTest.cpp
+    serialization/EtchValidatorObjectTest.cpp
     util/EtchUtilTest.cpp
     ${GTEST}/src/gtest-all.cc
     ${GMOCK}/src/gmock-all.cc

Added: incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorObjectTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorObjectTest.cpp?rev=1345071&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorObjectTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchValidatorObjectTest.cpp Fri Jun  1 11:29:23 2012
@@ -0,0 +1,211 @@
+
+/* $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/EtchValidatorObject.h"
+#include "capu/util/SmartPointer.h"
+#include "common/EtchInt32.h"
+#include "common/EtchBool.h"
+#include "common/EtchLong.h"
+#include "common/EtchShort.h"
+#include "common/EtchByte.h"
+#include "common/EtchString.h"
+#include "serialization/EtchTypeCodes.h"
+#include "capu/os/NumericLimits.h"
+
+TEST(EtchValidatorObjectTest, createTest) {
+  capu::SmartPointer<EtchValidatorObject> ptr = NULL;
+  capu::SmartPointer<EtchValidator> val;
+  EXPECT_TRUE(EtchValidatorObject::Get(0, val) == ETCH_OK);
+  ptr = capu::smartpointer_cast<EtchValidatorObject>(val);
+  EXPECT_TRUE(ptr->getNDims() == 0);
+
+  EXPECT_TRUE(EtchValidatorObject::Get(2, val) == ETCH_OK);
+  ptr = capu::smartpointer_cast<EtchValidatorObject>(val);
+  EXPECT_TRUE(ptr->getNDims() == 2);
+}
+
+TEST(EtchValidatorObjectTest, validateTest) {
+  EtchObject* boolean = NULL;
+  EtchObject* integer = new EtchInt32(4);
+  EtchObject* boolean2 = new EtchBool(false);
+  capu::SmartPointer<EtchValidator> ptr = NULL;
+  EXPECT_TRUE(EtchValidatorObject::Get(0, ptr) == ETCH_OK);
+  EXPECT_TRUE((capu::smartpointer_cast<EtchTypeValidator>(ptr))->getNDims() == 0);
+  EXPECT_FALSE(ptr->validate(boolean));
+  EXPECT_TRUE(ptr->validate(integer));
+  EXPECT_TRUE(ptr->validate(boolean2));
+  delete integer;
+  delete boolean2;
+}
+
+TEST(EtchValidatorObjectTest, validateValueTest) {
+  EtchObject* byte = NULL;
+  EtchObject* result = NULL;
+  EtchObject* integer = new EtchInt32(capu::NumericLimitMin<capu::int16_t > ());
+  EtchObject* integer2 = new EtchInt32(0);
+  EtchObject* integer3 = new EtchInt32(capu::NumericLimitMax<capu::int16_t > ());
+  EtchObject* integer4 = new EtchInt32(897);
+
+  //exceed limits of integer
+  EtchObject* integer5 = new EtchInt32(capu::NumericLimitMax<capu::int16_t > () + 2);
+
+  EtchObject* longInteger = new EtchLong(capu::NumericLimitMin<capu::int16_t > ());
+  EtchObject* longInteger2 = new EtchLong(0);
+  EtchObject* longInteger3 = new EtchLong(capu::NumericLimitMax<capu::int16_t > ());
+  EtchObject* longInteger4 = new EtchLong(897);
+  //exceed limits of integer
+  EtchObject* longInteger5 = new EtchLong((capu::int64_t)capu::NumericLimitMax<capu::int16_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(EtchValidatorObject::Get(0, ptr) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(byte, result) == ETCH_ERROR);
+  EXPECT_TRUE(ptr->validateValue(str, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(longInteger5, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(integer5, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(integer, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(integer2, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(integer3, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(longInteger, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(longInteger2, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(longInteger3, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(shortInteger, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(shortInteger2, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(shortInteger3, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(byte1, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(byte2, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(byte3, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(byte4, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(integer4, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(longInteger4, result) == ETCH_OK);
+  EXPECT_TRUE(ptr->validateValue(shortInteger4, result) == ETCH_OK);
+
+  delete integer;
+  delete integer2;
+  delete integer3;
+  delete integer4;
+  delete integer5;
+  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(EtchValidatorObjectTest, elementValidatorTest) {
+  capu::SmartPointer<EtchValidator> ptr = NULL;
+  EXPECT_TRUE(EtchValidatorObject::Get(1, ptr) == ETCH_OK);
+  capu::SmartPointer<EtchValidator> elementValidator;
+  ptr->getElementValidator(elementValidator);
+
+
+  EtchObject* integer = new EtchInt32(capu::NumericLimitMin<capu::int16_t > ());
+  EtchObject* integer2 = new EtchInt32(0);
+  EtchObject* integer3 = new EtchInt32(capu::NumericLimitMax<capu::int16_t > ());
+  EtchObject* integer4 = new EtchInt32(897);
+
+  //exceed limits of integer
+  EtchObject* integer5 = new EtchInt32(capu::NumericLimitMax<capu::int16_t > () + 2);
+
+  EtchObject* longInteger = new EtchLong(capu::NumericLimitMin<capu::int16_t > ());
+  EtchObject* longInteger2 = new EtchLong(0);
+  EtchObject* longInteger3 = new EtchLong(capu::NumericLimitMax<capu::int16_t > ());
+  EtchObject* longInteger4 = new EtchLong(897);
+  //exceed limits of integer
+  EtchObject* longInteger5 = new EtchLong((capu::int64_t)capu::NumericLimitMax<capu::int16_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_TRUE(elementValidator->validate(str));
+  EXPECT_TRUE(elementValidator->validate(longInteger5));
+  EXPECT_TRUE(elementValidator->validate(integer5));
+  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 integer5;
+  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;
+}