activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r602755 - in /activemq/activemq-cpp/decaf/trunk/src: main/decaf/internal/nio/ main/decaf/internal/util/ main/decaf/nio/ test/ test/decaf/internal/nio/ test/decaf/internal/util/
Date Sun, 09 Dec 2007 23:48:52 GMT
Author: tabish
Date: Sun Dec  9 15:48:51 2007
New Revision: 602755

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

Working on implementing the NIO package

Added:
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/DoubleArrayBufferTest.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/DoubleArrayBufferTest.h
Modified:
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/util/ByteArrayAdapter.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/util/ByteArrayAdapter.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/DoubleBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/Makefile.am
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/ByteArrayBufferTest.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/util/ByteArrayAdapterTest.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp?rev=602755&r1=602754&r2=602755&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp Sun Dec  9 15:48:51 2007
@@ -324,7 +324,7 @@
                 "ByteArrayBuffer::getLong(i) - Not enough data to fill a long long." );
         }
 
-        return this->_array->getLong( index + offset );
+        return this->_array->getLongAt( index + offset );
     }
     DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
@@ -357,7 +357,7 @@
                 "ByteArrayBuffer::getInt(i) - Not enough data to fill an int." );
         };
 
-        return this->_array->getInt( offset + index );
+        return this->_array->getIntAt( offset + index );
     }
     DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
@@ -390,7 +390,7 @@
                 "ByteArrayBuffer::getShort(i) - Not enough data to fill a short." );
         }
 
-        return this->_array->getShort( offset + index );
+        return this->_array->getShortAt( offset + index );
     }
     DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
@@ -565,7 +565,7 @@
                 "ByteArrayBuffer::putLong() - Buffer is Read Only." );
         }
 
-        this->_array->putLong( index + offset, value );
+        this->_array->putLongAt( index + offset, value );
 
         return *this;
     }
@@ -604,7 +604,7 @@
                 "ByteArrayBuffer::putInt() - Buffer is Read Only." );
         }
 
-        this->_array->putInt( index + offset, value );
+        this->_array->putIntAt( index + offset, value );
 
         return *this;
     }
@@ -643,7 +643,7 @@
                 "ByteArrayBuffer::putShort() - Buffer is Read Only." );
         }
 
-        this->_array->putShort( index + offset, value );
+        this->_array->putShortAt( index + offset, value );
 
         return *this;
     }

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.cpp?rev=602755&r1=602754&r2=602755&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.cpp Sun Dec  9 15:48:51 2007
@@ -30,7 +30,8 @@
     : DoubleBuffer( capacity ){
 
     // Allocate using the ByteArray, not read-only initially.  Take a reference to it.
-    this->_array = new ByteArrayPerspective( capacity );
+    // The capacity is the given capacity times the size of the stored datatype
+    this->_array = new ByteArrayPerspective( capacity * sizeof(double) );
     this->offset = 0;
     this->readOnly = readOnly;
 }
@@ -54,10 +55,10 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 DoubleArrayBuffer::DoubleArrayBuffer( ByteArrayPerspective& array,
-                                      std::size_t offset, std::size_t length,
+                                      std::size_t offset, std::size_t capacity,
                                       bool readOnly )
     throw( decaf::lang::exceptions::IndexOutOfBoundsException )
-    : DoubleBuffer( length ) {
+    : DoubleBuffer( capacity ) {
 
     try{
         if( offset > array.getCapacity() ) {
@@ -168,9 +169,9 @@
 
         // copy from the current pos to the beginning all the remaining bytes
         // the set pos to the
-        memcpy( this->array() + offset,
-                this->array() + offset + this->position(),
-                this->remaining() );
+        for( std::size_t ix = 0; ix < this->remaining(); ++ix ) {
+            this->put( ix, this->get( this->position() + ix ) );
+        }
 
         this->position( this->limit() - this->position() );
         this->limit( this->capacity() );
@@ -210,7 +211,7 @@
 
     try{
 
-        if( ( index + sizeof(double) ) >= this->limit() ) {
+        if( index >= this->limit() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "DoubleArrayBuffer::get - Not enough data to fill request." );
@@ -251,7 +252,7 @@
                 "DoubleArrayBuffer::put(i,i) - Buffer is Read Only." );
         }
 
-        if( index + sizeof(double) >= this->limit() ) {
+        if( index >= this->limit() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "DoubleArrayBuffer::put(i,i) - Not enough data to fill request." );

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=602755&r1=602754&r2=602755&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 Sun Dec  9 15:48:51 2007
@@ -35,9 +35,9 @@
 
     try{
 
-        this->array = new unsigned char[capacity];
-        memset( this->array, 0, capacity );
-        this->initialize( array, capacity, true );
+        this->array.bytes = new unsigned char[capacity];
+        memset( this->array.bytes, 0, capacity );
+        this->initialize( array.bytes, capacity, true );
     }
     DECAF_CATCH_RETHROW( Exception )
     DECAF_CATCHALL_THROW( Exception )
@@ -131,7 +131,7 @@
                 "ByteArrayAdapter::initialize - Passed Buffer is null" );
         }
 
-        this->array = array;
+        this->array.bytes = array;
         this->capacity = capacity;
         this->own = own;
     }
@@ -145,7 +145,7 @@
     try{
 
         if( own ) {
-            delete array;
+            delete array.bytes;
         }
     }
     DECAF_CATCH_NOTHROW( Exception )
@@ -175,7 +175,7 @@
         }
 
         // Read, starting at offset, length number of bytes to Buffer
-        memcpy( buffer, this->array + offset, length );
+        memcpy( buffer, this->array.bytes + offset, length );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
     DECAF_CATCH_RETHROW( BufferUnderflowException )
@@ -206,7 +206,7 @@
         }
 
         // Write, starting at offset, length number of bytes from buffer.
-        memcpy( this->array + offset, buffer, length );
+        memcpy( this->array.bytes + offset, buffer, length );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
     DECAF_CATCH_RETHROW( BufferOverflowException )
@@ -228,12 +228,12 @@
 
         // Save old state
         std::size_t oldCapacity = this->capacity;
-        unsigned char* oldArray = this->array;
+        unsigned char* oldArray = this->array.bytes;
 
         // Resize and copy as much of the old as we can back and delete old array
-        this->array = new unsigned char[capacity];
+        this->array.bytes = new unsigned char[capacity];
         this->capacity = capacity;
-        memcpy( this->array, oldArray, Math::min( (int)oldCapacity, (int)capacity ) );
+        memcpy( this->array.bytes, oldArray, Math::min( (int)oldCapacity, (int)capacity ) );
         delete oldArray;
     }
     DECAF_CATCH_RETHROW( InvalidStateException )
@@ -242,7 +242,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 void ByteArrayAdapter::clear() {
-    memset( this->array, 0, this->capacity );
+    memset( this->array.bytes, 0, this->capacity );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -257,7 +257,7 @@
                 "ByteArrayAdapter::operator[] - Index %d is out of bounds", index );
         }
 
-        return this->array[index];
+        return this->array.bytes[index];
     }
     DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
@@ -275,7 +275,7 @@
                 "ByteArrayAdapter::operator[] - Index %d is out of bounds", index );
         }
 
-        return this->array[index];
+        return this->array.bytes[index];
     }
     DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
@@ -306,7 +306,26 @@
 
     try{
 
-        unsigned long long lvalue = this->getLong( index );
+        if( index >= this->getDoubleCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteArrayAdapter::getDouble(i) - Not enough data to fill a long long." );
+        }
+
+        return this->array.doubles[ index ];
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double ByteArrayAdapter::getDoubleAt( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        unsigned long long lvalue = this->getLongAt( index );
         return Double::longBitsToDouble( lvalue );
     }
     DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
@@ -320,7 +339,26 @@
 
     try{
 
-        unsigned int ivalue = this->getInt( index );
+        if( index >= this->getFloatCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteArrayAdapter::getFloat(i) - Not enough data to fill a long long." );
+        }
+
+        return this->array.floats[ index ];
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float ByteArrayAdapter::getFloatAt( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        unsigned int ivalue = this->getIntAt( index );
         return Float::intBitsToFloat( ivalue );
     }
     DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
@@ -334,7 +372,26 @@
 
     try{
 
-        if( ( index + sizeof(long long) ) > this->getCapacity() ) {
+        if( index >= this->getLongCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteArrayAdapter::getLong(i) - Not enough data to fill a long long." );
+        }
+
+        return this->array.longs[ index ];
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long ByteArrayAdapter::getLongAt( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( ( index + sizeof( long long ) ) > this->getCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::getLong(i) - Not enough data to fill a long long." );
@@ -371,7 +428,26 @@
 
     try{
 
-        if( ( index + sizeof(int) ) > this->getCapacity() ) {
+        if( index >= this->getIntCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteArrayAdapter::getInt(i) - Not enough data to fill an int." );
+        }
+
+        return this->array.ints[ index ];
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int ByteArrayAdapter::getIntAt( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( ( index + sizeof( int ) ) > this->getCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::getInt(i) - Not enough data to fill an int." );
@@ -396,7 +472,26 @@
 
     try{
 
-        if( ( index + sizeof(short) ) > this->getCapacity() ) {
+        if( index >= this->getShortCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteArrayAdapter::getShort(i) - Not enough data to fill a short." );
+        }
+
+        return this->array.shorts[ index ];
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+short ByteArrayAdapter::getShortAt( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException )  {
+
+    try{
+
+        if( ( index + sizeof( short ) ) > this->getCapacity() ) {
             throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteArrayAdapter::getShort(i) - Not enough data to fill a short." );
@@ -455,7 +550,27 @@
 
     try{
 
-        this->putLong( index, Double::doubleToLongBits( value ) );
+        if( index >= this->getDoubleCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteArrayAdapter::putDouble(i,i) - Not enough data to fill request." );
+        }
+
+        this->array.doubles[ index ] = value;
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayAdapter& ByteArrayAdapter::putDoubleAt( std::size_t index, double value )
+    throw( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        this->putLongAt( index, Double::doubleToLongBits( value ) );
         return *this;
     }
     DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
@@ -469,7 +584,27 @@
 
     try{
 
-        this->putInt( index, Float::floatToIntBits( value ) );
+        if( index >= this->getFloatCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteArrayAdapter::putFloat(i,i) - Not enough data to fill request." );
+        }
+
+        this->array.floats[index] = value;
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayAdapter& ByteArrayAdapter::putFloatAt( std::size_t index, float value )
+    throw( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        this->putIntAt( index, Float::floatToIntBits( value ) );
         return *this;
     }
     DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
@@ -483,6 +618,26 @@
 
     try{
 
+        if( index >= this->getLongCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteArrayAdapter::putLong(i,i) - Not enough data to fill request." );
+        }
+
+        this->array.longs[index] = value;
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayAdapter& ByteArrayAdapter::putLongAt( std::size_t index, long long value )
+    throw( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
         unsigned char buffer[sizeof(value)];
 
         buffer[0] = (unsigned char)((value & 0xFF00000000000000ULL) >> 56);
@@ -509,6 +664,26 @@
 
     try{
 
+        if( index >= this->getIntCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteArrayAdapter::putInt(i,i) - Not enough data to fill request." );
+        }
+
+        this->array.ints[index] = value;
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayAdapter& ByteArrayAdapter::putIntAt( std::size_t index, int value )
+    throw( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
         unsigned char buffer[sizeof(value)];
 
         buffer[0] = (value & 0xFF000000) >> 24;
@@ -527,6 +702,26 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 ByteArrayAdapter& ByteArrayAdapter::putShort( std::size_t index, short value )
+    throw( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( index >= this->getShortCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteArrayAdapter::putShort(i,i) - Not enough data to fill request." );
+        }
+
+        this->array.shorts[index] = value;
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayAdapter& ByteArrayAdapter::putShortAt( std::size_t index, short value )
     throw( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/util/ByteArrayAdapter.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/util/ByteArrayAdapter.h?rev=602755&r1=602754&r2=602755&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/util/ByteArrayAdapter.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/util/ByteArrayAdapter.h Sun Dec  9 15:48:51 2007
@@ -40,8 +40,20 @@
     class ByteArrayAdapter {
     private:
 
+        // Used to allow this adapter to view its array as the different
+        // types it supports
+        union Array {
+            unsigned char* bytes;
+            char* chars;
+            short* shorts;
+            int* ints;
+            long long* longs;
+            float* floats;
+            double* doubles;
+        };
+
         // Buffer to read and write to, may be shared with other instances.
-        unsigned char* array;
+        Array array;
 
         // Size of the Buffer
         std::size_t capacity;
@@ -147,12 +159,60 @@
         }
 
         /**
+         * Gets the capacity of the underlying array as if it contains chars
+         * @return the size the array.
+         */
+        virtual std::size_t getCharCapacity() const {
+            return this->capacity;
+        }
+
+        /**
+         * Gets the capacity of the underlying array as if it contains doubles
+         * @return the size the array.
+         */
+        virtual std::size_t getDoubleCapacity() const {
+            return this->capacity / sizeof( double );
+        }
+
+        /**
+         * Gets the capacity of the underlying array as if it contains doubles
+         * @return the size the array.
+         */
+        virtual std::size_t getFloatCapacity() const {
+            return this->capacity / sizeof( float );
+        }
+
+        /**
+         * Gets the capacity of the underlying array as if it contains doubles
+         * @return the size the array.
+         */
+        virtual std::size_t getLongCapacity() const {
+            return this->capacity / sizeof( long long );
+        }
+
+        /**
+         * Gets the capacity of the underlying array as if it contains ints
+         * @return the size the array.
+         */
+        virtual std::size_t getIntCapacity() const {
+            return this->capacity / sizeof( int );
+        }
+
+        /**
+         * Gets the capacity of the underlying array as if it contains shorts
+         * @return the size the array.
+         */
+        virtual std::size_t getShortCapacity() const {
+            return this->capacity / sizeof( short );
+        }
+
+        /**
          * Gets the pointer to the array we are wrapping.  Changes to the data in this
          * array are reflected by all ByteArrayAdapter objects that point to this array.
          * @returns an unsigned char* pointer to the array this object wraps.
          */
         virtual unsigned char* getByteArray() {
-            return this->array;
+            return this->array.bytes;
         }
 
         /**
@@ -161,7 +221,7 @@
          * @returns an char* pointer to the array this object wraps.
          */
         virtual char* getCharArray() {
-            return reinterpret_cast<char*>( this->array );
+            return this->array.chars;
         }
 
         /**
@@ -170,7 +230,7 @@
          * @returns an short* pointer to the array this object wraps.
          */
         virtual short* getShortArray() {
-            return reinterpret_cast<short*>( this->array );
+            return this->array.shorts;
         }
 
         /**
@@ -179,7 +239,7 @@
          * @returns an int* pointer to the array this object wraps.
          */
         virtual int* getIntArray() {
-            return reinterpret_cast<int*>( this->array );
+            return this->array.ints;
         }
 
         /**
@@ -188,7 +248,7 @@
          * @returns an long long* pointer to the array this object wraps.
          */
         virtual long long* getLongArray() {
-            return reinterpret_cast<long long*>( this->array );
+            return this->array.longs;
         }
 
         /**
@@ -197,7 +257,7 @@
          * @returns an double* pointer to the array this object wraps.
          */
         virtual double* getDoubleArray() {
-            return reinterpret_cast<double*>( this->array );
+            return this->array.doubles;
         }
 
         /**
@@ -206,7 +266,7 @@
          * @returns an float* pointer to the array this object wraps.
          */
         virtual float* getFloatArray() {
-            return reinterpret_cast<float*>( this->array );
+            return this->array.floats;
         }
 
         /**
@@ -294,7 +354,10 @@
         }
 
         /**
-         * Reads eight bytes at the given index and returns it
+         * Reads eight bytes at the given index and returns it.  The index is a
+         * relative to the size of the type to be read, in otherwords when accessing
+         * the element in the array index * sizeof( type ) if the actual start index
+         * of the type to be read.
          * @param index - the index in the Buffer where the bytes are to be read
          * @returns the double at the given index in the buffer
          * @throws IndexOutOfBoundsException - If there are not enough bytes
@@ -304,7 +367,20 @@
             throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Reads four bytes at the given index and returns it
+         * Reads eight bytes at the given byte index and returns it
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the double at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual double getDoubleAt( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Reads four bytes at the given index and returns it. The index is a
+         * relative to the size of the type to be read, in otherwords when accessing
+         * the element in the array index * sizeof( type ) if the actual start index
+         * of the type to be read.
          * @param index - the index in the Buffer where the bytes are to be read
          * @returns the float at the given index in the buffer
          * @throws IndexOutOfBoundsException - If there are not enough bytes
@@ -314,7 +390,20 @@
             throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Reads eight bytes at the given index and returns it
+         * Reads four bytes at the given byte index and returns it
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the float at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual float getFloatAt( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Reads eight bytes at the given index and returns it.  The index is a
+         * relative to the size of the type to be read, in otherwords when accessing
+         * the element in the array index * sizeof( type ) if the actual start index
+         * of the type to be read.
          * @param index - the index in the Buffer where the bytes are to be read
          * @returns the long long at the given index in the buffer
          * @throws IndexOutOfBoundsException - If there are not enough bytes
@@ -324,7 +413,20 @@
             throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Reads four bytes at the given index and returns it
+         * Reads eight bytes at the given byte index and returns it.
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the long long at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual long long getLongAt( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Reads four bytes at the given index and returns it.  The index is a
+         * relative to the size of the type to be read, in otherwords when accessing
+         * the element in the array index * sizeof( type ) if the actual start index
+         * of the type to be read.
          * @param index - the index in the Buffer where the bytes are to be read
          * @returns the int at the given index in the buffer
          * @throws IndexOutOfBoundsException - If there are not enough bytes
@@ -334,7 +436,20 @@
             throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Reads two bytes at the given index and returns it
+         * Reads four bytes at the given byte index and returns it.
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the int at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual int getIntAt( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Reads two bytes at the given index and returns it. The index is a
+         * relative to the size of the type to be read, in otherwords when accessing
+         * the element in the array index * sizeof( type ) if the actual start index
+         * of the type to be read.
          * @param index - the index in the Buffer where the bytes are to be read
          * @returns the short at the given index in the buffer
          * @throws IndexOutOfBoundsException - If there are not enough bytes
@@ -344,7 +459,20 @@
             throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Writes the given byte into this buffer at the given index.
+         * Reads two bytes at the given byte index and returns it.
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the short at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual short getShortAt( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Writes the given byte into this buffer at the given index. The index is a
+         * relative to the size of the type to be read, in otherwords when accessing
+         * the element in the array index * sizeof( type ) if the actual start index
+         * of the type to be read.
          * @param index - position in the Buffer to write the data
          * @param value - the byte to write.
          * @returns a reference to this buffer
@@ -356,7 +484,9 @@
 
         /**
          * Writes one byte containing the given value, into this buffer at the
-         * given index.
+         * given index. The index is a relative to the size of the type to be read,
+         * in otherwords when accessing the element in the array index * sizeof( type )
+         * if the actual start index of the type to be read.
          * @param index - position in the Buffer to write the data
          * @param value - the value to write.
          * @returns a reference to this buffer
@@ -368,7 +498,9 @@
 
         /**
          * Writes eight bytes containing the given value, into this buffer at the
-         * given index.
+         * given index. The index is a relative to the size of the type to be read,
+         * in otherwords when accessing the element in the array index * sizeof( type )
+         * if the actual start index of the type to be read.
          * @param index - position in the Buffer to write the data
          * @param value - the value to write.
          * @returns a reference to this buffer
@@ -379,8 +511,22 @@
             throw( lang::exceptions::IndexOutOfBoundsException );
 
         /**
+         * Writes eight bytes containing the given value, into this buffer at the
+         * given byte index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         */
+        virtual ByteArrayAdapter& putDoubleAt( std::size_t index, double value )
+            throw( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
          * Writes four bytes containing the given value, into this buffer at the
-         * given index.
+         * given index. The index is a relative to the size of the type to be read,
+         * in otherwords when accessing the element in the array index * sizeof( type )
+         * if the actual start index of the type to be read.
          * @param index - position in the Buffer to write the data
          * @param value - the value to write.
          * @returns a reference to this buffer
@@ -391,8 +537,22 @@
             throw( lang::exceptions::IndexOutOfBoundsException );
 
         /**
+         * Writes four bytes containing the given value, into this buffer at the
+         * given byte index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         */
+        virtual ByteArrayAdapter& putFloatAt( std::size_t index, float value )
+            throw( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
          * Writes eight bytes containing the given value, into this buffer at the
-         * given index.
+         * given index. The index is a relative to the size of the type to be read,
+         * in otherwords when accessing the element in the array index * sizeof( type )
+         * if the actual start index of the type to be read.
          * @param index - position in the Buffer to write the data
          * @param value - the value to write.
          * @returns a reference to this buffer
@@ -403,8 +563,22 @@
             throw( lang::exceptions::IndexOutOfBoundsException );
 
         /**
+         * Writes eight bytes containing the given value, into this buffer at the
+         * given byte index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         */
+        virtual ByteArrayAdapter& putLongAt( std::size_t index, long long value )
+            throw( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
          * Writes four bytes containing the given value, into this buffer at the
-         * given index.
+         * given index. The index is a relative to the size of the type to be read,
+         * in otherwords when accessing the element in the array index * sizeof( type )
+         * if the actual start index of the type to be read.
          * @param index - position in the Buffer to write the data
          * @param value - the value to write.
          * @returns a reference to this buffer
@@ -415,8 +589,22 @@
             throw( lang::exceptions::IndexOutOfBoundsException );
 
         /**
+         * Writes four bytes containing the given value, into this buffer at the
+         * given byte index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         */
+        virtual ByteArrayAdapter& putIntAt( std::size_t index, int value )
+            throw( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
          * Writes two bytes containing the given value, into this buffer at the
-         * given index.
+         * given index. The index is a relative to the size of the type to be read,
+         * in otherwords when accessing the element in the array index * sizeof( type )
+         * if the actual start index of the type to be read.
          * @param index - position in the Buffer to write the data
          * @param value - the value to write.
          * @returns a reference to this buffer
@@ -424,6 +612,18 @@
          * minus the size of the type being written.
          */
         virtual ByteArrayAdapter& putShort( std::size_t index, short value )
+            throw( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Writes two bytes containing the given value, into this buffer at the
+         * given byte index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         */
+        virtual ByteArrayAdapter& putShortAt( std::size_t index, short value )
             throw( lang::exceptions::IndexOutOfBoundsException );
 
     private:

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/DoubleBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/DoubleBuffer.cpp?rev=602755&r1=602754&r2=602755&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/DoubleBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/DoubleBuffer.cpp Sun Dec  9 15:48:51 2007
@@ -85,13 +85,14 @@
 ////////////////////////////////////////////////////////////////////////////////
 std::string DoubleBuffer::toString() const {
 
-    std::string strbuf;
+    std::ostringstream stream;
 
-    for( std::size_t i = this->position(); i < this->limit(); i++ ) {
-        strbuf.append( Double::valueOf( get( i ) ).toString() );
-    }
+    stream << "DoubleBuffer, status: "
+           << "capacity =" << this->capacity()
+           << " position =" << this->position()
+           << " limit = " << this->limit();
 
-    return strbuf;
+    return stream.str();
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/decaf/trunk/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/Makefile.am?rev=602755&r1=602754&r2=602755&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/Makefile.am Sun Dec  9 15:48:51 2007
@@ -21,6 +21,7 @@
   decaf/internal/nio/ByteArrayBufferTest.cpp \
   decaf/internal/nio/BufferFactoryTest.cpp \
   decaf/internal/nio/CharArrayBufferTest.cpp \
+  decaf/internal/nio/DoubleArrayBufferTest.cpp \
   decaf/lang/ByteTest.cpp \
   decaf/lang/CharacterTest.cpp \
   decaf/lang/BooleanTest.cpp \
@@ -66,6 +67,7 @@
   decaf/internal/nio/ByteArrayBufferTest.h \
   decaf/internal/nio/BufferFactoryTest.h \
   decaf/internal/nio/CharArrayBufferTest.h \
+  decaf/internal/nio/DoubleArrayBufferTest.h \
   decaf/lang/ByteTest.h \
   decaf/lang/CharacterTest.h \
   decaf/lang/BooleanTest.h \

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/ByteArrayBufferTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/ByteArrayBufferTest.cpp?rev=602755&r1=602754&r2=602755&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/ByteArrayBufferTest.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/ByteArrayBufferTest.cpp Sun Dec  9 15:48:51 2007
@@ -585,13 +585,7 @@
         slice->put( ix, testData1[ix] );
     }
 
-    std::cout << "\n TestBuffer1 = " << testBuffer1->toString();
-    std::cout << "\n slice = " << slice->toString();
-    std::cout << "\n slice says its capacity is = " << slice->capacity();
-
     for( std::size_t ix = 0; ix < slice->capacity(); ix++ ) {
-        std::cout << "TestBuffer1 get index = " << ix + 1
-                  << ", slice get index = " << ix << "\n";
         CPPUNIT_ASSERT( testBuffer1->get( ix + 1 ) == slice->get( ix ) );
     }
     testBuffer1->put( 2, 100 );

Added: activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/DoubleArrayBufferTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/DoubleArrayBufferTest.cpp?rev=602755&view=auto
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/DoubleArrayBufferTest.cpp (added)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/DoubleArrayBufferTest.cpp Sun Dec  9 15:48:51 2007
@@ -0,0 +1,596 @@
+/*
+ * 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 "DoubleArrayBufferTest.h"
+#include <decaf/lang/Integer.h>
+#include <decaf/lang/Double.h>
+#include <decaf/lang/Float.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::nio;
+using namespace decaf::internal::nio;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::test() {
+
+    // Check that we have setup the array and our initial assumptions on state
+    // are correct.  This is the first test run.
+    CPPUNIT_ASSERT( testBuffer1 != NULL );
+    CPPUNIT_ASSERT( testBuffer1->capacity() == testData1Size );
+    CPPUNIT_ASSERT( testBuffer1->hasRemaining() == true );
+    CPPUNIT_ASSERT( testBuffer1->limit() == testBuffer1->capacity() );
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+    CPPUNIT_ASSERT( testBuffer1->isReadOnly() == false );
+    CPPUNIT_ASSERT( testBuffer1->toString() != "" );
+    CPPUNIT_ASSERT( testBuffer1->hasArray() == true );
+    CPPUNIT_ASSERT( testBuffer1->array() != NULL );
+    CPPUNIT_ASSERT( testBuffer1->arrayOffset() == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testArray() {
+
+    double* array = testBuffer1->array();
+
+    testBuffer1->put( 0, 10.0 );
+    CPPUNIT_ASSERT( array[0] == 10.0 );
+
+    assertContentEquals(
+        testBuffer1, array, testBuffer1->arrayOffset(), testBuffer1->capacity() );
+
+    loadTestData1( array, testBuffer1->arrayOffset(), testBuffer1->capacity() );
+    assertContentEquals(
+        testBuffer1, array, testBuffer1->arrayOffset(), testBuffer1->capacity()) ;
+
+    loadTestData2( array, testBuffer1->arrayOffset(), testBuffer1->capacity());
+    assertContentEquals(
+        testBuffer1, array, testBuffer1->arrayOffset(), testBuffer1->capacity() );
+
+    loadTestData1( testBuffer1 );
+    assertContentEquals(
+        testBuffer1, array, testBuffer1->arrayOffset(), testBuffer1->capacity() );
+
+    loadTestData2( testBuffer1 );
+    assertContentEquals(
+        testBuffer1, array, testBuffer1->arrayOffset(), testBuffer1->capacity() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testArrayOffset() {
+
+    double* array = testBuffer1->array();
+
+    assertContentEquals(testBuffer1, array, testBuffer1->arrayOffset(), testBuffer1->capacity());
+
+    loadTestData1(array, testBuffer1->arrayOffset(), testBuffer1->capacity());
+    assertContentEquals(testBuffer1, array, testBuffer1->arrayOffset(), testBuffer1->capacity());
+
+    loadTestData2(array, testBuffer1->arrayOffset(), testBuffer1->capacity());
+    assertContentEquals(testBuffer1, array, testBuffer1->arrayOffset(), testBuffer1->capacity());
+
+    loadTestData1(testBuffer1);
+    assertContentEquals(testBuffer1, array, testBuffer1->arrayOffset(), testBuffer1->capacity());
+
+    loadTestData2(testBuffer1);
+    assertContentEquals(testBuffer1, array, testBuffer1->arrayOffset(), testBuffer1->capacity());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testReadOnlyArray() {
+
+    DoubleBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+
+    CPPUNIT_ASSERT( readOnly != NULL );
+    CPPUNIT_ASSERT( readOnly->isReadOnly() == true );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw UnsupportedOperationException",
+        readOnly->array(),
+        UnsupportedOperationException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw UnsupportedOperationException",
+        readOnly->arrayOffset(),
+        UnsupportedOperationException );
+
+    delete readOnly;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testAsReadOnlyBuffer() {
+
+    testBuffer1->clear();
+    testBuffer1->mark();
+    testBuffer1->position( testBuffer1->limit() );
+
+    // readonly's contents should be the same as testBuffer1
+    DoubleBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+    CPPUNIT_ASSERT( testBuffer1 != readOnly );
+    CPPUNIT_ASSERT( readOnly->isReadOnly() );
+    CPPUNIT_ASSERT( testBuffer1->position() == readOnly->position() );
+    CPPUNIT_ASSERT( testBuffer1->limit() == readOnly->limit() );
+
+    for( std::size_t i = 0; i < testBuffer1->capacity(); ++i ) {
+        CPPUNIT_ASSERT( testBuffer1->get( i ) == readOnly->get( i ) );
+    }
+
+    // readOnly's position, mark, and limit should be independent to testBuffer1
+    readOnly->reset();
+    CPPUNIT_ASSERT( readOnly->position() == 0 );
+    readOnly->clear();
+    CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->limit() );
+    testBuffer1->reset();
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    delete readOnly;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testCompact() {
+
+    loadTestData1( testBuffer1 );
+
+    // case: buffer is full
+    testBuffer1->clear();
+    testBuffer1->mark();
+
+    DoubleBuffer& ret = testBuffer1->compact();
+    CPPUNIT_ASSERT( &ret == testBuffer1 );
+    CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->capacity() );
+    CPPUNIT_ASSERT( testBuffer1->limit() == testBuffer1->capacity() );
+
+    assertContentLikeTestData1( testBuffer1, 0, 0.0, testBuffer1->capacity() );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw InvalidMarkException",
+        testBuffer1->reset(),
+        InvalidMarkException );
+
+    // case: buffer is empty
+    testBuffer1->position(0);
+    testBuffer1->limit(0);
+    testBuffer1->mark();
+    ret = testBuffer1->compact();
+    CPPUNIT_ASSERT( &ret == testBuffer1 );
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+    CPPUNIT_ASSERT( testBuffer1->limit() == testBuffer1->capacity() );
+
+    assertContentLikeTestData1(testBuffer1, 0, 0.0, testBuffer1->capacity());
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw InvalidMarkException",
+        testBuffer1->reset(),
+        InvalidMarkException );
+
+    // case: normal
+    CPPUNIT_ASSERT( testBuffer1->capacity() > 5 );
+
+    testBuffer1->position(1);
+    testBuffer1->limit(5);
+    testBuffer1->mark();
+    ret = testBuffer1->compact();
+    CPPUNIT_ASSERT( &ret == testBuffer1);
+    CPPUNIT_ASSERT( testBuffer1->position() == 4 );
+    CPPUNIT_ASSERT( testBuffer1->limit() == testBuffer1->capacity() );
+
+    assertContentLikeTestData1(testBuffer1, 0, 1.0, 4);
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw InvalidMarkException",
+        testBuffer1->reset(),
+        InvalidMarkException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testCompareTo() {
+
+    DoubleBuffer* other = DoubleBuffer::allocate( testBuffer1->capacity() );
+
+    loadTestData1(testBuffer1);
+    loadTestData1(other);
+
+    CPPUNIT_ASSERT( 0 == testBuffer1->compareTo( *other ) );
+    CPPUNIT_ASSERT( 0 == other->compareTo( *testBuffer1 ) );
+    testBuffer1->position(1);
+    CPPUNIT_ASSERT( testBuffer1->compareTo( *other ) > 0 );
+    CPPUNIT_ASSERT( other->compareTo( *testBuffer1 ) < 0 );
+    other->position( 2 );
+    CPPUNIT_ASSERT( testBuffer1->compareTo( *other ) < 0 );
+    CPPUNIT_ASSERT( other->compareTo( *testBuffer1 ) > 0 );
+    testBuffer1->position(2);
+    other->limit(5);
+    CPPUNIT_ASSERT( testBuffer1->compareTo( *other ) > 0 );
+    CPPUNIT_ASSERT( other->compareTo( *testBuffer1 ) < 0 );
+
+    std::vector<double> array1( 1, Double::NaN );
+    std::vector<double> array2( 1, Double::NaN );
+    std::vector<double> array3( 1, 42.0 );
+
+    DoubleBuffer* dbuffer1 = DoubleBuffer::wrap( array1 );
+    DoubleBuffer* dbuffer2 = DoubleBuffer::wrap( array2 );
+    DoubleBuffer* dbuffer3 = DoubleBuffer::wrap( array3 );
+
+//    CPPUNIT_ASSERT_MESSAGE(
+//        "Failed equal comparison with NaN entry",
+//        dbuffer1->compareTo( *dbuffer2 ) );
+//    CPPUNIT_ASSERT_MESSAGE(
+//        "Failed greater than comparison with NaN entry",
+//        dbuffer3->compareTo( *dbuffer1 ) );
+//    CPPUNIT_ASSERT_MESSAGE(
+//        "Failed greater than comparison with NaN entry",
+//        dbuffer1->compareTo( *dbuffer3 ) );
+
+    delete other;
+    delete dbuffer1;
+    delete dbuffer2;
+    delete dbuffer3;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testDuplicate() {
+    testBuffer1->clear();
+    testBuffer1->mark();
+    testBuffer1->position(testBuffer1->limit());
+
+    // duplicate's contents should be the same as testBuffer1
+    DoubleBuffer* duplicate = testBuffer1->duplicate();
+    CPPUNIT_ASSERT( testBuffer1 == duplicate );
+    CPPUNIT_ASSERT( testBuffer1->position() == duplicate->position() );
+    CPPUNIT_ASSERT( testBuffer1->limit() == duplicate->limit() );
+    CPPUNIT_ASSERT( testBuffer1->isReadOnly() == duplicate->isReadOnly() );
+    assertContentEquals( testBuffer1, duplicate );
+
+    // duplicate's position, mark, and limit should be independent to testBuffer1
+    duplicate->reset();
+    CPPUNIT_ASSERT( duplicate->position() == 0 );
+    duplicate->clear();
+    CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->limit() );
+    testBuffer1->reset();
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    delete duplicate;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testEquals() {
+
+    // equal to self
+    CPPUNIT_ASSERT( testBuffer1->equals( *testBuffer1 ) );
+    DoubleBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+    CPPUNIT_ASSERT( testBuffer1->equals( *readOnly ) );
+    DoubleBuffer* duplicate = testBuffer1->duplicate();
+    CPPUNIT_ASSERT( testBuffer1->equals( *duplicate ) );
+
+    CPPUNIT_ASSERT( testBuffer1->capacity() > 5 );
+
+    testBuffer1->limit( testBuffer1->capacity() ).position(0);
+    readOnly->limit( readOnly->capacity() ).position( 1 );
+    CPPUNIT_ASSERT( !testBuffer1->equals( *readOnly ) );
+
+    testBuffer1->limit( testBuffer1->capacity() - 1).position(0);
+    duplicate->limit( duplicate->capacity() ).position( 0 );
+    CPPUNIT_ASSERT( !testBuffer1->equals( *duplicate ) );
+
+    delete readOnly;
+    delete duplicate;
+}
+
+/*
+ * Class under test for double get()
+ */
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testGet() {
+
+    testBuffer1->clear();
+    for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+        CPPUNIT_ASSERT( testBuffer1->position() == i );
+        CPPUNIT_ASSERT( testBuffer1->get() == testBuffer1->get(i) );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferUnderflowException",
+        testBuffer1->get(),
+        BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testGetDoubleArray() {
+
+    std::vector<double> array(1);
+    testBuffer1->clear();
+
+    for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+        CPPUNIT_ASSERT( testBuffer1->position() == i );
+        DoubleBuffer& ret = testBuffer1->get( array );
+        CPPUNIT_ASSERT( array[0] == testBuffer1->get(i) );
+        CPPUNIT_ASSERT( &ret == testBuffer1 );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferUnderflowException",
+        testBuffer1->get( array ),
+        BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testGetDoubleArray2() {
+
+    testBuffer1->clear();
+    double* array = new double[testBuffer1->capacity()];
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferUnderflowException",
+        testBuffer1->get( array, 0, testBuffer1->capacity() ),
+        BufferUnderflowException );
+
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    testBuffer1->get( array, 10, 0 );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw IndexOutOfBoundsException",
+        testBuffer1->get( array, testBuffer1->capacity() + 1, 1 ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw IndexOutOfBoundsException",
+        testBuffer1->get(array, 2, testBuffer1->capacity() ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw IndexOutOfBoundsException",
+        testBuffer1->get( array, 1, Integer::MAX_VALUE ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw IndexOutOfBoundsException",
+        testBuffer1->get( array, Integer::MAX_VALUE, 1 ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    testBuffer1->clear();
+    DoubleBuffer& ret = testBuffer1->get( array, 0, testBuffer1->capacity() );
+    CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->capacity() );
+    assertContentEquals( testBuffer1, array, 0, testBuffer1->capacity() );
+    CPPUNIT_ASSERT( &ret == testBuffer1 );
+
+    delete array;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testGet2() {
+
+    testBuffer1->clear();
+    for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+        CPPUNIT_ASSERT( testBuffer1->position() == i );
+        CPPUNIT_ASSERT( testBuffer1->get() == testBuffer1->get(i) );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferOverflowException",
+        testBuffer1->get( testBuffer1->limit() ),
+        BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testHasArray() {
+    CPPUNIT_ASSERT( testBuffer1->hasArray() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testPutDouble() {
+
+    testBuffer1->clear();
+
+    for( std::size_t i = 0; i < testBuffer1->capacity(); i++) {
+        CPPUNIT_ASSERT( testBuffer1->position() == i );
+        DoubleBuffer& ret = testBuffer1->put( (double)i );
+        CPPUNIT_ASSERT( testBuffer1->get(i) == (double)i );
+        CPPUNIT_ASSERT( &ret == testBuffer1 );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferOverflowException",
+        testBuffer1->put( 0 ),
+        BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testPutDoubleArray() {
+
+    double* array = new double[1];
+
+    testBuffer1->clear();
+    for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+        CPPUNIT_ASSERT( testBuffer1->position() == i );
+        array[0] = (double) i;
+        DoubleBuffer& ret = testBuffer1->put( array, 0, 1 );
+        CPPUNIT_ASSERT( testBuffer1->get(i) == (double)i );
+        CPPUNIT_ASSERT( &ret == testBuffer1 );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferOverflowException",
+        testBuffer1->put( array, 0, 1 ),
+        BufferOverflowException );
+
+    delete array;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testPutDoubleArray2() {
+
+    testBuffer1->clear();
+    double* array1 = new double[ testBuffer1->capacity() ];
+    double* array2 = new double[ testBuffer1->capacity() + 1 ];
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferOverflowException",
+        testBuffer1->put( array2, 0, testBuffer1->capacity() + 1 ),
+        BufferOverflowException );
+
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferOverflowException",
+        testBuffer1->put( array1, testBuffer1->capacity() + 1, 0 ),
+        BufferOverflowException );
+
+    testBuffer1->put( array1, testBuffer1->capacity() + 1, 0 );
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw IndexOutOfBoundsException",
+        testBuffer1->put( array1, 2, testBuffer1->capacity() + 1 ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw IndexOutOfBoundsException",
+        testBuffer1->put( array1, Integer::MAX_VALUE, 1 ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw IndexOutOfBoundsException",
+        testBuffer1->put( array1, 1, Integer::MAX_VALUE ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    loadTestData2( array1, 0, testBuffer1->capacity() );
+    DoubleBuffer& ret = testBuffer1->put( array1, 0, testBuffer1->capacity() );
+    CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->capacity() );
+    assertContentEquals( testBuffer1, array1, 0, testBuffer1->capacity() );
+    CPPUNIT_ASSERT( &ret == testBuffer1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testPutDoubleBuffer() {
+
+    DoubleBuffer* other = DoubleBuffer::allocate( testBuffer1->capacity() );
+    DoubleBuffer* other1 = DoubleBuffer::allocate( testBuffer1->capacity() + 1 );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw IllegalArgumentException",
+        testBuffer1->put( *testBuffer1 ),
+        IllegalArgumentException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferOverflowException",
+        testBuffer1->put( *other1 ),
+        BufferOverflowException );
+
+    loadTestData2(other);
+    other->clear();
+    testBuffer1->clear();
+    DoubleBuffer& ret = testBuffer1->put( *other );
+
+    CPPUNIT_ASSERT( other->position() == other->capacity() );
+    CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->capacity() );
+    assertContentEquals( other, testBuffer1 );
+    CPPUNIT_ASSERT( &ret == testBuffer1 );
+
+    delete other;
+    delete other1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testGetWithIndex() {
+
+    testBuffer1->clear();
+
+    for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+        CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+        DoubleBuffer& ret = testBuffer1->put( i, (double)i );
+        CPPUNIT_ASSERT( testBuffer1->get(i) == (double)i );
+        CPPUNIT_ASSERT( &ret == testBuffer1 );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw IndexOutOfBoundsException",
+        testBuffer1->put( testBuffer1->limit(), 0 ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testPutIndexed() {
+
+    DoubleBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+    readOnly->clear();
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a ReadOnlyBufferException",
+        readOnly->put( 0, 0 ),
+        ReadOnlyBufferException );
+    delete readOnly;
+
+    testBuffer1->clear();
+
+    for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+        CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+        DoubleBuffer& ret = testBuffer1->put(i, i );
+        CPPUNIT_ASSERT( testBuffer1->get(i) == i );
+        CPPUNIT_ASSERT( &ret == testBuffer1 );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1->put( testBuffer1->limit(), 0 ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testSlice() {
+
+    CPPUNIT_ASSERT( testBuffer1->capacity() > 5 );
+    testBuffer1->position(1);
+    testBuffer1->limit(testBuffer1->capacity() - 1);
+
+    DoubleBuffer* slice = testBuffer1->slice();
+    CPPUNIT_ASSERT( testBuffer1->isReadOnly() == slice->isReadOnly() );
+    CPPUNIT_ASSERT( slice->position() == 0 );
+    CPPUNIT_ASSERT( slice->limit() == testBuffer1->remaining() );
+    CPPUNIT_ASSERT( slice->capacity() == testBuffer1->remaining() );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw InvalidMarkException",
+        slice->reset(),
+        InvalidMarkException );
+
+    // slice share the same content with testBuffer1
+    // FIXME:
+    loadTestData1(slice);
+    assertContentLikeTestData1(testBuffer1, 1, 0, slice->capacity());
+    testBuffer1->put( 2, 500 );
+    CPPUNIT_ASSERT( slice->get(1) == 500 );
+
+    delete slice;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+void DoubleArrayBufferTest::testToString() {
+
+    std::string str = testBuffer1->toString();
+    CPPUNIT_ASSERT( str.find("Double") != string::npos );
+    CPPUNIT_ASSERT( str.find( Integer::toString( testBuffer1->position() ) ) != string::npos );
+    CPPUNIT_ASSERT( str.find( Integer::toString( testBuffer1->limit() ) ) != string::npos );
+    CPPUNIT_ASSERT( str.find( Integer::toString( testBuffer1->capacity() ) ) != string::npos );
+}

Added: activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/DoubleArrayBufferTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/DoubleArrayBufferTest.h?rev=602755&view=auto
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/DoubleArrayBufferTest.h (added)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/DoubleArrayBufferTest.h Sun Dec  9 15:48:51 2007
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_INTERNAL_NIO_DOUBLEARRAYBUFFERTEST_H_
+#define _DECAF_INTERNAL_NIO_DOUBLEARRAYBUFFERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/nio/DoubleBuffer.h>
+
+namespace decaf{
+namespace internal{
+namespace nio{
+
+    class DoubleArrayBufferTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( DoubleArrayBufferTest );
+        CPPUNIT_TEST( test );
+        CPPUNIT_TEST( testArray );
+        CPPUNIT_TEST( testArrayOffset );
+        CPPUNIT_TEST( testReadOnlyArray );
+        CPPUNIT_TEST( testAsReadOnlyBuffer );
+        CPPUNIT_TEST( testCompact );
+        CPPUNIT_TEST( testCompareTo );
+//        CPPUNIT_TEST( testDuplicate );
+//        CPPUNIT_TEST( testEquals );
+//        CPPUNIT_TEST( testHasArray );
+//        CPPUNIT_TEST( testGet );
+//        CPPUNIT_TEST( testGet2 );
+//        CPPUNIT_TEST( testGetDoubleArray );
+//        CPPUNIT_TEST( testGetDoubleArray2 );
+//        CPPUNIT_TEST( testGetWithIndex );
+//        CPPUNIT_TEST( testPutDouble );
+//        CPPUNIT_TEST( testPutDoubleArray );
+//        CPPUNIT_TEST( testPutDoubleArray2 );
+//        CPPUNIT_TEST( testPutDoubleBuffer );
+//        CPPUNIT_TEST( testPutIndexed );
+//        CPPUNIT_TEST( testSlice );
+//        CPPUNIT_TEST( testToString );
+        CPPUNIT_TEST_SUITE_END();
+
+        decaf::nio::DoubleBuffer* testBuffer1;
+        double* testData1;
+
+        static const std::size_t testData1Size = 100;
+        static const std::size_t SMALL_TEST_LENGTH = 5;
+        static const std::size_t BUFFER_LENGTH = 250;
+
+    public:
+
+        DoubleArrayBufferTest() {}
+        virtual ~DoubleArrayBufferTest() {}
+
+        void setUp() {
+            testBuffer1 = decaf::nio::DoubleBuffer::allocate( testData1Size );
+
+            testData1 = new double[testData1Size];
+            for( std::size_t i = 0; i < testData1Size; ++i ){
+                testData1[i] = (double)i;
+            }
+        }
+
+        void tearDown() {
+            delete testBuffer1;
+            delete testData1;
+        }
+
+        void test();
+        void testArray();
+        void testArrayOffset();
+        void testReadOnlyArray();
+        void testAsReadOnlyBuffer();
+        void testCompact();
+        void testCompareTo();
+        void testDuplicate();
+        void testEquals();
+        void testHasArray();
+        void testGet();
+        void testGet2();
+        void testGetDoubleArray();
+        void testGetDoubleArray2();
+        void testGetWithIndex();
+        void testPutDouble();
+        void testPutDoubleArray();
+        void testPutDoubleArray2();
+        void testPutDoubleBuffer();
+        void testPutIndexed();
+        void testSlice();
+        void testToString();
+
+    protected:
+
+        void loadTestData1( double* array, std::size_t offset, std::size_t length ) {
+            for( std::size_t i = 0; i < length; i++ ) {
+                array[offset + i] = (double)i;
+            }
+        }
+
+        void loadTestData2( double* array, std::size_t offset, std::size_t length ) {
+            for( std::size_t i = 0; i < length; i++ ) {
+                array[offset + i] = (double)length - i;
+            }
+        }
+
+        void loadTestData1( decaf::nio::DoubleBuffer* buf ) {
+            buf->clear();
+            for( std::size_t i = 0; i < buf->capacity(); i++ ) {
+                buf->put( i, (double)i );
+            }
+        }
+
+        void loadTestData2( decaf::nio::DoubleBuffer* buf ) {
+            buf->clear();
+            for( std::size_t i = 0; i < buf->capacity(); i++ ) {
+                buf->put(i, (double) buf->capacity() - i);
+            }
+        }
+
+        void assertContentEquals( decaf::nio::DoubleBuffer* buf, double* array,
+                                  std::size_t offset, std::size_t length) {
+
+            for( std::size_t i = 0; i < length; i++ ) {
+                CPPUNIT_ASSERT( buf->get(i) == array[offset + i] );
+            }
+        }
+
+        void assertContentEquals( decaf::nio::DoubleBuffer* buf,
+                                  decaf::nio::DoubleBuffer* other ) {
+            CPPUNIT_ASSERT( buf->capacity() == other->capacity() );
+            for( std::size_t i = 0; i < buf->capacity(); i++ ) {
+                CPPUNIT_ASSERT(buf->get(i) == other->get(i) );
+            }
+        }
+
+        void assertContentLikeTestData1(
+            decaf::nio::DoubleBuffer* buf, std::size_t startIndex,
+            double startValue, std::size_t length ) {
+
+            double value = startValue;
+            for( std::size_t i = 0; i < length; i++ ) {
+                CPPUNIT_ASSERT( buf->get( startIndex + i ) == value );
+                value = value + 1.0;
+            }
+        }
+
+    };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_NIO_DOUBLEARRAYBUFFERTEST_H_*/

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=602755&r1=602754&r2=602755&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 Sun Dec  9 15:48:51 2007
@@ -311,7 +311,7 @@
     ByteArrayAdapter testBuffer1( testData1Size );
 
     std::size_t i = 0;
-    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(long long); i+=sizeof(long long) ) {
+    for( ; i < testBuffer1.getLongCapacity(); ++i  ) {
         testBuffer1.putLong( i, i + 99 );
         CPPUNIT_ASSERT( testBuffer1.getLong( i ) == (long long)(i + 99) );
     }
@@ -328,7 +328,7 @@
     ByteArrayAdapter testBuffer1( testData1Size );
 
     std::size_t i = 0;
-    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(int); i+=sizeof(int) ) {
+    for( ; i < testBuffer1.getIntCapacity(); ++i  ) {
         testBuffer1.putInt( i, i + 99 );
         CPPUNIT_ASSERT( testBuffer1.getInt( i ) == (int)(i + 99) );
     }
@@ -345,7 +345,7 @@
     ByteArrayAdapter testBuffer1( testData1Size );
 
     std::size_t i = 0;
-    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(short); i+=sizeof(short) ) {
+    for( ; i < testBuffer1.getShortCapacity(); ++i  ) {
         testBuffer1.putShort( i, i + 99 );
         CPPUNIT_ASSERT( testBuffer1.getShort( i ) == (short)(i + 99) );
     }
@@ -362,7 +362,7 @@
     ByteArrayAdapter testBuffer1( testData1Size );
 
     std::size_t i = 0;
-    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(double); i+=sizeof(double) ) {
+    for( ; i < testBuffer1.getDoubleCapacity(); ++i  ) {
         testBuffer1.putDouble( i, i + 99.025 );
         CPPUNIT_ASSERT( Double::doubleToLongBits( testBuffer1.getDouble( i ) ) ==
                         Double::doubleToLongBits( (double)(i + 99.025) ) );
@@ -380,7 +380,7 @@
     ByteArrayAdapter testBuffer1( testData1Size );
 
     std::size_t i = 0;
-    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof(float); i+=sizeof(float) ) {
+    for( ; i < testBuffer1.getFloatCapacity(); ++i  ) {
         testBuffer1.putFloat( i, i + 99.025 );
         CPPUNIT_ASSERT( Float::floatToIntBits( testBuffer1.getFloat( i ) ) ==
                         Float::floatToIntBits( (float)(i + 99.025) ) );
@@ -398,7 +398,7 @@
     ByteArrayAdapter testBuffer1( testData1Size );
 
     std::vector<unsigned char> values;
-    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( char ); i += sizeof( char ) ) {
+    for( std::size_t i = 0; i < testBuffer1.getCapacity(); ++i ) {
         testBuffer1.put( i, (unsigned char)i );
         values.push_back( (unsigned char)i );
     }
@@ -406,7 +406,7 @@
     std::size_t i = 0;
     std::size_t j = 0;
 
-    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( unsigned char ); i += sizeof( unsigned char ), j++ ) {
+    for( ; i < testBuffer1.getCapacity(); ++i, ++j ) {
         CPPUNIT_ASSERT( testBuffer1.get( i ) == values[j] );
     }
 
@@ -422,7 +422,7 @@
     ByteArrayAdapter testBuffer1( testData1Size );
 
     std::vector<char> values;
-    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( char ); i += sizeof( char ) ) {
+    for( std::size_t i = 0; i < testBuffer1.getCapacity(); ++i ) {
         testBuffer1.putChar( i, (char)i );
         values.push_back( (char)i );
     }
@@ -430,7 +430,7 @@
     std::size_t i = 0;
     std::size_t j = 0;
 
-    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( char ); i += sizeof( char ), j++ ) {
+    for( ; i < testBuffer1.getCapacity(); ++i, ++j ) {
         CPPUNIT_ASSERT( testBuffer1.getChar( i ) == values[j] );
     }
 
@@ -446,7 +446,7 @@
     ByteArrayAdapter testBuffer1( testData1Size );
 
     std::vector<short> values;
-    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( short ); i += sizeof( short ) ) {
+    for( std::size_t i = 0; i < testBuffer1.getShortCapacity(); ++i ) {
         testBuffer1.putShort( i, (short)i );
         values.push_back( (short)i );
     }
@@ -454,7 +454,7 @@
     std::size_t i = 0;
     std::size_t j = 0;
 
-    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( short ); i += sizeof( short ), j++ ) {
+    for( ; i < testBuffer1.getShortCapacity(); ++i, ++j ) {
         CPPUNIT_ASSERT( testBuffer1.getShort( i ) == values[j] );
     }
 
@@ -470,7 +470,7 @@
     ByteArrayAdapter testBuffer1( testData1Size );
 
     std::vector<int> values;
-    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( int ); i += sizeof( int ) ) {
+    for( std::size_t i = 0; i < testBuffer1.getIntCapacity(); ++i ) {
         testBuffer1.putInt( i, (int)i );
         values.push_back( (int)i );
     }
@@ -478,7 +478,7 @@
     std::size_t i = 0;
     std::size_t j = 0;
 
-    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( int ); i += sizeof( int ), j++ ) {
+    for( ; i < testBuffer1.getIntCapacity(); ++i, ++j ) {
         CPPUNIT_ASSERT( testBuffer1.getInt( i ) == values[j] );
     }
 
@@ -494,7 +494,7 @@
     ByteArrayAdapter testBuffer1( testData1Size );
 
     std::vector<long long> values;
-    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( long long ); i += sizeof( long long ) ) {
+    for( std::size_t i = 0; i < testBuffer1.getLongCapacity(); ++i ) {
         testBuffer1.putLong( i, (long long)i );
         values.push_back( (long long)i );
     }
@@ -502,7 +502,7 @@
     std::size_t i = 0;
     std::size_t j = 0;
 
-    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( long long ); i += sizeof( long long ), j++ ) {
+    for( ; i < testBuffer1.getLongCapacity(); ++i, ++j ) {
         CPPUNIT_ASSERT( testBuffer1.getLong( i ) == values[j] );
     }
 
@@ -518,7 +518,7 @@
     ByteArrayAdapter testBuffer1( testData1Size );
 
     std::vector<float> values;
-    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( float ); i += sizeof( float ) ) {
+    for( std::size_t i = 0; i < testBuffer1.getFloatCapacity(); ++i ) {
         testBuffer1.putFloat( i, (float)i + 0.025f );
         values.push_back( (float)i + 0.025f );
     }
@@ -526,7 +526,7 @@
     std::size_t i = 0;
     std::size_t j = 0;
 
-    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( float ); i += sizeof( float ), j++ ) {
+    for( ; i < testBuffer1.getFloatCapacity(); ++i, ++j ) {
         CPPUNIT_ASSERT( Float::floatToIntBits( testBuffer1.getFloat( i ) ) ==
                         Float::floatToIntBits( values[j] ) );
     }
@@ -543,7 +543,7 @@
     ByteArrayAdapter testBuffer1( testData1Size );
 
     std::vector<double> values;
-    for( std::size_t i = 0; ( testBuffer1.getCapacity() - i ) >= sizeof( double ); i += sizeof( double ) ) {
+    for( std::size_t i = 0; i < testBuffer1.getDoubleCapacity(); ++i ) {
         testBuffer1.putDouble( i, (double)i + 0.025 );
         values.push_back( (double)i + 0.025 );
     }
@@ -551,7 +551,7 @@
     std::size_t i = 0;
     std::size_t j = 0;
 
-    for( ; ( testBuffer1.getCapacity() - i ) >= sizeof( double ); i += sizeof( double ), j++ ) {
+    for( ; i < testBuffer1.getDoubleCapacity(); ++i, ++j ) {
         CPPUNIT_ASSERT( Double::doubleToLongBits( testBuffer1.getDouble( i ) ) ==
                         Double::doubleToLongBits( values[j] ) );
     }

Modified: activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp?rev=602755&r1=602754&r2=602755&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp Sun Dec  9 15:48:51 2007
@@ -28,6 +28,8 @@
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::internal::nio::BufferFactoryTest );
 #include <decaf/internal/nio/CharArrayBufferTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::internal::nio::CharArrayBufferTest );
+#include <decaf/internal/nio/DoubleArrayBufferTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::internal::nio::DoubleArrayBufferTest );
 
 #include <decaf/nio/BufferTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::nio::BufferTest );



Mime
View raw message