activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r602189 - in /activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio: CharArrayBufferTest.cpp CharArrayBufferTest.h
Date Fri, 07 Dec 2007 19:29:05 GMT
Author: tabish
Date: Fri Dec  7 11:29:04 2007
New Revision: 602189

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

Starting the NIO implementation

Modified:
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.h

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.cpp?rev=602189&r1=602188&r2=602189&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.cpp
(original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.cpp
Fri Dec  7 11:29:04 2007
@@ -675,6 +675,257 @@
 
     CPPUNIT_ASSERT_THROW_MESSAGE(
         "Should throw a BufferOverflowException",
-        testBuffer1->put( "ASDFGHJKJKL" );,
+        testBuffer1->put( "ASDFGHJKJKL" ),
         BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testPutStringWithArgs() {
+
+    testBuffer1->clear();
+    string str;
+    str.resize( testBuffer1->capacity() );
+
+    // Throw a BufferOverflowException and no character is transfered to
+    // CharBuffer
+    std::string toBig = "";
+    toBig.resize( testBuffer1->capacity() + 1 );
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a BufferOverflowException",
+        testBuffer1->put( toBig, 0, testBuffer1->capacity() + 1 ),
+        BufferOverflowException );
+
+    CPPUNIT_ASSERT( 0 == testBuffer1->position() );
+
+    testBuffer1->clear();
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1->put( str, str.length() + 1, str.length() + 2 ),
+        IndexOutOfBoundsException );
+
+    testBuffer1->put( str, str.length(), str.length() );
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1->put( str, 2, 1 ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1->put( str, 2, str.length() + 1 ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    str.resize( testBuffer1->capacity() );
+
+    CharBuffer& ret = testBuffer1->put( str, 0, str.length() );
+    CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->capacity() );
+
+    for( std::size_t ix = 0; ix < testBuffer1->capacity(); ++ix ) {
+        CPPUNIT_ASSERT( testBuffer1->get( ix ) == str.at( ix ) );
+    }
+
+    CPPUNIT_ASSERT( &ret == testBuffer1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testAppendSelf() {
+
+    CharBuffer* cb = CharBuffer::allocate(10);
+    CharBuffer* cb2 = cb->duplicate();
+
+    cb->append( cb );
+    CPPUNIT_ASSERT( 10 == cb->position() );
+    cb->clear();
+    CPPUNIT_ASSERT( cb2->equals( *cb ) );
+
+    cb->put("abc");
+    cb2 = cb->duplicate();
+    cb->append( cb );
+    CPPUNIT_ASSERT( 10 == cb->position() );
+    cb->clear();
+    cb2->clear();
+    CPPUNIT_ASSERT( cb2 == cb );
+
+    cb->put("edfg");
+    cb->clear();
+    cb2 = cb->duplicate();
+    cb->append( cb );
+    CPPUNIT_ASSERT(10 == cb->position());
+    cb->clear();
+    cb2->clear();
+    CPPUNIT_ASSERT( cb == cb2 );
+
+    delete cb;
+    delete cb2;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testAppendOverFlow() {
+
+    CharBuffer* cb = CharBuffer::allocate( 1 );
+    CharSequence* cs = testBuffer1->subSequence( 0, 25 );
+
+    cb->put( 'A' );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a BufferOverflowException",
+        cb->append('C'),
+        BufferOverflowException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a BufferOverflowException",
+        cb->append( cs ),
+        BufferOverflowException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a BufferOverflowException",
+        cb->append( cs, 1, 2 ),
+        BufferOverflowException );
+
+    delete cb;
+    delete cs;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testReadOnlyMap() {
+
+    CharBuffer cb = CharBuffer::wrap("ABCDE").asReadOnlyBuffer();
+    CharSequence cs = "String";
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a ReadOnlyBufferException",
+        cb->append( 'A' ),
+        ReadOnlyBufferException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a ReadOnlyBufferException",
+        cb->append( cs ),
+        ReadOnlyBufferException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a ReadOnlyBufferException",
+        cb->append( cs, 1, 2 ),
+        ReadOnlyBufferException );
+
+    cb->append( cs, 1, 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testAppendCNormal() {
+    CharBuffer* cb = CharBuffer::allocate(2);
+    cb->put('A');
+    CPPUNIT_ASSERT( cb == &( cb->append('B') ) );
+    CPPUNIT_ASSERT( 'B' == cb->get( 1 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testAppendCharSequenceNormal() {
+
+    CharBuffer* cb = CharBuffer::allocate(10);
+    cb->put('A');
+    CPPUNIT_ASSERT( cb == &( cb->append( "String" ) ) );
+    CPPUNIT_ASSERT( "AString" == cb->flip().toString());
+    cb->append( (const lang::CharSequence*)NULL );
+    CPPUNIT_ASSERT( cb->flip().toString() == "null" );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testAppendCharSequenceIINormal() {
+
+    CharBuffer* cb = CharBuffer::allocate(10);
+    cb->put('A');
+    CPPUNIT_ASSERT( cb, cb->append("String", 1, 3) );
+    CPPUNIT_ASSERT( "Atr" == cb->flip().toString() );
+
+    cb->append( (const lang::CharSequence*)NULL, 0, 1 );
+    CPPUNIT_ASSERT( "n" == cb->flip().toString() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testAppendCharSequenceII_IllegalArgument() {
+
+    CharBuffer* cb = CharBuffer::allocate(10);
+    cb->append( "String", 0, 0 );
+    cb->append( "String", 2, 2 );
+
+    try {
+        cb->append("String", 3, 2);
+        fail("should throw IndexOutOfBoundsException.");
+    } catch (IndexOutOfBoundsException ex) {
+        // expected;
+    }
+    try {
+        cb->append("String", 3, 0);
+        fail("should throw IndexOutOfBoundsException.");
+    } catch (IndexOutOfBoundsException ex) {
+        // expected;
+    }
+    try {
+        cb->append("String", 3, 110);
+        fail("should throw IndexOutOfBoundsException.");
+    } catch (IndexOutOfBoundsException ex) {
+        // expected;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testReadCharBuffer() {
+
+    CharBuffer* source = CharBuffer::wrap("String");
+    CharBuffer* target = CharBuffer::allocate(10);
+
+    CPPUNIT_ASSERT( 6 == source.read( target ) );
+    CPPUNIT_ASSERT( "String" == target.flip().toString() );
+
+    // return -1 when nothing to read
+    CPPUNIT_ASSERT( string::npos == source.read(target) );
+
+    // NullPointerException
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a NullPointerException",
+        source->read( NULL ),
+        NullPointerException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testReadReadOnly() {
+
+    CharBuffer* source = CharBuffer::wrap("String");
+    CharBuffer* target = CharBuffer::allocate(10).asReadOnlyBuffer();
+
+    // NullPointerException
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a ReadOnlyBufferException",
+        source->read( target ),
+        ReadOnlyBufferException );
+
+    // if target has no remaining, needn't to check the isReadOnly
+    target.flip();
+    CPPUNIT_ASSERT( 0 == source->read( target ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testReadOverflow() {
+
+    CharBuffer* source = CharBuffer::wrap("String");
+    CharBuffer* target = CharBuffer::allocate( 1 );
+
+    CPPUNIT_ASSERT( 1 == source->read(target) );
+    CPPUNIT_ASSERT( "S" == target->flip().toString() );
+    CPPUNIT_ASSERT( 1 == source->position() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testReadSelf() {
+
+    CharBuffer* source = CharBuffer::wrap("abuffer");
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IllegalArgumentException",
+        source->read( source ),
+        IllegalArgumentException );
 }

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.h?rev=602189&r1=602188&r2=602189&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.h Fri
Dec  7 11:29:04 2007
@@ -55,6 +55,7 @@
         CPPUNIT_TEST( testLength );
         CPPUNIT_TEST( testSubSequence );
         CPPUNIT_TEST( testPutString );
+        CPPUNIT_TEST( testPutStringWithArgs );
         CPPUNIT_TEST_SUITE_END();
 
         decaf::nio::CharBuffer* testBuffer1;
@@ -108,6 +109,19 @@
         void testLength();
         void testSubSequence();
         void testPutString();
+        void testPutStringWithArgs();
+
+        void testAppendSelf();
+        void testAppendOverFlow();
+        void testReadOnlyMap();
+        void testAppendCNormal();
+        void testAppendCharSequenceNormal();
+        void testAppendCharSequenceIINormal();
+        void testAppendCharSequenceII_IllegalArgument();
+        void testReadCharBuffer();
+        void testReadReadOnly();
+        void testReadOverflow();
+        void testReadSelf();
 
     };
 



Mime
View raw message