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 2008/04/29 22:52:37 UTC
svn commit: r652104 [22/29] - in /activemq/activemq-cpp/trunk: ./ m4/
src/examples/ src/examples/consumers/ src/main/ src/main/decaf/
src/main/decaf/internal/ src/main/decaf/internal/net/
src/main/decaf/internal/nio/ src/main/decaf/internal/util/ src/m...
Added: activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/BufferFactoryTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/BufferFactoryTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/BufferFactoryTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/BufferFactoryTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,72 @@
+/*
+ * 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 "BufferFactoryTest.h"
+
+#include <decaf/nio/ByteBuffer.h>
+#include <decaf/nio/CharBuffer.h>
+#include <decaf/nio/DoubleBuffer.h>
+#include <decaf/nio/FloatBuffer.h>
+#include <decaf/nio/LongBuffer.h>
+#include <decaf/nio/IntBuffer.h>
+#include <decaf/nio/ShortBuffer.h>
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::nio;
+using namespace decaf::nio;
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferFactoryTest::testCreateByteBuffer1() {
+
+ ByteBuffer* buffer = BufferFactory::createByteBuffer( 500 );
+ CPPUNIT_ASSERT( buffer != NULL );
+ CPPUNIT_ASSERT( buffer->capacity() == 500 );
+ CPPUNIT_ASSERT( buffer->isReadOnly() == false );
+
+ delete buffer;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferFactoryTest::testCreateByteBuffer2() {
+
+ std::vector<unsigned char> array;
+ array.resize( 500 );
+ ByteBuffer* buffer = BufferFactory::createByteBuffer( array );
+ CPPUNIT_ASSERT( buffer != NULL );
+ CPPUNIT_ASSERT( buffer->hasArray() == true );
+ CPPUNIT_ASSERT( buffer->array() == &array[0] );
+ CPPUNIT_ASSERT( buffer->capacity() == 500 );
+ CPPUNIT_ASSERT( buffer->isReadOnly() == false );
+
+ delete buffer;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferFactoryTest::testCreateByteBuffer3() {
+
+ std::vector<unsigned char> array;
+ array.resize( 500 );
+ ByteBuffer* buffer = BufferFactory::createByteBuffer( &array[0], 100, 400 );
+ CPPUNIT_ASSERT( buffer != NULL );
+ CPPUNIT_ASSERT( buffer->hasArray() == true );
+ CPPUNIT_ASSERT( buffer->array() == &array[0] );
+ CPPUNIT_ASSERT( buffer->capacity() == 400 );
+ CPPUNIT_ASSERT( buffer->isReadOnly() == false );
+
+ delete buffer;
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/BufferFactoryTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/BufferFactoryTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/BufferFactoryTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/BufferFactoryTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,51 @@
+/*
+ * 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_INTERNAL_NIO_BUFFERFACTORYTEST_H_
+#define _DECAF_INTERNAL_NIO_BUFFERFACTORYTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/internal/nio/BufferFactory.h>
+
+namespace decaf{
+namespace internal{
+namespace nio{
+
+ class BufferFactoryTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( BufferFactoryTest );
+ CPPUNIT_TEST( testCreateByteBuffer1 );
+ CPPUNIT_TEST( testCreateByteBuffer2 );
+ CPPUNIT_TEST( testCreateByteBuffer3 );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ BufferFactoryTest() {}
+ virtual ~BufferFactoryTest() {}
+
+ void testCreateByteBuffer1();
+ void testCreateByteBuffer2();
+ void testCreateByteBuffer3();
+
+ };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_NIO_BUFFERFACTORYTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayBufferTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayBufferTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayBufferTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayBufferTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,1223 @@
+/*
+ * 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 "ByteArrayBufferTest.h"
+#include <decaf/lang/Integer.h>
+#include <decaf/lang/Double.h>
+#include <decaf/lang/Float.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::nio;
+using namespace decaf::internal::nio;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::test() {
+
+ // Check that we have setup the array and our initial assumptions on state
+ // are correct. This is the first test run.
+ CPPUNIT_ASSERT( testBuffer1 != NULL );
+ CPPUNIT_ASSERT( testBuffer1->capacity() == testData1Size );
+ CPPUNIT_ASSERT( testBuffer1->hasRemaining() == true );
+ CPPUNIT_ASSERT( testBuffer1->limit() == testBuffer1->capacity() );
+ CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+ CPPUNIT_ASSERT( testBuffer1->isReadOnly() == false );
+ CPPUNIT_ASSERT( testBuffer1->toString() != "" );
+ CPPUNIT_ASSERT( testBuffer1->hasArray() == true );
+ CPPUNIT_ASSERT( testBuffer1->array() != NULL );
+ CPPUNIT_ASSERT( testBuffer1->arrayOffset() == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testArray() {
+
+ 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 ByteArrayBufferTest::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;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testReadOnlyArray() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+
+ CPPUNIT_ASSERT( readOnly != NULL );
+ CPPUNIT_ASSERT( readOnly->isReadOnly() == true );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw UnsupportedOperationException",
+ readOnly->array(),
+ UnsupportedOperationException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw UnsupportedOperationException",
+ readOnly->arrayOffset(),
+ UnsupportedOperationException );
+
+ delete readOnly;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::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);
+
+ delete readOnly;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::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();
+
+ for( std::size_t ix = 0; ix < testData1Size; ++ix ){
+ testBuffer1->put( ix, testData1[ix] );
+ }
+
+ ByteBuffer& ret = testBuffer1->compact();
+
+ CPPUNIT_ASSERT( &ret == testBuffer1 );
+ CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->capacity() );
+ CPPUNIT_ASSERT( testBuffer1->limit() == testBuffer1->capacity() );
+
+ for( std::size_t ix = 0; 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 = 0; 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 = 0; 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 ByteArrayBufferTest::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;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testDuplicate() {
+
+ testBuffer1->clear();
+ testBuffer1->mark();
+ testBuffer1->position( testBuffer1->limit() );
+
+ for( std::size_t ix = 0; ix < testData1Size; ++ix ){
+ testBuffer1->put( ix, testData1[ix] );
+ }
+
+ // duplicate's contents should be the same as buf
+ ByteBuffer* duplicate = testBuffer1->duplicate();
+ CPPUNIT_ASSERT( testBuffer1 != duplicate );
+ CPPUNIT_ASSERT( testBuffer1->position() == duplicate->position() );
+ CPPUNIT_ASSERT( testBuffer1->limit() == duplicate->limit() );
+ CPPUNIT_ASSERT( testBuffer1->isReadOnly() == duplicate->isReadOnly() );
+
+ for( std::size_t ix = 0; ix < testBuffer1->capacity(); ix++ ) {
+ CPPUNIT_ASSERT( testBuffer1->get( ix ) == duplicate->get( ix ) );
+ }
+
+ // duplicate's position, mark, and limit should be independent to buf
+ duplicate->reset();
+ CPPUNIT_ASSERT( duplicate->position() == 0 );
+ duplicate->clear();
+ CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->limit() );
+ testBuffer1->reset();
+ CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+ delete duplicate;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testEquals() {
+
+ // equal to self
+ CPPUNIT_ASSERT( testBuffer1->equals( *testBuffer1 ) );
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ CPPUNIT_ASSERT( testBuffer1->equals( *readOnly ) );
+ ByteBuffer* duplicate = testBuffer1->duplicate();
+ CPPUNIT_ASSERT( testBuffer1->equals( *duplicate ) );
+
+ CPPUNIT_ASSERT( testBuffer1->capacity() > SMALL_TEST_LENGTH );
+
+ testBuffer1->limit( testBuffer1->capacity() ).position( 0 );
+ readOnly->limit( readOnly->capacity() ).position( 1 );
+ CPPUNIT_ASSERT( !testBuffer1->equals( *readOnly ) );
+
+ testBuffer1->limit( testBuffer1->capacity() - 1 ).position( 0 );
+ duplicate->limit( duplicate->capacity() ).position( 0 );
+ CPPUNIT_ASSERT( !testBuffer1->equals( *duplicate ) );
+
+ delete readOnly;
+ delete duplicate;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::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 ByteArrayBufferTest::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 ByteArrayBufferTest::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 = 0; ix < testBuffer1->capacity() - 1; ix++ ) {
+ CPPUNIT_ASSERT( testBuffer1->get( ix ) == array[ix] );
+ }
+
+ CPPUNIT_ASSERT( &ret == testBuffer1);
+
+ delete [] array;
+ delete [] array2;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::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 ByteArrayBufferTest::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( (unsigned char)i );
+ CPPUNIT_ASSERT( testBuffer1->get(i) == i );
+ CPPUNIT_ASSERT( &ret == testBuffer1 );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferOverflowException",
+ testBuffer1->put( 0 ),
+ BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::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] = (unsigned char)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 ByteArrayBufferTest::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 = 0; ix < testBuffer1->capacity() - 1; ix++ ) {
+ CPPUNIT_ASSERT( testBuffer1->get( ix ) == array[ix] );
+ }
+ CPPUNIT_ASSERT( &ret == testBuffer1 );
+
+ delete [] array;
+ delete [] array2;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::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 );
+ toBig->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 = 0; ix < testBuffer1->capacity() - 1; ix++ ) {
+ CPPUNIT_ASSERT( testBuffer1->get( ix ) == other->get( ix ) );
+ }
+ CPPUNIT_ASSERT( &ret == testBuffer1 );
+
+ delete other;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::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 ByteArrayBufferTest::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 ByteArrayBufferTest::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 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testGetChar() {
+
+ std::vector<char> chars;
+ for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+ testBuffer1->put( i, (char)i);
+ chars.push_back( (char)i );
+ }
+ testBuffer1->clear();
+
+ for( std::size_t i = 0; testBuffer1->remaining() != 0; i++ ) {
+ CPPUNIT_ASSERT( testBuffer1->getChar() == chars[i] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferUnderflowException",
+ testBuffer1->getChar(),
+ BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testGetChar2() {
+
+ std::vector<char> chars;
+ for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+ testBuffer1->put( i, (char)i);
+ chars.push_back( (char)i );
+ }
+ testBuffer1->clear();
+
+ for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+ CPPUNIT_ASSERT( testBuffer1->getChar( i ) == chars[i] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->getChar( testBuffer1->capacity() + 1 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testPutChar() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->putChar( (char)1 ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+
+ for( std::size_t i = 0; testBuffer1->remaining() > 0; i++ ) {
+
+ testBuffer1->mark();
+ testBuffer1->putChar( (char)i );
+ testBuffer1->reset();
+ CPPUNIT_ASSERT( testBuffer1->get() == (char)i );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferOverflowException",
+ testBuffer1->putChar( 'A' ),
+ BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testPutChar2() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->putChar( (char)1 ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+
+ std::size_t i = 0;
+ for( ; i < testBuffer1->capacity(); i++ ) {
+
+ testBuffer1->mark();
+ testBuffer1->putChar( i, (char)i );
+ testBuffer1->reset();
+ CPPUNIT_ASSERT( testBuffer1->get( i ) == (char)i );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->putChar( i, 'A' ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testGetDouble() {
+
+ std::vector<double> values;
+ for( std::size_t i = 0; i < testBuffer1->capacity() / sizeof( double ); i++ ) {
+ testBuffer1->putDouble( (double)i );
+ values.push_back( (double)i );
+ }
+ testBuffer1->clear();
+
+ for( std::size_t i = 0;
+ testBuffer1->remaining() >= sizeof( double ); i++ ) {
+
+ CPPUNIT_ASSERT( testBuffer1->getDouble() == values[i] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferUnderflowException",
+ testBuffer1->getDouble(),
+ BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testGetDouble2() {
+
+ std::vector<double> values;
+ for( std::size_t i = 0; i < testBuffer1->capacity() / sizeof( double ); i++ ) {
+ testBuffer1->putDouble( (double)i );
+ values.push_back( (double)i );
+ }
+ testBuffer1->clear();
+
+ std::size_t i = 0;
+ std::size_t j = 0;
+
+ for( ; ( testBuffer1->capacity() - i ) >= sizeof( double ); i += sizeof( double ), j++ ) {
+ CPPUNIT_ASSERT( testBuffer1->getDouble( i ) == values[j] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->getDouble( i ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testPutDouble() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->putDouble( 1.64684 ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+
+ for( std::size_t i = 0; testBuffer1->remaining() >= sizeof( double );
+ i += sizeof( double ) ) {
+
+ testBuffer1->mark();
+ testBuffer1->putDouble( i + 48.25136 );
+ testBuffer1->reset();
+ CPPUNIT_ASSERT( Double::doubleToLongBits( testBuffer1->getDouble() )==
+ Double::doubleToLongBits( 48.25136 + i ) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferOverflowException",
+ testBuffer1->putDouble( 3.14159 ),
+ BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testPutDouble2() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->putDouble( (double)1.004 ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+
+ std::size_t i = 0;
+ for( ; ( testBuffer1->capacity() - i ) >= sizeof( double ); i += sizeof( double ) ) {
+
+ testBuffer1->mark();
+ testBuffer1->putDouble( i, i + 99.99 );
+ testBuffer1->reset();
+ CPPUNIT_ASSERT( Double::doubleToLongBits( testBuffer1->getDouble( i ) )==
+ Double::doubleToLongBits( 99.99 + i ) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->putDouble( i, 3.14159 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testGetFloat() {
+
+ std::vector<float> values;
+ for( std::size_t i = 0; i < testBuffer1->capacity() / sizeof( float ); i++ ) {
+ testBuffer1->putFloat( (float)i );
+ values.push_back( (float)i );
+ }
+ testBuffer1->clear();
+
+ for( std::size_t i = 0;
+ testBuffer1->remaining() >= sizeof( float ); i++ ) {
+
+ CPPUNIT_ASSERT( testBuffer1->getFloat() == values[i] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferUnderflowException",
+ testBuffer1->getFloat(),
+ BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testGetFloat2() {
+
+ std::vector<float> values;
+ for( std::size_t i = 0; i < testBuffer1->capacity() / sizeof( float ); i++ ) {
+ testBuffer1->putFloat( (float)i );
+ values.push_back( (float)i );
+ }
+ testBuffer1->clear();
+
+ std::size_t i = 0;
+ std::size_t j = 0;
+
+ for( ; ( testBuffer1->capacity() - i ) >= sizeof( float ); i += sizeof( float ), j++ ) {
+ CPPUNIT_ASSERT( testBuffer1->getFloat( i ) == values[j] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->getFloat( i ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testPutFloat() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->putFloat( 1.64684f ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+
+ for( std::size_t i = 0; testBuffer1->remaining() >= sizeof( float );
+ i += sizeof( float ) ) {
+
+ testBuffer1->mark();
+ testBuffer1->putFloat( i + 48.25136f );
+ testBuffer1->reset();
+ CPPUNIT_ASSERT( Float::floatToIntBits( testBuffer1->getFloat() ) ==
+ Float::floatToIntBits( 48.25136f + i ) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferOverflowException",
+ testBuffer1->putFloat( 3.14159f ),
+ BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testPutFloat2() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->putFloat( (float)1.004f ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+
+ std::size_t i = 0;
+ for( ; ( testBuffer1->capacity() - i ) >= sizeof( float ); i += sizeof( float ) ) {
+
+ testBuffer1->mark();
+ testBuffer1->putFloat( i, i + 99.99f );
+ testBuffer1->reset();
+ CPPUNIT_ASSERT( Float::floatToIntBits( testBuffer1->getFloat( i ) )==
+ Float::floatToIntBits( 99.99f + i ) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->putFloat( i, 3.14159f ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testGetLong() {
+
+ std::vector<long long> values;
+ for( std::size_t i = 0; i < testBuffer1->capacity() / sizeof( long long ); i++ ) {
+ testBuffer1->putLong( (long long)i );
+ values.push_back( (long long)i );
+ }
+ testBuffer1->clear();
+
+ for( std::size_t i = 0;
+ testBuffer1->remaining() >= sizeof( long long ); i++ ) {
+
+ CPPUNIT_ASSERT( testBuffer1->getLong() == values[i] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferUnderflowException",
+ testBuffer1->getLong(),
+ BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testGetLong2() {
+
+ std::vector<long long> values;
+ for( std::size_t i = 0; i < testBuffer1->capacity() / sizeof( long long ); i++ ) {
+ testBuffer1->putLong( (long long)i );
+ values.push_back( (long long)i );
+ }
+ testBuffer1->clear();
+
+ std::size_t i = 0;
+ std::size_t j = 0;
+
+ for( ; ( testBuffer1->capacity() - i ) >= sizeof( long long ); i += sizeof( long long ), j++ ) {
+ CPPUNIT_ASSERT( testBuffer1->getLong( i ) == values[j] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->getLong( i ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testPutLong() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->putLong( 15474 ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+
+ for( std::size_t i = 0; testBuffer1->remaining() >= sizeof( long long );
+ i += sizeof( long long ) ) {
+
+ testBuffer1->mark();
+ testBuffer1->putLong( i + 48 );
+ testBuffer1->reset();
+ CPPUNIT_ASSERT( testBuffer1->getLong() == ( i + 48 ) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferOverflowException",
+ testBuffer1->putLong( 3 ),
+ BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testPutLong2() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->putLong( (long long)85 ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+
+ std::size_t i = 0;
+ for( ; ( testBuffer1->capacity() - i ) >= sizeof( long long ); i += sizeof( long long ) ) {
+
+ testBuffer1->mark();
+ testBuffer1->putLong( i, i + 99 );
+ testBuffer1->reset();
+ CPPUNIT_ASSERT( testBuffer1->getLong( i ) == i + 99 );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->putLong( i, 3 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testGetInt() {
+
+ std::vector<int> values;
+ for( std::size_t i = 0; i < testBuffer1->capacity() / sizeof( int ); i++ ) {
+ testBuffer1->putInt( (int)i );
+ values.push_back( (int)i );
+ }
+ testBuffer1->clear();
+
+ for( std::size_t i = 0;
+ testBuffer1->remaining() >= sizeof( int ); i++ ) {
+
+ CPPUNIT_ASSERT( testBuffer1->getInt() == values[i] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferUnderflowException",
+ testBuffer1->getInt(),
+ BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testGetInt2() {
+
+ std::vector<int> values;
+ for( std::size_t i = 0; i < testBuffer1->capacity() / sizeof( int ); i++ ) {
+ testBuffer1->putInt( (int)i );
+ values.push_back( (int)i );
+ }
+ testBuffer1->clear();
+
+ std::size_t i = 0;
+ std::size_t j = 0;
+
+ for( ; ( testBuffer1->capacity() - i ) >= sizeof( int ); i += sizeof( int ), j++ ) {
+ CPPUNIT_ASSERT( testBuffer1->getInt( i ) == values[j] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->getInt( i ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testPutInt() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->putInt( 15474 ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+
+ for( std::size_t i = 0; testBuffer1->remaining() >= sizeof( int );
+ i += sizeof( int ) ) {
+
+ testBuffer1->mark();
+ testBuffer1->putInt( i + 48 );
+ testBuffer1->reset();
+ CPPUNIT_ASSERT( testBuffer1->getInt() == (int)( i + 48 ) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferOverflowException",
+ testBuffer1->putInt( 3 ),
+ BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testPutInt2() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->putInt( (int)85 ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+
+ std::size_t i = 0;
+ for( ; ( testBuffer1->capacity() - i ) >= sizeof( int ); i += sizeof( int ) ) {
+
+ testBuffer1->mark();
+ testBuffer1->putInt( i, i + 99 );
+ testBuffer1->reset();
+ CPPUNIT_ASSERT( testBuffer1->getInt( i ) == (int)(i + 99) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->putInt( i, 3 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testGetShort() {
+
+ std::vector<short> values;
+ for( std::size_t i = 0; i < testBuffer1->capacity() / sizeof( short ); i++ ) {
+ testBuffer1->putShort( (short)i );
+ values.push_back( (short)i );
+ }
+ testBuffer1->clear();
+
+ for( std::size_t i = 0;
+ testBuffer1->remaining() >= sizeof( short ); i++ ) {
+
+ CPPUNIT_ASSERT( testBuffer1->getShort() == values[i] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferUnderflowException",
+ testBuffer1->getShort(),
+ BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testGetShort2() {
+
+ std::vector<short> values;
+ for( std::size_t i = 0; i < testBuffer1->capacity() / sizeof( short ); i++ ) {
+ testBuffer1->putShort( (short)i );
+ values.push_back( (short)i );
+ }
+ testBuffer1->clear();
+
+ std::size_t i = 0;
+ std::size_t j = 0;
+
+ for( ; ( testBuffer1->capacity() - i ) >= sizeof( short ); i += sizeof( short ), j++ ) {
+ CPPUNIT_ASSERT( testBuffer1->getShort( i ) == values[j] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->getShort( i ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testPutShort() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->putShort( 15474 ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+
+ for( std::size_t i = 0; testBuffer1->remaining() >= sizeof( short );
+ i += sizeof( short ) ) {
+
+ testBuffer1->mark();
+ testBuffer1->putShort( i + 48 );
+ testBuffer1->reset();
+ CPPUNIT_ASSERT( testBuffer1->getShort() == (short)( i + 48 ) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a BufferOverflowException",
+ testBuffer1->putShort( 3 ),
+ BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testPutShort2() {
+
+ ByteBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+ readOnly->clear();
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a ReadOnlyBufferException",
+ readOnly->putShort( (short)85 ),
+ ReadOnlyBufferException );
+ delete readOnly;
+
+ testBuffer1->clear();
+
+ std::size_t i = 0;
+ for( ; ( testBuffer1->capacity() - i ) >= sizeof( short ); i += sizeof( short ) ) {
+
+ testBuffer1->mark();
+ testBuffer1->putShort( i, i + 99 );
+ testBuffer1->reset();
+ CPPUNIT_ASSERT( testBuffer1->getShort( i ) == (short)(i + 99) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1->putShort( i, 3 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayBufferTest::testWrapNullArray() {
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a NullPointerException",
+ testBuffer1->wrap( NULL, 0, 3 ),
+ NullPointerException );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayBufferTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayBufferTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayBufferTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayBufferTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,158 @@
+/*
+ * 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_INTERNAL_NIO_BYTEBUFFERTEST_H_
+#define _DECAF_INTERNAL_NIO_BYTEBUFFERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/nio/ByteBuffer.h>
+
+namespace decaf{
+namespace internal{
+namespace nio{
+
+ class ByteArrayBufferTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( ByteArrayBufferTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST( testArray );
+ CPPUNIT_TEST( testArrayOffset );
+ CPPUNIT_TEST( testReadOnlyArray );
+ CPPUNIT_TEST( testAsReadOnlyBuffer );
+ CPPUNIT_TEST( testCompact );
+ 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( testGetChar );
+ CPPUNIT_TEST( testGetChar2 );
+ CPPUNIT_TEST( testPutChar );
+ CPPUNIT_TEST( testPutChar2 );
+ CPPUNIT_TEST( testGetDouble );
+ CPPUNIT_TEST( testGetDouble2 );
+ CPPUNIT_TEST( testPutDouble );
+ CPPUNIT_TEST( testPutDouble2 );
+ CPPUNIT_TEST( testGetFloat );
+ CPPUNIT_TEST( testGetFloat2 );
+ CPPUNIT_TEST( testPutFloat );
+ CPPUNIT_TEST( testPutFloat2 );
+ CPPUNIT_TEST( testGetLong );
+ CPPUNIT_TEST( testGetLong2 );
+ CPPUNIT_TEST( testPutLong );
+ CPPUNIT_TEST( testPutLong2 );
+ CPPUNIT_TEST( testGetInt );
+ CPPUNIT_TEST( testGetInt2 );
+ CPPUNIT_TEST( testPutInt );
+ CPPUNIT_TEST( testPutInt2 );
+ CPPUNIT_TEST( testGetShort );
+ CPPUNIT_TEST( testGetShort2 );
+ CPPUNIT_TEST( testPutShort );
+ CPPUNIT_TEST( testPutShort2 );
+ CPPUNIT_TEST( testWrapNullArray );
+ CPPUNIT_TEST_SUITE_END();
+
+ private:
+
+ decaf::nio::ByteBuffer* testBuffer1;
+ 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:
+
+ ByteArrayBufferTest() {}
+ virtual ~ByteArrayBufferTest() {}
+
+ void setUp() {
+ testBuffer1 = decaf::nio::ByteBuffer::allocate( testData1Size );
+
+ testData1 = new unsigned char[testData1Size];
+ for( std::size_t i = 0; i < testData1Size; ++i ){
+ testData1[i] = (unsigned char)i;
+ }
+ }
+
+ void tearDown() {
+ delete testBuffer1;
+ delete [] testData1;
+ }
+
+ void test();
+ void testArray();
+ void testArrayOffset();
+ void testReadOnlyArray();
+ void testAsReadOnlyBuffer();
+ void testCompact();
+ 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();
+ void testGetChar();
+ void testGetChar2();
+ void testPutChar();
+ void testPutChar2();
+ void testGetDouble();
+ void testGetDouble2();
+ void testPutDouble();
+ void testPutDouble2();
+ void testGetFloat();
+ void testGetFloat2();
+ void testPutFloat();
+ void testPutFloat2();
+ void testGetLong();
+ void testGetLong2();
+ void testPutLong();
+ void testPutLong2();
+ void testGetInt();
+ void testGetInt2();
+ void testPutInt();
+ void testPutInt2();
+ void testGetShort();
+ void testGetShort2();
+ void testPutShort();
+ void testPutShort2();
+ void testWrapNullArray();
+
+ };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_NIO_BYTEBUFFERTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayPerspectiveTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayPerspectiveTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayPerspectiveTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayPerspectiveTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,264 @@
+/*
+ * 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 "ByteArrayPerspectiveTest.h"
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::util;
+using namespace decaf::internal::nio;
+using namespace decaf::nio;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayPerspectiveTest::testReferences(){
+
+ ByteArrayPerspective array( (std::size_t)256 );
+ CPPUNIT_ASSERT( array.getReferences() == 1 );
+ array.takeRef();
+ CPPUNIT_ASSERT( array.getReferences() == 2 );
+ array.returnRef();
+ array.returnRef();
+ CPPUNIT_ASSERT( array.getReferences() == 0 );
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayPerspectiveTest::testRead(){
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayPerspective array( data, 256 );
+
+ CPPUNIT_ASSERT( array.getCapacity() == 256 );
+
+ unsigned char* result = new unsigned char[256];
+ array.read( result, 0, 256 );
+
+ for( int i = 0; i < 256; ++i ){
+ CPPUNIT_ASSERT( data[i] == result[i] );
+ }
+
+ delete [] data;
+ delete [] result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayPerspectiveTest::testWrite(){
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayPerspective array( (std::size_t)256 );
+
+ CPPUNIT_ASSERT( array.getCapacity() == 256 );
+
+ array.write( data, 0, 256 );
+ unsigned char* result = new unsigned char[256];
+ array.read( result, 0, 256 );
+
+ for( int i = 0; i < 256; ++i ){
+ CPPUNIT_ASSERT( data[i] == result[i] );
+ }
+
+ delete [] data;
+ delete [] result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayPerspectiveTest::testCtor1(){
+
+ ByteArrayPerspective array1( (std::size_t)256 );
+ CPPUNIT_ASSERT( array1.getCapacity() == 256 );
+ ByteArrayPerspective array2( (std::size_t)54 );
+ CPPUNIT_ASSERT( array2.getCapacity() == 54 );
+ ByteArrayPerspective array3( (std::size_t)5555 );
+ CPPUNIT_ASSERT( array3.getCapacity() == 5555 );
+ ByteArrayPerspective array4( (std::size_t)0 );
+ CPPUNIT_ASSERT( array4.getCapacity() == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayPerspectiveTest::testCtor2(){
+
+ unsigned char* data1 = new unsigned char[256];
+ unsigned char* data2 = new unsigned char[999];
+ unsigned char* data3 = new unsigned char[12];
+ unsigned char* data4 = new unsigned char[0];
+
+ ByteArrayPerspective array1( data1, 256, true );
+ ByteArrayPerspective array2( data2, 999, true );
+ ByteArrayPerspective array3( data3, 10, true );
+ ByteArrayPerspective array4( data4, 0, true );
+
+ CPPUNIT_ASSERT( array1.getCapacity() == 256 );
+ CPPUNIT_ASSERT( array2.getCapacity() == 999 );
+ CPPUNIT_ASSERT( array3.getCapacity() == 10 );
+ CPPUNIT_ASSERT( array4.getCapacity() == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayPerspectiveTest::testClear(){
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayPerspective array( (std::size_t)256 );
+
+ CPPUNIT_ASSERT( array.getCapacity() == 256 );
+
+ array.write( data, 0, 256 );
+ unsigned char* result = new unsigned char[256];
+ array.read( result, 0, 256 );
+
+ for( int i = 0; i < 256; ++i ){
+ CPPUNIT_ASSERT( data[i] == result[i] );
+ }
+
+ array.clear();
+ array.read( result, 0, 256 );
+
+ for( int i = 0; i < 256; ++i ){
+ CPPUNIT_ASSERT( result[i] == 0 );
+ }
+
+ delete [] data;
+ delete [] result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayPerspectiveTest::testReszie(){
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayPerspective array( (std::size_t)256 );
+
+ CPPUNIT_ASSERT( array.getCapacity() == 256 );
+
+ array.write( data, 0, 256 );
+ unsigned char* result = new unsigned char[256];
+ array.read( result, 0, 256 );
+
+ for( int i = 0; i < 256; ++i ){
+ CPPUNIT_ASSERT( data[i] == result[i] );
+ }
+
+ array.resize( 128 );
+ CPPUNIT_ASSERT( array.getCapacity() == 128 );
+ unsigned char* result2 = new unsigned char[128];
+ array.read( result2, 0, 128 );
+
+ for( int i = 0; i < 128; ++i ){
+ CPPUNIT_ASSERT( result[i] == data[i] );
+ }
+
+ delete [] data;
+ delete [] result;
+ delete [] result2;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayPerspectiveTest::testOperators(){
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayPerspective array( data, 256 );
+
+ CPPUNIT_ASSERT( array.getCapacity() == 256 );
+
+ for( int i = 0; i < 256; ++i ){
+ CPPUNIT_ASSERT( data[i] == array[i] );
+ }
+
+ delete [] data;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayPerspectiveTest::testReadExceptions() {
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayPerspective array( data, 256, true );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should Throw NullPointerException",
+ array.read( NULL, 0, 500 ),
+ NullPointerException );
+
+ unsigned char result[5000];
+ ByteArrayPerspective array2( 256 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should Throw BufferUnderflowException",
+ array.read( result, 0, 500 ),
+ BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayPerspectiveTest::testWriteExceptions() {
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayPerspective array( data, 256, true );
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should Throw NullPointerException",
+ array.write( NULL, 0, 500 ),
+ NullPointerException );
+
+ unsigned char result[5000];
+ ByteArrayPerspective array2( 256 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should Throw BufferOverflowException",
+ array.write( result, 0, 500 ),
+ BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayPerspectiveTest::testOperatorsExceptions() {
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayPerspective array( data, 256, true );
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should Throw IndexOutOfBoundsException",
+ array[9999],
+ IndexOutOfBoundsException );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayPerspectiveTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayPerspectiveTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayPerspectiveTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/internal/nio/ByteArrayPerspectiveTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,68 @@
+/*
+ * 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_INTERNAL_NIO_BYTEARRAYPERSPECTIVETEST_H_
+#define _DECAF_INTERNAL_NIO_BYTEARRAYPERSPECTIVETEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/internal/nio/ByteArrayPerspective.h>
+#include <decaf/util/Config.h>
+
+namespace decaf{
+namespace internal{
+namespace nio{
+
+ class ByteArrayPerspectiveTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( ByteArrayPerspectiveTest );
+ CPPUNIT_TEST( testReferences );
+ CPPUNIT_TEST( testRead );
+ CPPUNIT_TEST( testReadExceptions );
+ CPPUNIT_TEST( testWrite );
+ CPPUNIT_TEST( testWriteExceptions );
+ CPPUNIT_TEST( testCtor1 );
+ CPPUNIT_TEST( testCtor2 );
+ CPPUNIT_TEST( testClear );
+ CPPUNIT_TEST( testReszie );
+ CPPUNIT_TEST( testOperators );
+ CPPUNIT_TEST( testOperatorsExceptions );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ ByteArrayPerspectiveTest() {}
+ virtual ~ByteArrayPerspectiveTest() {}
+
+ virtual void testReferences();
+ virtual void testRead();
+ virtual void testWrite();
+ virtual void testCtor1();
+ virtual void testCtor2();
+ virtual void testClear();
+ virtual void testReszie();
+ virtual void testOperators();
+ virtual void testReadExceptions();
+ virtual void testWriteExceptions();
+ virtual void testOperatorsExceptions();
+
+ };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_NIO_BYTEARRAYPERSPECTIVETEST_H_*/