Modified: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/MutexTest.h URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/MutexTest.h?rev=419365&r1=419364&r2=419365&view=diff ============================================================================== --- incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/MutexTest.h (original) +++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/MutexTest.h Wed Jul 5 15:27:34 2006 @@ -1,593 +1,593 @@ -#ifndef ACTIVEMQ_CONCURRENT_MUTEXTEST_H_ -#define ACTIVEMQ_CONCURRENT_MUTEXTEST_H_ - -#include -#include - -#include -#include -#include -#include - -namespace activemq{ -namespace concurrent{ - - class MutexTest : public CppUnit::TestFixture { - - CPPUNIT_TEST_SUITE( MutexTest ); - CPPUNIT_TEST( test ); - CPPUNIT_TEST( testWait ); - CPPUNIT_TEST( testTimedWait ); - CPPUNIT_TEST( testNotify ); - CPPUNIT_TEST( testNotifyAll ); - CPPUNIT_TEST( testRecursiveLock ); - CPPUNIT_TEST( testDoubleLock ); - CPPUNIT_TEST_SUITE_END(); - - public: - - class MyThread - : - public Thread, - public Synchronizable{ - - private: - - Mutex mutex; - - public: - - int value; - MyThread(){ value = 0;} - virtual ~MyThread(){} - - virtual void lock() throw(exceptions::ActiveMQException){ - mutex.lock(); - } - virtual void unlock() throw(exceptions::ActiveMQException){ - mutex.unlock(); - } - virtual void wait() throw(exceptions::ActiveMQException){ - mutex.wait(); - } - virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){ - mutex.wait( millisecs ); - } - virtual void notify() throw(exceptions::ActiveMQException){ - mutex.notify(); - } - virtual void notifyAll() throw(exceptions::ActiveMQException){ - mutex.notifyAll(); - } - - virtual void run(){ - - { - Lock lock (this); - - value = value * 25; - } - } - - }; - - class MyWaitingThread - : - public Thread, - public Synchronizable{ - - private: - - Mutex mutex; - - public: - - int value; - MyWaitingThread(){ value = 0;} - virtual ~MyWaitingThread(){} - virtual void lock() throw(exceptions::ActiveMQException){ - mutex.lock(); - } - virtual void unlock() throw(exceptions::ActiveMQException){ - mutex.unlock(); - } - virtual void wait() throw(exceptions::ActiveMQException){ - mutex.wait(); - } - virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){ - mutex.wait( millisecs ); - } - virtual void notify() throw(exceptions::ActiveMQException){ - mutex.notify(); - } - virtual void notifyAll() throw(exceptions::ActiveMQException){ - mutex.notifyAll(); - } - - virtual void run(){ - - try - { - synchronized(this) - { - this->wait(); - - std::cout.flush(); - - value = value * 25; - } - } - catch(exceptions::ActiveMQException& ex) - { - ex.setMark( __FILE__, __LINE__ ); - } - } - }; - - class MyTimedWaitingThread - : - public Thread, - public Synchronizable{ - - private: - - Mutex mutex; - - public: - - int value; - MyTimedWaitingThread(){ value = 0;} - virtual ~MyTimedWaitingThread(){} - virtual void lock() throw(exceptions::ActiveMQException){ - mutex.lock(); - } - virtual void unlock() throw(exceptions::ActiveMQException){ - mutex.unlock(); - } - virtual void wait() throw(exceptions::ActiveMQException){ - mutex.wait(); - } - virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){ - mutex.wait( millisecs ); - } - virtual void notify() throw(exceptions::ActiveMQException){ - mutex.notify(); - } - virtual void notifyAll() throw(exceptions::ActiveMQException){ - mutex.notifyAll(); - } - - virtual void run(){ - - try - { - synchronized(this) - { - this->wait(2000); - - value = 666; - } - } - catch(exceptions::ActiveMQException& ex) - { - ex.setMark( __FILE__, __LINE__ ); - } - } - }; - - class MyNotifiedThread - : - public Thread, - public Synchronizable{ - - public: - - bool done; - Mutex* mutex; - - public: - - int value; - MyNotifiedThread(Mutex* mutex){ this->mutex = mutex; done = false; } - virtual ~MyNotifiedThread(){} - virtual void lock() throw(exceptions::ActiveMQException){ - mutex->lock(); - } - virtual void unlock() throw(exceptions::ActiveMQException){ - mutex->unlock(); - } - virtual void wait() throw(exceptions::ActiveMQException){ - mutex->wait(); - } - virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){ - mutex->wait( millisecs ); - } - virtual void notify() throw(exceptions::ActiveMQException){ - mutex->notify(); - } - virtual void notifyAll() throw(exceptions::ActiveMQException){ - mutex->notifyAll(); - } - - virtual void run(){ - - try - { - done = false; - synchronized(this) - { - this->wait(); - done = true; - } - } - catch(exceptions::ActiveMQException& ex) - { - ex.setMark( __FILE__, __LINE__ ); - } - } - }; - - class MyRecursiveLockThread - : - public Thread, - public Synchronizable{ - - public: - - bool done; - Mutex* mutex; - - public: - - int value; - MyRecursiveLockThread(Mutex* mutex){ this->mutex = mutex; done = false; } - virtual ~MyRecursiveLockThread(){} - virtual void lock() throw(exceptions::ActiveMQException){ - mutex->lock(); - } - virtual void unlock() throw(exceptions::ActiveMQException){ - mutex->unlock(); - } - virtual void wait() throw(exceptions::ActiveMQException){ - mutex->wait(); - } - virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){ - mutex->wait( millisecs ); - } - virtual void notify() throw(exceptions::ActiveMQException){ - mutex->notify(); - } - virtual void notifyAll() throw(exceptions::ActiveMQException){ - mutex->notifyAll(); - } - - virtual void run(){ - - try - { - done = false; - synchronized(this) - { - synchronized(this) - { - this->wait(); - done = true; - } - } - } - catch(exceptions::ActiveMQException& ex) - { - ex.setMark( __FILE__, __LINE__ ); - } - } - }; - - class MyDoubleLockThread - : - public Thread - { - - public: - - bool done; - Mutex* mutex1; - Mutex* mutex2; - - public: - - int value; - MyDoubleLockThread(Mutex* mutex1, Mutex* mutex2) - { - this->mutex1 = mutex1; - this->mutex2 = mutex2; - done = false; - } - - virtual ~MyDoubleLockThread(){} - - virtual void run(){ - - try - { - done = false; - synchronized(mutex1) - { - synchronized(mutex2) - { - mutex2->wait(); - done = true; - } - } - } - catch(exceptions::ActiveMQException& ex) - { - ex.setMark( __FILE__, __LINE__ ); - } - } - }; - - public: - - virtual void setUp(){}; - virtual void tearDown(){}; - - void testTimedWait(){ - - try - { - MyTimedWaitingThread test; - time_t startTime = time( NULL ); - test.start(); - test.join(); - time_t endTime = time( NULL ); - - long delta = endTime - startTime; - - CPPUNIT_ASSERT( delta >= 1 && delta <= 3 ); - } - catch(exceptions::ActiveMQException& ex) - { - std::cout << ex.getMessage() << std::endl; - } - } - - void testWait(){ - - try - { - MyWaitingThread test; - test.start(); - - Thread::sleep(1000); - - synchronized(&test) - { - for( int ix=0; ix<100; ix++ ){ - test.value += 1; - } - - test.notify(); - } - - test.join(); - - CPPUNIT_ASSERT( test.value == 2500 ); - - } - catch(exceptions::ActiveMQException& ex) - { - ex.setMark( __FILE__, __LINE__ ); - } - } - - void test() - { - MyThread test; - test.lock(); - - test.start(); - - for( int ix=0; ix<100; ix++ ){ - test.value += 1; - } - - test.unlock(); - test.join(); - - CPPUNIT_ASSERT( test.value == 2500 ); - } - - void testNotify() - { - try{ - Mutex mutex; - const int numThreads = 30; - MyNotifiedThread* threads[numThreads]; - - // Create and start all the threads. - for( int ix=0; ixstart(); - } - - // Sleep so all the threads can get to the wait. - Thread::sleep( 1000 ); - - synchronized(&mutex) - { - mutex.notify(); - } - - Thread::sleep( 1000 ); - - int counter = 0; - for( int ix=0; ixdone ){ - counter++; - } - } - - // Make sure only 1 thread was notified. - CPPUNIT_ASSERT( counter == 1 ); - - synchronized(&mutex) - { - // Notify all threads. - for( int ix=0; ixdone ){ - numComplete++; - } - } - CPPUNIT_ASSERT( numComplete == numThreads ); - - synchronized( &mutex ) - { - mutex.wait( 5 ); - } - - synchronized( &mutex ) - { - mutex.notifyAll(); - } - - }catch( exceptions::ActiveMQException& ex ){ - ex.setMark( __FILE__, __LINE__ ); - } - } - - void testNotifyAll() - { - try{ - Mutex mutex; - - const int numThreads = 100; - MyNotifiedThread* threads[numThreads]; - - // Create and start all the threads. - for( int ix=0; ixstart(); - } - - // Sleep so all the threads can get to the wait. - Thread::sleep( 1000 ); - - for( int ix=0; ixdone == true ){ - printf("threads[%d] is done prematurely\n", ix ); - } - CPPUNIT_ASSERT( threads[ix]->done == false ); - } - - // Notify all threads. - synchronized( &mutex ){ - mutex.notifyAll(); - } - - // Sleep to give the threads time to wake up. - Thread::sleep( 1000 ); - - int numComplete = 0; - for( int ix=0; ixdone ){ - numComplete++; - } - } - printf("numComplete: %d, numThreads: %d\n", numComplete, numThreads ); - CPPUNIT_ASSERT( numComplete == numThreads ); - - }catch( exceptions::ActiveMQException& ex ){ - ex.setMark( __FILE__, __LINE__ ); - } - } - - void testRecursiveLock() - { - try{ - Mutex mutex; - - const int numThreads = 30; - MyRecursiveLockThread* threads[numThreads]; - - // Create and start all the threads. - for( int ix=0; ixstart(); - } - - // Sleep so all the threads can get to the wait. - Thread::sleep( 1000 ); - - for( int ix=0; ixdone == true ){ - std::cout << "threads[" << ix - << "] is done prematurely\n"; - } - CPPUNIT_ASSERT( threads[ix]->done == false ); - } - - // Notify all threads. - synchronized( &mutex ) - { - synchronized( &mutex ) - { - mutex.notifyAll(); - } - } - - // Sleep to give the threads time to wake up. - Thread::sleep( 1000 ); - - for( int ix=0; ixdone != true ){ - std::cout<< "threads[" << ix << "] is not done\n"; - } - CPPUNIT_ASSERT( threads[ix]->done == true ); - } - }catch( exceptions::ActiveMQException& ex ){ - ex.setMark( __FILE__, __LINE__ ); - } - } - - void testDoubleLock() - { - try{ - Mutex mutex1; - Mutex mutex2; - - MyDoubleLockThread thread(&mutex1, &mutex2); - - thread.start(); - - // Let the thread get both locks - Thread::sleep( 200 ); - - // Lock mutex 2, thread is waiting on it - synchronized(&mutex2) - { - mutex2.notify(); - } - - // Let the thread die - thread.join(); - - CPPUNIT_ASSERT( thread.done ); - }catch( exceptions::ActiveMQException& ex ){ - ex.setMark( __FILE__, __LINE__ ); - } - } - }; - -}} - -#endif /*ACTIVEMQ_CONCURRENT_MUTEXTEST_H_*/ +#ifndef ACTIVEMQ_CONCURRENT_MUTEXTEST_H_ +#define ACTIVEMQ_CONCURRENT_MUTEXTEST_H_ + +#include +#include + +#include +#include +#include +#include + +namespace activemq{ +namespace concurrent{ + + class MutexTest : public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE( MutexTest ); + CPPUNIT_TEST( test ); + CPPUNIT_TEST( testWait ); + CPPUNIT_TEST( testTimedWait ); + CPPUNIT_TEST( testNotify ); + CPPUNIT_TEST( testNotifyAll ); + CPPUNIT_TEST( testRecursiveLock ); + CPPUNIT_TEST( testDoubleLock ); + CPPUNIT_TEST_SUITE_END(); + + public: + + class MyThread + : + public Thread, + public Synchronizable{ + + private: + + Mutex mutex; + + public: + + int value; + MyThread(){ value = 0;} + virtual ~MyThread(){} + + virtual void lock() throw(exceptions::ActiveMQException){ + mutex.lock(); + } + virtual void unlock() throw(exceptions::ActiveMQException){ + mutex.unlock(); + } + virtual void wait() throw(exceptions::ActiveMQException){ + mutex.wait(); + } + virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){ + mutex.wait( millisecs ); + } + virtual void notify() throw(exceptions::ActiveMQException){ + mutex.notify(); + } + virtual void notifyAll() throw(exceptions::ActiveMQException){ + mutex.notifyAll(); + } + + virtual void run(){ + + { + Lock lock (this); + + value = value * 25; + } + } + + }; + + class MyWaitingThread + : + public Thread, + public Synchronizable{ + + private: + + Mutex mutex; + + public: + + int value; + MyWaitingThread(){ value = 0;} + virtual ~MyWaitingThread(){} + virtual void lock() throw(exceptions::ActiveMQException){ + mutex.lock(); + } + virtual void unlock() throw(exceptions::ActiveMQException){ + mutex.unlock(); + } + virtual void wait() throw(exceptions::ActiveMQException){ + mutex.wait(); + } + virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){ + mutex.wait( millisecs ); + } + virtual void notify() throw(exceptions::ActiveMQException){ + mutex.notify(); + } + virtual void notifyAll() throw(exceptions::ActiveMQException){ + mutex.notifyAll(); + } + + virtual void run(){ + + try + { + synchronized(this) + { + this->wait(); + + std::cout.flush(); + + value = value * 25; + } + } + catch(exceptions::ActiveMQException& ex) + { + ex.setMark( __FILE__, __LINE__ ); + } + } + }; + + class MyTimedWaitingThread + : + public Thread, + public Synchronizable{ + + private: + + Mutex mutex; + + public: + + int value; + MyTimedWaitingThread(){ value = 0;} + virtual ~MyTimedWaitingThread(){} + virtual void lock() throw(exceptions::ActiveMQException){ + mutex.lock(); + } + virtual void unlock() throw(exceptions::ActiveMQException){ + mutex.unlock(); + } + virtual void wait() throw(exceptions::ActiveMQException){ + mutex.wait(); + } + virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){ + mutex.wait( millisecs ); + } + virtual void notify() throw(exceptions::ActiveMQException){ + mutex.notify(); + } + virtual void notifyAll() throw(exceptions::ActiveMQException){ + mutex.notifyAll(); + } + + virtual void run(){ + + try + { + synchronized(this) + { + this->wait(2000); + + value = 666; + } + } + catch(exceptions::ActiveMQException& ex) + { + ex.setMark( __FILE__, __LINE__ ); + } + } + }; + + class MyNotifiedThread + : + public Thread, + public Synchronizable{ + + public: + + bool done; + Mutex* mutex; + + public: + + int value; + MyNotifiedThread(Mutex* mutex){ this->mutex = mutex; done = false; } + virtual ~MyNotifiedThread(){} + virtual void lock() throw(exceptions::ActiveMQException){ + mutex->lock(); + } + virtual void unlock() throw(exceptions::ActiveMQException){ + mutex->unlock(); + } + virtual void wait() throw(exceptions::ActiveMQException){ + mutex->wait(); + } + virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){ + mutex->wait( millisecs ); + } + virtual void notify() throw(exceptions::ActiveMQException){ + mutex->notify(); + } + virtual void notifyAll() throw(exceptions::ActiveMQException){ + mutex->notifyAll(); + } + + virtual void run(){ + + try + { + done = false; + synchronized(this) + { + this->wait(); + done = true; + } + } + catch(exceptions::ActiveMQException& ex) + { + ex.setMark( __FILE__, __LINE__ ); + } + } + }; + + class MyRecursiveLockThread + : + public Thread, + public Synchronizable{ + + public: + + bool done; + Mutex* mutex; + + public: + + int value; + MyRecursiveLockThread(Mutex* mutex){ this->mutex = mutex; done = false; } + virtual ~MyRecursiveLockThread(){} + virtual void lock() throw(exceptions::ActiveMQException){ + mutex->lock(); + } + virtual void unlock() throw(exceptions::ActiveMQException){ + mutex->unlock(); + } + virtual void wait() throw(exceptions::ActiveMQException){ + mutex->wait(); + } + virtual void wait(unsigned long millisecs) throw(exceptions::ActiveMQException){ + mutex->wait( millisecs ); + } + virtual void notify() throw(exceptions::ActiveMQException){ + mutex->notify(); + } + virtual void notifyAll() throw(exceptions::ActiveMQException){ + mutex->notifyAll(); + } + + virtual void run(){ + + try + { + done = false; + synchronized(this) + { + synchronized(this) + { + this->wait(); + done = true; + } + } + } + catch(exceptions::ActiveMQException& ex) + { + ex.setMark( __FILE__, __LINE__ ); + } + } + }; + + class MyDoubleLockThread + : + public Thread + { + + public: + + bool done; + Mutex* mutex1; + Mutex* mutex2; + + public: + + int value; + MyDoubleLockThread(Mutex* mutex1, Mutex* mutex2) + { + this->mutex1 = mutex1; + this->mutex2 = mutex2; + done = false; + } + + virtual ~MyDoubleLockThread(){} + + virtual void run(){ + + try + { + done = false; + synchronized(mutex1) + { + synchronized(mutex2) + { + mutex2->wait(); + done = true; + } + } + } + catch(exceptions::ActiveMQException& ex) + { + ex.setMark( __FILE__, __LINE__ ); + } + } + }; + + public: + + virtual void setUp(){}; + virtual void tearDown(){}; + + void testTimedWait(){ + + try + { + MyTimedWaitingThread test; + time_t startTime = time( NULL ); + test.start(); + test.join(); + time_t endTime = time( NULL ); + + long delta = endTime - startTime; + + CPPUNIT_ASSERT( delta >= 1 && delta <= 3 ); + } + catch(exceptions::ActiveMQException& ex) + { + std::cout << ex.getMessage() << std::endl; + } + } + + void testWait(){ + + try + { + MyWaitingThread test; + test.start(); + + Thread::sleep(1000); + + synchronized(&test) + { + for( int ix=0; ix<100; ix++ ){ + test.value += 1; + } + + test.notify(); + } + + test.join(); + + CPPUNIT_ASSERT( test.value == 2500 ); + + } + catch(exceptions::ActiveMQException& ex) + { + ex.setMark( __FILE__, __LINE__ ); + } + } + + void test() + { + MyThread test; + test.lock(); + + test.start(); + + for( int ix=0; ix<100; ix++ ){ + test.value += 1; + } + + test.unlock(); + test.join(); + + CPPUNIT_ASSERT( test.value == 2500 ); + } + + void testNotify() + { + try{ + Mutex mutex; + const int numThreads = 30; + MyNotifiedThread* threads[numThreads]; + + // Create and start all the threads. + for( int ix=0; ixstart(); + } + + // Sleep so all the threads can get to the wait. + Thread::sleep( 1000 ); + + synchronized(&mutex) + { + mutex.notify(); + } + + Thread::sleep( 1000 ); + + int counter = 0; + for( int ix=0; ixdone ){ + counter++; + } + } + + // Make sure only 1 thread was notified. + CPPUNIT_ASSERT( counter == 1 ); + + synchronized(&mutex) + { + // Notify all threads. + for( int ix=0; ixdone ){ + numComplete++; + } + } + CPPUNIT_ASSERT( numComplete == numThreads ); + + synchronized( &mutex ) + { + mutex.wait( 5 ); + } + + synchronized( &mutex ) + { + mutex.notifyAll(); + } + + }catch( exceptions::ActiveMQException& ex ){ + ex.setMark( __FILE__, __LINE__ ); + } + } + + void testNotifyAll() + { + try{ + Mutex mutex; + + const int numThreads = 100; + MyNotifiedThread* threads[numThreads]; + + // Create and start all the threads. + for( int ix=0; ixstart(); + } + + // Sleep so all the threads can get to the wait. + Thread::sleep( 1000 ); + + for( int ix=0; ixdone == true ){ + printf("threads[%d] is done prematurely\n", ix ); + } + CPPUNIT_ASSERT( threads[ix]->done == false ); + } + + // Notify all threads. + synchronized( &mutex ){ + mutex.notifyAll(); + } + + // Sleep to give the threads time to wake up. + Thread::sleep( 1000 ); + + int numComplete = 0; + for( int ix=0; ixdone ){ + numComplete++; + } + } + printf("numComplete: %d, numThreads: %d\n", numComplete, numThreads ); + CPPUNIT_ASSERT( numComplete == numThreads ); + + }catch( exceptions::ActiveMQException& ex ){ + ex.setMark( __FILE__, __LINE__ ); + } + } + + void testRecursiveLock() + { + try{ + Mutex mutex; + + const int numThreads = 30; + MyRecursiveLockThread* threads[numThreads]; + + // Create and start all the threads. + for( int ix=0; ixstart(); + } + + // Sleep so all the threads can get to the wait. + Thread::sleep( 1000 ); + + for( int ix=0; ixdone == true ){ + std::cout << "threads[" << ix + << "] is done prematurely\n"; + } + CPPUNIT_ASSERT( threads[ix]->done == false ); + } + + // Notify all threads. + synchronized( &mutex ) + { + synchronized( &mutex ) + { + mutex.notifyAll(); + } + } + + // Sleep to give the threads time to wake up. + Thread::sleep( 1000 ); + + for( int ix=0; ixdone != true ){ + std::cout<< "threads[" << ix << "] is not done\n"; + } + CPPUNIT_ASSERT( threads[ix]->done == true ); + } + }catch( exceptions::ActiveMQException& ex ){ + ex.setMark( __FILE__, __LINE__ ); + } + } + + void testDoubleLock() + { + try{ + Mutex mutex1; + Mutex mutex2; + + MyDoubleLockThread thread(&mutex1, &mutex2); + + thread.start(); + + // Let the thread get both locks + Thread::sleep( 200 ); + + // Lock mutex 2, thread is waiting on it + synchronized(&mutex2) + { + mutex2.notify(); + } + + // Let the thread die + thread.join(); + + CPPUNIT_ASSERT( thread.done ); + }catch( exceptions::ActiveMQException& ex ){ + ex.setMark( __FILE__, __LINE__ ); + } + } + }; + +}} + +#endif /*ACTIVEMQ_CONCURRENT_MUTEXTEST_H_*/ Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/MutexTest.h ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.cpp URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.cpp?rev=419365&r1=419364&r2=419365&view=diff ============================================================================== --- incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.cpp (original) +++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.cpp Wed Jul 5 15:27:34 2006 @@ -1,3 +1,3 @@ -#include "ThreadPoolTest.h" - -CPPUNIT_TEST_SUITE_REGISTRATION( activemq::concurrent::ThreadPoolTest ); +#include "ThreadPoolTest.h" + +CPPUNIT_TEST_SUITE_REGISTRATION( activemq::concurrent::ThreadPoolTest ); Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.cpp ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.h URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.h?rev=419365&r1=419364&r2=419365&view=diff ============================================================================== --- incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.h (original) +++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.h Wed Jul 5 15:27:34 2006 @@ -1,233 +1,233 @@ -#ifndef THREADPOOLTEST_H_ -#define THREADPOOLTEST_H_ - -#include -#include - -#include -#include -#include -#include -#include - -namespace activemq{ -namespace concurrent{ - - class ThreadPoolTest : - public CppUnit::TestFixture, - public TaskListener - { - CPPUNIT_TEST_SUITE( ThreadPoolTest ); - CPPUNIT_TEST( test1 ); - CPPUNIT_TEST( test2 ); - CPPUNIT_TEST_SUITE_END(); - - int tasksToComplete; - int complete; - Mutex mutex; - Mutex completeMutex; - bool caughtEx; - - public: - - ThreadPoolTest() - { - complete = 0; - tasksToComplete = 0; - caughtEx = false; - } - - virtual ~ThreadPoolTest() {}; - - virtual void onTaskComplete(Runnable* task) - { - try{ - synchronized(&mutex) - { - complete++; - - if(tasksToComplete == complete) - { - mutex.notifyAll(); - } - } - }catch( exceptions::ActiveMQException& ex ){ - ex.setMark( __FILE__, __LINE__ ); - } - } - - virtual void onTaskException(Runnable* task, exceptions::ActiveMQException& ex) - { - caughtEx = true; - } - - public: - - class MyTask : public Runnable - { - public: - - int value; - - MyTask(int x) - { - value = x; - } - - virtual ~MyTask() {}; - - virtual void run(void) - { - value += 100; - } - }; - - class MyWaitingTask : public Runnable - { - public: - - Mutex* mutex; - Mutex* complete; - - MyWaitingTask(Mutex* mutex, Mutex* complete) - { - this->mutex = mutex; - this->complete = complete; - } - - virtual ~MyWaitingTask() {}; - - virtual void run(void) - { - try - { - synchronized(mutex) - { - mutex->wait(); - } - - synchronized(complete) - { - complete->notify(); - } - } - catch( exceptions::ActiveMQException& ex ) - { - ex.setMark( __FILE__, __LINE__ ); - } - } - }; - - public: - - void test2() - { - try - { - ThreadPool pool; - Mutex myMutex; - - CPPUNIT_ASSERT( pool.getMaxThreads() == ThreadPool::DEFAULT_MAX_POOL_SIZE ); - CPPUNIT_ASSERT( pool.getBlockSize() == ThreadPool::DEFAULT_MAX_BLOCK_SIZE ); - pool.setMaxThreads(3); - pool.setBlockSize(1); - CPPUNIT_ASSERT( pool.getMaxThreads() == 3 ); - CPPUNIT_ASSERT( pool.getBlockSize() == 1 ); - CPPUNIT_ASSERT( pool.getPoolSize() == 0 ); - pool.reserve( 4 ); - CPPUNIT_ASSERT( pool.getPoolSize() == 3 ); - CPPUNIT_ASSERT( pool.getFreeThreadCount() == 3 ); - - MyWaitingTask task1(&myMutex, &completeMutex); - MyWaitingTask task2(&myMutex, &completeMutex); - MyWaitingTask task3(&myMutex, &completeMutex); - MyWaitingTask task4(&myMutex, &completeMutex); - - complete = 0; - tasksToComplete = 4; - - pool.queueTask(ThreadPool::Task(&task1, this)); - pool.queueTask(ThreadPool::Task(&task2, this)); - pool.queueTask(ThreadPool::Task(&task3, this)); - pool.queueTask(ThreadPool::Task(&task4, this)); - - Thread::sleep( 1000 ); - - CPPUNIT_ASSERT( pool.getFreeThreadCount() == 0 ); - CPPUNIT_ASSERT( pool.getBacklog() == 1 ); - - int count = 0; - while(complete != tasksToComplete && count < 100) - { - synchronized(&myMutex) - { - myMutex.notifyAll(); - } - - synchronized(&completeMutex) - { - completeMutex.wait(1000); - } - - count++; - } - - CPPUNIT_ASSERT( complete == tasksToComplete ); - CPPUNIT_ASSERT( caughtEx == false ); - } - catch( exceptions::ActiveMQException& ex ) - { - ex.setMark( __FILE__, __LINE__ ); - } - } - - void test1() - { - MyTask task1(1); - MyTask task2(2); - MyTask task3(3); - - complete = 0; - tasksToComplete = 3; - - ThreadPool* pool = ThreadPool::getInstance(); - - // Can't check this here since one of the other tests might - // have used the global thread pool. - // CPPUNIT_ASSERT( pool->getPoolSize() == 0 ); - - pool->queueTask(ThreadPool::Task(&task1, this)); - pool->queueTask(ThreadPool::Task(&task2, this)); - pool->queueTask(ThreadPool::Task(&task3, this)); - - Thread::sleep(500); - - CPPUNIT_ASSERT( complete == tasksToComplete ); - - CPPUNIT_ASSERT( task1.value == 101 ); - CPPUNIT_ASSERT( task2.value == 102 ); - CPPUNIT_ASSERT( task3.value == 103 ); - - CPPUNIT_ASSERT( pool->getPoolSize() > 0 ); - CPPUNIT_ASSERT( pool->getBacklog() == 0 ); - - CPPUNIT_ASSERT( pool->getMaxThreads() == ThreadPool::DEFAULT_MAX_POOL_SIZE ); - CPPUNIT_ASSERT( pool->getBlockSize() == ThreadPool::DEFAULT_MAX_BLOCK_SIZE ); - - pool->setMaxThreads(50); - pool->setBlockSize(50); - - CPPUNIT_ASSERT( pool->getMaxThreads() == 50 ); - CPPUNIT_ASSERT( pool->getBlockSize() == 50 ); - - Thread::sleep(500); - - CPPUNIT_ASSERT( pool->getFreeThreadCount() == pool->getPoolSize() ); - CPPUNIT_ASSERT( caughtEx == false ); - - } - }; - -}} - -#endif /*THREADPOOLTEST_H_*/ +#ifndef THREADPOOLTEST_H_ +#define THREADPOOLTEST_H_ + +#include +#include + +#include +#include +#include +#include +#include + +namespace activemq{ +namespace concurrent{ + + class ThreadPoolTest : + public CppUnit::TestFixture, + public TaskListener + { + CPPUNIT_TEST_SUITE( ThreadPoolTest ); + CPPUNIT_TEST( test1 ); + CPPUNIT_TEST( test2 ); + CPPUNIT_TEST_SUITE_END(); + + int tasksToComplete; + int complete; + Mutex mutex; + Mutex completeMutex; + bool caughtEx; + + public: + + ThreadPoolTest() + { + complete = 0; + tasksToComplete = 0; + caughtEx = false; + } + + virtual ~ThreadPoolTest() {}; + + virtual void onTaskComplete(Runnable* task) + { + try{ + synchronized(&mutex) + { + complete++; + + if(tasksToComplete == complete) + { + mutex.notifyAll(); + } + } + }catch( exceptions::ActiveMQException& ex ){ + ex.setMark( __FILE__, __LINE__ ); + } + } + + virtual void onTaskException(Runnable* task, exceptions::ActiveMQException& ex) + { + caughtEx = true; + } + + public: + + class MyTask : public Runnable + { + public: + + int value; + + MyTask(int x) + { + value = x; + } + + virtual ~MyTask() {}; + + virtual void run(void) + { + value += 100; + } + }; + + class MyWaitingTask : public Runnable + { + public: + + Mutex* mutex; + Mutex* complete; + + MyWaitingTask(Mutex* mutex, Mutex* complete) + { + this->mutex = mutex; + this->complete = complete; + } + + virtual ~MyWaitingTask() {}; + + virtual void run(void) + { + try + { + synchronized(mutex) + { + mutex->wait(); + } + + synchronized(complete) + { + complete->notify(); + } + } + catch( exceptions::ActiveMQException& ex ) + { + ex.setMark( __FILE__, __LINE__ ); + } + } + }; + + public: + + void test2() + { + try + { + ThreadPool pool; + Mutex myMutex; + + CPPUNIT_ASSERT( pool.getMaxThreads() == ThreadPool::DEFAULT_MAX_POOL_SIZE ); + CPPUNIT_ASSERT( pool.getBlockSize() == ThreadPool::DEFAULT_MAX_BLOCK_SIZE ); + pool.setMaxThreads(3); + pool.setBlockSize(1); + CPPUNIT_ASSERT( pool.getMaxThreads() == 3 ); + CPPUNIT_ASSERT( pool.getBlockSize() == 1 ); + CPPUNIT_ASSERT( pool.getPoolSize() == 0 ); + pool.reserve( 4 ); + CPPUNIT_ASSERT( pool.getPoolSize() == 3 ); + CPPUNIT_ASSERT( pool.getFreeThreadCount() == 3 ); + + MyWaitingTask task1(&myMutex, &completeMutex); + MyWaitingTask task2(&myMutex, &completeMutex); + MyWaitingTask task3(&myMutex, &completeMutex); + MyWaitingTask task4(&myMutex, &completeMutex); + + complete = 0; + tasksToComplete = 4; + + pool.queueTask(ThreadPool::Task(&task1, this)); + pool.queueTask(ThreadPool::Task(&task2, this)); + pool.queueTask(ThreadPool::Task(&task3, this)); + pool.queueTask(ThreadPool::Task(&task4, this)); + + Thread::sleep( 1000 ); + + CPPUNIT_ASSERT( pool.getFreeThreadCount() == 0 ); + CPPUNIT_ASSERT( pool.getBacklog() == 1 ); + + int count = 0; + while(complete != tasksToComplete && count < 100) + { + synchronized(&myMutex) + { + myMutex.notifyAll(); + } + + synchronized(&completeMutex) + { + completeMutex.wait(1000); + } + + count++; + } + + CPPUNIT_ASSERT( complete == tasksToComplete ); + CPPUNIT_ASSERT( caughtEx == false ); + } + catch( exceptions::ActiveMQException& ex ) + { + ex.setMark( __FILE__, __LINE__ ); + } + } + + void test1() + { + MyTask task1(1); + MyTask task2(2); + MyTask task3(3); + + complete = 0; + tasksToComplete = 3; + + ThreadPool* pool = ThreadPool::getInstance(); + + // Can't check this here since one of the other tests might + // have used the global thread pool. + // CPPUNIT_ASSERT( pool->getPoolSize() == 0 ); + + pool->queueTask(ThreadPool::Task(&task1, this)); + pool->queueTask(ThreadPool::Task(&task2, this)); + pool->queueTask(ThreadPool::Task(&task3, this)); + + Thread::sleep(500); + + CPPUNIT_ASSERT( complete == tasksToComplete ); + + CPPUNIT_ASSERT( task1.value == 101 ); + CPPUNIT_ASSERT( task2.value == 102 ); + CPPUNIT_ASSERT( task3.value == 103 ); + + CPPUNIT_ASSERT( pool->getPoolSize() > 0 ); + CPPUNIT_ASSERT( pool->getBacklog() == 0 ); + + CPPUNIT_ASSERT( pool->getMaxThreads() == ThreadPool::DEFAULT_MAX_POOL_SIZE ); + CPPUNIT_ASSERT( pool->getBlockSize() == ThreadPool::DEFAULT_MAX_BLOCK_SIZE ); + + pool->setMaxThreads(50); + pool->setBlockSize(50); + + CPPUNIT_ASSERT( pool->getMaxThreads() == 50 ); + CPPUNIT_ASSERT( pool->getBlockSize() == 50 ); + + Thread::sleep(500); + + CPPUNIT_ASSERT( pool->getFreeThreadCount() == pool->getPoolSize() ); + CPPUNIT_ASSERT( caughtEx == false ); + + } + }; + +}} + +#endif /*THREADPOOLTEST_H_*/ Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadPoolTest.h ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadTest.cpp ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/concurrent/ThreadTest.h ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.cpp URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.cpp?rev=419365&r1=419364&r2=419365&view=diff ============================================================================== --- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.cpp (original) +++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.cpp Wed Jul 5 15:27:34 2006 @@ -1,3 +1,3 @@ -#include "ConnectorFactoryMapRegistrarTest.h" - -CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::ConnectorFactoryMapRegistrarTest ); +#include "ConnectorFactoryMapRegistrarTest.h" + +CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::ConnectorFactoryMapRegistrarTest ); Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.cpp ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapRegistrarTest.h ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapTest.cpp ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/ConnectorFactoryMapTest.h ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.cpp URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.cpp?rev=419365&r1=419364&r2=419365&view=diff ============================================================================== --- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.cpp (original) +++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.cpp Wed Jul 5 15:27:34 2006 @@ -1,3 +1,3 @@ -#include "StompCommandReaderTest.h" - -CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::stomp::StompCommandReaderTest ); +#include "StompCommandReaderTest.h" + +CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::stomp::StompCommandReaderTest ); Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.cpp ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.h URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.h?rev=419365&r1=419364&r2=419365&view=diff ============================================================================== --- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.h (original) +++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.h Wed Jul 5 15:27:34 2006 @@ -1,108 +1,108 @@ -#ifndef _ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDREADERTEST_H_ -#define _ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDREADERTEST_H_ - -#include -#include - -#include -#include -#include -#include -#include - -#include - -namespace activemq{ -namespace connector{ -namespace stomp{ - - class StompCommandReaderTest : public CppUnit::TestFixture - { - CPPUNIT_TEST_SUITE( StompCommandReaderTest ); - CPPUNIT_TEST( test ); - CPPUNIT_TEST_SUITE_END(); - - public: - - StompCommandReaderTest() {} - virtual ~StompCommandReaderTest() {} - - void test( void ) - { - io::ByteArrayInputStream biStream; - - StompCommandReader reader( &biStream ); - - const char* connectedStr = - "CONNECTED\nsession:test\n\n\0\n"; - const char* textStr = - "MESSAGE\n" - "destination:/topic/a\n" - "message-id:123\n" - "sampleProperty:testvalue\n\n" - "testMessage\0\n"; - const char* bytesStr = - "MESSAGE\n" // 8 - "destination:/topic/a\n" // 21 - "message-id:123\n" // 15 - "content-length:9\n" // 17 - "sampleProperty:testvalue\n\n" // 26 - "123456789\0\n"; // 11 - - biStream.setByteArray( - (const unsigned char*)connectedStr, 27 ); - - transport::Command* command = reader.readCommand(); - - CPPUNIT_ASSERT( command != NULL ); - - commands::ConnectedCommand* connected = - dynamic_cast< commands::ConnectedCommand* >( command ); - - CPPUNIT_ASSERT( connected != NULL ); - - CPPUNIT_ASSERT( connected->getSessionId() != NULL ); - std::string sessionId = connected->getSessionId(); - CPPUNIT_ASSERT( sessionId == "test" ); - - biStream.setByteArray( - (const unsigned char*)textStr, 83 ); - - command = reader.readCommand(); - - CPPUNIT_ASSERT( command != NULL ); - - commands::TextMessageCommand* textMessage = - dynamic_cast< commands::TextMessageCommand* >( command ); - - CPPUNIT_ASSERT( textMessage != NULL ); - - CPPUNIT_ASSERT( textMessage->getText() != NULL ); - std::string text = textMessage->getText(); - CPPUNIT_ASSERT( text == "testMessage" ); - - biStream.setByteArray( - (const unsigned char*)bytesStr, 98 ); - - command = reader.readCommand(); - - CPPUNIT_ASSERT( command != NULL ); - - commands::BytesMessageCommand* bytesMessage = - dynamic_cast< commands::BytesMessageCommand* >( command ); - - CPPUNIT_ASSERT( bytesMessage != NULL ); - - CPPUNIT_ASSERT( bytesMessage->getBodyBytes() != NULL ); - std::string bytesText( - (const char*)bytesMessage->getBodyBytes(), - (int)bytesMessage->getBodyLength() ); - CPPUNIT_ASSERT( bytesText == "123456789" ); - - } - - }; - -}}} - -#endif /*_ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDREADERTEST_H_*/ +#ifndef _ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDREADERTEST_H_ +#define _ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDREADERTEST_H_ + +#include +#include + +#include +#include +#include +#include +#include + +#include + +namespace activemq{ +namespace connector{ +namespace stomp{ + + class StompCommandReaderTest : public CppUnit::TestFixture + { + CPPUNIT_TEST_SUITE( StompCommandReaderTest ); + CPPUNIT_TEST( test ); + CPPUNIT_TEST_SUITE_END(); + + public: + + StompCommandReaderTest() {} + virtual ~StompCommandReaderTest() {} + + void test( void ) + { + io::ByteArrayInputStream biStream; + + StompCommandReader reader( &biStream ); + + const char* connectedStr = + "CONNECTED\nsession:test\n\n\0\n"; + const char* textStr = + "MESSAGE\n" + "destination:/topic/a\n" + "message-id:123\n" + "sampleProperty:testvalue\n\n" + "testMessage\0\n"; + const char* bytesStr = + "MESSAGE\n" // 8 + "destination:/topic/a\n" // 21 + "message-id:123\n" // 15 + "content-length:9\n" // 17 + "sampleProperty:testvalue\n\n" // 26 + "123456789\0\n"; // 11 + + biStream.setByteArray( + (const unsigned char*)connectedStr, 27 ); + + transport::Command* command = reader.readCommand(); + + CPPUNIT_ASSERT( command != NULL ); + + commands::ConnectedCommand* connected = + dynamic_cast< commands::ConnectedCommand* >( command ); + + CPPUNIT_ASSERT( connected != NULL ); + + CPPUNIT_ASSERT( connected->getSessionId() != NULL ); + std::string sessionId = connected->getSessionId(); + CPPUNIT_ASSERT( sessionId == "test" ); + + biStream.setByteArray( + (const unsigned char*)textStr, 83 ); + + command = reader.readCommand(); + + CPPUNIT_ASSERT( command != NULL ); + + commands::TextMessageCommand* textMessage = + dynamic_cast< commands::TextMessageCommand* >( command ); + + CPPUNIT_ASSERT( textMessage != NULL ); + + CPPUNIT_ASSERT( textMessage->getText() != NULL ); + std::string text = textMessage->getText(); + CPPUNIT_ASSERT( text == "testMessage" ); + + biStream.setByteArray( + (const unsigned char*)bytesStr, 98 ); + + command = reader.readCommand(); + + CPPUNIT_ASSERT( command != NULL ); + + commands::BytesMessageCommand* bytesMessage = + dynamic_cast< commands::BytesMessageCommand* >( command ); + + CPPUNIT_ASSERT( bytesMessage != NULL ); + + CPPUNIT_ASSERT( bytesMessage->getBodyBytes() != NULL ); + std::string bytesText( + (const char*)bytesMessage->getBodyBytes(), + (int)bytesMessage->getBodyLength() ); + CPPUNIT_ASSERT( bytesText == "123456789" ); + + } + + }; + +}}} + +#endif /*_ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDREADERTEST_H_*/ Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandReaderTest.h ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.cpp URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.cpp?rev=419365&r1=419364&r2=419365&view=diff ============================================================================== --- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.cpp (original) +++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.cpp Wed Jul 5 15:27:34 2006 @@ -1,3 +1,3 @@ -#include "StompCommandWriterTest.h" - -CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::stomp::StompCommandWriterTest ); +#include "StompCommandWriterTest.h" + +CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::stomp::StompCommandWriterTest ); Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.cpp ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.h URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.h?rev=419365&r1=419364&r2=419365&view=diff ============================================================================== --- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.h (original) +++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.h Wed Jul 5 15:27:34 2006 @@ -1,102 +1,102 @@ -#ifndef _ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDWRITERTEST_H_ -#define _ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDWRITERTEST_H_ - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace activemq{ -namespace connector{ -namespace stomp{ - - class StompCommandWriterTest : public CppUnit::TestFixture - { - CPPUNIT_TEST_SUITE( StompCommandWriterTest ); - CPPUNIT_TEST( test ); - CPPUNIT_TEST_SUITE_END(); - - public: - - StompCommandWriterTest() {} - virtual ~StompCommandWriterTest() {} - - void test( void ) - { - io::ByteArrayOutputStream boStream; - - StompCommandWriter writer( &boStream ); - - const char* result = - "CONNECTED\nsession:test\n\n\0\n" // 26 = 26 - "SEND\n" // 5 - "destination:/topic/a\n" // 21 - "message-id:123\n" // 15 - "sampleProperty:testvalue\n\n" // 26 - "testMessage\0\n" // 13 = 80 - "SEND\n" // 5 - "content-length:9\n" // 17 - "destination:/topic/a\n" // 21 - "message-id:123\n" // 15 - "sampleProperty:testvalue\n\n" // 26 - "123456789\0\n"; // 11 = 95 - // 201 - commands::ConnectedCommand connectedCommand; - commands::TextMessageCommand textCommand; - commands::BytesMessageCommand bytesCommand; - - // Sync to expected output - connectedCommand.setSessionId( "test" ); - - // Sync to expected output - textCommand.setCMSDestination( StompTopic("a") ); - textCommand.setCMSMessageId( "123" ); - textCommand.getProperties().setProperty( - "sampleProperty", "testvalue" ); - textCommand.setText( "testMessage" ); - - // Sync to expected output - bytesCommand.setCMSDestination( StompTopic("a") ); - bytesCommand.setCMSMessageId( "123" ); - bytesCommand.getProperties().setProperty( - "sampleProperty", "testvalue" ); - bytesCommand.setBodyBytes( - (const unsigned char*)"123456789", 9 ); - - writer.writeCommand( &connectedCommand ); - writer.writeCommand( &textCommand ); - writer.writeCommand( &bytesCommand ); - - const unsigned char* alloc = boStream.getByteArray(); - - //for( int i = 0; i < 201; ++i ) - //{ - // std::cout << result[i] << " == " << alloc[i] << std::endl; - //} - - CPPUNIT_ASSERT( boStream.getByteArraySize() == 201 ); - - for( int i = 0; i < 201; ++i ) - { - CPPUNIT_ASSERT( result[i] == alloc[i] ); - } - - // Use STL Compare - CPPUNIT_ASSERT( - std::equal( &result[0], &result[200], - boStream.getByteArray() ) ); - } - - }; - -}}} - -#endif /*_ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDWRITERTEST_H_*/ +#ifndef _ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDWRITERTEST_H_ +#define _ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDWRITERTEST_H_ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace activemq{ +namespace connector{ +namespace stomp{ + + class StompCommandWriterTest : public CppUnit::TestFixture + { + CPPUNIT_TEST_SUITE( StompCommandWriterTest ); + CPPUNIT_TEST( test ); + CPPUNIT_TEST_SUITE_END(); + + public: + + StompCommandWriterTest() {} + virtual ~StompCommandWriterTest() {} + + void test( void ) + { + io::ByteArrayOutputStream boStream; + + StompCommandWriter writer( &boStream ); + + const char* result = + "CONNECTED\nsession:test\n\n\0\n" // 26 = 26 + "SEND\n" // 5 + "destination:/topic/a\n" // 21 + "message-id:123\n" // 15 + "sampleProperty:testvalue\n\n" // 26 + "testMessage\0\n" // 13 = 80 + "SEND\n" // 5 + "content-length:9\n" // 17 + "destination:/topic/a\n" // 21 + "message-id:123\n" // 15 + "sampleProperty:testvalue\n\n" // 26 + "123456789\0\n"; // 11 = 95 + // 201 + commands::ConnectedCommand connectedCommand; + commands::TextMessageCommand textCommand; + commands::BytesMessageCommand bytesCommand; + + // Sync to expected output + connectedCommand.setSessionId( "test" ); + + // Sync to expected output + textCommand.setCMSDestination( StompTopic("a") ); + textCommand.setCMSMessageId( "123" ); + textCommand.getProperties().setProperty( + "sampleProperty", "testvalue" ); + textCommand.setText( "testMessage" ); + + // Sync to expected output + bytesCommand.setCMSDestination( StompTopic("a") ); + bytesCommand.setCMSMessageId( "123" ); + bytesCommand.getProperties().setProperty( + "sampleProperty", "testvalue" ); + bytesCommand.setBodyBytes( + (const unsigned char*)"123456789", 9 ); + + writer.writeCommand( &connectedCommand ); + writer.writeCommand( &textCommand ); + writer.writeCommand( &bytesCommand ); + + const unsigned char* alloc = boStream.getByteArray(); + + //for( int i = 0; i < 201; ++i ) + //{ + // std::cout << result[i] << " == " << alloc[i] << std::endl; + //} + + CPPUNIT_ASSERT( boStream.getByteArraySize() == 201 ); + + for( int i = 0; i < 201; ++i ) + { + CPPUNIT_ASSERT( result[i] == alloc[i] ); + } + + // Use STL Compare + CPPUNIT_ASSERT( + std::equal( &result[0], &result[200], + boStream.getByteArray() ) ); + } + + }; + +}}} + +#endif /*_ACTIVEMQ_CONNECTOR_STOMP_STOMPCOMMANDWRITERTEST_H_*/ Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompCommandWriterTest.h ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.cpp URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.cpp?rev=419365&r1=419364&r2=419365&view=diff ============================================================================== --- incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.cpp (original) +++ incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.cpp Wed Jul 5 15:27:34 2006 @@ -1,3 +1,3 @@ -#include "StompConnectorTest.h" - -CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::stomp::StompConnectorTest ); +#include "StompConnectorTest.h" + +CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::stomp::StompConnectorTest ); Propchange: incubator/activemq/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.cpp ------------------------------------------------------------------------------ svn:eol-style = native