Author: tabish
Date: Fri May 30 07:58:20 2008
New Revision: 661749
URL: http://svn.apache.org/viewvc?rev=661749&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-172
Added:
activemq/activemq-cpp/trunk/src/test/decaf/util/ListTest.cpp
activemq/activemq-cpp/trunk/src/test/decaf/util/ListTest.h
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/ListTest.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/ListTest.cpp?rev=661749&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/ListTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/ListTest.cpp Fri May 30
07:58:20 2008
@@ -0,0 +1,303 @@
+/*
+ * 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 "ListTest.h"
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+ListTest::ListTest(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testContains(){
+
+ List<string> list;
+ CPPUNIT_ASSERT( list.contains( "bob" ) == false);
+
+ list.add( "bob" );
+
+ CPPUNIT_ASSERT(list.contains( "bob" ) == true );
+ CPPUNIT_ASSERT(list.contains( "fred" ) == false );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testIndexOf(){
+
+ List<string> list;
+
+ list.add( "bob" ); // 0
+ list.add( "fred" ); // 1
+ list.add( "george" ); // 2
+ list.add( "steve" ); // 3
+
+ CPPUNIT_ASSERT( list.indexOf( "bob" ) == 0 );
+ CPPUNIT_ASSERT( list.indexOf( "fred" ) == 1 );
+ CPPUNIT_ASSERT( list.indexOf( "george" ) == 2 );
+ CPPUNIT_ASSERT( list.indexOf( "steve" ) == 3 );
+
+ 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( "george" ) == 1 );
+ CPPUNIT_ASSERT( list.indexOf( "steve" ) == 2 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testLastIndexOf(){
+
+ List<string> list;
+
+ list.add( "bob" ); // 0
+ list.add( "fred" ); // 1
+ list.add( "george" ); // 2
+ list.add( "bob" ); // 3
+
+ CPPUNIT_ASSERT( list.indexOf( "bob" ) == 0 );
+ CPPUNIT_ASSERT( list.lastIndexOf( "bob" ) == 3 );
+
+ list.remove( "fred" );
+
+ CPPUNIT_ASSERT( list.indexOf( "bob" ) == 0 );
+ CPPUNIT_ASSERT( 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 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testClear(){
+
+ List<string> list;
+ list.add( "bob" );
+ list.add( "fred" );
+
+ CPPUNIT_ASSERT( list.size() == 2 );
+ list.clear();
+ CPPUNIT_ASSERT( list.size() == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testIsEmpty(){
+
+ List<string> list;
+ list.add( "bob" );
+ list.add( "fred" );
+
+ CPPUNIT_ASSERT(list.isEmpty() == false );
+ list.clear();
+ CPPUNIT_ASSERT(list.isEmpty() == true );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testSize(){
+
+ List<string> list;
+
+ CPPUNIT_ASSERT( list.size() == 0 );
+ list.add( "bob" );
+ CPPUNIT_ASSERT( list.size() == 1 );
+ list.add( "fred" );
+ CPPUNIT_ASSERT( list.size() == 2 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testGet(){
+ List<string> list;
+
+ list.add( "fred" );
+ list.add( "fred" );
+ list.add( "fred" );
+ list.add( "bob" );
+
+ CPPUNIT_ASSERT( list.get(0) == "fred" );
+ CPPUNIT_ASSERT( list.get(1) == "fred" );
+ CPPUNIT_ASSERT( list.get(2) == "fred" );
+ CPPUNIT_ASSERT( list.get(3) == "bob" );
+ list.remove( "fred" );
+ CPPUNIT_ASSERT( list.get(0) == "bob" );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testSet(){
+ List<string> list;
+
+ list.add( "fred" );
+ list.add( "fred" );
+ list.add( "fred" );
+ list.add( "bob" );
+
+ CPPUNIT_ASSERT( list.get(0) == "fred" );
+ CPPUNIT_ASSERT( list.get(1) == "fred" );
+ CPPUNIT_ASSERT( list.get(2) == "fred" );
+ CPPUNIT_ASSERT( list.get(3) == "bob" );
+
+ list.set( 0, "steve" );
+ list.set( 1, "joe" );
+
+ CPPUNIT_ASSERT( list.get(0) == "steve" );
+ CPPUNIT_ASSERT( list.get(1) == "joe" );
+ CPPUNIT_ASSERT( list.get(2) == "fred" );
+ CPPUNIT_ASSERT( list.get(3) == "bob" );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testAdd(){
+ List<string> list;
+
+ list.add( "fred" );
+ list.add( "fred" );
+ list.add( "fred" );
+ CPPUNIT_ASSERT( list.contains("fred") == true );
+ CPPUNIT_ASSERT( list.size() == 3 );
+ list.remove( "fred" );
+ CPPUNIT_ASSERT( list.contains("fred") == false );
+ CPPUNIT_ASSERT( list.isEmpty() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testAdd2(){
+ List<string> list;
+
+ list.add( "fred" );
+ list.add( "fred" );
+ list.add( "fred" );
+
+ CPPUNIT_ASSERT( list.get(0) == "fred" );
+ CPPUNIT_ASSERT( list.get(1) == "fred" );
+ CPPUNIT_ASSERT( list.get(2) == "fred" );
+
+ list.add( 1, "bob" );
+
+ CPPUNIT_ASSERT( list.get(0) == "fred" );
+ CPPUNIT_ASSERT( list.get(1) == "bob" );
+ CPPUNIT_ASSERT( list.get(2) == "fred" );
+ CPPUNIT_ASSERT( list.get(3) == "fred" );
+
+ list.add( 3, "bob" );
+
+ CPPUNIT_ASSERT( list.get(3) == "bob" );
+ CPPUNIT_ASSERT( list.get(4) == "fred" );
+
+ list.add( 5, "bob" );
+
+ CPPUNIT_ASSERT( list.get(4) == "fred" );
+ CPPUNIT_ASSERT( list.get(5) == "bob" );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.add( list.size() + 1, "bob" ),
+ decaf::lang::exceptions::IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testRemove(){
+ List<string> list;
+
+ list.add( "fred" );
+ CPPUNIT_ASSERT( list.contains( "fred" ) == true );
+ list.remove( "fred" );
+ CPPUNIT_ASSERT( list.contains( "fred" ) == false );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testRemove2(){
+ List<string> list;
+
+ list.add( "fred" );
+ list.add( "bob" );
+ list.add( "steve" );
+ list.add( "mike" );
+ list.add( "larry" );
+
+ CPPUNIT_ASSERT( list.remove(0) == "fred" );
+ CPPUNIT_ASSERT( list.get(0) == "bob" );
+
+ CPPUNIT_ASSERT( list.remove(2) == "mike" );
+ CPPUNIT_ASSERT( list.get(2) == "larry" );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw an IndexOutOfBoundsException",
+ list.remove( list.size() + 1 ),
+ decaf::lang::exceptions::IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testToArray(){
+
+ List<string> list;
+
+ list.add( "fred1" );
+ list.add( "fred2" );
+ list.add( "fred3" );
+ CPPUNIT_ASSERT( list.size() == 3 );
+
+ std::vector<std::string> array = list.toArray();
+
+ CPPUNIT_ASSERT( array.size() == 3 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ListTest::testIterator(){
+
+ List<string> list;
+
+ list.add( "fred1" );
+ list.add( "fred2" );
+ list.add( "fred3" );
+
+ Iterator<string>* iterator1 = list.iterator();
+ CPPUNIT_ASSERT( iterator1 != NULL );
+ CPPUNIT_ASSERT( iterator1->hasNext() == true );
+
+ size_t count = 0;
+ while( iterator1->hasNext() ) {
+ iterator1->next();
+ ++count;
+ }
+
+ CPPUNIT_ASSERT( count == list.size() );
+
+ Iterator<string>* iterator2 = list.iterator();
+
+ while( iterator2->hasNext() ) {
+ iterator2->next();
+ iterator2->remove();
+ }
+
+ CPPUNIT_ASSERT( list.isEmpty() );
+
+ delete iterator1;
+ delete iterator2;
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/util/ListTest.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/util/ListTest.h?rev=661749&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/util/ListTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/util/ListTest.h Fri May 30
07:58:20 2008
@@ -0,0 +1,73 @@
+/*
+ * 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_LISTTEST_H_
+#define _DECAF_UTIL_LISTTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/util/List.h>
+#include <decaf/util/Iterator.h>
+
+namespace decaf{
+namespace util{
+
+ class ListTest : public CppUnit::TestFixture
+ {
+ CPPUNIT_TEST_SUITE( ListTest );
+ CPPUNIT_TEST( testContains );
+ CPPUNIT_TEST( testIndexOf );
+ CPPUNIT_TEST( testLastIndexOf );
+ CPPUNIT_TEST( testClear );
+ CPPUNIT_TEST( testSize );
+ CPPUNIT_TEST( testGet );
+ CPPUNIT_TEST( testSet );
+ CPPUNIT_TEST( testAdd );
+ CPPUNIT_TEST( testAdd2 );
+ CPPUNIT_TEST( testRemove );
+ CPPUNIT_TEST( testRemove2 );
+ CPPUNIT_TEST( testIsEmpty );
+ CPPUNIT_TEST( testToArray );
+ CPPUNIT_TEST( testIterator );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ ListTest();
+ virtual ~ListTest() {}
+
+ void testContains();
+ void testIndexOf();
+ void testLastIndexOf();
+ void testClear();
+ void testSize();
+ void testGet();
+ void testSet();
+ void testAdd();
+ void testAdd2();
+ void testRemove();
+ void testRemove2();
+ void testIsEmpty();
+ void testToArray();
+ void testIterator();
+
+ };
+
+}}
+
+#endif /*_DECAF_UTIL_LISTTEST_H_*/