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:35:57 UTC
svn commit: r1345121 - in /incubator/etch/trunk/binding-cpp/runtime:
include/common/ include/serialization/ src/main/ src/main/common/
src/main/serialization/ src/test/ src/test/common/ src/test/serialization/
Author: veithm
Date: Fri Jun 1 12:35:56 2012
New Revision: 1345121
URL: http://svn.apache.org/viewvc?rev=1345121&view=rev
Log:
ETCH-184 Implementation of EtchDateSerializer
EtchDateSerializer has been implemented
Change-Id: I1d786ee32af263c4f4c4e8bc4161c79ce7a20f3b
Added:
incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchDateSerializer.h
incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchDateSerializer.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchDateSerializerTest.cpp
Modified:
incubator/etch/trunk/binding-cpp/runtime/include/common/EtchDate.h
incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchDate.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt
incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchDateTest.cpp
Modified: incubator/etch/trunk/binding-cpp/runtime/include/common/EtchDate.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/common/EtchDate.h?rev=1345121&r1=1345120&r2=1345121&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/common/EtchDate.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/common/EtchDate.h Fri Jun 1 12:35:56 2012
@@ -20,7 +20,6 @@
#define ETCHDATE_H
#include "common/EtchObject.h"
#include "common/EtchObjectType.h"
-#include <time.h>
class EtchDate : public EtchObject {
public:
@@ -30,9 +29,17 @@ public:
*/
static const EtchObjectType* TYPE();
- //Constructor
+ /**
+ * Constructor
+ */
EtchDate();
+ /**
+ * Constructor
+ * @param value the time
+ */
+ EtchDate(capu::time_t value);
+
//Destructor
virtual ~EtchDate();
Added: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchDateSerializer.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchDateSerializer.h?rev=1345121&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchDateSerializer.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchDateSerializer.h Fri Jun 1 12:35:56 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.
+ */
+
+#ifndef __ETCHDATESERIALIZER_H__
+#define __ETCHDATESERIALIZER_H__
+
+#include "common/EtchDate.h"
+#include "serialization/EtchImportExportHelper.h"
+#include "serialization/EtchStructValue.h"
+#include "serialization/EtchField.h"
+#include "serialization/EtchType.h"
+#include "serialization/EtchClass2TypeMap.h"
+#include "serialization/EtchValidatorLong.h"
+
+class EtchDateSerializer : public EtchImportExportHelper {
+public:
+
+ /**
+ * Constructor
+ */
+ EtchDateSerializer(EtchType* type, EtchField* field);
+
+ /**
+ * Destructor
+ */
+ virtual ~EtchDateSerializer();
+
+ /**
+ * @see EtchImportExportHelper
+ */
+ virtual status_t exportValue(EtchValueFactory* vf, capu::SmartPointer<EtchObject> value, EtchStructValue*& result);
+
+ /**
+ * @see EtchImportExportHelper
+ */
+ virtual status_t importValue(EtchStructValue* _struct, capu::SmartPointer<EtchObject> &result);
+
+
+ /**
+ * Defines custom fields in the value factory so that the importer can find them.
+ * @param type
+ * @param collection
+ */
+ static status_t Init(EtchType* type, EtchClass2TypeMap* class2type);
+
+private:
+
+ EtchField mField;
+ EtchType* mType;
+ const static EtchString FIELD_NAME;
+};
+
+#endif /* ETCHDATESERIALIZER_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=1345121&r1=1345120&r2=1345121&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:35:56 2012
@@ -93,6 +93,7 @@ SET(MAIN_INCLUDES
${PROJECT_SOURCE_DIR}/include/serialization/EtchAuthenticationExceptionSerializer.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchHashTableSerializer.h
${PROJECT_SOURCE_DIR}/include/serialization/EtchSetSerializer.h
+ ${PROJECT_SOURCE_DIR}/include/serialization/EtchDateSerializer.h
${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
)
@@ -146,6 +147,7 @@ SET(MAIN_SOURCES
serialization/EtchAuthenticationExceptionSerializer.cpp
serialization/EtchHashTableSerializer.cpp
serialization/EtchSetSerializer.cpp
+ serialization/EtchDateSerializer.cpp
util/EtchUtil.cpp
)
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchDate.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchDate.cpp?rev=1345121&r1=1345120&r2=1345121&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchDate.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/common/EtchDate.cpp Fri Jun 1 12:35:56 2012
@@ -27,6 +27,10 @@ EtchDate::EtchDate()
: EtchObject(EtchDate::TYPE()), mValue(0) {
}
+EtchDate::EtchDate(capu::time_t value)
+: EtchObject(EtchDate::TYPE()), mValue(value) {
+}
+
EtchDate::~EtchDate() {
}
Added: incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchDateSerializer.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchDateSerializer.cpp?rev=1345121&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchDateSerializer.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchDateSerializer.cpp Fri Jun 1 12:35:56 2012
@@ -0,0 +1,81 @@
+/* $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/EtchDateSerializer.h"
+
+const EtchString EtchDateSerializer::FIELD_NAME("dateTime");
+
+EtchDateSerializer::EtchDateSerializer(EtchType* type, EtchField* field)
+: mField(*field), mType(type) {
+
+}
+
+EtchDateSerializer::~EtchDateSerializer() {
+
+}
+
+status_t EtchDateSerializer::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;
+
+ EtchLong date = *((EtchLong*) tmp.get());
+ result = new EtchDate((capu::time_t)date.get());
+ return ETCH_OK;
+}
+
+status_t EtchDateSerializer::exportValue(EtchValueFactory* vf, capu::SmartPointer<EtchObject> value, EtchStructValue*& result) {
+ if ((value.get() == NULL) || (vf == NULL))
+ return ETCH_EINVAL;
+ if (value->getObjectType() != EtchDate::TYPE())
+ return ETCH_EINVAL;
+ result = new EtchStructValue(mType, vf);
+ EtchLong *date = new EtchLong(((EtchDate*) value.get())->get());
+ if (result->put(mField, date) != ETCH_OK)
+ return ETCH_ERROR;
+
+ return ETCH_OK;
+}
+
+status_t EtchDateSerializer::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(EtchDate::TYPE(), type);
+ type->setComponentType(EtchDate::TYPE());
+
+ //set the import export helper
+ type->setImportExportHelper(new EtchDateSerializer(type, &field_ptr));
+ capu::SmartPointer<EtchValidator> val;
+ result = EtchValidatorLong::Get(0, val);
+ if (result != ETCH_OK)
+ return result;
+ result = type->putValidator(field_ptr, val);
+ if (result != ETCH_OK)
+ return result;
+ type->lock();
+ return ETCH_OK;
+}
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=1345121&r1=1345120&r2=1345121&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:35:56 2012
@@ -74,6 +74,7 @@ add_executable (etch-cpp-test
serialization/EtchAuthenticationExceptionSerializerTest.cpp
serialization/EtchHashTableSerializerTest.cpp
serialization/EtchSetSerializerTest.cpp
+ serialization/EtchDateSerializerTest.cpp
util/EtchUtilTest.cpp
${GTEST}/src/gtest-all.cc
${GMOCK}/src/gmock-all.cc
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchDateTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchDateTest.cpp?rev=1345121&r1=1345120&r2=1345121&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchDateTest.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/common/EtchDateTest.cpp Fri Jun 1 12:35:56 2012
@@ -34,8 +34,7 @@ TEST(EtchDateTest, set) {
TEST(EtchDateTest, get) {
EtchDate* i1 = new EtchDate();
- time_t _time;
- time(&_time);
+ time_t _time = 1234567;
i1->set(_time);
EXPECT_TRUE(i1->get() == _time);
delete i1;
Added: incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchDateSerializerTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchDateSerializerTest.cpp?rev=1345121&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchDateSerializerTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchDateSerializerTest.cpp Fri Jun 1 12:35:56 2012
@@ -0,0 +1,168 @@
+/* $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/EtchDateSerializer.h"
+#include "common/EtchNativeArray.h"
+
+class MockValueFactory6 : public virtual EtchValueFactory {
+public:
+
+ ~MockValueFactory6() {
+
+ }
+ 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(EtchDateSerializationTest, initTest) {
+ EtchClass2TypeMap* c2type = new EtchClass2TypeMap();
+ EtchString typeName("type1");
+ EtchType* type = new EtchType(10, typeName);
+ EtchType* result;
+ EXPECT_TRUE(EtchDateSerializer::Init(type, c2type) == ETCH_OK);
+ c2type->get(EtchDate::TYPE(), &result);
+
+ //check the added type to class to type matching
+ EXPECT_TRUE(type == result);
+ //check the initialized component type
+ EXPECT_TRUE(type->getComponentType() == EtchDate::TYPE());
+
+ //to check the initialized validator
+ capu::SmartPointer<EtchValidator> validator;
+ EtchField field;
+ typeName = "dateTime";
+ type->getField(typeName, &field);
+ //check validator
+ type->getValidator(field, validator);
+ capu::SmartPointer<EtchValidator> val;
+ EtchValidatorLong::Get(0, val);
+ EXPECT_TRUE(validator == val);
+ delete type;
+ delete c2type;
+}
+
+TEST(EtchDateSerializationTest, exportTest) {
+ EtchClass2TypeMap* c2type = new EtchClass2TypeMap();
+ EtchString typeName("type1");
+ EtchValueFactory* factory = new MockValueFactory6();
+ EtchType* type = new EtchType(10, typeName);
+ capu::SmartPointer<EtchObject> object = new EtchDate();
+ capu::SmartPointer<EtchObject> object2 = new EtchInt32();
+ capu::SmartPointer<EtchObject> object3;
+ EtchStructValue* result;
+ //initialize the serializer
+ EXPECT_TRUE(EtchDateSerializer::Init(type, c2type) == ETCH_OK);
+ EtchImportExportHelper* test = type->getImportExportHelper();
+ //some test values
+ (capu::smartpointer_cast<EtchDate > (object))->set(5);
+
+ //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("dateTime");
+ 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<EtchDate> serialized_exp = capu::smartpointer_cast<EtchDate > (object3);
+ //check the assigned type
+ EXPECT_TRUE(type->getComponentType() == EtchDate::TYPE());
+ //check the serialized value
+ EXPECT_TRUE(serialized_exp->get() == 5);
+
+ delete c2type;
+ delete factory;
+ delete type;
+ delete result;
+}
+
+TEST(EtchDateSerializationTest, importTest) {
+ EtchClass2TypeMap* c2type = new EtchClass2TypeMap();
+ EtchString typeName("type1");
+ EtchValueFactory* factory = new MockValueFactory6();
+ EtchType* type = new EtchType(10, typeName);
+ capu::SmartPointer<EtchObject> object = new EtchDate();
+ EtchStructValue* structValue;
+ //initialize the serializer
+ EXPECT_TRUE(EtchDateSerializer::Init(type, c2type) == ETCH_OK);
+ //get the serializer
+ EtchImportExportHelper* test = type->getImportExportHelper();
+ //some test values
+ (capu::smartpointer_cast<EtchDate > (object))->set(5);
+ //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<EtchDate> imported_exp = capu::smartpointer_cast<EtchDate > (result);
+ //check the imported value
+ EXPECT_TRUE(imported_exp->get() == 5);
+ delete c2type;
+ delete factory;
+ delete type;
+ delete structValue;
+}