You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by ve...@apache.org on 2012/06/01 14:18:02 UTC
svn commit: r1345104 - in /incubator/etch/trunk/binding-cpp/runtime:
include/serialization/ src/main/ src/main/serialization/ src/test/
src/test/serialization/
Author: veithm
Date: Fri Jun 1 12:18:02 2012
New Revision: 1345104
URL: http://svn.apache.org/viewvc?rev=1345104&view=rev
Log:
ETCH-184 Implementation of EtchRuntimeExceptionSerializer
Change-Id: I45704bd54ef2c5f318009e7b41ad7813d1745d03
Added:
incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchRuntimeExceptionSerializer.h
- copied, changed from r1345101, incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchListSerializer.h
incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchRuntimeExceptionSerializer.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchRuntimeExceptionSerializerTest.cpp
Modified:
incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchListSerializer.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/serialization/EtchListSerializer.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchListSerializer.h?rev=1345104&r1=1345103&r2=1345104&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchListSerializer.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchListSerializer.h Fri Jun 1 12:18:02 2012
@@ -54,7 +54,7 @@ public:
/**
* Defines custom fields in the value factory so that the importer can find them.
* @param type
- * @param collection
+ * @param class2type
*/
static status_t Init(EtchType* type, EtchClass2TypeMap* class2type);
Copied: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchRuntimeExceptionSerializer.h (from r1345101, incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchListSerializer.h)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchRuntimeExceptionSerializer.h?p2=incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchRuntimeExceptionSerializer.h&p1=incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchListSerializer.h&r1=1345101&r2=1345104&rev=1345104&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchListSerializer.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchRuntimeExceptionSerializer.h Fri Jun 1 12:18:02 2012
@@ -16,30 +16,31 @@
* limitations under the License.
*/
-#ifndef __ETCHLISTSERIALIZER_H__
-#define __ETCHLISTSERIALIZER_H__
-#include "common/EtchList.h"
-#include "common/EtchNativeArray.h"
+#ifndef __ETCHRUNTIMEEXCEPTIONSERIALIZER_H__
+#define __ETCHRUNTIMEEXCEPTIONSERIALIZER_H__
+
+#include "common/EtchString.h"
+#include "common/EtchRuntimeException.h"
#include "serialization/EtchImportExportHelper.h"
#include "serialization/EtchStructValue.h"
-#include "serialization/EtchField.h"
#include "serialization/EtchType.h"
+#include "serialization/EtchField.h"
#include "serialization/EtchClass2TypeMap.h"
-#include "serialization/EtchValidatorObject.h"
+#include "serialization/EtchValidatorString.h"
-class EtchListSerializer : public EtchImportExportHelper {
+class EtchRuntimeExceptionSerializer : public EtchImportExportHelper {
public:
/**
* Constructor
*/
- EtchListSerializer(EtchType* type, EtchField* field);
+ EtchRuntimeExceptionSerializer(EtchType* type, EtchField* field);
/**
* Destructor
*/
- virtual ~EtchListSerializer();
+ virtual ~EtchRuntimeExceptionSerializer();
/**
* @see EtchImportExportHelper
@@ -54,7 +55,7 @@ public:
/**
* Defines custom fields in the value factory so that the importer can find them.
* @param type
- * @param collection
+ * @param class2type
*/
static status_t Init(EtchType* type, EtchClass2TypeMap* class2type);
@@ -63,7 +64,9 @@ private:
EtchType* mType;
EtchField mField;
const static EtchString FIELD_NAME;
+
};
-#endif /* ETCHLISTSERIALIZER_H */
+
+#endif /* ETCHRUNTIMEEXCEPTIONSERIALIZER_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=1345104&r1=1345103&r2=1345104&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 12:18:02 2012
@@ -88,6 +88,7 @@ SET(MAIN_INCLUDES
${PROJECT_SOURCE_DIR}/include/serialization/EtchClass2TypeMap.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchListSerializer.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorRuntimeException.h
+ ${PROJECT_SOURCE_DIR}/include/serialization/EtchRuntimeExceptionSerializer.h
${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
)
@@ -136,6 +137,7 @@ SET(MAIN_SOURCES
serialization/EtchClass2TypeMap.cpp
serialization/EtchListSerializer.cpp
serialization/EtchValidatorRuntimeException.cpp
+ serialization/EtchRuntimeExceptionSerializer.cpp
util/EtchUtil.cpp
)
Added: incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchRuntimeExceptionSerializer.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchRuntimeExceptionSerializer.cpp?rev=1345104&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchRuntimeExceptionSerializer.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchRuntimeExceptionSerializer.cpp Fri Jun 1 12:18:02 2012
@@ -0,0 +1,83 @@
+/* $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/EtchRuntimeExceptionSerializer.h"
+
+const EtchString EtchRuntimeExceptionSerializer::FIELD_NAME("msg");
+
+// TODO: check signature regarding by value copy
+EtchRuntimeExceptionSerializer::EtchRuntimeExceptionSerializer(EtchType* type, EtchField* field)
+: mField(*field), mType(type) {
+
+}
+
+EtchRuntimeExceptionSerializer::~EtchRuntimeExceptionSerializer() {
+
+}
+
+status_t EtchRuntimeExceptionSerializer::importValue(EtchStructValue* value, capu::SmartPointer<EtchObject> &result) {
+ if (value == NULL) {
+ return ETCH_EINVAL;
+ } else if (!value->isType(mType)) {
+ return ETCH_EINVAL;
+ }
+
+ capu::SmartPointer<EtchObject> tmp;
+ if (value->get(mField, &tmp) != ETCH_OK)
+ return ETCH_ERROR;
+
+ EtchString str = *((EtchString*) tmp.get());
+ result = new EtchRuntimeException(str, ETCH_ERROR);
+ return ETCH_OK;
+}
+
+status_t EtchRuntimeExceptionSerializer::exportValue(EtchValueFactory* vf, capu::SmartPointer<EtchObject> value, EtchStructValue *&result) {
+ if ((value.get() == NULL) || (vf == NULL))
+ return ETCH_EINVAL;
+ if (value->getObjectType() != EtchRuntimeException::TYPE())
+ return ETCH_EINVAL;
+ result = new EtchStructValue(mType, vf);
+ capu::SmartPointer<EtchString> str = new EtchString(((EtchRuntimeException*) value.get())->getErrorMessage());
+
+ if (result->put(mField, str) != ETCH_OK)
+ return ETCH_ERROR;
+
+ return ETCH_OK;
+}
+
+status_t EtchRuntimeExceptionSerializer::Init(EtchType* type, EtchClass2TypeMap* class2type) {
+
+ status_t result;
+ EtchField field_ptr;
+ result = type->getField(FIELD_NAME, &field_ptr);
+ if (result != ETCH_OK)
+ return result;
+ class2type->put(EtchRuntimeException::TYPE(), type);
+ type->setComponentType(EtchRuntimeException::TYPE());
+ //set the import export helper
+ type->setImportExportHelper(new EtchRuntimeExceptionSerializer(type, &field_ptr));
+ capu::SmartPointer<EtchValidator> tmp;
+ result = EtchValidatorString::Get(0, tmp);
+ if (result != ETCH_OK)
+ return result;
+ result = type->putValidator(field_ptr, tmp);
+ if (result != ETCH_OK)
+ return result;
+ type->lock();
+ return ETCH_OK;
+}
\ 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=1345104&r1=1345103&r2=1345104&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 12:18:02 2012
@@ -69,6 +69,7 @@ add_executable (etch-cpp-test
serialization/EtchClass2TypeMapTest.cpp
serialization/EtchListSerializerTest.cpp
serialization/EtchValidatorRuntimeExceptionTest.cpp
+ serialization/EtchRuntimeExceptionSerializerTest.cpp
util/EtchUtilTest.cpp
${GTEST}/src/gtest-all.cc
${GMOCK}/src/gmock-all.cc
Added: incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchRuntimeExceptionSerializerTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchRuntimeExceptionSerializerTest.cpp?rev=1345104&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchRuntimeExceptionSerializerTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchRuntimeExceptionSerializerTest.cpp Fri Jun 1 12:18:02 2012
@@ -0,0 +1,166 @@
+/* $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 "gmock/gmock.h"
+#include "serialization/EtchValueFactory.h"
+#include "serialization/EtchRuntimeExceptionSerializer.h"
+#include "common/EtchNativeArray.h"
+
+class MockValueFactory2 : public virtual EtchValueFactory {
+public:
+
+ ~MockValueFactory2() {
+
+ }
+ MOCK_METHOD2(getType, status_t(capu::uint32_t id, EtchType*& result));
+
+ MOCK_METHOD2(getType, status_t(EtchString& name, EtchType*& result));
+
+ MOCK_METHOD1(addType, status_t(EtchType* type));
+
+ MOCK_METHOD0(lockDynamicTypes, status_t());
+
+ MOCK_METHOD0(unlockDynamicTypes, status_t());
+
+ MOCK_METHOD2(getMessageId, status_t(EtchMessage* msg, capu::int64_t &result));
+
+ MOCK_METHOD2(setMessageId, status_t(EtchMessage* msg, capu::int64_t msgid));
+
+ MOCK_METHOD0(get_mf__messageId, EtchField());
+
+ MOCK_METHOD2(getInReplyTo, status_t(EtchMessage* msg, capu::int64_t &result));
+
+ MOCK_METHOD2(setInReplyTo, status_t(EtchMessage* msg, capu::int64_t msgid));
+
+ MOCK_METHOD0(get_mf__inReplyTo, EtchField());
+
+ MOCK_METHOD2(importCustomValue, status_t(EtchStructValue* _struct, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(exportCustomValue, status_t(capu::SmartPointer<EtchObject> value, EtchStructValue*& result));
+
+ MOCK_METHOD0(get_mt__exception, EtchType*());
+
+ MOCK_METHOD2(getCustomStructType, status_t(capu::int32_t c, EtchType *& type));
+
+ EtchLevel getLevel() {
+ return LEVEL_FULL;
+ }
+
+ MOCK_METHOD1(setLevel, EtchLevel(EtchLevel level));
+
+};
+
+TEST(EtchRuntimeExceptionSerializationTest, initTest) {
+ EtchClass2TypeMap* c2type = new EtchClass2TypeMap();
+ EtchString typeName("type1");
+ EtchType* type = new EtchType(10, typeName);
+ EtchType* result;
+ EtchRuntimeExceptionSerializer::Init(type, c2type);
+ c2type->get(EtchRuntimeException::TYPE(), &result);
+
+ //check the added type to class to type matching
+ EXPECT_TRUE(type == result);
+ //check the initialized component type
+ EXPECT_TRUE(type->getComponentType() == EtchRuntimeException::TYPE());
+
+ //to check the initialized validator
+ capu::SmartPointer<EtchValidator> validator;
+ EtchField field;
+ typeName = "msg";
+ type->getField(typeName, &field);
+ //check validator
+ type->getValidator(field, validator);
+ capu::SmartPointer<EtchValidator> val;
+ EtchValidatorString::Get(0, val);
+ EXPECT_TRUE(validator == val);
+ delete type;
+ delete c2type;
+}
+
+TEST(EtchRuntimeExceptionSerializationTest, exportTest) {
+ EtchClass2TypeMap* c2type = new EtchClass2TypeMap();
+ EtchString typeName("type1");
+ EtchString message("message");
+ EtchValueFactory* factory = new MockValueFactory2();
+ EtchType* type = new EtchType(10, typeName);
+ capu::SmartPointer<EtchObject> object = new EtchRuntimeException(message, ETCH_ERROR);
+ capu::SmartPointer<EtchObject> object2 = new EtchInt32();
+ capu::SmartPointer<EtchObject> object3;
+ EtchStructValue* result;
+ //initialize the serializer
+ EtchRuntimeExceptionSerializer::Init(type, c2type);
+ EtchImportExportHelper* test = type->getImportExportHelper();
+ //check with invalid values
+ EXPECT_TRUE(test->exportValue(NULL, NULL, result) == ETCH_EINVAL);
+ EXPECT_TRUE(test->exportValue(NULL, object, result) == ETCH_EINVAL);
+ EXPECT_TRUE(test->exportValue(factory, NULL, result) == ETCH_EINVAL);
+ EXPECT_TRUE(test->exportValue(factory, object2, result) == ETCH_EINVAL);
+ //export values
+ EXPECT_TRUE(test->exportValue(factory, object, result) == ETCH_OK);
+
+ //check it has been correctly serialized or not
+ EtchString str("msg");
+ EtchField field;
+
+ //get the fields
+ EXPECT_TRUE(type->getField(str, &field) == ETCH_OK);
+ //use the field to get the serialized value
+ EXPECT_TRUE(result->get(field, &object3) == ETCH_OK);
+ capu::SmartPointer<EtchString> serialized_exp = capu::smartpointer_cast<EtchString > (object3);
+ //check the assigned type
+ EXPECT_TRUE(type->getComponentType() == EtchRuntimeException::TYPE());
+ //check the serialized value
+ EXPECT_TRUE(serialized_exp->equals(&message));
+
+ delete c2type;
+ delete factory;
+ delete type;
+ delete result;
+}
+
+TEST(EtchRuntimeExceptionSerializationTest, importTest) {
+ EtchClass2TypeMap* c2type = new EtchClass2TypeMap();
+ EtchString typeName("type1");
+ EtchString message("message");
+ EtchValueFactory* factory = new MockValueFactory2();
+ EtchType* type = new EtchType(10, typeName);
+ capu::SmartPointer<EtchObject> object = new EtchRuntimeException(message, ETCH_ERROR);
+ EtchStructValue* structValue;
+ //initialize the serializer
+ EtchRuntimeExceptionSerializer::Init(type, c2type);
+ //get the serializer
+ EtchImportExportHelper* test = type->getImportExportHelper();
+ //export values
+ EXPECT_TRUE(test->exportValue(factory, object, structValue) == ETCH_OK);
+ //UPPER PART IS USED FOR GENERATING EXAMPLE INPUT VALUE FOR IMPORT
+ capu::SmartPointer<EtchObject> result;
+ //IMPORT TEST
+ EXPECT_TRUE(test->importValue(NULL, result) == ETCH_EINVAL);
+ EXPECT_TRUE(test->importValue(structValue, result) == ETCH_OK);
+
+ capu::SmartPointer<EtchRuntimeException> imported_exp = capu::smartpointer_cast<EtchRuntimeException > (result);
+ //check the imported value
+ EXPECT_TRUE(imported_exp->getErrorMessage().equals(&message));
+ delete c2type;
+ delete factory;
+ delete type;
+ delete structValue;
+}