activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r598843 - in /activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio: ByteBufferTest.cpp ByteBufferTest.h
Date Wed, 28 Nov 2007 01:29:29 GMT
Author: tabish
Date: Tue Nov 27 17:29:28 2007
New Revision: 598843

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

Working on the NIO package

Adding tests for ByteBuffer in decaf::nio

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=598843&r1=598842&r2=598843&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 17:29:28
2007
@@ -139,44 +139,94 @@
     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
-//    }
+    for( std::size_t ix; ix < testBuffer1->capacity(); ix++ ) {
+        CPPUNIT_ASSERT( testBuffer1->get( ix ) == testData1[ix] );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a InvalidMarkException",
+        readOnly->reset(),
+        InvalidMarkException );
+
+    delete readOnly;
+
+    // case: buffer is empty
+    testBuffer1->position(0);
+    testBuffer1->limit(0);
+    testBuffer1->mark();
+    ret = testBuffer1->compact();
+    CPPUNIT_ASSERT( &ret == testBuffer1 );
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+    CPPUNIT_ASSERT( testBuffer1->limit() == testBuffer1->capacity() );
+
+    for( std::size_t ix; ix < testBuffer1->capacity(); ix++ ) {
+        CPPUNIT_ASSERT( testBuffer1->get( ix ) == testData1[ix] );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a InvalidMarkException",
+        testBuffer1->reset(),
+        InvalidMarkException );
+
+    // case: normal
+    testBuffer1->position(1);
+    testBuffer1->limit(SMALL_TEST_LENGTH);
+    testBuffer1->mark();
+    ret = testBuffer1->compact();
+    CPPUNIT_ASSERT( &ret == testBuffer1 );
+    CPPUNIT_ASSERT( testBuffer1->position() == SMALL_TEST_LENGTH - 1  );
+    CPPUNIT_ASSERT( testBuffer1->limit() == testBuffer1->capacity() );
+
+    for( std::size_t ix; ix < SMALL_TEST_LENGTH - 1; ix++ ) {
+        CPPUNIT_ASSERT( testBuffer1->get( ix ) == testData1[ix + 1] );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a InvalidMarkException",
+        testBuffer1->reset(),
+        InvalidMarkException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testCompareTo() {
+
+    // compare to self
+    CPPUNIT_ASSERT( 0 == testBuffer1->compareTo( *testBuffer1 ) );
+
+    CPPUNIT_ASSERT( testBuffer1->capacity() > SMALL_TEST_LENGTH );
+    testBuffer1->clear();
+    ByteBuffer* other = ByteBuffer::allocate( testBuffer1->capacity() );
+
+    for( std::size_t ix = 0; ix < testData1Size; ++ix ){
+        testBuffer1->put( ix, testData1[ix] );
+    }
+
+    for( std::size_t ix = 0; ix < testData1Size; ++ix ){
+        other->put( ix, testData1[ix] );
+    }
+
+    CPPUNIT_ASSERT( 0 == testBuffer1->compareTo( *other ) );
+    CPPUNIT_ASSERT( 0 == other->compareTo( *testBuffer1 ) );
+    testBuffer1->position(1);
+    CPPUNIT_ASSERT( testBuffer1->compareTo( *other ) > 0 );
+    CPPUNIT_ASSERT( other->compareTo( *testBuffer1 ) < 0 );
+    other->position( 2 );
+    CPPUNIT_ASSERT( testBuffer1->compareTo( *other ) < 0 );
+    CPPUNIT_ASSERT( other->compareTo( *testBuffer1 ) > 0 );
+    testBuffer1->position( 2 );
+    other->limit(SMALL_TEST_LENGTH);
+    CPPUNIT_ASSERT( testBuffer1->compareTo( *other ) > 0 );
+    CPPUNIT_ASSERT( other->compareTo( *testBuffer1 ) < 0 );
+
+    unsigned char* data = new unsigned char[21];
+    memset( data, 0, 21 );
+    ByteBuffer* empty = ByteBuffer::allocate(21);
+    ByteBuffer* wrapped = ByteBuffer::wrap( data, (std::size_t)0, (std::size_t)21 );
+
+    CPPUNIT_ASSERT( wrapped->compareTo( *empty ) == 0 );
+
+    delete empty;
+    delete wrapped;
+    delete other;
+    delete data;
 }

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=598843&r1=598842&r2=598843&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 17:29:28
2007
@@ -35,6 +35,7 @@
         CPPUNIT_TEST( testReadOnlyArray );
         CPPUNIT_TEST( testAsReadOnlyBuffer );
         CPPUNIT_TEST( testCompact );
+        CPPUNIT_TEST( testCompareTo );
         CPPUNIT_TEST_SUITE_END();
 
     private:
@@ -43,6 +44,8 @@
         unsigned char* testData1;
 
         static const std::size_t testData1Size = 100;
+        static const std::size_t SMALL_TEST_LENGTH = 5;
+        static const std::size_t BUFFER_LENGTH = 250;
 
     public:
 
@@ -69,6 +72,7 @@
         void testReadOnlyArray();
         void testAsReadOnlyBuffer();
         void testCompact();
+        void testCompareTo();
 
     };
 



Mime
View raw message