activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r505088 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/openwire/marshal: BaseDataStreamMarshallerTest.cpp BaseDataStreamMarshallerTest.h
Date Thu, 08 Feb 2007 23:43:37 GMT
Author: nmittler
Date: Thu Feb  8 15:43:36 2007
New Revision: 505088

URL: http://svn.apache.org/viewvc?view=rev&rev=505088
Log:
[AMQCPP-30] Updating test for BaseDataStreamMarshaller to add test for nested objects with
loose marshalling

Modified:
    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/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=505088&r1=505087&r2=505088
==============================================================================
--- 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
Thu Feb  8 15:43:36 2007
@@ -40,31 +40,36 @@
 ////////////////////////////////////////////////////////////////////////////////
 void BaseDataStreamMarshallerTest::testLooseMarshal()
 {   
-    SimpleProperties props;
+    SimpleDataStructureMarshaller simpleMarshaller;
+    ComplexDataStructureMarshaller complexMarshaller;
+    SimpleProperties props;    
     OpenWireFormat openWireFormat(props);
-    SimpleDataStructureMarshaller dsm;
+    openWireFormat.addMarshaller( &simpleMarshaller );
+    openWireFormat.addMarshaller( &complexMarshaller );
 
     // Marshal the dataStructure to a byte array.
     ByteArrayOutputStream baos;
     DataOutputStream looseOut( &baos );
-    looseOut.writeByte( dataStructure.getDataStructureType() );    
-    dsm.looseMarshal( &openWireFormat, &dataStructure, &looseOut );
+    looseOut.writeByte( dataStructure->getDataStructureType() );    
+    complexMarshaller.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() );
+    CPPUNIT_ASSERT( dataType == dataStructure->getDataStructureType() );
 
-    dsm.looseUnmarshal( &openWireFormat, &ds, &looseIn );
+    ComplexDataStructure ds;
+    complexMarshaller.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 );
+    CPPUNIT_ASSERT( ds.boolValue == dataStructure->boolValue );
+    CPPUNIT_ASSERT( ds.cachedChild != NULL );
+    CPPUNIT_ASSERT( ds.cachedChild->boolValue == dataStructure->cachedChild->boolValue
);
+    CPPUNIT_ASSERT( ds.cachedChild->charValue == dataStructure->cachedChild->charValue
);
+    CPPUNIT_ASSERT( ds.cachedChild->shortValue == dataStructure->cachedChild->shortValue
);
+    CPPUNIT_ASSERT( ds.cachedChild->intValue == dataStructure->cachedChild->intValue
);
+    CPPUNIT_ASSERT( ds.cachedChild->floatValue == dataStructure->cachedChild->floatValue
);
+    CPPUNIT_ASSERT( ds.cachedChild->doubleValue == dataStructure->cachedChild->doubleValue
);
+    CPPUNIT_ASSERT( ds.cachedChild->stringValue == dataStructure->cachedChild->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=505088&r1=505087&r2=505088
==============================================================================
--- 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
Thu Feb  8 15:43:36 2007
@@ -188,9 +188,149 @@
             }
         };
         
+        class ComplexDataStructure : public commands::BaseDataStructure {
+            
+        public:
+        
+            bool boolValue;
+            SimpleDataStructure* cachedChild;
+                        
+        public:
+        
+            const static unsigned char TYPE = 0xFE;
+            
+            ComplexDataStructure(){
+                cachedChild = NULL;
+            }
+            virtual ~ComplexDataStructure(){
+                setCachedChild( NULL );
+            }
+            
+            void setCachedChild( SimpleDataStructure* child ) {
+                if( cachedChild != NULL ) {
+                    delete cachedChild;
+                    cachedChild = NULL;
+                }
+                
+                if( child != NULL ) {
+                    cachedChild = child;
+                }
+            }
+            
+            virtual unsigned char getDataStructureType() const {
+                return TYPE;
+            }
+            
+            virtual DataStructure* cloneDataStructure() const {
+                ComplexDataStructure* s = new ComplexDataStructure();
+                s->copyDataStructure( this );
+                return s;
+            }
+
+            virtual void copyDataStructure( const DataStructure* src ){
+                const ComplexDataStructure* srcObj = dynamic_cast<const ComplexDataStructure*>(src);
+                if( srcObj == NULL ){
+                    return;
+                }
+                boolValue = srcObj->boolValue;
+                
+                if( cachedChild != NULL ) {
+                    delete cachedChild;
+                    cachedChild = NULL;
+                }
+                
+                if( srcObj->cachedChild != NULL ) {
+                    cachedChild = dynamic_cast<SimpleDataStructure*>(srcObj->cachedChild->cloneDataStructure());
+                }             
+            }
+        };
+        
+        class ComplexDataStructureMarshaller : public BaseDataStreamMarshaller{
+        public:
+        
+            virtual ~ComplexDataStructureMarshaller(){}
+         
+            virtual commands::DataStructure* createObject() const {
+                return new ComplexDataStructure();
+            }
+            
+            virtual unsigned char getDataStructureType() const {
+                return ComplexDataStructure::TYPE;
+            }
+            
+            virtual void tightUnmarshal( OpenWireFormat* wireFormat,
+                                     commands::DataStructure* dataStructure,
+                                     io::DataInputStream* dataIn,
+                                     utils::BooleanStream* bs ) throw( io::IOException )

+             {
+                BaseDataStreamMarshaller::tightUnmarshal( wireFormat, dataStructure, dataIn,
bs );
+
+                ComplexDataStructure* info =
+                    dynamic_cast<ComplexDataStructure*>( dataStructure );
+                    
+                info->boolValue = bs->readBoolean();
+                info->setCachedChild( dynamic_cast< SimpleDataStructure* >(
+                    tightUnmarshalCachedObject( wireFormat, dataIn, bs ) ) );
+             }
+
+            virtual int tightMarshal1( OpenWireFormat* wireFormat,
+                                       commands::DataStructure* dataStructure,
+                                       utils::BooleanStream* bs ) throw( io::IOException
)
+            {
+                ComplexDataStructure* info =
+                    dynamic_cast<ComplexDataStructure*>( dataStructure );
+            
+                int rc = BaseDataStreamMarshaller::tightMarshal1( wireFormat, dataStructure,
bs );
+                bs->writeBoolean( info->boolValue );
+                rc += tightMarshalCachedObject1( wireFormat, info->cachedChild, bs );
+            
+                return rc;
+            }
+    
+            virtual void tightMarshal2( OpenWireFormat* wireFormat,
+                                        commands::DataStructure* dataStructure,
+                                        io::DataOutputStream* dataOut,
+                                        utils::BooleanStream* bs ) throw( io::IOException
)
+            {
+                BaseDataStreamMarshaller::tightMarshal2( wireFormat, dataStructure, dataOut,
bs );
+
+                ComplexDataStructure* info =
+                    dynamic_cast<ComplexDataStructure*>( dataStructure );
+                    
+                bs->readBoolean();
+                tightMarshalCachedObject2( wireFormat, info->cachedChild, dataOut, bs
);
+                
+            }
+    
+            virtual void looseUnmarshal( OpenWireFormat* wireFormat,
+                                         commands::DataStructure* dataStructure,
+                                         io::DataInputStream* dataIn ) throw( io::IOException
)
+            {
+                BaseDataStreamMarshaller::looseUnmarshal( wireFormat, dataStructure, dataIn
);
+                ComplexDataStructure* info =
+                    dynamic_cast<ComplexDataStructure*>( dataStructure );
+                    
+                info->boolValue = dataIn->readBoolean();
+                info->setCachedChild( dynamic_cast< SimpleDataStructure* >( 
+                    looseUnmarshalCachedObject( wireFormat, dataIn ) ) );
+            }
+    
+            virtual void looseMarshal( OpenWireFormat* wireFormat,
+                                       commands::DataStructure* dataStructure,
+                                       io::DataOutputStream* dataOut ) throw( io::IOException
)
+            {
+                ComplexDataStructure* info =
+                    dynamic_cast<ComplexDataStructure*>( dataStructure );
+                BaseDataStreamMarshaller::looseMarshal( wireFormat, dataStructure, dataOut
);
+    
+                dataOut->writeBoolean( info->boolValue );
+                looseMarshalCachedObject( wireFormat, info->cachedChild, dataOut );
+            }
+        };
+        
     private:
     
-        SimpleDataStructure dataStructure;
+        ComplexDataStructure* dataStructure;
 
     public:
     
@@ -198,16 +338,25 @@
         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";
+            dataStructure = new ComplexDataStructure();
+            dataStructure->boolValue = true;
+            dataStructure->setCachedChild( new SimpleDataStructure() );
+            dataStructure->cachedChild->boolValue = true;
+            dataStructure->cachedChild->charValue = 'a';
+            dataStructure->cachedChild->shortValue = 1000;
+            dataStructure->cachedChild->intValue = 100000;
+            dataStructure->cachedChild->longValue = 1000000;
+            dataStructure->cachedChild->floatValue = 10.3f;
+            dataStructure->cachedChild->doubleValue = 20.1;
+            dataStructure->cachedChild->stringValue = "hello world";
         } 
+        
         virtual void tearDown(){
+            
+            if( dataStructure != NULL ) {
+                delete dataStructure;
+                dataStructure = NULL;
+            }
         }
     
         void testLooseMarshal();



Mime
View raw message