activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r591695 - in /activemq/activemq-cpp/decaf/trunk/src/test/decaf/io: DataOutputStreamTest.cpp DataOutputStreamTest.h
Date Sat, 03 Nov 2007 21:34:39 GMT
Author: tabish
Date: Sat Nov  3 14:34:38 2007
New Revision: 591695

URL: http://svn.apache.org/viewvc?rev=591695&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103
http://issues.apache.org/activemq/browse/AMQCPP-136

Modified:
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.h

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.cpp?rev=591695&r1=591694&r2=591695&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.cpp Sat Nov 
3 14:34:38 2007
@@ -23,6 +23,233 @@
 using namespace decaf::io;
 using namespace decaf::util;
 
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testFlush() {
+
+    try {
+        os->writeInt(9087589);
+        os->flush();
+        openDataInputStream();
+        int c = is->readInt();
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Failed to flush correctly", 9087589 == c);
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during flush test : " + e.getMessage());
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testSize() {
+
+    try {
+        os->write( (unsigned char*)&testData[0], 0, 150 );
+        os->close();
+        openDataInputStream();
+        unsigned char rbuf[150];
+        is->read( rbuf, 0, 150 );
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Incorrect size returned", 150 == os->size());
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during write test : " + e.getMessage());
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWrite1() {
+
+    try {
+        os->write( (unsigned char*)&testData[0], 0, 150 );
+        os->close();
+        openDataInputStream();
+        unsigned char* rbuf = new unsigned char[150];
+        is->read(rbuf, 0, 150);
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Incorrect bytes written",
+            string( (const char*)rbuf, 150 ) == testData.substr( 0, 150 ) );
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during write test : " + e.getMessage());
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWrite2() {
+
+    try {
+        os->write( 't' );
+        os->close();
+        openDataInputStream();
+        char c = is->readChar();
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Incorrect int written", 't' == c);
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during write test : " + e.getMessage());
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteBoolean() {
+
+    try {
+        os->writeBoolean(true);
+        os->close();
+        openDataInputStream();
+        bool c = is->readBoolean();
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Incorrect boolean written", c );
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during writeBoolean test : " + e.getMessage());
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteByte() {
+    try {
+        os->writeByte( (unsigned char) 127 );
+        os->close();
+        openDataInputStream();
+        unsigned char c = is->readByte();
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Incorrect unsigned char written", c == (unsigned char) 127);
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during writeByte test : " + e.getMessage());
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteBytes() {
+
+    try {
+        os->writeBytes( testData );
+        os->close();
+        openDataInputStream();
+        std::vector<unsigned char> result( testData.size() );
+        is->read( result );
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Incorrect bytes written",
+            string( (const char*)&result[0], result.size() ) == testData );
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during writeBytes test : " + e.getMessage());
+    }
+
+    // regression test for HARMONY-1101
+    DataOutputStream tester(NULL);
+    tester.writeBytes("");
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteChar() {
+    try {
+        os->writeChar('T');
+        os->close();
+        openDataInputStream();
+        char c = is->readChar();
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Incorrect char written", 'T' == c );
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during writeChar test : " + e.getMessage());
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteChars() {
+
+    try {
+        os->writeChars( testData );
+        os->close();
+        openDataInputStream();
+        std::vector<unsigned char> result( testData.size() );
+        is->read( result );
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Incorrect bytes written",
+            string( (const char*)&result[0], result.size() ) == testData );
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during writeChars test : " + e.getMessage());
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteDouble() {
+    try {
+        os->writeDouble(908755555456.98);
+        os->close();
+        openDataInputStream();
+        double c = is->readDouble();
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Incorrect double written", 908755555456.98 == c);
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during writeDouble test : " + e.getMessage());
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteFloat() {
+    try {
+        os->writeFloat(9087.456f);
+        os->close();
+        openDataInputStream();
+        float c = is->readFloat();
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Incorrect float written", c == 9087.456f);
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during writeFloattest : " + e.getMessage());
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteInt() {
+    try {
+        os->writeInt(9087589);
+        os->close();
+        openDataInputStream();
+        int c = is->readInt();
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Incorrect int written", 9087589 == c);
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during writeInt test : " + e.getMessage());
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteLong() {
+    try {
+        os->writeLong(908755555456LL);
+        os->close();
+        openDataInputStream();
+        long long c = is->readLong();
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Incorrect long written", 908755555456LL == c);
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during writeLong test" + e.getMessage());
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteShort() {
+    try {
+        os->writeShort((short) 9087);
+        os->close();
+        openDataInputStream();
+        short c = is->readShort();
+        is->close();
+        CPPUNIT_ASSERT_MESSAGE("Incorrect short written", 9087 == c);
+    } catch( IOException &e ) {
+        CPPUNIT_FAIL("Exception during writeShort test : " + e.getMessage());
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteUTF() {
+    string testString = "test string one";
+    os->writeUTF( testString );
+    os->close();
+    openDataInputStream();
+    CPPUNIT_ASSERT_MESSAGE("Failed to write string in UTF format",
+        is->available() == testString.length() + 2 );
+    CPPUNIT_ASSERT_MESSAGE("Incorrect string returned",
+        is->readUTF() == testString );
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void DataOutputStreamTest::test(){
 
     unsigned char byteVal = (unsigned char)'T';

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.h?rev=591695&r1=591694&r2=591695&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.h Sat Nov  3
14:34:38 2007
@@ -23,7 +23,9 @@
 
 #include <decaf/util/Endian.h>
 #include <decaf/io/DataOutputStream.h>
+#include <decaf/io/DataInputStream.h>
 #include <decaf/io/ByteArrayOutputStream.h>
+#include <decaf/io/ByteArrayInputStream.h>
 
 namespace decaf{
 namespace io{
@@ -32,15 +34,73 @@
 
         CPPUNIT_TEST_SUITE( DataOutputStreamTest );
         CPPUNIT_TEST( test );
+        CPPUNIT_TEST( testFlush );
+        CPPUNIT_TEST( testSize );
+        CPPUNIT_TEST( testWrite1 );
+        CPPUNIT_TEST( testWrite2 );
+        CPPUNIT_TEST( testWriteBoolean );
+        CPPUNIT_TEST( testWriteByte );
+        CPPUNIT_TEST( testWriteBytes );
+        CPPUNIT_TEST( testWriteChar );
+        CPPUNIT_TEST( testWriteChars );
+        CPPUNIT_TEST( testWriteDouble );
+        CPPUNIT_TEST( testWriteFloat );
+        CPPUNIT_TEST( testWriteInt );
+        CPPUNIT_TEST( testWriteLong );
+        CPPUNIT_TEST( testWriteShort );
+        CPPUNIT_TEST( testWriteUTF );
         CPPUNIT_TEST_SUITE_END();
 
+        ByteArrayOutputStream* baos;
+        ByteArrayInputStream* bais;
+
+        DataOutputStream* os;
+        DataInputStream* is;
+
+        std::string testData;
+
     public:
 
         virtual ~DataOutputStreamTest(){}
-        virtual void setUp(){}
-        virtual void tearDown(){}
+        virtual void setUp(){
+            testData = "Test_All_Tests\nTest_decaf_io_BufferedInputStream\nTest_BufferedOutputStream\nTest_decaf_io_ByteArrayInputStream\nTest_decaf_io_ByteArrayOutputStream\nTest_decaf_io_DataInputStream\nTest_decaf_io_File\nTest_decaf_io_FileDescriptor\nTest_decaf_io_FileInputStream\nTest_decaf_io_FileNotFoundException\nTest_decaf_io_FileOutputStream\nTest_decaf_io_FilterInputStream\nTest_decaf_io_FilterOutputStream\nTest_decaf_io_InputStream\nTest_decaf_io_IOException\nTest_decaf_io_OutputStream\nTest_decaf_io_PrintStream\nTest_decaf_io_RandomAccessFile\nTest_decaf_io_SyncFailedException\nTest_decaf_lang_AbstractMethodError\nTest_decaf_lang_ArithmeticException\nTest_decaf_lang_ArrayIndexOutOfBoundsException\nTest_decaf_lang_ArrayStoreException\nTest_decaf_lang_Boolean\nTest_decaf_lang_Byte\nTest_decaf_lang_Character\nTest_decaf_lang_Class\nTest_decaf_lang_ClassCastException\nTest_decaf_lang_ClassCircularityError\nTest_decaf_lang_ClassFormatError\nTest_decaf_lang_ClassLoad
 er\nTest_decaf_lang_ClassNotFoundException\nTest_decaf_lang_CloneNotSupportedException\nTest_decaf_lang_Double\nTest_decaf_lang_Error\nTest_decaf_lang_Exception\nTest_decaf_lang_ExceptionInInitializerError\nTest_decaf_lang_Float\nTest_decaf_lang_IllegalAccessError\nTest_decaf_lang_IllegalAccessException\nTest_decaf_lang_IllegalArgumentException\nTest_decaf_lang_IllegalMonitorStateException\nTest_decaf_lang_IllegalThreadStateException\nTest_decaf_lang_IncompatibleClassChangeError\nTest_decaf_lang_IndexOutOfBoundsException\nTest_decaf_lang_InstantiationError\nTest_decaf_lang_InstantiationException\nTest_decaf_lang_Integer\nTest_decaf_lang_InternalError\nTest_decaf_lang_InterruptedException\nTest_decaf_lang_LinkageError\nTest_decaf_lang_Long\nTest_decaf_lang_Math\nTest_decaf_lang_NegativeArraySizeException\nTest_decaf_lang_NoClassDefFoundError\nTest_decaf_lang_NoSuchFieldError\nTest_decaf_lang_NoSuchMethodError\nTest_decaf_lang_NullPointerException\nTest_decaf_lang_Number\nTest
 _decaf_lang_NumberFormatException\nTest_decaf_lang_Object\nTest_decaf_lang_OutOfMemoryError\nTest_decaf_lang_RuntimeException\nTest_decaf_lang_SecurityManager\nTest_decaf_lang_Short\nTest_decaf_lang_StackOverflowError\nTest_decaf_lang_String\nTest_decaf_lang_StringBuffer\nTest_decaf_lang_StringIndexOutOfBoundsException\nTest_decaf_lang_System\nTest_decaf_lang_Thread\nTest_decaf_lang_ThreadDeath\nTest_decaf_lang_ThreadGroup\nTest_decaf_lang_Throwable\nTest_decaf_lang_UnknownError\nTest_decaf_lang_UnsatisfiedLinkError\nTest_decaf_lang_VerifyError\nTest_decaf_lang_VirtualMachineError\nTest_decaf_lang_vm_Image\nTest_decaf_lang_vm_MemorySegment\nTest_decaf_lang_vm_ROMStoreException\nTest_decaf_lang_vm_VM\nTest_decaf_lang_Void\nTest_decaf_net_BindException\nTest_decaf_net_ConnectException\nTest_decaf_net_DatagramPacket\nTest_decaf_net_DatagramSocket\nTest_decaf_net_DatagramSocketImpl\nTest_decaf_net_InetAddress\nTest_decaf_net_NoRouteToHostException\nTest_decaf_net_PlainDatagramSo
 cketImpl\nTest_decaf_net_PlainSocketImpl\nTest_decaf_net_Socket\nTest_decaf_net_SocketException\nTest_decaf_net_SocketImpl\nTest_decaf_net_SocketInputStream\nTest_decaf_net_SocketOutputStream\nTest_decaf_net_UnknownHostException\nTest_decaf_util_ArrayEnumerator\nTest_decaf_util_Date\nTest_decaf_util_EventObject\nTest_decaf_util_HashEnumerator\nTest_decaf_util_Hashtable\nTest_decaf_util_Properties\nTest_decaf_util_ResourceBundle\nTest_decaf_util_tm\nTest_decaf_util_Vector\n";
+            baos = new ByteArrayOutputStream();
+            os = new DataOutputStream( baos );
+            is = NULL;
+            bais = NULL;
+        }
+        virtual void tearDown(){
+            try {
+                delete os;
+                delete baos;
+                delete is;
+                delete bais;
+            } catch(...) {}
+        }
 
         void test();
+        void testFlush();
+        void testSize();
+        void testWrite1();
+        void testWrite2();
+        void testWriteBoolean();
+        void testWriteByte();
+        void testWriteBytes();
+        void testWriteChar();
+        void testWriteChars();
+        void testWriteDouble();
+        void testWriteFloat();
+        void testWriteInt();
+        void testWriteLong();
+        void testWriteShort();
+        void testWriteUTF();
+
+    private:
+
+        void openDataInputStream() {
+            bais = new ByteArrayInputStream( baos->toByteArray(), baos->size() );
+            is = new DataInputStream( bais );
+        }
 
     };
 



Mime
View raw message