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 2012/07/27 01:27:58 UTC

svn commit: r1366234 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util: HashMapTest.cpp HashMapTest.h StlMapTest.cpp StlMapTest.h concurrent/ConcurrentStlMapTest.cpp concurrent/ConcurrentStlMapTest.h

Author: tabish
Date: Thu Jul 26 23:27:58 2012
New Revision: 1366234

URL: http://svn.apache.org/viewvc?rev=1366234&view=rev
Log:
Add even more unit tests

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/HashMapTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/HashMapTest.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ConcurrentStlMapTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ConcurrentStlMapTest.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/HashMapTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/HashMapTest.cpp?rev=1366234&r1=1366233&r2=1366234&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/HashMapTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/HashMapTest.cpp Thu Jul 26 23:27:58 2012
@@ -553,3 +553,112 @@ void HashMapTest::testToString() {
     std::string result = hashMap.toString();
     CPPUNIT_ASSERT_MESSAGE("should return something", result != "");
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void HashMapTest::testEntrySetIterator() {
+
+    HashMap<int, std::string> map;
+    populateMap(map);
+
+    int count = 0;
+    Pointer< Iterator<MapEntry<int, std::string> > > iterator(map.entrySet().iterator());
+    while (iterator->hasNext()) {
+        MapEntry<int, std::string> entry = iterator->next();
+        CPPUNIT_ASSERT_EQUAL(count, entry.getKey());
+        CPPUNIT_ASSERT_EQUAL(Integer::toString(count), entry.getValue());
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't cover the expected range", count++ == MAP_SIZE);
+
+    iterator.reset(map.entrySet().iterator());
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+
+    count = 0;
+    while (iterator->hasNext()) {
+        iterator->next();
+        iterator->remove();
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't remove the expected range", count++ == MAP_SIZE);
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void HashMapTest::testKeySetIterator() {
+
+    HashMap<int, std::string> map;
+    populateMap(map);
+
+    int count = 0;
+    Pointer< Iterator<int> > iterator(map.keySet().iterator());
+    while (iterator->hasNext()) {
+        int key = iterator->next();
+        CPPUNIT_ASSERT_EQUAL(count, key);
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't cover the expected range", count++ == MAP_SIZE);
+
+    iterator.reset(map.keySet().iterator());
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+
+    count = 0;
+    while (iterator->hasNext()) {
+        iterator->next();
+        iterator->remove();
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't remove the expected range", count++ == MAP_SIZE);
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void HashMapTest::testValuesIterator() {
+
+    HashMap<int, std::string> map;
+    populateMap(map);
+
+    int count = 0;
+    Pointer< Iterator<std::string> > iterator(map.values().iterator());
+    while (iterator->hasNext()) {
+        std::string value = iterator->next();
+        CPPUNIT_ASSERT_EQUAL(Integer::toString(count), value);
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't cover the expected range", count++ == MAP_SIZE);
+
+    iterator.reset(map.values().iterator());
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+
+    count = 0;
+    while (iterator->hasNext()) {
+        iterator->next();
+        iterator->remove();
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't remove the expected range", count++ == MAP_SIZE);
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/HashMapTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/HashMapTest.h?rev=1366234&r1=1366233&r2=1366234&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/HashMapTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/HashMapTest.h Thu Jul 26 23:27:58 2012
@@ -34,7 +34,6 @@ namespace util {
         CPPUNIT_TEST( testClear );
         CPPUNIT_TEST( testContainsKey );
         CPPUNIT_TEST( testContainsValue );
-        CPPUNIT_TEST( testEntrySet );
         CPPUNIT_TEST( testGet );
         CPPUNIT_TEST( testPut );
         CPPUNIT_TEST( testRemove );
@@ -43,8 +42,13 @@ namespace util {
         CPPUNIT_TEST( testPutAll );
         CPPUNIT_TEST( testRehash );
         CPPUNIT_TEST( testSize );
+        CPPUNIT_TEST( testEntrySet );
         CPPUNIT_TEST( testValues );
         CPPUNIT_TEST( testToString );
+        CPPUNIT_TEST( testEntrySetIterator );
+        CPPUNIT_TEST( testKeySetIterator );
+        CPPUNIT_TEST( testValuesIterator );
+        CPPUNIT_TEST( testToString );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -61,17 +65,20 @@ namespace util {
         void testClear();
         void testContainsKey();
         void testContainsValue();
-        void testEntrySet();
         void testGet();
         void testPut();
         void testRemove();
         void testIsEmpty();
-        void testKeySet();
         void testPutAll();
         void testRehash();
+        void testToString();
         void testSize();
+        void testEntrySet();
+        void testKeySet();
         void testValues();
-        void testToString();
+        void testEntrySetIterator();
+        void testKeySetIterator();
+        void testValuesIterator();
 
     };
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp?rev=1366234&r1=1366233&r2=1366234&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.cpp Thu Jul 26 23:27:58 2012
@@ -23,11 +23,13 @@
 #include <decaf/util/ArrayList.h>
 #include <decaf/lang/Integer.h>
 #include <decaf/lang/exceptions/IllegalArgumentException.h>
+#include <decaf/lang/exceptions/IllegalStateException.h>
 
 using namespace std;
 using namespace decaf;
 using namespace decaf::util;
 using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
 namespace {
@@ -348,3 +350,112 @@ void StlMapTest::testValues() {
     CPPUNIT_ASSERT_MESSAGE("Removing from collection should alter Map",
                            !map.containsKey(10));
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void StlMapTest::testEntrySetIterator() {
+
+    StlMap<int, std::string> map;
+    populateMap(map);
+
+    int count = 0;
+    Pointer< Iterator<MapEntry<int, std::string> > > iterator(map.entrySet().iterator());
+    while (iterator->hasNext()) {
+        MapEntry<int, std::string> entry = iterator->next();
+        CPPUNIT_ASSERT_EQUAL(count, entry.getKey());
+        CPPUNIT_ASSERT_EQUAL(Integer::toString(count), entry.getValue());
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't cover the expected range", count++ == MAP_SIZE);
+
+    iterator.reset(map.entrySet().iterator());
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+
+    count = 0;
+    while (iterator->hasNext()) {
+        iterator->next();
+        iterator->remove();
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't remove the expected range", count++ == MAP_SIZE);
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StlMapTest::testKeySetIterator() {
+
+    StlMap<int, std::string> map;
+    populateMap(map);
+
+    int count = 0;
+    Pointer< Iterator<int> > iterator(map.keySet().iterator());
+    while (iterator->hasNext()) {
+        int key = iterator->next();
+        CPPUNIT_ASSERT_EQUAL(count, key);
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't cover the expected range", count++ == MAP_SIZE);
+
+    iterator.reset(map.keySet().iterator());
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+
+    count = 0;
+    while (iterator->hasNext()) {
+        iterator->next();
+        iterator->remove();
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't remove the expected range", count++ == MAP_SIZE);
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void StlMapTest::testValuesIterator() {
+
+    StlMap<int, std::string> map;
+    populateMap(map);
+
+    int count = 0;
+    Pointer< Iterator<std::string> > iterator(map.values().iterator());
+    while (iterator->hasNext()) {
+        std::string value = iterator->next();
+        CPPUNIT_ASSERT_EQUAL(Integer::toString(count), value);
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't cover the expected range", count++ == MAP_SIZE);
+
+    iterator.reset(map.values().iterator());
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+
+    count = 0;
+    while (iterator->hasNext()) {
+        iterator->next();
+        iterator->remove();
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't remove the expected range", count++ == MAP_SIZE);
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.h?rev=1366234&r1=1366233&r2=1366234&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StlMapTest.h Thu Jul 26 23:27:58 2012
@@ -41,6 +41,9 @@ namespace util {
         CPPUNIT_TEST( testEntrySet );
         CPPUNIT_TEST( testKeySet );
         CPPUNIT_TEST( testValues );
+        CPPUNIT_TEST( testEntrySetIterator );
+        CPPUNIT_TEST( testKeySetIterator );
+        CPPUNIT_TEST( testValuesIterator );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -62,6 +65,9 @@ namespace util {
         void testEntrySet();
         void testKeySet();
         void testValues();
+        void testEntrySetIterator();
+        void testKeySetIterator();
+        void testValuesIterator();
 
     };
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ConcurrentStlMapTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ConcurrentStlMapTest.cpp?rev=1366234&r1=1366233&r2=1366234&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ConcurrentStlMapTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ConcurrentStlMapTest.cpp Thu Jul 26 23:27:58 2012
@@ -23,12 +23,14 @@
 #include <decaf/util/ArrayList.h>
 #include <decaf/lang/Integer.h>
 #include <decaf/lang/exceptions/IllegalArgumentException.h>
+#include <decaf/lang/exceptions/IllegalStateException.h>
 
 using namespace std;
 using namespace decaf;
 using namespace decaf::util;
 using namespace decaf::util::concurrent;
 using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
 namespace {
@@ -419,3 +421,112 @@ void ConcurrentStlMapTest::testValues() 
     CPPUNIT_ASSERT_MESSAGE("Removing from collection should alter Map",
                            !map.containsKey(10));
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void ConcurrentStlMapTest::testEntrySetIterator() {
+
+    ConcurrentStlMap<int, std::string> map;
+    populateMap(map);
+
+    int count = 0;
+    Pointer< Iterator<MapEntry<int, std::string> > > iterator(map.entrySet().iterator());
+    while (iterator->hasNext()) {
+        MapEntry<int, std::string> entry = iterator->next();
+        CPPUNIT_ASSERT_EQUAL(count, entry.getKey());
+        CPPUNIT_ASSERT_EQUAL(Integer::toString(count), entry.getValue());
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't cover the expected range", count++ == MAP_SIZE);
+
+    iterator.reset(map.entrySet().iterator());
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+
+    count = 0;
+    while (iterator->hasNext()) {
+        iterator->next();
+        iterator->remove();
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't remove the expected range", count++ == MAP_SIZE);
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ConcurrentStlMapTest::testKeySetIterator() {
+
+    ConcurrentStlMap<int, std::string> map;
+    populateMap(map);
+
+    int count = 0;
+    Pointer< Iterator<int> > iterator(map.keySet().iterator());
+    while (iterator->hasNext()) {
+        int key = iterator->next();
+        CPPUNIT_ASSERT_EQUAL(count, key);
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't cover the expected range", count++ == MAP_SIZE);
+
+    iterator.reset(map.keySet().iterator());
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+
+    count = 0;
+    while (iterator->hasNext()) {
+        iterator->next();
+        iterator->remove();
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't remove the expected range", count++ == MAP_SIZE);
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ConcurrentStlMapTest::testValuesIterator() {
+
+    ConcurrentStlMap<int, std::string> map;
+    populateMap(map);
+
+    int count = 0;
+    Pointer< Iterator<std::string> > iterator(map.values().iterator());
+    while (iterator->hasNext()) {
+        std::string value = iterator->next();
+        CPPUNIT_ASSERT_EQUAL(Integer::toString(count), value);
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't cover the expected range", count++ == MAP_SIZE);
+
+    iterator.reset(map.values().iterator());
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+
+    count = 0;
+    while (iterator->hasNext()) {
+        iterator->next();
+        iterator->remove();
+        count++;
+    }
+
+    CPPUNIT_ASSERT_MESSAGE("Iterator didn't remove the expected range", count++ == MAP_SIZE);
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IllegalStateException",
+        iterator->remove(),
+        IllegalStateException);
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ConcurrentStlMapTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ConcurrentStlMapTest.h?rev=1366234&r1=1366233&r2=1366234&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ConcurrentStlMapTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/ConcurrentStlMapTest.h Thu Jul 26 23:27:58 2012
@@ -44,6 +44,9 @@ namespace concurrent {
         CPPUNIT_TEST( testEntrySet );
         CPPUNIT_TEST( testKeySet );
         CPPUNIT_TEST( testValues );
+        CPPUNIT_TEST( testEntrySetIterator );
+        CPPUNIT_TEST( testKeySetIterator );
+        CPPUNIT_TEST( testValuesIterator );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -67,6 +70,9 @@ namespace concurrent {
         void testEntrySet();
         void testKeySet();
         void testValues();
+        void testEntrySetIterator();
+        void testKeySetIterator();
+        void testValuesIterator();
 
     };