Author: nmittler Date: Tue Nov 28 17:22:21 2006 New Revision: 480317 URL: http://svn.apache.org/viewvc?view=rev&rev=480317 Log: [AMQCPP-16] Adding unit tests for primitive map
Added: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.cpp incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.h Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.h incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp?view=diff&rev=480317&r1=480316&r2=480317 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp (original) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.cpp Tue Nov 28 17:22:21 2006 @@ -17,7 +17,7 @@ #include "PrimitiveMap.h" -using namespace activemq::connector::openwire; +using namespace activemq::util; using namespace activemq::exceptions; using namespace std; @@ -187,7 +187,7 @@ } //////////////////////////////////////////////////////////////////////////////// -void PrimitiveMap::setString( const string& key, string& value ){ +void PrimitiveMap::setString( const string& key, const string& value ){ ValueNode node; node.setString( value ); Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.h URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.h?view=diff&rev=480317&r1=480316&r2=480317 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.h (original) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/PrimitiveMap.h Tue Nov 28 17:22:21 2006 @@ -15,15 +15,14 @@ * limitations under the License. */ -#ifndef ACTIVEMQ_CONNECTOR_OPENWIRE_PRIMITIVEMAP_H_ -#define ACTIVEMQ_CONNECTOR_OPENWIRE_PRIMITIVEMAP_H_ +#ifndef ACTIVEMQ_UTIL_PRIMITIVEMAP_H_ +#define ACTIVEMQ_UTIL_PRIMITIVEMAP_H_ #include <string> #include <activemq/util/Map.h> namespace activemq{ -namespace connector{ -namespace openwire{ +namespace util{ /** * Map of named primitives. @@ -243,7 +242,7 @@ return value.floatValue; } - void setString( std::string& lvalue ){ + void setString( const std::string& lvalue ){ clear(); valueType = STRING_TYPE; value.stringValue = new std::string( lvalue ); @@ -326,7 +325,7 @@ virtual std::string getString( const std::string& key ) const throw(activemq::exceptions::NoSuchElementException); - virtual void setString( const std::string& key, std::string& value ); + virtual void setString( const std::string& key, const std::string& value ); /** * Removes the value (key/value pair) for the specified key from @@ -346,6 +345,6 @@ virtual std::vector<ValueNode> getValues() const; }; -}}} +}} -#endif /*ACTIVEMQ_CONNECTOR_OPENWIRE_PRIMITIVEMAP_H_*/ +#endif /*ACTIVEMQ_UTIL_PRIMITIVEMAP_H_*/ Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am?view=diff&rev=480317&r1=480316&r2=480317 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Tue Nov 28 17:22:21 2006 @@ -69,6 +69,7 @@ activemq/util/IntegerTest.cpp \ activemq/util/LongTest.cpp \ activemq/util/MapTest.cpp \ + activemq/util/PrimitiveMapTest.cpp \ activemq/util/QueueTest.cpp \ activemq/util/StringTokenizerTest.cpp \ main.cpp Added: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.cpp URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.cpp?view=auto&rev=480317 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.cpp (added) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.cpp Tue Nov 28 17:22:21 2006 @@ -0,0 +1,233 @@ +/* + * 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 "PrimitiveMapTest.h" + +CPPUNIT_TEST_SUITE_REGISTRATION( activemq::util::PrimitiveMapTest ); + +using namespace activemq::util; + +void PrimitiveMapTest::testValueNode(){ + + PrimitiveMap::ValueNode node; + + node.setBool( true ); + CPPUNIT_ASSERT( node.getValueType() == PrimitiveMap::BOOLEAN_TYPE ); + CPPUNIT_ASSERT( node.getBool() == true ); + node.setBool( false ); + CPPUNIT_ASSERT( node.getValueType() == PrimitiveMap::BOOLEAN_TYPE ); + CPPUNIT_ASSERT( node.getBool() == false ); + + node.setByte( 5 ); + CPPUNIT_ASSERT( node.getValueType() == PrimitiveMap::BYTE_TYPE ); + CPPUNIT_ASSERT( node.getByte() == 5 ); + + node.setChar( 'a' ); + CPPUNIT_ASSERT( node.getValueType() == PrimitiveMap::CHAR_TYPE ); + CPPUNIT_ASSERT( node.getChar() == 'a' ); + + node.setShort( 10 ); + CPPUNIT_ASSERT( node.getValueType() == PrimitiveMap::SHORT_TYPE ); + CPPUNIT_ASSERT( node.getShort() == 10 ); + + node.setInt( 10000 ); + CPPUNIT_ASSERT( node.getValueType() == PrimitiveMap::INTEGER_TYPE ); + CPPUNIT_ASSERT( node.getInt() == 10000 ); + + node.setLong( 100000L ); + CPPUNIT_ASSERT( node.getValueType() == PrimitiveMap::LONG_TYPE ); + CPPUNIT_ASSERT( node.getLong() == 100000L ); + + node.setDouble( 2.3 ); + CPPUNIT_ASSERT( node.getValueType() == PrimitiveMap::DOUBLE_TYPE ); + CPPUNIT_ASSERT( node.getDouble() == 2.3 ); + + node.setFloat( 3.2f ); + CPPUNIT_ASSERT( node.getValueType() == PrimitiveMap::FLOAT_TYPE ); + CPPUNIT_ASSERT( node.getFloat() == 3.2f ); + + node.setString( "hello" ); + CPPUNIT_ASSERT( node.getValueType() == PrimitiveMap::STRING_TYPE ); + CPPUNIT_ASSERT( node.getString() == "hello" ); + + try{ + node.getFloat(); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){ + } + + node.clear(); + CPPUNIT_ASSERT( node.getValueType() == PrimitiveMap::NULL_TYPE ); +} + +void PrimitiveMapTest::testSetGet(){ + + PrimitiveMap pmap; + + try{ + pmap.getBool( "bool" ); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){} + pmap.setBool( "bool", true ); + CPPUNIT_ASSERT( pmap.getBool("bool") == true ); + pmap.setBool( "bool", false ); + CPPUNIT_ASSERT( pmap.getBool("bool") == false ); + + try{ + pmap.getByte( "byte" ); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){} + pmap.setByte( "byte", 1 ); + CPPUNIT_ASSERT( pmap.getByte("byte") == 1 ); + + try{ + pmap.getChar( "char" ); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){} + pmap.setChar( "char", 'a' ); + CPPUNIT_ASSERT( pmap.getChar("char") == 'a' ); + + try{ + pmap.getShort( "short" ); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){} + pmap.setShort( "short", 2 ); + CPPUNIT_ASSERT( pmap.getShort("short") == 2 ); + + try{ + pmap.getInt( "int" ); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){} + pmap.setInt( "int", 3 ); + CPPUNIT_ASSERT( pmap.getInt("int") == 3 ); + + try{ + pmap.getLong( "long" ); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){} + pmap.setLong( "long", 4L ); + CPPUNIT_ASSERT( pmap.getLong("long") == 4L ); + + try{ + pmap.getDouble( "double" ); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){} + pmap.setDouble( "double", 2.3 ); + CPPUNIT_ASSERT( pmap.getDouble("double") == 2.3 ); + + try{ + pmap.getFloat( "float" ); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){} + pmap.setFloat( "float", 3.2f ); + CPPUNIT_ASSERT( pmap.getFloat("float") == 3.2f ); + + try{ + pmap.getString( "string" ); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){} + pmap.setString( "string", "hello" ); + CPPUNIT_ASSERT( pmap.getString("string") == "hello" ); +} + +void PrimitiveMapTest::testRemove(){ + + PrimitiveMap pmap; + pmap.setInt("int", 5 ); + pmap.setFloat( "float", 5.5f ); + pmap.setInt("int2", 6 ); + pmap.remove("int"); + try{ + pmap.getInt("int"); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){} +} + +void PrimitiveMapTest::testCount(){ + + PrimitiveMap pmap; + CPPUNIT_ASSERT( pmap.count() == 0 ); + pmap.setInt("int", 5 ); + CPPUNIT_ASSERT( pmap.count() == 1); + pmap.setFloat( "float", 5.5f ); + CPPUNIT_ASSERT( pmap.count() == 2 ); + pmap.setInt("int2", 6 ); + CPPUNIT_ASSERT( pmap.count() == 3 ); + pmap.remove("int"); + CPPUNIT_ASSERT( pmap.count() == 2 ); +} + +void PrimitiveMapTest::testClear(){ + + PrimitiveMap pmap; + pmap.setInt("int", 5 ); + pmap.setFloat( "float", 5.5f ); + pmap.setInt("int2", 6 ); + + pmap.clear(); + CPPUNIT_ASSERT( pmap.count() == 0 ); + + try{ + pmap.getInt("int"); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){} + + try{ + pmap.getFloat("float"); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){} + + try{ + pmap.getInt("int2"); + CPPUNIT_ASSERT( false ); + } catch( activemq::exceptions::NoSuchElementException& e ){} +} + +void PrimitiveMapTest::testContains(){ + + PrimitiveMap pmap; + + CPPUNIT_ASSERT( pmap.contains("int") == false ); + + pmap.setInt("int", 5 ); + CPPUNIT_ASSERT( pmap.contains("int") == true ); + + pmap.setFloat( "float", 5.5f ); + CPPUNIT_ASSERT( pmap.contains("float") == true ); + + pmap.setInt("int2", 6 ); + CPPUNIT_ASSERT( pmap.contains("int2") == true ); + + pmap.remove("int"); + CPPUNIT_ASSERT( pmap.contains("int") == false ); +} + +void PrimitiveMapTest::testGetKeys(){ + + PrimitiveMap pmap; + + pmap.setInt("int", 5 ); + pmap.setFloat( "float", 5.5f ); + pmap.setInt("int2", 6 ); + std::vector<std::string> keys = pmap.getKeys(); + + CPPUNIT_ASSERT( keys.size() == 3 ); + CPPUNIT_ASSERT( keys[0] == "int" || keys[0] == "float" || keys[0] == "int2" ); + CPPUNIT_ASSERT( keys[1] == "int" || keys[1] == "float" || keys[1] == "int2" ); + CPPUNIT_ASSERT( keys[2] == "int" || keys[2] == "float" || keys[2] == "int2" ); +} + Added: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.h URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.h?view=auto&rev=480317 ============================================================================== --- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.h (added) +++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/PrimitiveMapTest.h Tue Nov 28 17:22:21 2006 @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ACTIVEMQ_UTIL_PRIMITIVEMAPTEST_H_ +#define ACTIVEMQ_UTIL_PRIMITIVEMAPTEST_H_ + +#include <activemq/util/PrimitiveMap.h> + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +namespace activemq{ +namespace util{ + + class PrimitiveMapTest : public CppUnit::TestFixture + { + CPPUNIT_TEST_SUITE( PrimitiveMapTest ); + CPPUNIT_TEST( testValueNode ); + CPPUNIT_TEST( testSetGet ); + CPPUNIT_TEST( testRemove ); + CPPUNIT_TEST( testCount ); + CPPUNIT_TEST( testClear ); + CPPUNIT_TEST( testContains ); + CPPUNIT_TEST( testGetKeys ); + CPPUNIT_TEST_SUITE_END(); + + public: + + PrimitiveMapTest(){}; + virtual ~PrimitiveMapTest(){}; + + void testValueNode(); + void testSetGet(); + void testRemove(); + void testCount(); + void testClear(); + void testContains(); + void testGetKeys(); + }; + +}} + +#endif /*ACTIVEMQ_UTIL_PRIMITIVEMAPTEST_H_*/