activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r598763 - in /activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio: ByteBufferTest.cpp ByteBufferTest.h
Date Tue, 27 Nov 2007 20:56:48 GMT
Author: tabish
Date: Tue Nov 27 12:56:47 2007
New Revision: 598763

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

Starting the NIO implementation

Testing the ByteBuffer class

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

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/ByteBufferTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/ByteBufferTest.cpp?rev=598763&r1=598762&r2=598763&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/ByteBufferTest.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/ByteBufferTest.cpp Tue Nov 27 12:56:47
2007
@@ -36,9 +36,34 @@
     testBuffer1->put( testData1, 0, testData1Size );
     testBuffer1->position( 0 );
 
+    testBuffer1->mark();
+
     for( std::size_t ix = 0; ix < testBuffer1->capacity(); ++ix ) {
         CPPUNIT_ASSERT( testBuffer1->get() == testData1[ix] );
     }
+
+    testBuffer1->reset();
+
+    unsigned char* array = testBuffer1->array();
+    CPPUNIT_ASSERT( array != NULL );
+
+    for( std::size_t ix = 0; ix < testBuffer1->capacity(); ++ix ) {
+        CPPUNIT_ASSERT( array[ix] == testData1[ix] );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testArrayOffset() {
+
+    testBuffer1->put( testData1, 0, testData1Size );
+    CPPUNIT_ASSERT( testBuffer1->arrayOffset() == 0 );
+    testBuffer1->rewind();
+    CPPUNIT_ASSERT( testBuffer1->arrayOffset() == 0 );
+
+    testBuffer1->get();
+    ByteBuffer* sliced = testBuffer1->slice();
+    CPPUNIT_ASSERT( sliced->arrayOffset() == 1 );
+    delete sliced;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -54,5 +79,111 @@
         readOnly->array(),
         UnsupportedOperationException );
 
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw UnsupportedOperationException",
+        readOnly->arrayOffset(),
+        UnsupportedOperationException );
+
     delete readOnly;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testAsReadOnlyBuffer() {
+
+    testBuffer1->clear();
+    testBuffer1->mark();
+    testBuffer1->position( testBuffer1->limit() );
+
+    // readonly's contents should be the same as buf
+    ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+
+    CPPUNIT_ASSERT( testBuffer1 != readOnly );
+    CPPUNIT_ASSERT( readOnly->isReadOnly() );
+    CPPUNIT_ASSERT( testBuffer1->position() == readOnly->position() );
+    CPPUNIT_ASSERT( testBuffer1->limit() == readOnly->limit() );
+
+    CPPUNIT_ASSERT( *testBuffer1 == *readOnly );
+    CPPUNIT_ASSERT( testBuffer1->compareTo( *readOnly ) == 0 );
+
+    // readonly's position, mark, and limit should be independent to buf
+    readOnly->reset();
+    CPPUNIT_ASSERT( readOnly->position() == 0 );
+    readOnly->clear();
+    CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->limit() );
+    testBuffer1->reset();
+    CPPUNIT_ASSERT( testBuffer1->position() == 0);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testCompact() {
+
+    // readonly's contents should be the same as buf
+    ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a ReadOnlyBufferExceptio",
+        readOnly->compact(),
+        ReadOnlyBufferException );
+
+    // case: buffer is full
+    testBuffer1->clear();
+    testBuffer1->mark();
+
+    testBuffer1->put( testData1, 0, testData1Size );
+
+    std::cout << "Position = " << testBuffer1->position()
+              << ", Capacity = " << testBuffer1->capacity()
+              << ", Limit = " << testBuffer1->limit() << "\n";
+
+    ByteBuffer& ret = testBuffer1->compact();
+
+    CPPUNIT_ASSERT( &ret == testBuffer1 );
+
+    std::cout << "Position = " << testBuffer1->position()
+              << ", Capacity = " << testBuffer1->capacity()
+              << ", Limit = " << testBuffer1->limit() << "\n";
+
+    CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->capacity() );
+    CPPUNIT_ASSERT( testBuffer1->limit() == testBuffer1->capacity() );
+
+//    assertContentLikeTestData1(buf, 0, (byte) 0, testBuffer1->capacity());
+//    try {
+//        testBuffer1->reset();
+//        fail("Should throw Exception"); //$NON-NLS-1$
+//    } catch (InvalidMarkException e) {
+//        // expected
+//    }
+//
+//    // case: buffer is empty
+//    testBuffer1->position(0);
+//    testBuffer1->limit(0);
+//    testBuffer1->mark();
+//    ret = testBuffer1->compact();
+//    assertSame(ret, buf);
+//    assertEquals(testBuffer1->position(), 0);
+//    assertEquals(testBuffer1->limit(), testBuffer1->capacity());
+//    assertContentLikeTestData1(buf, 0, (byte) 0, testBuffer1->capacity());
+//    try {
+//        testBuffer1->reset();
+//        fail("Should throw Exception"); //$NON-NLS-1$
+//    } catch (InvalidMarkException e) {
+//        // expected
+//    }
+//
+//    // case: normal
+//    assertTrue(testBuffer1->capacity() > SMALL_TEST_LENGTH);
+//    testBuffer1->position(1);
+//    testBuffer1->limit(SMALL_TEST_LENGTH);
+//    testBuffer1->mark();
+//    ret = testBuffer1->compact();
+//    assertSame(ret, buf);
+//    assertEquals(testBuffer1->position(), 4);
+//    assertEquals(testBuffer1->limit(), testBuffer1->capacity());
+//    assertContentLikeTestData1(buf, 0, (byte) 1, 4);
+//    try {
+//        testBuffer1->reset();
+//        fail("Should throw Exception"); //$NON-NLS-1$
+//    } catch (InvalidMarkException e) {
+//        // expected
+//    }
 }

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/ByteBufferTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/ByteBufferTest.h?rev=598763&r1=598762&r2=598763&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/ByteBufferTest.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/ByteBufferTest.h Tue Nov 27 12:56:47
2007
@@ -31,7 +31,10 @@
         CPPUNIT_TEST_SUITE( ByteBufferTest );
         CPPUNIT_TEST( test );
         CPPUNIT_TEST( testArray );
+        CPPUNIT_TEST( testArrayOffset );
         CPPUNIT_TEST( testReadOnlyArray );
+        CPPUNIT_TEST( testAsReadOnlyBuffer );
+        CPPUNIT_TEST( testCompact );
         CPPUNIT_TEST_SUITE_END();
 
     private:
@@ -62,7 +65,10 @@
 
         void test();
         void testArray();
+        void testArrayOffset();
         void testReadOnlyArray();
+        void testAsReadOnlyBuffer();
+        void testCompact();
 
     };
 



Mime
View raw message