activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r545820 - in /activemq/activemq-cpp/trunk/src/decaf/src/test: ./ decaf/io/ decaf/util/
Date Sun, 10 Jun 2007 00:27:58 GMT
Author: tabish
Date: Sat Jun  9 17:27:57 2007
New Revision: 545820

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

Building up the Decaf Library

Added:
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayInputStreamTest.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayInputStreamTest.h
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayOutputStreamTest.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayOutputStreamTest.h
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataInputStreamTest.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataInputStreamTest.h
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataOutputStreamTest.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataOutputStreamTest.h
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/Endian.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/Endian.h
Modified:
    activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am

Modified: activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am?view=diff&rev=545820&r1=545819&r2=545820
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am Sat Jun  9 17:27:57 2007
@@ -20,7 +20,14 @@
   decaf/lang/IntegerTest.cpp \
   decaf/lang/LongTest.cpp \
   decaf/lang/ThreadTest.cpp \
+  decaf/io/BufferedInputStreamTest.cpp \
+  decaf/io/BufferedOutputStreamTest.cpp \
+  decaf/io/ByteArrayInputStreamTest.cpp \
+  decaf/io/ByteArrayOutputStreamTest.cpp \
+  decaf/io/DataInputStreamTest.cpp \
+  decaf/io/DataOutputStreamTest.cpp \
   decaf/util/StringTokenizerTest.cpp \
+  decaf/util/Endian.cpp \
   decaf/util/DateTest.cpp \
   decaf/util/GuidTest.cpp \
   decaf/util/concurrent/CountDownLatchTest.cpp \
@@ -33,7 +40,14 @@
   decaf/lang/IntegerTest.h \
   decaf/lang/LongTest.h \
   decaf/lang/ThreadTest.h \
+  decaf/io/BufferedInputStreamTest.h \
+  decaf/io/BufferedOutputStreamTest.h \
+  decaf/io/ByteArrayInputStreamTest.h \
+  decaf/io/ByteArrayOutputStreamTest.h \
+  decaf/io/DataInputStreamTest.h \
+  decaf/io/DataOutputStreamTest.h \
   decaf/util/StringTokenizerTest.h \
+  decaf/util/Endian.h \
   decaf/util/DateTest.h \
   decaf/util/GuidTest.h \
   decaf/util/concurrent/CountDownLatchTest.h \

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayInputStreamTest.cpp?view=auto&rev=545820
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayInputStreamTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayInputStreamTest.cpp Sat
Jun  9 17:27:57 2007
@@ -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.
+ */
+
+#include "ByteArrayInputStreamTest.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::ByteArrayInputStreamTest );
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::io;
+using namespace decaf::util;
+
+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, 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, 3) == 3 );
+    CPPUNIT_ASSERT( stream_a.read(&buffer[3], 2) == 2 );
+    CPPUNIT_ASSERT( std::string((const char*)buffer) == std::string("teste") );
+
+    stream_a.close();
+
+    delete [] buffer;
+}

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayInputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayInputStreamTest.h?view=auto&rev=545820
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayInputStreamTest.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayInputStreamTest.h Sat
Jun  9 17:27:57 2007
@@ -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_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_SUITE_END();
+
+   public:
+
+       ByteArrayInputStreamTest() {}
+       virtual ~ByteArrayInputStreamTest() {}
+
+       void testStream();
+
+   };
+
+}}
+
+#endif /*_DECAF_IO_BYTEARRAYINPUTSTREAMTEST_H_*/

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayOutputStreamTest.cpp?view=auto&rev=545820
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayOutputStreamTest.cpp
(added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayOutputStreamTest.cpp
Sat Jun  9 17:27:57 2007
@@ -0,0 +1,58 @@
+/*
+ * 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"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::ByteArrayOutputStreamTest );
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::io;
+using namespace decaf::util;
+
+void ByteArrayOutputStreamTest::testStream()
+{
+    ByteArrayOutputStream stream_a;
+
+    stream_a.write('a');
+    stream_a.write(60);
+    stream_a.write('c');
+
+    CPPUNIT_ASSERT( stream_a.getByteArraySize() == 3 );
+
+    stream_a.clear();
+
+    CPPUNIT_ASSERT( stream_a.getByteArraySize() == 0 );
+
+    stream_a.write((const unsigned char*)("abc"), 3);
+
+    CPPUNIT_ASSERT( stream_a.getByteArraySize() == 3 );
+
+    stream_a.clear();
+
+    CPPUNIT_ASSERT( stream_a.getByteArraySize() == 0 );
+
+    stream_a.write((const unsigned char*)("abc"), 3);
+
+    unsigned char buffer[4];
+
+    memset(buffer, 0, 4);
+    memcpy(buffer, stream_a.getByteArray(), stream_a.getByteArraySize());
+
+    CPPUNIT_ASSERT( std::string((const char*)buffer) == std::string("abc") );
+}

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayOutputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayOutputStreamTest.h?view=auto&rev=545820
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayOutputStreamTest.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/ByteArrayOutputStreamTest.h Sat
Jun  9 17:27:57 2007
@@ -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_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_SUITE_END();
+
+    public:
+
+        ByteArrayOutputStreamTest() {}
+        virtual ~ByteArrayOutputStreamTest() {}
+
+        void testStream();
+
+    };
+
+}}
+
+#endif /*_DECAF_IO_BYTEARRAYOUTPUTSTREAMTEST_H_*/

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataInputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataInputStreamTest.cpp?view=auto&rev=545820
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataInputStreamTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataInputStreamTest.cpp Sat Jun
 9 17:27:57 2007
@@ -0,0 +1,111 @@
+/*
+ * 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"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::DataInputStreamTest );
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::io;
+using namespace decaf::util;
+
+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' );
+}

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataInputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataInputStreamTest.h?view=auto&rev=545820
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataInputStreamTest.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataInputStreamTest.h Sat Jun
 9 17:27:57 2007
@@ -0,0 +1,57 @@
+/*
+ * 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/BufferedInputStream.h>
+#include <decaf/io/ByteArrayInputStream.h>
+#include <decaf/io/DataInputStream.h>
+
+#ifdef min
+#undef min
+#endif
+
+#include <algorithm>
+
+namespace decaf{
+namespace io{
+
+    class DataInputStreamTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( DataInputStreamTest );
+        CPPUNIT_TEST( test );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        virtual ~DataInputStreamTest(){}
+        virtual void setUp(){}
+        virtual void tearDown(){}
+
+        void test();
+
+    };
+
+}}
+
+#endif /*_DECAF_IO_DATAINPUTSTREAMTEST_H_*/

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataOutputStreamTest.cpp?view=auto&rev=545820
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataOutputStreamTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataOutputStreamTest.cpp Sat Jun
 9 17:27:57 2007
@@ -0,0 +1,88 @@
+/*
+ * 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"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::DataOutputStreamTest );
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::io;
+using namespace decaf::util;
+
+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, 3 );
+
+    const unsigned char* buffer = myStream.getByteArray();
+    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/decaf/src/test/decaf/io/DataOutputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataOutputStreamTest.h?view=auto&rev=545820
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataOutputStreamTest.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/DataOutputStreamTest.h Sat Jun
 9 17:27:57 2007
@@ -0,0 +1,49 @@
+/*
+ * 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/ByteArrayOutputStream.h>
+
+namespace decaf{
+namespace io{
+
+    class DataOutputStreamTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( DataOutputStreamTest );
+        CPPUNIT_TEST( test );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        virtual ~DataOutputStreamTest(){}
+        virtual void setUp(){}
+        virtual void tearDown(){}
+
+        void test();
+
+    };
+
+}}
+
+#endif /*_DECAF_IO_DATAOUTPUTSTREAMTEST_H_*/

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/Endian.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/Endian.cpp?view=auto&rev=545820
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/Endian.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/Endian.cpp Sat Jun  9 17:27:57
2007
@@ -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 "Endian.h"
+#include <decaf/util/Config.h>
+#include <string.h>
+
+using namespace decaf;
+using namespace decaf::util;
+
+////////////////////////////////////////////////////////////////////////////////
+void Endian::byteSwap(unsigned char* data, int dataLength) {
+
+    #ifdef WORDS_BIGENDIAN
+        return;
+    #endif
+
+    for (int i = 0; i<dataLength/2; i++) {
+        unsigned char temp = data[i];
+        data[i] = data[dataLength-1-i];
+        data[dataLength-1-i] = temp;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char Endian::byteSwap( unsigned char value ){
+
+    #ifdef WORDS_BIGENDIAN
+        return value;
+    #endif
+
+    return value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned short Endian::byteSwap( unsigned short value ){
+
+    #ifdef WORDS_BIGENDIAN
+        return value;
+    #endif
+
+    return (((unsigned short)value & 0xFF00 ) >> 8 ) |
+           (((unsigned short)value & 0x00FF ) << 8 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned int Endian::byteSwap( unsigned int value ){
+
+    #ifdef WORDS_BIGENDIAN
+        return value;
+    #endif
+
+    return (((unsigned int)value & 0xFF000000 ) >> 24 ) |
+           (((unsigned int)value & 0x00FF0000 ) >> 8 )  |
+           (((unsigned int)value & 0x0000FF00 ) << 8 )  |
+           (((unsigned int)value & 0x000000FF ) << 24 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned long long Endian::byteSwap( unsigned long long value ){
+
+    #ifdef WORDS_BIGENDIAN
+        return value;
+    #endif
+
+    return (((unsigned long long)value & 0xFF00000000000000ULL ) >> 56 ) |
+           (((unsigned long long)value & 0x00FF000000000000ULL ) >> 40 ) |
+           (((unsigned long long)value & 0x0000FF0000000000ULL ) >> 24 ) |
+           (((unsigned long long)value & 0x000000FF00000000ULL ) >> 8 )  |
+           (((unsigned long long)value & 0x00000000FF000000ULL ) << 8 )  |
+           (((unsigned long long)value & 0x0000000000FF0000ULL ) << 24 ) |
+           (((unsigned long long)value & 0x000000000000FF00ULL ) << 40 ) |
+           (((unsigned long long)value & 0x00000000000000FFULL ) << 56 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float Endian::byteSwap( float value ){
+
+    #ifdef WORDS_BIGENDIAN
+        return value;
+    #endif
+
+    unsigned int lvalue = 0;
+    memcpy( &lvalue, &value, sizeof( float ) );
+    lvalue = byteSwap( lvalue );
+    memcpy( &value, &lvalue, sizeof( unsigned int ) );
+    return value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double Endian::byteSwap( double value ){
+
+    #ifdef WORDS_BIGENDIAN
+        return value;
+    #endif
+
+    unsigned long long lvalue = 0;
+    memcpy( &lvalue, &value, sizeof( double ) );
+    lvalue = byteSwap( lvalue );
+    memcpy( &value, &lvalue, sizeof( unsigned long long ) );
+    return value;
+}
+

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/Endian.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/Endian.h?view=auto&rev=545820
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/Endian.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/util/Endian.h Sat Jun  9 17:27:57
2007
@@ -0,0 +1,43 @@
+/*
+ * 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_UTIL_ENDIAN_H
+#define _DECAF_UTIL_ENDIAN_H
+
+namespace decaf{
+namespace util{
+
+    class Endian{
+    public:
+
+        static void byteSwap(unsigned char* data, int dataLength);
+
+        static unsigned char byteSwap( unsigned char value );
+
+        static unsigned short byteSwap( unsigned short value );
+
+        static unsigned int byteSwap( unsigned int value );
+
+        static unsigned long long byteSwap( unsigned long long value );
+
+        static float byteSwap( float value );
+
+        static double byteSwap( double value );
+    };
+
+}}
+
+#endif /*_DECAF_UTIL_ENDIAN_H*/



Mime
View raw message