activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r591336 - in /activemq/activemq-cpp/decaf/trunk/src/test/decaf/io: ByteArrayInputStreamTest.cpp ByteArrayInputStreamTest.h
Date Fri, 02 Nov 2007 14:03:45 GMT
Author: tabish
Date: Fri Nov  2 07:03:44 2007
New Revision: 591336

URL: http://svn.apache.org/viewvc?rev=591336&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/ByteArrayInputStreamTest.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.h

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.cpp?rev=591336&r1=591335&r2=591336&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.cpp Fri Nov
 2 07:03:44 2007
@@ -23,6 +23,152 @@
 using namespace decaf::io;
 using namespace decaf::util;
 
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testConstructor() {
+
+    std::vector<unsigned char> testBuffer;
+
+    testBuffer.push_back('t');
+    testBuffer.push_back('e');
+    testBuffer.push_back('s');
+    testBuffer.push_back('t');
+
+    ByteArrayInputStream stream_a( &testBuffer[0], testBuffer.size());
+    ByteArrayInputStream stream_b( testBuffer );
+
+    CPPUNIT_ASSERT_MESSAGE( "Unable to create ByteArrayInputStream",
+                            stream_a.available() == testBuffer.size() );
+    CPPUNIT_ASSERT_MESSAGE( "Unable to create ByteArrayInputStream",
+                            stream_b.available() == testBuffer.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testConstructor2() {
+
+    // Test for method ByteArrayInputStream(byte [], int, int)
+    std::vector<unsigned char> testBuffer;
+    for( int i = 0; i < 128; i++ ) {
+        testBuffer.push_back( (char)i );
+    }
+
+    ByteArrayInputStream bis( &testBuffer[0], 100 );
+
+    CPPUNIT_ASSERT_MESSAGE( "Unable to create ByteArrayInputStream",
+                            100 == bis.available() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testAvailable() {
+
+    // Test for method ByteArrayInputStream(byte [], int, int)
+    std::vector<unsigned char> testBuffer;
+    for( int i = 0; i < 128; i++ ) {
+        testBuffer.push_back( (char)i );
+    }
+
+    ByteArrayInputStream bis( &testBuffer[0], 128 );
+
+    CPPUNIT_ASSERT_MESSAGE( "Unable to create ByteArrayInputStream",
+                            128 == bis.available() );
+    for( int j = 0; j < 10; j++ ) {
+        bis.read();
+    }
+
+    // Test for method int ByteArrayInputStream.available()
+    CPPUNIT_ASSERT_MESSAGE( "Returned incorrect number of available bytes",
+                            bis.available() == ( testBuffer.size() - 10 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testClose() {
+
+    std::vector<unsigned char> testBuffer;
+    for( int i = 0; i < 128; i++ ) {
+        testBuffer.push_back( (char)i );
+    }
+
+    ByteArrayInputStream is( testBuffer );
+
+    // Test for method void ByteArrayInputStream.close()
+    try {
+        is.read();
+    } catch( IOException& e ) {
+        CPPUNIT_FAIL("Failed reading from input stream");
+    }
+
+    try {
+        is.close();
+    } catch( IOException& e ) {
+        CPPUNIT_FAIL("Failed closing input stream");
+    }
+
+    try {
+        is.read();
+    } catch( Exception& e ) {
+        CPPUNIT_FAIL("Should be able to read from closed stream");
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testRead() {
+
+    try{
+
+        std::vector<unsigned char> testBuffer;
+        for( int i = 0; i < 128; i++ ) {
+            testBuffer.push_back( (char)i );
+        }
+
+        ByteArrayInputStream is( testBuffer );
+
+        // Test for method int ByteArrayInputStream.read()
+        int c = is.read();
+        is.reset();
+        CPPUNIT_ASSERT_MESSAGE( "read returned incorrect char",
+                                c == testBuffer.at(0) );
+    } catch(...) {
+        CPPUNIT_FAIL( "Shouldn't get any exceptions in this test." );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testRead2() {
+
+    std::vector<unsigned char> testBuffer;
+    for( int i = 0; i < 128; i++ ) {
+        testBuffer.push_back( (char)i );
+    }
+
+    ByteArrayInputStream is( testBuffer );
+
+    unsigned char buf1[20];
+    is.skip(50);
+    is.read( buf1, 20 );
+    CPPUNIT_ASSERT_MESSAGE(
+        "Failed to read correct data",
+        string( (const char*)buf1, 20 ) == string( (const char*)&testBuffer[50], 20)
);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testSkip() {
+
+    std::vector<unsigned char> testBuffer;
+    for( int i = 0; i < 128; i++ ) {
+        testBuffer.push_back( (char)i );
+    }
+
+    ByteArrayInputStream is( testBuffer );
+
+    unsigned char buf1[10];
+    is.skip(100);
+    is.read( buf1, 10 );
+
+    CPPUNIT_ASSERT_MESSAGE(
+        "Failed to skip to correct position",
+        string( (const char*)buf1, 10 ) == string( (const char*)&testBuffer[100], 10)
);
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void ByteArrayInputStreamTest::testStream()
 {
     std::vector<unsigned char> testBuffer;

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.h?rev=591336&r1=591335&r2=591336&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayInputStreamTest.h Fri Nov
 2 07:03:44 2007
@@ -26,10 +26,17 @@
 namespace decaf{
 namespace io{
 
-   class ByteArrayInputStreamTest : public CppUnit::TestFixture
-   {
+   class ByteArrayInputStreamTest : public CppUnit::TestFixture {
+
        CPPUNIT_TEST_SUITE( ByteArrayInputStreamTest );
        CPPUNIT_TEST( testStream );
+       CPPUNIT_TEST( testConstructor );
+       CPPUNIT_TEST( testConstructor2 );
+       CPPUNIT_TEST( testAvailable );
+       CPPUNIT_TEST( testClose );
+       CPPUNIT_TEST( testRead );
+       CPPUNIT_TEST( testRead2 );
+       CPPUNIT_TEST( testSkip );
        CPPUNIT_TEST_SUITE_END();
 
    public:
@@ -38,6 +45,13 @@
        virtual ~ByteArrayInputStreamTest() {}
 
        void testStream();
+       void testConstructor();
+       void testConstructor2();
+       void testAvailable();
+       void testClose();
+       void testRead();
+       void testRead2();
+       void testSkip();
 
    };
 



Mime
View raw message