You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/10/31 20:46:00 UTC

svn commit: r590802 - in /activemq/activemq-cpp/decaf/trunk/src/test/decaf/io: BufferedInputStreamTest.cpp BufferedInputStreamTest.h

Author: tabish
Date: Wed Oct 31 12:46:00 2007
New Revision: 590802

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

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=590802&r1=590801&r2=590802&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 Wed Oct 31 12:46:00 2007
@@ -60,6 +60,46 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStreamTest::testAvailable() {
+
+    std::string testStr = "TEST12345678910";
+    MyInputStream myStream( testStr );
+    // Create buffer with exact size of data
+    BufferedInputStream is( &myStream, testStr.length() );
+
+    // Test for method int BufferedInputStream.available()
+    try {
+        CPPUNIT_ASSERT_MESSAGE( "Returned incorrect number of available bytes",
+                                 is.available() == testStr.length() );
+    } catch( IOException& e ) {
+        CPPUNIT_ASSERT_MESSAGE("Exception during available test", false );
+    }
+
+    // Test that a closed stream throws an IOE for available()
+    std::string testStr2 = "hello world";
+    MyInputStream myStream2( testStr2 );
+    BufferedInputStream bis( &myStream2, testStr2.length() );
+
+    int available;
+
+    try {
+        available = bis.available();
+        bis.close();
+    } catch( IOException& ex ) {
+        CPPUNIT_ASSERT(false);
+        return; // never reached.
+    }
+    CPPUNIT_ASSERT( available != 0 );
+
+    try {
+        bis.available();
+        CPPUNIT_ASSERT_MESSAGE("Expected test to throw IOE.", false );
+    } catch (IOException& ex) {
+        // expected
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void BufferedInputStreamTest::testSmallerBuffer(){
 
     std::string testStr = "TEST12345678910";

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=590802&r1=590801&r2=590802&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 Wed Oct 31 12:46:00 2007
@@ -33,6 +33,7 @@
         CPPUNIT_TEST( testSmallerBuffer );
         CPPUNIT_TEST( testBiggerBuffer );
         CPPUNIT_TEST( testConstructor );
+        CPPUNIT_TEST( testAvailable );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -42,12 +43,15 @@
             std::string data;
             std::size_t pos;
             bool throwOnRead;
+            bool closed;
+
         public:
 
             MyInputStream( const std::string& data ){
                 this->data = data;
                 this->pos = 0;
                 this->throwOnRead = false;
+                this->closed = false;
             }
             virtual ~MyInputStream(){}
 
@@ -59,7 +63,16 @@
                 return this->throwOnRead;
             }
 
+            bool isClosed() const {
+                return this->closed;
+            }
+
             virtual std::size_t available() const throw (IOException){
+                if( isClosed() ) {
+                    throw IOException(
+                        __FILE__, __LINE__,
+                        "MyInputStream::read - Stream already closed." );
+                }
                 std::size_t len = data.length();
                 return len - pos;
             }
@@ -103,7 +116,7 @@
             }
 
             virtual void close() throw(lang::Exception){
-                // do nothing.
+                this->closed = true;
             }
             virtual std::size_t skip( std::size_t num ) throw ( io::IOException, lang::exceptions::UnsupportedOperationException ) {
                 return ( pos += std::min( num, available() ) );
@@ -132,6 +145,7 @@
         void testSmallerBuffer();
         void testBiggerBuffer();
         void testConstructor();
+        void testAvailable();
 
     };