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 [26/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/io/DataInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/DataInputStreamTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/DataInputStreamTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/DataInputStreamTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,518 @@
+/*
+ * 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 "DataInputStreamTest.h"
+
+#include <decaf/lang/Integer.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 DataInputStreamTest::testConstructor() {
+
+ try {
+
+ os->writeChar('t');
+ os->close();
+ openDataInputStream();
+ } catch (IOException e) {
+ CPPUNIT_FAIL("IOException during constructor test : " + e.getMessage());
+ }
+
+ try {
+ is->close();
+ } catch (IOException e) {
+ CPPUNIT_FAIL("IOException during constructor test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::testRead1() {
+
+ try {
+
+ std::vector<unsigned char> test( testData.begin(), testData.end() );
+ os->write( test );
+ os->close();
+ openDataInputStream();
+ std::vector<unsigned char> result;
+ result.resize( testData.length() );
+ is->read( result );
+ CPPUNIT_ASSERT_MESSAGE( "Incorrect data read",
+ string( (const char*)&result[0], result.size() ) == testData );
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("IOException during read test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::testRead2() {
+ try {
+
+ os->write( std::vector<unsigned char>( testData.begin(), testData.end() ) );
+ os->close();
+ openDataInputStream();
+ unsigned char* result = new unsigned char[ testData.length() ];
+ is->read( result, 0, testData.length() );
+ CPPUNIT_ASSERT_MESSAGE("Incorrect data read",
+ string( (const char*)result, testData.size() ) == testData );
+ delete [] result;
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("IOException during read test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readBoolean() {
+
+ try {
+ os->writeBoolean(true);
+ os->close();
+ openDataInputStream();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect boolean written", is->readBoolean() );
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("readBoolean test failed : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readByte() {
+ try {
+ os->writeByte( (unsigned char) 127);
+ os->close();
+ openDataInputStream();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect byte read", is->readByte() == (unsigned char) 127);
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("IOException during readByte test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readChar() {
+ try {
+ os->writeChar('t');
+ os->close();
+ openDataInputStream();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect char read", 't' == is->readChar());
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("IOException during readChar test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readDouble() {
+ try {
+ os->writeDouble(2345.76834720202);
+ os->close();
+ openDataInputStream();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect double read",
+ 2345.76834720202 == is->readDouble());
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("IOException during readDouble test" + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readFloat() {
+ try {
+ os->writeFloat(29.08764f);
+ os->close();
+ openDataInputStream();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect float read", is->readFloat() == 29.08764f);
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("readFloat test failed : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readFully1() {
+ try {
+ os->write( std::vector<unsigned char>( testData.begin(), testData.end() ) );
+ os->close();
+ openDataInputStream();
+ std::vector<unsigned char> result;
+ result.resize( testData.length() );
+ is->readFully( result );
+ CPPUNIT_ASSERT_MESSAGE( "Incorrect data read",
+ string( (const char*)&result[0], 0, result.size() ) == testData );
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("IOException during readFully test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readFully2() {
+
+ try {
+ os->write( std::vector<unsigned char>( testData.begin(), testData.end() ) );
+ os->close();
+ openDataInputStream();
+ unsigned char* rbytes = new unsigned char[ testData.length() ];
+ is->readFully( rbytes, 0, testData.length() );
+ CPPUNIT_ASSERT_MESSAGE("Incorrect data read",
+ string( (const char*)rbytes, 0, testData.length() ) == testData );
+ delete [] rbytes;
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("IOException during readFully test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readFullyNullArray() {
+ std::vector<unsigned char> test( 5000 );
+ DataInputStream is(
+ new ByteArrayInputStream( test ), true );
+
+ unsigned char* nullByteArray = NULL;
+
+ is.readFully( nullByteArray, 0, 0);
+ is.readFully( nullByteArray, 1, 0);
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw NullPointerException",
+ is.readFully( nullByteArray, 0, 1),
+ NullPointerException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw NullPointerException",
+ is.readFully( nullByteArray, 1, 1),
+ NullPointerException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw NullPointerException",
+ is.readFully( nullByteArray, 1, Integer::MAX_VALUE),
+ NullPointerException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readFullyNullStream() {
+
+ DataInputStream is(NULL);
+ unsigned char* byteArray = new unsigned char[testData.length()];
+
+ is.readFully( byteArray, 0, 0 );
+ is.readFully( byteArray, 1, 0 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw NullPointerException",
+ is.readFully( byteArray, 1, 1 ),
+ NullPointerException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw NullPointerException",
+ is.readFully( byteArray, 0, 1 ),
+ NullPointerException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw NullPointerException",
+ is.readFully( byteArray, 0, Integer::MAX_VALUE ),
+ NullPointerException );
+
+ delete [] byteArray;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readFullyNullStreamNullArray() {
+
+ DataInputStream is(NULL);
+ unsigned char* nullByteArray = NULL;
+
+ is.readFully( nullByteArray, 0, 0 );
+ is.readFully( nullByteArray, 1, 0 );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw NullPointerException",
+ is.readFully( nullByteArray, 0, 1),
+ NullPointerException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw NullPointerException",
+ is.readFully( nullByteArray, 1, 1),
+ NullPointerException );
+
+ CPPUNIT_ASSERT_THROW_MESSAGE(
+ "should throw NullPointerException",
+ is.readFully( nullByteArray, 1, Integer::MAX_VALUE),
+ NullPointerException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readInt() {
+ try {
+ os->writeInt(768347202);
+ os->close();
+ openDataInputStream();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect int read", 768347202 == is->readInt());
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("IOException during readInt test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readLong() {
+ try {
+ os->writeLong(9875645283333LL);
+ os->close();
+ openDataInputStream();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect long read", 9875645283333LL == is->readLong());
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("read long test failed : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readShort() {
+ try {
+ os->writeShort(9875);
+ os->close();
+ openDataInputStream();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect short read", is->readShort() == (short) 9875);
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during read short test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readUnsignedByte() {
+ try {
+ os->writeByte((unsigned char) -127);
+ os->close();
+ openDataInputStream();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect byte read", 129 == is->readUnsignedByte());
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("IOException during readUnsignedByte test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_readUnsignedShort() {
+ os->writeShort(9875);
+ os->close();
+ openDataInputStream();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect short read", 9875 == is->readUnsignedShort());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test_skipBytes() {
+ try {
+ os->write( std::vector<unsigned char>( testData.begin(), testData.end() ) );
+ os->close();
+ openDataInputStream();
+ is->skip( 100 );
+ std::vector<unsigned char> result( 50 );
+ is->read( result );
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect data read",
+ string( (const char*)&result[0], 50) == testData.substr( 100, 50) );
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("IOException during skipBytes test 1 : " + e.getMessage());
+ }
+ try {
+
+ std::size_t skipped = 0;
+ openDataInputStream();
+
+ CPPUNIT_ASSERT_NO_THROW_MESSAGE(
+ "Should throw an EOFException",
+ skipped = is->skip( 500000 ) );
+
+ CPPUNIT_ASSERT_MESSAGE(
+ "Skipped should report " +
+ Integer::toString( (int)testData.length() ) + " not " +
+ Integer::toString( (int)skipped ),
+ skipped == testData.length() );
+
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("IOException during skipBytes test 2 : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::test(){
+
+ unsigned char buffer[30];
+ int ix = 0;
+
+ unsigned char byteVal = (unsigned char)'T';
+ unsigned short shortVal = 5;
+ unsigned int intVal = 10000;
+ unsigned long long longVal = 1000000000;
+ float floatVal = 10.0f;
+ double doubleVal = 100.0;
+ unsigned char arrayVal[3] = {
+ 'a', 'b', 'c'
+ };
+
+ int size = sizeof(char);
+ memcpy( (char*)(buffer+ix), (char*)&byteVal, size );
+ ix += size;
+
+ size = sizeof(unsigned short);
+ unsigned short tempShort = util::Endian::byteSwap(shortVal);
+ memcpy( (char*)(buffer+ix), (char*)&tempShort, size );
+ ix += size;
+
+ size = sizeof(unsigned int);
+ unsigned int tempInt = util::Endian::byteSwap(intVal);
+ memcpy( (char*)(buffer+ix), (char*)&tempInt, size );
+ ix += size;
+
+ size = sizeof(unsigned long long);
+ unsigned long long tempLong = util::Endian::byteSwap(longVal);
+ memcpy( (char*)(buffer+ix), (char*)&tempLong, size );
+ ix += size;
+
+ size = sizeof(float);
+ float tempFloat = util::Endian::byteSwap(floatVal);
+ memcpy( (char*)(buffer+ix), (char*)&tempFloat, size );
+ ix += size;
+
+ size = sizeof(double);
+ double tempDouble = util::Endian::byteSwap(doubleVal);
+ memcpy( (char*)(buffer+ix), (char*)&tempDouble, size );
+ ix += size;
+
+ size = 3;
+ memcpy( (char*)(buffer+ix), (char*)&arrayVal, size );
+ ix += size;
+
+ // Create the stream with the buffer we just wrote to.
+ ByteArrayInputStream myStream( buffer, 30 );
+ DataInputStream reader( &myStream );
+
+ byteVal = reader.readByte();
+ //std::cout << "Byte Value = " << byteVal << std::endl;
+ CPPUNIT_ASSERT( byteVal == (unsigned char)'T' );
+
+ shortVal = reader.readShort();
+ //std::cout << "short Value = " << shortVal << std::endl;
+ CPPUNIT_ASSERT( shortVal == 5 );
+
+ intVal = reader.readInt();
+ //std::cout << "int Value = " << intVal << std::endl;
+ CPPUNIT_ASSERT( intVal == 10000 );
+
+ longVal = reader.readLong();
+ //std::cout << "long long Value = " << longVal << std::endl;
+ CPPUNIT_ASSERT( longVal == 1000000000 );
+
+ floatVal = reader.readFloat();
+ //std::cout << "float Value = " << floatVal << std::endl;
+ CPPUNIT_ASSERT( floatVal == 10.0f );
+
+ doubleVal = reader.readDouble();
+ //std::cout << "double Value = " << doubleVal << std::endl;
+ CPPUNIT_ASSERT( doubleVal == 100.0 );
+
+ reader.read( arrayVal, 0, 3 );
+ //std::cout << "char[0] Value = " << (int)arrayVal[0] << std::endl;
+ CPPUNIT_ASSERT( arrayVal[0] == 'a' );
+ //std::cout << "char[1] Value = " << (int)arrayVal[1] << std::endl;
+ CPPUNIT_ASSERT( arrayVal[1] == 'b' );
+ //std::cout << "char[2] Value = " << (int)arrayVal[2] << std::endl;
+ CPPUNIT_ASSERT( arrayVal[2] == 'c' );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::testString() {
+
+ std::string data1 = "This is a Test";
+ std::string data2 = "of the readString method";
+ std::string data3 = "This one should fail";
+
+ std::vector<unsigned char> buffer;
+
+ buffer.insert( buffer.begin(), data1.begin(), data1.end() );
+ buffer.push_back( '\0' );
+ buffer.insert( buffer.end(), data2.begin(), data2.end() );
+ buffer.push_back( '\0' );
+ buffer.insert( buffer.end(), data3.begin(), data3.end() );
+
+ // Create the stream with the buffer we just wrote to.
+ ByteArrayInputStream myStream( buffer );
+ DataInputStream reader( &myStream );
+
+ std::string result1 = reader.readString();
+ std::string result2 = reader.readString();
+
+ CPPUNIT_ASSERT( result1 == data1 );
+ CPPUNIT_ASSERT( result2 == data2 );
+
+ try{
+ std::string result3 = reader.readString();
+ CPPUNIT_ASSERT( false );
+ } catch(...){
+ CPPUNIT_ASSERT( true );
+ }
+
+ try{
+ std::vector<unsigned char> buffer2;
+ reader.readFully( buffer2 );
+ } catch(...){
+ CPPUNIT_ASSERT( false );
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataInputStreamTest::testUTF() {
+
+ std::string data1 = "This is a Test";
+ std::string data2 = "of the readString method";
+ std::string data3 = "This one should fail";
+
+ char sizeData[sizeof(short)] = {0};
+ short tempShort = 0;
+
+ std::vector<unsigned char> buffer;
+
+ tempShort = util::Endian::byteSwap( ((unsigned short)data1.size()) );
+ memcpy( sizeData, (char*)&tempShort, sizeof( short ) );
+ buffer.insert( buffer.end(), sizeData, sizeData + sizeof(short) );
+ buffer.insert( buffer.end(), data1.begin(), data1.end() );
+
+ tempShort = util::Endian::byteSwap( ((unsigned short)data2.size()) );
+ memcpy( sizeData, (char*)&tempShort, sizeof( short ) );
+ buffer.insert( buffer.end(), sizeData, sizeData + sizeof(short) );
+ buffer.insert( buffer.end(), data2.begin(), data2.end() );
+
+ tempShort = util::Endian::byteSwap( (unsigned short)(data3.size() + 10 ) );
+ memcpy( sizeData, (char*)&tempShort, sizeof( short ) );
+ buffer.insert( buffer.end(), sizeData, sizeData + sizeof(short) );
+ buffer.insert( buffer.end(), data3.begin(), data3.end() );
+
+ // Create the stream with the buffer we just wrote to.
+ ByteArrayInputStream myStream( buffer );
+ DataInputStream reader( &myStream );
+
+ std::string result1 = reader.readUTF();
+ std::string result2 = reader.readUTF();
+
+ CPPUNIT_ASSERT( result1 == data1 );
+ CPPUNIT_ASSERT( result2 == data2 );
+
+ try{
+ std::string result3 = reader.readUTF();
+ CPPUNIT_ASSERT( false );
+ } catch(...){
+ CPPUNIT_ASSERT( true );
+ }
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/DataInputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/DataInputStreamTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/DataInputStreamTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/DataInputStreamTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,126 @@
+/*
+ * 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_DATAINPUTSTREAMTEST_H_
+#define _DECAF_IO_DATAINPUTSTREAMTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/util/Endian.h>
+#include <decaf/lang/Exception.h>
+#include <decaf/io/ByteArrayInputStream.h>
+#include <decaf/io/ByteArrayOutputStream.h>
+#include <decaf/io/DataInputStream.h>
+#include <decaf/io/DataOutputStream.h>
+#include <algorithm>
+
+namespace decaf{
+namespace io{
+
+ class DataInputStreamTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( DataInputStreamTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST( testString );
+ CPPUNIT_TEST( testUTF );
+ CPPUNIT_TEST( testConstructor );
+ CPPUNIT_TEST( testRead1 );
+ CPPUNIT_TEST( testRead2 );
+ CPPUNIT_TEST( test_readBoolean );
+ CPPUNIT_TEST( test_readByte );
+ CPPUNIT_TEST( test_readChar );
+ CPPUNIT_TEST( test_readDouble );
+ CPPUNIT_TEST( test_readFloat );
+ CPPUNIT_TEST( test_readFully1 );
+ CPPUNIT_TEST( test_readFully2 );
+ CPPUNIT_TEST( test_readFullyNullArray );
+ CPPUNIT_TEST( test_readFullyNullStream );
+ CPPUNIT_TEST( test_readFullyNullStreamNullArray );
+ CPPUNIT_TEST( test_readInt );
+ CPPUNIT_TEST( test_readLong );
+ CPPUNIT_TEST( test_readShort );
+ CPPUNIT_TEST( test_readUnsignedByte );
+ CPPUNIT_TEST( test_readUnsignedShort );
+ CPPUNIT_TEST( test_skipBytes );
+ CPPUNIT_TEST_SUITE_END();
+
+ ByteArrayOutputStream* baos;
+ ByteArrayInputStream* bais;
+
+ DataOutputStream* os;
+ DataInputStream* is;
+
+ std::string testData;
+
+ public:
+
+ virtual ~DataInputStreamTest(){}
+ virtual void setUp(){
+ testData = "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_ClassLoad
er\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\nTest
_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_PlainDatagramSo
cketImpl\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";
+ baos = new ByteArrayOutputStream();
+ os = new DataOutputStream( baos );
+ is = NULL;
+ bais = NULL;
+ }
+ virtual void tearDown(){
+ try {
+ delete os;
+ delete baos;
+ delete is;
+ delete bais;
+ } catch(...) {}
+ }
+
+ void test();
+ void testString();
+ void testUTF();
+ void testConstructor();
+ void testRead1();
+ void testRead2();
+ void test_readBoolean();
+ void test_readByte();
+ void test_readChar();
+ void test_readDouble();
+ void test_readFloat();
+ void test_readFully1();
+ void test_readFully2();
+ void test_readFullyNullArray();
+ void test_readFullyNullStream();
+ void test_readFullyNullStreamNullArray();
+ void test_readInt();
+ void test_readLong();
+ void test_readShort();
+ void test_readUnsignedByte();
+ void test_readUnsignedShort();
+ void test_skipBytes();
+
+ private:
+
+ void openDataInputStream() {
+ delete bais;
+ delete is;
+
+ bais = new ByteArrayInputStream( baos->toByteArray(), baos->size() );
+ is = new DataInputStream( bais );
+ }
+
+ };
+
+}}
+
+#endif /*_DECAF_IO_DATAINPUTSTREAMTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/DataOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/DataOutputStreamTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/DataOutputStreamTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/DataOutputStreamTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,314 @@
+/*
+ * 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 "DataOutputStreamTest.h"
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::io;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testFlush() {
+
+ try {
+ os->writeInt(9087589);
+ os->flush();
+ openDataInputStream();
+ int c = is->readInt();
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Failed to flush correctly", 9087589 == c);
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during flush test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testSize() {
+
+ try {
+ os->write( (unsigned char*)&testData[0], 0, 150 );
+ os->close();
+ openDataInputStream();
+ unsigned char rbuf[150];
+ is->read( rbuf, 0, 150 );
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect size returned", 150 == os->size());
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during write test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWrite1() {
+
+ try {
+ os->write( (unsigned char*)&testData[0], 0, 150 );
+ os->close();
+ openDataInputStream();
+ unsigned char* rbuf = new unsigned char[150];
+ is->read(rbuf, 0, 150);
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect bytes written",
+ string( (const char*)rbuf, 150 ) == testData.substr( 0, 150 ) );
+ delete [] rbuf;
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during write test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWrite2() {
+
+ try {
+ os->write( 't' );
+ os->close();
+ openDataInputStream();
+ char c = is->readChar();
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect int written", 't' == c);
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during write test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteBoolean() {
+
+ try {
+ os->writeBoolean(true);
+ os->close();
+ openDataInputStream();
+ bool c = is->readBoolean();
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect boolean written", c );
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during writeBoolean test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteByte() {
+ try {
+ os->writeByte( (unsigned char) 127 );
+ os->close();
+ openDataInputStream();
+ unsigned char c = is->readByte();
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect unsigned char written", c == (unsigned char) 127);
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during writeByte test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteBytes() {
+
+ try {
+ os->writeBytes( testData );
+ os->close();
+ openDataInputStream();
+ std::vector<unsigned char> result( testData.size() );
+ is->read( result );
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect bytes written",
+ string( (const char*)&result[0], result.size() ) == testData );
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during writeBytes test : " + e.getMessage());
+ }
+
+ // regression test for HARMONY-1101
+ DataOutputStream tester(NULL);
+ tester.writeBytes("");
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteChar() {
+ try {
+ os->writeChar('T');
+ os->close();
+ openDataInputStream();
+ char c = is->readChar();
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect char written", 'T' == c );
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during writeChar test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteChars() {
+
+ try {
+ os->writeChars( testData );
+ os->close();
+ openDataInputStream();
+ std::vector<unsigned char> result( testData.size() );
+ is->read( result );
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect bytes written",
+ string( (const char*)&result[0], result.size() ) == testData );
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during writeChars test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteDouble() {
+ try {
+ os->writeDouble(908755555456.98);
+ os->close();
+ openDataInputStream();
+ double c = is->readDouble();
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect double written", 908755555456.98 == c);
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during writeDouble test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteFloat() {
+ try {
+ os->writeFloat(9087.456f);
+ os->close();
+ openDataInputStream();
+ float c = is->readFloat();
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect float written", c == 9087.456f);
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during writeFloattest : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteInt() {
+ try {
+ os->writeInt(9087589);
+ os->close();
+ openDataInputStream();
+ int c = is->readInt();
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect int written", 9087589 == c);
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during writeInt test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteLong() {
+ try {
+ os->writeLong(908755555456LL);
+ os->close();
+ openDataInputStream();
+ long long c = is->readLong();
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect long written", 908755555456LL == c);
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during writeLong test" + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteShort() {
+ try {
+ os->writeShort((short) 9087);
+ os->close();
+ openDataInputStream();
+ short c = is->readShort();
+ is->close();
+ CPPUNIT_ASSERT_MESSAGE("Incorrect short written", 9087 == c);
+ } catch( IOException &e ) {
+ CPPUNIT_FAIL("Exception during writeShort test : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::testWriteUTF() {
+ string testString = "test string one";
+ os->writeUTF( testString );
+ os->close();
+ openDataInputStream();
+ CPPUNIT_ASSERT_MESSAGE("Failed to write string in UTF format",
+ is->available() == testString.length() + 2 );
+ CPPUNIT_ASSERT_MESSAGE("Incorrect string returned",
+ is->readUTF() == testString );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DataOutputStreamTest::test(){
+
+ unsigned char byteVal = (unsigned char)'T';
+ unsigned short shortVal = 5;
+ unsigned int intVal = 10000;
+ unsigned long long longVal = 1000000000;
+ float floatVal = 10.0f;
+ double doubleVal = 100.0;
+ unsigned char arrayVal[3] = {
+ 'a', 'b', 'c'
+ };
+
+ // Create the stream with the buffer we just wrote to.
+ ByteArrayOutputStream myStream;
+ DataOutputStream writer( &myStream );
+
+ writer.writeByte( byteVal );
+ writer.writeShort( shortVal );
+ writer.writeInt( intVal );
+ writer.writeLong( longVal );
+ writer.writeFloat( floatVal );
+ writer.writeDouble( doubleVal );
+ writer.write( arrayVal, 0, 3 );
+
+ const unsigned char* buffer = myStream.toByteArray();
+ int ix = 0;
+
+ unsigned char tempByte = buffer[ix];
+ CPPUNIT_ASSERT( tempByte == byteVal );
+ ix += sizeof( tempByte );
+
+ unsigned short tempShort = 0;
+ memcpy( &tempShort, buffer+ix, sizeof( unsigned short ) );
+ tempShort = util::Endian::byteSwap( tempShort );
+ CPPUNIT_ASSERT( tempShort == shortVal );
+ ix += sizeof( tempShort );
+
+ unsigned int tempInt = 0;
+ memcpy( &tempInt, buffer+ix, sizeof( unsigned int ) );
+ tempInt = util::Endian::byteSwap( tempInt );
+ CPPUNIT_ASSERT( tempInt == intVal );
+ ix += sizeof( tempInt );
+
+ unsigned long long tempLong = 0;
+ memcpy( &tempLong, buffer+ix, sizeof( unsigned long long ) );
+ tempLong = util::Endian::byteSwap( tempLong );
+ CPPUNIT_ASSERT( tempLong == longVal );
+ ix += sizeof( tempLong );
+
+ float tempFloat = 0;
+ memcpy( &tempFloat, buffer+ix, sizeof( float ) );
+ tempFloat = util::Endian::byteSwap( tempFloat );
+ CPPUNIT_ASSERT( tempFloat == floatVal );
+ ix += sizeof( tempFloat );
+
+ double tempDouble = 0;
+ memcpy( &tempDouble, buffer+ix, sizeof( double ) );
+ tempDouble = util::Endian::byteSwap( tempDouble );
+ CPPUNIT_ASSERT( tempDouble == doubleVal );
+ ix += sizeof( tempDouble );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/DataOutputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/DataOutputStreamTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/DataOutputStreamTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/DataOutputStreamTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,109 @@
+/*
+ * 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_DATAOUTPUTSTREAMTEST_H_
+#define _DECAF_IO_DATAOUTPUTSTREAMTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/util/Endian.h>
+#include <decaf/io/DataOutputStream.h>
+#include <decaf/io/DataInputStream.h>
+#include <decaf/io/ByteArrayOutputStream.h>
+#include <decaf/io/ByteArrayInputStream.h>
+
+namespace decaf{
+namespace io{
+
+ class DataOutputStreamTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( DataOutputStreamTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST( testFlush );
+ CPPUNIT_TEST( testSize );
+ CPPUNIT_TEST( testWrite1 );
+ CPPUNIT_TEST( testWrite2 );
+ CPPUNIT_TEST( testWriteBoolean );
+ CPPUNIT_TEST( testWriteByte );
+ CPPUNIT_TEST( testWriteBytes );
+ CPPUNIT_TEST( testWriteChar );
+ CPPUNIT_TEST( testWriteChars );
+ CPPUNIT_TEST( testWriteDouble );
+ CPPUNIT_TEST( testWriteFloat );
+ CPPUNIT_TEST( testWriteInt );
+ CPPUNIT_TEST( testWriteLong );
+ CPPUNIT_TEST( testWriteShort );
+ CPPUNIT_TEST( testWriteUTF );
+ CPPUNIT_TEST_SUITE_END();
+
+ ByteArrayOutputStream* baos;
+ ByteArrayInputStream* bais;
+
+ DataOutputStream* os;
+ DataInputStream* is;
+
+ std::string testData;
+
+ public:
+
+ virtual ~DataOutputStreamTest(){}
+ virtual void setUp(){
+ testData = "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_ClassLoad
er\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\nTest
_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_PlainDatagramSo
cketImpl\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";
+ baos = new ByteArrayOutputStream();
+ os = new DataOutputStream( baos );
+ is = NULL;
+ bais = NULL;
+ }
+ virtual void tearDown(){
+ try {
+ delete os;
+ delete baos;
+ delete is;
+ delete bais;
+ } catch(...) {}
+ }
+
+ void test();
+ void testFlush();
+ void testSize();
+ void testWrite1();
+ void testWrite2();
+ void testWriteBoolean();
+ void testWriteByte();
+ void testWriteBytes();
+ void testWriteChar();
+ void testWriteChars();
+ void testWriteDouble();
+ void testWriteFloat();
+ void testWriteInt();
+ void testWriteLong();
+ void testWriteShort();
+ void testWriteUTF();
+
+ private:
+
+ void openDataInputStream() {
+ bais = new ByteArrayInputStream( baos->toByteArray(), baos->size() );
+ is = new DataInputStream( bais );
+ }
+
+ };
+
+}}
+
+#endif /*_DECAF_IO_DATAOUTPUTSTREAMTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/FilterInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/FilterInputStreamTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/FilterInputStreamTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/FilterInputStreamTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,117 @@
+/*
+ * 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 "FilterInputStreamTest.h"
+#include <decaf/io/ByteArrayInputStream.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::io;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+void FilterInputStreamTest::testAvailable() {
+
+ std::string testStr = "TEST12345678910";
+ MyInputStream myStream( testStr );
+ FilterInputStream is( &myStream );
+
+ CPPUNIT_ASSERT_MESSAGE( "Returned incorrect number of available bytes",
+ is.available() == testStr.length() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FilterInputStreamTest::testClose() {
+
+ std::string testStr = "TEST12345678910";
+ MyInputStream myStream( testStr );
+ FilterInputStream is( &myStream );
+
+ try {
+ is.close();
+ } catch( IOException& e ) {
+ CPPUNIT_FAIL("Exception attempting to close stream");
+ }
+
+ try {
+ is.read();
+ } catch( IOException& e ) {
+ return;
+ }
+
+ CPPUNIT_FAIL("Able to read from closed stream");
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FilterInputStreamTest::testRead() {
+
+ std::string testStr = "TEST12345678910";
+ MyInputStream myStream( testStr );
+ FilterInputStream is( &myStream );
+
+ char c = is.read();
+ CPPUNIT_ASSERT_MESSAGE( "read returned incorrect char",
+ c == testStr.at(0) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FilterInputStreamTest::testRead2() {
+
+ std::string testStr = "TEST12345678910ABCDEFGHIJKLMNOPQRSTU";
+ MyInputStream myStream( testStr );
+ FilterInputStream is( &myStream );
+
+ unsigned char buf[30];
+ is.read( buf, 0, 30 );
+ CPPUNIT_ASSERT_MESSAGE( "Failed to read correct data",
+ string( (const char*)buf, 30 ) == testStr.substr(0, 30) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FilterInputStreamTest::testRead3() {
+
+ std::string testStr;
+ for( int i = 0; i < 4000; ++i ) {
+ testStr += (char)i;
+ }
+ MyInputStream myStream( testStr );
+ FilterInputStream is( &myStream );
+
+ unsigned char buf[100];
+ is.skip(3000);
+ is.read( buf, 0, 100 );
+ CPPUNIT_ASSERT_MESSAGE( "Failed to read correct data",
+ string( (const char*)buf, 100 ) == testStr.substr( 3000, 100 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FilterInputStreamTest::testSkip() {
+
+ std::string testStr;
+ for( int i = 0; i < 4000; ++i ) {
+ testStr += (char)i;
+ }
+ MyInputStream myStream( testStr );
+ FilterInputStream is( &myStream );
+
+ unsigned char buf[100];
+ is.skip( 1000 );
+ is.read( buf, 0, 100 );
+ CPPUNIT_ASSERT_MESSAGE( "Failed to skip to correct position",
+ string( (const char*)buf, 100 ) == testStr.substr( 1000, 100 ) );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/FilterInputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/FilterInputStreamTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/FilterInputStreamTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/FilterInputStreamTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,173 @@
+/*
+ * 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_FILTERINPUTSTREAMTEST_H_
+#define _DECAF_IO_FILTERINPUTSTREAMTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/lang/Exception.h>
+#include <decaf/io/FilterInputStream.h>
+
+namespace decaf{
+namespace io{
+
+ class FilterInputStreamTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( FilterInputStreamTest );
+ CPPUNIT_TEST( testAvailable );
+ CPPUNIT_TEST( testClose );
+ CPPUNIT_TEST( testRead );
+ CPPUNIT_TEST( testRead2 );
+ CPPUNIT_TEST( testRead3 );
+ CPPUNIT_TEST( testSkip );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ FilterInputStreamTest() {}
+ virtual ~FilterInputStreamTest() {}
+
+ void testAvailable();
+ void testClose();
+ void testRead();
+ void testRead2();
+ void testRead3();
+ void testSkip();
+
+ 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_FILTERINPUTSTREAMTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/FilterOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/FilterOutputStreamTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/FilterOutputStreamTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/FilterOutputStreamTest.cpp 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.
+ */
+
+#include "FilterOutputStreamTest.h"
+#include <decaf/io/ByteArrayOutputStream.h>
+#include <decaf/io/ByteArrayInputStream.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::io;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+void FilterOutputStreamTest::testConstructor() {
+
+ try {
+ ByteArrayOutputStream baos;
+ FilterOutputStream os( &baos );
+ os.write( 't' );
+ } catch( IOException& e ) {
+ CPPUNIT_FAIL("Constructor test failed : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FilterOutputStreamTest::testClose() {
+
+ try {
+ ByteArrayOutputStream baos;
+ FilterOutputStream os( &baos );
+ os.write( (unsigned char*)&testString[0], 0, 500 );
+ os.flush();
+ CPPUNIT_ASSERT_MESSAGE( "Bytes not written after flush",
+ 500 == baos.size() );
+ os.close();
+ } catch( IOException& e ) {
+ CPPUNIT_FAIL("Close test failed : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FilterOutputStreamTest::testFlush() {
+
+ try {
+ ByteArrayOutputStream baos;
+ FilterOutputStream os( &baos );
+ os.write( (unsigned char*)&testString[0], 0, 500 );
+ os.flush();
+ CPPUNIT_ASSERT_MESSAGE( "Bytes not written after flush",
+ 500 == baos.size() );
+ os.close();
+ } catch( IOException& e ) {
+ CPPUNIT_FAIL("Flush test failed : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FilterOutputStreamTest::testWrite1() {
+
+ try {
+ ByteArrayOutputStream baos;
+ FilterOutputStream os( &baos );
+ os.write( (unsigned char*)&testString[0], 0, testString.size() );
+ ByteArrayInputStream bais( baos.toByteArray(), baos.size() );
+ os.flush();
+ CPPUNIT_ASSERT_MESSAGE( "Bytes not written after flush",
+ bais.available() == testString.length() );
+ unsigned char* wbytes = new unsigned char[ testString.length() ];
+ bais.read( wbytes, 0, testString.length() );
+ CPPUNIT_ASSERT_MESSAGE("Incorrect bytes written",
+ testString == string( (const char*)wbytes, testString.length() ) );
+
+ delete [] wbytes;
+ } catch( IOException& e ) {
+ CPPUNIT_FAIL("Write test failed : " + e.getMessage());
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FilterOutputStreamTest::testWrite2() {
+
+ try {
+ ByteArrayOutputStream baos;
+ FilterOutputStream os( &baos );
+ os.write('t');
+ ByteArrayInputStream bais( baos.toByteArray(), baos.size() );
+ os.flush();
+ CPPUNIT_ASSERT_MESSAGE( "Byte not written after flush", 1 == bais.available() );
+ unsigned char wbytes[1];
+ bais.read( wbytes, 0, 1 );
+ CPPUNIT_ASSERT_MESSAGE("Incorrect byte written", 't' == wbytes[0] );
+ } catch( IOException& e ) {
+ CPPUNIT_FAIL("Write test failed : " + e.getMessage());
+ }
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/io/FilterOutputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/io/FilterOutputStreamTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/io/FilterOutputStreamTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/io/FilterOutputStreamTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,61 @@
+/*
+ * 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_FILTEROUTPUTSTREAMTEST_H_
+#define _DECAF_IO_FILTEROUTPUTSTREAMTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/lang/Exception.h>
+#include <decaf/io/FilterOutputStream.h>
+
+namespace decaf{
+namespace io{
+
+ class FilterOutputStreamTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( FilterOutputStreamTest );
+ CPPUNIT_TEST( testConstructor );
+ CPPUNIT_TEST( testClose );
+ CPPUNIT_TEST( testFlush );
+ CPPUNIT_TEST( testWrite1 );
+ CPPUNIT_TEST( testWrite2 );
+ CPPUNIT_TEST_SUITE_END();
+
+ std::string testString;
+
+ public:
+
+ FilterOutputStreamTest() {}
+ virtual ~FilterOutputStreamTest() {}
+ 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 testConstructor();
+ void testClose();
+ void testFlush();
+ void testWrite1();
+ void testWrite2();
+
+ };
+
+}}
+
+#endif /*_DECAF_IO_FILTEROUTPUTSTREAMTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/lang/BooleanTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/lang/BooleanTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/lang/BooleanTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/lang/BooleanTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,45 @@
+/*
+ * 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 "BooleanTest.h"
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+
+void BooleanTest::test(void)
+{
+ bool x = Boolean::parseBoolean("false");
+ bool y = Boolean::parseBoolean("true");
+ bool z = Boolean::parseBoolean("false");
+
+ CPPUNIT_ASSERT( x == false );
+ CPPUNIT_ASSERT( y == true );
+ CPPUNIT_ASSERT( z == false );
+
+ std::string x1 = Boolean::toString( x );
+ std::string y1 = Boolean::toString( y );
+ std::string z1 = Boolean::toString( z );
+
+ CPPUNIT_ASSERT( x1 == "false" );
+ CPPUNIT_ASSERT( y1 == "true" );
+ CPPUNIT_ASSERT( z1 == "false" );
+
+ Boolean b( true );
+ CPPUNIT_ASSERT( b.booleanValue() == true );
+
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/lang/BooleanTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/lang/BooleanTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/lang/BooleanTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/lang/BooleanTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,46 @@
+/*
+ * 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_LANG_BOOLEANTEST_H_
+#define _DECAF_LANG_BOOLEANTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/lang/Boolean.h>
+
+namespace decaf{
+namespace lang{
+
+ class BooleanTest : public CppUnit::TestFixture
+ {
+ CPPUNIT_TEST_SUITE( BooleanTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ BooleanTest() {}
+ virtual ~BooleanTest() {}
+
+ virtual void test(void);
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_BOOLEANTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/lang/ByteTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/lang/ByteTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/lang/ByteTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/lang/ByteTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,46 @@
+/*
+ * 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 "ByteTest.h"
+
+using namespace decaf;
+using namespace decaf::lang;
+
+////////////////////////////////////////////////////////////////////////////////
+ByteTest::ByteTest(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteTest::test() {
+
+ Byte ubyte( 'b' );
+
+ CPPUNIT_ASSERT( ubyte < 'a' == false );
+ CPPUNIT_ASSERT( ubyte.compareTo( 'a' ) == 1 );
+ CPPUNIT_ASSERT( ubyte.compareTo( 'b' ) == 0 );
+ CPPUNIT_ASSERT( ubyte.compareTo( 'c' ) == -1 );
+
+ CPPUNIT_ASSERT( ubyte.parseByte( "60" ) == 60 );
+ CPPUNIT_ASSERT( ubyte.parseByte( "ff", 16 ) == 255 );
+
+ CPPUNIT_ASSERT( ubyte.toString( 60 ) == "60" );
+ CPPUNIT_ASSERT( ubyte.toString( 255 ) == "255" );
+
+ CPPUNIT_ASSERT( ubyte.decode( "0xFF" ) == 255 );
+ CPPUNIT_ASSERT( ubyte.decode( "255" ) == 255 );
+
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/lang/ByteTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/lang/ByteTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/lang/ByteTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/lang/ByteTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,45 @@
+/*
+ * 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_LANG_BYTETEST_H_
+#define _DECAF_LANG_BYTETEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/lang/Byte.h>
+
+namespace decaf{
+namespace lang{
+
+ class ByteTest : public CppUnit::TestFixture
+ {
+ CPPUNIT_TEST_SUITE( ByteTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ ByteTest();
+ virtual ~ByteTest() {}
+
+ virtual void test();
+ };
+
+}}
+
+#endif /*_DECAF_LANG_BYTETEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/lang/CharacterTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/lang/CharacterTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/lang/CharacterTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/lang/CharacterTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,50 @@
+/*
+ * 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 "CharacterTest.h"
+
+using namespace decaf;
+using namespace decaf::lang;
+
+////////////////////////////////////////////////////////////////////////////////
+CharacterTest::CharacterTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharacterTest::test() {
+
+ Character character( 'b' );
+
+ CPPUNIT_ASSERT( character < 'a' == false );
+ CPPUNIT_ASSERT( character.compareTo( 'a' ) == 1 );
+ CPPUNIT_ASSERT( character.compareTo( 'b' ) == 0 );
+ CPPUNIT_ASSERT( character.compareTo( 'c' ) == -1 );
+
+ CPPUNIT_ASSERT( Character::isDigit('a') == false );
+ CPPUNIT_ASSERT( Character::isDigit('7') == true );
+ CPPUNIT_ASSERT( Character::isLowerCase('a') == true );
+ CPPUNIT_ASSERT( Character::isLowerCase('A') == false );
+ CPPUNIT_ASSERT( Character::isUpperCase('a') == false );
+ CPPUNIT_ASSERT( Character::isUpperCase('A') == true );
+ CPPUNIT_ASSERT( Character::isLetter('a') == true );
+ CPPUNIT_ASSERT( Character::isLetter('8') == false );
+ CPPUNIT_ASSERT( Character::isLetterOrDigit('a') == true );
+ CPPUNIT_ASSERT( Character::isLetterOrDigit('&') == false );
+ CPPUNIT_ASSERT( Character::digit( '9', 10 ) == 9 );
+
+}
+
Added: activemq/activemq-cpp/trunk/src/test/decaf/lang/CharacterTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/lang/CharacterTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/lang/CharacterTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/lang/CharacterTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,46 @@
+/*
+ * 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_LANG_CHARACTERTEST_H_
+#define _DECAF_LANG_CHARACTERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/lang/Character.h>
+
+namespace decaf{
+namespace lang{
+
+ class CharacterTest : public CppUnit::TestFixture
+ {
+ CPPUNIT_TEST_SUITE( CharacterTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ CharacterTest();
+ virtual ~CharacterTest() {}
+
+ virtual void test();
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_CHARACTERTEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/lang/DoubleTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/lang/DoubleTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/lang/DoubleTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/lang/DoubleTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,33 @@
+/*
+ * 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 "DoubleTest.h"
+
+#include <decaf/lang/Double.h>
+#include <string>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+
+////////////////////////////////////////////////////////////////////////////////
+DoubleTest::DoubleTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleTest::test() {
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/lang/DoubleTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/lang/DoubleTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/lang/DoubleTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/lang/DoubleTest.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,44 @@
+/*
+ * 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_LANG_DOUBLETEST_H_
+#define _DECAF_LANG_DOUBLETEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf{
+namespace lang{
+
+ class DoubleTest : public CppUnit::TestFixture
+ {
+ CPPUNIT_TEST_SUITE( DoubleTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ DoubleTest();
+ virtual ~DoubleTest() {}
+
+ virtual void test();
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_DOUBLETEST_H_*/
Added: activemq/activemq-cpp/trunk/src/test/decaf/lang/ExceptionTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/lang/ExceptionTest.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/lang/ExceptionTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/lang/ExceptionTest.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,37 @@
+/*
+ * 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 "ExceptionTest.h"
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+
+////////////////////////////////////////////////////////////////////////////////
+void ExceptionTest::testMessage0(){
+ char* text = "This is a test";
+ Exception ex( __FILE__, __LINE__, text );
+ CPPUNIT_ASSERT( strcmp( ex.getMessage().c_str(), text ) == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ExceptionTest::testMessage3(){
+ Exception ex( __FILE__, __LINE__,
+ "This is a test %d %d %d", 1, 100, 1000 );
+ CPPUNIT_ASSERT( strcmp( ex.getMessage().c_str(),
+ "This is a test 1 100 1000" ) == 0 );
+}
Added: activemq/activemq-cpp/trunk/src/test/decaf/lang/ExceptionTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/lang/ExceptionTest.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/lang/ExceptionTest.h (added)
+++ activemq/activemq-cpp/trunk/src/test/decaf/lang/ExceptionTest.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_LANG_EXCEPTIONTEST_H_
+#define _DECAF_LANG_EXCEPTIONTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/lang/Exception.h>
+#include <string.h>
+
+namespace decaf{
+namespace lang{
+
+ class ExceptionTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( ExceptionTest );
+ CPPUNIT_TEST( testMessage0 );
+ CPPUNIT_TEST( testMessage3 );
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+
+ virtual ~ExceptionTest(){}
+
+ virtual void setUp(){}
+ virtual void tearDown(){}
+
+ void testMessage0();
+ void testMessage3();
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_EXCEPTIONTEST_H_*/