activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r587160 - in /activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool: AmqCppGeneratorTask.java AmqCppTestMarshallingClassesGenerator.java AmqCppTestMarshallingHeadersGenerator.java
Date Mon, 22 Oct 2007 17:16:25 GMT
Author: tabish
Date: Mon Oct 22 10:16:24 2007
New Revision: 587160

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

Updated generator code to build unit tests.

Modified:
    activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppGeneratorTask.java
    activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingClassesGenerator.java
    activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingHeadersGenerator.java

Modified: activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppGeneratorTask.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppGeneratorTask.java?rev=587160&r1=587159&r2=587160&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppGeneratorTask.java
(original)
+++ activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppGeneratorTask.java
Mon Oct 22 10:16:24 2007
@@ -79,28 +79,28 @@
                 script.setJam(jam);
                 script.setTargetDir(target+"/src/main");
                 script.setOpenwireVersion(version);
-                script.run();
+//                script.run();
             }
             {
                 AmqCppHeadersGenerator script = new AmqCppHeadersGenerator();
                 script.setJam(jam);
                 script.setTargetDir(target+"/src/main");
                 script.setOpenwireVersion(version);
-                script.run();
+//                script.run();
             }
             {
                 AmqCppMarshallingHeadersGenerator script = new AmqCppMarshallingHeadersGenerator();
                 script.setJam(jam);
                 script.setTargetDir(target+"/src/main");
                 script.setOpenwireVersion(version);
-                script.run();
+//                script.run();
             }
             {
                 AmqCppMarshallingClassesGenerator script = new AmqCppMarshallingClassesGenerator();
                 script.setJam(jam);
                 script.setTargetDir(target+"/src/main");
                 script.setOpenwireVersion(version);
-                script.run();
+//                script.run();
             }
             {
                 AmqCppTestMarshallingHeadersGenerator script = new AmqCppTestMarshallingHeadersGenerator();

Modified: activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingClassesGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingClassesGenerator.java?rev=587160&r1=587159&r2=587160&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingClassesGenerator.java
(original)
+++ activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingClassesGenerator.java
Mon Oct 22 10:16:24 2007
@@ -42,11 +42,10 @@
     protected void generateFile(PrintWriter out) throws Exception {
         generateLicence(out);
 
-        String target = super.getClassName();
-
 out.println("");
 out.println("#include <activemq/connector/openwire/marshal/v"+getOpenwireVersion()+"/"+className+".h>");
 out.println("");
+out.println("#include <activemq/connector/openwire/marshal/v"+getOpenwireVersion()+"/"+super.getTargetClassName(jclass)+".h>");
 out.println("#include <activemq/connector/openwire/commands/"+jclass.getSimpleName()+".h>");
 out.println("");
 out.println("CPPUNIT_TEST_SUITE_REGISTRATION( activemq::connector::openwire::marshal::v"+getOpenwireVersion()+"::"+className+"
);");
@@ -57,6 +56,9 @@
 out.println("#include <activemq/connector/openwire/OpenWireFormat.h>");
 out.println("#include <activemq/connector/openwire/commands/DataStructure.h>");
 out.println("#include <activemq/connector/openwire/utils/BooleanStream.h>");
+out.println("#include <activemq/io/ByteArrayOutputStream.h>");
+out.println("#include <activemq/io/ByteArrayInputStream.h>");
+out.println("#include <activemq/util/Properties.h>");
 out.println("//");
 out.println("//     NOTE!: This file is autogenerated - do not modify!");
 out.println("//            if you need to make a change, please see the Java Classes in the");
@@ -66,6 +68,8 @@
 out.println("using namespace std;");
 out.println("using namespace activemq;");
 out.println("using namespace activemq::io;");
+out.println("using namespace activemq::util;");
+out.println("using namespace activemq::exceptions;");
 out.println("using namespace activemq::connector;");
 out.println("using namespace activemq::connector::openwire;");
 out.println("using namespace activemq::connector::openwire::commands;");
@@ -76,16 +80,104 @@
 out.println("///////////////////////////////////////////////////////////////////////////////");
 out.println("void "+className+"::test() {");
 out.println("");
-out.println("    "+ target + " myMarshaller;");
+out.println("    "+ super.getTargetClassName(jclass) + " myMarshaller;");
 out.println("    "+ jclass.getSimpleName() + " myCommand;");
 out.println("    "+ jclass.getSimpleName() + "* myCommand2;");
 out.println("");
 out.println("    CPPUNIT_ASSERT( myMarshaller.getDataStructureType() == myCommand.getDataStructureType()
);");
-out.println("    myCommand2 = myMarshaller.createObject();");
+out.println("    myCommand2 = dynamic_cast<"+jclass.getSimpleName()+"*>( myMarshaller.createObject()
);");
 out.println("    CPPUNIT_ASSERT( myCommand2 != NULL );");
 out.println("    delete myCommand2;");
+out.println("}");
+out.println("");
+out.println("///////////////////////////////////////////////////////////////////////////////");
+out.println("void "+className+"::testLooseMarshal() {");
+out.println("");
+out.println("    "+ super.getTargetClassName(jclass) +" marshaller;");
+out.println("    Properties props;");
+out.println("    OpenWireFormat openWireFormat( props );");
+out.println("");
+out.println("    // Configure for this test.");
+out.println("    openWireFormat.setVersion( "+getOpenwireVersion()+" );");
+out.println("    openWireFormat.setTightEncodingEnabled( false );");
+out.println("");
+out.println("    "+jclass.getSimpleName()+" outCommand;");
+out.println("    "+jclass.getSimpleName()+" inCommand;");
+out.println("");
+out.println("    try {");
+out.println("");
+out.println("        // Marshal the dataStructure to a byte array.");
+out.println("        ByteArrayOutputStream baos;");
+out.println("        DataOutputStream dataOut( &baos );");
+out.println("        dataOut.writeByte( outCommand.getDataStructureType() );");
+out.println("        marshaller.looseMarshal( &openWireFormat, &outCommand, &dataOut
);");
+out.println("");
+out.println("        // Now read it back in and make sure it's all right.");
+out.println("        ByteArrayInputStream bais( baos.getByteArray(), baos.getByteArraySize()
);");
+out.println("        DataInputStream dataIn( &bais );");
+out.println("        unsigned char dataType = dataIn.readByte();");
+out.println("        CPPUNIT_ASSERT( dataType == outCommand.getDataStructureType() );");
+out.println("        marshaller.looseUnmarshal( &openWireFormat, &inCommand, &dataIn
);");
+out.println("");
+out.println("        CPPUNIT_ASSERT( inCommand.equals( &outCommand ) == true );");
+out.println("");
+out.println("    } catch( ActiveMQException& e ) {");
+out.println("        e.printStackTrace();");
+out.println("        CPPUNIT_ASSERT( false );");
+out.println("    } catch( ... ) {");
+out.println("        CPPUNIT_ASSERT( false );");
+out.println("    }");
+out.println("}");
+out.println("");
+out.println("///////////////////////////////////////////////////////////////////////////////");
+out.println("void "+className+"::testTightMarshal() {");
 out.println("");
+out.println("    "+ super.getTargetClassName(jclass) +" marshaller;");
+out.println("    Properties props;");
+out.println("    OpenWireFormat openWireFormat( props );");
+out.println("");
+out.println("    // Configure for this test.");
+out.println("    openWireFormat.setVersion( "+getOpenwireVersion()+" );");
+out.println("    openWireFormat.setTightEncodingEnabled( true );");
+out.println("");
+out.println("    "+jclass.getSimpleName()+" outCommand;");
+out.println("    "+jclass.getSimpleName()+" inCommand;");
+out.println("");
+out.println("    try {");
+out.println("");
+out.println("        // Marshal the dataStructure to a byte array.");
+out.println("        ByteArrayOutputStream baos;");
+out.println("        DataOutputStream dataOut( &baos );");
+out.println("        // Phase 1 - count the size");
+out.println("        int size = 1;");
+out.println("        BooleanStream bs;");
+out.println("        size += marshaller.tightMarshal1( &openWireFormat, &outCommand,
&bs );");
+out.println("        size += bs.marshalledSize();");
+out.println("        // Phase 2 - marshal");
+out.println("        dataOut.writeByte( outCommand.getDataStructureType() );");
+out.println("        bs.marshal( &dataOut );");
+out.println("        marshaller.tightMarshal2( &openWireFormat, &outCommand, &dataOut,
&bs );");
+out.println("");
+out.println("        // Now read it back in and make sure it's all right.");
+out.println("        ByteArrayInputStream bais( baos.getByteArray(), baos.getByteArraySize()
);");
+out.println("        DataInputStream dataIn( &bais );");
+out.println("");
+out.println("        unsigned char dataType = dataIn.readByte();");
+out.println("        CPPUNIT_ASSERT( dataType == outCommand.getDataStructureType() );");
+out.println("        bs.clear();");
+out.println("        bs.unmarshal( &dataIn );");
+out.println("        marshaller.tightUnmarshal( &openWireFormat, &inCommand, &dataIn,
&bs );");
+out.println("");
+out.println("        CPPUNIT_ASSERT( inCommand.equals( &outCommand ) == true );");
+out.println("");
+out.println("    } catch( ActiveMQException& e ) {");
+out.println("        e.printStackTrace();");
+out.println("        CPPUNIT_ASSERT( false );");
+out.println("    } catch( ... ) {");
+out.println("        CPPUNIT_ASSERT( false );");
+out.println("    }");
 out.println("}");
+out.println("");
     }
 
 }

Modified: activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingHeadersGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingHeadersGenerator.java?rev=587160&r1=587159&r2=587160&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingHeadersGenerator.java
(original)
+++ activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppTestMarshallingHeadersGenerator.java
Mon Oct 22 10:16:24 2007
@@ -52,6 +52,10 @@
         return super.getClassName(jclass) + "Test";
     }
 
+    protected String getTargetClassName(JClass jclass) {
+        return super.getClassName(jclass);
+    }
+
     protected String getFilePostFix() {
         return ".h";
     }
@@ -150,6 +154,8 @@
 out.println("");
 out.println("        CPPUNIT_TEST_SUITE( "+className+" );");
 out.println("        CPPUNIT_TEST( test );");
+out.println("        CPPUNIT_TEST( testLooseMarshal );");
+out.println("        CPPUNIT_TEST( testTightMarshal );");
 out.println("        CPPUNIT_TEST_SUITE_END();");
 out.println("");
 out.println("    public:");
@@ -161,6 +167,8 @@
 out.println("         * Test the marshaller and its marshalled type.");
 out.println("         */");
 out.println("        virtual void test();");
+out.println("        virtual void testLooseMarshal();");
+out.println("        virtual void testTightMarshal();");
 out.println("");
 out.println("    };");
 out.println("");



Mime
View raw message