activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r601583 - in /activemq/activemq-cpp/decaf/trunk/src: main/decaf/internal/nio/ main/decaf/nio/ test/decaf/internal/nio/
Date Thu, 06 Dec 2007 00:10:38 GMT
Author: tabish
Date: Wed Dec  5 16:10:37 2007
New Revision: 601583

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

Working on implementing the NIO package

Modified:
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/CharArrayBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.h
    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/internal/nio/CharArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/CharArrayBuffer.cpp?rev=601583&r1=601582&r2=601583&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/CharArrayBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/CharArrayBuffer.cpp Wed
Dec  5 16:10:37 2007
@@ -287,12 +287,21 @@
 
     try{
 
-        CharArrayBuffer* buffer = new CharArrayBuffer(
-            *(this->_array),
-            this->offset + this->position() + start,
-            this->capacity(),
-            this->isReadOnly() );
+        if( start > end ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "CharArrayBuffer::subSequence - start > end" );
+        }
 
+        if( start > this->limit() || end > this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "CharArrayBuffer::subSequence - Sequence exceed limit" );
+        }
+
+        CharArrayBuffer* buffer = new CharArrayBuffer( *this );
+
+        buffer->position( this->position() + start );
         buffer->limit( this->position() + end );
 
         return buffer;

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=601583&r1=601582&r2=601583&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 Wed Dec  5 16:10:37
2007
@@ -338,12 +338,14 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-CharBuffer& CharBuffer::put( const std::string src )
+CharBuffer& CharBuffer::put( const std::string& src )
     throw( BufferOverflowException, ReadOnlyBufferException ) {
 
     try{
+        std::cout << "\n put - string is size = " << src.length();
 
         if( !src.empty() ) {
+            std::cout << "\n Putting string = " << src << std::endl;
             this->put( src.c_str(), 0, src.size() );
         }
 

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.h?rev=601583&r1=601582&r2=601583&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.h Wed Dec  5 16:10:37
2007
@@ -399,7 +399,7 @@
          * @throws BufferOverflowException - If this buffer's current position is not
          * @throws ReadOnlyBufferException - If this buffer is read-only
          */
-        CharBuffer& put( const std::string src )
+        CharBuffer& put( const std::string& src )
             throw( BufferOverflowException, ReadOnlyBufferException );
 
         /**

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=601583&r1=601582&r2=601583&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
Wed Dec  5 16:10:37 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 );
@@ -618,4 +612,71 @@
         "Should throw a NullPointerException",
         testBuffer1->wrap( (char*)NULL, 0, 3 ),
         NullPointerException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testCharAt() {
+
+    for( std::size_t i = 0; i < testBuffer1->remaining(); i++ ) {
+        CPPUNIT_ASSERT( testBuffer1->get( testBuffer1->position() + i ) ==
+                        testBuffer1->charAt(i) );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1->charAt( testBuffer1->remaining() ),
+        IndexOutOfBoundsException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testLength() {
+    CPPUNIT_ASSERT( testBuffer1->length() == testBuffer1->remaining() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testSubSequence() {
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1->subSequence(testBuffer1->length() + 1, testBuffer1->length()
+ 1),
+        IndexOutOfBoundsException );
+
+    CharSequence* sub1 = testBuffer1->subSequence(
+        testBuffer1->length(), testBuffer1->length() );
+    CPPUNIT_ASSERT( sub1->length() == 0 );
+    delete sub1;
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1->subSequence( 1, 0 ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a IndexOutOfBoundsException",
+        testBuffer1->subSequence( 1, testBuffer1->length() + 1 ),
+        IndexOutOfBoundsException );
+
+    CharSequence* sub2 = testBuffer1->subSequence( 0, testBuffer1->length() );
+    CPPUNIT_ASSERT( sub2->toString() == testBuffer1->toString() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CharArrayBufferTest::testPutString() {
+
+    testBuffer1->clear();
+    for( std::size_t i = 0; i < testBuffer1->capacity(); i++ ) {
+        cout << "\n i = " << i << ", pos = " << testBuffer1->position();
+        CPPUNIT_ASSERT( testBuffer1->position() == i );
+        string testString = Integer::valueOf( i ).toString();
+        std::cout << "\n Size of string now = " << testString.size();
+        CharBuffer& ret = testBuffer1->put( testString );
+        std::cout << "\n " << testBuffer1->get(i) <<  " == " <<
(char)i;
+        CPPUNIT_ASSERT( testBuffer1->get(i) == (char)i );
+        CPPUNIT_ASSERT( &ret == testBuffer1 );
+    }
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw a BufferOverflowException",
+        testBuffer1->put( "ASDFGHJKJKL" );,
+        BufferOverflowException );
 }

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=601583&r1=601582&r2=601583&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 Wed
Dec  5 16:10:37 2007
@@ -51,6 +51,10 @@
         CPPUNIT_TEST( testSlice );
         CPPUNIT_TEST( testToString );
         CPPUNIT_TEST( testWrapNullArray );
+        CPPUNIT_TEST( testCharAt );
+        CPPUNIT_TEST( testLength );
+        CPPUNIT_TEST( testSubSequence );
+        CPPUNIT_TEST( testPutString );
         CPPUNIT_TEST_SUITE_END();
 
         decaf::nio::CharBuffer* testBuffer1;
@@ -100,6 +104,10 @@
         void testSlice();
         void testToString();
         void testWrapNullArray();
+        void testCharAt();
+        void testLength();
+        void testSubSequence();
+        void testPutString();
 
     };
 



Mime
View raw message