activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r907849 [2/2] - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/ main/decaf/io/ main/decaf/lang/ main/decaf/util/ main/decaf/util/logging/ test-benchmarks/ test-benchmarks/decaf/io/ test/ test/decaf/io/
Date Mon, 08 Feb 2010 23:53:36 GMT
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp?rev=907849&r1=907848&r2=907849&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/BufferedOutputStreamTest.cpp
Mon Feb  8 23:53:34 2010
@@ -169,8 +169,7 @@
         BufferedOutputStream os( &baos, (std::size_t)512 );
         os.write( (unsigned char*)&testString[0], 0, 500 );
 
-        ByteArrayInputStream bais1( baos.toByteArray(), baos.size() );
-        CPPUNIT_ASSERT_MESSAGE( "Bytes written, not buffered", 0 == bais1.available());
+        CPPUNIT_ASSERT_MESSAGE( "Bytes written, not buffered", NULL == baos.toByteArray()
);
         os.flush();
         ByteArrayInputStream bais2( baos.toByteArray(), baos.size() );
         CPPUNIT_ASSERT_MESSAGE( "Bytes not written after flush", 500 == bais2.available()
);
@@ -293,8 +292,7 @@
         ByteArrayOutputStream baos;
         BufferedOutputStream os( &baos );
         os.write('t');
-        ByteArrayInputStream bais1( baos.toByteArray(), baos.size() );
-        CPPUNIT_ASSERT_MESSAGE( "Byte written, not buffered", 0 == bais1.available() );
+        CPPUNIT_ASSERT_MESSAGE( "Byte written, not buffered", NULL == baos.toByteArray()
);
         os.flush();
 
         ByteArrayInputStream bais2( baos.toByteArray(), baos.size() );

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/InputStreamReaderTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/InputStreamReaderTest.cpp?rev=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/InputStreamReaderTest.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/InputStreamReaderTest.cpp Mon
Feb  8 23:53:34 2010
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "InputStreamReaderTest.h"
+
+#include <decaf/io/Reader.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+
+#include <vector>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+const std::string InputStreamReaderTest::TEST_STRING = "This is a test message with some
simple text in it.";
+
+////////////////////////////////////////////////////////////////////////////////
+InputStreamReaderTest::InputStreamReaderTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+InputStreamReaderTest::~InputStreamReaderTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InputStreamReaderTest::setUp() {
+
+    this->buffer1 = new ByteArrayInputStream( (unsigned char*)TEST_STRING.c_str(), TEST_STRING.length()
);
+    this->reader1 = new InputStreamReader( this->buffer1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InputStreamReaderTest::tearDown() {
+
+    try{
+        delete this->reader1;
+        delete this->buffer1;
+    } catch(...) {}
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InputStreamReaderTest::testClose() {
+
+    this->reader1->close();
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IOException",
+        this->reader1->read(),
+        IOException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IOException",
+        this->reader1->ready(),
+        IOException );
+
+    CPPUNIT_ASSERT_NO_THROW( this->reader1->close() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InputStreamReaderTest::testConstructorInputStream() {
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an NullPointerException",
+        InputStreamReader( NULL ),
+        NullPointerException );
+
+    InputStreamReader* reader2 = new InputStreamReader( this->buffer1 );
+    reader2->close();
+    delete reader2;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InputStreamReaderTest::testRead() {
+
+    CPPUNIT_ASSERT_EQUAL( 'T', (char) this->reader1->read() );
+    CPPUNIT_ASSERT_EQUAL( 'h', (char) this->reader1->read() );
+    CPPUNIT_ASSERT_EQUAL( 'i', (char) this->reader1->read() );
+    CPPUNIT_ASSERT_EQUAL( 's', (char) this->reader1->read() );
+    CPPUNIT_ASSERT_EQUAL( ' ', (char) this->reader1->read() );
+
+    std::vector<char> buffer( TEST_STRING.length() - 5 );
+    this->reader1->read( &buffer[0], 0, TEST_STRING.length() - 5 );
+    CPPUNIT_ASSERT_EQUAL( -1, this->reader1->read() );
+
+    this->reader1->close();
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IOException",
+        this->reader1->read(),
+        IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InputStreamReaderTest::testReady() {
+
+    CPPUNIT_ASSERT_MESSAGE( "Ready test failed", this->reader1->ready() );
+    this->reader1->read();
+    CPPUNIT_ASSERT_MESSAGE("More chars, but not ready", this->reader1->ready());
+
+    CPPUNIT_ASSERT( this->reader1->ready() );
+    std::vector<char> buffer( TEST_STRING.length() - 1 );
+    this->reader1->read( buffer );
+    CPPUNIT_ASSERT( !this->reader1->ready() );
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/InputStreamReaderTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/InputStreamReaderTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/InputStreamReaderTest.h?rev=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/InputStreamReaderTest.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/InputStreamReaderTest.h Mon
Feb  8 23:53:34 2010
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_IO_INPUTSTREAMREADERTEST_H_
+#define _DECAF_IO_INPUTSTREAMREADERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/io/ByteArrayInputStream.h>
+#include <decaf/io/InputStreamReader.h>
+
+namespace decaf {
+namespace io {
+
+    class InputStreamReaderTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( InputStreamReaderTest );
+        CPPUNIT_TEST( testClose );
+        CPPUNIT_TEST( testConstructorInputStream );
+        CPPUNIT_TEST( testRead );
+        CPPUNIT_TEST( testReady );
+        CPPUNIT_TEST_SUITE_END();
+
+    private:
+
+        ByteArrayInputStream* buffer1;
+
+        InputStreamReader* reader1;
+
+        static const std::string TEST_STRING;
+
+    public:
+
+        InputStreamReaderTest();
+        virtual ~InputStreamReaderTest();
+
+        virtual void setUp();
+        virtual void tearDown();
+
+        void testClose();
+        void testConstructorInputStream();
+        void testRead();
+        void testReady();
+
+    };
+
+}}
+
+#endif /* _DECAF_IO_INPUTSTREAMREADERTEST_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/InputStreamReaderTest.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/OutputStreamWriterTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/OutputStreamWriterTest.cpp?rev=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/OutputStreamWriterTest.cpp
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/OutputStreamWriterTest.cpp
Mon Feb  8 23:53:34 2010
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "OutputStreamWriterTest.h"
+
+#include <decaf/io/Writer.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+#include <decaf/io/ByteArrayInputStream.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+const int OutputStreamWriterTest::BUFFER_SIZE = 10000;
+const std::string OutputStreamWriterTest::TEST_STRING =
+    "Test_All_Tests\nTest_decaf_io_BufferedInputStream\nTest_decaf_io_BufferedOutputStream\nTest_decaf_io_ByteArrayInputStream\nTest_decaf_io_ByteArrayOutputStream\nTest_decaf_io_DataInputStream\n";
+
+////////////////////////////////////////////////////////////////////////////////
+OutputStreamWriterTest::OutputStreamWriterTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+OutputStreamWriterTest::~OutputStreamWriterTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OutputStreamWriterTest::setUp() {
+
+    this->buffer1 = new ByteArrayOutputStream();
+    this->writer1 = new OutputStreamWriter( this->buffer1 );
+    this->reader = NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OutputStreamWriterTest::tearDown() {
+
+    try{
+
+        delete this->writer1;
+        delete this->buffer1;
+        delete this->reader;
+
+    } catch(...) {}
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OutputStreamWriterTest::testClose() {
+
+    this->writer1->flush();
+    this->writer1->close();
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IOException",
+        this->writer1->flush(),
+        IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OutputStreamWriterTest::testFlush() {
+
+    this->writer1->write( TEST_STRING );
+    this->writer1->flush();
+
+    std::string result = this->buffer1->toString();
+    CPPUNIT_ASSERT_EQUAL( TEST_STRING, result );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OutputStreamWriterTest::testWriteCharArrayIntInt() {
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an NullPointerException",
+        this->writer1->write( NULL, 1, 1 ),
+        NullPointerException );
+
+    this->writer1->write( TEST_STRING.c_str(), 1, 2 );
+    this->writer1->flush();
+
+    CPPUNIT_ASSERT_EQUAL( std::string("es"), this->buffer1->toString() );
+
+    this->writer1->write( TEST_STRING.c_str(), 0, TEST_STRING.length() );
+    this->writer1->flush();
+
+    CPPUNIT_ASSERT_EQUAL( std::string("es") + TEST_STRING, this->buffer1->toString()
);
+
+    this->writer1->close();
+
+    // After the stream is closed, should throw IOException first
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IOException",
+        this->writer1->write( NULL, 0, 10 ),
+        IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OutputStreamWriterTest::testWriteChar() {
+
+    this->writer1->write( 'a' );
+    this->writer1->flush();
+    CPPUNIT_ASSERT_EQUAL( std::string( "a" ), this->buffer1->toString() );
+
+    this->writer1->write( 'b' );
+    this->writer1->flush();
+    CPPUNIT_ASSERT_EQUAL( std::string( "ab" ), this->buffer1->toString() );
+
+    this->writer1->write( 'c' );
+    this->writer1->flush();
+    CPPUNIT_ASSERT_EQUAL( std::string( "abc" ), this->buffer1->toString() );
+
+    this->writer1->close();
+
+    // After the stream is closed, should throw IOException first
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IOException",
+        this->writer1->write( 'd' ),
+        IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OutputStreamWriterTest::testWriteStringIntInt() {
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IndexOutOfBoundsException",
+        this->writer1->write( string( "" ), 0, 1 ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IndexOutOfBoundsException",
+        this->writer1->write( string( "abc" ), 1, 3 ),
+        IndexOutOfBoundsException );
+
+    this->writer1->write( "abc", 1, 2 );
+    this->writer1->flush();
+    CPPUNIT_ASSERT_EQUAL( std::string( "bc" ), this->buffer1->toString() );
+
+    this->writer1->write( TEST_STRING, 0, TEST_STRING.length() );
+    this->writer1->flush();
+    CPPUNIT_ASSERT_EQUAL( std::string( "bc" ) + TEST_STRING, this->buffer1->toString()
);
+
+    this->writer1->close();
+
+    // After the stream is closed, should throw IOException first
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IOException",
+        this->writer1->write( "abcdefg", 0, 3 ),
+        IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OutputStreamWriterTest::testOutputStreamWriterOutputStream() {
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an NullPointerException",
+        OutputStreamWriter( NULL ),
+        NullPointerException );
+
+    OutputStreamWriter* writer2 = new OutputStreamWriter( this->buffer1 );
+    writer2->close();
+    delete writer2;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OutputStreamWriterTest::testWriteString() {
+
+    this->writer1->write( "abc" );
+    this->writer1->flush();
+    CPPUNIT_ASSERT_EQUAL( std::string( "abc" ), this->buffer1->toString() );
+
+    this->writer1->write( TEST_STRING, 0, TEST_STRING.length() );
+    this->writer1->flush();
+    CPPUNIT_ASSERT_EQUAL( std::string( "abc" ) + TEST_STRING, this->buffer1->toString()
);
+
+    this->writer1->close();
+
+    // After the stream is closed, should throw IOException first
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IOException",
+        this->writer1->write( TEST_STRING ),
+        IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void OutputStreamWriterTest::openInputStream() {
+    this->reader = new InputStreamReader(
+        new ByteArrayInputStream( this->buffer1->toByteArrayRef() ), true );
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/OutputStreamWriterTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/OutputStreamWriterTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/OutputStreamWriterTest.h?rev=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/OutputStreamWriterTest.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/OutputStreamWriterTest.h Mon
Feb  8 23:53:34 2010
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_IO_OUTPUTSTREAMWRITERTEST_H_
+#define _DECAF_IO_OUTPUTSTREAMWRITERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/io/ByteArrayOutputStream.h>
+#include <decaf/io/OutputStreamWriter.h>
+#include <decaf/io/InputStreamReader.h>
+
+namespace decaf {
+namespace io {
+
+    class OutputStreamWriterTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( OutputStreamWriterTest );
+        CPPUNIT_TEST( testClose );
+        CPPUNIT_TEST( testFlush );
+        CPPUNIT_TEST( testWriteCharArrayIntInt );
+        CPPUNIT_TEST( testWriteChar );
+        CPPUNIT_TEST( testWriteStringIntInt );
+        CPPUNIT_TEST( testOutputStreamWriterOutputStream );
+        CPPUNIT_TEST( testWriteString );
+        CPPUNIT_TEST_SUITE_END();
+
+    private:
+
+        OutputStreamWriter* writer1;
+
+        ByteArrayOutputStream* buffer1;
+
+        InputStreamReader* reader;
+
+        static const int BUFFER_SIZE;
+        static const std::string TEST_STRING;
+
+    public:
+
+        OutputStreamWriterTest();
+
+        virtual ~OutputStreamWriterTest();
+
+        virtual void setUp();
+        virtual void tearDown();
+
+        void testClose();
+        void testFlush();
+        void testWriteCharArrayIntInt();
+        void testWriteChar();
+        void testWriteStringIntInt();
+        void testOutputStreamWriterOutputStream();
+        void testWriteString();
+
+    private:
+
+        void openInputStream();
+
+    };
+
+}}
+
+#endif /* _DECAF_IO_OUTPUTSTREAMWRITERTEST_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/OutputStreamWriterTest.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ReaderTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ReaderTest.cpp?rev=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ReaderTest.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ReaderTest.cpp Mon Feb  8 23:53:34
2010
@@ -0,0 +1,246 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ReaderTest.h"
+
+#include <decaf/io/Reader.h>
+#include <decaf/nio/CharBuffer.h>
+#include <decaf/lang/Math.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+
+#include <vector>
+
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::nio;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace decaf{
+namespace io{
+
+    class MockReader : public decaf::io::Reader {
+    private:
+
+        std::vector<char> contents;
+
+        std::size_t current_offset;
+        std::size_t length;
+
+    public:
+
+        MockReader() : Reader() {
+            this->current_offset = 0;
+            this->length = 0;
+        }
+
+        MockReader( std::vector<char>& data ) : Reader() {
+            this->contents = data;
+            this->length = contents.size();
+            this->current_offset = 0;
+        }
+
+        virtual void close() throw( decaf::io::IOException ) {
+            contents.clear();
+        }
+
+        virtual int read( char* buffer, std::size_t offset, std::size_t length )
+            throw( decaf::io::IOException,
+                   decaf::lang::exceptions::NullPointerException ) {
+
+            if( contents.empty() ) {
+                return -1;
+            }
+            if( this->length <= current_offset ) {
+                return -1;
+            }
+
+            length = Math::min( (long long)length, (long long)( this->length - current_offset
) );
+            for( std::size_t i = 0; i < length; i++ ) {
+                buffer[offset + i] = contents[current_offset + i];
+            }
+
+            current_offset += length;
+            return length;
+        }
+
+        virtual int read( decaf::nio::CharBuffer* charBuffer )
+                 throw( decaf::io::IOException,
+                        decaf::lang::exceptions::NullPointerException,
+                        decaf::nio::ReadOnlyBufferException ) {
+
+            return Reader::read( charBuffer );
+        }
+
+        virtual int read() throw( decaf::io::IOException ) {
+            return Reader::read();
+        }
+
+        virtual int read( std::vector<char>& buffer )
+            throw( decaf::io::IOException ) {
+
+            return Reader::read( buffer );
+        }
+
+    };
+
+}}
+
+////////////////////////////////////////////////////////////////////////////////
+ReaderTest::ReaderTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ReaderTest::~ReaderTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ReaderTest::testReaderCharBufferNull() {
+
+    std::string s = "MY TEST STRING";
+    std::vector<char> srcBuffer( s.begin(), s.end() );
+    MockReader mockReader( srcBuffer );
+
+    CharBuffer* charBuffer = NULL;
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an NullPointerException",
+        mockReader.read( charBuffer ),
+        NullPointerException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ReaderTest::testReaderCharBufferZeroChar() {
+
+    // the charBuffer has the capacity of 0, then there the number of char read
+    // to the CharBuffer is 0. Furthermore, the MockReader is intact in its content.
+    std::string s = "MY TEST STRING";
+    std::vector<char> srcBuffer( s.begin(), s.end() );
+
+    MockReader mockReader( srcBuffer );
+    CharBuffer* charBuffer = CharBuffer::allocate( 0 );
+
+    int result = mockReader.read( charBuffer );
+    CPPUNIT_ASSERT_EQUAL( 0, result );
+    std::vector<char> destBuffer( srcBuffer.size() );
+    mockReader.read( destBuffer );
+    CPPUNIT_ASSERT_EQUAL( s, std::string( destBuffer.begin(), destBuffer.end() ) );
+
+    delete charBuffer;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ReaderTest::testReaderCharBufferChar() {
+
+    std::string s = "MY TEST STRING";
+    std::vector<char> srcBuffer( s.begin(), s.end() );
+    const int CHARBUFFER_SIZE = 10;
+    MockReader mockReader( srcBuffer );
+    CharBuffer* charBuffer = CharBuffer::allocate( CHARBUFFER_SIZE );
+    charBuffer->append( 'A' );
+    const int CHARBUFFER_REMAINING = charBuffer->remaining();
+    int result = mockReader.read( charBuffer );
+
+    CPPUNIT_ASSERT_EQUAL( CHARBUFFER_REMAINING, result );
+    charBuffer->rewind();
+
+    CharSequence* subseq =
+        charBuffer->subSequence( CHARBUFFER_SIZE - CHARBUFFER_REMAINING, CHARBUFFER_SIZE
);
+
+    CPPUNIT_ASSERT_EQUAL( s.substr( 0, CHARBUFFER_REMAINING ),
+                          subseq->toString() );
+
+    delete subseq;
+
+    std::vector<char> destBuffer( srcBuffer.size() - CHARBUFFER_REMAINING );
+
+    mockReader.read( destBuffer );
+    CPPUNIT_ASSERT_EQUAL( s.substr( CHARBUFFER_REMAINING ),
+                          std::string( destBuffer.begin(), destBuffer.end() ) );
+
+    delete charBuffer;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ReaderTest::testMark() {
+
+    MockReader mockReader;
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw IOException for Reader do not support mark",
+        mockReader.mark(0),
+        IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ReaderTest::testRead() {
+
+    MockReader reader;
+
+    // return -1 when the stream is null;
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be equal to -1", -1, reader.read());
+
+    std::string s = "MY TEST STRING";
+    std::vector<char> srcBuffer( s.begin(), s.end() );
+    MockReader mockReader(srcBuffer);
+
+    // normal read
+    for( std::size_t ix = 0; ix < srcBuffer.size(); ++ix ) {
+
+        char c = srcBuffer[ix];
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(
+            std::string( "Should be equal to \'" ) + c + "\'",
+            (int)c, mockReader.read() );
+    }
+
+    // return -1 when read Out of Index
+    mockReader.read();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Should be equal to -1", -1, reader.read() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ReaderTest::testReady() {
+    MockReader mockReader;
+    CPPUNIT_ASSERT_MESSAGE( "Should always return false", !mockReader.ready() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ReaderTest::testReset() {
+
+    MockReader mockReader;
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an IOException",
+        mockReader.reset(),
+        IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ReaderTest::testSkip() {
+    std::string s = "MY TEST STRING";
+    std::vector<char> srcBuffer( s.begin(), s.end() );
+    int length = srcBuffer.size();
+    MockReader mockReader( srcBuffer );
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Should be equal to \'M\'", (int)'M', mockReader.read()
);
+
+    // normal skip
+    mockReader.skip( length / 2 );
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Should be equal to \'S\'", (int)'S', mockReader.read()
);
+
+    // try to skip a bigger number of characters than the total
+    // Should do nothing
+    mockReader.skip( length );
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ReaderTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ReaderTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ReaderTest.h?rev=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ReaderTest.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ReaderTest.h Mon Feb  8 23:53:34
2010
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_IO_READERTEST_H_
+#define _DECAF_IO_READERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf {
+namespace io {
+
+    class ReaderTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( ReaderTest );
+        CPPUNIT_TEST( testReaderCharBufferNull );
+        CPPUNIT_TEST( testReaderCharBufferZeroChar );
+        CPPUNIT_TEST( testReaderCharBufferChar );
+        CPPUNIT_TEST( testMark );
+        CPPUNIT_TEST( testRead );
+        CPPUNIT_TEST( testReady );
+        CPPUNIT_TEST( testReset );
+        CPPUNIT_TEST( testSkip );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        ReaderTest();
+        virtual ~ReaderTest();
+
+        void testReaderCharBufferNull();
+        void testReaderCharBufferZeroChar();
+        void testReaderCharBufferChar();
+        void testMark();
+        void testRead();
+        void testReady();
+        void testReset();
+        void testSkip();
+
+    };
+
+}}
+
+#endif /* _DECAF_IO_READERTEST_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/ReaderTest.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/WriterTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/WriterTest.cpp?rev=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/WriterTest.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/WriterTest.cpp Mon Feb  8 23:53:34
2010
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "WriterTest.h"
+
+#include <decaf/io/Writer.h>
+#include <decaf/nio/CharBuffer.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::io;
+using namespace decaf::nio;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace decaf{
+namespace io{
+
+    class MockWriter : public Writer {
+    private:
+
+        char* contents;
+        std::size_t length;
+        std::size_t offset;
+
+    public:
+
+        MockWriter( std::size_t capacity ) {
+            contents = new char[capacity];
+            length = capacity;
+            offset = 0;
+        }
+
+        virtual ~MockWriter() {
+            close();
+        }
+
+        virtual void close() throw( decaf::io::IOException ) {
+            flush();
+            delete contents;
+            contents = NULL;
+        }
+
+        virtual void flush() throw( decaf::io::IOException ) {
+        }
+
+        virtual void write( const char* buffer, std::size_t offset, std::size_t count )
+            throw( decaf::io::IOException, lang::exceptions::NullPointerException ) {
+
+            if( NULL == contents ) {
+                throw IOException( __FILE__, __LINE__, "Writer was already closed." );
+            }
+
+            if( offset >= count ) {
+                throw IndexOutOfBoundsException( __FILE__, __LINE__, "offset must be less
than count." );
+            }
+
+            for( std::size_t i = 0; i < count; i++ ) {
+                contents[this->offset + i] = buffer[offset + i];
+            }
+
+            this->offset += count;
+
+        }
+
+        virtual void write( char v )
+            throw( IOException ) {
+
+            Writer::write( v );
+        }
+
+        virtual void write( const std::vector<char>& buffer )
+            throw( IOException ) {
+
+            Writer::write( buffer );
+        }
+
+        virtual void write( const std::string& str )
+            throw( IOException ) {
+
+            Writer::write( str );
+        }
+
+        virtual void write( const std::string& str, std::size_t offset, std::size_t count
)
+            throw( IOException, lang::exceptions::IndexOutOfBoundsException ) {
+
+            Writer::write( str, offset, count );
+        }
+
+        std::vector<char> getContents() {
+
+            std::vector<char> result( offset );
+
+            for( std::size_t i = 0; i < offset; i++ ) {
+                result[i] = contents[i];
+            }
+
+            return result;
+        }
+    };
+
+}}
+
+////////////////////////////////////////////////////////////////////////////////
+WriterTest::WriterTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+WriterTest::~WriterTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void WriterTest::testWriteChar() {
+
+    std::string testString = "My Test String";
+    MockWriter writer( 20 );
+
+    std::string::const_iterator iter = testString.begin();
+    for( ; iter != testString.end(); ++iter ) {
+        writer.write( *iter );
+    }
+
+    std::vector<char> result = writer.getContents();
+    CPPUNIT_ASSERT_EQUAL( testString, std::string( result.begin(), result.end() ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void WriterTest::testWriteVector() {
+
+    std::string testString = "My Test String";
+    MockWriter writer( 20 );
+
+    std::vector<char> buffer( testString.begin(), testString.end() );
+    writer.write( buffer );
+
+    std::vector<char> result = writer.getContents();
+    CPPUNIT_ASSERT_EQUAL( testString, std::string( result.begin(), result.end() ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void WriterTest::testWriteString() {
+
+    std::string testString = "My Test String";
+    MockWriter writer( 20 );
+
+    writer.write( testString );
+
+    std::vector<char> result = writer.getContents();
+    CPPUNIT_ASSERT_EQUAL( testString, std::string( result.begin(), result.end() ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void WriterTest::testWriteStringOffsetCount() {
+
+    std::string testString = "My Test String";
+    MockWriter writer( 20 );
+
+    writer.write( testString, 0, testString.length() );
+
+    std::vector<char> result = writer.getContents();
+    CPPUNIT_ASSERT_EQUAL( testString, std::string( result.begin(), result.end() ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void WriterTest::testAppendChar() {
+
+    char testChar = ' ';
+    MockWriter writer(20);
+
+    writer.append( testChar );
+
+    CPPUNIT_ASSERT_EQUAL( testChar, writer.getContents()[0] );
+
+    writer.close();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void WriterTest::testAppendCharSequence() {
+
+    std::string testString = "My Test String";
+    MockWriter writer( 20 );
+
+    CharBuffer* buffer = CharBuffer::allocate( testString.size() );
+    buffer->put( testString );
+    buffer->rewind();
+
+    writer.append( buffer );
+
+    std::vector<char> result = writer.getContents();
+    CPPUNIT_ASSERT_EQUAL( testString, std::string( result.begin(), result.end() ) );
+
+    writer.close();
+
+    delete buffer;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void WriterTest::testAppendCharSequenceIntInt() {
+
+    std::string testString = "My Test String";
+    MockWriter writer(20);
+
+    CharBuffer* buffer = CharBuffer::allocate( testString.size() );
+    buffer->put( testString );
+    buffer->rewind();
+
+    writer.append( buffer, 1, 3 );
+
+    std::vector<char> result = writer.getContents();
+    CPPUNIT_ASSERT_EQUAL( testString.substr( 1, 2 ), std::string( result.begin(), result.end()
) );
+
+    writer.close();
+
+    delete buffer;
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/WriterTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/WriterTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/WriterTest.h?rev=907849&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/WriterTest.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/WriterTest.h Mon Feb  8 23:53:34
2010
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_IO_WRITERTEST_H_
+#define _DECAF_IO_WRITERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf {
+namespace io {
+
+    class WriterTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( WriterTest );
+        CPPUNIT_TEST( testWriteChar );
+        CPPUNIT_TEST( testWriteVector );
+        CPPUNIT_TEST( testWriteString );
+        CPPUNIT_TEST( testWriteStringOffsetCount );
+        CPPUNIT_TEST( testAppendChar );
+        CPPUNIT_TEST( testAppendCharSequence );
+        CPPUNIT_TEST( testAppendCharSequenceIntInt );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        WriterTest();
+        virtual ~WriterTest();
+
+        void testWriteChar();
+        void testWriteVector();
+        void testWriteString();
+        void testWriteStringOffsetCount();
+        void testAppendChar();
+        void testAppendCharSequence();
+        void testAppendCharSequenceIntInt();
+
+    };
+
+}}
+
+#endif /* _DECAF_IO_WRITERTEST_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/io/WriterTest.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp?rev=907849&r1=907848&r2=907849&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp Mon Feb  8 23:53:34
2010
@@ -184,6 +184,14 @@
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::DataInputStreamTest );
 #include <decaf/io/DataOutputStreamTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::DataOutputStreamTest );
+#include <decaf/io/WriterTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::WriterTest );
+#include <decaf/io/ReaderTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::ReaderTest );
+#include <decaf/io/OutputStreamWriterTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::OutputStreamWriterTest );
+#include <decaf/io/InputStreamReaderTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::InputStreamReaderTest );
 
 #include <decaf/lang/MathTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::MathTest );



Mime
View raw message