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 2010/12/17 00:18:06 UTC
svn commit: r1050221 [7/8] - in
/activemq/activemq-cpp/trunk/activemq-cpp/src: main/ main/activemq/cmsutil/
main/activemq/core/ main/activemq/state/ main/activemq/threads/
main/activemq/transport/ main/activemq/transport/failover/
main/activemq/util/ m...
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/ListTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/ListTest.cpp?rev=1050221&r1=1050220&r2=1050221&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/ListTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/ListTest.cpp Thu Dec 16 23:18:02 2010
@@ -19,17 +19,186 @@
#include <decaf/util/List.h>
#include <decaf/util/StlList.h>
+#include <decaf/util/StlSet.h>
#include <decaf/util/Iterator.h>
+#include <decaf/lang/Integer.h>
using namespace std;
using namespace decaf;
using namespace decaf::util;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+const int ListTest::SIZE = 256;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace {
+
+ void populate( StlList<int>& list, int n ) {
+
+ CPPUNIT_ASSERT( list.isEmpty() );
+
+ for( int i = 0; i < n; ++i ) {
+ list.add( i );
+ }
+
+ CPPUNIT_ASSERT( !list.isEmpty());
+ CPPUNIT_ASSERT_EQUAL( n, list.size() );
+ }
+
+ void populate( StlList<std::string>& list, int n ) {
+
+ CPPUNIT_ASSERT( list.isEmpty() );
+
+ for( int i = 0; i < n; ++i ) {
+ list.add( Integer::toString( i ) );
+ }
+
+ CPPUNIT_ASSERT( !list.isEmpty());
+ CPPUNIT_ASSERT_EQUAL( n, list.size() );
+ }
+
+ void populate( std::vector<int>& list, int n ) {
+
+ CPPUNIT_ASSERT( list.empty() );
+
+ for( int i = 0; i < n; ++i ) {
+ list.push_back( i );
+ }
+
+ CPPUNIT_ASSERT( !list.empty());
+ CPPUNIT_ASSERT_EQUAL( n, (int)list.size() );
+ }
+}
////////////////////////////////////////////////////////////////////////////////
ListTest::ListTest(){
}
////////////////////////////////////////////////////////////////////////////////
+void ListTest::testConstructor1(){
+
+ StlList<int> list;
+
+ CPPUNIT_ASSERT( list.size() == 0 );
+ CPPUNIT_ASSERT( list.isEmpty() );
+
+ list.add( 1 );
+
+ CPPUNIT_ASSERT( list.size() == 1 );
+ CPPUNIT_ASSERT( !list.isEmpty() );
+
+ list.add( 1 );
+
+ CPPUNIT_ASSERT( list.size() == 2 );
+ CPPUNIT_ASSERT( !list.isEmpty() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testConstructor2(){
+
+ StlList<int> list1;
+
+ for( int i = 0; i < 50; ++i ) {
+ list1.add( i );
+ }
+
+ StlList<int> list2( list1 );
+
+ CPPUNIT_ASSERT( list1.size() == list2.size() );
+
+ for( int i = 0; i < 50; ++i ) {
+ CPPUNIT_ASSERT( list2.contains( i ) );
+ }
+
+ CPPUNIT_ASSERT( list2.equals( list1 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testConstructor3(){
+
+ StlSet<int> collection;
+
+ for( int i = 0; i < 50; ++i ) {
+ collection.add( i );
+ }
+
+ StlList<int> list( collection );
+
+ CPPUNIT_ASSERT( collection.size() == list.size() );
+
+ for( int i = 0; i < 50; ++i ) {
+ CPPUNIT_ASSERT( list.contains( i ) );
+ }
+
+ CPPUNIT_ASSERT( list.equals( collection ) );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void ListTest::testEquals() {
+
+ StlList<int> list1;
+ populate( list1, 7 );
+ StlList<int> list2;
+ populate( list2, 7 );
+
+ CPPUNIT_ASSERT( list1.equals( list2 ) );
+ CPPUNIT_ASSERT( list2.equals( list1 ) );
+
+ list1.add( 42 );
+ CPPUNIT_ASSERT( !list1.equals( list2 ) );
+ CPPUNIT_ASSERT( !list2.equals( list1 ) );
+ list2.add( 42 );
+ CPPUNIT_ASSERT( list1.equals( list2 ) );
+ CPPUNIT_ASSERT( list2.equals( list1 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testCopy1() {
+
+ StlList<int> list1;
+
+ for( int i = 0; i < 50; ++i ) {
+ list1.add( i );
+ }
+
+ StlList<int> list2;
+
+ list2.copy( list1 );
+
+ CPPUNIT_ASSERT( list1.size() == list2.size() );
+
+ for( int i = 0; i < 50; ++i ) {
+ CPPUNIT_ASSERT( list2.contains( i ) );
+ }
+
+ CPPUNIT_ASSERT( list2.equals( list1 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testCopy2() {
+
+ StlSet<int> collection;
+
+ for( int i = 0; i < 50; ++i ) {
+ collection.add( i );
+ }
+
+ StlList<int> list;
+
+ list.copy( collection );
+
+ CPPUNIT_ASSERT( collection.size() == list.size() );
+
+ for( int i = 0; i < 50; ++i ) {
+ CPPUNIT_ASSERT( list.contains( i ) );
+ }
+
+ CPPUNIT_ASSERT( list.equals( collection ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
void ListTest::testContains(){
StlList<string> list;
@@ -59,12 +228,7 @@ void ListTest::testIndexOf(){
list.remove( "fred" );
CPPUNIT_ASSERT( list.indexOf( "bob" ) == 0 );
-
- CPPUNIT_ASSERT_THROW_MESSAGE(
- "Should throw an NoSuchElementException",
- list.indexOf( "fred" ),
- decaf::lang::exceptions::NoSuchElementException );
-
+ CPPUNIT_ASSERT( list.indexOf( "fred" ) == -1 );
CPPUNIT_ASSERT( list.indexOf( "george" ) == 1 );
CPPUNIT_ASSERT( list.indexOf( "steve" ) == 2 );
}
@@ -79,25 +243,18 @@ void ListTest::testLastIndexOf(){
list.add( "george" ); // 2
list.add( "bob" ); // 3
- CPPUNIT_ASSERT( list.indexOf( "bob" ) == 0 );
- CPPUNIT_ASSERT( list.lastIndexOf( "bob" ) == 3 );
+ CPPUNIT_ASSERT_MESSAGE( "indexOf 'bob' before remove failed", list.indexOf( "bob" ) == 0 );
+ CPPUNIT_ASSERT_MESSAGE( "lastIndexOf 'bob' before remove failed", list.lastIndexOf( "bob" ) == 3 );
list.remove( "fred" );
- CPPUNIT_ASSERT( list.indexOf( "bob" ) == 0 );
- CPPUNIT_ASSERT( list.lastIndexOf( "bob" ) == 2 );
+ CPPUNIT_ASSERT_MESSAGE( "indexOf 'bob' after remove failed", list.indexOf( "bob" ) == 0 );
+ CPPUNIT_ASSERT_MESSAGE( "lastIndexOf 'bob' after remove failed", list.lastIndexOf( "bob" ) == 2 );
list.remove( "bob" );
- CPPUNIT_ASSERT_THROW_MESSAGE(
- "Should throw an NoSuchElementException",
- list.lastIndexOf( "bob" ),
- decaf::lang::exceptions::NoSuchElementException );
-
- CPPUNIT_ASSERT_THROW_MESSAGE(
- "Should throw an NoSuchElementException",
- list.indexOf( "bob" ),
- decaf::lang::exceptions::NoSuchElementException );
+ CPPUNIT_ASSERT( list.indexOf( "bob" ) == -1 );
+ CPPUNIT_ASSERT( list.lastIndexOf( "bob" ) == -1 );
}
////////////////////////////////////////////////////////////////////////////////
@@ -226,6 +383,300 @@ void ListTest::testAdd2(){
}
////////////////////////////////////////////////////////////////////////////////
+void ListTest::testAdd3() {
+
+ StlList<int> array;
+ populate( array, SIZE );
+ std::vector<int> mirror;
+ populate( mirror, SIZE );
+
+ array.add( 50, 42 );
+ CPPUNIT_ASSERT_MESSAGE( "Failed to add Object", array.get( 50 ) == 42 );
+ CPPUNIT_ASSERT_MESSAGE( "Failed to fix up list after insert",
+ array.get( 51 ) == mirror[50] && ( array.get( 52 ) == mirror[51] ) );
+ int oldItem = array.get( 25 );
+ array.add( 25, 0 );
+ CPPUNIT_ASSERT_MESSAGE( "Should have returned zero", array.get( 25 ) == 0 );
+ CPPUNIT_ASSERT_MESSAGE( "Should have returned the old item from slot 25", array.get( 26 ) == oldItem );
+
+ array.add( 0, 84 );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Failed to add Object", array.get( 0 ), 84 );
+ CPPUNIT_ASSERT_EQUAL( array.get( 1 ), mirror[0] );
+ CPPUNIT_ASSERT_EQUAL( array.get( 2 ), mirror[1] );
+
+ oldItem = array.get( 0 );
+ array.add( 0, 0 );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Should have returned null", 0, array.get( 0 ) );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Should have returned the old item from slot 0", array.get( 1 ), oldItem );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ array.add( -1, 0 ),
+ IndexOutOfBoundsException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ array.add( array.size() + 1, 0 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testAddAll1() {
+
+ StlList<int> array;
+ populate( array, 100 );
+ std::vector<int> mirror;
+ populate( mirror, 100 );
+
+ array.addAll( 50, array );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Returned incorrect size after adding to existing list", 200, array.size() );
+
+ for( int i = 0; i < 50; i++ ) {
+ CPPUNIT_ASSERT_MESSAGE( "Manipulated elements < index", array.get( i ) == mirror[i] );
+ }
+
+ for( int i = 0; i >= 50 && ( i < 150 ); i++ ) {
+ CPPUNIT_ASSERT_MESSAGE( "Failed to ad elements properly", array.get( i ) == mirror[i - 50] );
+ }
+
+ for( int i = 0; i >= 150 && ( i < 200 ); i++ ) {
+ CPPUNIT_ASSERT_MESSAGE( "Failed to ad elements properly", array.get( i ) == mirror[i - 100] );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testAddAll2() {
+
+ StlList<int> emptyCollection;
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ StlList<int>().addAll( -1, emptyCollection ),
+ IndexOutOfBoundsException );
+
+ {
+ std::string data[] = { "1", "2", "3", "4", "5", "6", "7", "8" };
+ StlList<std::string> list1;
+ StlList<std::string> list2;
+ for( int i = 0; i < 8; ++i ) {
+ list1.add( data[i] );
+ list2.add( data[i] );
+ list2.add( data[i] );
+ }
+
+ while( list1.size() > 0 ) {
+ list1.removeAt( 0 );
+ }
+ list1.addAll( list2 );
+ CPPUNIT_ASSERT_MESSAGE( "The object list is not the same as original list",
+ list1.containsAll( list2 ) && list2.containsAll( list1 ) );
+
+ StlList<std::string> list3;
+ for( int i = 0; i < 100; i++ ) {
+ if( list1.size() > 0 ) {
+ list3.removeAll( list1 );
+ list3.addAll( list1 );
+ }
+ }
+ CPPUNIT_ASSERT_MESSAGE( "The object list is not the same as original list",
+ list3.containsAll( list1 ) && list1.containsAll( list3 ) );
+ }
+ {
+ StlList<std::string> list1;
+ StlList<std::string> list2;
+ int location = 2;
+
+ std::string data1[] = { "1", "2", "3", "4", "5", "6" };
+ std::string data2[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+ for( int i = 0; i < 6; i++ ) {
+ list1.add( data1[i] );
+ }
+ for( int i = 0; i < 8; i++ ) {
+ list2.add( data2[i] );
+ }
+
+ list1.removeAt( location );
+ list1.addAll( location, list2 );
+
+ // Inserted elements should be equal to second array
+ for( int i = 0; i < 8; i++ ) {
+ CPPUNIT_ASSERT_EQUAL( data2[i], list1.get( location + i ) );
+ }
+ // Elements after inserted location should
+ // be equals to related elements in first array
+ for( int i = location + 1; i < 6; i++ ) {
+ CPPUNIT_ASSERT_EQUAL( data1[i], list1.get( i + 8 - 1 ) );
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testAddAll3() {
+
+ StlList<int> list;
+ list.addAll( 0, list );
+ list.addAll( list.size(), list );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.addAll( -1, list ),
+ IndexOutOfBoundsException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.addAll( list.size() + 1, list ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testAddAll4() {
+
+ StlList<std::string> array;
+ StlList<std::string> blist;
+
+ array.add( "a" );
+ array.add( "b" );
+ blist.add( "c" );
+ blist.add( "d" );
+ blist.removeAt( 0 );
+ blist.addAll( 0, array );
+
+ CPPUNIT_ASSERT_EQUAL( std::string("a"), blist.get(0) );
+ CPPUNIT_ASSERT_EQUAL( std::string("b"), blist.get(1) );
+ CPPUNIT_ASSERT_EQUAL( std::string("d"), blist.get(2) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testAddAll5() {
+
+ StlList<std::string> array;
+ populate( array, 100 );
+
+ StlList<std::string> l;
+ l.addAll( array );
+ for( int i = 0; i < array.size(); i++ ) {
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Failed to add elements properly",
+ l.get(i), array.get( i ) );
+ }
+ array.addAll( array );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Returned incorrect size after adding to existing list",
+ 200, array.size());
+
+ for( int i = 0; i < 100; i++ ) {
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Added to list in incorrect order",
+ array.get(i), l.get(i) );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Failed to add to existing list",
+ array.get(i + 100), l.get(i) );
+ }
+
+ StlList<int> originalList;
+ for( int j = 0; j < 12; j++ ) {
+ originalList.add( j );
+ }
+
+ originalList.removeAt( 0 );
+ originalList.removeAt( 0 );
+
+ StlList<int> additionalList;
+ for( int j = 0; j < 11; j++ ) {
+ additionalList.add( j );
+ }
+ CPPUNIT_ASSERT( originalList.addAll( additionalList ) );
+ CPPUNIT_ASSERT_EQUAL( 21, originalList.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testAddAll6() {
+
+ StlList<int> arrayListA;
+ arrayListA.add( 1 );
+ StlList<int> arrayListB;
+ arrayListB.add( 1 );
+ arrayListA.addAll( 1, arrayListB );
+ int size = arrayListA.size();
+ CPPUNIT_ASSERT_EQUAL( 2, size );
+ for( int index = 0; index < size; index++ ) {
+ CPPUNIT_ASSERT_EQUAL( 1, arrayListA.get( index ) );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testAddAll7() {
+
+ StlList<int> arrayList;
+ arrayList.add( 1 );
+ arrayList.addAll( 1, arrayList );
+ int size = arrayList.size();
+ CPPUNIT_ASSERT_EQUAL( 2, size );
+ for( int index = 0; index < size; index++ ) {
+ CPPUNIT_ASSERT_EQUAL( 1, arrayList.get( index ) );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testAddAll8() {
+
+ StlList<std::string> arrayList;
+ arrayList.add( "1" );
+ arrayList.add( "2" );
+
+ StlList<std::string> list;
+ list.add( "a" );
+ list.add( 0, "b" );
+ list.add( 0, "c" );
+ list.add( 0, "d" );
+ list.add( 0, "e" );
+ list.add( 0, "f" );
+ list.add( 0, "g" );
+ list.add( 0, "h" );
+ list.add( 0, "i" );
+
+ list.addAll( 6, arrayList );
+
+ CPPUNIT_ASSERT_EQUAL( 11, list.size() );
+ CPPUNIT_ASSERT( !list.contains( "q" ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testAddAll9() {
+
+ StlList<std::string> list;
+ list.add( "one" );
+ list.add( "two" );
+ CPPUNIT_ASSERT_EQUAL( 2, list.size() );
+
+ list.removeAt( 0 );
+ CPPUNIT_ASSERT_EQUAL( 1, list.size() );
+
+ StlList<std::string> collection;
+ collection.add( "1" );
+ collection.add( "2" );
+ collection.add( "3" );
+ CPPUNIT_ASSERT_EQUAL( 3, collection.size() );
+
+ list.addAll( 0, collection );
+ CPPUNIT_ASSERT_EQUAL( 4, list.size() );
+
+ list.removeAt( 0 );
+ list.removeAt( 0 );
+ CPPUNIT_ASSERT_EQUAL( 2, list.size() );
+
+ collection.add( "4" );
+ collection.add( "5" );
+ collection.add( "6" );
+ collection.add( "7" );
+ collection.add( "8" );
+ collection.add( "9" );
+ collection.add( "10" );
+ collection.add( "11" );
+ collection.add( "12" );
+
+ CPPUNIT_ASSERT_EQUAL( 12, collection.size() );
+
+ list.addAll( 0, collection );
+ CPPUNIT_ASSERT_EQUAL( 14, list.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
void ListTest::testRemove(){
StlList<string> list;
@@ -245,18 +696,91 @@ void ListTest::testRemove2(){
list.add( "mike" );
list.add( "larry" );
- CPPUNIT_ASSERT( list.remove(0) == "fred" );
+ CPPUNIT_ASSERT( list.removeAt(0) == "fred" );
CPPUNIT_ASSERT( list.get(0) == "bob" );
- CPPUNIT_ASSERT( list.remove(2) == "mike" );
+ CPPUNIT_ASSERT( list.removeAt(2) == "mike" );
CPPUNIT_ASSERT( list.get(2) == "larry" );
CPPUNIT_ASSERT_THROW_MESSAGE(
"Should throw an IndexOutOfBoundsException",
- list.remove( list.size() + 1 ),
+ list.removeAt( list.size() + 1 ),
decaf::lang::exceptions::IndexOutOfBoundsException );
}
+//////////////////////////////////////////////////////////////////////////////
+void ListTest::testRemove3() {
+
+ StlList<int> list1;
+ populate( list1, SIZE );
+ StlList<int> list2;
+ populate( list2, SIZE );
+
+ list1.remove( 42 );
+ list2.remove( 42 );
+
+ CPPUNIT_ASSERT_MESSAGE( "Lists should be equal", list1.equals( list2 ) );
+ list1.remove( 42 );
+ CPPUNIT_ASSERT_MESSAGE( "Lists should be equal", list1.equals( list2 ) );
+
+ CPPUNIT_ASSERT( list1.remove( 0 ) );
+ CPPUNIT_ASSERT_MESSAGE( "Lists should not be equal", !list1.equals( list2 ) );
+
+ list1.clear();
+ populate( list1, SIZE );
+
+ for( int i = 0; i < SIZE; i++ ) {
+ CPPUNIT_ASSERT( list1.remove( i ) );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testRemoveAt() {
+
+ StlList<int> array;
+ populate( array, SIZE );
+
+ array.removeAt( 10 );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to remove element", -1, array.indexOf( 10 ) );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ array.removeAt( 9999 ),
+ IndexOutOfBoundsException );
+
+ StlList<int> myArray( array );
+ array.add( 25, 9999 );
+ array.add( 50, 9999 );
+ array.removeAt( 50 );
+ array.removeAt( 25 );
+ CPPUNIT_ASSERT_MESSAGE("Removing index did not work", array.equals( myArray ) );
+
+ std::string data[] = { "a", "b", "c", "d", "e", "f", "g" };
+ StlList<std::string> list;
+ for( int i = 0; i < 7; ++i ) {
+ list.add( data[i] );
+ }
+
+ CPPUNIT_ASSERT_MESSAGE( "Removed wrong element 1", list.removeAt(0) == "a" );
+ CPPUNIT_ASSERT_MESSAGE( "Removed wrong element 2", list.removeAt(4) == "f" );
+
+ StlList<int> l;
+ l.add( 5 );
+ l.add( 6 );
+ l.removeAt( 0 );
+ l.removeAt( 0 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ l.removeAt( -1 ),
+ IndexOutOfBoundsException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ l.removeAt( 0 ),
+ IndexOutOfBoundsException );
+}
+
////////////////////////////////////////////////////////////////////////////////
void ListTest::testToArray(){
@@ -305,3 +829,27 @@ void ListTest::testIterator(){
delete iterator1;
delete iterator2;
}
+
+//////////////////////////////////////////////////////////////////////////////
+void ListTest::testListIterator1IndexOutOfBoundsException() {
+
+ StlList<int> list;
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ std::auto_ptr< ListIterator<int> > it( list.listIterator( -1 ) ),
+ IndexOutOfBoundsException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void ListTest::testListIterator2IndexOutOfBoundsException() {
+
+ StlList<int> list;
+ list.add( 1 );
+ list.add( 2 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ std::auto_ptr< ListIterator<int> > it( list.listIterator( 100 ) ),
+ IndexOutOfBoundsException );
+}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/ListTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/ListTest.h?rev=1050221&r1=1050220&r2=1050221&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/ListTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/ListTest.h Thu Dec 16 23:18:02 2010
@@ -27,41 +27,85 @@ namespace util{
class ListTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( ListTest );
+ CPPUNIT_TEST( testConstructor1 );
+ CPPUNIT_TEST( testConstructor2 );
+ CPPUNIT_TEST( testConstructor3 );
+ CPPUNIT_TEST( testEquals );
CPPUNIT_TEST( testContains );
CPPUNIT_TEST( testIndexOf );
CPPUNIT_TEST( testLastIndexOf );
CPPUNIT_TEST( testClear );
+ CPPUNIT_TEST( testCopy1 );
+ CPPUNIT_TEST( testCopy2 );
CPPUNIT_TEST( testSize );
CPPUNIT_TEST( testGet );
CPPUNIT_TEST( testSet );
CPPUNIT_TEST( testAdd );
CPPUNIT_TEST( testAdd2 );
+ CPPUNIT_TEST( testAdd3 );
CPPUNIT_TEST( testRemove );
CPPUNIT_TEST( testRemove2 );
+ CPPUNIT_TEST( testRemove3 );
+ CPPUNIT_TEST( testRemoveAt );
CPPUNIT_TEST( testIsEmpty );
CPPUNIT_TEST( testToArray );
CPPUNIT_TEST( testIterator );
+ CPPUNIT_TEST( testAddAll1 );
+ CPPUNIT_TEST( testAddAll2 );
+ CPPUNIT_TEST( testAddAll3 );
+ CPPUNIT_TEST( testAddAll4 );
+ CPPUNIT_TEST( testAddAll5 );
+ CPPUNIT_TEST( testAddAll6 );
+ CPPUNIT_TEST( testAddAll7 );
+ CPPUNIT_TEST( testAddAll8 );
+ CPPUNIT_TEST( testAddAll9 );
+ CPPUNIT_TEST( testListIterator1IndexOutOfBoundsException );
+ CPPUNIT_TEST( testListIterator2IndexOutOfBoundsException );
CPPUNIT_TEST_SUITE_END();
+ private:
+
+ static const int SIZE;
+
public:
ListTest();
virtual ~ListTest() {}
+ void testConstructor1();
+ void testConstructor2();
+ void testConstructor3();
+ void testEquals();
void testContains();
void testIndexOf();
void testLastIndexOf();
void testClear();
+ void testCopy1();
+ void testCopy2();
void testSize();
void testGet();
void testSet();
void testAdd();
void testAdd2();
+ void testAdd3();
void testRemove();
void testRemove2();
+ void testRemove3();
+ void testRemoveAt();
void testIsEmpty();
void testToArray();
void testIterator();
+ void testAddAll1();
+ void testAddAll2();
+ void testAddAll3();
+ void testAddAll4();
+ void testAddAll5();
+ void testAddAll6();
+ void testAddAll7();
+ void testAddAll8();
+ void testAddAll9();
+ void testListIterator1IndexOutOfBoundsException();
+ void testListIterator2IndexOutOfBoundsException();
};
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/PriorityQueueTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/PriorityQueueTest.cpp?rev=1050221&r1=1050220&r2=1050221&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/PriorityQueueTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/PriorityQueueTest.cpp Thu Dec 16 23:18:02 2010
@@ -19,7 +19,7 @@
#include <decaf/util/PriorityQueue.h>
#include <decaf/util/Comparator.h>
-#include <decaf/util/StlList.h>
+#include <decaf/util/LinkedList.h>
#include <algorithm>
#include <memory>
@@ -72,7 +72,7 @@ void PriorityQueueTest::testConstructor_
void PriorityQueueTest::testConstructor_3() {
PriorityQueue<int> intQueue;
- StlList<int> collection;
+ LinkedList<int> collection;
int array[] = { 12, 2, 456, -11, 99, 111, 456 };
@@ -97,7 +97,7 @@ void PriorityQueueTest::testConstructor_
void PriorityQueueTest::testAssignment() {
PriorityQueue<int> intQueue;
- StlList<int> collection;
+ LinkedList<int> collection;
int array[] = { 12, 2, 456, -11, 99, 111, 456 };
@@ -161,7 +161,7 @@ void PriorityQueueTest::testOfferString(
CPPUNIT_ASSERT_THROW_MESSAGE(
"Should Throw a NoSuchElementException",
queue.remove(),
- decaf::lang::exceptions::NoSuchElementException );
+ decaf::util::NoSuchElementException );
}
////////////////////////////////////////////////////////////////////////////////
@@ -261,7 +261,7 @@ void PriorityQueueTest::testAdd() {
void PriorityQueueTest::testAddAll() {
PriorityQueue<int> integerQueue;
- StlList<int> list;
+ LinkedList<int> list;
list.add( 2 );
list.add( 45 );
list.add( 7 );
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/SetTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/SetTest.cpp?rev=1050221&r1=1050220&r2=1050221&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/SetTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/SetTest.cpp Thu Dec 16 23:18:02 2010
@@ -18,6 +18,7 @@
#include "SetTest.h"
#include <decaf/util/StlSet.h>
+#include <decaf/util/LinkedList.h>
#include <decaf/util/Iterator.h>
using namespace std;
@@ -29,6 +30,109 @@ SetTest::SetTest(){
}
////////////////////////////////////////////////////////////////////////////////
+void SetTest::testConstructor1(){
+
+ StlSet<int> set;
+
+ CPPUNIT_ASSERT( set.size() == 0 );
+ CPPUNIT_ASSERT( set.isEmpty() );
+
+ set.add( 1 );
+
+ CPPUNIT_ASSERT( set.size() == 1 );
+ CPPUNIT_ASSERT( !set.isEmpty() );
+
+ set.add( 1 );
+
+ CPPUNIT_ASSERT( set.size() == 1 );
+ CPPUNIT_ASSERT( !set.isEmpty() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SetTest::testConstructor2(){
+
+ StlSet<int> set1;
+
+ for( int i = 0; i < 50; ++i ) {
+ set1.add( i );
+ }
+
+ StlSet<int> set2( set1 );
+
+ CPPUNIT_ASSERT( set1.size() == set2.size() );
+
+ for( int i = 0; i < 50; ++i ) {
+ CPPUNIT_ASSERT( set2.contains( i ) );
+ }
+
+ CPPUNIT_ASSERT( set2.equals( set1 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SetTest::testConstructor3(){
+
+ LinkedList<int> collection;
+
+ for( int i = 0; i < 50; ++i ) {
+ collection.add( i );
+ }
+
+ StlSet<int> set( collection );
+
+ CPPUNIT_ASSERT( collection.size() == set.size() );
+
+ for( int i = 0; i < 50; ++i ) {
+ CPPUNIT_ASSERT( set.contains( i ) );
+ }
+
+ CPPUNIT_ASSERT( set.equals( collection ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SetTest::testCopy1() {
+
+ StlSet<int> set1;
+
+ for( int i = 0; i < 50; ++i ) {
+ set1.add( i );
+ }
+
+ StlSet<int> set2;
+
+ set2.copy( set1 );
+
+ CPPUNIT_ASSERT( set1.size() == set2.size() );
+
+ for( int i = 0; i < 50; ++i ) {
+ CPPUNIT_ASSERT( set2.contains( i ) );
+ }
+
+ CPPUNIT_ASSERT( set2.equals( set1 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void SetTest::testCopy2() {
+
+ LinkedList<int> collection;
+
+ for( int i = 0; i < 50; ++i ) {
+ collection.add( i );
+ }
+
+ StlSet<int> set;
+
+ set.copy( collection );
+
+ CPPUNIT_ASSERT( collection.size() == set.size() );
+
+ for( int i = 0; i < 50; ++i ) {
+ CPPUNIT_ASSERT( set.contains( i ) );
+ }
+
+ CPPUNIT_ASSERT( set.equals( collection ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
void SetTest::testContains(){
StlSet<string> set;
@@ -36,8 +140,8 @@ void SetTest::testContains(){
set.add( "bob" );
- CPPUNIT_ASSERT(set.contains( "bob" ) == true );
- CPPUNIT_ASSERT(set.contains( "fred" ) == false );
+ CPPUNIT_ASSERT( set.contains( "bob" ) == true );
+ CPPUNIT_ASSERT( set.contains( "fred" ) == false );
}
////////////////////////////////////////////////////////////////////////////////
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/SetTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/SetTest.h?rev=1050221&r1=1050220&r2=1050221&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/SetTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/SetTest.h Thu Dec 16 23:18:02 2010
@@ -27,8 +27,13 @@ namespace util{
class SetTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( SetTest );
+ CPPUNIT_TEST( testConstructor1 );
+ CPPUNIT_TEST( testConstructor2 );
+ CPPUNIT_TEST( testConstructor3 );
CPPUNIT_TEST( testContains );
CPPUNIT_TEST( testClear );
+ CPPUNIT_TEST( testCopy1 );
+ CPPUNIT_TEST( testCopy2 );
CPPUNIT_TEST( testSize );
CPPUNIT_TEST( testAdd );
CPPUNIT_TEST( testRemove );
@@ -42,8 +47,13 @@ namespace util{
SetTest();
virtual ~SetTest() {}
+ void testConstructor1();
+ void testConstructor2();
+ void testConstructor3();
void testContains();
void testClear();
+ void testCopy1();
+ void testCopy2();
void testSize();
void testAdd();
void testRemove();
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=1050221&r1=1050220&r2=1050221&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 Dec 16 23:18:02 2010
@@ -98,7 +98,7 @@ public:
/**
* {@inheritDoc}
*/
- virtual void clear() throw( decaf::lang::exceptions::UnsupportedOperationException ) {
+ virtual void clear() {
valueMap.clear();
}
@@ -147,25 +147,23 @@ public:
/**
* {@inheritDoc}
*/
- virtual V& get( const K& key )
- throw( lang::exceptions::NoSuchElementException ) {
+ virtual V& get( const K& key ) {
typename std::map<K,V,COMPARATOR>::iterator iter;
iter = valueMap.find( key );
if( iter == valueMap.end() ){
- throw lang::exceptions::NoSuchElementException(
+ throw util::NoSuchElementException(
__FILE__, __LINE__, "Key does not exist in map" );
}
return iter->second;
}
- virtual const V& get( const K& key ) const
- throw( lang::exceptions::NoSuchElementException ) {
+ virtual const V& get( const K& key ) const {
typename std::map<K,V,COMPARATOR>::const_iterator iter;
iter = valueMap.find( key );
if( iter == valueMap.end() ){
- throw lang::exceptions::NoSuchElementException(
+ throw util::NoSuchElementException(
__FILE__, __LINE__, "Key does not exist in map" );
}
@@ -175,8 +173,7 @@ public:
/**
* {@inheritDoc}
*/
- virtual void put( const K& key, const V& value )
- throw ( decaf::lang::exceptions::UnsupportedOperationException ) {
+ virtual void put( const K& key, const V& value ) {
valueMap[key] = value;
}
@@ -184,13 +181,11 @@ public:
/**
* {@inheritDoc}
*/
- virtual void putAll( const StlTestMap<K,V,COMPARATOR>& other )
- throw ( decaf::lang::exceptions::UnsupportedOperationException ) {
+ virtual void putAll( const StlTestMap<K,V,COMPARATOR>& other ) {
this->valueMap.insert( other.valueMap.begin(), other.valueMap.end() );
}
- virtual void putAll( const Map<K,V,COMPARATOR>& other )
- throw ( decaf::lang::exceptions::UnsupportedOperationException ) {
+ virtual void putAll( const Map<K,V,COMPARATOR>& other ) {
std::vector<K> keys = other.keySet();
@@ -204,13 +199,11 @@ public:
/**
* {@inheritDoc}
*/
- virtual V remove( const K& key )
- throw ( decaf::lang::exceptions::NoSuchElementException,
- decaf::lang::exceptions::UnsupportedOperationException ) {
+ virtual V remove( const K& key ) {
typename std::map<K,V,COMPARATOR>::iterator iter = valueMap.find( key );
if( iter == valueMap.end() ) {
- throw decaf::lang::exceptions::NoSuchElementException(
+ throw decaf::util::NoSuchElementException(
__FILE__, __LINE__, "Key is not present in this Map." );
}
@@ -251,50 +244,39 @@ public:
public:
- virtual void lock() throw( decaf::lang::exceptions::RuntimeException ) {
+ virtual void lock() {
mutex.lock();
}
- virtual bool tryLock() throw( decaf::lang::exceptions::RuntimeException ) {
+ virtual bool tryLock() {
return mutex.tryLock();
}
- virtual void unlock() throw( decaf::lang::exceptions::RuntimeException ) {
+ virtual void unlock() {
mutex.unlock();
}
- virtual void wait() throw( decaf::lang::exceptions::RuntimeException,
- decaf::lang::exceptions::IllegalMonitorStateException,
- decaf::lang::exceptions::InterruptedException ) {
+ virtual void wait() {
mutex.wait();
}
- virtual void wait( long long millisecs )
- throw( decaf::lang::exceptions::RuntimeException,
- decaf::lang::exceptions::IllegalMonitorStateException,
- decaf::lang::exceptions::InterruptedException ) {
+ virtual void wait( long long millisecs ) {
mutex.wait( millisecs );
}
- virtual void wait( long long millisecs, int nanos )
- throw( decaf::lang::exceptions::RuntimeException,
- decaf::lang::exceptions::IllegalArgumentException,
- decaf::lang::exceptions::IllegalMonitorStateException,
- decaf::lang::exceptions::InterruptedException ) {
+ virtual void wait( long long millisecs, int nanos ) {
mutex.wait( millisecs, nanos );
}
- virtual void notify() throw( decaf::lang::exceptions::RuntimeException,
- decaf::lang::exceptions::IllegalMonitorStateException ) {
+ virtual void notify() {
mutex.notify();
}
- virtual void notifyAll() throw( decaf::lang::exceptions::RuntimeException,
- decaf::lang::exceptions::IllegalMonitorStateException ) {
+ virtual void notifyAll() {
mutex.notifyAll();
}
@@ -311,7 +293,7 @@ void StlMapTest::testConstructor() {
CPPUNIT_ASSERT_THROW_MESSAGE(
"Should Throw a NoSuchElementException",
map1.get( "TEST" ),
- decaf::lang::exceptions::NoSuchElementException );
+ decaf::util::NoSuchElementException );
StlTestMap<string, int> srcMap;
srcMap.put( "A", 1 );
@@ -439,7 +421,7 @@ void StlMapTest::testGet() {
try{
boolMap.get( "mike" );
CPPUNIT_ASSERT(false);
- } catch( decaf::lang::exceptions::NoSuchElementException& e ){
+ } catch( decaf::util::NoSuchElementException& e ){
}
}
@@ -496,6 +478,6 @@ void StlMapTest::testRemove() {
CPPUNIT_ASSERT_THROW_MESSAGE(
"Should throw a NoSuchElementException",
boolMap.remove( "fred" ),
- decaf::lang::exceptions::NoSuchElementException );
+ decaf::util::NoSuchElementException );
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StringTokenizerTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StringTokenizerTest.cpp?rev=1050221&r1=1050220&r2=1050221&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StringTokenizerTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/StringTokenizerTest.cpp Thu Dec 16 23:18:02 2010
@@ -53,7 +53,7 @@ void StringTokenizerTest::test()
tokenizer3.nextToken();
CPPUNIT_ASSERT( false );
}
- catch(lang::exceptions::NoSuchElementException ex)
+ catch(decaf::util::NoSuchElementException ex)
{
CPPUNIT_ASSERT( true );
}
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=1050221&r1=1050220&r2=1050221&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 Dec 16 23:18:02 2010
@@ -87,7 +87,7 @@ void ConcurrentStlMapTest::testValue(){
try{
boolMap.get( "mike" );
CPPUNIT_ASSERT(false);
- } catch( decaf::lang::exceptions::NoSuchElementException& e ){
+ } catch( decaf::util::NoSuchElementException& e ){
}
}
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArrayListTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArrayListTest.cpp?rev=1050221&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArrayListTest.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArrayListTest.cpp Thu Dec 16 23:18:02 2010
@@ -0,0 +1,959 @@
+/*
+ * 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 "CopyOnWriteArrayListTest.h"
+
+#include <decaf/util/concurrent/CopyOnWriteArrayList.h>
+#include <decaf/util/StlList.h>
+#include <decaf/lang/Integer.h>
+
+using namespace decaf;
+using namespace decaf::util;
+using namespace decaf::util::concurrent;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+const int CopyOnWriteArrayListTest::SIZE = 256;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace {
+
+ void populate( CopyOnWriteArrayList<int>& list, int n ) {
+
+ CPPUNIT_ASSERT( list.isEmpty() );
+
+ for( int i = 0; i < n; ++i ) {
+ list.add( i );
+ }
+
+ CPPUNIT_ASSERT( !list.isEmpty());
+ CPPUNIT_ASSERT_EQUAL( n, list.size() );
+ }
+
+ void populate( CopyOnWriteArrayList<std::string>& list, int n ) {
+
+ CPPUNIT_ASSERT( list.isEmpty() );
+
+ for( int i = 0; i < n; ++i ) {
+ list.add( Integer::toString( i ) );
+ }
+
+ CPPUNIT_ASSERT( !list.isEmpty());
+ CPPUNIT_ASSERT_EQUAL( n, list.size() );
+ }
+
+ void populate( std::vector<int>& list, int n ) {
+
+ CPPUNIT_ASSERT( list.empty() );
+
+ for( int i = 0; i < n; ++i ) {
+ list.push_back( i );
+ }
+
+ CPPUNIT_ASSERT( !list.empty());
+ CPPUNIT_ASSERT_EQUAL( n, (int)list.size() );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CopyOnWriteArrayListTest::CopyOnWriteArrayListTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CopyOnWriteArrayListTest::~CopyOnWriteArrayListTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testConstructor1() {
+
+ CopyOnWriteArrayList<int> array;
+ CPPUNIT_ASSERT( array.isEmpty() );
+ CPPUNIT_ASSERT( array.size() == 0 );
+
+ CopyOnWriteArrayList<std::string> strArray;
+ CPPUNIT_ASSERT( strArray.isEmpty() );
+ CPPUNIT_ASSERT( strArray.size() == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testConstructor2() {
+
+ StlList<int> intsList;
+
+ for( int i = 0; i < SIZE; ++i ) {
+ intsList.add( i );
+ }
+
+ CopyOnWriteArrayList<int> array( intsList );
+ CPPUNIT_ASSERT( !array.isEmpty() );
+ CPPUNIT_ASSERT( array.size() == SIZE );
+
+ for( int i = 0; i < SIZE; ++i ) {
+ CPPUNIT_ASSERT_EQUAL( intsList.get( i ), array.get( i ) );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testConstructor3() {
+
+ int ints[SIZE];
+
+ for( int i = 0; i < SIZE; ++i ) {
+ ints[i] = i;
+ }
+
+ CopyOnWriteArrayList<int> array( ints, SIZE );
+ CPPUNIT_ASSERT( !array.isEmpty() );
+ CPPUNIT_ASSERT( array.size() == SIZE );
+
+ for( int i = 0; i < SIZE; ++i ) {
+ CPPUNIT_ASSERT_EQUAL( ints[i], array.get( i ) );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAll() {
+
+ CopyOnWriteArrayList<int> list;
+ for( int i = 0; i < 3; ++i ) {
+ list.add( i );
+ }
+
+ StlList<int> collection;
+ for( int i = 3; i < 6; ++i ) {
+ collection.add( i );
+ }
+
+ list.addAll( collection );
+ CPPUNIT_ASSERT_EQUAL( 6, list.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAll1() {
+
+ CopyOnWriteArrayList<int> array;
+ populate( array, 100 );
+ std::vector<int> mirror;
+ populate( mirror, 100 );
+
+ array.addAll( 50, array );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Returned incorrect size after adding to existing list", 200, array.size() );
+
+ for( int i = 0; i < 50; i++ ) {
+ CPPUNIT_ASSERT_MESSAGE( "Manipulated elements < index", array.get( i ) == mirror[i] );
+ }
+
+ for( int i = 0; i >= 50 && ( i < 150 ); i++ ) {
+ CPPUNIT_ASSERT_MESSAGE( "Failed to ad elements properly", array.get( i ) == mirror[i - 50] );
+ }
+
+ for( int i = 0; i >= 150 && ( i < 200 ); i++ ) {
+ CPPUNIT_ASSERT_MESSAGE( "Failed to ad elements properly", array.get( i ) == mirror[i - 100] );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAll2() {
+
+ StlList<int> emptyCollection;
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ CopyOnWriteArrayList<int>().addAll( -1, emptyCollection ),
+ IndexOutOfBoundsException );
+
+ {
+ std::string data[] = { "1", "2", "3", "4", "5", "6", "7", "8" };
+ CopyOnWriteArrayList<std::string> list1;
+ CopyOnWriteArrayList<std::string> list2;
+ for( int i = 0; i < 8; ++i ) {
+ list1.add( data[i] );
+ list2.add( data[i] );
+ list2.add( data[i] );
+ }
+
+ while( list1.size() > 0 ) {
+ list1.removeAt( 0 );
+ }
+ list1.addAll( list2 );
+ CPPUNIT_ASSERT_MESSAGE( "The object list is not the same as original list",
+ list1.containsAll( list2 ) && list2.containsAll( list1 ) );
+
+ CopyOnWriteArrayList<std::string> list3;
+ for( int i = 0; i < 100; i++ ) {
+ if( list1.size() > 0 ) {
+ list3.removeAll( list1 );
+ list3.addAll( list1 );
+ }
+ }
+ CPPUNIT_ASSERT_MESSAGE( "The object list is not the same as original list",
+ list3.containsAll( list1 ) && list1.containsAll( list3 ) );
+ }
+ {
+ CopyOnWriteArrayList<std::string> list1;
+ CopyOnWriteArrayList<std::string> list2;
+ int location = 2;
+
+ std::string data1[] = { "1", "2", "3", "4", "5", "6" };
+ std::string data2[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+ for( int i = 0; i < 6; i++ ) {
+ list1.add( data1[i] );
+ }
+ for( int i = 0; i < 8; i++ ) {
+ list2.add( data2[i] );
+ }
+
+ list1.removeAt( location );
+ list1.addAll( location, list2 );
+
+ // Inserted elements should be equal to second array
+ for( int i = 0; i < 8; i++ ) {
+ CPPUNIT_ASSERT_EQUAL( data2[i], list1.get( location + i ) );
+ }
+ // Elements after inserted location should
+ // be equals to related elements in first array
+ for( int i = location + 1; i < 6; i++ ) {
+ CPPUNIT_ASSERT_EQUAL( data1[i], list1.get( i + 8 - 1 ) );
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAll3() {
+
+ CopyOnWriteArrayList<int> list;
+ list.addAll( 0, list );
+ list.addAll( list.size(), list );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.addAll( -1, list ),
+ IndexOutOfBoundsException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.addAll( list.size() + 1, list ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAll4() {
+
+ CopyOnWriteArrayList<std::string> array;
+ CopyOnWriteArrayList<std::string> blist;
+
+ array.add( "a" );
+ array.add( "b" );
+ blist.add( "c" );
+ blist.add( "d" );
+ blist.removeAt( 0 );
+ blist.addAll( 0, array );
+
+ CPPUNIT_ASSERT_EQUAL( std::string("a"), blist.get(0) );
+ CPPUNIT_ASSERT_EQUAL( std::string("b"), blist.get(1) );
+ CPPUNIT_ASSERT_EQUAL( std::string("d"), blist.get(2) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAll5() {
+
+ CopyOnWriteArrayList<std::string> array;
+ populate( array, 100 );
+
+ CopyOnWriteArrayList<std::string> l;
+ l.addAll( array );
+ for( int i = 0; i < array.size(); i++ ) {
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Failed to add elements properly",
+ l.get(i), array.get( i ) );
+ }
+ array.addAll( array );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Returned incorrect size after adding to existing list",
+ 200, array.size());
+
+ for( int i = 0; i < 100; i++ ) {
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Added to list in incorrect order",
+ array.get(i), l.get(i) );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( "Failed to add to existing list",
+ array.get(i + 100), l.get(i) );
+ }
+
+ CopyOnWriteArrayList<int> originalList;
+ for( int j = 0; j < 12; j++ ) {
+ originalList.add( j );
+ }
+
+ originalList.removeAt( 0 );
+ originalList.removeAt( 0 );
+
+ CopyOnWriteArrayList<int> additionalList;
+ for( int j = 0; j < 11; j++ ) {
+ additionalList.add( j );
+ }
+ CPPUNIT_ASSERT( originalList.addAll( additionalList ) );
+ CPPUNIT_ASSERT_EQUAL( 21, originalList.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAll6() {
+
+ CopyOnWriteArrayList<int> arrayListA;
+ arrayListA.add( 1 );
+ CopyOnWriteArrayList<int> arrayListB;
+ arrayListB.add( 1 );
+ arrayListA.addAll( 1, arrayListB );
+ int size = arrayListA.size();
+ CPPUNIT_ASSERT_EQUAL( 2, size );
+ for( int index = 0; index < size; index++ ) {
+ CPPUNIT_ASSERT_EQUAL( 1, arrayListA.get( index ) );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAll7() {
+
+ CopyOnWriteArrayList<int> arrayList;
+ arrayList.add( 1 );
+ arrayList.addAll( 1, arrayList );
+ int size = arrayList.size();
+ CPPUNIT_ASSERT_EQUAL( 2, size );
+ for( int index = 0; index < size; index++ ) {
+ CPPUNIT_ASSERT_EQUAL( 1, arrayList.get( index ) );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAll8() {
+
+ CopyOnWriteArrayList<std::string> arrayList;
+ arrayList.add( "1" );
+ arrayList.add( "2" );
+
+ CopyOnWriteArrayList<std::string> list;
+ list.add( "a" );
+ list.add( 0, "b" );
+ list.add( 0, "c" );
+ list.add( 0, "d" );
+ list.add( 0, "e" );
+ list.add( 0, "f" );
+ list.add( 0, "g" );
+ list.add( 0, "h" );
+ list.add( 0, "i" );
+
+ list.addAll( 6, arrayList );
+
+ CPPUNIT_ASSERT_EQUAL( 11, list.size() );
+ CPPUNIT_ASSERT( !list.contains( "q" ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAll9() {
+
+ CopyOnWriteArrayList<std::string> list;
+ list.add( "one" );
+ list.add( "two" );
+ CPPUNIT_ASSERT_EQUAL( 2, list.size() );
+
+ list.removeAt( 0 );
+ CPPUNIT_ASSERT_EQUAL( 1, list.size() );
+
+ CopyOnWriteArrayList<std::string> collection;
+ collection.add( "1" );
+ collection.add( "2" );
+ collection.add( "3" );
+ CPPUNIT_ASSERT_EQUAL( 3, collection.size() );
+
+ list.addAll( 0, collection );
+ CPPUNIT_ASSERT_EQUAL( 4, list.size() );
+
+ list.removeAt( 0 );
+ list.removeAt( 0 );
+ CPPUNIT_ASSERT_EQUAL( 2, list.size() );
+
+ collection.add( "4" );
+ collection.add( "5" );
+ collection.add( "6" );
+ collection.add( "7" );
+ collection.add( "8" );
+ collection.add( "9" );
+ collection.add( "10" );
+ collection.add( "11" );
+ collection.add( "12" );
+
+ CPPUNIT_ASSERT_EQUAL( 12, collection.size() );
+
+ list.addAll( 0, collection );
+ CPPUNIT_ASSERT_EQUAL( 14, list.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testClear() {
+
+ CopyOnWriteArrayList<int> list;
+
+ populate( list, SIZE );
+
+ CPPUNIT_ASSERT( !list.isEmpty() );
+
+ list.clear();
+
+ CPPUNIT_ASSERT( list.isEmpty() );
+ CPPUNIT_ASSERT_EQUAL( 0, list.size() );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testContains() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, 3 );
+
+ CPPUNIT_ASSERT( list.contains( 1 ) );
+ CPPUNIT_ASSERT( !list.contains( 5 ) );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testGet() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, 3 );
+
+ CPPUNIT_ASSERT_EQUAL( 0, list.get( 0 ) );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testIsEmpty() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, SIZE );
+
+ CopyOnWriteArrayList<int> empty;
+
+ CPPUNIT_ASSERT( empty.isEmpty() );
+ CPPUNIT_ASSERT( !list.isEmpty() );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testIndexOf1() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, 3 );
+
+ CPPUNIT_ASSERT_EQUAL( 1, list.indexOf( 1 ) );
+ CPPUNIT_ASSERT_EQUAL( -1, list.indexOf( 99 ) );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testLastIndexOf1() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, 3 );
+ list.add( 1 );
+ list.add( 3 );
+ CPPUNIT_ASSERT_EQUAL( 3, list.lastIndexOf( 1 ) );
+ CPPUNIT_ASSERT_EQUAL( -1, list.lastIndexOf( 6 ) );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddIndex() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, 3 );
+
+ list.add( 0, 4 );
+ CPPUNIT_ASSERT_EQUAL( 4, list.size() );
+ CPPUNIT_ASSERT_EQUAL( 4, list.get( 0 ) );
+ CPPUNIT_ASSERT_EQUAL( 0, list.get( 1 ) );
+
+ list.add( 2, 6 );
+ CPPUNIT_ASSERT_EQUAL( 5, list.size() );
+ CPPUNIT_ASSERT_EQUAL( 6, list.get( 2 ) );
+ CPPUNIT_ASSERT_EQUAL( 2, list.get( 4 ) );
+
+ CopyOnWriteArrayList<int> list2;
+ list2.add( 0, 42 );
+ CPPUNIT_ASSERT_EQUAL( 1, list2.size() );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAllIndex() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, 3 );
+
+ StlList<int> collection;
+ for( int i = 0; i < 6; ++i ) {
+ collection.add( i + 10 );
+ }
+
+ list.addAll( 0, collection );
+ CPPUNIT_ASSERT_EQUAL( 9, list.size() );
+ CPPUNIT_ASSERT_EQUAL( 10, list.get( 0 ) );
+ CPPUNIT_ASSERT_EQUAL( 0, list.get( 6 ) );
+
+ list.addAll( 6, collection );
+ CPPUNIT_ASSERT_EQUAL( 15, list.size() );
+ CPPUNIT_ASSERT_EQUAL( 10, list.get( 6 ) );
+ CPPUNIT_ASSERT_EQUAL( 0, list.get( 12 ) );
+
+ CopyOnWriteArrayList<int> list2;
+ list2.addAll( 0, collection );
+ CPPUNIT_ASSERT_EQUAL( 6, list2.size() );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testContainsAll() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, 7 );
+
+ StlList<int> collection;
+ for( int i = 0; i < 6; ++i ) {
+ collection.add( i );
+ }
+
+ CPPUNIT_ASSERT( list.containsAll( collection ) );
+ collection.add( 42 );
+ CPPUNIT_ASSERT( !list.containsAll( collection ) );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testEquals() {
+
+ CopyOnWriteArrayList<int> list1;
+ populate( list1, 7 );
+ CopyOnWriteArrayList<int> list2;
+ populate( list2, 7 );
+
+ CPPUNIT_ASSERT( list1.equals( list2 ) );
+ CPPUNIT_ASSERT( list2.equals( list1 ) );
+
+ list1.add( 42 );
+ CPPUNIT_ASSERT( !list1.equals( list2 ) );
+ CPPUNIT_ASSERT( !list2.equals( list1 ) );
+ list2.add( 42 );
+ CPPUNIT_ASSERT( list1.equals( list2 ) );
+ CPPUNIT_ASSERT( list2.equals( list1 ) );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testRemove() {
+
+ CopyOnWriteArrayList<int> list1;
+ populate( list1, SIZE );
+ CopyOnWriteArrayList<int> list2;
+ populate( list2, SIZE );
+
+ list1.remove( 42 );
+ list2.remove( 42 );
+
+ CPPUNIT_ASSERT_MESSAGE( "Lists should be equal", list1.equals( list2 ) );
+ list1.remove( 42 );
+ CPPUNIT_ASSERT_MESSAGE( "Lists should be equal", list1.equals( list2 ) );
+
+ CPPUNIT_ASSERT( list1.remove( 0 ) );
+ CPPUNIT_ASSERT_MESSAGE( "Lists should not be equal", !list1.equals( list2 ) );
+
+ list1.clear();
+ populate( list1, SIZE );
+
+ for( int i = 0; i < SIZE; i++ ) {
+ CPPUNIT_ASSERT( list1.remove( i ) );
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testRemoveAt() {
+
+ CopyOnWriteArrayList<int> list1;
+ populate( list1, 7 );
+ CopyOnWriteArrayList<int> list2;
+ populate( list2, 7 );
+
+ CPPUNIT_ASSERT_EQUAL( 2, list1.removeAt( 2 ) );
+ CPPUNIT_ASSERT_EQUAL( 6, list1.size() );
+ CPPUNIT_ASSERT_EQUAL( 3, list1.removeAt( 2 ) );
+ CPPUNIT_ASSERT_EQUAL( 5, list1.size() );
+
+ CPPUNIT_ASSERT_EQUAL( 6, list2.removeAt( 6 ) );
+ CPPUNIT_ASSERT_EQUAL( 6, list2.size() );
+ CPPUNIT_ASSERT_EQUAL( 0, list2.removeAt( 0 ) );
+ CPPUNIT_ASSERT_EQUAL( 5, list2.size() );
+ CPPUNIT_ASSERT_EQUAL( 5, list2.removeAt( 4 ) );
+ CPPUNIT_ASSERT_EQUAL( 4, list2.size() );
+ CPPUNIT_ASSERT_EQUAL( 1, list2.removeAt( 0 ) );
+ CPPUNIT_ASSERT_EQUAL( 3, list2.size() );
+ CPPUNIT_ASSERT_EQUAL( 4, list2.removeAt( 2 ) );
+ CPPUNIT_ASSERT_EQUAL( 2, list2.size() );
+ CPPUNIT_ASSERT_EQUAL( 2, list2.removeAt( 0 ) );
+ CPPUNIT_ASSERT_EQUAL( 1, list2.size() );
+ CPPUNIT_ASSERT_EQUAL( 3, list2.removeAt( 0 ) );
+ CPPUNIT_ASSERT_EQUAL( 0, list2.size() );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddIfAbsent1() {
+ CopyOnWriteArrayList<int> list;
+ populate( list, SIZE );
+
+ list.addIfAbsent( 1 );
+
+ CPPUNIT_ASSERT_EQUAL( SIZE, list.size() );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddIfAbsent2() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, SIZE );
+
+ CPPUNIT_ASSERT( !list.contains(SIZE) );
+ list.addIfAbsent( SIZE );
+ CPPUNIT_ASSERT( list.contains(SIZE) );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testIterator() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, SIZE );
+
+ std::auto_ptr< Iterator<int> > i( list.iterator() );
+ int j;
+ for( j = 0; i->hasNext(); j++ ) {
+ CPPUNIT_ASSERT_EQUAL( j, i->next() );
+ }
+
+ CPPUNIT_ASSERT_EQUAL( SIZE, j );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testIteratorRemove() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, SIZE );
+
+ std::auto_ptr< Iterator<int> > it( list.iterator() );
+
+ it->next();
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an UnsupportedOperationException",
+ it->remove(),
+ UnsupportedOperationException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testListIterator1() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, SIZE );
+
+ std::auto_ptr< ListIterator<int> > i( list.listIterator() );
+ int j;
+ for( j = 0; i->hasNext(); j++ ) {
+ CPPUNIT_ASSERT_EQUAL( j, i->next() );
+ }
+
+ CPPUNIT_ASSERT_EQUAL( SIZE, j );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testListIterator2() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, SIZE );
+
+ std::auto_ptr< ListIterator<int> > i( list.listIterator( 1 ) );
+ int j;
+ for( j = 0; i->hasNext(); j++ ) {
+ CPPUNIT_ASSERT_EQUAL( j+1, i->next() );
+ }
+
+ CPPUNIT_ASSERT_EQUAL( SIZE - 1, j );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testSet() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, SIZE );
+
+ CPPUNIT_ASSERT_EQUAL( 2, list.set( 2, 4 ) );
+ CPPUNIT_ASSERT_EQUAL( 4, list.get( 2 ) );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testSize() {
+
+ CopyOnWriteArrayList<int> empty;
+ CopyOnWriteArrayList<int> list;
+ populate( list, SIZE );
+
+ CPPUNIT_ASSERT_EQUAL( SIZE, list.size() );
+ CPPUNIT_ASSERT_EQUAL( 0, empty.size() );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAll1IndexOutOfBoundsException() {
+
+ CopyOnWriteArrayList<int> list;
+ StlList<int> collection;
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.addAll( -1, collection ),
+ IndexOutOfBoundsException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAll2IndexOutOfBoundsException() {
+
+ CopyOnWriteArrayList<int> list;
+ list.add( 1 );
+ list.add( 2 );
+
+ StlList<int> collection;
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.addAll( 100, collection ),
+ IndexOutOfBoundsException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testListIterator1IndexOutOfBoundsException() {
+
+ CopyOnWriteArrayList<int> list;
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ std::auto_ptr< ListIterator<int> > it( list.listIterator( -1 ) ),
+ IndexOutOfBoundsException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testListIterator2IndexOutOfBoundsException() {
+
+ CopyOnWriteArrayList<int> list;
+ list.add( 1 );
+ list.add( 2 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ std::auto_ptr< ListIterator<int> > it( list.listIterator( 100 ) ),
+ IndexOutOfBoundsException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAdd1IndexOutOfBoundsException() {
+
+ CopyOnWriteArrayList<int> list;
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.add( -1, 42 ),
+ IndexOutOfBoundsException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAdd2IndexOutOfBoundsException() {
+
+ CopyOnWriteArrayList<int> list;
+ list.add( 1 );
+ list.add( 2 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.add( 100, 42 ),
+ IndexOutOfBoundsException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testRemoveAt1IndexOutOfBounds() {
+
+ CopyOnWriteArrayList<int> list;
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.removeAt( -1 ),
+ IndexOutOfBoundsException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testRemoveAt2IndexOutOfBounds() {
+
+ CopyOnWriteArrayList<int> list;
+ list.add( 1 );
+ list.add( 2 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.removeAt( 100 ),
+ IndexOutOfBoundsException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testGet1IndexOutOfBoundsException() {
+
+ CopyOnWriteArrayList<int> list;
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.get( -1 ),
+ IndexOutOfBoundsException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testGet2IndexOutOfBoundsException() {
+
+ CopyOnWriteArrayList<int> list;
+ list.add( 1 );
+ list.add( 2 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.get( 100 ),
+ IndexOutOfBoundsException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testSet1IndexOutOfBoundsException() {
+
+ CopyOnWriteArrayList<int> list;
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.set( -1, 42 ),
+ IndexOutOfBoundsException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testSet2IndexOutOfBoundsException() {
+
+ CopyOnWriteArrayList<int> list;
+ list.add( 1 );
+ list.add( 2 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.set( 100, 42 ),
+ IndexOutOfBoundsException );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testToArray() {
+
+ CopyOnWriteArrayList<int> list;
+ list.add( 1 );
+ list.add( 2 );
+ list.add( 3 );
+
+ std::vector<int> result = list.toArray();
+
+ CPPUNIT_ASSERT_EQUAL( 3, (int)result.size() );
+ CPPUNIT_ASSERT_EQUAL( 1, result[0] );
+ CPPUNIT_ASSERT_EQUAL( 2, result[1] );
+ CPPUNIT_ASSERT_EQUAL( 3, result[2] );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testLastIndexOf2() {
+ CopyOnWriteArrayList<int> list;
+ populate( list, 3 );
+ list.add( 1 );
+ list.add( 3 );
+
+ CPPUNIT_ASSERT_EQUAL( 3, list.lastIndexOf( 1, 4 ) );
+ CPPUNIT_ASSERT_EQUAL( -1, list.lastIndexOf( 3, 3 ) );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testIndexOf2() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, 3 );
+
+ CPPUNIT_ASSERT_EQUAL( 1, list.indexOf( 1, 0 ) );
+ CPPUNIT_ASSERT_EQUAL( -1, list.indexOf( 1, 2 ) );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testAddAllAbsent() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, 3 );
+
+ StlList<int> collection;
+ collection.add( 3 );
+ collection.add( 4 );
+ collection.add( 1 ); // will not add this element
+
+ list.addAllAbsent( collection );
+
+ CPPUNIT_ASSERT_EQUAL( 5, list.size() );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testRemoveAll() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, 3 );
+
+ StlList<int> collection;
+ collection.add( 1 );
+ collection.add( 2 );
+
+ list.removeAll( collection );
+
+ CPPUNIT_ASSERT_EQUAL( 1, list.size() );
+
+ CopyOnWriteArrayList<int> list2;
+ list2.removeAll( collection );
+ CPPUNIT_ASSERT_EQUAL( 0, list2.size() );
+
+ CopyOnWriteArrayList<int> list3;
+ populate( list3, 3 );
+ collection.clear();
+
+ list3.removeAll( collection );
+ CPPUNIT_ASSERT_EQUAL( 3, list3.size() );
+}
+
+//////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArrayListTest::testRetainAll() {
+
+ CopyOnWriteArrayList<int> list;
+ populate( list, 3 );
+
+ StlList<int> collection;
+ collection.add( 1 );
+ collection.add( 2 );
+
+ list.retainAll( collection );
+
+ CPPUNIT_ASSERT_EQUAL( 2, list.size() );
+
+ CopyOnWriteArrayList<int> list2;
+ list2.retainAll( collection );
+ CPPUNIT_ASSERT_EQUAL( 0, list2.size() );
+
+ CopyOnWriteArrayList<int> list3;
+ populate( list3, 3 );
+ collection.clear();
+
+ list3.retainAll( collection );
+ CPPUNIT_ASSERT_EQUAL( 0, list3.size() );
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArrayListTest.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArrayListTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArrayListTest.h?rev=1050221&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArrayListTest.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArrayListTest.h Thu Dec 16 23:18:02 2010
@@ -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.
+ */
+
+#ifndef _DECAF_UTIL_CONCURRENT_COPYONWRITEARRAYLISTTEST_H_
+#define _DECAF_UTIL_CONCURRENT_COPYONWRITEARRAYLISTTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf {
+namespace util {
+namespace concurrent {
+
+ class CopyOnWriteArrayListTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( CopyOnWriteArrayListTest );
+ CPPUNIT_TEST( testConstructor1 );
+ CPPUNIT_TEST( testConstructor2 );
+ CPPUNIT_TEST( testConstructor3 );
+ CPPUNIT_TEST( testAddAll );
+ CPPUNIT_TEST( testAddAll1 );
+ CPPUNIT_TEST( testAddAll2 );
+ CPPUNIT_TEST( testAddAll3 );
+ CPPUNIT_TEST( testAddAll4 );
+ CPPUNIT_TEST( testAddAll5 );
+ CPPUNIT_TEST( testAddAll6 );
+ CPPUNIT_TEST( testAddAll7 );
+ CPPUNIT_TEST( testAddAll8 );
+ CPPUNIT_TEST( testAddAll9 );
+ CPPUNIT_TEST( testClear );
+ CPPUNIT_TEST( testContains );
+ CPPUNIT_TEST( testContainsAll );
+ CPPUNIT_TEST( testGet );
+ CPPUNIT_TEST( testSet );
+ CPPUNIT_TEST( testSize );
+ CPPUNIT_TEST( testIsEmpty );
+ CPPUNIT_TEST( testToArray );
+ CPPUNIT_TEST( testIndexOf1 );
+ CPPUNIT_TEST( testIndexOf2 );
+ CPPUNIT_TEST( testLastIndexOf1 );
+ CPPUNIT_TEST( testLastIndexOf2 );
+ CPPUNIT_TEST( testAddIndex );
+ CPPUNIT_TEST( testAddAllIndex );
+ CPPUNIT_TEST( testEquals );
+ CPPUNIT_TEST( testRemove );
+ CPPUNIT_TEST( testRemoveAt );
+ CPPUNIT_TEST( testRemoveAll );
+ CPPUNIT_TEST( testRetainAll );
+ CPPUNIT_TEST( testAddIfAbsent1 );
+ CPPUNIT_TEST( testAddIfAbsent2 );
+ CPPUNIT_TEST( testAddAllAbsent );
+ CPPUNIT_TEST( testIterator );
+ CPPUNIT_TEST( testIteratorRemove );
+ CPPUNIT_TEST( testListIterator1 );
+ CPPUNIT_TEST( testListIterator2 );
+ CPPUNIT_TEST( testAddAll1IndexOutOfBoundsException );
+ CPPUNIT_TEST( testAddAll2IndexOutOfBoundsException );
+ CPPUNIT_TEST( testListIterator1IndexOutOfBoundsException );
+ CPPUNIT_TEST( testListIterator2IndexOutOfBoundsException );
+ CPPUNIT_TEST( testAdd1IndexOutOfBoundsException );
+ CPPUNIT_TEST( testAdd2IndexOutOfBoundsException );
+ CPPUNIT_TEST( testRemoveAt1IndexOutOfBounds );
+ CPPUNIT_TEST( testRemoveAt2IndexOutOfBounds );
+ CPPUNIT_TEST( testGet1IndexOutOfBoundsException );
+ CPPUNIT_TEST( testGet2IndexOutOfBoundsException );
+ CPPUNIT_TEST( testSet1IndexOutOfBoundsException );
+ CPPUNIT_TEST( testSet2IndexOutOfBoundsException );
+ CPPUNIT_TEST_SUITE_END();
+
+ private:
+
+ static const int SIZE;
+
+ public:
+
+ CopyOnWriteArrayListTest();
+ virtual ~CopyOnWriteArrayListTest();
+
+ void testConstructor1();
+ void testConstructor2();
+ void testConstructor3();
+ void testAddAll();
+ void testAddAll1();
+ void testAddAll2();
+ void testAddAll3();
+ void testAddAll4();
+ void testAddAll5();
+ void testAddAll6();
+ void testAddAll7();
+ void testAddAll8();
+ void testAddAll9();
+ void testClear();
+ void testContains();
+ void testContainsAll();
+ void testGet();
+ void testSet();
+ void testSize();
+ void testIsEmpty();
+ void testToArray();
+ void testIndexOf1();
+ void testIndexOf2();
+ void testLastIndexOf1();
+ void testLastIndexOf2();
+ void testAddIndex();
+ void testAddAllIndex();
+ void testEquals();
+ void testRemove();
+ void testRemoveAt();
+ void testRemoveAll();
+ void testRetainAll();
+ void testAddIfAbsent1();
+ void testAddIfAbsent2();
+ void testAddAllAbsent();
+ void testIterator();
+ void testIteratorRemove();
+ void testListIterator1();
+ void testListIterator2();
+ void testAddAll1IndexOutOfBoundsException();
+ void testAddAll2IndexOutOfBoundsException();
+ void testListIterator1IndexOutOfBoundsException();
+ void testListIterator2IndexOutOfBoundsException();
+ void testAdd1IndexOutOfBoundsException();
+ void testAdd2IndexOutOfBoundsException();
+ void testRemoveAt1IndexOutOfBounds();
+ void testRemoveAt2IndexOutOfBounds();
+ void testGet1IndexOutOfBoundsException();
+ void testGet2IndexOutOfBoundsException();
+ void testSet1IndexOutOfBoundsException();
+ void testSet2IndexOutOfBoundsException();
+
+ };
+
+}}}
+
+#endif /* _DECAF_UTIL_CONCURRENT_COPYONWRITEARRAYLISTTEST_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArrayListTest.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArraySetTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArraySetTest.cpp?rev=1050221&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArraySetTest.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArraySetTest.cpp Thu Dec 16 23:18:02 2010
@@ -0,0 +1,301 @@
+/*
+ * 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 "CopyOnWriteArraySetTest.h"
+
+#include <decaf/util/concurrent/CopyOnWriteArraySet.h>
+#include <decaf/util/StlList.h>
+
+using namespace decaf;
+using namespace decaf::util;
+using namespace decaf::util::concurrent;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace {
+
+ void populate( CopyOnWriteArraySet<int>& set, int n ) {
+
+ CPPUNIT_ASSERT( set.isEmpty() );
+
+ for( int i = 0; i < n; ++i ) {
+ set.add( i );
+ }
+
+ CPPUNIT_ASSERT( !set.isEmpty());
+ CPPUNIT_ASSERT_EQUAL( n, set.size() );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+const int CopyOnWriteArraySetTest::SIZE = 50;
+
+////////////////////////////////////////////////////////////////////////////////
+CopyOnWriteArraySetTest::CopyOnWriteArraySetTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CopyOnWriteArraySetTest::~CopyOnWriteArraySetTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testConstructor1() {
+
+ CopyOnWriteArraySet<int> set;
+ CPPUNIT_ASSERT( set.isEmpty() );
+ CPPUNIT_ASSERT( set.size() == 0 );
+
+ CopyOnWriteArraySet<std::string> strSet;
+ CPPUNIT_ASSERT( strSet.isEmpty() );
+ CPPUNIT_ASSERT( strSet.size() == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testConstructor2() {
+
+ StlList<int> intsList;
+
+ for( int i = 0; i < SIZE; ++i ) {
+ intsList.add( i );
+ }
+
+ CopyOnWriteArraySet<int> array( intsList );
+ CPPUNIT_ASSERT( !array.isEmpty() );
+ CPPUNIT_ASSERT( array.size() == SIZE );
+
+ for( int i = 0; i < SIZE; ++i ) {
+ CPPUNIT_ASSERT( array.contains( i ) );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testConstructor3() {
+
+ int ints[SIZE];
+
+ for( int i = 0; i < SIZE; ++i ) {
+ ints[i] = i;
+ }
+
+ CopyOnWriteArraySet<int> array( ints, SIZE );
+ CPPUNIT_ASSERT( !array.isEmpty() );
+ CPPUNIT_ASSERT( array.size() == SIZE );
+
+ for( int i = 0; i < SIZE; ++i ) {
+ CPPUNIT_ASSERT( array.contains( i ) );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testAddAll1() {
+
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ StlList<int> intsList;
+ intsList.add( 3 );
+ intsList.add( 4 );
+ intsList.add( 5 );
+
+ full.addAll( intsList );
+ CPPUNIT_ASSERT_EQUAL( 6, full.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testAddAll2() {
+
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ StlList<int> intsList;
+ intsList.add( 3 );
+ intsList.add( 4 );
+ intsList.add( 1 );
+
+ full.addAll( intsList );
+ CPPUNIT_ASSERT_EQUAL( 5, full.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testAdd1() {
+
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ full.add( 1 );
+ CPPUNIT_ASSERT_EQUAL( 3, full.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testAdd2() {
+
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ full.add( 3 );
+ CPPUNIT_ASSERT_EQUAL( 4, full.size() );
+ CPPUNIT_ASSERT( full.contains( 3 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testClear() {
+
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ full.clear();
+ CPPUNIT_ASSERT_EQUAL( 0, full.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testContains() {
+
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ CPPUNIT_ASSERT( full.contains( 1 ) );
+ CPPUNIT_ASSERT( !full.contains( 5 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testEquals() {
+
+ CopyOnWriteArraySet<int> a;
+ populate( a, 3 );
+ CopyOnWriteArraySet<int> b;
+ populate( b, 3 );
+
+ CPPUNIT_ASSERT( a.equals( b ) );
+ CPPUNIT_ASSERT( b.equals( a ) );
+ a.add( 42 );
+
+ CPPUNIT_ASSERT( !a.equals( b ) );
+ CPPUNIT_ASSERT( !b.equals( a ) );
+ b.add( 42 );
+
+ CPPUNIT_ASSERT( a.equals( b ) );
+ CPPUNIT_ASSERT( b.equals( a ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testContainsAll() {
+
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ StlList<int> intsList;
+ intsList.add( 1 );
+ intsList.add( 2 );
+
+ CPPUNIT_ASSERT( full.containsAll( intsList ) );
+
+ intsList.add( 6 );
+ CPPUNIT_ASSERT( !full.containsAll( intsList ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testIsEmpty() {
+
+ CopyOnWriteArraySet<int> empty;
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ CPPUNIT_ASSERT( empty.isEmpty() );
+ CPPUNIT_ASSERT( !full.isEmpty() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testIterator() {
+
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ std::auto_ptr< Iterator<int> > iter( full.iterator() );
+ int j;
+ for( j = 0; iter->hasNext(); j++ ) {
+ CPPUNIT_ASSERT_EQUAL( j, iter->next() );
+ }
+
+ CPPUNIT_ASSERT_EQUAL( 3, j );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testIteratorRemove() {
+
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ std::auto_ptr< Iterator<int> > iter( full.iterator() );
+ iter->next();
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a UnsupportedOperationException",
+ iter->remove(),
+ UnsupportedOperationException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testRemoveAll() {
+
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ StlList<int> intsList;
+ intsList.add( 1 );
+ intsList.add( 2 );
+
+ full.removeAll( intsList );
+ CPPUNIT_ASSERT_EQUAL( 1, full.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testRemove() {
+
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ full.remove( 1 );
+
+ CPPUNIT_ASSERT( !full.contains( 1 ) );
+ CPPUNIT_ASSERT_EQUAL( 2, full.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testSize() {
+
+ CopyOnWriteArraySet<int> empty;
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ CPPUNIT_ASSERT_EQUAL( 3, full.size() );
+ CPPUNIT_ASSERT_EQUAL( 0, empty.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CopyOnWriteArraySetTest::testToArray() {
+
+ CopyOnWriteArraySet<int> full;
+ populate( full, 3 );
+
+ std::vector<int> array = full.toArray();
+
+ CPPUNIT_ASSERT_EQUAL( 3, (int)array.size() );
+ CPPUNIT_ASSERT_EQUAL( 0, array[0] );
+ CPPUNIT_ASSERT_EQUAL( 1, array[1] );
+ CPPUNIT_ASSERT_EQUAL( 2, array[2] );
+}
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArraySetTest.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArraySetTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArraySetTest.h?rev=1050221&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArraySetTest.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArraySetTest.h Thu Dec 16 23:18:02 2010
@@ -0,0 +1,83 @@
+/*
+ * 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_CONCURRENT_COPYONWRITEARRAYSETTEST_H_
+#define _DECAF_UTIL_CONCURRENT_COPYONWRITEARRAYSETTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf {
+namespace util {
+namespace concurrent {
+
+ class CopyOnWriteArraySetTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( CopyOnWriteArraySetTest );
+ CPPUNIT_TEST( testConstructor1 );
+ CPPUNIT_TEST( testConstructor2 );
+ CPPUNIT_TEST( testConstructor3 );
+ CPPUNIT_TEST( testAddAll1 );
+ CPPUNIT_TEST( testAddAll2 );
+ CPPUNIT_TEST( testAdd1 );
+ CPPUNIT_TEST( testAdd2 );
+ CPPUNIT_TEST( testClear );
+ CPPUNIT_TEST( testContains );
+ CPPUNIT_TEST( testContainsAll );
+ CPPUNIT_TEST( testEquals );
+ CPPUNIT_TEST( testIsEmpty );
+ CPPUNIT_TEST( testIterator );
+ CPPUNIT_TEST( testIteratorRemove );
+ CPPUNIT_TEST( testRemoveAll );
+ CPPUNIT_TEST( testRemove );
+ CPPUNIT_TEST( testSize );
+ CPPUNIT_TEST( testToArray );
+ CPPUNIT_TEST_SUITE_END();
+
+ private:
+
+ static const int SIZE;
+
+ public:
+
+ CopyOnWriteArraySetTest();
+ virtual ~CopyOnWriteArraySetTest();
+
+ void testConstructor1();
+ void testConstructor2();
+ void testConstructor3();
+ void testAddAll1();
+ void testAddAll2();
+ void testAdd1();
+ void testAdd2();
+ void testClear();
+ void testContains();
+ void testContainsAll();
+ void testEquals();
+ void testIsEmpty();
+ void testIterator();
+ void testIteratorRemove();
+ void testRemoveAll();
+ void testRemove();
+ void testSize();
+ void testToArray();
+
+ };
+
+}}}
+
+#endif /* _DECAF_UTIL_CONCURRENT_COPYONWRITEARRAYSETTEST_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/CopyOnWriteArraySetTest.h
------------------------------------------------------------------------------
svn:eol-style = native