activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r505132 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/activemq/connector/openwire/marshal/ test/activemq/connector/openwire/marshal/
Date Fri, 09 Feb 2007 02:02:22 GMT
Author: nmittler
Date: Thu Feb  8 18:02:22 2007
New Revision: 505132

URL: http://svn.apache.org/viewvc?view=rev&rev=505132
Log:
[AMQCPP-30] Added test for tightMarhshalling to BaseDataStreamMarshallerTest.  Also worked
out some kinks in 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=505132&r1=505131&r2=505132
==============================================================================
--- 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
Thu Feb  8 18:02:22 2007
@@ -219,7 +219,7 @@
                                                     throw ( io::IOException ) {
     try{
         
-        bs->writeBoolean( value == "" );
+        bs->writeBoolean( value != "" );
         if( value != "" )
         {
             size_t strlen = value.length();
@@ -255,6 +255,7 @@
             }
             
             bs->writeBoolean( isOnlyAscii );
+            
             return utflen + 2;
         }
         else
@@ -279,10 +280,8 @@
 
             // If we verified it only holds ascii values
             if( bs->readBoolean() ) {
-
                 dataOut->writeShort( (short)value.length() );
                 dataOut->writeBytes( value );
-
             } else {
                 dataOut->writeChars( value );
             }
@@ -829,7 +828,7 @@
         // Now build a string and copy data into it.
         std::string text;
         text.resize( size );
-        text.assign( (char*)data, (int)size );
+        text.assign( (char*)data, (int)size-1 );
         delete data;
         
         return text; 

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=505132&r1=505131&r2=505132
==============================================================================
--- 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 18:02:22 2007
@@ -22,6 +22,7 @@
 #include <activemq/util/PrimitiveMap.h>
 #include <activemq/connector/openwire/marshal/BaseDataStreamMarshaller.h>
 #include <activemq/connector/openwire/OpenWireFormatFactory.h>
+#include <activemq/connector/openwire/utils/BooleanStream.h>
 #include <activemq/util/SimpleProperties.h>
 #include <activemq/io/ByteArrayOutputStream.h>
 #include <activemq/io/DataOutputStream.h>
@@ -35,23 +36,24 @@
 using namespace activemq::exceptions;
 using namespace activemq::connector;
 using namespace activemq::connector::openwire;
+using namespace activemq::connector::openwire::utils;
 using namespace activemq::connector::openwire::marshal;
 
 ////////////////////////////////////////////////////////////////////////////////
 void BaseDataStreamMarshallerTest::testLooseMarshal()
 {   
-    SimpleDataStructureMarshaller simpleMarshaller;
-    ComplexDataStructureMarshaller complexMarshaller;
+    SimpleDataStructureMarshaller* simpleMarshaller = new SimpleDataStructureMarshaller();
+    ComplexDataStructureMarshaller* complexMarshaller = new ComplexDataStructureMarshaller();
     SimpleProperties props;    
     OpenWireFormat openWireFormat(props);
-    openWireFormat.addMarshaller( &simpleMarshaller );
-    openWireFormat.addMarshaller( &complexMarshaller );
+    openWireFormat.addMarshaller( simpleMarshaller );
+    openWireFormat.addMarshaller( complexMarshaller );
 
     // Marshal the dataStructure to a byte array.
     ByteArrayOutputStream baos;
     DataOutputStream looseOut( &baos );
     looseOut.writeByte( dataStructure->getDataStructureType() );    
-    complexMarshaller.looseMarshal( &openWireFormat, dataStructure, &looseOut );
+    complexMarshaller->looseMarshal( &openWireFormat, dataStructure, &looseOut
);
     
     // Now read it back in and make sure it's all right.
     ByteArrayInputStream bais( baos.getByteArray(), baos.getByteArraySize() );
@@ -61,7 +63,7 @@
     CPPUNIT_ASSERT( dataType == dataStructure->getDataStructureType() );
 
     ComplexDataStructure ds;
-    complexMarshaller.looseUnmarshal( &openWireFormat, &ds, &looseIn );
+    complexMarshaller->looseUnmarshal( &openWireFormat, &ds, &looseIn );
     
     CPPUNIT_ASSERT( ds.boolValue == dataStructure->boolValue );
     CPPUNIT_ASSERT( ds.cachedChild != NULL );
@@ -73,3 +75,55 @@
     CPPUNIT_ASSERT( ds.cachedChild->doubleValue == dataStructure->cachedChild->doubleValue
);
     CPPUNIT_ASSERT( ds.cachedChild->stringValue == dataStructure->cachedChild->stringValue
);
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void BaseDataStreamMarshallerTest::testTightMarshal()
+{   
+    SimpleDataStructureMarshaller* simpleMarshaller = new SimpleDataStructureMarshaller();
+    ComplexDataStructureMarshaller* complexMarshaller = new ComplexDataStructureMarshaller();
+    SimpleProperties props;    
+    OpenWireFormat openWireFormat(props);
+    openWireFormat.addMarshaller( simpleMarshaller );
+    openWireFormat.addMarshaller( complexMarshaller );
+
+    // Marshal the dataStructure to a byte array.
+    ByteArrayOutputStream baos;
+    DataOutputStream dataOut( &baos );
+    
+    // Phase 1 - count the size
+    int size = 1;
+    BooleanStream bs;
+    size += complexMarshaller->tightMarshal1( &openWireFormat, dataStructure, &bs
);
+    size += bs.marshalledSize();
+    
+    // Phase 2 - marshal
+    dataOut.writeByte( dataStructure->getDataStructureType() );
+    bs.marshal( &dataOut );
+    complexMarshaller->tightMarshal2( &openWireFormat, dataStructure, &dataOut,
&bs );
+    
+    
+    // Now read it back in and make sure it's all right.
+    ByteArrayInputStream bais( baos.getByteArray(), baos.getByteArraySize() );
+    DataInputStream dataIn( &bais );
+    
+    unsigned char dataType = dataIn.readByte();
+    CPPUNIT_ASSERT( dataType == dataStructure->getDataStructureType() );
+
+    ComplexDataStructure ds;
+    bs.clear();
+    bs.unmarshal( &dataIn );
+    complexMarshaller->tightUnmarshal( &openWireFormat, &ds, &dataIn, &bs
);
+    
+    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
);
+    printf("string1[%s,%d] string2[%s,%d]\n",ds.cachedChild->stringValue.c_str(), (int)ds.cachedChild->stringValue.size(),
dataStructure->cachedChild->stringValue.c_str(), dataStructure->cachedChild->stringValue.size()
);
+    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=505132&r1=505131&r2=505132
==============================================================================
--- 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 18:02:22 2007
@@ -33,6 +33,7 @@
         
         CPPUNIT_TEST_SUITE( BaseDataStreamMarshallerTest );
         CPPUNIT_TEST( testLooseMarshal );
+        CPPUNIT_TEST( testTightMarshal );
         CPPUNIT_TEST_SUITE_END();                 
         
     public:
@@ -360,6 +361,7 @@
         }
     
         void testLooseMarshal();
+        void testTightMarshal();
         
     };
 



Mime
View raw message