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 [25/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/util/ByteArrayAdapterTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,565 @@
+/*
+ * 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 "ByteArrayAdapterTest.h"
+
+#include <decaf/lang/Double.h>
+#include <decaf/lang/Float.h>
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::util;
+using namespace decaf::nio;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testArray() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ testBuffer1.write( testData1, 0, testData1Size );
+
+ for( std::size_t ix = 0; ix < testBuffer1.getCapacity(); ++ix ) {
+ CPPUNIT_ASSERT( testBuffer1.get( ix ) == testData1[ix] );
+ }
+
+ unsigned char* array = testBuffer1.getByteArray();
+ CPPUNIT_ASSERT( array != NULL );
+
+ for( std::size_t ix = 0; ix < testBuffer1.getCapacity(); ++ix ) {
+ CPPUNIT_ASSERT( array[ix] == testData1[ix] );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testRead(){
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayAdapter 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 ByteArrayAdapterTest::testWrite(){
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayAdapter 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 ByteArrayAdapterTest::testCtor1(){
+
+ ByteArrayAdapter array1( (std::size_t)256 );
+ CPPUNIT_ASSERT( array1.getCapacity() == 256 );
+ ByteArrayAdapter array2( (std::size_t)54 );
+ CPPUNIT_ASSERT( array2.getCapacity() == 54 );
+ ByteArrayAdapter array3( (std::size_t)5555 );
+ CPPUNIT_ASSERT( array3.getCapacity() == 5555 );
+ ByteArrayAdapter array4( (std::size_t)0 );
+ CPPUNIT_ASSERT( array4.getCapacity() == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::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];
+
+ ByteArrayAdapter array1( data1, 256, true );
+ ByteArrayAdapter array2( data2, 999, true );
+ ByteArrayAdapter array3( data3, 10, true );
+ ByteArrayAdapter 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 ByteArrayAdapterTest::testClear(){
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayAdapter 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 ByteArrayAdapterTest::testReszie(){
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayAdapter 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 ByteArrayAdapterTest::testOperators(){
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayAdapter array( data, 256 );
+
+ CPPUNIT_ASSERT( array.getCapacity() == 256 );
+
+ for( int i = 0; i < 256; ++i ){
+ CPPUNIT_ASSERT( data[i] == array[i] );
+ }
+
+ delete [] data;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testReadExceptions() {
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayAdapter array( data, 256, true );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should Throw NullPointerException",
+ array.read( NULL, 0, 500 ),
+ NullPointerException );
+
+ unsigned char result[5000];
+ ByteArrayAdapter array2( 256 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should Throw BufferUnderflowException",
+ array.read( result, 0, 500 ),
+ BufferUnderflowException );
+
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testWriteExceptions() {
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayAdapter array( data, 256, true );
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should Throw NullPointerException",
+ array.write( NULL, 0, 500 ),
+ NullPointerException );
+
+ unsigned char result[5000];
+ ByteArrayAdapter array2( 256 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should Throw BufferOverflowException",
+ array.write( result, 0, 500 ),
+ BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testOperatorsExceptions() {
+
+ unsigned char* data = new unsigned char[256];
+ for( int i = 0; i < 256; ++i ) {
+ data[i] = i;
+ }
+
+ ByteArrayAdapter array( data, 256, true );
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should Throw IndexOutOfBoundsException",
+ array[9999],
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPut() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::size_t i = 0;
+ for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(unsigned char); i+=sizeof(unsigned char) ) {
+ testBuffer1.put( i, (unsigned char)(i + 99) );
+ CPPUNIT_ASSERT( testBuffer1.get( i ) == (unsigned char)(i + 99) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.put( i, 3 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPutChar() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::size_t i = 0;
+ for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(char); i+=sizeof(char) ) {
+ testBuffer1.putChar( i, i + 99 );
+ CPPUNIT_ASSERT( testBuffer1.getChar( i ) == (char)(i + 99) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.putChar( i, 3 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPutLong() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::size_t i = 0;
+ for( ; i < testBuffer1.getLongCapacity(); ++i ) {
+ testBuffer1.putLong( i, i + 99 );
+ CPPUNIT_ASSERT( testBuffer1.getLong( i ) == (long long)(i + 99) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.putLong( i, 3 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPutInt() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::size_t i = 0;
+ for( ; i < testBuffer1.getIntCapacity(); ++i ) {
+ testBuffer1.putInt( i, i + 99 );
+ CPPUNIT_ASSERT( testBuffer1.getInt( i ) == (int)(i + 99) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.putInt( i, 3 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPutShort() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::size_t i = 0;
+ for( ; i < testBuffer1.getShortCapacity(); ++i ) {
+ testBuffer1.putShort( i, i + 99 );
+ CPPUNIT_ASSERT( testBuffer1.getShort( i ) == (short)(i + 99) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.putShort( i, 3 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPutDouble() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::size_t i = 0;
+ for( ; i < testBuffer1.getDoubleCapacity(); ++i ) {
+ testBuffer1.putDouble( i, i + 99.025 );
+ CPPUNIT_ASSERT( Double::doubleToLongBits( testBuffer1.getDouble( i ) ) ==
+ Double::doubleToLongBits( (double)(i + 99.025) ) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.putDouble( i, 3 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPutFloat() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::size_t i = 0;
+ for( ; i < testBuffer1.getFloatCapacity(); ++i ) {
+ testBuffer1.putFloat( i, i + 99.025 );
+ CPPUNIT_ASSERT( Float::floatToIntBits( testBuffer1.getFloat( i ) ) ==
+ Float::floatToIntBits( (float)(i + 99.025) ) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.putFloat( i, 3 ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGet() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::vector<unsigned char> values;
+ for( std::size_t i = 0; i < testBuffer1.getCapacity(); ++i ) {
+ testBuffer1.put( i, (unsigned char)i );
+ values.push_back( (unsigned char)i );
+ }
+
+ std::size_t i = 0;
+ std::size_t j = 0;
+
+ for( ; i < testBuffer1.getCapacity(); ++i, ++j ) {
+ CPPUNIT_ASSERT( testBuffer1.get( i ) == values[j] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.get( i ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGetChar() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::vector<char> values;
+ for( std::size_t i = 0; i < testBuffer1.getCapacity(); ++i ) {
+ testBuffer1.putChar( i, (char)i );
+ values.push_back( (char)i );
+ }
+
+ std::size_t i = 0;
+ std::size_t j = 0;
+
+ for( ; i < testBuffer1.getCapacity(); ++i, ++j ) {
+ CPPUNIT_ASSERT( testBuffer1.getChar( i ) == values[j] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.getChar( i ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGetShort() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::vector<short> values;
+ for( std::size_t i = 0; i < testBuffer1.getShortCapacity(); ++i ) {
+ testBuffer1.putShort( i, (short)i );
+ values.push_back( (short)i );
+ }
+
+ std::size_t i = 0;
+ std::size_t j = 0;
+
+ for( ; i < testBuffer1.getShortCapacity(); ++i, ++j ) {
+ CPPUNIT_ASSERT( testBuffer1.getShort( i ) == values[j] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.getShort( i ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGetInt() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::vector<int> values;
+ for( std::size_t i = 0; i < testBuffer1.getIntCapacity(); ++i ) {
+ testBuffer1.putInt( i, (int)i );
+ values.push_back( (int)i );
+ }
+
+ std::size_t i = 0;
+ std::size_t j = 0;
+
+ for( ; i < testBuffer1.getIntCapacity(); ++i, ++j ) {
+ CPPUNIT_ASSERT( testBuffer1.getInt( i ) == values[j] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.getInt( i ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGetLong() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::vector<long long> values;
+ for( std::size_t i = 0; i < testBuffer1.getLongCapacity(); ++i ) {
+ testBuffer1.putLong( i, (long long)i );
+ values.push_back( (long long)i );
+ }
+
+ std::size_t i = 0;
+ std::size_t j = 0;
+
+ for( ; i < testBuffer1.getLongCapacity(); ++i, ++j ) {
+ CPPUNIT_ASSERT( testBuffer1.getLong( i ) == values[j] );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.getLong( i ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGetFloat() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::vector<float> values;
+ for( std::size_t i = 0; i < testBuffer1.getFloatCapacity(); ++i ) {
+ testBuffer1.putFloat( i, (float)i + 0.025f );
+ values.push_back( (float)i + 0.025f );
+ }
+
+ std::size_t i = 0;
+ std::size_t j = 0;
+
+ for( ; i < testBuffer1.getFloatCapacity(); ++i, ++j ) {
+ CPPUNIT_ASSERT( Float::floatToIntBits( testBuffer1.getFloat( i ) ) ==
+ Float::floatToIntBits( values[j] ) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.getFloat( i ),
+ IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGetDouble() {
+
+ ByteArrayAdapter testBuffer1( testData1Size );
+
+ std::vector<double> values;
+ for( std::size_t i = 0; i < testBuffer1.getDoubleCapacity(); ++i ) {
+ testBuffer1.putDouble( i, (double)i + 0.025 );
+ values.push_back( (double)i + 0.025 );
+ }
+
+ std::size_t i = 0;
+ std::size_t j = 0;
+
+ for( ; i < testBuffer1.getDoubleCapacity(); ++i, ++j ) {
+ CPPUNIT_ASSERT( Double::doubleToLongBits( testBuffer1.getDouble( i ) ) ==
+ Double::doubleToLongBits( values[j] ) );
+ }
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should throw a IndexOutOfBoundsException",
+ testBuffer1.getDouble( i ),
+ IndexOutOfBoundsException );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,110 @@
+/*
+ * 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_UTIL_BYTEARRAYTEST_H_
+#define _DECAF_INTERNAL_UTIL_BYTEARRAYTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/internal/util/ByteArrayAdapter.h>
+#include <decaf/util/Config.h>
+
+namespace decaf{
+namespace internal{
+namespace util{
+
+ class ByteArrayAdapterTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( ByteArrayAdapterTest );
+ 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( testArray );
+ CPPUNIT_TEST( testGet );
+ CPPUNIT_TEST( testGetChar );
+ CPPUNIT_TEST( testGetShort );
+ CPPUNIT_TEST( testGetInt );
+ CPPUNIT_TEST( testGetLong );
+ CPPUNIT_TEST( testGetDouble );
+ CPPUNIT_TEST( testGetFloat );
+ CPPUNIT_TEST( testPut );
+ CPPUNIT_TEST( testPutChar );
+ CPPUNIT_TEST( testPutShort );
+ CPPUNIT_TEST( testPutInt );
+ CPPUNIT_TEST( testPutLong );
+ CPPUNIT_TEST( testPutDouble );
+ CPPUNIT_TEST( testPutFloat );
+ CPPUNIT_TEST_SUITE_END();
+
+ unsigned char* testData1;
+ static const std::size_t testData1Size = 100;
+
+ public:
+
+ ByteArrayAdapterTest() {}
+ virtual ~ByteArrayAdapterTest() {}
+
+ void setUp() {
+ testData1 = new unsigned char[testData1Size];
+ for( std::size_t i = 0; i < testData1Size; ++i ){
+ testData1[i] = (unsigned char)i;
+ }
+ }
+
+ void tearDown() {
+ delete [] testData1;
+ }
+
+ void testRead();
+ void testWrite();
+ void testCtor1();
+ void testCtor2();
+ void testClear();
+ void testReszie();
+ void testOperators();
+ void testReadExceptions();
+ void testWriteExceptions();
+ void testOperatorsExceptions();
+ void testArray();
+ void testGet();
+ void testGetChar();
+ void testGetShort();
+ void testGetInt();
+ void testGetLong();
+ void testGetDouble();
+ void testGetFloat();
+ void testPut();
+ void testPutChar();
+ void testPutShort();
+ void testPutInt();
+ void testPutLong();
+ void testPutDouble();
+ void testPutFloat();
+
+ };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_UTIL_BYTEARRAYTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedInputStreamTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedInputStreamTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedInputStreamTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,292 @@
+/*
+ * 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 "BufferedInputStreamTest.h"
+#include <decaf/io/ByteArrayInputStream.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::io;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStreamTest::testConstructor() {
+
+ std::string testStr = "TEST12345678910";
+ MyInputStream myStream( testStr );
+
+ // Test for method BufferedInputStream(InputStream, int)
+ bool exceptionFired = false;
+ try {
+
+ // Create buffer with exact size of data
+ BufferedInputStream is( &myStream, testStr.length() );
+
+ // Ensure buffer gets filled by evaluating one read
+ is.read();
+
+ // Read the remaining buffered characters, no IOException should
+ // occur.
+ is.skip( testStr.length() - 2 );
+ is.read();
+ try {
+ // is.read should now throw an exception because it will have to
+ // be filled.
+ is.read();
+ } catch (IOException& e) {
+ exceptionFired = true;
+ }
+
+ CPPUNIT_ASSERT_MESSAGE( "Exception should have been triggered by read()", exceptionFired );
+
+ } catch (IOException& e) {
+ e.printStackTrace();
+ CPPUNIT_ASSERT_MESSAGE("Exception during test_1_Constructor", false );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStreamTest::testAvailable() {
+
+ std::string testStr = "TEST12345678910";
+ MyInputStream myStream( testStr );
+ // Create buffer with exact size of data
+ BufferedInputStream is( &myStream, testStr.length() );
+
+ // Test for method int BufferedInputStream.available()
+ try {
+ CPPUNIT_ASSERT_MESSAGE( "Returned incorrect number of available bytes",
+ is.available() == testStr.length() );
+ } catch( IOException& e ) {
+ CPPUNIT_ASSERT_MESSAGE("Exception during available test", false );
+ }
+
+ // Test that a closed stream throws an IOE for available()
+ std::string testStr2 = "hello world";
+ MyInputStream myStream2( testStr2 );
+ BufferedInputStream bis( &myStream2, testStr2.length() );
+
+ std::size_t available;
+
+ try {
+ available = bis.available();
+ bis.close();
+ } catch( IOException& ex ) {
+ CPPUNIT_ASSERT(false);
+ return; // never reached.
+ }
+ CPPUNIT_ASSERT( available != 0 );
+
+ try {
+ bis.available();
+ CPPUNIT_ASSERT_MESSAGE("Expected test to throw IOE.", false );
+ } catch (IOException& ex) {
+ // expected
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStreamTest::testClose() {
+
+ try{
+ std::string testStr = "TEST12345678910";
+ MyInputStream myStream( testStr );
+
+ // Test for method void java.io.BufferedInputStream.close()
+ BufferedInputStream i1( &myStream );
+ BufferedInputStream i2( &myStream );
+
+ // Test a null stream
+ MyInputStream* ptr = NULL;
+ BufferedInputStream buf( ptr, (std::size_t)5 );
+ buf.close();
+ } catch(...) {
+ CPPUNIT_FAIL("Close shouldn't throw an error here" );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStreamTest::testRead() {
+
+ try {
+ // Test for method int BufferedInputStream.read()
+ std::string testStr = "TEST12345678910";
+ MyInputStream myStream( testStr );
+ // Create buffer with exact size of data
+ BufferedInputStream is( &myStream, testStr.length() );
+
+ char c = is.read();
+ CPPUNIT_ASSERT_MESSAGE( "read returned incorrect char",
+ c == testStr.at(0) );
+ } catch( IOException& e ) {
+ CPPUNIT_FAIL( "Exception during read test" );
+ }
+
+ unsigned char bytes[256];
+ for( int i = 0; i < 256; i++ ) {
+ bytes[i] = (unsigned char)i;
+ }
+
+ // New stream, owns the inner one.
+ BufferedInputStream is(
+ new ByteArrayInputStream( &bytes[0], (std::size_t)256 ), (std::size_t)12, true );
+
+ try {
+ CPPUNIT_ASSERT_MESSAGE( "Wrong initial byte", 0 == is.read() );
+ // Fill the buffer
+ unsigned char buf[14];
+ is.read( &buf[0], 0, (std::size_t)14 );
+
+ // Read greater than the buffer
+ CPPUNIT_ASSERT_MESSAGE( "Wrong block read data",
+ string( (const char*)&buf[0], 14 ) ==
+ string( (const char*)&bytes[1], 14 ) );
+
+ CPPUNIT_ASSERT_MESSAGE("Wrong bytes", 15 == is.read() ); // Check next byte
+
+ } catch( IOException& e ) {
+ CPPUNIT_FAIL("Exception during read test");
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStreamTest::testRead2() {
+
+ std::string testStr;
+ testStr.append( "A", 3000 );
+ testStr.append( "B", 1000 );
+ MyInputStream myStream( testStr );
+ // Create buffer with exact size of data
+ BufferedInputStream is( &myStream, testStr.length() );
+
+ // Test for method int BufferedInputStream.read(byte [], int,
+ // int)
+ unsigned char buf1[100];
+ try {
+ is.skip( 3000 );
+ is.read( buf1, 0, 100 );
+ CPPUNIT_ASSERT_MESSAGE(
+ "Failed to read correct data",
+ string( (const char*)&buf1[0], 100 ) == testStr.substr( 3000, 100 ) );
+
+ } catch (IOException& e) {
+ CPPUNIT_FAIL("Exception during read test");
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStreamTest::testReadException() {
+
+ BufferedInputStream bis( NULL );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw IOException",
+ bis.read( NULL, 0, (size_t)-1 ),
+ IOException );
+
+ bis.close();
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw IOException",
+ bis.read( NULL, 0, 1 ),
+ IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStreamTest::testSmallerBuffer(){
+
+ std::string testStr = "TEST12345678910";
+ MyInputStream myStream( testStr );
+ BufferedInputStream bufStream( &myStream, (std::size_t)1 );
+
+ std::size_t available = bufStream.available();
+ CPPUNIT_ASSERT( available == testStr.length() );
+
+ unsigned char dummy = bufStream.read();
+ CPPUNIT_ASSERT( dummy == 'T' );
+
+ available = bufStream.available();
+ CPPUNIT_ASSERT( available == (testStr.length() - 1) );
+
+ dummy = bufStream.read();
+ CPPUNIT_ASSERT( dummy == 'E' );
+
+ available = bufStream.available();
+ CPPUNIT_ASSERT( available == (testStr.length() - 2 ) );
+
+ dummy = bufStream.read();
+ CPPUNIT_ASSERT( dummy == 'S' );
+
+ available = bufStream.available();
+ CPPUNIT_ASSERT( available == (testStr.length() - 3 ) );
+
+ dummy = bufStream.read();
+ CPPUNIT_ASSERT( dummy == 'T' );
+
+ unsigned char dummyBuf[20];
+ memset( dummyBuf, 0, 20 );
+ std::size_t numRead = bufStream.read( dummyBuf, 0, 10 );
+ CPPUNIT_ASSERT( numRead == 10 );
+ CPPUNIT_ASSERT( strcmp( (char*)dummyBuf, "1234567891" ) == 0 );
+
+ available = bufStream.available();
+ CPPUNIT_ASSERT( available == 1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedInputStreamTest::testBiggerBuffer(){
+
+ std::string testStr = "TEST12345678910";
+ MyInputStream myStream( testStr );
+ BufferedInputStream bufStream( &myStream, (std::size_t)10 );
+
+ std::size_t available = bufStream.available();
+ CPPUNIT_ASSERT( available == testStr.length() );
+
+ unsigned char dummy = bufStream.read();
+ CPPUNIT_ASSERT( dummy == 'T' );
+
+ available = bufStream.available();
+ CPPUNIT_ASSERT( available == (testStr.length() - 1 ) );
+
+ dummy = bufStream.read();
+ CPPUNIT_ASSERT( dummy == 'E' );
+
+ available = bufStream.available();
+ CPPUNIT_ASSERT( available == (testStr.length() - 2 ) );
+
+ dummy = bufStream.read();
+ CPPUNIT_ASSERT( dummy == 'S' );
+
+ available = bufStream.available();
+ CPPUNIT_ASSERT( available == (testStr.length() - 3 ) );
+
+ dummy = bufStream.read();
+ CPPUNIT_ASSERT( dummy == 'T' );
+
+ unsigned char dummyBuf[20];
+ memset( dummyBuf, 0, 20 );
+ std::size_t numRead = bufStream.read( dummyBuf, 0, 10 );
+ CPPUNIT_ASSERT( numRead == 10 );
+ CPPUNIT_ASSERT( strcmp( (char*)dummyBuf, "1234567891" ) == 0 );
+
+ available = bufStream.available();
+ CPPUNIT_ASSERT( available == 1 );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedInputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedInputStreamTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedInputStreamTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedInputStreamTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,178 @@
+/*
+ * 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_IO_BUFFEREDINPUTSTREAMTEST_H_
+#define _DECAF_IO_BUFFEREDINPUTSTREAMTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/io/BufferedInputStream.h>
+#include <decaf/util/Config.h>
+
+namespace decaf{
+namespace io{
+
+ class BufferedInputStreamTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( BufferedInputStreamTest );
+ CPPUNIT_TEST( testSmallerBuffer );
+ CPPUNIT_TEST( testBiggerBuffer );
+ CPPUNIT_TEST( testConstructor );
+ CPPUNIT_TEST( testAvailable );
+ CPPUNIT_TEST( testClose );
+ CPPUNIT_TEST( testRead );
+ CPPUNIT_TEST( testRead2 );
+ CPPUNIT_TEST( testReadException );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ virtual ~BufferedInputStreamTest(){}
+ virtual void setUp(){}
+ virtual void tearDown(){}
+
+ void testSmallerBuffer();
+ void testBiggerBuffer();
+ void testConstructor();
+ void testAvailable();
+ void testClose();
+ void testRead();
+ void testReadException();
+ void testRead2();
+
+ public:
+
+ class MyInputStream : public InputStream{
+ private:
+ std::string data;
+ std::size_t pos;
+ bool throwOnRead;
+ bool closed;
+
+ public:
+
+ MyInputStream( const std::string& data ){
+ this->data = data;
+ this->pos = 0;
+ this->throwOnRead = false;
+ this->closed = false;
+ }
+ virtual ~MyInputStream(){}
+
+ void setThrowOnRead( bool value ) {
+ this->throwOnRead = value;
+ }
+
+ bool isThrowOnRead() const {
+ return this->throwOnRead;
+ }
+
+ bool isClosed() const {
+ return this->closed;
+ }
+
+ virtual std::size_t available() const throw (IOException){
+ if( isClosed() ) {
+ throw IOException(
+ __FILE__, __LINE__,
+ "MyInputStream::read - Stream already closed." );
+ }
+ std::size_t len = data.length();
+ return len - pos;
+ }
+
+ virtual unsigned char read() throw (IOException){
+ if( this->isThrowOnRead() ) {
+ throw IOException(
+ __FILE__, __LINE__,
+ "MyInputStream::read - Throw on Read on." );
+ }
+
+ if( pos >= data.length() ){
+ throw IOException();
+ }
+
+ return data.c_str()[pos++];
+ }
+
+ virtual int read( unsigned char* buffer,
+ std::size_t offset,
+ std::size_t bufferSize )
+ throw (IOException){
+
+ std::size_t numToRead = std::min( bufferSize, available() );
+
+ if( this->isThrowOnRead() ) {
+ throw IOException(
+ __FILE__, __LINE__,
+ "MyInputStream::read - Throw on Read on." );
+ }
+
+ // Simulate EOF
+ if( numToRead == 0 ) {
+ return -1;
+ }
+
+ const char* str = data.c_str();
+ for( std::size_t ix=0; ix<numToRead; ++ix ){
+ buffer[ix+offset] = str[pos+ix];
+ }
+
+ pos += numToRead;
+
+ return (int)numToRead;
+ }
+
+ virtual void close() throw(lang::Exception){
+ this->closed = true;
+ }
+ virtual std::size_t skip( std::size_t num ) throw ( io::IOException, lang::exceptions::UnsupportedOperationException ) {
+ return ( pos += std::min( num, available() ) );
+ }
+
+ virtual void mark( int readLimit DECAF_UNUSED ) {
+
+ }
+
+ virtual void reset() throw ( IOException ) {
+ throw IOException(
+ __FILE__, __LINE__,
+ "BufferedInputStream::reset - mark no yet supported." );
+ }
+
+ virtual bool markSupported() const{ return false; }
+
+ virtual void lock() throw(lang::Exception){
+ }
+ virtual void unlock() throw(lang::Exception){
+ }
+ virtual void wait() throw(lang::Exception){
+ }
+ virtual void wait(unsigned long millisecs DECAF_UNUSED) throw(lang::Exception){
+ }
+ virtual void notify() throw(lang::Exception){
+ }
+ virtual void notifyAll() throw(lang::Exception){
+ }
+ };
+
+ };
+
+}}
+
+#endif /*_DECAF_IO_BUFFEREDINPUTSTREAMTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedOutputStreamTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedOutputStreamTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedOutputStreamTest.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 "BufferedOutputStreamTest.h"
+#include <decaf/io/ByteArrayOutputStream.h>
+#include <decaf/io/ByteArrayInputStream.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::io;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testConstructor1() {
+
+ try {
+ MyOutputStream myStream;
+ BufferedOutputStream os( &myStream );
+ os.write( (unsigned char*)&testString[0], 0, 500 );
+ } catch( IOException& e ) {
+ CPPUNIT_FAIL("Constrcutor test failed");
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testConstructor2() {
+
+ try {
+ MyOutputStream myStream;
+ BufferedOutputStream os( &myStream, (std::size_t)1024 );
+ os.write( (unsigned char*)&testString[0], 0, 500 );
+ } catch( IOException& e) {
+ CPPUNIT_FAIL("IOException during Constrcutor test");
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testFlush() {
+
+ try {
+
+ ByteArrayOutputStream myStream;
+ BufferedOutputStream os( &myStream, (std::size_t)600 );
+ os.write( (unsigned char*)&testString[0], 0, 500 );
+ os.flush();
+ CPPUNIT_ASSERT_MESSAGE("Bytes not written after flush",
+ 500 == myStream.size() );
+ } catch( IOException& e) {
+ CPPUNIT_FAIL("Flush test failed");
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWrite() {
+
+ try {
+
+ ByteArrayOutputStream baos;
+ BufferedOutputStream os( &baos, (std::size_t)512 );
+ os.write( (unsigned char*)&testString[0], 0, 500 );
+
+ ByteArrayInputStream bais1( baos.toByteArray(), baos.size() );
+ CPPUNIT_ASSERT_MESSAGE( "Bytes written, not buffered", 0 == bais1.available());
+ os.flush();
+ ByteArrayInputStream bais2( baos.toByteArray(), baos.size() );
+ CPPUNIT_ASSERT_MESSAGE( "Bytes not written after flush", 500 == bais2.available() );
+ os.write( (unsigned char*)&testString[500], 0, 514 );
+ ByteArrayInputStream bais3( baos.toByteArray(), baos.size() );
+ CPPUNIT_ASSERT_MESSAGE( "Bytes not written when buffer full",
+ bais3.available() >= 1000);
+ unsigned char wbytes[1014] = {0};
+ bais3.read( wbytes, 0, 1013 );
+
+ CPPUNIT_ASSERT_MESSAGE(
+ "Incorrect bytes written",
+ testString.substr(0, 1012) == string( (const char*)wbytes ) );
+
+ } catch( IOException& e) {
+ CPPUNIT_FAIL("write test failed: ");
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWriteException() {
+
+ BufferedOutputStream bos( new ByteArrayOutputStream(), true );
+ unsigned char* nullByteArray = NULL;
+ unsigned char byteArray[10];
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw NullPointerException",
+ bos.write( nullByteArray, 0, (std::size_t)1 ),
+ NullPointerException );
+
+ bos.write( byteArray, 0, 0 );
+ bos.write( byteArray, 0, 1 );
+ bos.write( byteArray, 0, 10 );
+ bos.close();
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw IOException",
+ bos.write( nullByteArray, 0, (std::size_t)1 ),
+ IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWriteNullStreamNullArray() {
+
+ BufferedOutputStream bos( NULL );
+ unsigned char* nullByteArray = NULL;
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw NullPointerException",
+ bos.write( nullByteArray, 0, (std::size_t)1 ),
+ IOException );
+
+ CPPUNIT_ASSERT_NO_THROW_MESSAGE(
+ "should not throw NullPointerException",
+ bos.write( nullByteArray, 0, (std::size_t)0 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWriteNullStreamNullArraySize() {
+
+ BufferedOutputStream bos( NULL, (std::size_t)1 );
+ unsigned char* nullByteArray = NULL;
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw IOException",
+ bos.write( nullByteArray, 0, (std::size_t)1 ),
+ IOException );
+
+ CPPUNIT_ASSERT_NO_THROW_MESSAGE(
+ "should not throw NullPointerException",
+ bos.write( nullByteArray, 0, (std::size_t)0 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWriteNullStream() {
+
+ BufferedOutputStream bos( NULL );
+ unsigned char byteArray[10];
+
+ CPPUNIT_ASSERT_NO_THROW_MESSAGE(
+ "should not throw IOException",
+ bos.write( byteArray, 0, (std::size_t)0 ) );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw IOException",
+ bos.write( byteArray, 0, (std::size_t)1 ),
+ IOException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw IOException",
+ bos.write( byteArray, 0, (std::size_t)10 ),
+ IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWriteNullStreamSize() {
+
+ BufferedOutputStream bos( NULL, (std::size_t)1 );
+ unsigned char byteArray[10];
+
+ bos.write( byteArray, 0, 0 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw NullPointerException",
+ bos.write( byteArray, 0, 2 ),
+ IOException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw NullPointerException",
+ bos.write( byteArray, 0, 10 ),
+ IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testWriteI() {
+
+ try {
+
+ ByteArrayOutputStream baos;
+ BufferedOutputStream os( &baos );
+ os.write('t');
+ ByteArrayInputStream bais1( baos.toByteArray(), baos.size() );
+ CPPUNIT_ASSERT_MESSAGE( "Byte written, not buffered", 0 == bais1.available() );
+ os.flush();
+
+ ByteArrayInputStream bais2( baos.toByteArray(), baos.size() );
+ CPPUNIT_ASSERT_MESSAGE( "Byte not written after flush", 1 == bais2.available() );
+ unsigned char wbytes[10];
+ bais2.read( wbytes, 0, 1 );
+ CPPUNIT_ASSERT_MESSAGE( "Incorrect byte written", 't' == wbytes[0] );
+
+ } catch( IOException& e) {
+ CPPUNIT_FAIL("Write test failed");
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testSmallerBuffer(){
+
+ MyOutputStream myStream;
+ BufferedOutputStream bufStream( &myStream, (std::size_t)1 );
+
+ const char* buffer = myStream.getBuffer();
+
+ bufStream.write( (unsigned char)'T' );
+ // Should not be written yet.
+ CPPUNIT_ASSERT( strcmp( buffer, "" ) == 0 );
+
+ bufStream.write( (unsigned char)'E' );
+ // This time the T should have been written.
+ CPPUNIT_ASSERT( strcmp( buffer, "T" ) == 0 );
+
+ bufStream.write( (unsigned char*)"ST", 0, 2 );
+ // This time the ES should have been written.
+ CPPUNIT_ASSERT( strcmp( buffer, "TES" ) == 0 );
+
+ bufStream.flush();
+ CPPUNIT_ASSERT( strcmp( buffer, "TEST" ) == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferedOutputStreamTest::testBiggerBuffer(){
+
+ MyOutputStream myStream;
+ BufferedOutputStream bufStream( &myStream, (std::size_t)10 );
+
+ const char* buffer = myStream.getBuffer();
+
+ bufStream.write( (unsigned char*)"TEST", 0, 4 );
+
+ // Should not be written yet.
+ CPPUNIT_ASSERT( strcmp( buffer, "" ) == 0 );
+
+ bufStream.flush();
+ CPPUNIT_ASSERT( strcmp( buffer, "TEST" ) == 0 );
+
+ bufStream.write( (unsigned char*)"TEST", 0, 4 );
+ bufStream.write( (unsigned char*)"12345678910", 0, 11);
+
+ CPPUNIT_ASSERT( strcmp( buffer, "TESTTEST123456" ) == 0 );
+
+ bufStream.flush();
+ CPPUNIT_ASSERT( strcmp( buffer, "TESTTEST12345678910" ) == 0 );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedOutputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedOutputStreamTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedOutputStreamTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/BufferedOutputStreamTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,143 @@
+/*
+ * 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_IO_BUFFEREDOUTPUTSTREAMTEST_H_
+#define _DECAF_IO_BUFFEREDOUTPUTSTREAMTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/io/BufferedOutputStream.h>
+#include <decaf/util/Config.h>
+#include <string.h>
+
+namespace decaf{
+namespace io{
+
+ class BufferedOutputStreamTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( BufferedOutputStreamTest );
+ CPPUNIT_TEST( testSmallerBuffer );
+ CPPUNIT_TEST( testBiggerBuffer );
+ CPPUNIT_TEST( testConstructor1 );
+ CPPUNIT_TEST( testConstructor2 );
+ CPPUNIT_TEST( testFlush );
+ CPPUNIT_TEST( testWrite );
+ CPPUNIT_TEST( testWriteException );
+ CPPUNIT_TEST( testWriteNullStream );
+ CPPUNIT_TEST( testWriteNullStreamNullArray );
+ CPPUNIT_TEST( testWriteNullStreamNullArraySize );
+ CPPUNIT_TEST( testWriteNullStreamSize );
+ CPPUNIT_TEST( testWriteI );
+ CPPUNIT_TEST_SUITE_END();
+
+ std::string testString;
+
+ public:
+
+ virtual ~BufferedOutputStreamTest(){}
+ virtual void setUp(){
+ testString = "Test_All_Tests\nTest_decaf_io_BufferedInputStream\nTest_BufferedOutputStream\nTest_decaf_io_ByteArrayInputStream\nTest_decaf_io_ByteArrayOutputStream\nTest_decaf_io_DataInputStream\nTest_decaf_io_File\nTest_decaf_io_FileDescriptor\nTest_decaf_io_FileInputStream\nTest_decaf_io_FileNotFoundException\nTest_decaf_io_FileOutputStream\nTest_decaf_io_FilterInputStream\nTest_decaf_io_FilterOutputStream\nTest_decaf_io_InputStream\nTest_decaf_io_IOException\nTest_decaf_io_OutputStream\nTest_decaf_io_PrintStream\nTest_decaf_io_RandomAccessFile\nTest_decaf_io_SyncFailedException\nTest_decaf_lang_AbstractMethodError\nTest_decaf_lang_ArithmeticException\nTest_decaf_lang_ArrayIndexOutOfBoundsException\nTest_decaf_lang_ArrayStoreException\nTest_decaf_lang_Boolean\nTest_decaf_lang_Byte\nTest_decaf_lang_Character\nTest_decaf_lang_Class\nTest_decaf_lang_ClassCastException\nTest_decaf_lang_ClassCircularityError\nTest_decaf_lang_ClassFormatError\nTest_decaf_lang_ClassLo
ader\nTest_decaf_lang_ClassNotFoundException\nTest_decaf_lang_CloneNotSupportedException\nTest_decaf_lang_Double\nTest_decaf_lang_Error\nTest_decaf_lang_Exception\nTest_decaf_lang_ExceptionInInitializerError\nTest_decaf_lang_Float\nTest_decaf_lang_IllegalAccessError\nTest_decaf_lang_IllegalAccessException\nTest_decaf_lang_IllegalArgumentException\nTest_decaf_lang_IllegalMonitorStateException\nTest_decaf_lang_IllegalThreadStateException\nTest_decaf_lang_IncompatibleClassChangeError\nTest_decaf_lang_IndexOutOfBoundsException\nTest_decaf_lang_InstantiationError\nTest_decaf_lang_InstantiationException\nTest_decaf_lang_Integer\nTest_decaf_lang_InternalError\nTest_decaf_lang_InterruptedException\nTest_decaf_lang_LinkageError\nTest_decaf_lang_Long\nTest_decaf_lang_Math\nTest_decaf_lang_NegativeArraySizeException\nTest_decaf_lang_NoClassDefFoundError\nTest_decaf_lang_NoSuchFieldError\nTest_decaf_lang_NoSuchMethodError\nTest_decaf_lang_NullPointerException\nTest_decaf_lang_Number\nTe
st_decaf_lang_NumberFormatException\nTest_decaf_lang_Object\nTest_decaf_lang_OutOfMemoryError\nTest_decaf_lang_RuntimeException\nTest_decaf_lang_SecurityManager\nTest_decaf_lang_Short\nTest_decaf_lang_StackOverflowError\nTest_decaf_lang_String\nTest_decaf_lang_StringBuffer\nTest_decaf_lang_StringIndexOutOfBoundsException\nTest_decaf_lang_System\nTest_decaf_lang_Thread\nTest_decaf_lang_ThreadDeath\nTest_decaf_lang_ThreadGroup\nTest_decaf_lang_Throwable\nTest_decaf_lang_UnknownError\nTest_decaf_lang_UnsatisfiedLinkError\nTest_decaf_lang_VerifyError\nTest_decaf_lang_VirtualMachineError\nTest_decaf_lang_vm_Image\nTest_decaf_lang_vm_MemorySegment\nTest_decaf_lang_vm_ROMStoreException\nTest_decaf_lang_vm_VM\nTest_decaf_lang_Void\nTest_decaf_net_BindException\nTest_decaf_net_ConnectException\nTest_decaf_net_DatagramPacket\nTest_decaf_net_DatagramSocket\nTest_decaf_net_DatagramSocketImpl\nTest_decaf_net_InetAddress\nTest_decaf_net_NoRouteToHostException\nTest_decaf_net_PlainDatagram
SocketImpl\nTest_decaf_net_PlainSocketImpl\nTest_decaf_net_Socket\nTest_decaf_net_SocketException\nTest_decaf_net_SocketImpl\nTest_decaf_net_SocketInputStream\nTest_decaf_net_SocketOutputStream\nTest_decaf_net_UnknownHostException\nTest_decaf_util_ArrayEnumerator\nTest_decaf_util_Date\nTest_decaf_util_EventObject\nTest_decaf_util_HashEnumerator\nTest_decaf_util_Hashtable\nTest_decaf_util_Properties\nTest_decaf_util_ResourceBundle\nTest_decaf_util_tm\nTest_decaf_util_Vector\n";
+ }
+ virtual void tearDown(){}
+
+ void testSmallerBuffer();
+ void testBiggerBuffer();
+ void testConstructor1();
+ void testConstructor2();
+ void testFlush();
+ void testWrite();
+ void testWriteException();
+ void testWriteNullStreamNullArray();
+ void testWriteNullStreamNullArraySize();
+ void testWriteNullStream();
+ void testWriteNullStreamSize();
+ void testWriteI();
+
+ public:
+
+ class MyOutputStream : public OutputStream{
+ private:
+ char buffer[100];
+ std::size_t pos;
+ public:
+
+ MyOutputStream(){
+ pos = 0;
+ memset( buffer, 0, 100 );
+ }
+ virtual ~MyOutputStream(){}
+
+ const char* getBuffer() const{ return buffer; }
+
+ virtual void write( unsigned char c ) throw (IOException){
+ if( pos >= 100 ){
+ throw IOException();
+ }
+
+ buffer[pos++] = c;
+ }
+
+ virtual void write( const std::vector<unsigned char>& buffer )
+ throw ( IOException ) {
+
+ if( buffer.empty() ){
+ return;
+ }
+
+ this->write( &buffer[0], 0, buffer.size() );
+ }
+
+ virtual void write( const unsigned char* buffer,
+ std::size_t offset,
+ std::size_t len ) throw (IOException){
+
+ if( (pos + len) > 100 ){
+ throw IOException();
+ }
+
+ memcpy( this->buffer + pos, buffer+offset, len );
+
+ pos += len;
+ }
+
+ virtual void flush() throw (IOException){
+ }
+
+ virtual void close() throw(lang::Exception){
+ // do nothing.
+ }
+
+ virtual void lock() throw(lang::Exception){
+ }
+ virtual void unlock() throw(lang::Exception){
+ }
+ virtual void wait() throw(lang::Exception){
+ }
+ virtual void wait(unsigned long millisecs DECAF_UNUSED) throw(lang::Exception){
+ }
+ virtual void notify() throw(lang::Exception){
+ }
+ virtual void notifyAll() throw(lang::Exception){
+ }
+ };
+
+ };
+
+}}
+
+#endif /*_DECAF_IO_BUFFEREDOUTPUTSTREAMTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayInputStreamTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayInputStreamTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayInputStreamTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,244 @@
+/*
+ * 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 "ByteArrayInputStreamTest.h"
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::io;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testConstructor() {
+
+ std::vector<unsigned char> testBuffer;
+
+ testBuffer.push_back('t');
+ testBuffer.push_back('e');
+ testBuffer.push_back('s');
+ testBuffer.push_back('t');
+
+ ByteArrayInputStream stream_a( &testBuffer[0], testBuffer.size());
+ ByteArrayInputStream stream_b( testBuffer );
+
+ CPPUNIT_ASSERT_MESSAGE( "Unable to create ByteArrayInputStream",
+ stream_a.available() == testBuffer.size() );
+ CPPUNIT_ASSERT_MESSAGE( "Unable to create ByteArrayInputStream",
+ stream_b.available() == testBuffer.size() );
+
+ ByteArrayInputStream nullStream;
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "Should have thrown an IO Exception",
+ nullStream.read(),
+ IOException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testConstructor2() {
+
+ // Test for method ByteArrayInputStream(byte [], int, int)
+ std::vector<unsigned char> testBuffer;
+ for( int i = 0; i < 128; i++ ) {
+ testBuffer.push_back( (char)i );
+ }
+
+ ByteArrayInputStream bis( &testBuffer[0], 100 );
+
+ CPPUNIT_ASSERT_MESSAGE( "Unable to create ByteArrayInputStream",
+ 100 == bis.available() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testAvailable() {
+
+ // Test for method ByteArrayInputStream(byte [], int, int)
+ std::vector<unsigned char> testBuffer;
+ for( int i = 0; i < 128; i++ ) {
+ testBuffer.push_back( (char)i );
+ }
+
+ ByteArrayInputStream bis( &testBuffer[0], 128 );
+
+ CPPUNIT_ASSERT_MESSAGE( "Unable to create ByteArrayInputStream",
+ 128 == bis.available() );
+ for( int j = 0; j < 10; j++ ) {
+ bis.read();
+ }
+
+ // Test for method int ByteArrayInputStream.available()
+ CPPUNIT_ASSERT_MESSAGE( "Returned incorrect number of available bytes",
+ bis.available() == ( testBuffer.size() - 10 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testClose() {
+
+ std::vector<unsigned char> testBuffer;
+ for( int i = 0; i < 128; i++ ) {
+ testBuffer.push_back( (char)i );
+ }
+
+ ByteArrayInputStream is( testBuffer );
+
+ // Test for method void ByteArrayInputStream.close()
+ try {
+ is.read();
+ } catch( IOException& e ) {
+ CPPUNIT_FAIL("Failed reading from input stream");
+ }
+
+ try {
+ is.close();
+ } catch( IOException& e ) {
+ CPPUNIT_FAIL("Failed closing input stream");
+ }
+
+ try {
+ is.read();
+ } catch( Exception& e ) {
+ CPPUNIT_FAIL("Should be able to read from closed stream");
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testRead() {
+
+ try{
+
+ std::vector<unsigned char> testBuffer;
+ for( int i = 0; i < 128; i++ ) {
+ testBuffer.push_back( (char)i );
+ }
+
+ ByteArrayInputStream is( testBuffer );
+
+ // Test for method int ByteArrayInputStream.read()
+ int c = is.read();
+ is.reset();
+ CPPUNIT_ASSERT_MESSAGE( "read returned incorrect char",
+ c == testBuffer.at(0) );
+ } catch(...) {
+ CPPUNIT_FAIL( "Shouldn't get any exceptions in this test." );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testRead2() {
+
+ std::vector<unsigned char> testBuffer;
+ for( int i = 0; i < 128; i++ ) {
+ testBuffer.push_back( (char)i );
+ }
+
+ ByteArrayInputStream is( testBuffer );
+
+ unsigned char buf1[20];
+ is.skip(50);
+ is.read( buf1, 0, 20 );
+ CPPUNIT_ASSERT_MESSAGE(
+ "Failed to read correct data",
+ string( (const char*)buf1, 20 ) == string( (const char*)&testBuffer[50], 20) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testRead3() {
+
+ std::vector<unsigned char> testBuffer;
+ testBuffer.insert( testBuffer.end(), 10, 'a' );
+ ByteArrayInputStream is( testBuffer );
+
+ unsigned char buf[10];
+ memset( buf, 'b', 10 );
+ is.read( buf, 5, 5 );
+
+ CPPUNIT_ASSERT_MESSAGE(
+ "Failed to read correct data",
+ string( (const char*)buf, 10 ) == "bbbbbaaaaa" );
+
+ // Try for an EOF
+ is.skip( 5 );
+ CPPUNIT_ASSERT( is.read( buf, 5, 5 ) == -1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testSkip() {
+
+ std::vector<unsigned char> testBuffer;
+ for( int i = 0; i < 128; i++ ) {
+ testBuffer.push_back( (char)i );
+ }
+
+ ByteArrayInputStream is( testBuffer );
+
+ unsigned char buf1[10];
+ is.skip(100);
+ is.read( buf1, 0, 10 );
+
+ CPPUNIT_ASSERT_MESSAGE(
+ "Failed to skip to correct position",
+ string( (const char*)buf1, 10 ) == string( (const char*)&testBuffer[100], 10) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayInputStreamTest::testStream()
+{
+ std::vector<unsigned char> testBuffer;
+
+ testBuffer.push_back('t');
+ testBuffer.push_back('e');
+ testBuffer.push_back('s');
+ testBuffer.push_back('t');
+
+ ByteArrayInputStream stream_a(&testBuffer[0], testBuffer.size());
+
+ CPPUNIT_ASSERT( stream_a.available() == 4 );
+
+ char a = stream_a.read();
+ char b = stream_a.read();
+ char c = stream_a.read();
+ char d = stream_a.read();
+
+ CPPUNIT_ASSERT( a == 't' && b == 'e' && c == 's' && d == 't' );
+ CPPUNIT_ASSERT( stream_a.available() == 0 );
+
+ testBuffer.push_back('e');
+
+ stream_a.setByteArray(&testBuffer[0], testBuffer.size());
+
+ CPPUNIT_ASSERT( stream_a.available() == 5 );
+
+ unsigned char* buffer = new unsigned char[6];
+
+ buffer[5] = '\0';
+
+ CPPUNIT_ASSERT( stream_a.read(buffer, 0, 5) == 5 );
+ CPPUNIT_ASSERT( std::string((const char*)buffer) == std::string("teste") );
+ CPPUNIT_ASSERT( stream_a.available() == 0 );
+
+ stream_a.setByteArray(&testBuffer[0], testBuffer.size());
+
+ memset(buffer, 0, 6);
+
+ CPPUNIT_ASSERT( stream_a.read(buffer, 0, 3) == 3 );
+ CPPUNIT_ASSERT( stream_a.read(&buffer[3], 0, 2) == 2 );
+ CPPUNIT_ASSERT( std::string((const char*)buffer) == std::string("teste") );
+
+ stream_a.close();
+
+ delete [] buffer;
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayInputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayInputStreamTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayInputStreamTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayInputStreamTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,62 @@
+/*
+ * 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_IO_BYTEARRAYINPUTSTREAMTEST_H_
+#define _DECAF_IO_BYTEARRAYINPUTSTREAMTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/io/ByteArrayInputStream.h>
+
+namespace decaf{
+namespace io{
+
+ class ByteArrayInputStreamTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( ByteArrayInputStreamTest );
+ CPPUNIT_TEST( testStream );
+ CPPUNIT_TEST( testConstructor );
+ CPPUNIT_TEST( testConstructor2 );
+ CPPUNIT_TEST( testAvailable );
+ CPPUNIT_TEST( testClose );
+ CPPUNIT_TEST( testRead );
+ CPPUNIT_TEST( testRead2 );
+ CPPUNIT_TEST( testRead3 );
+ CPPUNIT_TEST( testSkip );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ ByteArrayInputStreamTest() {}
+ virtual ~ByteArrayInputStreamTest() {}
+
+ void testStream();
+ void testConstructor();
+ void testConstructor2();
+ void testAvailable();
+ void testClose();
+ void testRead();
+ void testRead2();
+ void testRead3();
+ void testSkip();
+
+ };
+
+}}
+
+#endif /*_DECAF_IO_BYTEARRAYINPUTSTREAMTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,153 @@
+/*
+ * 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 "ByteArrayOutputStreamTest.h"
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::io;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testConstructor1() {
+ std::vector<unsigned char> buffer;
+ ByteArrayOutputStream baos( buffer );
+ CPPUNIT_ASSERT_MESSAGE("Failed to create stream", 0 == baos.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testConstructor2() {
+ ByteArrayOutputStream baos;
+ CPPUNIT_ASSERT_MESSAGE("Failed to create stream", 0 == baos.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testClose() {
+
+ CPPUNIT_ASSERT_MESSAGE(
+ "close() does nothing for this implementation of OutputSteam",
+ true );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testReset() {
+ ByteArrayOutputStream baos;
+ baos.write( (unsigned char*)&testString[0], 0, 100 );
+ baos.reset();
+ CPPUNIT_ASSERT_MESSAGE("reset failed", 0 == baos.size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testSize() {
+ ByteArrayOutputStream baos;
+ baos.write( (unsigned char*)&testString[0], 0, 100 );
+ CPPUNIT_ASSERT_MESSAGE("size test failed", 100 == baos.size());
+ baos.reset();
+ CPPUNIT_ASSERT_MESSAGE("size test failed", 0 == baos.size());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testToByteArray() {
+ const unsigned char* bytes = NULL;
+ ByteArrayOutputStream baos;
+ baos.write( (unsigned char*)&testString[0], 0, testString.length() );
+ bytes = baos.toByteArray();
+ for( std::size_t i = 0; i < testString.length(); i++) {
+ CPPUNIT_ASSERT_MESSAGE("Error in byte array", bytes[i] == testString.at(i) );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testToString() {
+
+ ByteArrayOutputStream baos;
+ baos.write( (unsigned char*)&testString[0], 0, testString.length() );
+ CPPUNIT_ASSERT_MESSAGE( "Returned incorrect String",
+ baos.toString() == testString );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testWrite1() {
+
+ ByteArrayOutputStream baos;
+ baos.write('t');
+ const unsigned char* bytes = baos.toByteArray();
+ CPPUNIT_ASSERT_MESSAGE( "Wrote incorrect bytes",
+ string("t") == string( (const char*)bytes, baos.size() ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testWrite2() {
+ ByteArrayOutputStream baos;
+ baos.write( (unsigned char*)&testString[0], 0, 100 );
+ const unsigned char* bytes = baos.toByteArray();
+ CPPUNIT_ASSERT_MESSAGE("Wrote incorrect bytes",
+ string((const char*)bytes, baos.size() ) == testString.substr(0, 100) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testWrite3() {
+ ByteArrayOutputStream baos;
+ baos.write( (unsigned char*)&testString[0], 50, 100 );
+ const unsigned char* bytes = baos.toByteArray();
+ CPPUNIT_ASSERT_MESSAGE("Wrote incorrect bytes",
+ string((const char*)bytes, baos.size() ) == testString.substr(50, 100) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testWriteToDecaf_io_OutputStream() {
+ ByteArrayOutputStream baos1;
+ ByteArrayOutputStream baos2;
+ baos1.write( (unsigned char*)&testString[0], 0, 100 );
+ baos1.writeTo( &baos2 );
+ CPPUNIT_ASSERT_MESSAGE( "Returned incorrect String",
+ baos2.toString() == testString.substr(0, 100) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayOutputStreamTest::testStream()
+{
+ ByteArrayOutputStream stream_a;
+
+ stream_a.write('a');
+ stream_a.write(60);
+ stream_a.write('c');
+
+ CPPUNIT_ASSERT( stream_a.size() == 3 );
+
+ stream_a.reset();
+
+ CPPUNIT_ASSERT( stream_a.size() == 0 );
+
+ stream_a.write((const unsigned char*)("abc"), 0, 3);
+
+ CPPUNIT_ASSERT( stream_a.size() == 3 );
+
+ stream_a.reset();
+
+ CPPUNIT_ASSERT( stream_a.size() == 0 );
+
+ stream_a.write((const unsigned char*)("abc"), 0, 3);
+
+ unsigned char buffer[4];
+
+ memset(buffer, 0, 4);
+ memcpy(buffer, stream_a.toByteArray(), stream_a.size());
+
+ CPPUNIT_ASSERT( std::string((const char*)buffer) == std::string("abc") );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/ByteArrayOutputStreamTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,74 @@
+/*
+ * 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_IO_BYTEARRAYOUTPUTSTREAMTEST_H_
+#define _DECAF_IO_BYTEARRAYOUTPUTSTREAMTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/io/ByteArrayOutputStream.h>
+
+namespace decaf{
+namespace io{
+
+ class ByteArrayOutputStreamTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( ByteArrayOutputStreamTest );
+ CPPUNIT_TEST( testStream );
+ CPPUNIT_TEST( testConstructor1 );
+ CPPUNIT_TEST( testConstructor2 );
+ CPPUNIT_TEST( testClose );
+ CPPUNIT_TEST( testReset );
+ CPPUNIT_TEST( testSize );
+ CPPUNIT_TEST( testToByteArray );
+ CPPUNIT_TEST( testToString );
+ CPPUNIT_TEST( testWrite1 );
+ CPPUNIT_TEST( testWrite2 );
+ CPPUNIT_TEST( testWrite3 );
+ CPPUNIT_TEST( testWriteToDecaf_io_OutputStream );
+ CPPUNIT_TEST_SUITE_END();
+
+ std::string testString;
+
+ public:
+
+ ByteArrayOutputStreamTest() {}
+ virtual ~ByteArrayOutputStreamTest() {}
+ virtual void setUp(){
+ testString = "Test_All_Tests\nTest_decaf_io_BufferedInputStream\nTest_BufferedOutputStream\nTest_decaf_io_ByteArrayInputStream\nTest_decaf_io_ByteArrayOutputStream\nTest_decaf_io_DataInputStream\nTest_decaf_io_File\nTest_decaf_io_FileDescriptor\nTest_decaf_io_FileInputStream\nTest_decaf_io_FileNotFoundException\nTest_decaf_io_FileOutputStream\nTest_decaf_io_FilterInputStream\nTest_decaf_io_FilterOutputStream\nTest_decaf_io_InputStream\nTest_decaf_io_IOException\nTest_decaf_io_OutputStream\nTest_decaf_io_PrintStream\nTest_decaf_io_RandomAccessFile\nTest_decaf_io_SyncFailedException\nTest_decaf_lang_AbstractMethodError\nTest_decaf_lang_ArithmeticException\nTest_decaf_lang_ArrayIndexOutOfBoundsException\nTest_decaf_lang_ArrayStoreException\nTest_decaf_lang_Boolean\nTest_decaf_lang_Byte\nTest_decaf_lang_Character\nTest_decaf_lang_Class\nTest_decaf_lang_ClassCastException\nTest_decaf_lang_ClassCircularityError\nTest_decaf_lang_ClassFormatError\nTest_decaf_lang_ClassLo
ader\nTest_decaf_lang_ClassNotFoundException\nTest_decaf_lang_CloneNotSupportedException\nTest_decaf_lang_Double\nTest_decaf_lang_Error\nTest_decaf_lang_Exception\nTest_decaf_lang_ExceptionInInitializerError\nTest_decaf_lang_Float\nTest_decaf_lang_IllegalAccessError\nTest_decaf_lang_IllegalAccessException\nTest_decaf_lang_IllegalArgumentException\nTest_decaf_lang_IllegalMonitorStateException\nTest_decaf_lang_IllegalThreadStateException\nTest_decaf_lang_IncompatibleClassChangeError\nTest_decaf_lang_IndexOutOfBoundsException\nTest_decaf_lang_InstantiationError\nTest_decaf_lang_InstantiationException\nTest_decaf_lang_Integer\nTest_decaf_lang_InternalError\nTest_decaf_lang_InterruptedException\nTest_decaf_lang_LinkageError\nTest_decaf_lang_Long\nTest_decaf_lang_Math\nTest_decaf_lang_NegativeArraySizeException\nTest_decaf_lang_NoClassDefFoundError\nTest_decaf_lang_NoSuchFieldError\nTest_decaf_lang_NoSuchMethodError\nTest_decaf_lang_NullPointerException\nTest_decaf_lang_Number\nTe
st_decaf_lang_NumberFormatException\nTest_decaf_lang_Object\nTest_decaf_lang_OutOfMemoryError\nTest_decaf_lang_RuntimeException\nTest_decaf_lang_SecurityManager\nTest_decaf_lang_Short\nTest_decaf_lang_StackOverflowError\nTest_decaf_lang_String\nTest_decaf_lang_StringBuffer\nTest_decaf_lang_StringIndexOutOfBoundsException\nTest_decaf_lang_System\nTest_decaf_lang_Thread\nTest_decaf_lang_ThreadDeath\nTest_decaf_lang_ThreadGroup\nTest_decaf_lang_Throwable\nTest_decaf_lang_UnknownError\nTest_decaf_lang_UnsatisfiedLinkError\nTest_decaf_lang_VerifyError\nTest_decaf_lang_VirtualMachineError\nTest_decaf_lang_vm_Image\nTest_decaf_lang_vm_MemorySegment\nTest_decaf_lang_vm_ROMStoreException\nTest_decaf_lang_vm_VM\nTest_decaf_lang_Void\nTest_decaf_net_BindException\nTest_decaf_net_ConnectException\nTest_decaf_net_DatagramPacket\nTest_decaf_net_DatagramSocket\nTest_decaf_net_DatagramSocketImpl\nTest_decaf_net_InetAddress\nTest_decaf_net_NoRouteToHostException\nTest_decaf_net_PlainDatagram
SocketImpl\nTest_decaf_net_PlainSocketImpl\nTest_decaf_net_Socket\nTest_decaf_net_SocketException\nTest_decaf_net_SocketImpl\nTest_decaf_net_SocketInputStream\nTest_decaf_net_SocketOutputStream\nTest_decaf_net_UnknownHostException\nTest_decaf_util_ArrayEnumerator\nTest_decaf_util_Date\nTest_decaf_util_EventObject\nTest_decaf_util_HashEnumerator\nTest_decaf_util_Hashtable\nTest_decaf_util_Properties\nTest_decaf_util_ResourceBundle\nTest_decaf_util_tm\nTest_decaf_util_Vector\n";
+ }
+ virtual void tearDown(){}
+
+ void testStream();
+ void testConstructor1();
+ void testConstructor2();
+ void testClose();
+ void testReset();
+ void testSize();
+ void testToByteArray();
+ void testToString();
+ void testWrite1();
+ void testWrite2();
+ void testWrite3();
+ void testWriteToDecaf_io_OutputStream();
+
+ };
+
+}}
+
+#endif /*_DECAF_IO_BYTEARRAYOUTPUTSTREAMTEST_H_*/