activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r555273 - in /activemq/activemq-cpp/trunk/src/decaf/src/test: ./ decaf/util/ decaf/util/concurrent/
Date Wed, 11 Jul 2007 13:56:28 GMT
Author: tabish
Date: Wed Jul 11 06:56:27 2007
New Revision: 555273

URL: http://svn.apache.org/viewvc?view=rev&rev=555273
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103

Added:
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/MapTest.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/MapTest.h
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/QueueTest.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/QueueTest.h
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/SetTest.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/SetTest.h
Modified:
    activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/concurrent/MutexTest.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/concurrent/MutexTest.h

Modified: activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am?view=diff&rev=555273&r1=555272&r2=555273
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am Wed Jul 11 06:56:27 2007
@@ -33,6 +33,9 @@
   decaf/util/DateTest.cpp \
   decaf/util/GuidTest.cpp \
   decaf/util/RandomTest.cpp \
+  decaf/util/MapTest.cpp \
+  decaf/util/QueueTest.cpp \
+  decaf/util/SetTest.cpp \
   decaf/util/concurrent/CountDownLatchTest.cpp \
   decaf/util/concurrent/MutexTest.cpp \
   decaf/util/concurrent/ThreadPoolTest.cpp \
@@ -56,6 +59,9 @@
   decaf/util/DateTest.h \
   decaf/util/GuidTest.h \
   decaf/util/RandomTest.h \
+  decaf/util/MapTest.h \
+  decaf/util/QueueTest.h \
+  decaf/util/SetTest.h \
   decaf/util/concurrent/CountDownLatchTest.h \
   decaf/util/concurrent/MutexTest.h \
   decaf/util/concurrent/ThreadPoolTest.h
@@ -68,8 +74,6 @@
 ## 
 ## Compiler/Linker Options
 ##
-CXXFLAGS = @CXXFLAGS@ -Wno-non-virtual-dtor -Wno-unused-parameter -Wno-uninitialized
 decaf_test_SOURCES = $(cc_sources)
-decaf_test_CXXFLAGS = -I$(srcdir)/../main @CPPUNIT_CFLAGS@
-decaf_test_LDADD= ../main/libdecaf.a @CPPUNIT_LIBS@
-
+decaf_test_CXXFLAGS = $(DECAF_TEST_CXXFLAGS) -I$(srcdir)/../main @CPPUNIT_CFLAGS@
+decaf_test_LDADD= $(DECAF_TEST_LIBS) @CPPUNIT_LIBS@ 

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/MapTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/MapTest.cpp?view=auto&rev=555273
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/MapTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/MapTest.cpp Wed Jul 11 06:56:27
2007
@@ -0,0 +1,121 @@
+/*
+ * 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>
+
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::MapTest );
+
+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/decaf/src/test/decaf/util/MapTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/MapTest.h?view=auto&rev=555273
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/MapTest.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/MapTest.h Wed Jul 11 06:56:27
2007
@@ -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/decaf/src/test/decaf/util/QueueTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/QueueTest.cpp?view=auto&rev=555273
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/QueueTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/QueueTest.cpp Wed Jul 11 06:56:27
2007
@@ -0,0 +1,49 @@
+/*
+ * 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"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::QueueTest );
+
+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/decaf/src/test/decaf/util/QueueTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/QueueTest.h?view=auto&rev=555273
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/QueueTest.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/QueueTest.h Wed Jul 11 06:56:27
2007
@@ -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/decaf/src/test/decaf/util/SetTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/SetTest.cpp?view=auto&rev=555273
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/SetTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/SetTest.cpp Wed Jul 11 06:56:27
2007
@@ -0,0 +1,149 @@
+/*
+ * 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"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::SetTest );
+
+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/decaf/src/test/decaf/util/SetTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/SetTest.h?view=auto&rev=555273
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/SetTest.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/SetTest.h Wed Jul 11 06:56:27
2007
@@ -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_*/

Modified: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/concurrent/MutexTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/concurrent/MutexTest.cpp?view=diff&rev=555273&r1=555272&r2=555273
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/concurrent/MutexTest.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/concurrent/MutexTest.cpp Wed
Jul 11 06:56:27 2007
@@ -333,3 +333,19 @@
         ex.setMark( __FILE__, __LINE__ );
     }
 }
+
+///////////////////////////////////////////////////////////////////////////////
+void MutexTest::testStressMutex(){
+    MyStoppableThread tester;
+
+    tester.start();
+
+    CPPUNIT_ASSERT( tester.isStarted() );
+
+    for( int i = 0; i < 100; ++i ) {
+        tester.stop();
+        tester.start();
+    }
+
+    CPPUNIT_ASSERT( true );
+}

Modified: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/concurrent/MutexTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/concurrent/MutexTest.h?view=diff&rev=555273&r1=555272&r2=555273
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/concurrent/MutexTest.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/concurrent/MutexTest.h Wed Jul
11 06:56:27 2007
@@ -22,8 +22,10 @@
 #include <cppunit/extensions/HelperMacros.h>
 
 #include <decaf/lang/Thread.h>
+#include <decaf/lang/Runnable.h>
 #include <decaf/util/concurrent/Concurrent.h>
 #include <decaf/util/concurrent/Mutex.h>
+#include <decaf/util/Random.h>
 #include <time.h>
 
 namespace decaf{
@@ -40,6 +42,7 @@
         CPPUNIT_TEST( testNotifyAll );
         CPPUNIT_TEST( testRecursiveLock );
         CPPUNIT_TEST( testDoubleLock );
+        CPPUNIT_TEST( testStressMutex );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -361,6 +364,113 @@
          }
       };
 
+      class MyStoppableThread : public lang::Runnable
+      {
+      public:
+
+          bool started;
+          bool closed;
+          Mutex mutex;
+          lang::Thread* thread;
+          util::Random rand;
+
+      public:
+
+          MyStoppableThread() {
+              this->started = false;
+              this->closed = false;
+              this->thread = NULL;
+          }
+
+          virtual ~MyStoppableThread(){ close(); }
+
+          virtual void start(){
+              synchronized( &mutex ) {
+
+                  if( closed || started ) {
+                      return;
+                  }
+
+                  started = true;
+
+                  // Don't create the thread unless we need to.
+                  if( thread == NULL ) {
+                      thread = new lang::Thread( this );
+                      thread->start();
+                  }
+
+                  mutex.notifyAll();
+              }
+          }
+
+          virtual void stop() {
+              synchronized( &mutex ) {
+
+                  if( closed || !started ) {
+                      return;
+                  }
+
+                  // Set the state to stopped.
+                  started = false;
+
+                  // Wakeup the thread so that it can acknowledge the stop request.
+                  mutex.notifyAll();
+
+                  // Wait for the thread to notify us that it has acknowledged
+                  // the stop request.
+                  mutex.wait();
+              }
+          }
+
+          virtual void close() {
+              synchronized( &mutex ) {
+
+                  closed = true;
+                  mutex.notifyAll();
+              }
+
+              if( thread != NULL ) {
+                  thread->join();
+                  delete thread;
+                  thread = NULL;
+              }
+          }
+
+          virtual bool isStarted() const {
+              return started;
+          }
+
+          virtual void run(){
+              try {
+
+                  while( true ) {
+
+                      lang::Thread::sleep( rand.nextInt( 100 ) );
+
+                      synchronized( &mutex ) {
+
+                          // If we're closing down, exit the thread.
+                          if( closed ) {
+                              return;
+                          }
+
+                          // When told to stop, the calling thread will wait for a
+                          // responding notification, indicating that we have acknowledged
+                          // the stop command.
+                          if( !isStarted() ) {
+                              mutex.notifyAll();
+
+                              // Wait for more data or to be woken up.
+                              mutex.wait();
+                          }
+                      }
+                  }
+              } catch(...) {
+                  CPPUNIT_ASSERT( false );
+              }
+          }
+      };
+
     public:
 
         virtual ~MutexTest(){}
@@ -374,6 +484,7 @@
         void testNotifyAll();
         void testRecursiveLock();
         void testDoubleLock();
+        void testStressMutex();
 
     };
 



Mime
View raw message