activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r587158 - in /activemq/activemq-cpp/trunk/src/test/activemq/connector/openwire/marshal/v2: BrokerIdMarshallerTest.cpp BrokerIdMarshallerTest.h
Date Mon, 22 Oct 2007 17:14:23 GMT
Author: tabish
Date: Mon Oct 22 10:14:22 2007
New Revision: 587158

URL: http://svn.apache.org/viewvc?rev=587158&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-142

Commiting the first auto generated unit test for marshalers.

Modified:
    activemq/activemq-cpp/trunk/src/test/activemq/connector/openwire/marshal/v2/BrokerIdMarshallerTest.cpp
    activemq/activemq-cpp/trunk/src/test/activemq/connector/openwire/marshal/v2/BrokerIdMarshallerTest.h

Modified: activemq/activemq-cpp/trunk/src/test/activemq/connector/openwire/marshal/v2/BrokerIdMarshallerTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/connector/openwire/marshal/v2/BrokerIdMarshallerTest.cpp?rev=587158&r1=587157&r2=587158&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/connector/openwire/marshal/v2/BrokerIdMarshallerTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/src/test/activemq/connector/openwire/marshal/v2/BrokerIdMarshallerTest.cpp
Mon Oct 22 10:14:22 2007
@@ -6,7 +6,7 @@
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -14,32 +14,139 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
-#include "BrokerIdMarshallerTest.h"
 
-CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::openwire::marshal::v2::BrokerIdMarshallerTest
);
+#include <activemq/connector/openwire/marshal/v2/BrokerIdMarshallerTest.h>
 
-#include <activemq/util/PrimitiveMap.h>
 #include <activemq/connector/openwire/marshal/v2/BrokerIdMarshaller.h>
 #include <activemq/connector/openwire/commands/BrokerId.h>
 
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::openwire::marshal::v2::BrokerIdMarshallerTest
);
+
+#include <activemq/io/DataInputStream.h>
+#include <activemq/io/DataOutputStream.h>
+#include <activemq/io/IOException.h>
+#include <activemq/connector/openwire/OpenWireFormat.h>
+#include <activemq/connector/openwire/commands/DataStructure.h>
+#include <activemq/connector/openwire/utils/BooleanStream.h>
+#include <activemq/io/ByteArrayOutputStream.h>
+#include <activemq/io/ByteArrayInputStream.h>
+#include <activemq/util/Properties.h>
+//
+//     NOTE!: This file is autogenerated - do not modify!
+//            if you need to make a change, please see the Java Classes in the
+//            activemq-core module
+//
+
 using namespace std;
 using namespace activemq;
-using namespace activemq::util;
 using namespace activemq::io;
+using namespace activemq::util;
 using namespace activemq::exceptions;
 using namespace activemq::connector;
 using namespace activemq::connector::openwire;
 using namespace activemq::connector::openwire::commands;
 using namespace activemq::connector::openwire::marshal;
+using namespace activemq::connector::openwire::utils;
 using namespace activemq::connector::openwire::marshal::v2;
 
-////////////////////////////////////////////////////////////////////////////////
-void BrokerIdMarshallerTest::test()
-{
+///////////////////////////////////////////////////////////////////////////////
+void BrokerIdMarshallerTest::test() {
+
     BrokerIdMarshaller myMarshaller;
-    BrokerId myCommand;    
-    unsigned char type = myMarshaller.getDataStructureType();
-    
-    CPPUNIT_ASSERT( type == myCommand.getDataStructureType() );
+    BrokerId myCommand;
+    BrokerId* myCommand2;
+
+    CPPUNIT_ASSERT( myMarshaller.getDataStructureType() == myCommand.getDataStructureType()
);
+    myCommand2 = dynamic_cast<BrokerId*>( myMarshaller.createObject() );
+    CPPUNIT_ASSERT( myCommand2 != NULL );
+    delete myCommand2;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void BrokerIdMarshallerTest::testLooseMarshal() {
+
+    BrokerIdMarshaller marshaller;
+    Properties props;
+    OpenWireFormat openWireFormat( props );
+
+    // Configure for this test.
+    openWireFormat.setVersion( 2 );
+    openWireFormat.setTightEncodingEnabled( false );
+
+    BrokerId outCommand;
+    BrokerId inCommand;
+
+    try {
+
+        // Marshal the dataStructure to a byte array.
+        ByteArrayOutputStream baos;
+        DataOutputStream dataOut( &baos );
+        dataOut.writeByte( outCommand.getDataStructureType() );
+        marshaller.looseMarshal( &openWireFormat, &outCommand, &dataOut );
+
+        // 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 == outCommand.getDataStructureType() );
+        marshaller.looseUnmarshal( &openWireFormat, &inCommand, &dataIn );
+
+        CPPUNIT_ASSERT( inCommand.equals( &outCommand ) == true );
+
+    } catch( ActiveMQException& e ) {
+        e.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    } catch( ... ) {
+        CPPUNIT_ASSERT( false );
+    }
 }
+
+///////////////////////////////////////////////////////////////////////////////
+void BrokerIdMarshallerTest::testTightMarshal() {
+
+    BrokerIdMarshaller marshaller;
+    Properties props;
+    OpenWireFormat openWireFormat( props );
+
+    // Configure for this test.
+    openWireFormat.setVersion( 2 );
+    openWireFormat.setTightEncodingEnabled( true );
+
+    BrokerId outCommand;
+    BrokerId inCommand;
+
+    try {
+
+        // Marshal the dataStructure to a byte array.
+        ByteArrayOutputStream baos;
+        DataOutputStream dataOut( &baos );
+        // Phase 1 - count the size
+        int size = 1;
+        BooleanStream bs;
+        size += marshaller.tightMarshal1( &openWireFormat, &outCommand, &bs );
+        size += bs.marshalledSize();
+        // Phase 2 - marshal
+        dataOut.writeByte( outCommand.getDataStructureType() );
+        bs.marshal( &dataOut );
+        marshaller.tightMarshal2( &openWireFormat, &outCommand, &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 == outCommand.getDataStructureType() );
+        bs.clear();
+        bs.unmarshal( &dataIn );
+        marshaller.tightUnmarshal( &openWireFormat, &inCommand, &dataIn, &bs
);
+
+        CPPUNIT_ASSERT( inCommand.equals( &outCommand ) == true );
+
+    } catch( ActiveMQException& e ) {
+        e.printStackTrace();
+        CPPUNIT_ASSERT( false );
+    } catch( ... ) {
+        CPPUNIT_ASSERT( false );
+    }
+}
+

Modified: activemq/activemq-cpp/trunk/src/test/activemq/connector/openwire/marshal/v2/BrokerIdMarshallerTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/activemq/connector/openwire/marshal/v2/BrokerIdMarshallerTest.h?rev=587158&r1=587157&r2=587158&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/activemq/connector/openwire/marshal/v2/BrokerIdMarshallerTest.h
(original)
+++ activemq/activemq-cpp/trunk/src/test/activemq/connector/openwire/marshal/v2/BrokerIdMarshallerTest.h
Mon Oct 22 10:14:22 2007
@@ -6,7 +6,7 @@
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,8 +15,13 @@
  * limitations under the License.
  */
 
-#ifndef _ACTIVEMQ_CONNECTOR_OPENWIRE_MARSHAL_V2_BROKERIDMARSHALLERTEST_H_
-#define _ACTIVEMQ_CONNECTOR_OPENWIRE_MARSHAL_V2_BROKERIDMARSHALLERTEST_H_
+#ifndef _ACTIVEMQ_CONNECTOR_OPENWIRE_MARSAHAL_V2_BROKERIDMARSHALLERTEST_H_
+#define _ACTIVEMQ_CONNECTOR_OPENWIRE_MARSAHAL_V2_BROKERIDMARSHALLERTEST_H_
+
+// Turn off warning message for ignored exception specification
+#ifdef _MSC_VER
+#pragma warning( disable : 4290 )
+#endif
 
 #include <cppunit/TestFixture.h>
 #include <cppunit/extensions/HelperMacros.h>
@@ -27,20 +32,36 @@
 namespace marshal{
 namespace v2{
 
+    /**
+     * Marshalling Test code for Open Wire Format for BrokerIdMarshallerTest
+     *
+     *  NOTE!: This file is autogenerated - do not modify!
+     *         if you need to make a change, please see the Java Classes
+     *         in the activemq-openwire-generator module
+     */
     class BrokerIdMarshallerTest : public CppUnit::TestFixture {
-        
+
         CPPUNIT_TEST_SUITE( BrokerIdMarshallerTest );
         CPPUNIT_TEST( test );
+        CPPUNIT_TEST( testLooseMarshal );
+        CPPUNIT_TEST( testTightMarshal );
         CPPUNIT_TEST_SUITE_END();
-        
+
     public:
-    
+
         BrokerIdMarshallerTest() {}
         virtual ~BrokerIdMarshallerTest() {}
-        
+
+        /**
+         * Test the marshaller and its marshalled type.
+         */
         virtual void test();
+        virtual void testLooseMarshal();
+        virtual void testTightMarshal();
+
     };
 
 }}}}}
 
-#endif /*_ACTIVEMQ_CONNECTOR_OPENWIRE_MARSHAL_V2_BROKERIDMARSHALLERTEST_H_*/
+#endif /*_ACTIVEMQ_CONNECTOR_OPENWIRE_MARSAHAL_V2_BROKERIDMARSHALLERTEST_H_*/
+



Mime
View raw message