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/08/02 17:18:59 UTC
svn commit: r1368523 - in /incubator/etch/trunk/binding-cpp/runtime:
include/transport/ src/main/transport/ src/test/transport/
Author: veithm
Date: Thu Aug 2 15:18:59 2012
New Revision: 1368523
URL: http://svn.apache.org/viewvc?rev=1368523&view=rev
Log:
ETCH-147 Added some notifications to EtchConnection
Added Session Up and Session Down notifications
Using EtchMonitor in WaitUp and WaitDown now
Change-Id: I8a9a91b2b5d8d7ebe4ee2425a14cd2321c34b94b
Modified:
incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchConnection.h
incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpConnection.h
incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpListener.h
incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchMessagizerTest.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchTcpConnectionTest.cpp
incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchTcpListenerTest.cpp
Modified: incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchConnection.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchConnection.h?rev=1368523&r1=1368522&r2=1368523&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchConnection.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchConnection.h Thu Aug 2 15:18:59 2012
@@ -18,19 +18,28 @@
#ifndef __ETCHCONNECTION_H__
#define __ETCHCONNECTION_H__
-#include "transport/EtchTransport.h"
-#include "common/EtchString.h"
-#include "common/EtchObject.h"
+
+#include "capu/os/Mutex.h"
#include "capu/os/Thread.h"
#include "capu/util/SmartPointer.h"
#include "common/EtchError.h"
+#include "common/EtchException.h"
#include "common/EtchInt32.h"
-#include "capu/os/Mutex.h"
+#include "common/EtchObject.h"
+#include "common/EtchString.h"
+#include "support/EtchMonitor.h"
+#include "transport/EtchSession.h"
+#include "transport/EtchTransport.h"
template <class S>
class EtchConnection : public virtual EtchTransport<S> {
public:
+ /**
+ * Default Constructor
+ */
+ EtchConnection();
+
/** Source query to get the local address. */
static const EtchString LOCAL_ADDRESS;
@@ -66,7 +75,7 @@ public:
* options and opening input and output streams.
*/
virtual status_t setupSocket() = 0;
-
+
protected:
/**
@@ -86,13 +95,34 @@ protected:
*/
virtual status_t readSocket() = 0;
- capu::Thread *mThread;
+ /**
+ * Waits until the connection is up.
+ * @param maxDelay time in milliseconds to wait.
+ */
+ virtual status_t waitUp(capu::int32_t maxDelay);
- capu::bool_t mIsStarted;
+ /**
+ * Waits until the connection is down.
+ * @param maxDelay time in milliseconds to wait.
+ */
+ virtual status_t waitDown(capu::int32_t maxDelay);
- static capu::Mutex mMutex;
+ /**
+ * fire up
+ */
+ virtual status_t fireUp();
+
+ /**
+ * fire down
+ */
+ virtual status_t fireDown();
+ S *mSession;
+ capu::Thread *mThread;
+ capu::bool_t mIsStarted;
+ static capu::Mutex mMutex;
static capu::Mutex mMutexConnection;
+ EtchMonitor mStatus;
};
template <class S>
@@ -110,6 +140,44 @@ capu::Mutex EtchConnection<S>::mMutex;
template <class S>
capu::Mutex EtchConnection<S>::mMutexConnection;
+template <class S>
+EtchConnection<S>::EtchConnection()
+: mStatus(EtchString("status"), (EtchString&) EtchSession::DOWN) {
+}
+
+template <class S>
+status_t EtchConnection<S>::waitUp(capu::int32_t maxDelay) {
+ return mStatus.waitUntilEq((EtchString&) EtchSession::UP, maxDelay);
+}
+
+template <class S>
+status_t EtchConnection<S>::waitDown(capu::int32_t maxDelay) {
+ return mStatus.waitUntilEq((EtchString&) EtchSession::DOWN, maxDelay);
+}
+
+template <class S>
+status_t EtchConnection<S>::fireUp() {
+ EtchString tmp;
+ mStatus.set((EtchString &) EtchSession::UP, tmp);
+
+ if (mSession != NULL) {
+ //TODO: run this in seperate thread
+ mSession->sessionNotify(new EtchString(EtchSession::UP));
+ }
+ return ETCH_ERROR;
+}
+
+template <class S>
+status_t EtchConnection<S>::fireDown() {
+ EtchString tmp;
+ mStatus.set((EtchString &) EtchSession::DOWN, tmp);
+
+ if (mSession != NULL) {
+ //TODO: run this in seperate thread
+ return mSession->sessionNotify(new EtchString(EtchSession::DOWN));
+ }
+ return ETCH_ERROR;
+}
#endif /* ETCHCONNECTION_H */
Modified: incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpConnection.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpConnection.h?rev=1368523&r1=1368522&r2=1368523&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpConnection.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpConnection.h Thu Aug 2 15:18:59 2012
@@ -128,11 +128,6 @@ public:
void setNumAttempts(capu::uint8_t numAttempts);
private:
- /**
- * The session for the connection.
- */
- EtchSessionData* mSession;
-
//PORT
capu::uint16_t mPort;
Modified: incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpListener.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpListener.h?rev=1368523&r1=1368522&r2=1368523&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpListener.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/include/transport/EtchTcpListener.h Thu Aug 2 15:18:59 2012
@@ -100,15 +100,8 @@ protected:
virtual status_t readSocket();
private:
- /**
- * The session for the connection.
- */
- EtchSessionListener<EtchSocket>* mSession;
-
EtchServerSocket* mSocket;
-
capu::uint16_t mPort;
-
capu::uint8_t mBackLog;
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp?rev=1368523&r1=1368522&r2=1368523&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp Thu Aug 2 15:18:59 2012
@@ -163,7 +163,7 @@ status_t EtchTcpConnection::transportCon
mMutex.unlock();
mThread = new capu::Thread(this);
mThread->start();
- capu::Thread::Sleep(((EtchInt32*) value.get())->get());
+ waitUp(((EtchInt32*) value.get())->get());
//TODO: Wait handling in one of the next releases
return ETCH_OK;
}
@@ -185,7 +185,7 @@ status_t EtchTcpConnection::transportCon
mIsStarted = false;
mMutex.unlock();
close();
- capu::Thread::Sleep(((EtchInt32*) value.get())->get());
+ waitDown(((EtchInt32*) value.get())->get());
//TODO: Wait handling in one of the next releases
return ETCH_OK;
}
@@ -236,11 +236,12 @@ void EtchTcpConnection::run() {
close();
break;
}
-
+ fireUp();
if (readSocket() != ETCH_OK) {
close();
break;
}
+ fireDown();
close();
first = false;
}
Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp?rev=1368523&r1=1368522&r2=1368523&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpListener.cpp Thu Aug 2 15:18:59 2012
@@ -98,7 +98,6 @@ status_t EtchTcpListener::readSocket() {
if (s == NULL)
break;
if (mSession != NULL) {
-
mSession->sessionAccepted(s);
} else {
delete s;
@@ -129,7 +128,7 @@ status_t EtchTcpListener::transportContr
mMutex.unlock();
mThread = new capu::Thread(this);
mThread->start();
- capu::Thread::Sleep(((EtchInt32*) value.get())->get());
+ waitUp(((EtchInt32*) value.get())->get());
//TODO: Wait handling in one of the next releases
return ETCH_OK;
}
@@ -151,7 +150,7 @@ status_t EtchTcpListener::transportContr
mIsStarted = false;
mMutex.unlock();
close();
- capu::Thread::Sleep(((EtchInt32*) value.get())->get());
+ waitDown(((EtchInt32*) value.get())->get());
//TODO: Wait handling in one of the next releases
return ETCH_OK;
}
@@ -194,10 +193,13 @@ void EtchTcpListener::run() {
if (openSocket(!first) != ETCH_OK) {
break;
}
+ fireUp();
if (readSocket() != ETCH_OK) {
close();
break;
}
+
+ fireDown();
close();
first = false;
}
@@ -207,3 +209,4 @@ void EtchTcpListener::run() {
status_t EtchTcpListener::setupSocket() {
return ETCH_EUNIMPL;
}
+
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchMessagizerTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchMessagizerTest.cpp?rev=1368523&r1=1368522&r2=1368523&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchMessagizerTest.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchMessagizerTest.cpp Thu Aug 2 15:18:59 2012
@@ -1,222 +1,229 @@
-/* $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/EtchDefaultValueFactory.h"
-#include "serialization/EtchBinaryTaggedData.h"
-#include "serialization/EtchBinaryTaggedDataInput.h"
-#include "serialization/EtchValidatorShort.h"
-#include "transport/EtchMessagizer.h"
-#include "transport/EtchTcpConnection.h"
-#include "transport/EtchPacketizer.h"
-#include "transport/EtchSessionListener.h"
-#include "transport/EtchTcpListener.h"
-
-
-class MockListener11 : public virtual EtchSessionListener<EtchSocket> {
-public:
-
- //This method is called
-
- status_t sessionAccepted(EtchSocket* connection) {
- delete connection;
+/* $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/EtchDefaultValueFactory.h"
+#include "serialization/EtchBinaryTaggedData.h"
+#include "serialization/EtchBinaryTaggedDataInput.h"
+#include "serialization/EtchValidatorShort.h"
+#include "transport/EtchMessagizer.h"
+#include "transport/EtchTcpConnection.h"
+#include "transport/EtchPacketizer.h"
+#include "transport/EtchSessionListener.h"
+#include "transport/EtchTcpListener.h"
+
+
+class MockListener11 : public virtual EtchSessionListener<EtchSocket> {
+public:
+
+ //This method is called
+
+ status_t sessionAccepted(EtchSocket* connection) {
+ delete connection;
+ return ETCH_OK;
+ }
+
+ MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
+ status_t sessionNotify(capu::SmartPointer<EtchObject> event) {
return ETCH_OK;
}
-
- MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
-
- MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
-
- MOCK_METHOD1(sessionNotify, status_t(capu::SmartPointer<EtchObject> event));
-};
-
-class MockMailboxManager : public EtchSessionMessage {
-public:
-
- status_t sessionMessage(capu::SmartPointer<EtchWho> receipent, capu::SmartPointer<EtchMessage> buf) {
- EXPECT_TRUE(buf->count() == 1);
+};
+
+class MockMailboxManager : public EtchSessionMessage {
+public:
+
+ status_t sessionMessage(capu::SmartPointer<EtchWho> receipent, capu::SmartPointer<EtchMessage> buf) {
+ EXPECT_TRUE(buf->count() == 1);
+ return ETCH_OK;
+ }
+
+ MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
+ status_t sessionNotify(capu::SmartPointer<EtchObject> event) {
return ETCH_OK;
}
-
- MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
-
- MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
-
- MOCK_METHOD1(sessionNotify, status_t(capu::SmartPointer<EtchObject> event));
-};
-
-TEST(EtchMessagizerTest, constructorTest) {
- EtchTypeMap types;
- EtchClass2TypeMap class2type;
- EtchDefaultValueFactory * factory;
- EtchDefaultValueFactory::Init(&types, &class2type);
- EtchString uri("tcp://127.0.0.1:4001");
- factory = new EtchDefaultValueFactory(uri, &types, &class2type);
- //created value factory
- EtchURL u("tcp://127.0.0.1:4001");
- EtchResources r;
- EtchObject *out;
- r.put((EtchString &) EtchTransport<EtchSessionMessage>::VALUE_FACTORY, factory, out);
- EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
- EtchTransportPacket* pac = new EtchPacketizer(conn, &u);
- EtchSessionPacket* mes = new EtchMessagizer(pac, &u, &r);
- //Created stack
- delete mes;
- delete pac;
- delete conn;
- delete factory;
- types.clear();
-}
-
-TEST(EtchMessagizerTest, TransportControlTest) {
- EtchTypeMap types;
- EtchClass2TypeMap class2type;
- EtchDefaultValueFactory * factory;
- EtchDefaultValueFactory::Init(&types, &class2type);
- EtchString uri("tcp://127.0.0.1:4001");
- factory = new EtchDefaultValueFactory(uri, &types, &class2type);
- //created value factory
- EtchURL u("tcp://127.0.0.1:4001");
- EtchResources r;
- EtchObject *out;
- r.put((EtchString &) EtchTransport<EtchSessionMessage>::VALUE_FACTORY, factory, out);
- EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
- EtchPacketizer* pac = new EtchPacketizer(conn, &u);
- EtchMessagizer* mess = new EtchMessagizer(pac, &u, &r);
-
- EtchSessionListener<EtchSocket>* mSessionListener = new MockListener11();
- EtchTcpListener* listener = new EtchTcpListener(&u);
- //Start the mock listener
- listener->setSession(mSessionListener);
- listener->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP), new EtchInt32(1000));
- mess->transportControl(new EtchString(EtchPacketizer::START_AND_WAIT_UP), new EtchInt32(1000));
- //test transport commands
- mess->transportControl(new EtchString(EtchPacketizer::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
- listener->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
- listener->setSession(mSessionListener);
-
- delete mSessionListener;
- delete mess;
- delete pac;
- delete conn;
- delete listener;
- delete factory;
- types.clear();
-}
-
-TEST(EtchMessagizerTest, TransportMessageTest) {
- EtchTypeMap types;
- EtchClass2TypeMap class2type;
- EtchDefaultValueFactory * factory;
- EtchDefaultValueFactory::Init(&types, &class2type);
- EtchString uri("tcp://127.0.0.1:4001");
- factory = new EtchDefaultValueFactory(uri, &types, &class2type);
- //default value factory
- EtchURL u("tcp://127.0.0.1:4001");
- EtchResources r;
- EtchObject *out;
- //add to the resource
- r.put((EtchString &) EtchTransport<EtchSessionMessage>::VALUE_FACTORY, factory, out);
- EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
- EtchPacketizer* pac = new EtchPacketizer(conn, &u);
- EtchMessagizer* mess = new EtchMessagizer(pac, &u, &r);
-
- //creation of example message which will be serialized
- EtchType *mt_foo = NULL;
- EtchField mf_x("x");
- EtchString str("foo");
- factory->getType(str, mt_foo);
- capu::SmartPointer<EtchValidator> v;
- EtchValidatorShort::Get(0, v);
- mt_foo->putValidator(mf_x, v);
- capu::SmartPointer<EtchShort> data = new EtchShort(10000);
- capu::SmartPointer<EtchMessage> msg = new EtchMessage(mt_foo, factory);
- msg->put(mf_x, data);
-
- EXPECT_TRUE(mess->transportMessage(NULL, msg) == ETCH_EINVAL);
-
- delete mess;
- delete pac;
- delete conn;
- delete factory;
- types.clear();
-}
-
-TEST(EtchMessagizerTest, SessionDataTest) {
- //creation of an example message to compare the deserialized messageMyValueFactory vf("tcp:");
- EtchTypeMap types;
- EtchClass2TypeMap class2type;
- EtchString name1("a");
- EtchString name2("b");
- EtchType *mt_foo = new EtchType(1, name1);
- EtchField mf_x(2, name2);
- capu::SmartPointer<EtchValidator> v;
- EtchValidatorShort::Get(0, v);
- mt_foo->putValidator(mf_x, v);
- types.add(mt_foo);
- capu::SmartPointer<EtchShort> data = new EtchShort(10000);
- //default value factory
- EtchDefaultValueFactory * factory;
- EtchDefaultValueFactory::Init(&types, &class2type);
- EtchString uri("tcp://127.0.0.1:4001");
-
-
- factory = new EtchDefaultValueFactory(uri, &types, &class2type);
- capu::SmartPointer<EtchMessage> msg = new EtchMessage(mt_foo, factory);
- msg->put(mf_x, data);
-
-
- EtchURL u(uri);
- EtchResources r;
- EtchObject *out;
- //add the value factory to the resources
- r.put((EtchString &) EtchTransport<EtchSessionMessage>::VALUE_FACTORY, factory, out);
- //create stack
- EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
- EtchPacketizer* pac = new EtchPacketizer(conn, &u);
- EtchMessagizer* mess = new EtchMessagizer(pac, &u, &r);
- capu::SmartPointer<EtchFlexBuffer> buffer = new EtchFlexBuffer();
-
- //A packet is created
- capu::int8_t byte_pos[] = {3, 1, 1, 2, -123, 39, 16, -127};
- buffer->setByteRepresentation(ETCH_BIG_ENDIAN);
- buffer->put((capu::int8_t *)"_header_", pac->getHeaderSize());
- buffer->put((capu::int8_t *)byte_pos, 8);
- buffer->setIndex(0);
- capu::int32_t pktsize = buffer->getLength() - pac->getHeaderSize();
- buffer->put((capu::int8_t *) & pac->SIG, sizeof (capu::int32_t));
- buffer->put((capu::int8_t *) & pktsize, sizeof (capu::int32_t));
- buffer->setIndex(pac->getHeaderSize());
- EXPECT_TRUE(buffer->getLength() == 16);
-
- //Simulate call with fake package
- EtchSessionMessage* mMailboxManager = new MockMailboxManager();
- mess->setSession(mMailboxManager);
- EXPECT_TRUE(mess->sessionPacket(NULL, buffer) == ETCH_OK);
-
- mess->setSession(NULL);
- types.clear();
- delete mMailboxManager;
- delete mess;
- delete pac;
- delete conn;
- delete factory;
-}
-
-
-
-
+};
+
+TEST(EtchMessagizerTest, constructorTest) {
+ EtchTypeMap types;
+ EtchClass2TypeMap class2type;
+ EtchDefaultValueFactory * factory;
+ EtchDefaultValueFactory::Init(&types, &class2type);
+ EtchString uri("tcp://127.0.0.1:4001");
+ factory = new EtchDefaultValueFactory(uri, &types, &class2type);
+ //created value factory
+ EtchURL u("tcp://127.0.0.1:4001");
+ EtchResources r;
+ EtchObject *out;
+ r.put((EtchString &) EtchTransport<EtchSessionMessage>::VALUE_FACTORY, factory, out);
+ EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
+ EtchTransportPacket* pac = new EtchPacketizer(conn, &u);
+ EtchSessionPacket* mes = new EtchMessagizer(pac, &u, &r);
+ //Created stack
+ delete mes;
+ delete pac;
+ delete conn;
+ delete factory;
+ types.clear();
+}
+
+TEST(EtchMessagizerTest, TransportControlTest) {
+ EtchTypeMap types;
+ EtchClass2TypeMap class2type;
+ EtchDefaultValueFactory * factory;
+ MockMailboxManager manager;
+ EtchDefaultValueFactory::Init(&types, &class2type);
+ EtchString uri("tcp://127.0.0.1:4001");
+ factory = new EtchDefaultValueFactory(uri, &types, &class2type);
+ //created value factory
+ EtchURL u("tcp://127.0.0.1:4001");
+ EtchResources r;
+ EtchObject *out;
+ r.put((EtchString &) EtchTransport<EtchSessionMessage>::VALUE_FACTORY, factory, out);
+ EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
+ EtchPacketizer* pac = new EtchPacketizer(conn, &u);
+ EtchMessagizer* mess = new EtchMessagizer(pac, &u, &r);
+ mess->setSession(&manager);
+
+ EtchSessionListener<EtchSocket>* mSessionListener = new MockListener11();
+ EtchTcpListener* listener = new EtchTcpListener(&u);
+ //Start the mock listener
+ listener->setSession(mSessionListener);
+ listener->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP), new EtchInt32(1000));
+ mess->transportControl(new EtchString(EtchPacketizer::START_AND_WAIT_UP), new EtchInt32(1000));
+ //test transport commands
+ mess->transportControl(new EtchString(EtchPacketizer::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
+ listener->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
+ listener->setSession(mSessionListener);
+
+ delete mSessionListener;
+ delete mess;
+ delete pac;
+ delete conn;
+ delete listener;
+ delete factory;
+ types.clear();
+}
+
+TEST(EtchMessagizerTest, TransportMessageTest) {
+ EtchTypeMap types;
+ EtchClass2TypeMap class2type;
+ EtchDefaultValueFactory * factory;
+ MockMailboxManager manager;
+ EtchDefaultValueFactory::Init(&types, &class2type);
+ EtchString uri("tcp://127.0.0.1:4001");
+ factory = new EtchDefaultValueFactory(uri, &types, &class2type);
+ //default value factory
+ EtchURL u("tcp://127.0.0.1:4001");
+ EtchResources r;
+ EtchObject *out;
+ //add to the resource
+ r.put((EtchString &) EtchTransport<EtchSessionMessage>::VALUE_FACTORY, factory, out);
+ EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
+ EtchPacketizer* pac = new EtchPacketizer(conn, &u);
+ EtchMessagizer* mess = new EtchMessagizer(pac, &u, &r);
+ mess->setSession(&manager);
+ //creation of example message which will be serialized
+ EtchType *mt_foo = NULL;
+ EtchField mf_x("x");
+ EtchString str("foo");
+ factory->getType(str, mt_foo);
+ capu::SmartPointer<EtchValidator> v;
+ EtchValidatorShort::Get(0, v);
+ mt_foo->putValidator(mf_x, v);
+ capu::SmartPointer<EtchShort> data = new EtchShort(10000);
+ capu::SmartPointer<EtchMessage> msg = new EtchMessage(mt_foo, factory);
+ msg->put(mf_x, data);
+
+ EXPECT_TRUE(mess->transportMessage(NULL, msg) == ETCH_EINVAL);
+
+ delete mess;
+ delete pac;
+ delete conn;
+ delete factory;
+ types.clear();
+}
+
+TEST(EtchMessagizerTest, SessionDataTest) {
+ //creation of an example message to compare the deserialized messageMyValueFactory vf("tcp:");
+ EtchTypeMap types;
+ EtchClass2TypeMap class2type;
+ EtchString name1("a");
+ EtchString name2("b");
+ EtchType *mt_foo = new EtchType(1, name1);
+ EtchField mf_x(2, name2);
+ capu::SmartPointer<EtchValidator> v;
+ EtchValidatorShort::Get(0, v);
+ mt_foo->putValidator(mf_x, v);
+ types.add(mt_foo);
+ capu::SmartPointer<EtchShort> data = new EtchShort(10000);
+ //default value factory
+ EtchDefaultValueFactory * factory;
+ EtchDefaultValueFactory::Init(&types, &class2type);
+ EtchString uri("tcp://127.0.0.1:4001");
+
+
+ factory = new EtchDefaultValueFactory(uri, &types, &class2type);
+ capu::SmartPointer<EtchMessage> msg = new EtchMessage(mt_foo, factory);
+ msg->put(mf_x, data);
+
+
+ EtchURL u(uri);
+ EtchResources r;
+ EtchObject *out;
+ //add the value factory to the resources
+ r.put((EtchString &) EtchTransport<EtchSessionMessage>::VALUE_FACTORY, factory, out);
+ //create stack
+ EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
+ EtchPacketizer* pac = new EtchPacketizer(conn, &u);
+ EtchMessagizer* mess = new EtchMessagizer(pac, &u, &r);
+ capu::SmartPointer<EtchFlexBuffer> buffer = new EtchFlexBuffer();
+
+ //A packet is created
+ capu::int8_t byte_pos[] = {3, 1, 1, 2, -123, 39, 16, -127};
+ buffer->setByteRepresentation(ETCH_BIG_ENDIAN);
+ buffer->put((capu::int8_t *)"_header_", pac->getHeaderSize());
+ buffer->put((capu::int8_t *)byte_pos, 8);
+ buffer->setIndex(0);
+ capu::int32_t pktsize = buffer->getLength() - pac->getHeaderSize();
+ buffer->put((capu::int8_t *) & pac->SIG, sizeof (capu::int32_t));
+ buffer->put((capu::int8_t *) & pktsize, sizeof (capu::int32_t));
+ buffer->setIndex(pac->getHeaderSize());
+ EXPECT_TRUE(buffer->getLength() == 16);
+
+ //Simulate call with fake package
+ EtchSessionMessage* mMailboxManager = new MockMailboxManager();
+ mess->setSession(mMailboxManager);
+ EXPECT_TRUE(mess->sessionPacket(NULL, buffer) == ETCH_OK);
+
+ mess->setSession(NULL);
+ types.clear();
+ delete mMailboxManager;
+ delete mess;
+ delete pac;
+ delete conn;
+ delete factory;
+}
+
+
+
+
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp?rev=1368523&r1=1368522&r2=1368523&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchPacketizerTest.cpp Thu Aug 2 15:18:59 2012
@@ -1,135 +1,141 @@
-/* $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/EtchPacketizer.h"
-#include "common/EtchString.h"
-#include "common/EtchError.h"
-#include "util/EtchURL.h"
-#include "transport/EtchTcpConnection.h"
-#include "capu/util/SmartPointer.h"
-#include "common/EtchSocket.h"
-#include "transport/EtchSessionListener.h"
-#include "transport/EtchTcpListener.h"
-#include "transport/EtchSessionPacket.h"
-#include "transport/EtchFlexBuffer.h"
-
-class MockListener3 : public virtual EtchSessionListener<EtchSocket> {
-public:
-
- //This method is called
-
- status_t sessionAccepted(EtchSocket* connection) {
- delete connection;
+/* $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/EtchPacketizer.h"
+#include "common/EtchString.h"
+#include "common/EtchError.h"
+#include "util/EtchURL.h"
+#include "transport/EtchTcpConnection.h"
+#include "capu/util/SmartPointer.h"
+#include "common/EtchSocket.h"
+#include "transport/EtchSessionListener.h"
+#include "transport/EtchTcpListener.h"
+#include "transport/EtchSessionPacket.h"
+#include "transport/EtchFlexBuffer.h"
+
+class MockListener3 : public virtual EtchSessionListener<EtchSocket> {
+public:
+
+ //This method is called
+
+ status_t sessionAccepted(EtchSocket* connection) {
+ delete connection;
+ return ETCH_OK;
+ }
+
+ MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
+ status_t sessionNotify(capu::SmartPointer<EtchObject> event) {
return ETCH_OK;
}
-
- MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
-
- MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
-
- MOCK_METHOD1(sessionNotify, status_t(capu::SmartPointer<EtchObject> event));
-};
-
-class MockMessagizer : public EtchSessionPacket {
-public:
-
- MOCK_METHOD2(sessionPacket, status_t(capu::SmartPointer<EtchWho> receipent, capu::SmartPointer<EtchFlexBuffer> buf));
-
- MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
-
- MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
-
- MOCK_METHOD1(sessionNotify, status_t(capu::SmartPointer<EtchObject> event));
-};
-
-TEST(EtchPacketizer, constructorTest) {
- EtchURL u("tcp://127.0.0.1:4001");
- EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
- EtchSessionData* packetizer = new EtchPacketizer(conn, &u);
- delete packetizer;
- delete conn;
-}
-
-TEST(EtchPacketizer, TransportControlTest) {
- EtchURL u("tcp://127.0.0.1:4001");
- EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
- EtchPacketizer* res = new EtchPacketizer(conn, &u);
-
- EtchSessionListener<EtchSocket>* mSessionListener = new MockListener3();
- EtchTcpListener* listener = new EtchTcpListener(&u);
- //Start the mock listener
- listener->setSession(mSessionListener);
- listener->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP), new EtchInt32(1000));
- res->transportControl(new EtchString(EtchPacketizer::START_AND_WAIT_UP), new EtchInt32(1000));
-
- res->transportControl(new EtchString(EtchPacketizer::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
- listener->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN),new EtchInt32(1000));
-
- conn->setSession(NULL);
- res->setSession(NULL);
- listener->setSession(NULL);
-
- delete mSessionListener;
- delete res;
- delete conn;
- delete listener;
-}
-
-TEST(EtchPacketizer, TransportPacketTest) {
- EtchURL u("tcp://127.0.0.1:4001");
- EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
- EtchPacketizer* packetizer = new EtchPacketizer(conn, &u);
- capu::SmartPointer<EtchFlexBuffer> buffer = new EtchFlexBuffer();
-
- //A packet is try to transmit data through not started transport
- buffer->put((capu::int8_t *)"_header_", packetizer->getHeaderSize());
- buffer->put((capu::int8_t *)"test", 4);
- buffer->setIndex(0);
-
- EXPECT_TRUE(packetizer->transportPacket(NULL, buffer) == ETCH_ERROR);
-
- delete packetizer;
- delete conn;
-}
-
-TEST(EtchPacketizer, SessionDataTest) {
- EtchURL u("tcp://127.0.0.1:4001");
- EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
- EtchPacketizer* packetizer = new EtchPacketizer(conn, &u);
- capu::SmartPointer<EtchFlexBuffer> buffer = new EtchFlexBuffer();
-
- //A packet is created
- capu::int32_t pktsize = 4;
- buffer->put((capu::int8_t *) & packetizer->SIG, sizeof (capu::int32_t));
- buffer->put((capu::int8_t *) & pktsize, sizeof (capu::int32_t));
- buffer->put((capu::int8_t *)"test", pktsize);
- buffer->setIndex(0);
- EXPECT_TRUE(buffer->getLength() == 12);
-
- EtchSessionPacket* mSessionPacker = new MockMessagizer();
- packetizer->setSession(mSessionPacker);
-
- MockMessagizer * mock = (MockMessagizer*) mSessionPacker;
- EXPECT_CALL(*mock, sessionPacket(capu::SmartPointer<EtchWho > (NULL), buffer));
- EXPECT_TRUE(packetizer->sessionData(NULL, buffer) == ETCH_OK);
-
- packetizer->setSession(NULL);
- delete mSessionPacker;
- delete packetizer;
- delete conn;
+};
+
+class MockMessagizer : public EtchSessionPacket {
+public:
+
+ MOCK_METHOD2(sessionPacket, status_t(capu::SmartPointer<EtchWho> receipent, capu::SmartPointer<EtchFlexBuffer> buf));
+
+ MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
+ status_t sessionNotify(capu::SmartPointer<EtchObject> event) {
+ return ETCH_OK;
+ }
+};
+
+TEST(EtchPacketizer, constructorTest) {
+ EtchURL u("tcp://127.0.0.1:4001");
+ EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
+ EtchSessionData* packetizer = new EtchPacketizer(conn, &u);
+ delete packetizer;
+ delete conn;
+}
+
+TEST(EtchPacketizer, TransportControlTest) {
+ EtchURL u("tcp://127.0.0.1:4001");
+ EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
+ EtchPacketizer* res = new EtchPacketizer(conn, &u);
+ MockMessagizer mes;
+ res->setSession(&mes);
+ EtchSessionListener<EtchSocket>* mSessionListener = new MockListener3();
+ EtchTcpListener* listener = new EtchTcpListener(&u);
+ //Start the mock listener
+ listener->setSession(mSessionListener);
+ listener->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP), new EtchInt32(1000));
+ res->transportControl(new EtchString(EtchPacketizer::START_AND_WAIT_UP), new EtchInt32(1000));
+
+ res->transportControl(new EtchString(EtchPacketizer::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
+ listener->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
+
+ conn->setSession(NULL);
+ res->setSession(NULL);
+ listener->setSession(NULL);
+
+ delete mSessionListener;
+ delete res;
+ delete conn;
+ delete listener;
+}
+
+TEST(EtchPacketizer, TransportPacketTest) {
+ EtchURL u("tcp://127.0.0.1:4001");
+ EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
+ EtchPacketizer* packetizer = new EtchPacketizer(conn, &u);
+ MockMessagizer mes;
+ packetizer->setSession(&mes);
+ capu::SmartPointer<EtchFlexBuffer> buffer = new EtchFlexBuffer();
+
+ //A packet is try to transmit data through not started transport
+ buffer->put((capu::int8_t *)"_header_", packetizer->getHeaderSize());
+ buffer->put((capu::int8_t *)"test", 4);
+ buffer->setIndex(0);
+
+ EXPECT_TRUE(packetizer->transportPacket(NULL, buffer) == ETCH_ERROR);
+
+ delete packetizer;
+ delete conn;
+}
+
+TEST(EtchPacketizer, SessionDataTest) {
+ EtchURL u("tcp://127.0.0.1:4001");
+ EtchTransportData* conn = new EtchTcpConnection(NULL, &u);
+ EtchPacketizer* packetizer = new EtchPacketizer(conn, &u);
+ capu::SmartPointer<EtchFlexBuffer> buffer = new EtchFlexBuffer();
+ //A packet is created
+ capu::int32_t pktsize = 4;
+ buffer->put((capu::int8_t *) & packetizer->SIG, sizeof (capu::int32_t));
+ buffer->put((capu::int8_t *) & pktsize, sizeof (capu::int32_t));
+ buffer->put((capu::int8_t *)"test", pktsize);
+ buffer->setIndex(0);
+ EXPECT_TRUE(buffer->getLength() == 12);
+
+ EtchSessionPacket* mSessionPacker = new MockMessagizer();
+ packetizer->setSession(mSessionPacker);
+
+ MockMessagizer * mock = (MockMessagizer*) mSessionPacker;
+ EXPECT_CALL(*mock, sessionPacket(capu::SmartPointer<EtchWho > (NULL), buffer));
+ EXPECT_TRUE(packetizer->sessionData(NULL, buffer) == ETCH_OK);
+
+ packetizer->setSession(NULL);
+ delete mSessionPacker;
+ delete packetizer;
+ delete conn;
}
\ No newline at end of file
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchTcpConnectionTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchTcpConnectionTest.cpp?rev=1368523&r1=1368522&r2=1368523&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchTcpConnectionTest.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchTcpConnectionTest.cpp Thu Aug 2 15:18:59 2012
@@ -1,135 +1,137 @@
-/* $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/EtchTcpConnection.h"
-#include "util/EtchResources.h"
-#include "util/EtchURL.h"
-#include "common/EtchError.h"
-#include "common/EtchSocket.h"
-#include "common/EtchString.h"
-#include "capu/util/SmartPointer.h"
-#include "transport/EtchTcpListener.h"
-#include "transport/EtchSessionData.h"
-#include "transport/EtchSessionListener.h"
-
-class MockPacketizer : public virtual EtchSessionData {
-public:
-
- //Communication Test Between Peers
-
- status_t sessionData(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchFlexBuffer> buf) {
- EXPECT_TRUE(memcmp(buf->getBuffer(), "mock", buf->getLength()) == 0);
+/* $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/EtchTcpConnection.h"
+#include "util/EtchResources.h"
+#include "util/EtchURL.h"
+#include "common/EtchError.h"
+#include "common/EtchSocket.h"
+#include "common/EtchString.h"
+#include "capu/util/SmartPointer.h"
+#include "transport/EtchTcpListener.h"
+#include "transport/EtchSessionData.h"
+#include "transport/EtchSessionListener.h"
+
+class MockPacketizer : public virtual EtchSessionData {
+public:
+
+ //Communication Test Between Peers
+
+ status_t sessionData(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchFlexBuffer> buf) {
+ EXPECT_TRUE(memcmp(buf->getBuffer(), "mock", buf->getLength()) == 0);
+ return ETCH_OK;
+ }
+
+ MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
+
+ status_t sessionNotify(capu::SmartPointer<EtchObject> event) {
return ETCH_OK;
}
-
- MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
-
- MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
-
- MOCK_METHOD1(sessionNotify, status_t(capu::SmartPointer<EtchObject> event));
-
-};
-
-class MockListener : public virtual EtchSessionListener<EtchSocket> {
-public:
-
- //Communication Test Between Peers
-
- EtchResources resources;
-
- status_t sessionAccepted(EtchSocket* connection) {
- EtchString _socket("socket");
- EtchObject *tmp;
- resources.put(_socket, connection, tmp);
- connection->send((unsigned char *) "mock", 4);
- capu::Thread::Sleep(1000);
- delete connection;
+
+};
+
+class MockListener : public virtual EtchSessionListener<EtchSocket> {
+public:
+
+ //Communication Test Between Peers
+
+ EtchResources resources;
+
+ status_t sessionAccepted(EtchSocket* connection) {
+ EtchString _socket("socket");
+ EtchObject *tmp;
+ resources.put(_socket, connection, tmp);
+ connection->send((unsigned char *) "mock", 4);
+ capu::Thread::Sleep(1000);
+ delete connection;
+ return ETCH_OK;
+ }
+
+ MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
+ status_t sessionNotify(capu::SmartPointer<EtchObject> event) {
return ETCH_OK;
}
-
- MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
-
- MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
-
- MOCK_METHOD1(sessionNotify, status_t(capu::SmartPointer<EtchObject> event));
-
-};
-
-TEST(EtchTcpConnection, constructorTest) {
- EtchURL url("tcp://127.0.0.1:4001");
- EtchResources resources;
- EtchTcpConnection * conn = new EtchTcpConnection(NULL, &url);
- EXPECT_TRUE(conn != NULL);
- delete conn;
-}
-
-TEST(EtchTcpConnection, isStartedTest) {
- EtchURL url("tcp://127.0.0.1:4001");
- EtchTcpConnection * conn = new EtchTcpConnection(NULL, &url);
+
+};
+
+TEST(EtchTcpConnection, constructorTest) {
+ EtchURL url("tcp://127.0.0.1:4001");
+ EtchTcpConnection * conn = new EtchTcpConnection(NULL, &url);
+ EXPECT_TRUE(conn != NULL);
+ delete conn;
+}
+
+TEST(EtchTcpConnection, isStartedTest) {
+ EtchURL url("tcp://127.0.0.1:4001");
+ EtchTcpConnection * conn = new EtchTcpConnection(NULL, &url);
+ EtchTcpListener *listener = new EtchTcpListener(&url);
+ EXPECT_FALSE(conn->isStarted());
+ EtchSessionListener<EtchSocket>* mSessionListener = new MockListener();
+ EtchSessionData* mPacketizer = new MockPacketizer();
+ //START THE LISTENER
+ listener->setSession(mSessionListener);
+ listener->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP), new EtchInt32(1000));
+ //START THE TRANSPORT
+ conn->setSession(mPacketizer);
+ conn->transportControl(new EtchString(EtchTcpConnection::START_AND_WAIT_UP), new EtchInt32(1000));
+ EXPECT_TRUE(conn->isStarted());
+ //STOP THE TRANSPORT
+ conn->transportControl(new EtchString(EtchTcpConnection::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
+ //STOP THE LISTENER
+ listener->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
+ EXPECT_FALSE(conn->isStarted());
+ conn->setSession(NULL);
+
+ delete listener;
+ delete conn;
+ delete mSessionListener;
+ delete mPacketizer;
+}
+
+TEST(EtchTcpConnectionAndListener, SessionAcceptTest) {
+ EtchURL url("tcp://127.0.0.1:4001");
+ EtchTcpConnection * conn = new EtchTcpConnection(NULL, &url);
+ EtchSessionListener<EtchSocket>* mSessionListener = new MockListener();
+ EtchSessionData* mPacketizer = new MockPacketizer();
EtchTcpListener *listener = new EtchTcpListener(&url);
- EXPECT_FALSE(conn->isStarted());
- EtchSessionListener<EtchSocket>* mSessionListener = new MockListener();
- EtchSessionData* mPacketizer = new MockPacketizer();
- //START THE LISTENER
+
+ //START THE LISTENER
listener->setSession(mSessionListener);
listener->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP), new EtchInt32(1000));
- //START THE TRANSPORT
- conn->setSession(mPacketizer);
- conn->transportControl(new EtchString(EtchTcpConnection::START_AND_WAIT_UP), new EtchInt32(1000));
- EXPECT_TRUE(conn->isStarted());
- //STOP THE TRANSPORT
- conn->transportControl(new EtchString(EtchTcpConnection::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
- //STOP THE LISTENER
+
+ //START THE TRANSPORT
+ conn->setSession(mPacketizer);
+ conn->transportControl(new EtchString(EtchTcpConnection::START_AND_WAIT_UP), new EtchInt32(1000));
+
+ conn->transportControl(new EtchString(EtchTcpConnection::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
+ //STOP THE LISTENER
listener->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
- EXPECT_FALSE(conn->isStarted());
- listener->setSession(NULL);
- conn->setSession(NULL);
-
- delete mSessionListener;
- delete mPacketizer;
- delete listener;
+ conn->setSession(NULL);
+
delete conn;
-}
-
-TEST(EtchTcpConnectionAndListener, SessionAcceptTest) {
- EtchURL url("tcp://127.0.0.1:4001");
- EtchTcpConnection * conn = new EtchTcpConnection(NULL, &url);
- EtchSessionListener<EtchSocket>* mSessionListener = new MockListener();
- EtchSessionData* mPacketizer = new MockPacketizer();
- EtchTcpListener listener(&url);
-
- //START THE LISTENER
- listener.setSession(mSessionListener);
- listener.transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP), new EtchInt32(1000));
-
- //START THE TRANSPORT
- conn->setSession(mPacketizer);
- conn->transportControl(new EtchString(EtchTcpConnection::START_AND_WAIT_UP), new EtchInt32(1000));
-
- conn->transportControl(new EtchString(EtchTcpConnection::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
- //STOP THE LISTENER
- listener.transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
-
- listener.setSession(NULL);
- conn->setSession(NULL);
-
- delete mSessionListener;
- delete mPacketizer;
- delete conn;
-}
+ delete listener;
+ delete mSessionListener;
+ delete mPacketizer;
+}
Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchTcpListenerTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchTcpListenerTest.cpp?rev=1368523&r1=1368522&r2=1368523&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchTcpListenerTest.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/transport/EtchTcpListenerTest.cpp Thu Aug 2 15:18:59 2012
@@ -1,110 +1,116 @@
-/* $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 "util/EtchResources.h"
-#include "util/EtchURL.h"
-#include "common/EtchError.h"
-#include "common/EtchSocket.h"
-#include "common/EtchString.h"
-#include "capu/util/SmartPointer.h"
-#include "transport/EtchTcpListener.h"
-#include "transport/EtchSessionData.h"
-#include "transport/EtchSessionListener.h"
-#include "transport/EtchTcpConnection.h"
-
-class MockPacketizer2 : public EtchSessionData {
-public:
-
- status_t sessionData(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchFlexBuffer> buf) {
- EXPECT_TRUE(memcmp(buf->getBuffer(), "mock", buf->getLength()) == 0);
+/* $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 "util/EtchResources.h"
+#include "util/EtchURL.h"
+#include "common/EtchError.h"
+#include "common/EtchSocket.h"
+#include "common/EtchString.h"
+#include "capu/util/SmartPointer.h"
+#include "transport/EtchTcpListener.h"
+#include "transport/EtchSessionData.h"
+#include "transport/EtchSessionListener.h"
+#include "transport/EtchTcpConnection.h"
+
+class MockPacketizer2 : public EtchSessionData {
+public:
+
+ status_t sessionData(capu::SmartPointer<EtchWho> sender, capu::SmartPointer<EtchFlexBuffer> buf) {
+ EXPECT_TRUE(memcmp(buf->getBuffer(), "mock", buf->getLength()) == 0);
+ return ETCH_OK;
+ }
+
+ MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
+ status_t sessionNotify(capu::SmartPointer<EtchObject> event) {
return ETCH_OK;
}
-
- MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
-
- MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
-
- MOCK_METHOD1(sessionNotify, status_t(capu::SmartPointer<EtchObject> event));
-};
-
-class MockListener2 : public virtual EtchSessionListener<EtchSocket> {
-public:
-
- EtchResources resources;
-
- status_t sessionAccepted(EtchSocket* connection) {
- EtchString _socket("socket");
- EtchObject *tmp;
- resources.put(_socket, connection, tmp);
- connection->send((unsigned char *) "mock", 4);
- delete connection;
+};
+
+class MockListener2 : public virtual EtchSessionListener<EtchSocket> {
+public:
+
+ EtchResources resources;
+
+ status_t sessionAccepted(EtchSocket* connection) {
+ EtchString _socket("socket");
+ EtchObject *tmp;
+ resources.put(_socket, connection, tmp);
+ connection->send((unsigned char *) "mock", 4);
+ delete connection;
+ return ETCH_OK;
+ }
+
+ MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
+
+ MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
+
+ status_t sessionNotify(capu::SmartPointer<EtchObject> event) {
return ETCH_OK;
}
-
- MOCK_METHOD2(sessionQuery, status_t(capu::SmartPointer<EtchObject> query, capu::SmartPointer<EtchObject> &result));
-
- MOCK_METHOD2(sessionControl, status_t(capu::SmartPointer<EtchObject> control, capu::SmartPointer<EtchObject> value));
-
- MOCK_METHOD1(sessionNotify, status_t(capu::SmartPointer<EtchObject> event));
-
-};
-
-TEST(EtchTcpListener, constructorTest) {
- EtchURL url("tcp://127.0.0.1:4001");
- EtchTcpListener * tcpListener = new EtchTcpListener(&url);
- EXPECT_TRUE(tcpListener != NULL);
- delete tcpListener;
-}
-
-TEST(EtchTcpListener, transportControlTest) {
- EtchURL url("tcp://127.0.0.1:4001");
- EtchTcpListener * tcpListener = new EtchTcpListener(&url);
- tcpListener->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP), new EtchInt32(1000));
- EXPECT_TRUE(tcpListener->isStarted());
- tcpListener->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
- delete tcpListener;
-}
-
-TEST(EtchTcpListener, isStartedTest) {
- EtchURL url("tcp://127.0.0.1:4001");
- EtchTcpConnection * conn = new EtchTcpConnection(NULL, &url);
- EtchTcpListener *listener = new EtchTcpListener(&url);
- EtchSessionListener<EtchSocket>* mSessionListener = new MockListener2();
- EtchSessionData* mPacketizer = new MockPacketizer2();
- EXPECT_FALSE(listener->isStarted());
- //START THE LISTENER
- listener->setSession(mSessionListener);
- listener->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP), new EtchInt32(1000));
- //START THE TRANSPORT
- conn->setSession(mPacketizer);
- conn->transportControl(new EtchString(EtchTcpConnection::START_AND_WAIT_UP), new EtchInt32(1000));
- EXPECT_TRUE(listener->isStarted());
- //STOP THE TRANSPORT
- conn->transportControl(new EtchString(EtchTcpConnection::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
- //STOP THE LISTENER
- listener->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
- EXPECT_FALSE(listener->isStarted());
- listener->setSession(NULL);
- conn->setSession(NULL);
-
- delete mSessionListener;
- delete mPacketizer;
- delete listener;
- delete conn;
+
+};
+
+TEST(EtchTcpListener, constructorTest) {
+ EtchURL url("tcp://127.0.0.1:4001");
+ EtchTcpListener * tcpListener = new EtchTcpListener(&url);
+ EXPECT_TRUE(tcpListener != NULL);
+ delete tcpListener;
+}
+
+TEST(EtchTcpListener, transportControlTest) {
+ MockListener2 mock;
+ EtchURL url("tcp://127.0.0.1:4001");
+ EtchTcpListener * tcpListener = new EtchTcpListener(&url);
+ tcpListener->setSession(&mock);
+ tcpListener->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP), new EtchInt32(1000));
+ EXPECT_TRUE(tcpListener->isStarted());
+ tcpListener->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
+ delete tcpListener;
+}
+
+TEST(EtchTcpListener, isStartedTest) {
+ EtchURL url("tcp://127.0.0.1:4001");
+ EtchTcpConnection * conn = new EtchTcpConnection(NULL, &url);
+ EtchTcpListener *listener = new EtchTcpListener(&url);
+ EtchSessionListener<EtchSocket>* mSessionListener = new MockListener2();
+ EtchSessionData* mPacketizer = new MockPacketizer2();
+ EXPECT_FALSE(listener->isStarted());
+ //START THE LISTENER
+ listener->setSession(mSessionListener);
+ listener->transportControl(new EtchString(EtchTcpListener::START_AND_WAIT_UP), new EtchInt32(1000));
+ //START THE TRANSPORT
+ conn->setSession(mPacketizer);
+ conn->transportControl(new EtchString(EtchTcpConnection::START_AND_WAIT_UP), new EtchInt32(1000));
+ EXPECT_TRUE(listener->isStarted());
+ //STOP THE TRANSPORT
+ conn->transportControl(new EtchString(EtchTcpConnection::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
+ //STOP THE LISTENER
+ listener->transportControl(new EtchString(EtchTcpListener::STOP_AND_WAIT_DOWN), new EtchInt32(1000));
+ EXPECT_FALSE(listener->isStarted());
+ listener->setSession(NULL);
+ conn->setSession(NULL);
+
+ delete mSessionListener;
+ delete mPacketizer;
+ delete listener;
+ delete conn;
}
\ No newline at end of file