activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r590349 - in /activemq/activemq-cpp/decaf/trunk/src/test: decaf/io/BufferedInputStreamTest.cpp decaf/io/BufferedInputStreamTest.h testRegistry.cpp
Date Tue, 30 Oct 2007 19:58:22 GMT
Author: tabish
Date: Tue Oct 30 12:58:21 2007
New Revision: 590349

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

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=590349&r1=590348&r2=590349&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 Tue Oct
30 12:58:21 2007
@@ -23,6 +23,43 @@
 using namespace decaf::io;
 using namespace decaf::util;
 
+////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStreamTest::testConstructor() {
+
+    std::string testStr = "TEST12345678910";
+    MyInputStream myStream( testStr );
+
+    // Test for method BufferedInputStream(InputStream, int)
+    bool exceptionFired = false;
+    try {
+
+        // Create buffer with exact size of data
+        BufferedInputStream is( &myStream, testStr.length() );
+
+//        // Ensure buffer gets filled by evaluating one read
+//        is.read();
+//
+//        // Read the remaining buffered characters, no IOException should
+//        // occur.
+//        is.skip( testStr.length() - 2 );
+//        is.read();
+//        try {
+//            // is.read should now throw an exception because it will have to
+//            // be filled.
+//            is.read();
+//        } catch (IOException& e) {
+//            exceptionFired = true;
+//        }
+
+        CPPUNIT_ASSERT_MESSAGE( "Exception should have been triggered by read()", exceptionFired
);
+
+    } catch (IOException& e) {
+        e.printStackTrace();
+        CPPUNIT_ASSERT_MESSAGE("Exception during test_1_Constructor", false );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void BufferedInputStreamTest::testSmallerBuffer(){
 
     std::string testStr = "TEST12345678910";
@@ -63,6 +100,7 @@
     CPPUNIT_ASSERT( available == 1 );
 }
 
+////////////////////////////////////////////////////////////////////////////////
 void BufferedInputStreamTest::testBiggerBuffer(){
 
     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=590349&r1=590348&r2=590349&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 Tue Oct
30 12:58:21 2007
@@ -32,6 +32,7 @@
         CPPUNIT_TEST_SUITE( BufferedInputStreamTest );
         CPPUNIT_TEST( testSmallerBuffer );
         CPPUNIT_TEST( testBiggerBuffer );
+        CPPUNIT_TEST( testConstructor );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -40,28 +41,57 @@
         private:
             std::string data;
             std::size_t pos;
+            bool throwOnRead;
         public:
 
             MyInputStream( const std::string& data ){
                 this->data = data;
-                pos = 0;
+                this->pos = 0;
+                this->throwOnRead = false;
             }
             virtual ~MyInputStream(){}
 
+            void setThrowOnRead( bool value ) {
+                this->throwOnRead = value;
+            }
+
+            bool isThrowOnRead() const {
+                return this->throwOnRead;
+            }
+
             virtual std::size_t available() const throw (IOException){
                 std::size_t len = data.length();
                 return len - pos;
             }
+
             virtual unsigned char read() throw (IOException){
+                if( this->isThrowOnRead() ) {
+                    throw IOException(
+                        __FILE__, __LINE__,
+                        "MyInputStream::read - Throw on Read on." );
+                }
+
                 if( pos >= data.length() ){
                     throw IOException();
                 }
 
                 return data.c_str()[pos++];
             }
+
             virtual int read( unsigned char* buffer, std::size_t bufferSize ) throw (IOException){
                 std::size_t numToRead = std::min( bufferSize, available() );
 
+                if( this->isThrowOnRead() ) {
+                    throw IOException(
+                        __FILE__, __LINE__,
+                        "MyInputStream::read - Throw on Read on." );
+                }
+
+                // Simulate EOF
+                if( numToRead == 0 ) {
+                    return -1;
+                }
+
                 const char* str = data.c_str();
                 for( std::size_t ix=0; ix<numToRead; ++ix ){
                     buffer[ix] = str[pos+ix];
@@ -75,8 +105,8 @@
             virtual void close() throw(lang::Exception){
                 // do nothing.
             }
-            virtual std::size_t skip( std::size_t num DECAF_UNUSED) throw ( io::IOException,
lang::exceptions::UnsupportedOperationException ) {
-                return 0;
+            virtual std::size_t skip( std::size_t num ) throw ( io::IOException, lang::exceptions::UnsupportedOperationException
) {
+                return ( pos += std::min( num, available() ) );
             }
 
             virtual void lock() throw(lang::Exception){
@@ -101,6 +131,7 @@
 
         void testSmallerBuffer();
         void testBiggerBuffer();
+        void testConstructor();
 
     };
 

Modified: activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp?rev=590349&r1=590348&r2=590349&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp Tue Oct 30 12:58:21 2007
@@ -18,18 +18,18 @@
 // All CPP Unit tests are registered in here so we can disable them and
 // enable them easily in one place.
 
-//#include <decaf/io/BufferedInputStreamTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::BufferedInputStreamTest );
-//#include <decaf/io/BufferedOutputStreamTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::BufferedOutputStreamTest );
-//#include <decaf/io/ByteArrayInputStreamTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::ByteArrayInputStreamTest );
-//#include <decaf/io/ByteArrayOutputStreamTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::ByteArrayOutputStreamTest );
-//#include <decaf/io/DataInputStreamTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::DataInputStreamTest );
-//#include <decaf/io/DataOutputStreamTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::DataOutputStreamTest );
+#include <decaf/io/BufferedInputStreamTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::BufferedInputStreamTest );
+#include <decaf/io/BufferedOutputStreamTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::BufferedOutputStreamTest );
+#include <decaf/io/ByteArrayInputStreamTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::ByteArrayInputStreamTest );
+#include <decaf/io/ByteArrayOutputStreamTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::ByteArrayOutputStreamTest );
+#include <decaf/io/DataInputStreamTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::DataInputStreamTest );
+#include <decaf/io/DataOutputStreamTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::DataOutputStreamTest );
 
 //#include <decaf/lang/MathTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::MathTest );
@@ -55,23 +55,23 @@
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::ThreadTest );
 //#include <decaf/lang/SystemTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::SystemTest );
-//
+
 //#include <decaf/net/SocketFactoryTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::net::SocketFactoryTest );
 //#include <decaf/net/SocketTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::net::SocketTest );
-#include <decaf/net/URITest.h>
-CPPUNIT_TEST_SUITE_REGISTRATION( decaf::net::URITest );
-#include <decaf/net/URISyntaxExceptionTest.h>
-CPPUNIT_TEST_SUITE_REGISTRATION( decaf::net::URISyntaxExceptionTest );
-//
+//#include <decaf/net/URITest.h>
+//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::net::URITest );
+//#include <decaf/net/URISyntaxExceptionTest.h>
+//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::net::URISyntaxExceptionTest );
+
 //#include <decaf/util/concurrent/CountDownLatchTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::concurrent::CountDownLatchTest );
 //#include <decaf/util/concurrent/MutexTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::concurrent::MutexTest );
 //#include <decaf/util/concurrent/ThreadPoolTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::concurrent::ThreadPoolTest );
-//
+
 //#include <decaf/util/DateTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::DateTest );
 //#include <decaf/util/UUIDTest.h>



Mime
View raw message