activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r602514 - in /activemq/activemq-cpp/decaf/trunk/src: main/decaf/nio/CharBuffer.cpp test/decaf/internal/nio/CharArrayBufferTest.cpp test/decaf/internal/nio/CharArrayBufferTest.h
Date Sat, 08 Dec 2007 17:19:07 GMT
Author: tabish
Date: Sat Dec  8 09:19:06 2007
New Revision: 602514

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

Working on implementing the NIO package

Modified:
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.h

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.cpp?rev=602514&r1=602513&r2=602514&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.cpp Sat Dec  8 09:19:06
2007
@@ -142,8 +142,9 @@
             return *this;
         }
 
-        return this->put( "null" );
+        return this->put( "null", start, end );
     }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_RETHROW( BufferOverflowException )
     DECAF_CATCH_RETHROW( ReadOnlyBufferException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
@@ -327,10 +328,18 @@
                 start, end );
         }
 
+        if( start > src.size() || end > src.size() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "CharBuffer::put - invalid start and end pos; start = %d, end = %d",
+                start, end );
+        }
+
         this->put( src.substr( start, end-start ) );
 
         return *this;
     }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_RETHROW( BufferOverflowException )
     DECAF_CATCH_RETHROW( ReadOnlyBufferException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.cpp?rev=602514&r1=602513&r2=602514&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.cpp
(original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.cpp
Sat Dec  8 09:19:06 2007
@@ -742,22 +742,22 @@
     cb->clear();
     CPPUNIT_ASSERT( cb2->equals( *cb ) );
 
-    cb->put("abc");
+    cb->put( "abc" );
     cb2 = cb->duplicate();
     cb->append( cb );
     CPPUNIT_ASSERT( 10 == cb->position() );
     cb->clear();
     cb2->clear();
-    CPPUNIT_ASSERT( cb2 == cb );
+    CPPUNIT_ASSERT( cb2->equals( *cb ) );
 
-    cb->put("edfg");
+    cb->put( "edfg" );
     cb->clear();
     cb2 = cb->duplicate();
     cb->append( cb );
-    CPPUNIT_ASSERT(10 == cb->position());
+    CPPUNIT_ASSERT( 10 == cb->position() );
     cb->clear();
     cb2->clear();
-    CPPUNIT_ASSERT( cb == cb2 );
+    CPPUNIT_ASSERT( cb->equals( *cb2 ) );
 
     delete cb;
     delete cb2;
@@ -793,8 +793,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 void CharArrayBufferTest::testReadOnlyMap() {
 
-    CharBuffer cb = CharBuffer::wrap("ABCDE").asReadOnlyBuffer();
-    CharSequence cs = "String";
+    CharBuffer* cb = testBuffer1->asReadOnlyBuffer();
+    MyCharSequence cs( "String" );
 
     CPPUNIT_ASSERT_THROW_MESSAGE(
         "Should throw a ReadOnlyBufferException",
@@ -803,15 +803,15 @@
 
     CPPUNIT_ASSERT_THROW_MESSAGE(
         "Should throw a ReadOnlyBufferException",
-        cb->append( cs ),
+        cb->append( &cs ),
         ReadOnlyBufferException );
 
     CPPUNIT_ASSERT_THROW_MESSAGE(
         "Should throw a ReadOnlyBufferException",
-        cb->append( cs, 1, 2 ),
+        cb->append( &cs, 1, 2 ),
         ReadOnlyBufferException );
 
-    cb->append( cs, 1, 1 );
+    delete cb;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -820,6 +820,7 @@
     cb->put('A');
     CPPUNIT_ASSERT( cb == &( cb->append('B') ) );
     CPPUNIT_ASSERT( 'B' == cb->get( 1 ) );
+    delete cb;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -827,75 +828,98 @@
 
     CharBuffer* cb = CharBuffer::allocate(10);
     cb->put('A');
-    CPPUNIT_ASSERT( cb == &( cb->append( "String" ) ) );
-    CPPUNIT_ASSERT( "AString" == cb->flip().toString());
+    MyCharSequence cs( "String" );
+
+    CPPUNIT_ASSERT( cb == &( cb->append( &cs ) ) );
+    cb->flip();
+    CPPUNIT_ASSERT( MyCharSequence("AString").toString() == cb->toString() );
     cb->append( (const lang::CharSequence*)NULL );
-    CPPUNIT_ASSERT( cb->flip().toString() == "null" );
+    cb->flip();
+    CPPUNIT_ASSERT( cb->toString() == "null" );
+
+    delete cb;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void CharArrayBufferTest::testAppendCharSequenceIINormal() {
 
-    CharBuffer* cb = CharBuffer::allocate(10);
-    cb->put('A');
-    CPPUNIT_ASSERT( cb, cb->append("String", 1, 3) );
-    CPPUNIT_ASSERT( "Atr" == cb->flip().toString() );
+    CharBuffer* cb = CharBuffer::allocate( 10 );
+    cb->put( 'A' );
+    MyCharSequence cs( "String" );
+
+    CPPUNIT_ASSERT( cb == &( cb->append( &cs, 1, 3 ) ) );
+    cb->flip();
+    CPPUNIT_ASSERT( "Atr" == cb->toString() );
 
     cb->append( (const lang::CharSequence*)NULL, 0, 1 );
-    CPPUNIT_ASSERT( "n" == cb->flip().toString() );
+    cb->flip();
+    CPPUNIT_ASSERT( "n" == cb->toString() );
+    delete cb;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void CharArrayBufferTest::testAppendCharSequenceII_IllegalArgument() {
 
-    CharBuffer* cb = CharBuffer::allocate(10);
-    cb->append( "String", 0, 0 );
-    cb->append( "String", 2, 2 );
+    CharBuffer* cb = CharBuffer::allocate( 10 );
+    MyCharSequence cs( "String" );
 
-    try {
-        cb->append("String", 3, 2);
-        fail("should throw IndexOutOfBoundsException.");
-    } catch (IndexOutOfBoundsException ex) {
-        // expected;
-    }
-    try {
-        cb->append("String", 3, 0);
-        fail("should throw IndexOutOfBoundsException.");
-    } catch (IndexOutOfBoundsException ex) {
-        // expected;
-    }
-    try {
-        cb->append("String", 3, 110);
-        fail("should throw IndexOutOfBoundsException.");
-    } catch (IndexOutOfBoundsException ex) {
-        // expected;
-    }
+    cb->append( &cs, 0, 0 );
+    cb->append( &cs, 2, 2 );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        cb->append( &cs, 3, 2 ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        cb->append( &cs, 3, 0 ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        cb->append( &cs, 3, 110 ),
+        IndexOutOfBoundsException );
+
+    delete cb;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void CharArrayBufferTest::testReadCharBuffer() {
 
-    CharBuffer* source = CharBuffer::wrap("String");
+    std::vector<char> buffer;
+    buffer.push_back('S');
+    buffer.push_back('t');
+    buffer.push_back('r');
+    buffer.push_back('i');
+    buffer.push_back('n');
+    buffer.push_back('g');
+
+    CharBuffer* source = CharBuffer::wrap( buffer );
     CharBuffer* target = CharBuffer::allocate(10);
 
-    CPPUNIT_ASSERT( 6 == source.read( target ) );
-    CPPUNIT_ASSERT( "String" == target.flip().toString() );
+    CPPUNIT_ASSERT( 6 == source->read( target ) );
+    target->flip();
+    CPPUNIT_ASSERT( "String" == target->toString() );
 
     // return -1 when nothing to read
-    CPPUNIT_ASSERT( string::npos == source.read(target) );
+    CPPUNIT_ASSERT( string::npos == source->read( target ) );
 
     // NullPointerException
     CPPUNIT_ASSERT_THROW_MESSAGE(
         "Should throw a NullPointerException",
         source->read( NULL ),
         NullPointerException );
+
+    delete source;
+    delete target;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void CharArrayBufferTest::testReadReadOnly() {
 
-    CharBuffer* source = CharBuffer::wrap("String");
-    CharBuffer* target = CharBuffer::allocate(10).asReadOnlyBuffer();
+    CharBuffer* source = CharBuffer::wrap( testData1, 0, testData1Size );
+    CharBuffer* target = testBuffer1->asReadOnlyBuffer();
 
     // NullPointerException
     CPPUNIT_ASSERT_THROW_MESSAGE(
@@ -904,28 +928,39 @@
         ReadOnlyBufferException );
 
     // if target has no remaining, needn't to check the isReadOnly
-    target.flip();
+    target->flip();
     CPPUNIT_ASSERT( 0 == source->read( target ) );
+
+    delete source;
+    delete target;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void CharArrayBufferTest::testReadOverflow() {
 
-    CharBuffer* source = CharBuffer::wrap("String");
+    std::vector<char> buffer;
+    buffer.push_back('S');
+    CharBuffer* source = CharBuffer::wrap( buffer );
     CharBuffer* target = CharBuffer::allocate( 1 );
 
     CPPUNIT_ASSERT( 1 == source->read(target) );
-    CPPUNIT_ASSERT( "S" == target->flip().toString() );
+    target->flip();
+    CPPUNIT_ASSERT( "S" == target->toString() );
     CPPUNIT_ASSERT( 1 == source->position() );
+
+    delete source;
+    delete target;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void CharArrayBufferTest::testReadSelf() {
 
-    CharBuffer* source = CharBuffer::wrap("abuffer");
+    CharBuffer* source = CharBuffer::wrap( testData1, 0, testData1Size );
 
     CPPUNIT_ASSERT_THROW_MESSAGE(
         "Should throw a IllegalArgumentException",
         source->read( source ),
         IllegalArgumentException );
+
+    delete source;
 }

Modified: activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.h?rev=602514&r1=602513&r2=602514&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/internal/nio/CharArrayBufferTest.h Sat
Dec  8 09:19:06 2007
@@ -56,6 +56,17 @@
         CPPUNIT_TEST( testSubSequence );
         CPPUNIT_TEST( testPutString );
         CPPUNIT_TEST( testPutStringWithArgs );
+        CPPUNIT_TEST( testAppendSelf );
+        CPPUNIT_TEST( testAppendOverFlow );
+        CPPUNIT_TEST( testReadOnlyMap );
+        CPPUNIT_TEST( testAppendCNormal );
+        CPPUNIT_TEST( testAppendCharSequenceNormal );
+        CPPUNIT_TEST( testAppendCharSequenceIINormal );
+        CPPUNIT_TEST( testAppendCharSequenceII_IllegalArgument );
+        CPPUNIT_TEST( testReadCharBuffer );
+        CPPUNIT_TEST( testReadReadOnly );
+        CPPUNIT_TEST( testReadOverflow );
+        CPPUNIT_TEST( testReadSelf );
         CPPUNIT_TEST_SUITE_END();
 
         decaf::nio::CharBuffer* testBuffer1;
@@ -65,6 +76,58 @@
         static const std::size_t SMALL_TEST_LENGTH = 5;
         static const std::size_t BUFFER_LENGTH = 250;
 
+        class MyCharSequence : public lang::CharSequence {
+        private:
+
+            std::string value;
+
+        public:
+
+            MyCharSequence( std::string value ) {
+                this->value = value;
+            }
+
+            virtual ~MyCharSequence() {}
+
+            virtual std::size_t length() const {
+                return this->value.length();
+            }
+
+            virtual char charAt( std::size_t index ) const
+                throw( lang::exceptions::IndexOutOfBoundsException ) {
+
+                if( index > this->value.length() ) {
+                    throw decaf::lang::exceptions::IndexOutOfBoundsException(
+                        __FILE__, __LINE__,
+                        "MyCharSequence::charAt - index is to big: %d", index );
+                }
+
+                return this->value.at( index );
+            }
+
+            virtual CharSequence* subSequence( std::size_t start, std::size_t end ) const
+                throw( lang::exceptions::IndexOutOfBoundsException ) {
+
+                if( start > end ) {
+                    throw decaf::lang::exceptions::IndexOutOfBoundsException(
+                        __FILE__, __LINE__,
+                        "CharArrayBuffer::subSequence - start > end" );
+                }
+
+                if( start > this->length() || end > this->length() ) {
+                    throw decaf::lang::exceptions::IndexOutOfBoundsException(
+                        __FILE__, __LINE__,
+                        "CharArrayBuffer::subSequence - Sequence exceed limit" );
+                }
+
+                return new MyCharSequence( this->value.substr( start, end - start ) );
+            }
+
+            virtual std::string toString() const {
+                return this->value;
+            }
+        };
+
     public:
 
         CharArrayBufferTest() {}
@@ -110,7 +173,6 @@
         void testSubSequence();
         void testPutString();
         void testPutStringWithArgs();
-
         void testAppendSelf();
         void testAppendOverFlow();
         void testReadOnlyMap();



Mime
View raw message