You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/12/11 15:45:35 UTC

svn commit: r603262 - in /activemq/activemq-cpp/decaf/trunk/src: main/decaf/internal/nio/ main/decaf/nio/ test/ test/decaf/internal/nio/

Author: tabish
Date: Tue Dec 11 06:45:34 2007
New Revision: 603262

URL: http://svn.apache.org/viewvc?rev=603262&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/FloatArrayBufferTest.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/FloatArrayBufferTest.h
Modified:
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/FloatBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/Makefile.am
    activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp?rev=603262&r1=603261&r2=603262&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp Tue Dec 11 06:45:34 2007
@@ -20,6 +20,7 @@
 #include <decaf/internal/nio/ByteArrayBuffer.h>
 #include <decaf/internal/nio/CharArrayBuffer.h>
 #include <decaf/internal/nio/DoubleArrayBuffer.h>
+#include <decaf/internal/nio/FloatArrayBuffer.h>
 
 using namespace decaf;
 using namespace decaf::internal;
@@ -125,6 +126,40 @@
 
     try{
         return new DoubleArrayBuffer( &buffer[0], 0, buffer.size(), false );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+FloatBuffer* BufferFactory::createFloatBuffer( std::size_t capacity ) {
+
+    try{
+        return new FloatArrayBuffer( capacity );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+FloatBuffer* BufferFactory::createFloatBuffer( float* buffer,
+                                               std::size_t offset,
+                                               std::size_t length )
+    throw( lang::exceptions::NullPointerException ) {
+
+    try{
+        return new FloatArrayBuffer( buffer, offset, length, false );
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
+    DECAF_CATCHALL_THROW( NullPointerException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+FloatBuffer* BufferFactory::createFloatBuffer( std::vector<float>& buffer ) {
+
+    try{
+        return new FloatArrayBuffer( &buffer[0], 0, buffer.size(), false );
     }
     DECAF_CATCH_RETHROW( Exception )
     DECAF_CATCHALL_THROW( Exception )

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h?rev=603262&r1=603261&r2=603262&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h Tue Dec 11 06:45:34 2007
@@ -120,7 +120,7 @@
         static decaf::nio::CharBuffer* createCharBuffer( std::vector<char>& buffer );
 
         /**
-         * Allocates a new char buffer whose position will be zero its limit will
+         * Allocates a new double buffer whose position will be zero its limit will
          * be its capacity and its mark is not set.
          * @param capacity - the internal buffer's capacity.
          * @returns a newly allocated DoubleBuffer which the caller owns.
@@ -158,6 +158,46 @@
          * @returns a new DoubleBuffer that is backed by buffer, caller owns.
          */
         static decaf::nio::DoubleBuffer* createDoubleBuffer( std::vector<double>& buffer );
+
+        /**
+         * Allocates a new float buffer whose position will be zero its limit will
+         * be its capacity and its mark is not set.
+         * @param capacity - the internal buffer's capacity.
+         * @returns a newly allocated DoubleBuffer which the caller owns.
+         */
+        static decaf::nio::FloatBuffer* createFloatBuffer( std::size_t capacity );
+
+        /**
+         * Wraps the passed buffer with a new FloatBuffer.
+         * <p>
+         * The new buffer will be backed by the given byte array; that is, modifications
+         * to the buffer will cause the array to be modified and vice versa. The new
+         * buffer's capacity will be array.length, its position will be offset, its limit
+         * will be offset + length, and its mark will be undefined. Its backing array
+         * will be the given array, and its array offset will be zero.
+         * @param buffer - The array that will back the new buffer
+         * @param offset - The offset of the subarray to be used
+         * @param length - The length of the subarray to be used
+         * @returns a new DoubleBuffer that is backed by buffer, caller owns.
+         */
+        static decaf::nio::FloatBuffer* createFloatBuffer( float* buffer,
+                                                           std::size_t offset,
+                                                           std::size_t length )
+            throw( lang::exceptions::NullPointerException );
+
+        /**
+         * Wraps the passed STL Float Vector in a DoubleBuffer.
+         * <p>
+         * The new buffer will be backed by the given byte array; modifications to the
+         * buffer will cause the array to be modified and vice versa. The new buffer's
+         * capacity and limit will be buffer.size(), its position will be zero, and its
+         * mark will be undefined. Its backing array will be the given array, and its
+         * array offset will be zero.
+         * @param buffer - The vector that will back the new buffer, the vector must
+         * have been sized to the desired size already by calling vector.resize( N ).
+         * @returns a new DoubleBuffer that is backed by buffer, caller owns.
+         */
+        static decaf::nio::FloatBuffer* createFloatBuffer( std::vector<float>& buffer );
 
     };
 

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/FloatBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/FloatBuffer.cpp?rev=603262&r1=603261&r2=603262&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/FloatBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/FloatBuffer.cpp Tue Dec 11 06:45:34 2007
@@ -19,10 +19,12 @@
 
 #include <decaf/lang/Float.h>
 #include <decaf/lang/Math.h>
+#include "decaf/internal/nio/BufferFactory.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;
 
@@ -30,6 +32,54 @@
 FloatBuffer::FloatBuffer( std::size_t capacity )
  :  Buffer( capacity ) {
 
+}
+
+////////////////////////////////////////////////////////////////////////////////
+FloatBuffer* FloatBuffer::allocate( std::size_t capacity ) {
+
+    try{
+
+        return BufferFactory::createFloatBuffer( capacity );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+FloatBuffer* FloatBuffer::wrap( float* buffer, std::size_t offset, std::size_t length )
+    throw( lang::exceptions::NullPointerException ) {
+
+    try{
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "CharBuffer::wrap - Passed Buffer is Null.");
+        }
+
+        return BufferFactory::createFloatBuffer( buffer, offset, length );
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
+    DECAF_CATCHALL_THROW( NullPointerException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+FloatBuffer* FloatBuffer::wrap( std::vector<float>& buffer ) {
+
+    try{
+
+        if( buffer.empty() ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "DoubleBuffer::wrap - Passed Buffer is Empty.");
+        }
+
+        return BufferFactory::createFloatBuffer( &buffer[0], 0, buffer.size() );
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
+    DECAF_CATCHALL_THROW( NullPointerException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////

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=603262&r1=603261&r2=603262&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/Makefile.am Tue Dec 11 06:45:34 2007
@@ -22,6 +22,7 @@
   decaf/internal/nio/BufferFactoryTest.cpp \
   decaf/internal/nio/CharArrayBufferTest.cpp \
   decaf/internal/nio/DoubleArrayBufferTest.cpp \
+  decaf/internal/nio/FloatArrayBufferTest.cpp \
   decaf/lang/ByteTest.cpp \
   decaf/lang/CharacterTest.cpp \
   decaf/lang/BooleanTest.cpp \
@@ -68,6 +69,7 @@
   decaf/internal/nio/BufferFactoryTest.h \
   decaf/internal/nio/CharArrayBufferTest.h \
   decaf/internal/nio/DoubleArrayBufferTest.h \
+  decaf/internal/nio/FloatArrayBufferTest.h \
   decaf/lang/ByteTest.h \
   decaf/lang/CharacterTest.h \
   decaf/lang/BooleanTest.h \

Added: activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/FloatArrayBufferTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/FloatArrayBufferTest.cpp?rev=603262&view=auto
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/FloatArrayBufferTest.cpp (added)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/FloatArrayBufferTest.cpp Tue Dec 11 06:45:34 2007
@@ -0,0 +1,556 @@
+/*
+ * 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 "FloatArrayBufferTest.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 FloatArrayBufferTest::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 FloatArrayBufferTest::testArray() {
+
+    float* 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 FloatArrayBufferTest::testArrayOffset() {
+
+    float* 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 FloatArrayBufferTest::testReadOnlyArray() {
+
+    FloatBuffer* 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 FloatArrayBufferTest::testAsReadOnlyBuffer() {
+
+    testBuffer1->clear();
+    testBuffer1->mark();
+    testBuffer1->position( testBuffer1->limit() );
+
+    // readonly's contents should be the same as testBuffer1
+    FloatBuffer* 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 FloatArrayBufferTest::testCompact() {
+
+    loadTestData1( testBuffer1 );
+
+    // case: buffer is full
+    testBuffer1->clear();
+    testBuffer1->mark();
+
+    FloatBuffer& 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 FloatArrayBufferTest::testCompareTo() {
+
+    FloatBuffer* other = FloatBuffer::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<float> array1( 1, Float::NaN );
+    std::vector<float> array2( 1, Float::NaN );
+    std::vector<float> array3( 1, 42.0 );
+
+    FloatBuffer* dbuffer1 = FloatBuffer::wrap( array1 );
+    FloatBuffer* dbuffer2 = FloatBuffer::wrap( array2 );
+    FloatBuffer* dbuffer3 = FloatBuffer::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 FloatArrayBufferTest::testDuplicate() {
+    testBuffer1->clear();
+    testBuffer1->mark();
+    testBuffer1->position(testBuffer1->limit());
+
+    // duplicate's contents should be the same as testBuffer1
+    FloatBuffer* 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 FloatArrayBufferTest::testEquals() {
+
+    // equal to self
+    CPPUNIT_ASSERT( testBuffer1->equals( *testBuffer1 ) );
+    FloatBuffer* readOnly = testBuffer1->asReadOnlyBuffer();
+    CPPUNIT_ASSERT( testBuffer1->equals( *readOnly ) );
+    FloatBuffer* 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;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FloatArrayBufferTest::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 FloatArrayBufferTest::testGetFloatArray() {
+
+    std::vector<float> array(1);
+    testBuffer1->clear();
+
+    for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+        CPPUNIT_ASSERT( testBuffer1->position() == i );
+        FloatBuffer& 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 FloatArrayBufferTest::testGetFloatArray2() {
+
+    testBuffer1->clear();
+    float* array = new float[testBuffer1->capacity()];
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferUnderflowException",
+        testBuffer1->get( array, 0, testBuffer1->capacity() + 1 ),
+        BufferUnderflowException );
+
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    testBuffer1->get( array, 10, 0 );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferUnderflowException",
+        testBuffer1->get( array, 1, Integer::MAX_VALUE ),
+        BufferUnderflowException );
+
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    testBuffer1->clear();
+    FloatBuffer& 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 FloatArrayBufferTest::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 IndexOutOfBoundsException",
+        testBuffer1->get( testBuffer1->limit() ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FloatArrayBufferTest::testHasArray() {
+    CPPUNIT_ASSERT( testBuffer1->hasArray() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FloatArrayBufferTest::testPutFloat() {
+
+    testBuffer1->clear();
+
+    for( std::size_t i = 0; i < testBuffer1->capacity(); i++) {
+        CPPUNIT_ASSERT( testBuffer1->position() == i );
+        FloatBuffer& ret = testBuffer1->put( (float)i );
+        CPPUNIT_ASSERT( testBuffer1->get(i) == (float)i );
+        CPPUNIT_ASSERT( &ret == testBuffer1 );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferOverflowException",
+        testBuffer1->put( 0 ),
+        BufferOverflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FloatArrayBufferTest::testPutFloatArray() {
+
+    float* array = new float[1];
+
+    testBuffer1->clear();
+    for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+        CPPUNIT_ASSERT( testBuffer1->position() == i );
+        array[0] = (float) i;
+        FloatBuffer& ret = testBuffer1->put( array, 0, 1 );
+        CPPUNIT_ASSERT( testBuffer1->get(i) == (float)i );
+        CPPUNIT_ASSERT( &ret == testBuffer1 );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferOverflowException",
+        testBuffer1->put( array, 0, 1 ),
+        BufferOverflowException );
+
+    delete array;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FloatArrayBufferTest::testPutFloatArray2() {
+
+    testBuffer1->clear();
+    float* array1 = new float[ testBuffer1->capacity() ];
+    float* array2 = new float[ testBuffer1->capacity() + 1 ];
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw BufferOverflowException",
+        testBuffer1->put( array2, 0, testBuffer1->capacity() + 1 ),
+        BufferOverflowException );
+
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    testBuffer1->put( array1, testBuffer1->capacity() + 1, 0 );
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+
+    loadTestData2( array1, 0, testBuffer1->capacity() );
+    FloatBuffer& ret = testBuffer1->put( array1, 0, testBuffer1->capacity() );
+    CPPUNIT_ASSERT( testBuffer1->position() == testBuffer1->capacity() );
+    assertContentEquals( testBuffer1, array1, 0, testBuffer1->capacity() );
+    CPPUNIT_ASSERT( &ret == testBuffer1 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FloatArrayBufferTest::testPutFloatBuffer() {
+
+    FloatBuffer* other = FloatBuffer::allocate( testBuffer1->capacity() );
+    FloatBuffer* other1 = FloatBuffer::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();
+    FloatBuffer& 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 FloatArrayBufferTest::testGetWithIndex() {
+
+    testBuffer1->clear();
+
+    for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+        CPPUNIT_ASSERT( testBuffer1->position() == 0 );
+        FloatBuffer& ret = testBuffer1->put( i, (float)i );
+        CPPUNIT_ASSERT( testBuffer1->get(i) == (float)i );
+        CPPUNIT_ASSERT( &ret == testBuffer1 );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw IndexOutOfBoundsException",
+        testBuffer1->put( testBuffer1->limit(), 0 ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FloatArrayBufferTest::testPutIndexed() {
+
+    FloatBuffer* 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 );
+        FloatBuffer& 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 FloatArrayBufferTest::testSlice() {
+
+    CPPUNIT_ASSERT( testBuffer1->capacity() > 5 );
+    testBuffer1->position(1);
+    testBuffer1->limit(testBuffer1->capacity() - 1);
+
+    FloatBuffer* 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 FloatArrayBufferTest::testToString() {
+
+    std::string str = testBuffer1->toString();
+    CPPUNIT_ASSERT( str.find("Float") != 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/FloatArrayBufferTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/FloatArrayBufferTest.h?rev=603262&view=auto
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/FloatArrayBufferTest.h (added)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/FloatArrayBufferTest.h Tue Dec 11 06:45:34 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_FLOATARRAYBUFFERTEST_H_
+#define _DECAF_INTERNAL_NIO_FLOATARRAYBUFFERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/nio/FloatBuffer.h>
+
+namespace decaf{
+namespace internal{
+namespace nio{
+
+    class FloatArrayBufferTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( FloatArrayBufferTest );
+        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( testGetFloatArray );
+        CPPUNIT_TEST( testGetFloatArray2 );
+        CPPUNIT_TEST( testGetWithIndex );
+        CPPUNIT_TEST( testPutFloat );
+        CPPUNIT_TEST( testPutFloatArray );
+        CPPUNIT_TEST( testPutFloatArray2 );
+        CPPUNIT_TEST( testPutFloatBuffer );
+        CPPUNIT_TEST( testPutIndexed );
+        CPPUNIT_TEST( testSlice );
+        CPPUNIT_TEST( testToString );
+        CPPUNIT_TEST_SUITE_END();
+
+        decaf::nio::FloatBuffer* testBuffer1;
+        float* 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:
+
+        FloatArrayBufferTest() {}
+        virtual ~FloatArrayBufferTest() {}
+
+        void setUp() {
+            testBuffer1 = decaf::nio::FloatBuffer::allocate( testData1Size );
+
+            testData1 = new float[testData1Size];
+            for( std::size_t i = 0; i < testData1Size; ++i ){
+                testData1[i] = (float)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 testGetFloatArray();
+        void testGetFloatArray2();
+        void testGetWithIndex();
+        void testPutFloat();
+        void testPutFloatArray();
+        void testPutFloatArray2();
+        void testPutFloatBuffer();
+        void testPutIndexed();
+        void testSlice();
+        void testToString();
+
+    protected:
+
+        void loadTestData1( float* array, std::size_t offset, std::size_t length ) {
+            for( std::size_t i = 0; i < length; i++ ) {
+                array[offset + i] = (float)i;
+            }
+        }
+
+        void loadTestData2( float* array, std::size_t offset, std::size_t length ) {
+            for( std::size_t i = 0; i < length; i++ ) {
+                array[offset + i] = (float)length - i;
+            }
+        }
+
+        void loadTestData1( decaf::nio::FloatBuffer* buf ) {
+            buf->clear();
+            for( std::size_t i = 0; i < buf->capacity(); i++ ) {
+                buf->put( i, (float)i );
+            }
+        }
+
+        void loadTestData2( decaf::nio::FloatBuffer* buf ) {
+            buf->clear();
+            for( std::size_t i = 0; i < buf->capacity(); i++ ) {
+                buf->put(i, (float) buf->capacity() - i);
+            }
+        }
+
+        void assertContentEquals( decaf::nio::FloatBuffer* buf, float* 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::FloatBuffer* buf,
+                                  decaf::nio::FloatBuffer* 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::FloatBuffer* buf, std::size_t startIndex,
+            float startValue, std::size_t length ) {
+
+            float 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_FLOATARRAYBUFFERTEST_H_*/

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=603262&r1=603261&r2=603262&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp Tue Dec 11 06:45:34 2007
@@ -30,6 +30,8 @@
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::internal::nio::CharArrayBufferTest );
 #include <decaf/internal/nio/DoubleArrayBufferTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::internal::nio::DoubleArrayBufferTest );
+#include <decaf/internal/nio/FloatArrayBufferTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::internal::nio::FloatArrayBufferTest );
 
 #include <decaf/nio/BufferTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::nio::BufferTest );