activemq-commits mailing list archives

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

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

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedOutputStreamTest.cpp?rev=591482&r1=591481&r2=591482&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedOutputStreamTest.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedOutputStreamTest.cpp Fri Nov
 2 14:41:02 2007
@@ -16,13 +16,197 @@
  */
 
 #include "BufferedOutputStreamTest.h"
+#include <decaf/io/ByteArrayOutputStream.h>
+#include <decaf/io/ByteArrayInputStream.h>
 
 using namespace std;
 using namespace decaf;
 using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 using namespace decaf::io;
 using namespace decaf::util;
 
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testConstructor1() {
+
+    try {
+        MyOutputStream myStream;
+        BufferedOutputStream os( &myStream );
+        os.write( (unsigned char*)&testString[0], 500 );
+    } catch( IOException& e ) {
+        CPPUNIT_FAIL("Constrcutor test failed");
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testConstructor2() {
+
+    try {
+        MyOutputStream myStream;
+        BufferedOutputStream os( &myStream, (std::size_t)1024 );
+        os.write( (unsigned char*)&testString[0], 500 );
+    } catch( IOException& e) {
+        CPPUNIT_FAIL("IOException during Constrcutor test");
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testFlush() {
+
+    try {
+
+        ByteArrayOutputStream myStream;
+        BufferedOutputStream os( &myStream, (std::size_t)600 );
+        os.write( (unsigned char*)&testString[0], 500 );
+        os.flush();
+        CPPUNIT_ASSERT_MESSAGE("Bytes not written after flush",
+                500 == myStream.getByteArraySize() );
+    } catch( IOException& e) {
+        CPPUNIT_FAIL("Flush test failed");
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWrite() {
+
+    try {
+
+        ByteArrayOutputStream baos;
+        BufferedOutputStream os( &baos, (std::size_t)512 );
+        os.write( (unsigned char*)&testString[0], 500 );
+
+        ByteArrayInputStream bais1( baos.getByteArray(), baos.getByteArraySize() );
+        CPPUNIT_ASSERT_MESSAGE( "Bytes written, not buffered", 0 == bais1.available());
+        os.flush();
+        ByteArrayInputStream bais2( baos.getByteArray(), baos.getByteArraySize() );
+        CPPUNIT_ASSERT_MESSAGE( "Bytes not written after flush", 500 == bais2.available()
);
+        os.write( (unsigned char*)&testString[500], 514 );
+        ByteArrayInputStream bais3( baos.getByteArray(), baos.getByteArraySize() );
+        CPPUNIT_ASSERT_MESSAGE( "Bytes not written when buffer full",
+                                bais3.available() >= 1000);
+        unsigned char wbytes[1014] = {0};
+        bais3.read( wbytes, 1013 );
+
+        CPPUNIT_ASSERT_MESSAGE(
+            "Incorrect bytes written",
+            testString.substr(0, 1012) == string( (const char*)wbytes ) );
+
+    } catch( IOException& e) {
+        CPPUNIT_FAIL("write test failed: ");
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWriteException() {
+
+    BufferedOutputStream bos( new ByteArrayOutputStream(), true );
+    unsigned char* nullByteArray = NULL;
+    unsigned char byteArray[10];
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "should throw NullPointerException",
+        bos.write( nullByteArray, (std::size_t)1 ),
+        NullPointerException );
+
+    bos.write( byteArray, 0 );
+    bos.write( byteArray, 1 );
+    bos.write( byteArray, 10 );
+    bos.close();
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "should throw IOException",
+        bos.write( nullByteArray, (std::size_t)1 ),
+        IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWriteNullStreamNullArray() {
+
+    BufferedOutputStream bos( NULL );
+    unsigned char* nullByteArray = NULL;
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "should throw NullPointerException",
+        bos.write( nullByteArray, (std::size_t)1 ),
+        NullPointerException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "should throw NullPointerException",
+        bos.write( nullByteArray, (std::size_t)0 ),
+        NullPointerException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWriteNullStreamNullArraySize() {
+
+    BufferedOutputStream bos( NULL, (std::size_t)1 );
+    unsigned char* nullByteArray = NULL;
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "should throw NullPointerException",
+        bos.write( nullByteArray, (std::size_t)1 ),
+        NullPointerException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "should throw NullPointerException",
+        bos.write( nullByteArray, (std::size_t)0 ),
+        NullPointerException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWriteNullStream() {
+
+    BufferedOutputStream bos( NULL );
+    unsigned char byteArray[10];
+
+    bos.write(byteArray, 0 );
+    bos.write(byteArray, 1 );
+    bos.write(byteArray, 10 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWriteNullStreamSize() {
+
+    BufferedOutputStream bos( NULL, (std::size_t)1 );
+    unsigned char byteArray[10];
+
+    bos.write( byteArray, 0 );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "should throw NullPointerException",
+        bos.write( byteArray, 2 ),
+        IOException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "should throw NullPointerException",
+        bos.write( byteArray, 10 ),
+        IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWriteI() {
+
+    try {
+
+        ByteArrayOutputStream baos;
+        BufferedOutputStream os( &baos );
+        os.write('t');
+        ByteArrayInputStream bais1( baos.getByteArray(), baos.getByteArraySize() );
+        CPPUNIT_ASSERT_MESSAGE( "Byte written, not buffered", 0 == bais1.available() );
+        os.flush();
+
+        ByteArrayInputStream bais2( baos.getByteArray(), baos.getByteArraySize() );
+        CPPUNIT_ASSERT_MESSAGE( "Byte not written after flush", 1 == bais2.available() );
+        unsigned char wbytes[10];
+        bais2.read( wbytes, 1 );
+        CPPUNIT_ASSERT_MESSAGE( "Incorrect byte written", 't' == wbytes[0] );
+
+    } catch( IOException& e) {
+        CPPUNIT_FAIL("Write test failed");
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void BufferedOutputStreamTest::testSmallerBuffer(){
 
     MyOutputStream myStream;
@@ -46,6 +230,7 @@
     CPPUNIT_ASSERT( strcmp( buffer, "TEST" ) == 0 );
 }
 
+////////////////////////////////////////////////////////////////////////////////
 void BufferedOutputStreamTest::testBiggerBuffer(){
 
     MyOutputStream myStream;
@@ -68,5 +253,4 @@
 
     bufStream.flush();
     CPPUNIT_ASSERT( strcmp( buffer, "TESTTEST12345678910" ) == 0 );
-
 }

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedOutputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedOutputStreamTest.h?rev=591482&r1=591481&r2=591482&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedOutputStreamTest.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/BufferedOutputStreamTest.h Fri Nov
 2 14:41:02 2007
@@ -33,8 +33,41 @@
       CPPUNIT_TEST_SUITE( BufferedOutputStreamTest );
       CPPUNIT_TEST( testSmallerBuffer );
       CPPUNIT_TEST( testBiggerBuffer );
+      CPPUNIT_TEST( testConstructor1 );
+      CPPUNIT_TEST( testConstructor2 );
+      CPPUNIT_TEST( testFlush );
+      CPPUNIT_TEST( testWrite );
+      CPPUNIT_TEST( testWriteException );
+      CPPUNIT_TEST( testWriteNullStream );
+      CPPUNIT_TEST( testWriteNullStreamNullArray );
+      CPPUNIT_TEST( testWriteNullStreamNullArraySize );
+      CPPUNIT_TEST( testWriteNullStreamSize );
+      CPPUNIT_TEST( testWriteI );
       CPPUNIT_TEST_SUITE_END();
 
+      std::string testString;
+
+    public:
+
+        virtual ~BufferedOutputStreamTest(){}
+        virtual void setUp(){
+            testString = "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_ClassLo
 ader\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\nTe
 st_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_PlainDatagram
 SocketImpl\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";
+        }
+        virtual void tearDown(){}
+
+        void testSmallerBuffer();
+        void testBiggerBuffer();
+        void testConstructor1();
+        void testConstructor2();
+        void testFlush();
+        void testWrite();
+        void testWriteException();
+        void testWriteNullStreamNullArray();
+        void testWriteNullStreamNullArraySize();
+        void testWriteNullStream();
+        void testWriteNullStreamSize();
+        void testWriteI();
+
     public:
 
         class MyOutputStream : public OutputStream{
@@ -90,15 +123,6 @@
             virtual void notifyAll() throw(lang::Exception){
             }
         };
-
-    public:
-
-        virtual ~BufferedOutputStreamTest(){}
-        virtual void setUp(){}
-        virtual void tearDown(){}
-
-        void testSmallerBuffer();
-        void testBiggerBuffer();
 
     };
 



Mime
View raw message