activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r882361 [3/4] - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/activemq/commands/ main/activemq/wireformat/openwire/utils/ main/cms/ test/activemq/commands/ test/activemq/wireformat/openwire/utils/
Date Thu, 19 Nov 2009 23:37:27 GMT
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/MapMessage.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/MapMessage.h?rev=882361&r1=882360&r2=882361&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/MapMessage.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/MapMessage.h Thu Nov 19 23:37:26 2009
@@ -21,6 +21,10 @@
 #include <cms/Config.h>
 #include <cms/Message.h>
 
+#include <cms/CMSException.h>
+#include <cms/MessageFormatException.h>
+#include <cms/MessageNotWriteableException.h>
+
 namespace cms{
 
     /**
@@ -101,7 +105,7 @@
          * @throws MessageFormatExceptio - if this type conversion is invalid.
          */
         virtual bool getBoolean( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( cms::MessageFormatException, cms::CMSException ) = 0;
 
         /**
          * Sets a boolean value with the specified name into the Map.
@@ -115,7 +119,7 @@
          * @throws MessageNotWritableException - if the Message is in Read-only Mode.
          */
         virtual void setBoolean( const std::string& name, bool value )
-            throw( CMSException ) = 0;
+            throw( cms::MessageNotWriteableException, cms::CMSException ) = 0;
 
         /**
          * Returns the Byte value of the Specified name
@@ -124,10 +128,10 @@
          *      Name of the value to fetch from the map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageFormatExceptio - if this type conversion is invalid.
+         * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual unsigned char getByte( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( cms::MessageFormatException, cms::CMSException ) = 0;
 
         /**
          * Sets a Byte value with the specified name into the Map.
@@ -138,10 +142,10 @@
          *      the Byte value to set in the Map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageNotWritableException - if the Message is in Read-only Mode.
+         * @throws MessageNotWriteableException - if the Message is in Read-only Mode.
          */
         virtual void setByte( const std::string& name, unsigned char value )
-            throw( CMSException ) = 0;
+            throw( cms::MessageNotWriteableException, cms::CMSException ) = 0;
 
         /**
          * Returns the Bytes value of the Specified name
@@ -150,10 +154,10 @@
          *      Name of the value to fetch from the map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageFormatExceptio - if this type conversion is invalid.
+         * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual std::vector<unsigned char> getBytes( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( cms::MessageFormatException, cms::CMSException ) = 0;
 
         /**
          * Sets a Bytes value with the specified name into the Map.
@@ -164,11 +168,11 @@
          *      The Bytes value to set in the Map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageNotWritableException - if the Message is in Read-only Mode.
+         * @throws MessageNotWriteableException - if the Message is in Read-only Mode.
          */
         virtual void setBytes( const std::string& name,
                                const std::vector<unsigned char>& value )
-                                    throw( CMSException ) = 0;
+                                    throw( cms::MessageNotWriteableException, cms::CMSException ) = 0;
 
         /**
          * Returns the Char value of the Specified name
@@ -177,10 +181,10 @@
          *      name of the value to fetch from the map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageFormatExceptio - if this type conversion is invalid.
+         * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual char getChar( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( cms::MessageFormatException, cms::CMSException ) = 0;
 
         /**
          * Sets a Char value with the specified name into the Map.
@@ -191,10 +195,10 @@
          *      the Char value to set in the Map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageNotWritableException - if the Message is in Read-only Mode.
+         * @throws MessageNotWriteableException - if the Message is in Read-only Mode.
          */
         virtual void setChar( const std::string& name, char value )
-            throw( CMSException ) = 0;
+            throw( cms::MessageNotWriteableException, cms::CMSException ) = 0;
 
         /**
          * Returns the Double value of the Specified name
@@ -203,10 +207,10 @@
          *      Name of the value to fetch from the map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageFormatExceptio - if this type conversion is invalid.
+         * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual double getDouble( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( cms::MessageFormatException, cms::CMSException ) = 0;
 
         /**
          * Sets a Double value with the specified name into the Map.
@@ -217,10 +221,10 @@
          *      The Double value to set in the Map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageNotWritableException - if the Message is in Read-only Mode.
+         * @throws MessageNotWriteableException - if the Message is in Read-only Mode.
          */
-        virtual void setDouble( const std::string& name,
-                                double value ) throw( CMSException ) = 0;
+        virtual void setDouble( const std::string& name, double value )
+            throw( cms::MessageNotWriteableException, cms::CMSException ) = 0;
 
         /**
          * Returns the Float value of the Specified name
@@ -229,10 +233,10 @@
          *      Name of the value to fetch from the map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageFormatExceptio - if this type conversion is invalid.
+         * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual float getFloat( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( cms::MessageFormatException, cms::CMSException ) = 0;
 
         /**
          * Sets a Float value with the specified name into the Map.
@@ -243,10 +247,10 @@
          *      The Float value to set in the Map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageNotWritableException - if the Message is in Read-only Mode.
+         * @throws MessageNotWriteableException - if the Message is in Read-only Mode.
          */
         virtual void setFloat( const std::string& name, float value )
-            throw( CMSException ) = 0;
+            throw( cms::MessageNotWriteableException, cms::CMSException ) = 0;
 
         /**
          * Returns the Int value of the Specified name
@@ -255,10 +259,10 @@
          *      Name of the value to fetch from the map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageFormatExceptio - if this type conversion is invalid.
+         * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual int getInt( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( cms::MessageFormatException, cms::CMSException ) = 0;
 
         /**
          * Sets a Int value with the specified name into the Map.
@@ -269,10 +273,10 @@
          *      The Int value to set in the Map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageNotWritableException - if the Message is in Read-only Mode.
+         * @throws MessageNotWriteableException - if the Message is in Read-only Mode.
          */
         virtual void setInt( const std::string& name, int value )
-            throw( CMSException ) = 0;
+            throw( cms::MessageNotWriteableException, cms::CMSException ) = 0;
 
         /**
          * Returns the Long value of the Specified name
@@ -281,10 +285,10 @@
          *      Name of the value to fetch from the map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageFormatExceptio - if this type conversion is invalid.
+         * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual long long getLong( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( cms::MessageFormatException, cms::CMSException ) = 0;
 
         /**
          * Sets a Long value with the specified name into the Map.
@@ -295,10 +299,10 @@
          *      The Long value to set in the Map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageNotWritableException - if the Message is in Read-only Mode.
+         * @throws MessageNotWriteableException - if the Message is in Read-only Mode.
          */
         virtual void setLong( const std::string& name, long long value )
-            throw( CMSException ) = 0;
+            throw( cms::MessageNotWriteableException, cms::CMSException ) = 0;
 
         /**
          * Returns the Short value of the Specified name
@@ -307,10 +311,10 @@
          *      Name of the value to fetch from the map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageFormatExceptio - if this type conversion is invalid.
+         * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual short getShort( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( cms::MessageFormatException, cms::CMSException ) = 0;
 
         /**
          * Sets a Short value with the specified name into the Map.
@@ -321,10 +325,10 @@
          *      The Short value to set in the Map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageNotWritableException - if the Message is in Read-only Mode.
+         * @throws MessageNotWriteableException - if the Message is in Read-only Mode.
          */
         virtual void setShort( const std::string& name, short value )
-            throw( CMSException ) = 0;
+            throw( cms::MessageNotWriteableException, cms::CMSException ) = 0;
 
         /**
          * Returns the String value of the Specified name
@@ -333,10 +337,10 @@
          *      Name of the value to fetch from the map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageFormatExceptio - if this type conversion is invalid.
+         * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual std::string getString( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( cms::MessageFormatException, cms::CMSException ) = 0;
 
         /**
          * Sets a String value with the specified name into the Map.
@@ -347,10 +351,10 @@
          *      The String value to set in the Map
          *
          * @throws CMSException - if the operation fails due to an internal error.
-         * @throws MessageNotWritableException - if the Message is in Read-only Mode.
+         * @throws MessageNotWriteableException - if the Message is in Read-only Mode.
          */
         virtual void setString( const std::string& name, const std::string& value )
-            throw( CMSException ) = 0;
+            throw( cms::MessageNotWriteableException, cms::CMSException ) = 0;
 
     };
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/Message.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/Message.h?rev=882361&r1=882360&r2=882361&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/Message.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/Message.h Thu Nov 19 23:37:26 2009
@@ -20,9 +20,13 @@
 
 #include <cms/Config.h>
 #include <cms/Destination.h>
-#include <cms/CMSException.h>
 #include <cms/DeliveryMode.h>
 
+#include <cms/CMSException.h>
+#include <cms/IllegalStateException.h>
+#include <cms/MessageFormatException.h>
+#include <cms/MessageNotWriteableException.h>
+
 namespace cms{
 
     /**
@@ -119,7 +123,7 @@
          * @throws CMSException - if an internal error occurs.
          * @throws IllegalStateException - if this method is called on a closed session.
          */
-        virtual void acknowledge() const throw( CMSException ) = 0;
+        virtual void acknowledge() const throw( IllegalStateException, CMSException ) = 0;
 
         /**
          * Clears out the body of the message.  This does not clear the
@@ -173,7 +177,7 @@
          * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual bool getBooleanProperty( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( MessageFormatException, CMSException ) = 0;
 
         /**
          * Gets a byte property.
@@ -186,7 +190,7 @@
          * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual unsigned char getByteProperty( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( MessageFormatException, CMSException ) = 0;
 
         /**
          * Gets a double property.
@@ -199,7 +203,7 @@
          * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual double getDoubleProperty( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( MessageFormatException, CMSException ) = 0;
 
         /**
          * Gets a float property.
@@ -212,7 +216,7 @@
          * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual float getFloatProperty( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( MessageFormatException, CMSException ) = 0;
 
         /**
          * Gets a int property.
@@ -225,7 +229,7 @@
          * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual int getIntProperty( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( MessageFormatException, CMSException ) = 0;
 
         /**
          * Gets a long property.
@@ -238,7 +242,7 @@
          * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual long long getLongProperty( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( MessageFormatException, CMSException ) = 0;
 
         /**
          * Gets a short property.
@@ -251,7 +255,7 @@
          * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual short getShortProperty( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( MessageFormatException, CMSException ) = 0;
 
         /**
          * Gets a string property.
@@ -264,7 +268,7 @@
          * @throws MessageFormatException - if this type conversion is invalid.
          */
         virtual std::string getStringProperty( const std::string& name ) const
-            throw( CMSException ) = 0;
+            throw( MessageFormatException, CMSException ) = 0;
 
         /**
          * Sets a boolean property.
@@ -278,7 +282,7 @@
          * @throws MessageNotWriteableException - if properties are read-only
          */
         virtual void setBooleanProperty( const std::string& name, bool value )
-            throw( CMSException ) = 0;
+            throw( MessageNotWriteableException, CMSException ) = 0;
 
         /**
          * Sets a byte property.
@@ -292,7 +296,7 @@
          * @throws MessageNotWriteableException - if properties are read-only
          */
         virtual void setByteProperty( const std::string& name, unsigned char value )
-            throw( CMSException ) = 0;
+            throw( MessageNotWriteableException, CMSException ) = 0;
 
         /**
          * Sets a double property.
@@ -306,7 +310,7 @@
          * @throws MessageNotWriteableException - if properties are read-only
          */
         virtual void setDoubleProperty( const std::string& name, double value )
-            throw( CMSException ) = 0;
+            throw( MessageNotWriteableException, CMSException ) = 0;
 
         /**
          * Sets a float property.
@@ -319,7 +323,7 @@
          * @throws MessageNotWriteableException - if properties are read-only
          */
         virtual void setFloatProperty( const std::string& name, float value )
-            throw( CMSException ) = 0;
+            throw( MessageNotWriteableException, CMSException ) = 0;
 
         /**
          * Sets a int property.
@@ -333,7 +337,7 @@
          * @throws MessageNotWriteableException - if properties are read-only
          */
         virtual void setIntProperty( const std::string& name, int value )
-            throw( CMSException ) = 0;
+            throw( MessageNotWriteableException, CMSException ) = 0;
 
         /**
          * Sets a long property.
@@ -347,7 +351,7 @@
          * @throws MessageNotWriteableException - if properties are read-only
          */
         virtual void setLongProperty( const std::string& name, long long value )
-            throw( CMSException ) = 0;
+            throw( MessageNotWriteableException, CMSException ) = 0;
 
         /**
          * Sets a short property.
@@ -361,7 +365,7 @@
          * @throws MessageNotWriteableException - if properties are read-only
          */
         virtual void setShortProperty( const std::string& name, short value )
-            throw( CMSException ) = 0;
+            throw( MessageNotWriteableException, CMSException ) = 0;
 
         /**
          * Sets a string property.
@@ -375,7 +379,7 @@
          * @throws MessageNotWriteableException - if properties are read-only
          */
         virtual void setStringProperty( const std::string& name, const std::string& value )
-            throw( CMSException ) = 0;
+            throw( MessageNotWriteableException, CMSException ) = 0;
 
         /**
          * Gets the correlation ID for the message.

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/TextMessage.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/TextMessage.h?rev=882361&r1=882360&r2=882361&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/TextMessage.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/TextMessage.h Thu Nov 19 23:37:26 2009
@@ -21,6 +21,7 @@
 #include <cms/Config.h>
 #include <cms/Message.h>
 #include <cms/CMSException.h>
+#include <cms/MessageNotWriteableException.h>
 
 namespace cms{
 
@@ -49,7 +50,7 @@
          *
          * @throws CMSException - if an internal error occurs.
          */
-        virtual std::string getText() const throw( CMSException ) = 0;
+        virtual std::string getText() const throw( cms::CMSException ) = 0;
 
         /**
          * Sets the message contents, does not take ownership of the passed
@@ -61,7 +62,8 @@
          * @throws CMSException - if an internal error occurs.
          * @throws MessageNotWriteableException - if the message is in read-only mode..
          */
-        virtual void setText( const char* msg ) throw( CMSException ) = 0;
+        virtual void setText( const char* msg ) throw( cms::MessageNotWriteableException,
+                                                       cms::CMSException ) = 0;
 
         /**
          * Sets the message contents
@@ -72,7 +74,8 @@
          * @throws CMSException - if an internal error occurs.
          * @throws MessageNotWriteableException - if the message is in read-only mode..
          */
-        virtual void setText( const std::string& msg ) throw( CMSException ) = 0;
+        virtual void setText( const std::string& msg ) throw( cms::MessageNotWriteableException,
+                                                              cms::CMSException ) = 0;
 
     };
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQBytesMessageTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQBytesMessageTest.cpp?rev=882361&r1=882360&r2=882361&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQBytesMessageTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQBytesMessageTest.cpp Thu Nov 19 23:37:26 2009
@@ -18,57 +18,438 @@
 #include "ActiveMQBytesMessageTest.h"
 
 #include <decaf/util/UUID.h>
+#include <decaf/lang/Exception.h>
 #include <activemq/commands/ActiveMQBytesMessage.h>
 
 using namespace std;
+using namespace cms;
 using namespace activemq;
 using namespace activemq::util;
 using namespace activemq::commands;
+using namespace decaf;
+using namespace decaf::lang;
 
 ////////////////////////////////////////////////////////////////////////////////
-void ActiveMQBytesMessageTest::test()
-{
-    ActiveMQBytesMessage myMessage;
-
-    CPPUNIT_ASSERT( myMessage.getDataStructureType() == ActiveMQBytesMessage::ID_ACTIVEMQBYTESMESSAGE );
-
-    // Write some data
-    myMessage.writeBoolean( false );
-    myMessage.writeByte( 127 );
-    myMessage.writeShort( 32767 );
-    myMessage.writeUnsignedShort( 65535 );
-    myMessage.writeDouble( 0.5622154 );
-    myMessage.writeUTF( "This is a UTF String" );
-
-    try{
-        myMessage.readInt();
-        CPPUNIT_ASSERT( false );
-    } catch(...) {}
-
-    myMessage.writeDouble( 1.012 );
-    myMessage.writeFloat( 10.000005f );
-    myMessage.writeInt( 15645646 );
-    myMessage.writeLong( 0xFFFAAA999LL );
-    myMessage.writeString( "This is a test String" );
-
-    CPPUNIT_ASSERT( myMessage.getBodyLength() != 0 );
-
-    // Get ready to read
-    myMessage.reset();
-
-    CPPUNIT_ASSERT( myMessage.readBoolean() == false );
-    CPPUNIT_ASSERT( myMessage.readByte() == 127 );
-    CPPUNIT_ASSERT( myMessage.readShort() == 32767 );
-    CPPUNIT_ASSERT( myMessage.readUnsignedShort() == 65535 );
-    CPPUNIT_ASSERT( myMessage.readDouble() == 0.5622154 );
-    CPPUNIT_ASSERT( myMessage.readUTF() == "This is a UTF String" );
-    CPPUNIT_ASSERT( myMessage.readDouble() == 1.012 );
-    CPPUNIT_ASSERT( myMessage.readFloat() == 10.000005f );
-    CPPUNIT_ASSERT( myMessage.readInt() == 15645646 );
-    CPPUNIT_ASSERT( myMessage.readLong() == 0xFFFAAA999ULL );
-    CPPUNIT_ASSERT( myMessage.readString() == "This is a test String" );
+void ActiveMQBytesMessageTest::testGetBodyLength() {
+    ActiveMQBytesMessage msg;
+    std::size_t len = 10;
 
-    myMessage.clearBody();
+    try {
 
-    CPPUNIT_ASSERT( myMessage.getBodyLength() == 0 );
+        for( std::size_t i = 0; i < len; i++ ) {
+            msg.writeLong( 5LL );
+        }
+
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+    }
+
+    try {
+
+        msg.reset();
+        CPPUNIT_ASSERT( msg.getBodyLength() == ( len * 8 ) );
+
+    } catch( Exception& e ) {
+        e.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testReadBoolean() {
+
+    ActiveMQBytesMessage msg;
+    try {
+        msg.writeBoolean( true );
+        msg.reset();
+        CPPUNIT_ASSERT( msg.readBoolean() );
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testReadByte() {
+
+    ActiveMQBytesMessage msg;
+    try {
+        msg.writeByte( (unsigned char)2 );
+        msg.reset();
+        CPPUNIT_ASSERT( msg.readByte() == 2 );
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testReadShort() {
+
+    ActiveMQBytesMessage msg;
+    try {
+        msg.writeShort( (short)3000 );
+        msg.reset();
+        CPPUNIT_ASSERT( msg.readShort() == 3000 );
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testReadUnsignedShort() {
+
+    ActiveMQBytesMessage msg;
+    try {
+        msg.writeShort( (short)3000 );
+        msg.reset();
+        CPPUNIT_ASSERT( msg.readUnsignedShort() == 3000 );
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testReadChar() {
+
+    ActiveMQBytesMessage msg;
+    try {
+        msg.writeChar( 'a' );
+        msg.reset();
+        CPPUNIT_ASSERT( msg.readChar() == 'a' );
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testReadInt() {
+
+    ActiveMQBytesMessage msg;
+    try {
+        msg.writeInt( 3000 );
+        msg.reset();
+        CPPUNIT_ASSERT( msg.readInt() == 3000 );
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testReadLong() {
+
+    ActiveMQBytesMessage msg;
+    try {
+        msg.writeLong( 3000 );
+        msg.reset();
+        CPPUNIT_ASSERT( msg.readLong() == 3000 );
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testReadFloat() {
+
+    ActiveMQBytesMessage msg;
+    try {
+        msg.writeFloat( 3.3f );
+        msg.reset();
+        CPPUNIT_ASSERT( msg.readFloat() == 3.3f );
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testReadDouble() {
+
+    ActiveMQBytesMessage msg;
+    try {
+        msg.writeDouble( 3.3 );
+        msg.reset();
+        CPPUNIT_ASSERT( msg.readDouble() == 3.3 );
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testReadUTF() {
+
+    ActiveMQBytesMessage msg;
+    try {
+        std::string str = "this is a test";
+        msg.writeUTF( str );
+        msg.reset();
+        CPPUNIT_ASSERT( msg.readUTF() == str );
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testReadBytesbyteArray() {
+
+    ActiveMQBytesMessage msg;
+    try {
+        unsigned char data[50];
+        for( int i = 0; i < 50; i++ ) {
+            data[i] = (unsigned char)i;
+        }
+        msg.writeBytes( &data[0], 0, 50 );
+        msg.reset();
+        unsigned char test[50];
+        msg.readBytes( test, 50 );
+        for( int i = 0; i < 50; i++ ) {
+            CPPUNIT_ASSERT( test[i] == i );
+        }
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testClearBody() {
+    ActiveMQBytesMessage bytesMessage;
+    try {
+        bytesMessage.writeInt( 1 );
+        bytesMessage.clearBody();
+        CPPUNIT_ASSERT( !bytesMessage.isReadOnlyBody() );
+        bytesMessage.writeInt( 1 );
+        bytesMessage.readInt();
+    } catch( MessageNotReadableException& mnwe ) {
+    } catch( MessageNotWriteableException& mnwe ) {
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testReset() {
+    ActiveMQBytesMessage message;
+    try {
+        message.writeDouble( 24.5 );
+        message.writeLong( 311 );
+    } catch( MessageNotWriteableException& mnwe ) {
+        CPPUNIT_FAIL( "should be writeable" );
+    }
+    message.reset();
+    try {
+        CPPUNIT_ASSERT( message.isReadOnlyBody() );
+        CPPUNIT_ASSERT_DOUBLES_EQUAL( message.readDouble(), 24.5, 0 );
+        CPPUNIT_ASSERT_EQUAL( message.readLong(), 311LL );
+    } catch( MessageNotReadableException& mnre ) {
+        CPPUNIT_FAIL( "should be readable" );
+    }
+    try {
+        message.writeInt( 33 );
+        CPPUNIT_FAIL( "should throw exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testReadOnlyBody() {
+
+    ActiveMQBytesMessage message;
+    std::vector<unsigned char> buffer(3);
+    unsigned char array[2];
+
+    try {
+        message.writeBoolean( true );
+        message.writeByte( (unsigned char)1 );
+        message.writeByte( (unsigned char)1 );
+        message.writeBytes( buffer );
+        message.writeBytes( &array[0], 0, 2 );
+        message.writeChar( 'a' );
+        message.writeDouble( 1.5 );
+        message.writeFloat( (float)1.5 );
+        message.writeInt( 1 );
+        message.writeLong( 1 );
+        message.writeString( "stringobj" );
+        message.writeShort( (short)1 );
+        message.writeShort( (short)1 );
+        message.writeUTF( "utfstring" );
+    } catch( MessageNotWriteableException& mnwe ) {
+        CPPUNIT_FAIL( "Should be writeable" );
+    }
+    message.reset();
+    try {
+        message.readBoolean();
+        message.readByte();
+        message.readByte();
+        message.readBytes( buffer );
+        message.readBytes( &array[0], 2 );
+        message.readChar();
+        message.readDouble();
+        message.readFloat();
+        message.readInt();
+        message.readLong();
+        message.readString();
+        message.readShort();
+        message.readUnsignedShort();
+        message.readUTF();
+    } catch( MessageNotReadableException& mnwe ) {
+        CPPUNIT_FAIL( "Should be readable" );
+    }
+    try {
+        message.writeBoolean( true );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        message.writeByte( (unsigned char)1 );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        message.writeBytes( buffer );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        message.writeBytes( &array[0], 0, 2 );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        message.writeChar( 'a' );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        message.writeDouble( 1.5 );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        message.writeFloat( (float)1.5 );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        message.writeInt( 1 );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        message.writeLong( 1 );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        message.writeString( "stringobj" );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        message.writeShort( (short)1 );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        message.writeUTF( "utfstring" );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQBytesMessageTest::testWriteOnlyBody() {
+    ActiveMQBytesMessage message;
+    message.clearBody();
+    std::vector<unsigned char> buffer(3);
+    unsigned char array[2];
+    try {
+        message.writeBoolean( true );
+        message.writeByte( (unsigned char)1 );
+        message.writeByte( (unsigned char)1 );
+        message.writeBytes( buffer );
+        message.writeBytes( &array[0], 0, 2 );
+        message.writeChar( 'a' );
+        message.writeDouble( 1.5 );
+        message.writeFloat( (float)1.5 );
+        message.writeInt( 1 );
+        message.writeLong( 1LL );
+        message.writeString( "stringobj" );
+        message.writeShort( (short)1 );
+        message.writeShort( (short)1 );
+        message.writeUTF( "utfstring" );
+    } catch( MessageNotWriteableException& mnwe ) {
+        CPPUNIT_FAIL( "Should be writeable" );
+    }
+    try {
+        message.readBoolean();
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotReadableException& mnwe ) {
+    }
+    try {
+        message.readByte();
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotReadableException& e ) {
+    }
+    try {
+        message.readBytes( buffer );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotReadableException& e ) {
+    }
+    try {
+        message.readBytes( &array[0], 2 );
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotReadableException& e ) {
+    }
+    try {
+        message.readChar();
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotReadableException& e ) {
+    }
+    try {
+        message.readDouble();
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotReadableException& e ) {
+    }
+    try {
+        message.readFloat();
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotReadableException& e ) {
+    }
+    try {
+        message.readInt();
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotReadableException& e ) {
+    }
+    try {
+        message.readLong();
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotReadableException& e ) {
+    }
+    try {
+        message.readString();
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotReadableException& e ) {
+    }
+    try {
+        message.readShort();
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotReadableException& e ) {
+    }
+    try {
+        message.readUnsignedShort();
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotReadableException& e ) {
+    }
+    try {
+        message.readUTF();
+        CPPUNIT_FAIL( "Should have thrown exception" );
+    } catch( MessageNotReadableException& e ) {
+    }
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQBytesMessageTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQBytesMessageTest.h?rev=882361&r1=882360&r2=882361&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQBytesMessageTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQBytesMessageTest.h Thu Nov 19 23:37:26 2009
@@ -27,7 +27,22 @@
     class ActiveMQBytesMessageTest : public CppUnit::TestFixture {
 
         CPPUNIT_TEST_SUITE( ActiveMQBytesMessageTest );
-        CPPUNIT_TEST( test );
+        CPPUNIT_TEST( testGetBodyLength );
+        CPPUNIT_TEST( testReadBoolean );
+        CPPUNIT_TEST( testReadByte );
+        CPPUNIT_TEST( testReadShort );
+        CPPUNIT_TEST( testReadUnsignedShort );
+        CPPUNIT_TEST( testReadChar );
+        CPPUNIT_TEST( testReadInt );
+        CPPUNIT_TEST( testReadLong );
+        CPPUNIT_TEST( testReadFloat );
+        CPPUNIT_TEST( testReadDouble );
+        CPPUNIT_TEST( testReadUTF );
+        CPPUNIT_TEST( testReadBytesbyteArray );
+        CPPUNIT_TEST( testClearBody );
+        CPPUNIT_TEST( testReset );
+        CPPUNIT_TEST( testReadOnlyBody );
+        CPPUNIT_TEST( testWriteOnlyBody );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -35,7 +50,24 @@
         ActiveMQBytesMessageTest() {}
         virtual ~ActiveMQBytesMessageTest() {}
 
-        void test();
+        void testGetBodyLength();
+        void testReadBoolean();
+        void testReadByte();
+        void testReadUnsignedByte();
+        void testReadShort();
+        void testReadUnsignedShort();
+        void testReadChar();
+        void testReadInt();
+        void testReadLong();
+        void testReadFloat();
+        void testReadDouble();
+        void testReadUTF();
+        void testReadBytesbyteArray();
+        void testClearBody();
+        void testReset();
+        void testReadOnlyBody();
+        void testWriteOnlyBody();
+
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMapMessageTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMapMessageTest.cpp?rev=882361&r1=882360&r2=882361&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMapMessageTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMapMessageTest.cpp Thu Nov 19 23:37:26 2009
@@ -19,14 +19,16 @@
 
 #include <activemq/commands/ActiveMQMapMessage.h>
 
+#include <algorithm>
+
+using namespace cms;
 using namespace std;
 using namespace activemq;
 using namespace activemq::util;
 using namespace activemq::commands;
 
 ////////////////////////////////////////////////////////////////////////////////
-void ActiveMQMapMessageTest::test()
-{
+void ActiveMQMapMessageTest::test() {
     ActiveMQMapMessage myMessage;
 
     CPPUNIT_ASSERT( myMessage.getDataStructureType() == ActiveMQMapMessage::ID_ACTIVEMQMAPMESSAGE );
@@ -62,3 +64,410 @@
     CPPUNIT_ASSERT( myMessage.getDouble( "double" ) == 64.54654 );
     CPPUNIT_ASSERT( myMessage.getBytes( "bytes" ) == data );
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testBytesConversion() {
+
+    ActiveMQMapMessage msg;
+
+    std::vector<unsigned char> buffer( 1 );
+
+    msg.setBoolean( "boolean", true );
+    msg.setByte( "byte", (unsigned char)1 );
+    msg.setBytes( "bytes", buffer );
+    msg.setChar( "char", 'a' );
+    msg.setDouble( "double", 1.5 );
+    msg.setFloat( "float", 1.5f );
+    msg.setInt( "int", 1 );
+    msg.setLong( "long", 1 );
+    msg.setShort( "short", (short)1 );
+    msg.setString( "string", "string" );
+
+    // Test with a 1Meg String
+    std::string bigString;
+
+    bigString.reserve( 1024 * 1024 );
+    for( int i = 0; i < 1024 * 1024; i++ ) {
+        bigString += ( (char)'a' + i % 26 );
+    }
+
+    msg.setString( "bigString", bigString );
+
+    ActiveMQMapMessage msg2;
+    msg2.copyDataStructure( &msg );
+
+    CPPUNIT_ASSERT_EQUAL( msg2.getBoolean("boolean"), true);
+    CPPUNIT_ASSERT_EQUAL( msg2.getByte( "byte" ), (unsigned char)1 );
+    CPPUNIT_ASSERT_EQUAL( msg2.getBytes( "bytes" ).size(), (std::size_t)1 );
+    CPPUNIT_ASSERT_EQUAL( msg2.getChar( "char" ), 'a' );
+    CPPUNIT_ASSERT_DOUBLES_EQUAL( msg2.getDouble( "double" ), 1.5, 0.01 );
+    CPPUNIT_ASSERT_DOUBLES_EQUAL( msg2.getFloat( "float" ), 1.5f, 0.01 );
+    CPPUNIT_ASSERT_EQUAL( msg2.getInt( "int" ), 1 );
+    CPPUNIT_ASSERT_EQUAL( msg2.getLong( "long" ), 1LL );
+    CPPUNIT_ASSERT_EQUAL( msg2.getShort( "short" ), (short)1 );
+    CPPUNIT_ASSERT_EQUAL( msg2.getString( "string" ), std::string( "string" ) );
+    CPPUNIT_ASSERT_EQUAL( msg2.getString( "bigString" ), bigString );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testGetBoolean() {
+
+    ActiveMQMapMessage msg;
+    msg.setBoolean( name, true );
+    msg.setReadOnlyBody( true );
+    CPPUNIT_ASSERT( msg.getBoolean( name ) );
+    msg.clearBody();
+    msg.setString( name, "true" );
+
+    ActiveMQMapMessage msg2;
+    msg2.copyDataStructure( &msg );
+
+    CPPUNIT_ASSERT( msg2.getBoolean( name ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testGetByte() {
+    ActiveMQMapMessage msg;
+    msg.setByte( name, (unsigned char)1 );
+
+    ActiveMQMapMessage msg2;
+    msg2.copyDataStructure( &msg );
+
+    CPPUNIT_ASSERT( msg2.getByte( name ) == (unsigned char)1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testGetShort() {
+    ActiveMQMapMessage msg;
+    try {
+        msg.setShort( name, (short)1 );
+
+        ActiveMQMapMessage msg2;
+        msg2.copyDataStructure( &msg );
+
+        CPPUNIT_ASSERT( msg2.getShort( name ) == (short)1 );
+
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testGetChar() {
+    ActiveMQMapMessage msg;
+    try {
+        msg.setChar( name, 'a' );
+
+        ActiveMQMapMessage msg2;
+        msg2.copyDataStructure( &msg );
+
+        CPPUNIT_ASSERT( msg2.getChar( name ) == 'a' );
+
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testGetInt() {
+    ActiveMQMapMessage msg;
+    try {
+        msg.setInt( name, 1 );
+
+        ActiveMQMapMessage msg2;
+        msg2.copyDataStructure( &msg );
+
+        CPPUNIT_ASSERT( msg2.getInt( name ) == 1 );
+
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testGetLong() {
+    ActiveMQMapMessage msg;
+    try {
+        msg.setLong( name, 1 );
+
+        ActiveMQMapMessage msg2;
+        msg2.copyDataStructure( &msg );
+
+        CPPUNIT_ASSERT( msg2.getLong( name ) == 1 );
+
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testGetFloat() {
+    ActiveMQMapMessage msg;
+    try {
+        msg.setFloat( name, 1.5f );
+
+        ActiveMQMapMessage msg2;
+        msg2.copyDataStructure( &msg );
+
+        CPPUNIT_ASSERT( msg2.getFloat( name ) == 1.5f );
+
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testGetDouble() {
+    ActiveMQMapMessage msg;
+    try {
+        msg.setDouble( name, 1.5 );
+
+        ActiveMQMapMessage msg2;
+        msg2.copyDataStructure( &msg );
+
+        CPPUNIT_ASSERT( msg2.getDouble( name ) == 1.5 );
+
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testGetString() {
+    ActiveMQMapMessage msg;
+    try {
+        std::string str = "test";
+        msg.setString( name, str );
+
+        ActiveMQMapMessage msg2;
+        msg2.copyDataStructure( &msg );
+
+        CPPUNIT_ASSERT( msg2.getString( name ) == str );
+
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testGetBytes() {
+    ActiveMQMapMessage msg;
+    try {
+
+        std::vector<unsigned char> bytes1( 3, 'a' );
+        std::vector<unsigned char> bytes2( 2, 'b' );
+
+        msg.setBytes( name, bytes1 );
+        msg.setBytes( name + "2", bytes2 );
+
+        ActiveMQMapMessage msg2;
+        msg2.copyDataStructure( &msg );
+
+        CPPUNIT_ASSERT( msg2.getBytes( name ) == bytes1 );
+        CPPUNIT_ASSERT_EQUAL( msg2.getBytes( name + "2" ).size(), bytes2.size() );
+
+    } catch( CMSException& ex ) {
+        ex.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testGetMapNames() {
+
+    ActiveMQMapMessage msg;
+
+    std::vector<unsigned char> bytes1( 3, 'a' );
+    std::vector<unsigned char> bytes2( 2, 'b' );
+
+    msg.setBoolean( "boolean", true );
+    msg.setByte( "byte", (unsigned char)1 );
+    msg.setBytes( "bytes1", bytes1 );
+    msg.setBytes( "bytes2", bytes2 );
+    msg.setChar( "char", 'a' );
+    msg.setDouble( "double", 1.5 );
+    msg.setFloat( "float", 1.5f );
+    msg.setInt( "int", 1 );
+    msg.setLong( "long", 1 );
+    msg.setShort( "short", (short)1 );
+    msg.setString( "string", "string" );
+
+    ActiveMQMapMessage msg2;
+    msg2.copyDataStructure( &msg );
+
+    std::vector<std::string> mapNamesList = msg2.getMapNames();
+
+    CPPUNIT_ASSERT_EQUAL( mapNamesList.size(), (std::size_t)11 );
+    CPPUNIT_ASSERT( std::find( mapNamesList.begin(), mapNamesList.end(), "boolean" ) != mapNamesList.end() );
+    CPPUNIT_ASSERT( std::find( mapNamesList.begin(), mapNamesList.end(), "byte" ) != mapNamesList.end() );
+    CPPUNIT_ASSERT( std::find( mapNamesList.begin(), mapNamesList.end(), "bytes1" ) != mapNamesList.end() );
+    CPPUNIT_ASSERT( std::find( mapNamesList.begin(), mapNamesList.end(), "bytes2" ) != mapNamesList.end() );
+    CPPUNIT_ASSERT( std::find( mapNamesList.begin(), mapNamesList.end(), "char" ) != mapNamesList.end() );
+    CPPUNIT_ASSERT( std::find( mapNamesList.begin(), mapNamesList.end(), "double" ) != mapNamesList.end() );
+    CPPUNIT_ASSERT( std::find( mapNamesList.begin(), mapNamesList.end(), "float" ) != mapNamesList.end() );
+    CPPUNIT_ASSERT( std::find( mapNamesList.begin(), mapNamesList.end(), "int" ) != mapNamesList.end() );
+    CPPUNIT_ASSERT( std::find( mapNamesList.begin(), mapNamesList.end(), "long" ) != mapNamesList.end() );
+    CPPUNIT_ASSERT( std::find( mapNamesList.begin(), mapNamesList.end(), "short" ) != mapNamesList.end() );
+    CPPUNIT_ASSERT( std::find( mapNamesList.begin(), mapNamesList.end(), "string" ) != mapNamesList.end() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testItemExists() {
+    ActiveMQMapMessage mapMessage;
+
+    mapMessage.setString( "exists", "test" );
+
+    ActiveMQMapMessage mapMessage2;
+    mapMessage2.copyDataStructure( &mapMessage );
+
+    CPPUNIT_ASSERT( mapMessage2.itemExists( "exists" ) );
+    CPPUNIT_ASSERT( !mapMessage2.itemExists( "doesntExist" ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testClearBody() {
+
+    ActiveMQMapMessage mapMessage;
+    mapMessage.setString( "String", "String" );
+    mapMessage.clearBody();
+    CPPUNIT_ASSERT( !mapMessage.isReadOnlyBody() );
+
+    mapMessage.onSend();
+    mapMessage.setContent( mapMessage.getContent() );
+    CPPUNIT_ASSERT( mapMessage.itemExists( "String" ) == false );
+    mapMessage.clearBody();
+    mapMessage.setString( "String", "String" );
+
+    ActiveMQMapMessage mapMessage2;
+    mapMessage2.copyDataStructure( &mapMessage );
+
+    CPPUNIT_ASSERT( mapMessage2.itemExists( "String" ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testReadOnlyBody() {
+
+    ActiveMQMapMessage msg;
+    std::vector<unsigned char> buffer(2);
+
+    msg.setBoolean( "boolean", true );
+    msg.setByte( "byte", (unsigned char)1 );
+    msg.setBytes( "bytes", buffer );
+    msg.setChar( "char", 'a' );
+    msg.setDouble( "double", 1.5 );
+    msg.setFloat( "float", 1.5f );
+    msg.setInt( "int", 1 );
+    msg.setLong( "long", 1 );
+    msg.setShort( "short", (short)1 );
+    msg.setString( "string", "string" );
+
+    msg.setReadOnlyBody( true );
+
+    try {
+        msg.getBoolean( "boolean" );
+        msg.getByte( "byte" );
+        msg.getBytes( "bytes" );
+        msg.getChar( "char" );
+        msg.getDouble( "double" );
+        msg.getFloat( "float" );
+        msg.getInt( "int" );
+        msg.getLong( "long" );
+        msg.getShort( "short" );
+        msg.getString( "string" );
+    } catch( MessageNotReadableException mnre ) {
+        CPPUNIT_FAIL( "should be readable" );
+    }
+    try {
+        msg.setBoolean( "boolean", true );
+        CPPUNIT_FAIL( "should throw exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        msg.setByte( "byte", (unsigned char)1 );
+        CPPUNIT_FAIL( "should throw exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        msg.setBytes( "bytes", buffer );
+        CPPUNIT_FAIL( "should throw exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        msg.setChar( "char", 'a' );
+        CPPUNIT_FAIL( "should throw exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        msg.setDouble( "double", 1.5 );
+        CPPUNIT_FAIL( "should throw exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        msg.setFloat( "float", 1.5f );
+        CPPUNIT_FAIL( "should throw exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        msg.setInt( "int", 1 );
+        CPPUNIT_FAIL( "should throw exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        msg.setLong( "long", 1 );
+        CPPUNIT_FAIL( "should throw exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        msg.setShort( "short", (short)1 );
+        CPPUNIT_FAIL( "should throw exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+    try {
+        msg.setString( "string", "string" );
+        CPPUNIT_FAIL( "should throw exception" );
+    } catch( MessageNotWriteableException& mnwe ) {
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMapMessageTest::testWriteOnlyBody() {
+
+    ActiveMQMapMessage msg;
+
+    std::vector<unsigned char> buffer1(1);
+    std::vector<unsigned char> buffer2(2);
+
+    msg.setReadOnlyBody( false );
+
+    msg.setBoolean( "boolean", true );
+    msg.setByte( "byte", (unsigned char)1 );
+    msg.setBytes( "bytes", buffer1 );
+    msg.setBytes( "bytes2", buffer2 );
+    msg.setChar( "char", 'a' );
+    msg.setDouble( "double", 1.5 );
+    msg.setFloat( "float", 1.5f );
+    msg.setInt( "int", 1 );
+    msg.setLong( "long", 1 );
+    msg.setShort( "short", (short)1 );
+    msg.setString( "string", "string" );
+
+    msg.setReadOnlyBody( true );
+
+    msg.getBoolean( "boolean" );
+    msg.getByte( "byte" );
+    msg.getBytes( "bytes" );
+    msg.getChar( "char" );
+    msg.getDouble( "double" );
+    msg.getFloat( "float" );
+    msg.getInt( "int" );
+    msg.getLong( "long" );
+    msg.getShort( "short" );
+    msg.getString( "string" );
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMapMessageTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMapMessageTest.h?rev=882361&r1=882360&r2=882361&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMapMessageTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMapMessageTest.h Thu Nov 19 23:37:26 2009
@@ -28,14 +28,51 @@
 
         CPPUNIT_TEST_SUITE( ActiveMQMapMessageTest );
         CPPUNIT_TEST( test );
+        CPPUNIT_TEST( testBytesConversion );
+        CPPUNIT_TEST( testGetBoolean );
+        CPPUNIT_TEST( testGetByte );
+        CPPUNIT_TEST( testGetShort );
+        CPPUNIT_TEST( testGetChar );
+        CPPUNIT_TEST( testGetInt );
+        CPPUNIT_TEST( testGetLong );
+        CPPUNIT_TEST( testGetFloat );
+        CPPUNIT_TEST( testGetDouble );
+        CPPUNIT_TEST( testGetString );
+        CPPUNIT_TEST( testGetBytes );
+        CPPUNIT_TEST( testGetMapNames );
+        CPPUNIT_TEST( testItemExists );
+        CPPUNIT_TEST( testClearBody );
+        CPPUNIT_TEST( testReadOnlyBody );
+        CPPUNIT_TEST( testWriteOnlyBody );
         CPPUNIT_TEST_SUITE_END();
 
+    private:
+
+        std::string name;
+
     public:
 
-        ActiveMQMapMessageTest() {}
+        ActiveMQMapMessageTest() { name = "test-name"; }
         virtual ~ActiveMQMapMessageTest() {}
 
-        virtual void test();
+        void test();
+        void testBytesConversion();
+        void testGetBoolean();
+        void testGetByte();
+        void testGetShort();
+        void testGetChar();
+        void testGetInt();
+        void testGetLong();
+        void testGetFloat();
+        void testGetDouble();
+        void testGetString();
+        void testGetBytes();
+        void testGetMapNames();
+        void testItemExists();
+        void testClearBody();
+        void testReadOnlyBody();
+        void testWriteOnlyBody();
+
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMessageTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMessageTest.cpp?rev=882361&r1=882360&r2=882361&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMessageTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMessageTest.cpp Thu Nov 19 23:37:26 2009
@@ -18,12 +18,82 @@
 #include "ActiveMQMessageTest.h"
 
 #include <activemq/commands/ActiveMQMessage.h>
+#include <activemq/commands/ActiveMQTopic.h>
+#include <activemq/commands/ActiveMQTempTopic.h>
+#include <activemq/commands/ProducerId.h>
 
+#include <decaf/lang/System.h>
+#include <decaf/lang/Pointer.h>
+
+using namespace cms;
 using namespace std;
 using namespace activemq;
 using namespace activemq::util;
 using namespace activemq::core;
 using namespace activemq::commands;
+using namespace decaf::lang;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace{
+
+    class MyAckHandler : public core::ActiveMQAckHandler {
+    public:
+
+        MyAckHandler() {
+            this->wasAcked = false;
+        }
+
+        /**
+         * Method called to acknowledge the message passed
+         * @param message Message to Acknowledge
+         * @throw CMSException
+         */
+        virtual void acknowledgeMessage( const commands::Message* message )
+            throw ( cms::CMSException ) {
+
+            this->wasAcked = true;
+        }
+
+        /**
+         * Public indicator that we have received an ack
+         */
+        bool wasAcked;
+
+    };
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::setUp() {
+
+    Pointer<ProducerId> producerId( new ProducerId() );
+    producerId->setConnectionId( "testConnectionId" );
+    producerId->setSessionId( 11 );
+    producerId->setValue( 1 );
+
+    this->cmsMessageId.reset( new MessageId() );
+    this->cmsMessageId->setProducerId( producerId );
+    this->cmsMessageId->setProducerSequenceId( 12 );
+
+    this->cmsCorrelationID = "testcorrelationid";
+    this->cmsDestination.reset( new ActiveMQTopic( "test.topic" ) );
+    this->cmsReplyTo.reset( new ActiveMQTempTopic( "test.replyto.topic:001" ) );
+    this->cmsDeliveryMode = DeliveryMode::NON_PERSISTENT;
+    this->cmsRedelivered = true;
+    this->cmsType = "test type";
+    this->cmsExpiration = 100000;
+    this->cmsPriority = 5;
+    this->cmsTimestamp = System::currentTimeMillis();
+    this->readOnlyMessage = false;
+
+    for( int i = 0; i < 3; i++ ) {
+        this->consumerIDs.push_back( i );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::tearDown() {
+
+}
 
 ////////////////////////////////////////////////////////////////////////////////
 void ActiveMQMessageTest::test()
@@ -67,3 +137,686 @@
     myMessage.setStringProperty( "JMSXGroupID", "hello" );
     CPPUNIT_ASSERT( myMessage.getStringProperty( "JMSXGroupID" ) == "hello" );
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testSetReadOnly() {
+
+    ActiveMQMessage msg;
+    msg.setReadOnlyProperties( true );
+    bool test = false;
+
+    try {
+        msg.setIntProperty( "test", 1 );
+    } catch( MessageNotWriteableException& me ) {
+        test = true;
+    } catch( CMSException& e ) {
+        e.printStackTrace();
+        test = false;
+    }
+
+    CPPUNIT_ASSERT( test );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testSetToForeignJMSID() {
+
+    ActiveMQMessage msg;
+    msg.setCMSMessageID( "ID:EMS-SERVER.8B443C380083:429" );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testEqualsObject() {
+
+    ActiveMQMessage msg1;
+    ActiveMQMessage msg2;
+
+    msg1.setMessageId( this->cmsMessageId );
+    CPPUNIT_ASSERT( !msg1.equals( &msg2 ) );
+
+    msg2.setMessageId( this->cmsMessageId );
+    CPPUNIT_ASSERT( msg1.equals( &msg2 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testShallowCopy() {
+
+    ActiveMQMessage msg1;
+    msg1.setMessageId( this->cmsMessageId );
+
+    ActiveMQMessage msg2;
+    msg2.copyDataStructure( &msg1 );
+
+    CPPUNIT_ASSERT( msg1.equals( &msg2 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testCopy() {
+
+    this->cmsCorrelationID = "testcorrelationid";
+    this->cmsDestination.reset( new ActiveMQTopic( "test.topic" ) );
+    this->cmsReplyTo.reset( new ActiveMQTempTopic( "test.replyto.topic:001" ) );
+    this->cmsRedelivered = true;
+    this->cmsType = "test type";
+    this->cmsExpiration = 100000;
+    this->cmsPriority = 5;
+    this->cmsTimestamp = System::currentTimeMillis();
+    this->readOnlyMessage = false;
+
+    ActiveMQMessage msg1;
+    msg1.setMessageId( this->cmsMessageId );
+    msg1.setCMSCorrelationID( this->cmsCorrelationID );
+    msg1.setCMSDestination( this->cmsDestination.get() );
+    msg1.setCMSReplyTo( this->cmsReplyTo.get() );
+    msg1.setCMSDeliveryMode( this->cmsDeliveryMode );
+    msg1.setCMSRedelivered( this->cmsRedelivered );
+    msg1.setCMSType( this->cmsType );
+    msg1.setCMSExpiration( this->cmsExpiration );
+    msg1.setCMSPriority( this->cmsPriority );
+    msg1.setCMSTimestamp( this->cmsTimestamp );
+    msg1.setReadOnlyProperties( true );
+
+    ActiveMQMessage msg2;
+    msg2.copyDataStructure( &msg1 );
+
+    CPPUNIT_ASSERT( msg1.getCMSMessageID() == msg2.getCMSMessageID() );
+    CPPUNIT_ASSERT( msg1.getCMSCorrelationID() == msg2.getCMSCorrelationID() );
+    CPPUNIT_ASSERT( msg1.getCMSDestination() == msg2.getCMSDestination() );
+    CPPUNIT_ASSERT( msg1.getCMSReplyTo() == msg2.getCMSReplyTo() );
+    CPPUNIT_ASSERT( msg1.getCMSDeliveryMode() == msg2.getCMSDeliveryMode() );
+    CPPUNIT_ASSERT( msg1.getCMSRedelivered() == msg2.getCMSRedelivered() );
+    CPPUNIT_ASSERT( msg1.getCMSType() == msg2.getCMSType() );
+    CPPUNIT_ASSERT( msg1.getCMSExpiration() == msg2.getCMSExpiration() );
+    CPPUNIT_ASSERT( msg1.getCMSPriority() == msg2.getCMSPriority() );
+    CPPUNIT_ASSERT( msg1.getCMSTimestamp() == msg2.getCMSTimestamp() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetAndSetCMSMessageID() {
+
+    ActiveMQMessage msg;
+    msg.setMessageId( this->cmsMessageId );
+    CPPUNIT_ASSERT( msg.getMessageId() == this->cmsMessageId );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetAndSetCMSTimestamp() {
+
+    ActiveMQMessage msg;
+    msg.setCMSTimestamp( this->cmsTimestamp );
+    CPPUNIT_ASSERT( msg.getCMSTimestamp() == this->cmsTimestamp );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetAndSetCMSCorrelationID() {
+
+    ActiveMQMessage msg;
+    msg.setCMSCorrelationID( this->cmsCorrelationID );
+    CPPUNIT_ASSERT( msg.getCMSCorrelationID() == this->cmsCorrelationID );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetAndSetCMSDeliveryMode() {
+
+    ActiveMQMessage msg;
+    msg.setCMSDeliveryMode( this->cmsDeliveryMode );
+    CPPUNIT_ASSERT( msg.getCMSDeliveryMode() == this->cmsDeliveryMode );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetAndSetCMSRedelivered() {
+
+    ActiveMQMessage msg;
+    msg.setRedeliveryCounter( 1 );
+    CPPUNIT_ASSERT( msg.getCMSRedelivered() == true );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetAndSetCMSType() {
+
+    ActiveMQMessage msg;
+    msg.setCMSType( this->cmsType );
+    CPPUNIT_ASSERT( msg.getCMSType() == this->cmsType );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetAndSetCMSExpiration() {
+
+    ActiveMQMessage msg;
+    msg.setCMSExpiration( this->cmsExpiration );
+    CPPUNIT_ASSERT( msg.getCMSExpiration() == this->cmsExpiration );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetAndSetCMSPriority() {
+
+    ActiveMQMessage msg;
+    msg.setCMSPriority( this->cmsPriority );
+    CPPUNIT_ASSERT( msg.getCMSPriority() == this->cmsPriority );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testClearProperties() {
+
+    ActiveMQMessage msg;
+
+    std::vector<unsigned char> buffer( 20 );
+
+    msg.setStringProperty( "test", "test" );
+    msg.setContent( buffer );
+    msg.setMessageId( this->cmsMessageId );
+    msg.clearProperties();
+
+    CPPUNIT_ASSERT( !msg.propertyExists( "test" ) );
+    CPPUNIT_ASSERT( msg.getCMSMessageID() != "" );
+    CPPUNIT_ASSERT( msg.getContent().size() == 20 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testPropertyExists() {
+
+    ActiveMQMessage msg;
+    msg.setStringProperty( "test", "test" );
+    CPPUNIT_ASSERT( msg.propertyExists( "test" ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetBooleanProperty() {
+
+    ActiveMQMessage msg;
+    std::string name = "booleanProperty";
+    msg.setBooleanProperty( name, true );
+    CPPUNIT_ASSERT( msg.getBooleanProperty( name ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetByteProperty() {
+
+    ActiveMQMessage msg;
+    std::string name = "byteProperty";
+    msg.setByteProperty( name, (unsigned char)1 );
+    CPPUNIT_ASSERT( msg.getByteProperty( name ) == 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetShortProperty() {
+
+    ActiveMQMessage msg;
+    std::string name = "shortProperty";
+    msg.setShortProperty( name, (short)1 );
+    CPPUNIT_ASSERT( msg.getShortProperty( name ) == 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetIntProperty() {
+
+    ActiveMQMessage msg;
+    std::string name = "intProperty";
+    msg.setIntProperty( name, 1 );
+    CPPUNIT_ASSERT( msg.getIntProperty( name ) == 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetLongProperty() {
+
+    ActiveMQMessage msg;
+    std::string name = "longProperty";
+    msg.setLongProperty( name, 1 );
+    CPPUNIT_ASSERT( msg.getLongProperty( name ) == 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetFloatProperty() {
+
+    ActiveMQMessage msg;
+    std::string name = "floatProperty";
+    msg.setFloatProperty( name, 1.3f );
+    CPPUNIT_ASSERT( msg.getFloatProperty( name ) == 1.3f );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetDoubleProperty() {
+
+    ActiveMQMessage msg;
+    std::string name = "doubleProperty";
+    msg.setDoubleProperty( name, 1.3 );
+    CPPUNIT_ASSERT( msg.getDoubleProperty( name ) == 1.3 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetStringProperty() {
+
+    ActiveMQMessage msg;
+    std::string name = "stringProperty";
+    msg.setStringProperty( name, name );
+    CPPUNIT_ASSERT( msg.getStringProperty( name ) == name );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetPropertyNames() {
+
+    ActiveMQMessage msg;
+    std::string name = "floatProperty";
+    msg.setFloatProperty( name, 1.3f );
+
+    std::vector<std::string> propertyNames = msg.getPropertyNames();
+    std::vector<std::string>::iterator iter = propertyNames.begin();
+
+    for( ; iter != propertyNames.end(); ++iter ) {
+        CPPUNIT_ASSERT( *iter == name );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testSetEmptyPropertyName() {
+
+    ActiveMQMessage msg;
+
+    try {
+        msg.setStringProperty("", "Cheese");
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( CMSException& e ) {
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testGetAndSetCMSXDeliveryCount() {
+
+    ActiveMQMessage msg;
+    msg.setIntProperty( "CMSXDeliveryCount", 1 );
+    int count = msg.getIntProperty( "CMSXDeliveryCount" );
+    CPPUNIT_ASSERT_MESSAGE( "expected delivery count = 1 - got: " + count, count == 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testClearBody() {
+
+    ActiveMQMessage message;
+    message.clearBody();
+    CPPUNIT_ASSERT( !message.isReadOnlyBody() );
+    CPPUNIT_ASSERT( message.getContent().size() == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testBooleanPropertyConversion() {
+
+    ActiveMQMessage msg;
+    std::string propertyName = "property";
+    msg.setBooleanProperty( propertyName, true );
+
+    CPPUNIT_ASSERT( msg.getBooleanProperty( propertyName ) );
+    CPPUNIT_ASSERT( msg.getStringProperty( propertyName ) == "true" );
+
+    try {
+        msg.getByteProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getShortProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getIntProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getLongProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getFloatProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getDoubleProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testBytePropertyConversion() {
+
+    ActiveMQMessage msg;
+    std::string propertyName = "property";
+    msg.setByteProperty( propertyName, (unsigned char)1 );
+
+    CPPUNIT_ASSERT( msg.getByteProperty( propertyName ) == 1 );
+    CPPUNIT_ASSERT( msg.getShortProperty( propertyName ) == 1 );
+    CPPUNIT_ASSERT( msg.getIntProperty( propertyName ) == 1 );
+    CPPUNIT_ASSERT( msg.getLongProperty( propertyName ) == 1 );
+    CPPUNIT_ASSERT( msg.getStringProperty( propertyName ) == "1" );
+
+    try {
+        msg.getBooleanProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getFloatProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getDoubleProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testShortPropertyConversion() {
+
+    ActiveMQMessage msg;
+    std::string propertyName = "property";
+    msg.setShortProperty( propertyName, (short)1 );
+
+    CPPUNIT_ASSERT( msg.getShortProperty( propertyName ) == 1 );
+    CPPUNIT_ASSERT( msg.getIntProperty( propertyName ) == 1 );
+    CPPUNIT_ASSERT( msg.getLongProperty( propertyName ) == 1 );
+    CPPUNIT_ASSERT( msg.getStringProperty( propertyName ) == "1" );
+
+    try {
+        msg.getBooleanProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getByteProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getFloatProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getDoubleProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testIntPropertyConversion() {
+
+    ActiveMQMessage msg;
+    std::string propertyName = "property";
+    msg.setIntProperty( propertyName, (int)1 );
+
+    CPPUNIT_ASSERT( msg.getIntProperty( propertyName ) == 1 );
+    CPPUNIT_ASSERT( msg.getLongProperty( propertyName ) == 1 );
+    CPPUNIT_ASSERT( msg.getStringProperty( propertyName ) == "1" );
+
+    try {
+        msg.getBooleanProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getByteProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getShortProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getFloatProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getDoubleProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testLongPropertyConversion() {
+
+    ActiveMQMessage msg;
+    std::string propertyName = "property";
+    msg.setLongProperty( propertyName, 1 );
+
+    CPPUNIT_ASSERT( msg.getLongProperty( propertyName ) == 1 );
+    CPPUNIT_ASSERT( msg.getStringProperty( propertyName ) == "1" );
+
+    try {
+        msg.getBooleanProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getByteProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getShortProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getIntProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getFloatProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getDoubleProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testFloatPropertyConversion() {
+
+    ActiveMQMessage msg;
+    std::string propertyName = "property";
+    msg.setFloatProperty( propertyName, (float)1.5 );
+
+    CPPUNIT_ASSERT_DOUBLES_EQUAL( msg.getFloatProperty( propertyName ), 1.5, 0 );
+    CPPUNIT_ASSERT_DOUBLES_EQUAL( msg.getDoubleProperty( propertyName ), 1.5, 0 );
+    CPPUNIT_ASSERT( msg.getStringProperty( propertyName ) == "1.5" );
+
+    try {
+        msg.getBooleanProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getByteProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getShortProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getIntProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getLongProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testDoublePropertyConversion() {
+
+    ActiveMQMessage msg;
+    std::string propertyName = "property";
+    msg.setDoubleProperty( propertyName, 1.5 );
+
+    CPPUNIT_ASSERT_DOUBLES_EQUAL( msg.getDoubleProperty( propertyName ), 1.5, 0 );
+    CPPUNIT_ASSERT( msg.getStringProperty( propertyName ) == "1.5" );
+
+    try {
+        msg.getBooleanProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getByteProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getShortProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getIntProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getLongProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getFloatProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testStringPropertyConversion() {
+
+    ActiveMQMessage msg;
+    std::string propertyName = "property";
+    std::string stringValue = "true";
+
+    msg.setStringProperty( propertyName, stringValue );
+
+    CPPUNIT_ASSERT( msg.getStringProperty( propertyName ) == stringValue );
+    CPPUNIT_ASSERT( msg.getBooleanProperty( propertyName ) == true );
+
+    stringValue = "1";
+    msg.setStringProperty( propertyName, stringValue );
+    CPPUNIT_ASSERT( msg.getByteProperty( propertyName ) == 1 );
+    CPPUNIT_ASSERT( msg.getShortProperty( propertyName ) == 1 );
+    CPPUNIT_ASSERT( msg.getIntProperty( propertyName ) == 1 );
+    CPPUNIT_ASSERT( msg.getLongProperty( propertyName ) == 1 );
+
+    stringValue = "1.5";
+    msg.setStringProperty( propertyName, stringValue );
+    CPPUNIT_ASSERT_DOUBLES_EQUAL( msg.getFloatProperty( propertyName ), 1.5, 0 );
+    CPPUNIT_ASSERT_DOUBLES_EQUAL( msg.getDoubleProperty( propertyName ), 1.5, 0 );
+
+    stringValue = "bad";
+    msg.setStringProperty( propertyName, stringValue );
+    try {
+        msg.getByteProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getShortProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getIntProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getLongProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getFloatProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+    try {
+        msg.getDoubleProperty( propertyName );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageFormatException& e ) {
+    }
+
+    CPPUNIT_ASSERT( !msg.getBooleanProperty( propertyName ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testReadOnlyProperties() {
+
+    ActiveMQMessage msg;
+    std::string propertyName = "property";
+    msg.setReadOnlyProperties( true );
+
+    try {
+        msg.setStringProperty( propertyName, "test" );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageNotWriteableException& e ) {
+    }
+    try {
+        msg.setBooleanProperty( propertyName, true );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageNotWriteableException& e ) {
+    }
+    try {
+        msg.setByteProperty( propertyName, (unsigned char)1 );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageNotWriteableException& e ) {
+    }
+    try {
+        msg.setShortProperty( propertyName, (short)1 );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageNotWriteableException& e ) {
+    }
+    try {
+        msg.setIntProperty( propertyName, 1 );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageNotWriteableException& e ) {
+    }
+    try {
+        msg.setLongProperty( propertyName, 1 );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageNotWriteableException& e ) {
+    }
+    try {
+        msg.setFloatProperty( propertyName, (float)1.5 );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageNotWriteableException& e ) {
+    }
+    try {
+        msg.setDoubleProperty( propertyName, 1.5 );
+        CPPUNIT_FAIL("Should have thrown exception");
+    } catch( MessageNotWriteableException& e ) {
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ActiveMQMessageTest::testIsExpired() {
+
+    ActiveMQMessage msg;
+    msg.setCMSExpiration( System::currentTimeMillis() - 100 );
+    CPPUNIT_ASSERT( msg.isExpired() );
+    msg.setCMSExpiration( System::currentTimeMillis() + 10000 );
+    CPPUNIT_ASSERT( !msg.isExpired() );
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMessageTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMessageTest.h?rev=882361&r1=882360&r2=882361&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMessageTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/ActiveMQMessageTest.h Thu Nov 19 23:37:26 2009
@@ -22,6 +22,15 @@
 #include <cppunit/extensions/HelperMacros.h>
 
 #include <activemq/core/ActiveMQAckHandler.h>
+#include <activemq/commands/ActiveMQDestination.h>
+#include <activemq/commands/ActiveMQTopic.h>
+#include <activemq/commands/ActiveMQTempTopic.h>
+#include <activemq/commands/MessageId.h>
+
+#include <decaf/lang/Pointer.h>
+
+#include <vector>
+#include <memory>
 
 namespace activemq{
 namespace commands{
@@ -30,39 +39,106 @@
 
         CPPUNIT_TEST_SUITE( ActiveMQMessageTest );
         CPPUNIT_TEST( test );
+        CPPUNIT_TEST( testSetReadOnly );
+        CPPUNIT_TEST( testSetToForeignJMSID );
+        CPPUNIT_TEST( testEqualsObject );
+        CPPUNIT_TEST( testShallowCopy );
+        CPPUNIT_TEST( testCopy );
+        CPPUNIT_TEST( testGetAndSetCMSMessageID );
+        CPPUNIT_TEST( testGetAndSetCMSTimestamp );
+        CPPUNIT_TEST( testGetAndSetCMSCorrelationID );
+        CPPUNIT_TEST( testGetAndSetCMSDeliveryMode );
+        CPPUNIT_TEST( testGetAndSetCMSRedelivered );
+        CPPUNIT_TEST( testGetAndSetCMSType );
+        CPPUNIT_TEST( testGetAndSetCMSExpiration );
+        CPPUNIT_TEST( testGetAndSetCMSPriority );
+        CPPUNIT_TEST( testClearProperties );
+        CPPUNIT_TEST( testPropertyExists );
+        CPPUNIT_TEST( testGetBooleanProperty );
+        CPPUNIT_TEST( testGetByteProperty );
+        CPPUNIT_TEST( testGetShortProperty );
+        CPPUNIT_TEST( testGetIntProperty );
+        CPPUNIT_TEST( testGetLongProperty );
+        CPPUNIT_TEST( testGetFloatProperty );
+        CPPUNIT_TEST( testGetDoubleProperty );
+        CPPUNIT_TEST( testGetStringProperty );
+        CPPUNIT_TEST( testGetPropertyNames );
+        CPPUNIT_TEST( testSetEmptyPropertyName );
+        CPPUNIT_TEST( testGetAndSetCMSXDeliveryCount );
+        CPPUNIT_TEST( testClearBody );
+        CPPUNIT_TEST( testBooleanPropertyConversion );
+        CPPUNIT_TEST( testBytePropertyConversion );
+        CPPUNIT_TEST( testShortPropertyConversion );
+        CPPUNIT_TEST( testIntPropertyConversion );
+        CPPUNIT_TEST( testLongPropertyConversion );
+        CPPUNIT_TEST( testFloatPropertyConversion );
+        CPPUNIT_TEST( testDoublePropertyConversion );
+        CPPUNIT_TEST( testReadOnlyProperties );
+        CPPUNIT_TEST( testIsExpired );
         CPPUNIT_TEST_SUITE_END();
 
-        class MyAckHandler : public core::ActiveMQAckHandler {
-        public:
+    private:
 
-            MyAckHandler() {
-                this->wasAcked = false;
-            }
-
-            /**
-             * Method called to acknowledge the message passed
-             * @param message Message to Acknowlegde
-             * @throw CMSException
-             */
-            virtual void acknowledgeMessage( const commands::Message* message )
-                throw ( cms::CMSException ) {
-
-                this->wasAcked = true;
-            }
-
-            /**
-             * Public indicator that we have received an ack
-             */
-            bool wasAcked;
+        bool readOnlyMessage;
+        decaf::lang::Pointer<commands::MessageId> cmsMessageId;
+        std::string cmsCorrelationID;
+        std::auto_ptr<commands::ActiveMQTopic> cmsDestination;
+        std::auto_ptr<commands::ActiveMQTempTopic> cmsReplyTo;
+        int cmsDeliveryMode;
+        bool cmsRedelivered;
+        std::string cmsType;
+        long long cmsExpiration;
+        int cmsPriority;
+        long long cmsTimestamp;
 
-        };
+        std::vector<long long> consumerIDs;
 
     public:
 
         ActiveMQMessageTest() {}
         virtual ~ActiveMQMessageTest() {}
 
-        virtual void test();
+        virtual void setUp();
+        virtual void tearDown();
+
+        void test();
+        void testSetReadOnly();
+        void testSetToForeignJMSID();
+        void testEqualsObject();
+        void testShallowCopy();
+        void testCopy();
+        void testGetAndSetCMSMessageID();
+        void testGetAndSetCMSTimestamp();
+        void testGetAndSetCMSCorrelationID();
+        void testGetAndSetCMSDeliveryMode();
+        void testGetAndSetCMSRedelivered();
+        void testGetAndSetCMSType();
+        void testGetAndSetCMSExpiration();
+        void testGetAndSetCMSPriority();
+        void testClearProperties();
+        void testPropertyExists();
+        void testGetBooleanProperty();
+        void testGetByteProperty();
+        void testGetShortProperty();
+        void testGetIntProperty();
+        void testGetLongProperty();
+        void testGetFloatProperty();
+        void testGetDoubleProperty();
+        void testGetStringProperty();
+        void testGetPropertyNames();
+        void testSetEmptyPropertyName();
+        void testGetAndSetCMSXDeliveryCount();
+        void testClearBody();
+        void testBooleanPropertyConversion();
+        void testBytePropertyConversion();
+        void testShortPropertyConversion();
+        void testIntPropertyConversion();
+        void testLongPropertyConversion();
+        void testFloatPropertyConversion();
+        void testDoublePropertyConversion();
+        void testStringPropertyConversion();
+        void testReadOnlyProperties();
+        void testIsExpired();
 
     };
 



Mime
View raw message