activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r591051 - in /activemq/activemq-cpp/decaf/trunk/src/test/decaf/io: BufferedInputStreamTest.cpp BufferedInputStreamTest.h
Date Thu, 01 Nov 2007 15:26:21 GMT
Author: tabish
Date: Thu Nov  1 08:26:20 2007
New Revision: 591051

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

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

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.cpp?rev=591051&r1=591050&r2=591051&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.cpp Thu Nov
 1 08:26:20 2007
@@ -16,6 +16,7 @@
  */
 
 #include "BufferedInputStreamTest.h"
+#include <decaf/io/ByteArrayInputStream.h>
 
 using namespace std;
 using namespace decaf;
@@ -116,6 +117,50 @@
         buf.close();
     } catch(...) {
         CPPUNIT_FAIL("Close shouldn't throw an error here" );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStreamTest::testRead() {
+
+    try {
+        // Test for method int BufferedInputStream.read()
+        std::string testStr = "TEST12345678910";
+        MyInputStream myStream( testStr );
+        // Create buffer with exact size of data
+        BufferedInputStream is( &myStream, testStr.length() );
+
+        char c = is.read();
+        CPPUNIT_ASSERT_MESSAGE( "read returned incorrect char",
+                                c == testStr.at(0) );
+    } catch( IOException& e ) {
+        CPPUNIT_FAIL( "Exception during read test" );
+    }
+
+    unsigned char bytes[256];
+    for( int i = 0; i < 256; i++ ) {
+        bytes[i] = (unsigned char)i;
+    }
+
+    // New stream, owns the inner one.
+    BufferedInputStream is(
+        new ByteArrayInputStream( &bytes[0], (std::size_t)256 ), (std::size_t)12, true
);
+
+    try {
+        CPPUNIT_ASSERT_MESSAGE( "Wrong initial byte", 0 == is.read() );
+        // Fill the buffer
+        unsigned char buf[14];
+        is.read( &buf[0], (std::size_t)14 );
+
+        // Read greater than the buffer
+        CPPUNIT_ASSERT_MESSAGE( "Wrong block read data",
+                string( (const char*)&buf[0], 14 ) ==
+                string( (const char*)&bytes[1], 14 ) );
+
+        CPPUNIT_ASSERT_MESSAGE("Wrong bytes", 15 == is.read() ); // Check next byte
+
+    } catch( IOException& e ) {
+        CPPUNIT_FAIL("Exception during read test");
     }
 }
 

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.h?rev=591051&r1=591050&r2=591051&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedInputStreamTest.h Thu Nov
 1 08:26:20 2007
@@ -35,6 +35,7 @@
         CPPUNIT_TEST( testConstructor );
         CPPUNIT_TEST( testAvailable );
         CPPUNIT_TEST( testClose );
+        CPPUNIT_TEST( testRead );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -48,6 +49,7 @@
         void testConstructor();
         void testAvailable();
         void testClose();
+        void testRead();
 
     public:
 



Mime
View raw message