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

svn commit: r1345128 - in /incubator/etch/trunk/binding-cpp/runtime: include/transport/EtchMessage.h src/main/CMakeLists.txt src/main/transport/EtchMessage.cpp src/test/CMakeLists.txt src/test/transport/EtchMessageTest.cpp

Author: veithm
Date: Fri Jun  1 12:38:24 2012
New Revision: 1345128

URL: http://svn.apache.org/viewvc?rev=1345128&view=rev
Log:
ETCH-182 EtchMessage has been implemented

Change-Id: I0949369a36b29eab63dd6f35a849138fd95aa750

Added:
    incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchMessage.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchMessageTest.cpp
Modified:
    incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchMessage.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/transport/EtchMessage.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchMessage.h?rev=1345128&r1=1345127&r2=1345128&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchMessage.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchMessage.h Fri Jun  1 12:38:24 2012
@@ -17,14 +17,88 @@
  */
 
 
-#ifndef ETCHMESSAGE_H
-#define ETCHMESSAGE_H
+#ifndef __ETCHMESSAGE_H__
+#define __ETCHMESSAGE_H__
 
-class EtchMessage {
+#include "capu/util/SmartPointer.h"
+#include "serialization/EtchType.h"
+#include "serialization/EtchValueFactory.h"
+#include "serialization/EtchStructValue.h"
 
+class EtchMessage : public EtchStructValue {
 public:
 
+  /**
+   * Constructor
+   */
+  EtchMessage(EtchType *type, EtchValueFactory* vf);
+
+  /**
+   * Constructor
+   */
+  EtchMessage(EtchType *type, EtchValueFactory* vf, capu::uint32_t length);
+
+  /**
+   * Destructor
+   */
+  virtual ~EtchMessage();
+
+  /**
+   * @return the value factory.
+   */
+  EtchValueFactory* getValueFactory();
+
+  /**
+   * Creates a message which is a reply to the current message.
+   * The current message's value factory is copied to the new
+   * message. The message-id of the current message (if any) is
+   * copied into the in-reply-to field of the new message.
+   * @param rType the type of the reply.
+   * @param a reply message.
+   * @return ETCH_OK if reply is created
+   *         ETCH_EINVAL if rType is null
+   *         ETCH_ERROR otherwise
+   */
+  status_t createReplyMessage(EtchType* rType, capu::SmartPointer<EtchMessage> &message);
+
+  /**
+   * 
+   * @param a reply message.
+   * @return ETCH_OK if reply is created
+   *         ETCH_ERROR otherwise
+   */
+  status_t createReplyMessage(capu::SmartPointer<EtchMessage> &message);
+
+  /**
+   * @param the connection specific unique identifier of this
+   * message, or null if there was no such identifier.
+   */
+  status_t getMessageId(capu::int64_t &result);
+
+  /**
+   * Sets the message-id field of this message.
+   * @param msgid the connection specific unique identifier of this
+   * message. Null if the message has not been sent yet. NOTE: the
+   * send process overwrites any value the user might set here. So
+   * don't bother trying to set it.
+   */
+  void setMessageId(capu::int64_t msgid);
+
+  /**
+   * @param the message-id of the message that this is a response to.
+   * Null if this is an original message or if the original message did
+   * not have a message-id.
+   */
+  status_t getInReplyToMessageId(capu::int64_t &result);
+
+  /**
+   * Sets the in-reply-to field of this message.
+   * @param msgid the message-id of the message that this is a response to.
+   */
+  void setInReplyToMessageId(capu::int64_t msgid);
 
+private:
+  EtchValueFactory* mVf;
 };
 
 #endif /* ETCHMESSAGE_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=1345128&r1=1345127&r2=1345128&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:38:24 2012
@@ -66,6 +66,7 @@ SET(MAIN_INCLUDES
     ${PROJECT_SOURCE_DIR}/include/transport/EtchTcpListener.h
     ${PROJECT_SOURCE_DIR}/include/transport/EtchTcpOption.h
     ${PROJECT_SOURCE_DIR}/include/transport/EtchPacketizer.h
+    ${PROJECT_SOURCE_DIR}/include/transport/EtchMessage.h
     ${PROJECT_SOURCE_DIR}/include/serialization/EtchValidator.h
     ${PROJECT_SOURCE_DIR}/include/serialization/EtchTypeValidator.h
     ${PROJECT_SOURCE_DIR}/include/serialization/EtchTypeCodes.h
@@ -123,6 +124,7 @@ SET(MAIN_SOURCES
     transport/EtchTcpListener.cpp
     transport/EtchTcpOption.cpp
     transport/EtchPacketizer.cpp
+    transport/EtchMessage.cpp
     serialization/EtchTypeValidator.cpp
     serialization/EtchValidatorBoolean.cpp
     serialization/EtchValidatorByte.cpp

Added: incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchMessage.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchMessage.cpp?rev=1345128&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchMessage.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchMessage.cpp Fri Jun  1 12:38:24 2012
@@ -0,0 +1,76 @@
+/* $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 "transport/EtchMessage.h"
+
+EtchMessage::EtchMessage(EtchType* type, EtchValueFactory* vf)
+: EtchStructValue(type, vf), mVf(vf) {
+
+}
+
+EtchMessage::EtchMessage(EtchType* type, EtchValueFactory* vf, capu::uint32_t length)
+: EtchStructValue(type, vf, length), mVf(vf) {
+
+}
+
+EtchMessage::~EtchMessage() {
+
+}
+
+EtchValueFactory* EtchMessage::getValueFactory() {
+  return mVf;
+}
+
+status_t EtchMessage::createReplyMessage(capu::SmartPointer<EtchMessage> &message) {
+  message = new EtchMessage(getType()->getResult(), mVf);
+  capu::int64_t tmp;
+  getMessageId(tmp);
+  message->setInReplyToMessageId(tmp);
+  if (message.get() != NULL)
+    return ETCH_OK;
+  else
+    return ETCH_ERROR;
+}
+
+status_t EtchMessage::createReplyMessage(EtchType* rType, capu::SmartPointer<EtchMessage> &message) {
+  message = new EtchMessage(rType, mVf);
+  capu::int64_t tmp;
+  getMessageId(tmp);
+  message->setInReplyToMessageId(tmp);
+  if (message.get() != NULL)
+    return ETCH_OK;
+  else
+    return ETCH_ERROR;
+}
+
+status_t EtchMessage::getMessageId(capu::int64_t &result) {
+  return mVf->getMessageId(this, result);
+}
+
+void EtchMessage::setMessageId(capu::int64_t msgid) {
+  mVf->setMessageId(this, msgid);
+}
+
+status_t EtchMessage::getInReplyToMessageId(capu::int64_t &result) {
+  return mVf->getInReplyTo(this, result);
+}
+
+void EtchMessage::setInReplyToMessageId(capu::int64_t msgid) {
+  mVf->setInReplyTo(this, msgid);
+}
+

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=1345128&r1=1345127&r2=1345128&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:38:24 2012
@@ -52,6 +52,7 @@ add_executable (etch-cpp-test
     transport/EtchTcpConnectionTest.cpp
     transport/EtchTcpListenerTest.cpp
     transport/EtchPacketizerTest.cpp
+    transport/EtchMessageTest.cpp
     serialization/EtchValidatorBooleanTest.cpp
     serialization/EtchValidatorByteTest.cpp
     serialization/EtchValidatorIntTest.cpp

Added: incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchMessageTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchMessageTest.cpp?rev=1345128&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchMessageTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchMessageTest.cpp Fri Jun  1 12:38:24 2012
@@ -0,0 +1,278 @@
+/* $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 "transport/EtchMessage.h"
+#include "serialization/EtchValidatorBoolean.h"
+
+class MockValueFactory7 : public virtual EtchValueFactory {
+public:
+
+  ~MockValueFactory7() {
+
+  }
+  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());
+
+  status_t getMessageId(EtchMessage* msg, capu::int64_t &result) {
+    result = 0;
+    return ETCH_OK;
+  }
+
+  MOCK_METHOD0(get_mf__messageId, EtchField());
+
+  status_t getInReplyTo(EtchMessage* msg, capu::int64_t &result) {
+    result = 0;
+    return ETCH_OK;
+  }
+  MOCK_METHOD2(setMessageId, status_t(EtchMessage* msg, capu::int64_t msgid));
+
+  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));
+private:
+  capu::int64_t tmp;
+};
+
+TEST(EtchMessageTest, createTest) {
+  EtchType *type = new EtchType("test");
+  EtchValueFactory *factory = new MockValueFactory7();
+  EtchMessage *message = new EtchMessage(type, factory);
+  EXPECT_TRUE(message != NULL);
+  delete message;
+  delete type;
+  delete factory;
+}
+
+TEST(EtchMessageTest, getMessageIdTests) {
+  EtchType *type = new EtchType("test");
+  EtchValueFactory *factory = new MockValueFactory7();
+  EtchMessage *message = new EtchMessage(type, factory);
+  EXPECT_TRUE(message != NULL);
+  capu::int64_t tmp;
+  EXPECT_TRUE(message->getInReplyToMessageId(tmp) == ETCH_OK);
+  EXPECT_TRUE(message->getMessageId(tmp) == ETCH_OK);
+  delete message;
+  delete type;
+  delete factory;
+}
+
+TEST(EtchMessage, getTypeTest) {
+  EtchField field1("type1");
+  EtchField field2("type2");
+
+  //CreateType
+  EtchType* comp = new EtchType(90, "comp");
+
+  //fill validators
+  capu::SmartPointer<EtchValidator> val1;
+  EtchValidatorBoolean::Get(0, val1);
+  capu::SmartPointer<EtchValidator> val2;
+  EtchValidatorBoolean::Get(0, val2);
+  comp->putValidator(field1, val1);
+  comp->putValidator(field2, val2);
+
+  //Create Value Factory
+  EtchValueFactory* factory = new MockValueFactory7();
+  
+  //create message
+  EtchMessage *sv = new EtchMessage(comp, factory);
+  EXPECT_TRUE(sv->getType()->equals(comp));
+  delete sv;
+  delete factory;
+  delete comp;
+}
+
+TEST(EtchMessageTest, isType) {
+  //Type 1
+  EtchField field1("type1");
+  EtchField field2("type2");
+
+  //CreateType
+  EtchType* comp = new EtchType(90, "comp");
+
+  capu::SmartPointer<EtchValidator> val1;
+  EtchValidatorBoolean::Get(0, val1);
+  capu::SmartPointer<EtchValidator> val2;
+  EtchValidatorBoolean::Get(0, val2);
+  comp->putValidator(field1, val1);
+  comp->putValidator(field2, val2);
+  //Create Value Factory
+  EtchValueFactory* factory = new MockValueFactory7();
+  //type 2
+  EtchString typeName2("comp2");
+  EtchType* comp2 = new EtchType(91, typeName2);
+
+  EtchMessage *sv = new EtchMessage(comp, factory);
+  EXPECT_TRUE(sv->isType(comp));
+  EXPECT_FALSE(sv->isType(comp2));
+  delete sv;
+  delete factory;
+  delete comp;
+  delete comp2;
+}
+
+TEST(EtchMessageTest, putTest) {
+  EtchString fieldtype1("type1");
+  EtchString fieldtype2("type2");
+  EtchString typeName("comp");
+
+  EtchField field1(fieldtype1);
+  EtchField field2(fieldtype2);
+  //Create Value Factory
+  EtchValueFactory* factory = new MockValueFactory7();
+  //CreateType
+  EtchType* comp = new EtchType(90, typeName);
+
+  capu::SmartPointer<EtchValidator> val1;
+  EtchValidatorBoolean::Get(0, val1);
+  capu::SmartPointer<EtchValidator> val2;
+  EtchValidatorBoolean::Get(0, val2);
+  comp->putValidator(field1, val1);
+  comp->putValidator(field2, val2);
+
+  EtchMessage *sv = new EtchMessage(comp, factory);
+
+  capu::SmartPointer<EtchObject> object = new EtchBool(true);
+  capu::SmartPointer<EtchObject> object2 = new EtchBool(false);
+  capu::SmartPointer<EtchObject> object3 = NULL;
+  capu::SmartPointer<EtchObject> object4 = NULL;
+
+  //check the empty struct value
+  EXPECT_TRUE(sv->count() == 0);
+  //add new element
+  EXPECT_TRUE(sv->put(field1, object) == ETCH_OK);
+  EXPECT_TRUE(sv->count() == 1);
+  //add another element
+  EXPECT_TRUE(sv->put(field2, object2) == ETCH_OK);
+  EXPECT_TRUE(sv->count() == 2);
+  //add a null element and expect a remove operation
+  EXPECT_TRUE(sv->put(field1, object3, &object4) == ETCH_OK);
+  EXPECT_TRUE(sv->count() == 1);
+
+  delete sv;
+  delete factory;
+  delete comp;
+}
+
+TEST(EtchMessageTest, getTest) {
+  EtchString fieldtype1("type1");
+  EtchString fieldtype2("type2");
+  EtchField field1(fieldtype1);
+  EtchField field2(fieldtype2);
+  EtchString typeName("comp");
+  EtchType* comp = new EtchType(90, typeName);
+
+  capu::SmartPointer<EtchValidator> val1;
+  EtchValidatorBoolean::Get(0, val1);
+  capu::SmartPointer<EtchValidator> val2;
+  EtchValidatorBoolean::Get(0, val2);
+  comp->putValidator(field1, val1);
+  comp->putValidator(field2, val2);
+
+  //Create Value Factory
+  EtchValueFactory* factory = new MockValueFactory7();
+  //create struct value
+  EtchMessage *sv = new EtchMessage(comp, factory);
+  EXPECT_TRUE(0 == sv->count());
+
+  //add element
+  capu::SmartPointer<EtchObject> object = new EtchBool(true);
+  EXPECT_TRUE(sv->put(field1, object) == ETCH_OK);
+  EXPECT_TRUE(sv->count() == 1);
+
+  //add another element
+  capu::SmartPointer<EtchObject> object2 = new EtchBool(false);
+  EXPECT_TRUE(sv->put(field1, object2, &object) == ETCH_OK);
+  EXPECT_TRUE(sv->count() == 1);
+  //get element
+  EXPECT_TRUE(sv->get(field1, &object) == ETCH_OK);
+  EXPECT_TRUE(((EtchBool*) object.get())->get() == false);
+
+  delete sv;
+  delete factory;
+  delete comp;
+}
+
+TEST(EtchMessageTest, removeTest) {
+  EtchString fieldtype1("type1");
+  EtchString typeName("comp");
+  EtchField field1(fieldtype1);
+  EtchValueFactory* factory = new MockValueFactory7();
+
+  EtchType* comp = new EtchType(90, typeName);
+
+  capu::SmartPointer<EtchValidator> val1;
+  EtchValidatorBoolean::Get(0, val1);
+  comp->putValidator(field1, val1);
+
+  EtchMessage *sv = new EtchMessage(comp, factory);
+  capu::SmartPointer<EtchObject> object;
+  capu::SmartPointer<EtchObject> object2;
+  //check the empty struct value
+  EXPECT_TRUE(sv->count() == 0);
+  EXPECT_TRUE(sv->get(field1, &object) == ETCH_ENOT_EXIST);
+
+  //try to delete non existing element
+  EXPECT_TRUE(sv->remove(field1, &object) == ETCH_ERANGE);
+  EXPECT_TRUE(sv->count() == 0);
+  EXPECT_TRUE(sv->get(field1, &object) == ETCH_ENOT_EXIST);
+
+  //add element
+  EtchObject* boolean = new EtchBool(true);
+  sv->put(field1, boolean);
+  EXPECT_TRUE(sv->count() == 1);
+  EXPECT_TRUE(sv->get(field1, &object) == ETCH_OK);
+  capu::SmartPointer<EtchBool> ptr = capu::smartpointer_cast<EtchBool> (object);
+  EXPECT_TRUE((ptr->get()) == true);
+
+  //delete element
+  EXPECT_TRUE(sv->remove(field1, &object2) == ETCH_OK);
+  EXPECT_TRUE(sv->count() == 0);
+  EXPECT_TRUE(sv->get(field1, &object2) == ETCH_ENOT_EXIST);
+  //try to delete non existing element
+  EXPECT_TRUE(sv->remove(field1, &object2) == ETCH_ERANGE);
+  EXPECT_TRUE(sv->count() == 0);
+  EXPECT_TRUE(sv->get(field1, &object2) == ETCH_ENOT_EXIST);
+  delete sv;
+  delete comp;
+  delete factory;
+}
+