activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r504774 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/activemq/connector/openwire/marshal/ test/activemq/connector/openwire/marshal/
Date Thu, 08 Feb 2007 03:12:28 GMT
Author: nmittler
Date: Wed Feb  7 19:12:27 2007
New Revision: 504774

URL: http://svn.apache.org/viewvc?view=rev&rev=504774
Log:
[AMQCPP-30] Adding first test for BaseDataStreamMarshaller

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/marshal/BaseDataStreamMarshallerTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/marshal/BaseDataStreamMarshallerTest.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.cpp?view=diff&rev=504774&r1=504773&r2=504774
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/connector/openwire/marshal/BaseDataStreamMarshaller.cpp
Wed Feb  7 19:12:27 2007
@@ -303,7 +303,7 @@
         dataOut->writeBoolean( value != "" );
         if( value != "" )
         {
-            dataOut->writeBytes( value );
+            dataOut->writeUTF( value );
         }
     }
     AMQ_CATCH_RETHROW( IOException )
@@ -317,7 +317,7 @@
         
     try{
         if( dataIn->readBoolean() ) {
-            return dataIn->readUTF();   // TODO
+            return dataIn->readUTF();
         } else {
             return "";
         }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/marshal/BaseDataStreamMarshallerTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/marshal/BaseDataStreamMarshallerTest.cpp?view=diff&rev=504774&r1=504773&r2=504774
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/marshal/BaseDataStreamMarshallerTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/marshal/BaseDataStreamMarshallerTest.cpp
Wed Feb  7 19:12:27 2007
@@ -21,6 +21,12 @@
 
 #include <activemq/util/PrimitiveMap.h>
 #include <activemq/connector/openwire/marshal/BaseDataStreamMarshaller.h>
+#include <activemq/connector/openwire/OpenWireFormatFactory.h>
+#include <activemq/util/SimpleProperties.h>
+#include <activemq/io/ByteArrayOutputStream.h>
+#include <activemq/io/DataOutputStream.h>
+#include <activemq/io/ByteArrayInputStream.h>
+#include <activemq/io/DataInputStream.h>
 
 using namespace std;
 using namespace activemq;
@@ -32,6 +38,33 @@
 using namespace activemq::connector::openwire::marshal;
 
 ////////////////////////////////////////////////////////////////////////////////
-void BaseDataStreamMarshallerTest::test()
-{
+void BaseDataStreamMarshallerTest::testLooseMarshal()
+{   
+    SimpleProperties props;
+    OpenWireFormat openWireFormat(props);
+    SimpleDataStructureMarshaller dsm;
+
+    // Marshal the dataStructure to a byte array.
+    ByteArrayOutputStream baos;
+    DataOutputStream looseOut( &baos );
+    looseOut.writeByte( dataStructure.getDataStructureType() );    
+    dsm.looseMarshal( &openWireFormat, &dataStructure, &looseOut );
+    
+    // Now read it back in and make sure it's all right.
+    SimpleDataStructure ds;
+    ByteArrayInputStream bais( baos.getByteArray(), baos.getByteArraySize() );
+    DataInputStream looseIn( &bais );
+    
+    unsigned char dataType = looseIn.readByte();
+    CPPUNIT_ASSERT( dataType == dataStructure.getDataStructureType() );
+
+    dsm.looseUnmarshal( &openWireFormat, &ds, &looseIn );
+    
+    CPPUNIT_ASSERT( ds.boolValue == dataStructure.boolValue );
+    CPPUNIT_ASSERT( ds.charValue == dataStructure.charValue );
+    CPPUNIT_ASSERT( ds.shortValue == dataStructure.shortValue );
+    CPPUNIT_ASSERT( ds.intValue == dataStructure.intValue );
+    CPPUNIT_ASSERT( ds.floatValue == dataStructure.floatValue );
+    CPPUNIT_ASSERT( ds.doubleValue == dataStructure.doubleValue );
+    CPPUNIT_ASSERT( ds.stringValue == dataStructure.stringValue );
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/marshal/BaseDataStreamMarshallerTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/marshal/BaseDataStreamMarshallerTest.h?view=diff&rev=504774&r1=504773&r2=504774
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/marshal/BaseDataStreamMarshallerTest.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/marshal/BaseDataStreamMarshallerTest.h
Wed Feb  7 19:12:27 2007
@@ -21,6 +21,9 @@
 #include <cppunit/TestFixture.h>
 #include <cppunit/extensions/HelperMacros.h>
 
+#include <activemq/connector/openwire/marshal/BaseDataStreamMarshaller.h>
+#include <activemq/connector/openwire/commands/DataStructure.h>
+
 namespace activemq{
 namespace connector{
 namespace openwire{
@@ -29,15 +32,185 @@
     class BaseDataStreamMarshallerTest : public CppUnit::TestFixture {
         
         CPPUNIT_TEST_SUITE( BaseDataStreamMarshallerTest );
-        CPPUNIT_TEST( test );
-        CPPUNIT_TEST_SUITE_END();
+        CPPUNIT_TEST( testLooseMarshal );
+        CPPUNIT_TEST_SUITE_END();                 
+        
+    public:
+    
+        class SimpleDataStructure : public commands::BaseDataStructure {
+            
+        public:
+        
+            bool boolValue;
+            char charValue;
+            short shortValue;
+            int intValue;
+            long long longValue;
+            float floatValue;
+            double doubleValue;
+            std::string stringValue;
+                        
+        public:
+        
+            const static unsigned char TYPE = 0xFF;
+            
+            virtual ~SimpleDataStructure(){}
+            
+            virtual unsigned char getDataStructureType() const {
+                return TYPE;
+            }
+            
+            virtual DataStructure* cloneDataStructure() const {
+                SimpleDataStructure* s = new SimpleDataStructure();
+                s->copyDataStructure( this );
+                return s;
+            }
+
+            virtual void copyDataStructure( const DataStructure* src ){
+                const SimpleDataStructure* srcObj = dynamic_cast<const SimpleDataStructure*>(src);
+                if( srcObj == NULL ){
+                    return;
+                }
+                boolValue = srcObj->boolValue;
+                charValue = srcObj->charValue;
+                shortValue = srcObj->shortValue;
+                intValue = srcObj->intValue;
+                longValue = srcObj->longValue;
+                floatValue = srcObj->floatValue;
+                doubleValue = srcObj->doubleValue;
+                stringValue = srcObj->stringValue;
+            }
+        };
+        
+        class SimpleDataStructureMarshaller : public BaseDataStreamMarshaller{
+        public:
+        
+            virtual ~SimpleDataStructureMarshaller(){}
+         
+            virtual commands::DataStructure* createObject() const {
+                return new SimpleDataStructure();
+            }
+            
+            virtual unsigned char getDataStructureType() const {
+                return SimpleDataStructure::TYPE;
+            }
+            
+            virtual void tightUnmarshal( OpenWireFormat* wireFormat,
+                                     commands::DataStructure* dataStructure,
+                                     io::DataInputStream* dataIn,
+                                     utils::BooleanStream* bs ) throw( io::IOException )

+             {
+                BaseDataStreamMarshaller::tightUnmarshal( wireFormat, dataStructure, dataIn,
bs );
+
+                SimpleDataStructure* info =
+                    dynamic_cast<SimpleDataStructure*>( dataStructure );
+                    
+                info->boolValue = bs->readBoolean();
+                info->charValue = dataIn->readChar();
+                info->shortValue = dataIn->readShort();
+                info->intValue = dataIn->readInt();
+                info->longValue = tightUnmarshalLong( wireFormat, dataIn, bs );
+                info->floatValue = dataIn->readFloat();
+                info->doubleValue = dataIn->readDouble();
+                info->stringValue = tightUnmarshalString( dataIn, bs );
+             }
+
+            virtual int tightMarshal1( OpenWireFormat* wireFormat,
+                                       commands::DataStructure* dataStructure,
+                                       utils::BooleanStream* bs ) throw( io::IOException
)
+            {
+                SimpleDataStructure* info =
+                    dynamic_cast<SimpleDataStructure*>( dataStructure );
+            
+                int rc = BaseDataStreamMarshaller::tightMarshal1( wireFormat, dataStructure,
bs );
+                bs->writeBoolean( info->boolValue );
+                rc += tightMarshalLong1( wireFormat, info->longValue, bs );
+                rc += tightMarshalString1( info->stringValue, bs );
+            
+                return 19 + rc;
+            }
+    
+            virtual void tightMarshal2( OpenWireFormat* wireFormat,
+                                        commands::DataStructure* dataStructure,
+                                        io::DataOutputStream* dataOut,
+                                        utils::BooleanStream* bs ) throw( io::IOException
)
+            {
+                BaseDataStreamMarshaller::tightMarshal2( wireFormat, dataStructure, dataOut,
bs );
+
+                SimpleDataStructure* info =
+                    dynamic_cast<SimpleDataStructure*>( dataStructure );
+                    
+                bs->readBoolean();
+                dataOut->writeChar( info->charValue );
+                dataOut->writeShort( info->shortValue );
+                dataOut->writeInt( info->intValue );                
+                tightMarshalLong2(wireFormat, info->longValue, dataOut, bs);
+                dataOut->writeFloat( info->floatValue );
+                dataOut->writeDouble( info->doubleValue );
+                tightMarshalString2( info->stringValue, dataOut, bs );
+                
+            }
+    
+            virtual void looseUnmarshal( OpenWireFormat* wireFormat,
+                                         commands::DataStructure* dataStructure,
+                                         io::DataInputStream* dataIn ) throw( io::IOException
)
+            {
+                BaseDataStreamMarshaller::looseUnmarshal( wireFormat, dataStructure, dataIn
);
+                SimpleDataStructure* info =
+                    dynamic_cast<SimpleDataStructure*>( dataStructure );
+                    
+                info->boolValue = dataIn->readBoolean();
+                info->charValue = dataIn->readChar();
+                info->shortValue = dataIn->readShort();
+                info->intValue = dataIn->readInt();
+                info->longValue = looseUnmarshalLong( wireFormat, dataIn );
+                info->floatValue = dataIn->readFloat();
+                info->doubleValue = dataIn->readDouble();
+                info->stringValue = looseUnmarshalString( dataIn );
+            }
+    
+            virtual void looseMarshal( OpenWireFormat* wireFormat,
+                                       commands::DataStructure* dataStructure,
+                                       io::DataOutputStream* dataOut ) throw( io::IOException
)
+            {
+                SimpleDataStructure* info =
+                    dynamic_cast<SimpleDataStructure*>( dataStructure );
+                BaseDataStreamMarshaller::looseMarshal( wireFormat, dataStructure, dataOut
);
+    
+                dataOut->writeBoolean( info->boolValue );
+                dataOut->writeChar( info->charValue );
+                dataOut->writeShort( info->shortValue );
+                dataOut->writeInt( info->intValue );
+                looseMarshalLong( wireFormat, info->longValue, dataOut );
+                dataOut->writeFloat( info->floatValue );
+                dataOut->writeDouble( info->doubleValue );
+                looseMarshalString( info->stringValue, dataOut );
+            }
+        };
+        
+    private:
+    
+        SimpleDataStructure dataStructure;
 
     public:
     
         BaseDataStreamMarshallerTest() {}
         virtual ~BaseDataStreamMarshallerTest() {}
+        
+        virtual void setUp(){
+            dataStructure.boolValue = true;
+            dataStructure.charValue = 'a';
+            dataStructure.shortValue = 1000;
+            dataStructure.intValue = 100000;
+            dataStructure.longValue = 1000000;
+            dataStructure.floatValue = 10.3f;
+            dataStructure.doubleValue = 20.1;
+            dataStructure.stringValue = "hello world";
+        } 
+        virtual void tearDown(){
+        }
     
-        void test();
+        void testLooseMarshal();
         
     };
 



Mime
View raw message