activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r487422 [2/2] - in /incubator/activemq/activemq-cpp/trunk/activemq-cpp/src: main/ main/activemq/connector/openwire/commands/ main/activemq/connector/stomp/commands/ main/activemq/io/ main/activemq/network/ main/cms/ test/activemq/connector/...
Date Fri, 15 Dec 2006 01:47:19 GMT
Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/commands/BytesMessageCommandTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/commands/BytesMessageCommandTest.h?view=diff&rev=487422&r1=487421&r2=487422
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/commands/BytesMessageCommandTest.h
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/commands/BytesMessageCommandTest.h
Thu Dec 14 17:47:17 2006
@@ -34,6 +34,8 @@
     {
         CPPUNIT_TEST_SUITE( BytesMessageCommandTest );
         CPPUNIT_TEST( test );
+        CPPUNIT_TEST( testReadOnly );
+        CPPUNIT_TEST( testWriteOnly );
         CPPUNIT_TEST_SUITE_END();
 
     protected:
@@ -42,8 +44,8 @@
         {
         public:
         
-            TestAckHandler(void) { wasAcked = false; }
-            virtual ~TestAckHandler(void) {}
+            TestAckHandler() { wasAcked = false; }
+            virtual ~TestAckHandler() {}
             
             virtual void acknowledgeMessage( const core::ActiveMQMessage* message)
                 throw ( cms::CMSException ) 
@@ -62,7 +64,7 @@
     	BytesMessageCommandTest() {}
     	virtual ~BytesMessageCommandTest() {}
 
-        void test(void)
+        void test()
         {
             TestAckHandler ackHandler;
             BytesMessageCommand cmd;
@@ -196,6 +198,201 @@
                             (const char*)cmd5->getBodyBytes() );
 
             delete cmd2;
+        }
+        
+        void testReadOnly(){
+            
+            StompFrame* frame = new StompFrame();
+            frame->setCommand( CommandConstants::toString( CommandConstants::MESSAGE )
);
+            frame->getProperties().setProperty( CommandConstants::toString( CommandConstants::HEADER_DESTINATION
), 
+                (std::string)CommandConstants::topicPrefix + "mytopic" );
+            
+            // write a bunch of values to the frame's body.
+            io::ByteArrayOutputStream os( frame->getBody() );
+            io::DataOutputStream dos(&os);
+            dos.writeBoolean( true );
+            dos.writeByte( 1 );
+            dos.writeChar( 'a' );
+            dos.writeFloat( 2.0f );
+            dos.writeDouble( 3.0 );
+            dos.writeShort( 4 );
+            dos.writeUnsignedShort( 5 );
+            dos.writeInt( 6 );
+            dos.writeLong( 7LL );
+            dos.writeBytes( "hello world" );
+            
+            // Assign the frame to the bytes message.
+            BytesMessageCommand cmd(frame);
+            
+            // First, verify that we can't write (read-only)
+            
+            try{
+                cmd.setBodyBytes( (unsigned char*)"test", 5 );
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.writeBoolean( true );
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.writeByte( 2 );
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.writeBytes( std::vector<unsigned char>() );
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.writeBytes( (unsigned char*)"test", 0, 5 );
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.writeChar( 'a' );
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.writeFloat( 1.0f );
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.writeDouble( 2.0 );
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.writeUnsignedShort( 3 );
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.writeShort( 4 );
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.writeInt( 5 );
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.writeLong( 6LL );
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.writeString( "test" );
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            // Now, verify that all the reads work properly
+            
+            CPPUNIT_ASSERT( cmd.readBoolean() == true );
+            CPPUNIT_ASSERT( cmd.readByte() == 1 );
+            CPPUNIT_ASSERT( cmd.readChar() == 'a' );
+            CPPUNIT_ASSERT( cmd.readFloat() == 2.0f );
+            CPPUNIT_ASSERT( cmd.readDouble() == 3.0 );
+            CPPUNIT_ASSERT( cmd.readShort() == 4 );
+            CPPUNIT_ASSERT( cmd.readUnsignedShort() == 5 );
+            CPPUNIT_ASSERT( cmd.readInt() == 6 );
+            CPPUNIT_ASSERT( cmd.readLong() == 7LL );
+            CPPUNIT_ASSERT( cmd.readString() == "hello world" );
+        }
+        
+        void testWriteOnly(){
+            
+            BytesMessageCommand cmd;
+            
+            // First, verify that we can't read (write-only)
+            
+            try{
+                cmd.readBoolean();
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.readByte();
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                std::vector<unsigned char> buf;
+                cmd.readBytes(buf);
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.readChar();
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.readFloat();
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.readDouble();
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.readUnsignedShort();
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.readShort();
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.readInt();
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.readLong();
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            try{
+                cmd.readString();
+                CPPUNIT_ASSERT( false );
+            } catch( exceptions::IllegalStateException& e ){}
+            
+            // Now, verify that all the writes work properly
+            
+            cmd.writeBoolean( true );
+            cmd.writeByte( 1 );
+            cmd.writeChar( 'a' );
+            cmd.writeFloat( 2.0f );
+            cmd.writeDouble( 3.0 );
+            cmd.writeShort( 4 );
+            cmd.writeUnsignedShort( 5 );
+            cmd.writeInt( 6 );
+            cmd.writeLong( 7LL );
+            cmd.writeString( "hello world" );
+            
+            // Switch to read-only mode.
+            cmd.reset();
+            
+            CPPUNIT_ASSERT( cmd.readBoolean() == true );
+            CPPUNIT_ASSERT( cmd.readByte() == 1 );
+            CPPUNIT_ASSERT( cmd.readChar() == 'a' );
+            CPPUNIT_ASSERT( cmd.readFloat() == 2.0f );
+            CPPUNIT_ASSERT( cmd.readDouble() == 3.0 );
+            CPPUNIT_ASSERT( cmd.readShort() == 4 );
+            CPPUNIT_ASSERT( cmd.readUnsignedShort() == 5 );
+            CPPUNIT_ASSERT( cmd.readInt() == 6 );
+            CPPUNIT_ASSERT( cmd.readLong() == 7LL );
+            CPPUNIT_ASSERT( cmd.readString() == "hello world" );
         }
 
     };

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/BufferedInputStreamTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/BufferedInputStreamTest.h?view=diff&rev=487422&r1=487421&r2=487422
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/BufferedInputStreamTest.h
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/BufferedInputStreamTest.h
Thu Dec 14 17:47:17 2006
@@ -59,7 +59,7 @@
 				
 				return data.c_str()[pos++];
 			}
-			virtual int read( unsigned char* buffer, const int bufferSize ) throw (IOException){
+			virtual int read( unsigned char* buffer, int bufferSize ) throw (IOException){
 				unsigned int numToRead = std::min( bufferSize, available() );
 				
 				const char* str = data.c_str();

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/BufferedOutputStreamTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/BufferedOutputStreamTest.h?view=diff&rev=487422&r1=487421&r2=487422
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/BufferedOutputStreamTest.h
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/BufferedOutputStreamTest.h
Thu Dec 14 17:47:17 2006
@@ -50,7 +50,7 @@
 			
 			const char* getBuffer() const{ return buffer; }
 			
-			virtual void write( const unsigned char c ) throw (IOException){
+			virtual void write( unsigned char c ) throw (IOException){
 				if( pos >= 100 ){
 					throw IOException();
 				}
@@ -58,7 +58,7 @@
 				buffer[pos++] = c;
 			}
 		
-			virtual void write( const unsigned char* buffer, const int len ) throw (IOException){
+			virtual void write( const unsigned char* buffer, int len ) throw (IOException){
 				
 				if( (pos + len) > 100 ){
 					throw IOException();

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/IOTransportTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/IOTransportTest.h?view=diff&rev=487422&r1=487421&r2=487422
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/IOTransportTest.h
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/transport/IOTransportTest.h
Thu Dec 14 17:47:17 2006
@@ -28,7 +28,7 @@
 #include <activemq/transport/Command.h>
 #include <activemq/transport/TransportExceptionListener.h>
 #include <activemq/concurrent/Concurrent.h>
-#include <activemq/io/ByteArrayInputStream.h>
+#include <activemq/io/BlockingByteArrayInputStream.h>
 #include <activemq/io/ByteArrayOutputStream.h>
 #include <activemq/concurrent/Thread.h>
 #include <activemq/concurrent/Mutex.h>
@@ -200,7 +200,7 @@
         // transport without any exceptions.
         void testStartClose(){
             
-            io::ByteArrayInputStream is;
+            io::BlockingByteArrayInputStream is;
             io::ByteArrayOutputStream os;
             MyCommandListener listener;
             MyCommandReader reader;
@@ -223,7 +223,7 @@
         
         void testRead(){
             
-            io::ByteArrayInputStream is;
+            io::BlockingByteArrayInputStream is;
             io::ByteArrayOutputStream os;
             MyCommandListener listener;
             MyCommandReader reader;
@@ -259,7 +259,7 @@
         
         void testWrite(){
             
-            io::ByteArrayInputStream is;
+            io::BlockingByteArrayInputStream is;
             io::ByteArrayOutputStream os;
             MyCommandListener listener;
             MyCommandReader reader;
@@ -301,7 +301,7 @@
         
         void testException(){
             
-            io::ByteArrayInputStream is;
+            io::BlockingByteArrayInputStream is;
             io::ByteArrayOutputStream os;
             MyCommandListener listener;
             MyCommandReader reader;



Mime
View raw message