You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/11/28 22:49:34 UTC
svn commit: r599159 - in
/activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio: ByteBufferTest.cpp
ByteBufferTest.h
Author: tabish
Date: Wed Nov 28 13:49:34 2007
New Revision: 599159
URL: http://svn.apache.org/viewvc?rev=599159&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103
Working on the NIO package
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=599159&r1=599158&r2=599159&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 Wed Nov 28 13:49:34 2007
@@ -16,6 +16,7 @@
*/
#include "ByteBufferTest.h"
+#include <decaf/lang/Integer.h>
using namespace std;
using namespace decaf;
@@ -139,7 +140,7 @@
CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->capacity() );
CPPUNIT_ASSERT( testBuffer1->limit() == testBuffer1->capacity() );
- for( std::size_t ix; ix < testBuffer1->capacity(); ix++ ) {
+ for( std::size_t ix = 0; ix < testBuffer1->capacity(); ix++ ) {
CPPUNIT_ASSERT( testBuffer1->get( ix ) == testData1[ix] );
}
@@ -159,7 +160,7 @@
CPPUNIT_ASSERT( testBuffer1->position() == 0 );
CPPUNIT_ASSERT( testBuffer1->limit() == testBuffer1->capacity() );
- for( std::size_t ix; ix < testBuffer1->capacity(); ix++ ) {
+ for( std::size_t ix = 0; ix < testBuffer1->capacity(); ix++ ) {
CPPUNIT_ASSERT( testBuffer1->get( ix ) == testData1[ix] );
}
@@ -177,7 +178,7 @@
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++ ) {
+ for( std::size_t ix = 0; ix < SMALL_TEST_LENGTH - 1; ix++ ) {
CPPUNIT_ASSERT( testBuffer1->get( ix ) == testData1[ix + 1] );
}
@@ -286,4 +287,306 @@
delete readOnly;
delete duplicate;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testGet() {
+
+ testBuffer1->clear();
+
+ for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+ CPPUNIT_ASSERT( testBuffer1->position() == i );
+ CPPUNIT_ASSERT( testBuffer1->get() == testBuffer1->get(i) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferUnderflowException",
+ testBuffer1->get(),
+ BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testGetbyteArray() {
+
+ std::vector<unsigned char> array;
+ array.resize( 1 );
+ testBuffer1->clear();
+
+ for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+
+ CPPUNIT_ASSERT( testBuffer1->position() == i );
+ ByteBuffer& ret = testBuffer1->get( array );
+ CPPUNIT_ASSERT( array[0] == testBuffer1->get( i ) );
+ CPPUNIT_ASSERT( &ret == testBuffer1 );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferUnderflowException",
+ testBuffer1->get( array ),
+ BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testGetbyteArray2() {
+
+ testBuffer1->clear();
+ unsigned char* array = new unsigned char[testBuffer1->capacity()];
+ unsigned char* array2 = new unsigned char[testBuffer1->capacity() + 1];
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferUnderflowException",
+ testBuffer1->get( array2, 0, testBuffer1->capacity() + 1 ),
+ BufferUnderflowException );
+
+ CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+ testBuffer1->get( array, testBuffer1->capacity(), 0 );
+
+ CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a NullPointerException",
+ testBuffer1->get( NULL, 0, 1 ),
+ NullPointerException );
+
+ CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+ testBuffer1->clear();
+ ByteBuffer& ret = testBuffer1->get( array, 0, testBuffer1->capacity() );
+ CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->capacity() );
+ for( std::size_t ix; ix < testBuffer1->capacity() - 1; ix++ ) {
+ CPPUNIT_ASSERT( testBuffer1->get( ix ) == array[ix] );
+ }
+
+ CPPUNIT_ASSERT( &ret == testBuffer1);
+
+ delete array;
+ delete array2;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testGetWithIndex() {
+
+ testBuffer1->clear();
+
+ for( std::size_t i = 0; i < testBuffer1->capacity(); i++) {
+ CPPUNIT_ASSERT( testBuffer1->position() == i );
+ CPPUNIT_ASSERT( testBuffer1->get() == testBuffer1->get(i) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->get( testBuffer1->limit() ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testPutbyte() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+
+ readOnly->clear();
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->put( 0 ),
+ ReadOnlyBufferException );
+
+ delete readOnly;
+
+ testBuffer1->clear();
+ for( size_t i = 0; i < testBuffer1->capacity(); i++) {
+ CPPUNIT_ASSERT( testBuffer1->position() == i );
+ ByteBuffer& ret = testBuffer1->put( i );
+ CPPUNIT_ASSERT( testBuffer1->get(i) == i );
+ CPPUNIT_ASSERT( &ret == testBuffer1 );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferOverflowException",
+ testBuffer1->put( 0 ),
+ BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testPutbyteArray() {
+
+ std::vector<unsigned char> array;
+ array.push_back( 127 );
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->put( array ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+ for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+ CPPUNIT_ASSERT( testBuffer1->position() == i );
+ array[0] = i;
+ ByteBuffer& ret = testBuffer1->put( array );
+ CPPUNIT_ASSERT( testBuffer1->get(i) == i );
+ CPPUNIT_ASSERT( &ret == testBuffer1 );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferOverflowException",
+ testBuffer1->put( array ),
+ BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testPutbyteArray2() {
+
+ testBuffer1->clear();
+ unsigned char* array = new unsigned char[testBuffer1->capacity()];
+ unsigned char* array2 = new unsigned char[testBuffer1->capacity() + 1];
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->put( array, 0, testBuffer1->capacity() ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferOverflowException",
+ testBuffer1->put( array2, 0, testBuffer1->capacity() + 1 ),
+ BufferOverflowException );
+
+ CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+ testBuffer1->put( array, testBuffer1->capacity(), 0 );
+ CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a NullPointerException",
+ testBuffer1->put( NULL, 2, Integer::MAX_VALUE ),
+ NullPointerException );
+
+ CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+ for( std::size_t ix = 0; ix < testData1Size; ++ix ){
+ testBuffer1->put( ix, testData1[ix] );
+ }
+
+ ByteBuffer& ret = testBuffer1->put( array, 0, testBuffer1->capacity() );
+ CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->capacity() );
+ for( std::size_t ix; ix < testBuffer1->capacity() - 1; ix++ ) {
+ CPPUNIT_ASSERT( testBuffer1->get( ix ) == array[ix] );
+ }
+ CPPUNIT_ASSERT( &ret == testBuffer1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testPutByteBuffer() {
+
+ ByteBuffer* other = ByteBuffer::allocate( testBuffer1->capacity() );
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->put( *other ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IllegalArgumentException",
+ testBuffer1->put( *testBuffer1 ),
+ IllegalArgumentException );
+
+ ByteBuffer* toBig = testBuffer1->allocate( testBuffer1->capacity() + 1 );
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferOverflowException",
+ testBuffer1->put( *toBig ),
+ BufferOverflowException );
+ delete toBig;
+
+ for( std::size_t ix = 0; ix < testData1Size; ++ix ){
+ other->put( ix, testData1[ix] );
+ }
+ other->clear();
+
+ testBuffer1->clear();
+ ByteBuffer& ret = testBuffer1->put( *other );
+ CPPUNIT_ASSERT( other->position() == other->capacity() );
+ CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->capacity() );
+ for( std::size_t ix; ix < testBuffer1->capacity() - 1; ix++ ) {
+ CPPUNIT_ASSERT( testBuffer1->get( ix ) == other->get( ix ) );
+ }
+ CPPUNIT_ASSERT( &ret == testBuffer1 );
+
+ delete other;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testPutIndexed() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->put( 0, 0 ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+
+ for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+ CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+ ByteBuffer& ret = testBuffer1->put(i, i );
+ CPPUNIT_ASSERT(testBuffer1->get(i) == i );
+ CPPUNIT_ASSERT( &ret == testBuffer1 );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->put( testBuffer1->limit(), 0 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testSlice() {
+
+ CPPUNIT_ASSERT( testBuffer1->capacity() > SMALL_TEST_LENGTH );
+ testBuffer1->position( 1 );
+ testBuffer1->limit( testBuffer1->capacity() - 1 );
+
+ ByteBuffer* slice = testBuffer1->slice();
+ CPPUNIT_ASSERT( testBuffer1->isReadOnly() == slice->isReadOnly() );
+ CPPUNIT_ASSERT( slice->position() == 0 );
+ CPPUNIT_ASSERT( slice->limit() == testBuffer1->remaining() );
+ CPPUNIT_ASSERT( slice->capacity() == testBuffer1->remaining() );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a InvalidMarkException",
+ slice->reset(),
+ InvalidMarkException );
+
+ // slice share the same content with buf
+ for( std::size_t ix = 0; ix < slice->capacity(); ++ix ){
+ slice->put( ix, testData1[ix] );
+ }
+
+ for( std::size_t ix = 0; ix < slice->capacity(); ix++ ) {
+ CPPUNIT_ASSERT( testBuffer1->get( ix + 1 ) == slice->get( ix ) );
+ }
+ testBuffer1->put( 2, 100 );
+ CPPUNIT_ASSERT( slice->get(1) == 100 );
+
+ delete slice;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteBufferTest::testToString() {
+
+ std::string str = testBuffer1->toString();
+ CPPUNIT_ASSERT( str.find( "Byte" ) == 0 || str.find( "byte" ) == 0 );
+ CPPUNIT_ASSERT( str.find( Integer::toString( testBuffer1->position() ) ) > 0 );
+ CPPUNIT_ASSERT( str.find( Integer::toString( testBuffer1->limit() ) ) > 0 );
+ CPPUNIT_ASSERT( str.find( Integer::toString( testBuffer1->capacity() ) ) > 0 );
}
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=599159&r1=599158&r2=599159&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 Wed Nov 28 13:49:34 2007
@@ -38,6 +38,17 @@
CPPUNIT_TEST( testCompareTo );
CPPUNIT_TEST( testDuplicate );
CPPUNIT_TEST( testEquals );
+ CPPUNIT_TEST( testGet );
+ CPPUNIT_TEST( testGetbyteArray );
+ CPPUNIT_TEST( testGetbyteArray2 );
+ CPPUNIT_TEST( testGetWithIndex );
+ CPPUNIT_TEST( testPutbyte );
+ CPPUNIT_TEST( testPutbyteArray );
+ CPPUNIT_TEST( testPutbyteArray2 );
+ CPPUNIT_TEST( testPutByteBuffer );
+ CPPUNIT_TEST( testPutIndexed );
+ CPPUNIT_TEST( testSlice );
+ CPPUNIT_TEST( testToString );
CPPUNIT_TEST_SUITE_END();
private:
@@ -77,6 +88,17 @@
void testCompareTo();
void testDuplicate();
void testEquals();
+ void testGet();
+ void testGetbyteArray();
+ void testGetbyteArray2();
+ void testGetWithIndex();
+ void testPutbyte();
+ void testPutbyteArray();
+ void testPutbyteArray2();
+ void testPutByteBuffer();
+ void testPutIndexed();
+ void testSlice();
+ void testToString();
};