activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r591663 - in /activemq/activemq-cpp/decaf/trunk/src: main/decaf/io/ test/decaf/io/
Date Sat, 03 Nov 2007 18:57:39 GMT
Author: tabish
Date: Sat Nov  3 11:57:38 2007
New Revision: 591663

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

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.cpp?rev=591663&r1=591662&r2=591663&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.cpp Sat Nov
 3 11:57:38 2007
@@ -40,7 +40,7 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void ByteArrayOutputStream::clear() throw ( IOException ) {
+void ByteArrayOutputStream::reset() throw ( IOException ) {
     // Empty the contents of the buffer to the output stream.
     activeBuffer->clear();
 }
@@ -66,3 +66,35 @@
     std::copy( buffer, buffer + len, iter );
 }
 
+////////////////////////////////////////////////////////////////////////////////
+std::string ByteArrayOutputStream::toString() const {
+
+    if( this->activeBuffer->empty() ) {
+        return "";
+    }
+
+    return string( (const char*)this->toByteArray(), this->size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStream::writeTo( OutputStream* out ) const
+    throw ( IOException, lang::exceptions::NullPointerException ) {
+
+    try{
+
+        if( this->size() == 0 ) {
+            return;
+        }
+
+        if( out == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "ByteArrayOutputStream::writeTo - Passed stream pointer is null" );
+        }
+
+        out->write( this->toByteArray(), this->size() );
+    }
+    DECAF_CATCH_RETHROW( IOException )
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCHALL_THROW( IOException )
+}

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.h?rev=591663&r1=591662&r2=591663&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/io/ByteArrayOutputStream.h Sat Nov  3
11:57:38 2007
@@ -74,7 +74,7 @@
          * Get a snapshot of the data
          * @return pointer to the data
          */
-        virtual const unsigned char* getByteArray() const {
+        virtual const unsigned char* toByteArray() const {
             if( activeBuffer->size() == 0 ){
                 return NULL;
             }
@@ -86,7 +86,7 @@
          * Get the Size of the Internal Buffer
          * @return size of the internal buffer
          */
-        virtual std::size_t getByteArraySize() const {
+        virtual std::size_t size() const {
             return activeBuffer->size();
         }
 
@@ -118,13 +118,27 @@
          * Clear current Stream contents
          * @throws IOException
          */
-        virtual void clear() throw ( IOException );
+        virtual void reset() throw ( IOException );
 
         /**
          * Invokes close on the target output stream.
          * @throws CMSException
          */
         void close() throw( lang::Exception ){ /* do nothing */ }
+
+        /**
+         * Converts the bytes in the buffer into a standard C++ string
+         * @returns a string contianing the bytes in the buffer
+         */
+        std::string toString() const;
+
+        /**
+         * Writes the complete contents of this byte array output stream to the
+         * specified output stream argument, as if by calling the output
+         * stream's write method using out.write( buf, 0, count ).
+         */
+        void writeTo( OutputStream* out ) const
+            throw ( IOException, lang::exceptions::NullPointerException );
 
     public:
 

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=591663&r1=591662&r2=591663&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 Sat Nov
 3 11:57:38 2007
@@ -60,7 +60,7 @@
         os.write( (unsigned char*)&testString[0], 500 );
         os.flush();
         CPPUNIT_ASSERT_MESSAGE("Bytes not written after flush",
-                500 == myStream.getByteArraySize() );
+                500 == myStream.size() );
     } catch( IOException& e) {
         CPPUNIT_FAIL("Flush test failed");
     }
@@ -75,13 +75,13 @@
         BufferedOutputStream os( &baos, (std::size_t)512 );
         os.write( (unsigned char*)&testString[0], 500 );
 
-        ByteArrayInputStream bais1( baos.getByteArray(), baos.getByteArraySize() );
+        ByteArrayInputStream bais1( baos.toByteArray(), baos.size() );
         CPPUNIT_ASSERT_MESSAGE( "Bytes written, not buffered", 0 == bais1.available());
         os.flush();
-        ByteArrayInputStream bais2( baos.getByteArray(), baos.getByteArraySize() );
+        ByteArrayInputStream bais2( baos.toByteArray(), baos.size() );
         CPPUNIT_ASSERT_MESSAGE( "Bytes not written after flush", 500 == bais2.available()
);
         os.write( (unsigned char*)&testString[500], 514 );
-        ByteArrayInputStream bais3( baos.getByteArray(), baos.getByteArraySize() );
+        ByteArrayInputStream bais3( baos.toByteArray(), baos.size() );
         CPPUNIT_ASSERT_MESSAGE( "Bytes not written when buffer full",
                                 bais3.available() >= 1000);
         unsigned char wbytes[1014] = {0};
@@ -191,11 +191,11 @@
         ByteArrayOutputStream baos;
         BufferedOutputStream os( &baos );
         os.write('t');
-        ByteArrayInputStream bais1( baos.getByteArray(), baos.getByteArraySize() );
+        ByteArrayInputStream bais1( baos.toByteArray(), baos.size() );
         CPPUNIT_ASSERT_MESSAGE( "Byte written, not buffered", 0 == bais1.available() );
         os.flush();
 
-        ByteArrayInputStream bais2( baos.getByteArray(), baos.getByteArraySize() );
+        ByteArrayInputStream bais2( baos.toByteArray(), baos.size() );
         CPPUNIT_ASSERT_MESSAGE( "Byte not written after flush", 1 == bais2.available() );
         unsigned char wbytes[10];
         bais2.read( wbytes, 1 );

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.cpp?rev=591663&r1=591662&r2=591663&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.cpp Sat
Nov  3 11:57:38 2007
@@ -23,6 +23,94 @@
 using namespace decaf::io;
 using namespace decaf::util;
 
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testConstructor1() {
+    std::vector<unsigned char> buffer;
+    ByteArrayOutputStream baos( buffer );
+    CPPUNIT_ASSERT_MESSAGE("Failed to create stream", 0 == baos.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testConstructor2() {
+    ByteArrayOutputStream baos;
+    CPPUNIT_ASSERT_MESSAGE("Failed to create stream", 0 == baos.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testClose() {
+
+    CPPUNIT_ASSERT_MESSAGE(
+        "close() does nothing for this implementation of OutputSteam",
+        true );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testReset() {
+    ByteArrayOutputStream baos;
+    baos.write( (unsigned char*)&testString[0], 100 );
+    baos.reset();
+    CPPUNIT_ASSERT_MESSAGE("reset failed", 0 == baos.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testSize() {
+    ByteArrayOutputStream baos;
+    baos.write( (unsigned char*)&testString[0], 100 );
+    CPPUNIT_ASSERT_MESSAGE("size test failed", 100 == baos.size());
+    baos.reset();
+    CPPUNIT_ASSERT_MESSAGE("size test failed", 0 == baos.size());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testToByteArray() {
+    const unsigned char* bytes = NULL;
+    ByteArrayOutputStream baos;
+    baos.write( (unsigned char*)&testString[0], testString.length() );
+    bytes = baos.toByteArray();
+    for( std::size_t i = 0; i < testString.length(); i++) {
+        CPPUNIT_ASSERT_MESSAGE("Error in byte array", bytes[i] == testString.at(i) );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testToString() {
+
+    ByteArrayOutputStream baos;
+    baos.write( (unsigned char*)&testString[0], testString.length() );
+    CPPUNIT_ASSERT_MESSAGE( "Returned incorrect String",
+                            baos.toString() == testString );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testWrite1() {
+
+    ByteArrayOutputStream baos;
+    baos.write('t');
+    const unsigned char* bytes = baos.toByteArray();
+    CPPUNIT_ASSERT_MESSAGE( "Wrote incorrect bytes",
+                            string("t") == string( (const char*)bytes, baos.size() ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testWrite2() {
+    ByteArrayOutputStream baos;
+    baos.write( (unsigned char*)&testString[0], 100 );
+    const unsigned char* bytes = baos.toByteArray();
+    CPPUNIT_ASSERT_MESSAGE("Wrote incorrect bytes",
+            string((const char*)bytes, baos.size() ) == testString.substr(0, 100) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testWriteToDecaf_io_OutputStream() {
+    ByteArrayOutputStream baos1;
+    ByteArrayOutputStream baos2;
+    baos1.write( (unsigned char*)&testString[0], 100 );
+    baos1.writeTo( &baos2 );
+    CPPUNIT_ASSERT_MESSAGE( "Returned incorrect String",
+                            baos2.toString() == testString.substr(0, 100) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void ByteArrayOutputStreamTest::testStream()
 {
     ByteArrayOutputStream stream_a;
@@ -31,26 +119,26 @@
     stream_a.write(60);
     stream_a.write('c');
 
-    CPPUNIT_ASSERT( stream_a.getByteArraySize() == 3 );
+    CPPUNIT_ASSERT( stream_a.size() == 3 );
 
-    stream_a.clear();
+    stream_a.reset();
 
-    CPPUNIT_ASSERT( stream_a.getByteArraySize() == 0 );
+    CPPUNIT_ASSERT( stream_a.size() == 0 );
 
     stream_a.write((const unsigned char*)("abc"), 3);
 
-    CPPUNIT_ASSERT( stream_a.getByteArraySize() == 3 );
+    CPPUNIT_ASSERT( stream_a.size() == 3 );
 
-    stream_a.clear();
+    stream_a.reset();
 
-    CPPUNIT_ASSERT( stream_a.getByteArraySize() == 0 );
+    CPPUNIT_ASSERT( stream_a.size() == 0 );
 
     stream_a.write((const unsigned char*)("abc"), 3);
 
     unsigned char buffer[4];
 
     memset(buffer, 0, 4);
-    memcpy(buffer, stream_a.getByteArray(), stream_a.getByteArraySize());
+    memcpy(buffer, stream_a.toByteArray(), stream_a.size());
 
     CPPUNIT_ASSERT( std::string((const char*)buffer) == std::string("abc") );
 }

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.h?rev=591663&r1=591662&r2=591663&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.h Sat Nov
 3 11:57:38 2007
@@ -26,18 +26,44 @@
 namespace decaf{
 namespace io{
 
-    class ByteArrayOutputStreamTest : public CppUnit::TestFixture
-    {
+    class ByteArrayOutputStreamTest : public CppUnit::TestFixture {
+
         CPPUNIT_TEST_SUITE( ByteArrayOutputStreamTest );
         CPPUNIT_TEST( testStream );
+        CPPUNIT_TEST( testConstructor1 );
+        CPPUNIT_TEST( testConstructor2 );
+        CPPUNIT_TEST( testClose );
+        CPPUNIT_TEST( testReset );
+        CPPUNIT_TEST( testSize );
+        CPPUNIT_TEST( testToByteArray );
+        CPPUNIT_TEST( testToString );
+        CPPUNIT_TEST( testWrite1 );
+        CPPUNIT_TEST( testWrite2 );
+        CPPUNIT_TEST( testWriteToDecaf_io_OutputStream );
         CPPUNIT_TEST_SUITE_END();
 
+        std::string testString;
+
     public:
 
         ByteArrayOutputStreamTest() {}
         virtual ~ByteArrayOutputStreamTest() {}
+        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 testStream();
+        void testConstructor1();
+        void testConstructor2();
+        void testClose();
+        void testReset();
+        void testSize();
+        void testToByteArray();
+        void testToString();
+        void testWrite1();
+        void testWrite2();
+        void testWriteToDecaf_io_OutputStream();
 
     };
 

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.cpp?rev=591663&r1=591662&r2=591663&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/DataOutputStreamTest.cpp Sat Nov 
3 11:57:38 2007
@@ -47,7 +47,7 @@
     writer.writeDouble( doubleVal );
     writer.write( arrayVal, 3 );
 
-    const unsigned char* buffer = myStream.getByteArray();
+    const unsigned char* buffer = myStream.toByteArray();
     int ix = 0;
 
     unsigned char tempByte = buffer[ix];

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/FilterOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/FilterOutputStreamTest.cpp?rev=591663&r1=591662&r2=591663&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/FilterOutputStreamTest.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/io/FilterOutputStreamTest.cpp Sat Nov
 3 11:57:38 2007
@@ -46,7 +46,7 @@
         os.write( (unsigned char*)&testString[0], 500 );
         os.flush();
         CPPUNIT_ASSERT_MESSAGE( "Bytes not written after flush",
-                                500 == baos.getByteArraySize() );
+                                500 == baos.size() );
         os.close();
     } catch( IOException& e ) {
         CPPUNIT_FAIL("Close test failed : " + e.getMessage());
@@ -62,7 +62,7 @@
         os.write( (unsigned char*)&testString[0], 500 );
         os.flush();
         CPPUNIT_ASSERT_MESSAGE( "Bytes not written after flush",
-                                500 == baos.getByteArraySize() );
+                                500 == baos.size() );
         os.close();
     } catch( IOException& e ) {
         CPPUNIT_FAIL("Flush test failed : " + e.getMessage());
@@ -76,7 +76,7 @@
         ByteArrayOutputStream baos;
         FilterOutputStream os( &baos );
         os.write( (unsigned char*)&testString[0], testString.size() );
-        ByteArrayInputStream bais( baos.getByteArray(), baos.getByteArraySize() );
+        ByteArrayInputStream bais( baos.toByteArray(), baos.size() );
         os.flush();
         CPPUNIT_ASSERT_MESSAGE( "Bytes not written after flush",
                                 bais.available() == testString.length() );
@@ -98,7 +98,7 @@
         ByteArrayOutputStream baos;
         FilterOutputStream os( &baos );
         os.write('t');
-        ByteArrayInputStream bais( baos.getByteArray(), baos.getByteArraySize() );
+        ByteArrayInputStream bais( baos.toByteArray(), baos.size() );
         os.flush();
         CPPUNIT_ASSERT_MESSAGE( "Byte not written after flush", 1 == bais.available() );
         unsigned char wbytes[1];



Mime
View raw message