You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2008/04/29 22:52:37 UTC
svn commit: r652104 [28/29] - in /activemq/activemq-cpp/trunk: ./ m4/
src/examples/ src/examples/consumers/ src/main/ src/main/decaf/
src/main/decaf/internal/ src/main/decaf/internal/net/
src/main/decaf/internal/nio/ src/main/decaf/internal/util/ src/m...
Added: activemq/activemq-cpp/trunk/src/test/decaf/lang/ThreadTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/lang/ThreadTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/lang/ThreadTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/lang/ThreadTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,68 @@
+/*
+ * 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 "ThreadTest.h"
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+
+void ThreadTest::testDelegate(){
+
+ Delegate test;
+ int initialValue = test.getStuff();
+
+ Thread thread( &test );
+ thread.start();
+ thread.join();
+
+ int finalValue = test.getStuff();
+
+ // The values should be different - this proves
+ // that the runnable was run.
+ CPPUNIT_ASSERT( finalValue != initialValue );
+}
+
+void ThreadTest::testDerived(){
+
+ Derived test;
+ int initialValue = test.getStuff();
+
+ test.start();
+ test.join();
+
+ int finalValue = test.getStuff();
+
+ // The values should be different - this proves
+ // that the runnable was run.
+ CPPUNIT_ASSERT( finalValue != initialValue );
+}
+
+void ThreadTest::testJoin(){
+
+ JoinTest test;
+
+ time_t startTime = time( NULL );
+ test.start();
+ test.join();
+ time_t endTime = time( NULL );
+
+ time_t delta = endTime - startTime;
+
+ // Should be about 5 seconds that elapsed.
+ CPPUNIT_ASSERT( delta >= 1 && delta <= 3 );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/lang/ThreadTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/lang/ThreadTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/lang/ThreadTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/lang/ThreadTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,108 @@
+/*
+ * 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 _DECAF_LANG_THREADTEST_H_
+#define _DECAF_LANG_THREADTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/lang/Thread.h>
+#include <time.h>
+
+namespace decaf{
+namespace lang{
+
+ class ThreadTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( ThreadTest );
+ CPPUNIT_TEST( testDelegate );
+ CPPUNIT_TEST( testDerived );
+ CPPUNIT_TEST( testJoin );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ class Delegate : public Runnable{
+ private:
+
+ int stuff;
+
+ public:
+
+ Delegate(){ stuff = 0; }
+ virtual ~Delegate(){}
+
+ int getStuff(){
+ return stuff;
+ }
+
+ virtual void run(){
+ stuff = 1;
+ }
+
+ };
+
+ class Derived : public Thread{
+ private:
+
+ int stuff;
+
+ public:
+
+ Derived(){ stuff = 0; }
+ virtual ~Derived(){}
+
+ int getStuff(){
+ return stuff;
+ }
+
+ virtual void run(){
+ stuff = 1;
+ }
+
+ };
+
+ class JoinTest : public Thread{
+ public:
+
+ JoinTest(){}
+ virtual ~JoinTest(){}
+
+ virtual void run(){
+
+ // Sleep for 2 seconds.
+ Thread::sleep( 2000 );
+ }
+
+ };
+
+ public:
+
+ virtual ~ThreadTest(){}
+
+ virtual void setUp(){}
+ virtual void tearDown(){}
+
+ void testDelegate();
+ void testDerived();
+ void testJoin();
+ };
+
+}}
+
+#endif /*_DECAF_LANG_THREADTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/net/SocketFactoryTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/net/SocketFactoryTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/net/SocketFactoryTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/net/SocketFactoryTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,147 @@
+/*
+ * 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 "SocketFactoryTest.h"
+
+#include <decaf/util/Properties.h>
+#include <decaf/net/SocketFactory.h>
+#include <decaf/net/TcpSocket.h>
+
+using namespace decaf;
+using namespace decaf::net;
+using namespace decaf::util;
+using namespace decaf::lang;
+using namespace decaf::util::concurrent;
+
+////////////////////////////////////////////////////////////////////////////////
+void SocketFactoryTest::test()
+{
+ try
+ {
+ MyServerThread serverThread;
+ serverThread.start();
+
+ Thread::sleep( 500 );
+
+ util::Properties properties;
+
+ std::ostringstream ostream;
+
+ ostream << "127.0.0.1:" << port;
+
+ properties.setProperty("soLinger", "false");
+
+ Socket* client = SocketFactory::createSocket(
+ ostream.str(), properties );
+
+ synchronized(&serverThread.mutex)
+ {
+ if(serverThread.getNumClients() != 1)
+ {
+ serverThread.mutex.wait(10000);
+ }
+ }
+
+ CPPUNIT_ASSERT( client->isConnected() );
+
+ CPPUNIT_ASSERT( serverThread.getNumClients() == 1 );
+
+ client->close();
+
+ synchronized(&serverThread.mutex)
+ {
+ if(serverThread.getNumClients() != 0)
+ {
+ serverThread.mutex.wait(10000);
+ }
+ }
+
+ CPPUNIT_ASSERT( serverThread.getNumClients() == 0 );
+
+ serverThread.stop();
+ serverThread.join();
+
+ delete client;
+ }
+ catch(lang::Exception ex)
+ {
+ std::cout << "SocketFactoryTest::test - Caught Exception." << std::endl;
+ ex.printStackTrace();
+ CPPUNIT_ASSERT( false );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SocketFactoryTest::testNoDelay()
+{
+ try
+ {
+ MyServerThread serverThread;
+ serverThread.start();
+
+ Thread::sleep( 40 );
+
+ util::Properties properties;
+
+ std::ostringstream ostream;
+
+ ostream << "127.0.0.1:" << port;
+
+ properties.setProperty( "soLinger", "false" );
+ properties.setProperty( "tcpNoDelay", "true" );
+
+ Socket* client = SocketFactory::createSocket(
+ ostream.str(), properties );
+
+ TcpSocket* tcpSock = dynamic_cast<TcpSocket*>( client );
+ CPPUNIT_ASSERT( tcpSock != NULL );
+ CPPUNIT_ASSERT( tcpSock->getTcpNoDelay() == true );
+
+ synchronized(&serverThread.mutex)
+ {
+ if(serverThread.getNumClients() != 1)
+ {
+ serverThread.mutex.wait(1000);
+ }
+ }
+
+ CPPUNIT_ASSERT( client->isConnected() );
+
+ CPPUNIT_ASSERT( serverThread.getNumClients() == 1 );
+
+ client->close();
+
+ synchronized(&serverThread.mutex)
+ {
+ if(serverThread.getNumClients() != 0)
+ {
+ serverThread.mutex.wait(1000);
+ }
+ }
+
+ CPPUNIT_ASSERT( serverThread.getNumClients() == 0 );
+
+ serverThread.stop();
+ serverThread.join();
+
+ delete client;
+ }
+ catch(lang::Exception ex)
+ {
+ CPPUNIT_ASSERT( false );
+ }
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/net/SocketFactoryTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/net/SocketFactoryTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/net/SocketFactoryTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/net/SocketFactoryTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,148 @@
+/*
+ * 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 _DECAF_NET_SOCKETFACTORYTEST_H_
+#define _DECAF_NET_SOCKETFACTORYTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/net/Socket.h>
+#include <decaf/net/ServerSocket.h>
+#include <decaf/util/concurrent/Concurrent.h>
+#include <decaf/util/concurrent/Mutex.h>
+#include <decaf/lang/Thread.h>
+
+#include <sstream>
+
+namespace decaf{
+namespace net{
+
+ class SocketFactoryTest : public CppUnit::TestFixture
+ {
+ CPPUNIT_TEST_SUITE( SocketFactoryTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST( testNoDelay );
+ CPPUNIT_TEST_SUITE_END();
+
+ static const int port = 23232;
+
+ class MyServerThread : public lang::Thread{
+ private:
+
+ bool done;
+ int numClients;
+ std::string lastMessage;
+
+ public:
+
+ util::concurrent::Mutex mutex;
+
+ public:
+
+ MyServerThread(){
+ done = false;
+ numClients = 0;
+ }
+ virtual ~MyServerThread(){
+ stop();
+ }
+
+ std::string getLastMessage(){
+ return lastMessage;
+ }
+
+ int getNumClients(){
+ return numClients;
+ }
+
+ virtual void stop(){
+ done = true;
+ }
+
+ virtual void run(){
+ try{
+ unsigned char buf[1000];
+
+ ServerSocket server;
+ server.bind( "127.0.0.1", port );
+
+ net::Socket* socket = server.accept();
+ server.close();
+
+ socket->setSoLinger( false );
+
+ synchronized(&mutex)
+ {
+ numClients++;
+ mutex.notifyAll();
+ }
+
+ while( !done && socket != NULL ){
+
+ io::InputStream* stream = socket->getInputStream();
+ memset( buf, 0, 1000 );
+ try{
+ if( stream->read( buf, 0, 1000 ) == -1 ) {
+ done = true;
+ continue;
+ }
+
+ lastMessage = (char*)buf;
+
+ if( strcmp( (char*)buf, "reply" ) == 0 ){
+ io::OutputStream* output = socket->getOutputStream();
+ output->write( (unsigned char*)"hello", 0, strlen("hello" ) );
+ }
+
+ }catch( io::IOException& ex ){
+ done = true;
+ }
+ }
+
+ socket->close();
+ delete socket;
+
+ numClients--;
+
+ synchronized(&mutex)
+ {
+ mutex.notifyAll();
+ }
+
+ }catch( io::IOException& ex ){
+ printf("%s\n", ex.getMessage().c_str() );
+ CPPUNIT_ASSERT( false );
+ }catch( ... ){
+ CPPUNIT_ASSERT( false );
+ }
+ }
+ };
+
+ public:
+
+ SocketFactoryTest() {}
+ virtual ~SocketFactoryTest() {}
+
+ void test();
+ void testNoDelay();
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_SOCKETFACTORYTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/net/SocketTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/net/SocketTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/net/SocketTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/net/SocketTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,281 @@
+/*
+ * 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 "SocketTest.h"
+
+#include <decaf/net/TcpSocket.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::net;
+using namespace decaf::util;
+using namespace decaf::lang;
+
+////////////////////////////////////////////////////////////////////////////////
+void SocketTest::testConnect() {
+
+ try{
+
+ MyServerThread serverThread;
+ serverThread.start();
+
+ Thread::sleep( 40 );
+
+ TcpSocket client;
+
+ client.connect("127.0.0.1", port);
+ client.setSoLinger( false );
+
+ synchronized(&serverThread.mutex)
+ {
+ if(serverThread.getNumClients() != 1)
+ {
+ serverThread.mutex.wait(1000);
+ }
+ }
+
+ CPPUNIT_ASSERT( serverThread.getNumClients() == 1 );
+
+ client.close();
+
+ synchronized(&serverThread.mutex)
+ {
+ if(serverThread.getNumClients() != 0)
+ {
+ serverThread.mutex.wait(1000);
+ }
+ }
+
+ CPPUNIT_ASSERT( serverThread.getNumClients() == 0 );
+
+ serverThread.stop();
+ serverThread.join();
+
+ }catch( io::IOException& ex ){
+ printf( "%s\n", ex.getMessage().c_str() );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SocketTest::testTx() {
+
+ try{
+
+ MyServerThread serverThread;
+ serverThread.start();
+
+ Thread::sleep( 10 );
+
+ TcpSocket client;
+
+ client.connect("127.0.0.1", port);
+ client.setSoLinger( false );
+
+ synchronized(&serverThread.mutex)
+ {
+ if(serverThread.getNumClients() != 1)
+ {
+ serverThread.mutex.wait(1000);
+ }
+ }
+
+ CPPUNIT_ASSERT( serverThread.getNumClients() == 1 );
+
+ io::OutputStream* stream = client.getOutputStream();
+
+ std::string msg = "don't reply";
+ stream->write( (unsigned char*)msg.c_str(), 0, msg.length() );
+
+ Thread::sleep( 10 );
+
+ CPPUNIT_ASSERT( serverThread.getLastMessage() == msg );
+
+ client.close();
+
+ synchronized(&serverThread.mutex)
+ {
+ if(serverThread.getNumClients() != 0)
+ {
+ serverThread.mutex.wait(1000);
+ }
+ }
+
+ CPPUNIT_ASSERT( serverThread.getNumClients() == 0 );
+
+ serverThread.stop();
+ serverThread.join();
+
+ }catch( io::IOException& ex ){
+ printf( "%s\n", ex.getMessage().c_str() );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SocketTest::testTrx() {
+
+ try{
+
+ MyServerThread serverThread;
+ serverThread.start();
+
+ Thread::sleep( 10 );
+
+ TcpSocket client;
+
+ client.connect("127.0.0.1", port);
+ client.setSoLinger(false);
+
+ synchronized(&serverThread.mutex)
+ {
+ if(serverThread.getNumClients() != 1)
+ {
+ serverThread.mutex.wait(1000);
+ }
+ }
+
+ CPPUNIT_ASSERT( serverThread.getNumClients() == 1 );
+
+ io::OutputStream* stream = client.getOutputStream();
+
+ std::string msg = "reply";
+ stream->write( (unsigned char*)msg.c_str(), 0, msg.length() );
+
+ synchronized(&serverThread.mutex)
+ {
+ serverThread.mutex.wait(300);
+ }
+
+ unsigned char buf[500];
+ memset( buf, 0, 500 );
+ io::InputStream* istream = client.getInputStream();
+ CPPUNIT_ASSERT( istream->available() != 0 );
+ std::size_t numRead = istream->read( buf, 0, 500 );
+ CPPUNIT_ASSERT( numRead == 5 );
+ CPPUNIT_ASSERT( strcmp( (char*)buf, "hello" ) == 0 );
+
+ client.close();
+
+ serverThread.stop();
+ serverThread.join();
+
+ }catch( io::IOException& ex ){
+ printf( "%s\n", ex.getMessage().c_str() );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SocketTest::testRxFail() {
+
+ try{
+
+ MyServerThread serverThread;
+ serverThread.start();
+
+ Thread::sleep( 10 );
+
+ TcpSocket client;
+
+ client.connect("127.0.0.1", port);
+ client.setSoLinger( false );
+
+ synchronized(&serverThread.mutex)
+ {
+ if(serverThread.getNumClients() != 1)
+ {
+ serverThread.mutex.wait(1000);
+ }
+ }
+
+ CPPUNIT_ASSERT( serverThread.getNumClients() == 1 );
+
+ // Give it a chance to get to its read call
+ Thread::sleep( 100 );
+
+ client.close();
+
+ synchronized(&serverThread.mutex)
+ {
+ if(serverThread.getNumClients() != 0)
+ {
+ serverThread.mutex.wait(1000);
+ }
+ }
+
+ CPPUNIT_ASSERT( serverThread.getNumClients() == 0 );
+
+ serverThread.stop();
+ serverThread.join();
+
+ }catch( io::IOException& ex ){
+ printf( "%s\n", ex.getMessage().c_str() );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SocketTest::testTrxNoDelay() {
+
+ try{
+
+ MyServerThread serverThread;
+ serverThread.start();
+
+ Thread::sleep( 10 );
+
+ TcpSocket client;
+
+ client.connect("127.0.0.1", port);
+ client.setSoLinger(false);
+ client.setTcpNoDelay(true);
+
+ CPPUNIT_ASSERT( client.getTcpNoDelay() == true );
+
+ synchronized(&serverThread.mutex)
+ {
+ if(serverThread.getNumClients() != 1)
+ {
+ serverThread.mutex.wait(1000);
+ }
+ }
+
+ CPPUNIT_ASSERT( serverThread.getNumClients() == 1 );
+
+ io::OutputStream* stream = client.getOutputStream();
+
+ std::string msg = "reply";
+ stream->write( (unsigned char*)msg.c_str(), 0, msg.length() );
+
+ synchronized(&serverThread.mutex)
+ {
+ serverThread.mutex.wait(300);
+ }
+
+ unsigned char buf[500];
+ memset( buf, 0, 500 );
+ io::InputStream* istream = client.getInputStream();
+ std::size_t numRead = istream->read( buf, 0, 500 );
+ CPPUNIT_ASSERT( numRead == 5 );
+ CPPUNIT_ASSERT( strcmp( (char*)buf, "hello" ) == 0 );
+
+ client.close();
+
+ serverThread.stop();
+ serverThread.join();
+
+ }catch( io::IOException& ex ){
+ printf( "%s\n", ex.getMessage().c_str() );
+ }
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/net/SocketTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/net/SocketTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/net/SocketTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/net/SocketTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,164 @@
+/*
+ * 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 _DECAF_NET_SOCKETTEST_H_
+#define _DECAF_NET_SOCKETTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/net/ServerSocket.h>
+#include <decaf/util/concurrent/Concurrent.h>
+#include <decaf/util/concurrent/Mutex.h>
+#include <decaf/lang/Thread.h>
+#include <list>
+#include <string.h>
+
+namespace decaf{
+namespace net{
+
+ class SocketTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( SocketTest );
+ CPPUNIT_TEST( testConnect );
+ CPPUNIT_TEST( testTx );
+ CPPUNIT_TEST( testTrx );
+ CPPUNIT_TEST( testTrxNoDelay );
+ CPPUNIT_TEST( testRxFail );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ static const int port = 23232;
+
+ class MyServerThread : public lang::Thread{
+ private:
+
+ bool done;
+ int numClients;
+ std::string lastMessage;
+
+ public:
+
+ util::concurrent::Mutex mutex;
+
+ public:
+
+ MyServerThread(){
+ done = false;
+ numClients = 0;
+ }
+
+ virtual ~MyServerThread(){
+ stop();
+ }
+
+ std::string getLastMessage(){
+ return lastMessage;
+ }
+
+ int getNumClients(){
+ return numClients;
+ }
+
+ virtual void stop(){
+ done = true;
+ }
+
+ virtual void run(){
+ try{
+ unsigned char buf[1000];
+
+ ServerSocket server;
+ server.bind( "127.0.0.1", port );
+
+ Socket* socket = server.accept();
+ server.close();
+
+ //socket->setSoTimeout( 10 );
+ socket->setSoLinger( false );
+ numClients++;
+
+ synchronized(&mutex)
+ {
+ mutex.notifyAll();
+ }
+
+ while( !done && socket != NULL ){
+
+ io::InputStream* stream = socket->getInputStream();
+
+ memset( buf, 0, 1000 );
+ try{
+
+ if( stream->read( buf, 0, 1000 ) == -1 ) {
+ done = true;
+ continue;
+ }
+
+ lastMessage = (char*)buf;
+
+ if( strcmp( (char*)buf, "reply" ) == 0 ){
+ io::OutputStream* output = socket->getOutputStream();
+ output->write( (unsigned char*)"hello", 0, strlen("hello" ) );
+
+ synchronized(&mutex)
+ {
+ mutex.notifyAll();
+ }
+ }
+
+ }catch( io::IOException& ex ){
+ done = true;
+ }
+ }
+
+ socket->close();
+ delete socket;
+
+ numClients--;
+
+ synchronized(&mutex)
+ {
+ mutex.notifyAll();
+ }
+
+ }catch( io::IOException& ex ){
+ printf("%s\n", ex.getMessage().c_str() );
+ CPPUNIT_ASSERT( false );
+ }catch( ... ){
+ CPPUNIT_ASSERT( false );
+ }
+ }
+
+ };
+
+ public:
+
+ virtual ~SocketTest() {}
+
+ void testConnect();
+ void testTx();
+ void testTrx();
+ void testRxFail();
+ void testTrxNoDelay();
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_SOCKETTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/net/URISyntaxExceptionTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/net/URISyntaxExceptionTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/net/URISyntaxExceptionTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/net/URISyntaxExceptionTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,42 @@
+/*
+ * 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 "URISyntaxExceptionTest.h"
+
+#include <decaf/net/URISyntaxException.h>
+
+using namespace decaf;
+using namespace decaf::net;
+
+////////////////////////////////////////////////////////////////////////////////
+URISyntaxExceptionTest::URISyntaxExceptionTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URISyntaxExceptionTest::test() {
+
+ URISyntaxException e1( __FILE__, __LINE__, "str", "problem", 2);
+ CPPUNIT_ASSERT_MESSAGE("returned incorrect reason",
+ e1.getReason() == "problem" );
+ CPPUNIT_ASSERT_MESSAGE("returned incorrect input", e1.getInput() == "str" );
+ CPPUNIT_ASSERT_MESSAGE("returned incorrect index", 2 == e1.getIndex());
+
+ URISyntaxException e2( __FILE__, __LINE__, "str", "problem");
+ CPPUNIT_ASSERT_MESSAGE("returned incorrect reason", e2.getReason() == "problem" );
+ CPPUNIT_ASSERT_MESSAGE("returned incorrect input", e2.getInput() == "str" );
+ CPPUNIT_ASSERT_MESSAGE("returned incorrect index", -1 == e2.getIndex());
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/net/URISyntaxExceptionTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/net/URISyntaxExceptionTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/net/URISyntaxExceptionTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/net/URISyntaxExceptionTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,43 @@
+/*
+ * 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 _DECAF_NET_URISYNTAXEXCEPTIONTEST_H_
+#define _DECAF_NET_URISYNTAXEXCEPTIONTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf{
+namespace net{
+
+ class URISyntaxExceptionTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( URISyntaxExceptionTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ URISyntaxExceptionTest();
+ virtual ~URISyntaxExceptionTest() {}
+
+ void test();
+ };
+
+}}
+
+#endif /*_DECAF_NET_URISYNTAXEXCEPTIONTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/net/URITest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/net/URITest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/net/URITest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/net/URITest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,156 @@
+/*
+ * 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 "URITest.h"
+
+#include <decaf/net/URI.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::net;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+URITest::URITest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URITest::test_Constructor_String() {
+
+// const std::string constructorTests[27] = {
+// "http://user@www.google.com:45/search?q=helpinfo#somefragment",
+// // http with authority, query and fragment
+// "ftp://ftp.is.co.za/rfc/rfc1808.txt", // ftp
+// "gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles",
+// // gopher
+// "mailto:mduerst@ifi.unizh.ch", // mailto
+// "news:comp.infosystems.www.servers.unix", // news
+// "telnet://melvyl.ucop.edu/", // telnet
+// "http://123.24.17.98/test", // IPv4 authority
+// "http://www.google.com:80/test",// domain name authority
+// "http://joe@[3ffe:2a00:100:7031::1]:80/test",
+// // IPv6 authority, with userinfo and port
+// "/relative", // relative starting with /
+// "//relative", // relative starting with //
+// "relative", // relative with no /
+// "#fragment",// relative just with fragment
+// "http://user@host:80", // UI, host,port
+// "http://user@host", // ui, host
+// "http://host", // host
+// "http://host:80", // host,port
+// "http://joe@:80", // ui, port (becomes registry-based)
+// "file:///foo/bar", // empty authority, non empty path
+// "ht?tp://hoe@host:80", // miscellaneous tests
+// "mai/lto:hey?joe#man", "http://host/a%20path#frag",
+// // path with an escaped octet for space char
+// "http://host/a%E2%82%ACpath#frag",
+// // path with escaped octet for unicode char, not USASCII
+// "http://host/a\u20ACpath#frag",
+// // path with unicode char, not USASCII equivalent to
+// // = "http://host/a\u0080path#frag",
+// "http://host%20name/", // escaped octets in host (becomes
+// // registry based)
+// "http://host\u00DFname/", // unicodechar in host (becomes
+// // registry based)
+// // equivalent to = "http://host\u00dfname/",
+// "ht123-+tp://www.google.com:80/test", // legal chars in scheme
+// };
+//
+// for( int i = 0; i < 27; i++ ) {
+// try {
+// new URI(constructorTests[i]);
+// } catch ( URISyntaxException e ) {
+// CPPUNIT_FAIL( string( "Failed to construct URI for: " ) +
+// constructorTests[i] + " : " +
+// e.getMessage() );
+// }
+// }
+
+ std::vector<const char*> constructorTestsInvalid;
+ // space char in path, not in escaped
+ constructorTestsInvalid.push_back( "http:///a path#frag" );
+ // octet form, with no host
+ constructorTestsInvalid.push_back( "http://host/a[path#frag" );
+ // an illegal char, not in escaped octet form, should throw an exception
+ // invalid escape sequence in path
+ constructorTestsInvalid.push_back( "http://host/a%path#frag" );
+ // incomplete escape sequence in path
+ constructorTestsInvalid.push_back( "http://host/a%#frag" );
+ // space char in fragment, not in
+ constructorTestsInvalid.push_back( "http://host#a frag" );
+ // escaped octet form, no path
+ // illegal char in fragment
+ constructorTestsInvalid.push_back( "http://host/a#fr#ag" );
+ // invalid escape sequence in fragment,
+ constructorTestsInvalid.push_back( "http:///path#fr%ag" );
+ // with no host
+ // incomplete escape sequence in fragment
+ constructorTestsInvalid.push_back( "http://host/path#frag%" );
+ // space char in query, not in escaped octet form
+ constructorTestsInvalid.push_back( "http://host/path?a query#frag" );
+ // invalid escape sequence in query, no path
+ constructorTestsInvalid.push_back( "http://host?query%ag" );
+ // incomplete escape sequence in query, with no host
+ constructorTestsInvalid.push_back( "http:///path?query%" );
+ // invalid char in scheme specific part
+ constructorTestsInvalid.push_back( "mailto:user^name@fklkf.com" );
+
+// for( size_t i = 0; i < constructorTestsInvalid.size(); i++ ) {
+// try {
+// new URI( constructorTestsInvalid[i] );
+// CPPUNIT_FAIL( string( "Failed to throw URISyntaxException for: " ) +
+// constructorTestsInvalid[i] );
+// } catch( URISyntaxException e ) {}
+// }
+
+// std::string invalid2[18] = {
+// // authority validation
+// "http://user@[3ffe:2x00:100:7031::1]:80/test", // malformed
+// // IPv6 authority
+// "http://[ipv6address]/apath#frag", // malformed ipv6 address
+// "http://[ipv6address/apath#frag", // malformed ipv6 address
+// "http://ipv6address]/apath#frag", // illegal char in host name
+// "http://ipv6[address/apath#frag",
+// "http://ipv6addr]ess/apath#frag",
+// "http://ipv6address[]/apath#frag",
+// // illegal char in username...
+// "http://us[]er@host/path?query#frag", "http://host name/path", // illegal
+// // char
+// // in
+// // authority
+// "http://host^name#fragment", // illegal char in authority
+// "telnet://us er@hostname/", // illegal char in authority
+// // missing components
+// "//", // Authority expected
+// "ascheme://", // Authority expected
+// "ascheme:", // Scheme-specific part expected
+// // scheme validation
+// "a scheme://reg/", // illegal char
+// "1scheme://reg/", // non alpha char as 1st char
+// "asche\u00dfme:ssp", // unicode char , not USASCII
+// "asc%20heme:ssp" // escape octets
+// };
+//
+// for( int i = 0; i < 18; i++ ) {
+// try {
+// new URI( invalid2[i] );
+// CPPUNIT_FAIL(
+// string( "Failed to throw URISyntaxException for: " ) + invalid2[i] );
+// } catch( URISyntaxException e ) {}
+// }
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/net/URITest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/net/URITest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/net/URITest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/net/URITest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,44 @@
+/*
+ * 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 _DECAF_NET_URITEST_H_
+#define _DECAF_NET_URITEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf{
+namespace net{
+
+ class URITest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( URITest );
+ CPPUNIT_TEST( test_Constructor_String );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ URITest();
+ virtual ~URITest() {}
+
+ void test_Constructor_String();
+
+ };
+
+}}
+
+#endif /*_DECAF_NET_URITEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/nio/BufferTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/nio/BufferTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/nio/BufferTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/nio/BufferTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,238 @@
+/*
+ * 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 "BufferTest.h"
+
+using namespace decaf;
+using namespace decaf::nio;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::test() {
+
+ // Check that we have setup the array and our initial assumptions on state
+ // are correct. This is the first test run.
+ CPPUNIT_ASSERT( buffer != NULL );
+ CPPUNIT_ASSERT( buffer->capacity() == DEFAULT_BUFFER_SIZE );
+ CPPUNIT_ASSERT( buffer->hasRemaining() == true );
+ CPPUNIT_ASSERT( buffer->limit() == buffer->capacity() );
+ CPPUNIT_ASSERT( buffer->position() == 0 );
+ CPPUNIT_ASSERT( buffer->isReadOnly() == false );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testCapacity() {
+
+ CPPUNIT_ASSERT( 0 == buffer->position() &&
+ buffer->position() <= buffer->limit() &&
+ buffer->limit() <= buffer->capacity() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testClear() {
+
+ Buffer& ret = buffer->clear();
+
+ CPPUNIT_ASSERT( &ret == buffer );
+ CPPUNIT_ASSERT( buffer->position() == 0 );
+ CPPUNIT_ASSERT( buffer->limit() == buffer->capacity() );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw InvalidMarkException",
+ buffer->reset(),
+ InvalidMarkException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testFlip() {
+
+ std::size_t oldPosition = buffer->position();
+
+ Buffer& ret = buffer->flip();
+ CPPUNIT_ASSERT( &ret == buffer );
+ CPPUNIT_ASSERT( buffer->position() == 0 );
+ CPPUNIT_ASSERT( buffer->limit() == oldPosition );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw InvalidMarkException",
+ buffer->reset(),
+ InvalidMarkException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testHasRemaining() {
+
+ CPPUNIT_ASSERT( buffer->hasRemaining() == ( buffer->position() < buffer->limit() ) );
+ buffer->position( buffer->limit() );
+ CPPUNIT_ASSERT( !buffer->hasRemaining() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testIsReadOnly() {
+
+ CPPUNIT_ASSERT( !buffer->isReadOnly() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testLimit() {
+
+ CPPUNIT_ASSERT( 0 == buffer->position() &&
+ buffer->position() <= buffer->limit() &&
+ buffer->limit() <= buffer->capacity() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testLimitInt() {
+
+ std::size_t oldPosition = buffer->position();
+ Buffer& ret = buffer->limit(buffer->limit());
+ CPPUNIT_ASSERT( &ret == buffer );
+
+ buffer->mark();
+ buffer->limit( buffer->capacity() );
+ CPPUNIT_ASSERT( buffer->limit() == buffer->capacity() );
+ // position should not change
+ CPPUNIT_ASSERT( buffer->position() == oldPosition );
+
+ // mark should be valid
+ buffer->reset();
+
+ buffer->limit(buffer->capacity());
+ buffer->position(buffer->capacity());
+ buffer->mark();
+ buffer->limit(buffer->capacity() - 1);
+ // position should be the new limit
+ CPPUNIT_ASSERT( buffer->position() == buffer->limit() );
+ // mark should be invalid
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw InvalidMarkException",
+ buffer->reset(),
+ InvalidMarkException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw IllegalArgumentException",
+ buffer->limit( buffer->capacity() + 1 ),
+ IllegalArgumentException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testMark() {
+
+ std::size_t oldPosition = buffer->position();
+ Buffer& ret = buffer->mark();
+ CPPUNIT_ASSERT( &ret == buffer );
+
+ buffer->mark();
+ buffer->position(buffer->limit());
+ buffer->reset();
+ CPPUNIT_ASSERT( buffer->position() == oldPosition);
+
+ buffer->mark();
+ buffer->position(buffer->limit());
+ buffer->reset();
+ CPPUNIT_ASSERT( buffer->position() == oldPosition);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testPosition() {
+
+ CPPUNIT_ASSERT( 0 == buffer->position() &&
+ buffer->position() <= buffer->limit() &&
+ buffer->limit() <= buffer->capacity() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testPositionInt() {
+
+ std::size_t oldPosition = buffer->position();
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw IllegalArgumentException",
+ buffer->position( buffer->limit() + 1 ),
+ IllegalArgumentException );
+
+ buffer->mark();
+ buffer->position(buffer->position());
+ buffer->reset();
+ CPPUNIT_ASSERT( buffer->position() == oldPosition );
+
+ buffer->position(0);
+ CPPUNIT_ASSERT( buffer->position() == 0 );
+ buffer->position(buffer->limit());
+ CPPUNIT_ASSERT( buffer->position() == buffer->limit() );
+
+ if (buffer->capacity() > 0) {
+ buffer->limit( buffer->capacity() );
+ buffer->position( buffer->limit() );
+ buffer->mark();
+ buffer->position( buffer->limit() - 1);
+ CPPUNIT_ASSERT( buffer->position() == buffer->limit() - 1 );
+
+ // mark should be invalid
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw InvalidMarkException",
+ buffer->reset(),
+ InvalidMarkException );
+ }
+
+ Buffer& ret = buffer->position(0);
+ CPPUNIT_ASSERT( &ret == buffer );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testRemaining() {
+ CPPUNIT_ASSERT( buffer->remaining() == ( buffer->limit() - buffer->position() ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testReset() {
+
+ std::size_t oldPosition = buffer->position();
+
+ buffer->mark();
+ buffer->position(buffer->limit());
+ buffer->reset();
+ CPPUNIT_ASSERT( buffer->position() == oldPosition );
+
+ buffer->mark();
+ buffer->position(buffer->limit());
+ buffer->reset();
+ CPPUNIT_ASSERT( buffer->position() == oldPosition );
+
+ Buffer& ret = buffer->reset();
+ CPPUNIT_ASSERT( &ret == buffer );
+
+ buffer->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw InvalidMarkException",
+ buffer->reset(),
+ InvalidMarkException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testRewind() {
+
+ Buffer& ret = buffer->rewind();
+ CPPUNIT_ASSERT( buffer->position() == 0 );
+ CPPUNIT_ASSERT( &ret == buffer );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw InvalidMarkException",
+ buffer->reset(),
+ InvalidMarkException );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/nio/BufferTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/nio/BufferTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/nio/BufferTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/nio/BufferTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,98 @@
+/*
+ * 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 _DECAF_NIO_BUFFERTEST_H_
+#define _DECAF_NIO_BUFFERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/nio/Buffer.h>
+
+namespace decaf{
+namespace nio{
+
+ class BufferTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( BufferTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST( testCapacity );
+ CPPUNIT_TEST( testClear );
+ CPPUNIT_TEST( testFlip );
+ CPPUNIT_TEST( testHasRemaining );
+ CPPUNIT_TEST( testIsReadOnly );
+ CPPUNIT_TEST( testLimit );
+ CPPUNIT_TEST( testLimitInt );
+ CPPUNIT_TEST( testMark );
+ CPPUNIT_TEST( testPosition );
+ CPPUNIT_TEST( testPositionInt );
+ CPPUNIT_TEST( testRemaining );
+ CPPUNIT_TEST( testReset );
+ CPPUNIT_TEST( testRewind );
+ CPPUNIT_TEST_SUITE_END();
+
+ private:
+
+ Buffer* buffer;
+
+ static const std::size_t DEFAULT_BUFFER_SIZE = 512;
+
+ class MyBuffer : public Buffer {
+ public:
+
+ MyBuffer( std::size_t capacity ) : Buffer( capacity ) {
+ }
+
+ virtual ~MyBuffer() {}
+
+ bool isReadOnly() const { return false; }
+ };
+
+ public:
+
+ BufferTest() {}
+ virtual ~BufferTest() {}
+
+ void setUp() {
+ buffer = new MyBuffer( DEFAULT_BUFFER_SIZE );
+ }
+
+ void tearDown() {
+ delete buffer;
+ buffer = NULL;
+ }
+
+ void test();
+ void testCapacity();
+ void testClear();
+ void testFlip();
+ void testHasRemaining();
+ void testIsReadOnly();
+ void testLimit();
+ void testLimitInt();
+ void testMark();
+ void testPosition();
+ void testPositionInt();
+ void testRemaining();
+ void testReset();
+ void testRewind();
+
+ };
+
+}}
+
+#endif /*_DECAF_NIO_BUFFERTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/DateTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/DateTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/DateTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/DateTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,42 @@
+/*
+ * 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 "DateTest.h"
+
+#include <decaf/util/Date.h>
+#include <decaf/lang/Thread.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::util;
+using namespace decaf::lang;
+
+void DateTest::test(){
+
+ Date date1;
+ CPPUNIT_ASSERT( date1.getTime() != 0 );
+
+ decaf::lang::Thread::sleep(55);
+
+ Date date2;
+
+ CPPUNIT_ASSERT( date1.before(date2) == true );
+ CPPUNIT_ASSERT( date1.after(date2) == false );
+
+ Date date3 = date1;
+ CPPUNIT_ASSERT( date1.equals( date3 ) == true );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/DateTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/DateTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/DateTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/DateTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,43 @@
+/*
+ * 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 _DECAF_UTIL_DATETEST_H_
+#define _DECAF_UTIL_DATETEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf{
+namespace util{
+
+ class DateTest : public CppUnit::TestFixture
+ {
+ CPPUNIT_TEST_SUITE( DateTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ DateTest(){};
+ virtual ~DateTest(){};
+
+ void test();
+
+ };
+
+}}
+
+#endif /*_DECAF_UTIL_DATETEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/Endian.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/Endian.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/Endian.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/Endian.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,117 @@
+/*
+ * 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 "Endian.h"
+#include <decaf/util/Config.h>
+#include <string.h>
+
+using namespace decaf;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+void Endian::byteSwap(unsigned char* data, int dataLength) {
+
+ #ifdef WORDS_BIGENDIAN
+ return;
+ #endif
+
+ for (int i = 0; i<dataLength/2; i++) {
+ unsigned char temp = data[i];
+ data[i] = data[dataLength-1-i];
+ data[dataLength-1-i] = temp;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char Endian::byteSwap( unsigned char value ){
+
+ #ifdef WORDS_BIGENDIAN
+ return value;
+ #endif
+
+ return value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned short Endian::byteSwap( unsigned short value ){
+
+ #ifdef WORDS_BIGENDIAN
+ return value;
+ #endif
+
+ return (((unsigned short)value & 0xFF00 ) >> 8 ) |
+ (((unsigned short)value & 0x00FF ) << 8 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned int Endian::byteSwap( unsigned int value ){
+
+ #ifdef WORDS_BIGENDIAN
+ return value;
+ #endif
+
+ return (((unsigned int)value & 0xFF000000 ) >> 24 ) |
+ (((unsigned int)value & 0x00FF0000 ) >> 8 ) |
+ (((unsigned int)value & 0x0000FF00 ) << 8 ) |
+ (((unsigned int)value & 0x000000FF ) << 24 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned long long Endian::byteSwap( unsigned long long value ){
+
+ #ifdef WORDS_BIGENDIAN
+ return value;
+ #endif
+
+ return (((unsigned long long)value & 0xFF00000000000000ULL ) >> 56 ) |
+ (((unsigned long long)value & 0x00FF000000000000ULL ) >> 40 ) |
+ (((unsigned long long)value & 0x0000FF0000000000ULL ) >> 24 ) |
+ (((unsigned long long)value & 0x000000FF00000000ULL ) >> 8 ) |
+ (((unsigned long long)value & 0x00000000FF000000ULL ) << 8 ) |
+ (((unsigned long long)value & 0x0000000000FF0000ULL ) << 24 ) |
+ (((unsigned long long)value & 0x000000000000FF00ULL ) << 40 ) |
+ (((unsigned long long)value & 0x00000000000000FFULL ) << 56 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float Endian::byteSwap( float value ){
+
+ #ifdef WORDS_BIGENDIAN
+ return value;
+ #endif
+
+ unsigned int lvalue = 0;
+ memcpy( &lvalue, &value, sizeof( float ) );
+ lvalue = byteSwap( lvalue );
+ memcpy( &value, &lvalue, sizeof( unsigned int ) );
+ return value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double Endian::byteSwap( double value ){
+
+ #ifdef WORDS_BIGENDIAN
+ return value;
+ #endif
+
+ unsigned long long lvalue = 0;
+ memcpy( &lvalue, &value, sizeof( double ) );
+ lvalue = byteSwap( lvalue );
+ memcpy( &value, &lvalue, sizeof( unsigned long long ) );
+ return value;
+}
+
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/Endian.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/Endian.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/Endian.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/Endian.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,43 @@
+/*
+ * 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 _DECAF_UTIL_ENDIAN_H
+#define _DECAF_UTIL_ENDIAN_H
+
+namespace decaf{
+namespace util{
+
+ class Endian{
+ public:
+
+ static void byteSwap(unsigned char* data, int dataLength);
+
+ static unsigned char byteSwap( unsigned char value );
+
+ static unsigned short byteSwap( unsigned short value );
+
+ static unsigned int byteSwap( unsigned int value );
+
+ static unsigned long long byteSwap( unsigned long long value );
+
+ static float byteSwap( float value );
+
+ static double byteSwap( double value );
+ };
+
+}}
+
+#endif /*_DECAF_UTIL_ENDIAN_H*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/MapTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/MapTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/MapTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/MapTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,119 @@
+/*
+ * 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 "MapTest.h"
+#include <string>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+MapTest::MapTest(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+MapTest::~MapTest(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void MapTest::testContainsKey(){
+
+ Map<string, bool> boolMap;
+ CPPUNIT_ASSERT(boolMap.containsKey("bob") == false);
+
+ boolMap.setValue( "bob", true );
+
+ CPPUNIT_ASSERT(boolMap.containsKey("bob") == true );
+ CPPUNIT_ASSERT(boolMap.containsKey("fred") == false );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void MapTest::testClear(){
+
+ Map<string, bool> boolMap;
+ boolMap.setValue( "bob", true );
+ boolMap.setValue( "fred", true );
+
+ CPPUNIT_ASSERT(boolMap.size() == 2 );
+ boolMap.clear();
+ CPPUNIT_ASSERT(boolMap.size() == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void MapTest::testIsEmpty(){
+
+ Map<string, bool> boolMap;
+ boolMap.setValue( "bob", true );
+ boolMap.setValue( "fred", true );
+
+ CPPUNIT_ASSERT(boolMap.isEmpty() == false );
+ boolMap.clear();
+ CPPUNIT_ASSERT(boolMap.isEmpty() == true );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void MapTest::testSize(){
+
+ Map<string, bool> boolMap;
+
+ CPPUNIT_ASSERT(boolMap.size() == 0 );
+ boolMap.setValue( "bob", true );
+ CPPUNIT_ASSERT(boolMap.size() == 1 );
+ boolMap.setValue( "fred", true );
+ CPPUNIT_ASSERT(boolMap.size() == 2 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void MapTest::testValue(){
+
+ Map<string, bool> boolMap;
+
+ boolMap.setValue( "fred", true );
+ CPPUNIT_ASSERT( boolMap.getValue("fred") == true );
+
+ boolMap.setValue( "bob", false );
+ CPPUNIT_ASSERT( boolMap.getValue("bob") == false );
+ CPPUNIT_ASSERT( boolMap.getValue("fred") == true );
+
+ try{
+ boolMap.getValue( "mike" );
+ CPPUNIT_ASSERT(false);
+ } catch( decaf::lang::exceptions::NoSuchElementException& e ){
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void MapTest::testRemove(){
+ Map<string, bool> boolMap;
+
+ boolMap.setValue( "fred", true );
+ CPPUNIT_ASSERT( boolMap.containsKey("fred") == true );
+ boolMap.remove( "fred" );
+ CPPUNIT_ASSERT( boolMap.containsKey("fred") == false );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void MapTest::testContiansValue(){
+ Map<string, bool> boolMap;
+
+ boolMap.setValue( "fred", true );
+ boolMap.setValue( "fred1", false );
+ CPPUNIT_ASSERT( boolMap.containsValue(true) == true );
+ boolMap.remove( "fred" );
+ CPPUNIT_ASSERT( boolMap.containsValue(true) == false );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/MapTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/MapTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/MapTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/MapTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,57 @@
+/*
+ * 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 _DECAF_UTIL_MAPTEST_H_
+#define _DECAF_UTIL_MAPTEST_H_
+
+#include <decaf/util/Map.h>
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf{
+namespace util{
+
+ class MapTest : public CppUnit::TestFixture
+ {
+ CPPUNIT_TEST_SUITE( MapTest );
+ CPPUNIT_TEST( testContainsKey );
+ CPPUNIT_TEST( testClear );
+ CPPUNIT_TEST( testSize );
+ CPPUNIT_TEST( testValue );
+ CPPUNIT_TEST( testRemove );
+ CPPUNIT_TEST( testContiansValue );
+ CPPUNIT_TEST( testIsEmpty );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ MapTest();
+ virtual ~MapTest();
+
+ void testContainsKey();
+ void testClear();
+ void testSize();
+ void testValue();
+ void testRemove();
+ void testContiansValue();
+ void testIsEmpty();
+
+ };
+
+}}
+
+#endif /*_DECAF_UTIL_MAPTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/QueueTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/QueueTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/QueueTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/QueueTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,47 @@
+/*
+ * 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 "QueueTest.h"
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+void QueueTest::test()
+{
+ Queue<char> q;
+
+ CPPUNIT_ASSERT( q.empty() == true );
+ CPPUNIT_ASSERT( q.size() == 0 );
+
+ q.push('a');
+
+ CPPUNIT_ASSERT( q.front() == 'a' );
+
+ q.pop();
+
+ CPPUNIT_ASSERT( q.empty() == true );
+
+ q.push('b');
+ q.push('c');
+
+ CPPUNIT_ASSERT( q.size() == 2 );
+
+ CPPUNIT_ASSERT( q.front() == 'b' );
+ CPPUNIT_ASSERT( q.back() == 'c' );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/QueueTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/QueueTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/QueueTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/QueueTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,44 @@
+/*
+ * 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 _DECAF_UTIL_QUEUETEST_H_
+#define _DECAF_UTIL_QUEUETEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/util/Queue.h>
+
+namespace decaf{
+namespace util{
+
+ class QueueTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( QueueTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ virtual ~QueueTest() {}
+
+ void test();
+ };
+
+}}
+
+#endif /*_DECAF_UTIL_QUEUETEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/RandomTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/RandomTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/RandomTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/RandomTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,84 @@
+/*
+ * 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 "RandomTest.h"
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::util;
+
+void RandomTest::test(){
+
+ Random rand(122760);
+ CPPUNIT_ASSERT_EQUAL(-1524104671, rand.nextInt());
+ CPPUNIT_ASSERT_EQUAL(2785759620113032781LL, rand.nextLong());
+ CPPUNIT_ASSERT_EQUAL(rand.nextDouble(), 0.8173322904425151);
+ CPPUNIT_ASSERT_EQUAL(rand.nextFloat(), 0.8239248f);
+
+ std::vector<unsigned char> b(0);
+ rand.nextBytes(b);
+ CPPUNIT_ASSERT_EQUAL(-899478426, rand.nextInt());
+
+ rand = Random(122760);
+ rand.nextInt();
+ rand.nextLong();
+ rand.nextDouble();
+ rand.nextFloat();
+ b = std::vector<unsigned char>(3);
+ rand.nextBytes(b);
+ CPPUNIT_ASSERT_EQUAL((unsigned char)102, b[0]);
+ CPPUNIT_ASSERT_EQUAL((unsigned char)12, b[1]);
+ CPPUNIT_ASSERT_EQUAL((unsigned char)99, b[2]);
+ CPPUNIT_ASSERT_EQUAL(-1550323395, rand.nextInt());
+
+ rand = Random(122760);
+ rand.nextInt();
+ rand.nextLong();
+ rand.nextDouble();
+ rand.nextFloat();
+ b = std::vector<unsigned char>(4);
+ rand.nextBytes(b);
+ CPPUNIT_ASSERT_EQUAL((unsigned char)102, b[0]);
+ CPPUNIT_ASSERT_EQUAL((unsigned char)12, b[1]);
+ CPPUNIT_ASSERT_EQUAL((unsigned char)99, b[2]);
+ CPPUNIT_ASSERT_EQUAL((unsigned char)-54, b[3]);
+ CPPUNIT_ASSERT_EQUAL(-1550323395, rand.nextInt());
+
+ rand = Random(122760);
+ rand.nextInt();
+ rand.nextLong();
+ rand.nextDouble();
+ rand.nextFloat();
+ b = std::vector<unsigned char>(5);
+ rand.nextBytes(b);
+ CPPUNIT_ASSERT_EQUAL((unsigned char)102, b[0]);
+ CPPUNIT_ASSERT_EQUAL((unsigned char)12, b[1]);
+ CPPUNIT_ASSERT_EQUAL((unsigned char)99, b[2]);
+ CPPUNIT_ASSERT_EQUAL((unsigned char)-54, b[3]);
+ CPPUNIT_ASSERT_EQUAL((unsigned char)61, b[4]);
+ CPPUNIT_ASSERT_EQUAL(-270809961, rand.nextInt());
+
+ bool ok = true;
+ rand = Random(0);
+ for (int i=0; i < 1000000; ++i) {
+ int x = rand.nextInt(1000);
+ if (x < 0 || x >= 1000) {
+ ok = false;
+ }
+ }
+ CPPUNIT_ASSERT(ok);
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/RandomTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/RandomTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/RandomTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/RandomTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,45 @@
+/*
+ * 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 _DECAF_UTIL_RANDOMTEST_H_
+#define _DECAF_UTIL_RANDOMTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/util/Random.h>
+
+namespace decaf{
+namespace util{
+
+ class RandomTest : public CppUnit::TestFixture
+ {
+ CPPUNIT_TEST_SUITE( RandomTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ RandomTest(){}
+ virtual ~RandomTest(){}
+
+ void test();
+ };
+
+}}
+
+#endif /*_DECAF_UTIL_RANDOMTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/SetTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/SetTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/SetTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/SetTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,147 @@
+/*
+ * 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 "SetTest.h"
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+SetTest::SetTest(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SetTest::testContains(){
+
+ Set<string> set;
+ CPPUNIT_ASSERT( set.contains( "bob" ) == false);
+
+ set.add( "bob" );
+
+ CPPUNIT_ASSERT(set.contains( "bob" ) == true );
+ CPPUNIT_ASSERT(set.contains( "fred" ) == false );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SetTest::testClear(){
+
+ Set<string> set;
+ set.add( "bob" );
+ set.add( "fred" );
+
+ CPPUNIT_ASSERT( set.size() == 2 );
+ set.clear();
+ CPPUNIT_ASSERT( set.size() == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SetTest::testIsEmpty(){
+
+ Set<string> set;
+ set.add( "bob" );
+ set.add( "fred" );
+
+ CPPUNIT_ASSERT(set.isEmpty() == false );
+ set.clear();
+ CPPUNIT_ASSERT(set.isEmpty() == true );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SetTest::testSize(){
+
+ Set<string> set;
+
+ CPPUNIT_ASSERT( set.size() == 0 );
+ set.add( "bob" );
+ CPPUNIT_ASSERT( set.size() == 1 );
+ set.add( "fred" );
+ CPPUNIT_ASSERT( set.size() == 2 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SetTest::testAdd(){
+ Set<string> set;
+
+ set.add( "fred" );
+ set.add( "fred" );
+ set.add( "fred" );
+ CPPUNIT_ASSERT( set.contains("fred") == true );
+ CPPUNIT_ASSERT( set.size() == 1 );
+ set.remove( "fred" );
+ CPPUNIT_ASSERT( set.contains("fred") == false );
+ CPPUNIT_ASSERT( set.isEmpty() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SetTest::testRemove(){
+ Set<string> set;
+
+ set.add( "fred" );
+ CPPUNIT_ASSERT( set.contains( "fred" ) == true );
+ set.remove( "fred" );
+ CPPUNIT_ASSERT( set.contains( "fred" ) == false );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SetTest::testToArray(){
+
+ Set<string> set;
+
+ set.add( "fred1" );
+ set.add( "fred2" );
+ set.add( "fred3" );
+ CPPUNIT_ASSERT( set.size() == 3 );
+
+ std::vector<std::string> array = set.toArray();
+
+ CPPUNIT_ASSERT( array.size() == 3 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SetTest::testIterator(){
+
+ Set<string> set;
+
+ set.add( "fred1" );
+ set.add( "fred2" );
+ set.add( "fred3" );
+
+ Iterator<string>* iterator1 = set.iterator();
+ CPPUNIT_ASSERT( iterator1 != NULL );
+ CPPUNIT_ASSERT( iterator1->hasNext() == true );
+
+ size_t count = 0;
+ while( iterator1->hasNext() ) {
+ iterator1->next();
+ ++count;
+ }
+
+ CPPUNIT_ASSERT( count == set.size() );
+
+ Iterator<string>* iterator2 = set.iterator();
+
+ while( iterator2->hasNext() ) {
+ iterator2->next();
+ iterator2->remove();
+ }
+
+ CPPUNIT_ASSERT( set.isEmpty() );
+
+ delete iterator1;
+ delete iterator2;
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/SetTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/SetTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/SetTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/SetTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,61 @@
+/*
+ * 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 _DECAF_UTIL_SETTEST_H_
+#define _DECAF_UTIL_SETTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/util/Set.h>
+#include <decaf/util/Iterator.h>
+
+namespace decaf{
+namespace util{
+
+ class SetTest : public CppUnit::TestFixture
+ {
+ CPPUNIT_TEST_SUITE( SetTest );
+ CPPUNIT_TEST( testContains );
+ CPPUNIT_TEST( testClear );
+ CPPUNIT_TEST( testSize );
+ CPPUNIT_TEST( testAdd );
+ CPPUNIT_TEST( testRemove );
+ CPPUNIT_TEST( testIsEmpty );
+ CPPUNIT_TEST( testToArray );
+ CPPUNIT_TEST( testIterator );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ SetTest();
+ virtual ~SetTest() {}
+
+ void testContains();
+ void testClear();
+ void testSize();
+ void testAdd();
+ void testRemove();
+ void testIsEmpty();
+ void testToArray();
+ void testIterator();
+
+ };
+
+}}
+
+#endif /*_DECAF_UTIL_SETTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/StringTokenizerTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/StringTokenizerTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/StringTokenizerTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/StringTokenizerTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,97 @@
+/*
+ * 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 "StringTokenizerTest.h"
+#include <decaf/util/StringTokenizer.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+void StringTokenizerTest::test()
+{
+ StringTokenizer tokenizer("stomp://127.0.0.1:23232", "://");
+ CPPUNIT_ASSERT( tokenizer.countTokens() == 3 );
+ CPPUNIT_ASSERT( tokenizer.nextToken() == "stomp" );
+ CPPUNIT_ASSERT( tokenizer.nextToken() == "127.0.0.1" );
+ CPPUNIT_ASSERT( tokenizer.nextToken() == "23232" );
+
+ StringTokenizer tokenizer1("::://stomp://127.0.0.1:23232:", ":/");
+ CPPUNIT_ASSERT( tokenizer1.countTokens() == 3 );
+ CPPUNIT_ASSERT( tokenizer1.nextToken() == "stomp" );
+ CPPUNIT_ASSERT( tokenizer1.nextToken() == "127.0.0.1" );
+ CPPUNIT_ASSERT( tokenizer1.nextToken() == "23232" );
+
+ StringTokenizer tokenizer2("test");
+ CPPUNIT_ASSERT( tokenizer2.countTokens() == 1 );
+ CPPUNIT_ASSERT( tokenizer2.hasMoreTokens() == true );
+ CPPUNIT_ASSERT( tokenizer2.nextToken() == "test" );
+ CPPUNIT_ASSERT( tokenizer2.hasMoreTokens() == false );
+
+ StringTokenizer tokenizer3(":", ":");
+ CPPUNIT_ASSERT( tokenizer3.countTokens() == 0 );
+ CPPUNIT_ASSERT( tokenizer3.hasMoreTokens() == false );
+ CPPUNIT_ASSERT( tokenizer3.nextToken(" ") == ":" );
+
+ try
+ {
+ tokenizer3.nextToken();
+ CPPUNIT_ASSERT( false );
+ }
+ catch(lang::exceptions::NoSuchElementException ex)
+ {
+ CPPUNIT_ASSERT( true );
+ }
+
+ StringTokenizer tokenizer4("the quick brown fox");
+ CPPUNIT_ASSERT( tokenizer4.countTokens() == 4 );
+ CPPUNIT_ASSERT( tokenizer4.hasMoreTokens() == true );
+ CPPUNIT_ASSERT( tokenizer4.nextToken() == "the" );
+ CPPUNIT_ASSERT( tokenizer4.nextToken() == "quick" );
+ CPPUNIT_ASSERT( tokenizer4.nextToken() == "brown" );
+ CPPUNIT_ASSERT( tokenizer4.nextToken() == "fox" );
+ CPPUNIT_ASSERT( tokenizer4.countTokens() == 0 );
+ CPPUNIT_ASSERT( tokenizer4.hasMoreTokens() == false );
+
+ StringTokenizer tokenizer5("the:quick:brown:fox", ":", true);
+ CPPUNIT_ASSERT( tokenizer5.countTokens() == 7 );
+ CPPUNIT_ASSERT( tokenizer5.hasMoreTokens() == true );
+ CPPUNIT_ASSERT( tokenizer5.nextToken() == "the" );
+ CPPUNIT_ASSERT( tokenizer5.nextToken() == ":" );
+ CPPUNIT_ASSERT( tokenizer5.nextToken() == "quick" );
+ CPPUNIT_ASSERT( tokenizer5.nextToken() == ":" );
+ CPPUNIT_ASSERT( tokenizer5.nextToken() == "brown" );
+ CPPUNIT_ASSERT( tokenizer5.nextToken() == ":" );
+ CPPUNIT_ASSERT( tokenizer5.nextToken() == "fox" );
+ CPPUNIT_ASSERT( tokenizer5.countTokens() == 0 );
+ CPPUNIT_ASSERT( tokenizer5.hasMoreTokens() == false );
+
+ std::vector<std::string> myArray;
+ StringTokenizer tokenizer6("the:quick:brown:fox", ":");
+ CPPUNIT_ASSERT( tokenizer6.countTokens() == 4 );
+ CPPUNIT_ASSERT( tokenizer6.toArray(myArray) == 4 );
+ CPPUNIT_ASSERT( tokenizer6.countTokens() == 0 );
+ tokenizer6.reset();
+ CPPUNIT_ASSERT( tokenizer6.countTokens() == 4 );
+ tokenizer6.reset("the:quick:brown:fox", "$");
+ CPPUNIT_ASSERT( tokenizer6.countTokens() == 1 );
+ tokenizer6.reset("this$is$a$test");
+ CPPUNIT_ASSERT( tokenizer6.countTokens() == 4 );
+ tokenizer6.reset("this$is$a$test", "$", true);
+ CPPUNIT_ASSERT( tokenizer6.countTokens() == 7 );
+}