activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r601063 - in /activemq/activemq-cpp/decaf/trunk/src: main/decaf/internal/util/ByteArrayAdapter.cpp test/decaf/internal/util/ByteArrayAdapterTest.cpp test/decaf/internal/util/ByteArrayAdapterTest.h
Date Tue, 04 Dec 2007 19:58:08 GMT
Author: tabish
Date: Tue Dec  4 11:58:07 2007
New Revision: 601063

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

Working on implementing the NIO package

Modified:
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/util/ByteArrayAdapter.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.h

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/util/ByteArrayAdapter.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/util/ByteArrayAdapter.cpp?rev=601063&r1=601062&r2=601063&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/util/ByteArrayAdapter.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/util/ByteArrayAdapter.cpp Tue
Dec  4 11:58:07 2007
@@ -342,7 +342,7 @@
 
         unsigned long long value = 0;
         unsigned char buffer[sizeof(value)] = {0};
-        this->read( buffer, index + sizeof(value), sizeof(value) );
+        this->read( buffer, index, sizeof(value) );
 
         // Have to do it this way because on Solaris and Cygwin we get all
         // kinds of warnings when shifting a byte up into a long long.
@@ -379,7 +379,7 @@
 
         unsigned int value = 0;
         unsigned char buffer[sizeof(value)] = {0};
-        this->read( buffer, index + sizeof(value), sizeof(value) );
+        this->read( buffer, index, sizeof(value) );
         value |= (buffer[0] << 24 | buffer[1] << 16 |
                   buffer[2] << 8 | buffer[3] << 0);
 
@@ -404,7 +404,7 @@
 
         short value = 0;
         unsigned char buffer[sizeof(value)] = {0};
-        this->read( buffer, index + sizeof(value), sizeof(value) );
+        this->read( buffer, index, sizeof(value) );
         value |= (buffer[0] << 8 | buffer[1] << 0);
 
         return value;
@@ -494,7 +494,7 @@
         buffer[6] = (unsigned char)((value & 0x000000000000FF00ULL) >> 8);
         buffer[7] = (unsigned char)((value & 0x00000000000000FFULL) >> 0);
 
-        this->write( buffer, index + sizeof(value), sizeof(value) );
+        this->write( buffer, index, sizeof(value) );
 
         return *this;
     }
@@ -516,7 +516,7 @@
         buffer[2] = (value & 0x0000FF00) >> 8;
         buffer[3] = (value & 0x000000FF) >> 0;
 
-        this->write( buffer, index + sizeof(value), sizeof(value) );
+        this->write( buffer, index, sizeof(value) );
 
         return *this;
     }
@@ -536,7 +536,7 @@
         buffer[0] = (value & 0xFF00) >> 8;
         buffer[1] = (value & 0x00FF) >> 0;
 
-        this->write( buffer, index + sizeof(value), sizeof(value) );
+        this->write( buffer, index, sizeof(value) );
 
         return *this;
     }

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.cpp?rev=601063&r1=601062&r2=601063&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.cpp
(original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.cpp
Tue Dec  4 11:58:07 2007
@@ -17,6 +17,9 @@
 
 #include "ByteArrayAdapterTest.h"
 
+#include <decaf/lang/Double.h>
+#include <decaf/lang/Float.h>
+
 using namespace decaf;
 using namespace decaf::internal;
 using namespace decaf::internal::util;
@@ -25,6 +28,25 @@
 using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testArray() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    testBuffer1.write( testData1, 0, testData1Size );
+
+    for( std::size_t ix = 0; ix < testBuffer1.getCapacity(); ++ix ) {
+        CPPUNIT_ASSERT( testBuffer1.get( ix ) == testData1[ix] );
+    }
+
+    unsigned char* array = testBuffer1.getByteArray();
+    CPPUNIT_ASSERT( array != NULL );
+
+    for( std::size_t ix = 0; ix < testBuffer1.getCapacity(); ++ix ) {
+        CPPUNIT_ASSERT( array[ix] == testData1[ix] );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void ByteArrayAdapterTest::testRead(){
 
     unsigned char* data = new unsigned char[256];
@@ -246,5 +268,296 @@
     CPPUNIT_ASSERT_THROW_MESSAGE(
         "Should Throw IndexOutOfBoundsException",
         array[9999],
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPut() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::size_t i = 0;
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(unsigned char); i+=sizeof(unsigned
char) ) {
+        testBuffer1.put( i, (unsigned char)(i + 99) );
+        CPPUNIT_ASSERT( testBuffer1.get( i ) == (unsigned char)(i + 99) );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.put( i, 3 ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPutChar() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::size_t i = 0;
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(char); i+=sizeof(char) ) {
+        testBuffer1.putChar( i, i + 99 );
+        CPPUNIT_ASSERT( testBuffer1.getChar( i ) == (char)(i + 99) );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.putChar( i, 3 ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPutLong() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::size_t i = 0;
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(long long); i+=sizeof(long long)
) {
+        testBuffer1.putLong( i, i + 99 );
+        CPPUNIT_ASSERT( testBuffer1.getLong( i ) == (long long)(i + 99) );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.putLong( i, 3 ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPutInt() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::size_t i = 0;
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(int); i+=sizeof(int) ) {
+        testBuffer1.putInt( i, i + 99 );
+        CPPUNIT_ASSERT( testBuffer1.getInt( i ) == (int)(i + 99) );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.putInt( i, 3 ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPutShort() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::size_t i = 0;
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(short); i+=sizeof(short) ) {
+        testBuffer1.putShort( i, i + 99 );
+        CPPUNIT_ASSERT( testBuffer1.getShort( i ) == (short)(i + 99) );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.putShort( i, 3 ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPutDouble() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::size_t i = 0;
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(double); i+=sizeof(double) ) {
+        testBuffer1.putDouble( i, i + 99.025 );
+        CPPUNIT_ASSERT( Double::doubleToLongBits( testBuffer1.getDouble( i ) ) ==
+                        Double::doubleToLongBits( (double)(i + 99.025) ) );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.putDouble( i, 3 ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testPutFloat() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::size_t i = 0;
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(float); i+=sizeof(float) ) {
+        testBuffer1.putFloat( i, i + 99.025 );
+        CPPUNIT_ASSERT( Float::floatToIntBits( testBuffer1.getFloat( i ) ) ==
+                        Float::floatToIntBits( (float)(i + 99.025) ) );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.putFloat( i, 3 ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGet() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::vector<unsigned char> values;
+    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( char ); i +=
sizeof( char ) ) {
+        testBuffer1.put( i, (unsigned char)i );
+        values.push_back( (unsigned char)i );
+    }
+
+    std::size_t i = 0;
+    std::size_t j = 0;
+
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( unsigned char ); i += sizeof(
unsigned char ), j++ ) {
+        CPPUNIT_ASSERT( testBuffer1.get( i ) == values[j] );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.get( i ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGetChar() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::vector<char> values;
+    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( char ); i +=
sizeof( char ) ) {
+        testBuffer1.putChar( i, (char)i );
+        values.push_back( (char)i );
+    }
+
+    std::size_t i = 0;
+    std::size_t j = 0;
+
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( char ); i += sizeof( char ), j++
) {
+        CPPUNIT_ASSERT( testBuffer1.getChar( i ) == values[j] );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.getChar( i ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGetShort() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::vector<short> values;
+    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( short ); i +=
sizeof( short ) ) {
+        testBuffer1.putShort( i, (short)i );
+        values.push_back( (short)i );
+    }
+
+    std::size_t i = 0;
+    std::size_t j = 0;
+
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( short ); i += sizeof( short ),
j++ ) {
+        CPPUNIT_ASSERT( testBuffer1.getShort( i ) == values[j] );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.getShort( i ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGetInt() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::vector<int> values;
+    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( int ); i += sizeof(
int ) ) {
+        testBuffer1.putInt( i, (int)i );
+        values.push_back( (int)i );
+    }
+
+    std::size_t i = 0;
+    std::size_t j = 0;
+
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( int ); i += sizeof( int ), j++
) {
+        CPPUNIT_ASSERT( testBuffer1.getInt( i ) == values[j] );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.getInt( i ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGetLong() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::vector<long long> values;
+    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( long long );
i += sizeof( long long ) ) {
+        testBuffer1.putLong( i, (long long)i );
+        values.push_back( (long long)i );
+    }
+
+    std::size_t i = 0;
+    std::size_t j = 0;
+
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( long long ); i += sizeof( long
long ), j++ ) {
+        CPPUNIT_ASSERT( testBuffer1.getLong( i ) == values[j] );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.getLong( i ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGetFloat() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::vector<float> values;
+    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( float ); i +=
sizeof( float ) ) {
+        testBuffer1.putFloat( i, (float)i + 0.025f );
+        values.push_back( (float)i + 0.025f );
+    }
+
+    std::size_t i = 0;
+    std::size_t j = 0;
+
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( float ); i += sizeof( float ),
j++ ) {
+        CPPUNIT_ASSERT( Float::floatToIntBits( testBuffer1.getFloat( i ) ) ==
+                        Float::floatToIntBits( values[j] ) );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.getFloat( i ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ByteArrayAdapterTest::testGetDouble() {
+
+    ByteArrayAdapter testBuffer1( testData1Size );
+
+    std::vector<double> values;
+    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( double ); i +=
sizeof( double ) ) {
+        testBuffer1.putDouble( i, (double)i + 0.025 );
+        values.push_back( (double)i + 0.025 );
+    }
+
+    std::size_t i = 0;
+    std::size_t j = 0;
+
+    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( double ); i += sizeof( double
), j++ ) {
+        CPPUNIT_ASSERT( Double::doubleToLongBits( testBuffer1.getDouble( i ) ) ==
+                        Double::doubleToLongBits( values[j] ) );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1.getDouble( i ),
         IndexOutOfBoundsException );
 }

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.h?rev=601063&r1=601062&r2=601063&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.h
(original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.h
Tue Dec  4 11:58:07 2007
@@ -41,23 +41,67 @@
         CPPUNIT_TEST( testReszie );
         CPPUNIT_TEST( testOperators );
         CPPUNIT_TEST( testOperatorsExceptions );
+        CPPUNIT_TEST( testArray );
+        CPPUNIT_TEST( testGet );
+        CPPUNIT_TEST( testGetChar );
+        CPPUNIT_TEST( testGetShort );
+        CPPUNIT_TEST( testGetInt );
+        CPPUNIT_TEST( testGetLong );
+        CPPUNIT_TEST( testGetDouble );
+        CPPUNIT_TEST( testGetFloat );
+        CPPUNIT_TEST( testPut );
+        CPPUNIT_TEST( testPutChar );
+        CPPUNIT_TEST( testPutShort );
+        CPPUNIT_TEST( testPutInt );
+        CPPUNIT_TEST( testPutLong );
+        CPPUNIT_TEST( testPutDouble );
+        CPPUNIT_TEST( testPutFloat );
         CPPUNIT_TEST_SUITE_END();
 
+        unsigned char* testData1;
+        static const std::size_t testData1Size = 100;
+
     public:
 
         ByteArrayAdapterTest() {}
         virtual ~ByteArrayAdapterTest() {}
 
-        virtual void testRead();
-        virtual void testWrite();
-        virtual void testCtor1();
-        virtual void testCtor2();
-        virtual void testClear();
-        virtual void testReszie();
-        virtual void testOperators();
-        virtual void testReadExceptions();
-        virtual void testWriteExceptions();
-        virtual void testOperatorsExceptions();
+        void setUp() {
+            testData1 = new unsigned char[testData1Size];
+            for( std::size_t i = 0; i < testData1Size; ++i ){
+                testData1[i] = (unsigned char)i;
+            }
+        }
+
+        void tearDown() {
+            delete testData1;
+        }
+
+        void testRead();
+        void testWrite();
+        void testCtor1();
+        void testCtor2();
+        void testClear();
+        void testReszie();
+        void testOperators();
+        void testReadExceptions();
+        void testWriteExceptions();
+        void testOperatorsExceptions();
+        void testArray();
+        void testGet();
+        void testGetChar();
+        void testGetShort();
+        void testGetInt();
+        void testGetLong();
+        void testGetDouble();
+        void testGetFloat();
+        void testPut();
+        void testPutChar();
+        void testPutShort();
+        void testPutInt();
+        void testPutLong();
+        void testPutDouble();
+        void testPutFloat();
 
     };
 



Mime
View raw message