activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r599562 - in /activemq/activemq-cpp/decaf/trunk/src/test: Makefile.am decaf/nio/BufferTest.cpp decaf/nio/BufferTest.h testRegistry.cpp
Date Thu, 29 Nov 2007 19:47:03 GMT
Author: tabish
Date: Thu Nov 29 11:47:01 2007
New Revision: 599562

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

Working on the NIO package

Added:
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/BufferTest.cpp
    activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/BufferTest.h
Modified:
    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/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/Makefile.am?rev=599562&r1=599561&r2=599562&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/Makefile.am Thu Nov 29 11:47:01 2007
@@ -53,6 +53,7 @@
   decaf/util/concurrent/CountDownLatchTest.cpp \
   decaf/util/concurrent/MutexTest.cpp \
   decaf/util/concurrent/ThreadPoolTest.cpp \
+  decaf/nio/BufferTest.cpp \
   decaf/nio/ByteBufferTest.cpp \
   testRegistry.cpp \
   main.cpp
@@ -95,6 +96,7 @@
   decaf/util/concurrent/CountDownLatchTest.h \
   decaf/util/concurrent/MutexTest.h \
   decaf/util/concurrent/ThreadPoolTest.h \
+  decaf/nio/BufferTest.h \
   decaf/nio/ByteBufferTest.h
 
 ## Compile this as part of make check

Added: activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/BufferTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/BufferTest.cpp?rev=599562&view=auto
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/BufferTest.cpp (added)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/BufferTest.cpp Thu Nov 29 11:47:01
2007
@@ -0,0 +1,238 @@
+/*
+ * 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 "BufferTest.h"
+
+using namespace decaf;
+using namespace decaf::nio;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::test() {
+
+    // Check that we have setup the array and our initial assumptions on state
+    // are correct.  This is the first test run.
+    CPPUNIT_ASSERT( buffer != NULL );
+    CPPUNIT_ASSERT( buffer->capacity() == DEFAULT_BUFFER_SIZE );
+    CPPUNIT_ASSERT( buffer->hasRemaining() == true );
+    CPPUNIT_ASSERT( buffer->limit() == buffer->capacity() );
+    CPPUNIT_ASSERT( buffer->position() == 0 );
+    CPPUNIT_ASSERT( buffer->isReadOnly() == false );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testCapacity() {
+
+    CPPUNIT_ASSERT( 0 == buffer->position() &&
+                    buffer->position() <= buffer->limit() &&
+                    buffer->limit() <= buffer->capacity() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testClear() {
+
+    Buffer& ret = buffer->clear();
+
+    CPPUNIT_ASSERT( &ret == buffer );
+    CPPUNIT_ASSERT( buffer->position() == 0 );
+    CPPUNIT_ASSERT( buffer->limit() == buffer->capacity() );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw InvalidMarkException",
+        buffer->reset(),
+        InvalidMarkException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testFlip() {
+
+    std::size_t oldPosition = buffer->position();
+
+    Buffer& ret = buffer->flip();
+    CPPUNIT_ASSERT( &ret == buffer );
+    CPPUNIT_ASSERT( buffer->position() == 0 );
+    CPPUNIT_ASSERT( buffer->limit() == oldPosition );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw InvalidMarkException",
+        buffer->reset(),
+        InvalidMarkException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testHasRemaining() {
+
+    CPPUNIT_ASSERT( buffer->hasRemaining() == ( buffer->position() < buffer->limit()
) );
+    buffer->position( buffer->limit() );
+    CPPUNIT_ASSERT( !buffer->hasRemaining() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testIsReadOnly() {
+
+    CPPUNIT_ASSERT( !buffer->isReadOnly() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testLimit() {
+
+    CPPUNIT_ASSERT( 0 == buffer->position() &&
+                    buffer->position() <= buffer->limit() &&
+                    buffer->limit() <= buffer->capacity() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testLimitInt() {
+
+    std::size_t oldPosition = buffer->position();
+    Buffer& ret = buffer->limit(buffer->limit());
+    CPPUNIT_ASSERT( &ret == buffer );
+
+    buffer->mark();
+    buffer->limit( buffer->capacity() );
+    CPPUNIT_ASSERT( buffer->limit() == buffer->capacity() );
+    // position should not change
+    CPPUNIT_ASSERT( buffer->position() == oldPosition );
+
+    // mark should be valid
+    buffer->reset();
+
+    buffer->limit(buffer->capacity());
+    buffer->position(buffer->capacity());
+    buffer->mark();
+    buffer->limit(buffer->capacity() - 1);
+    // position should be the new limit
+    CPPUNIT_ASSERT( buffer->position() == buffer->limit() );
+    // mark should be invalid
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw InvalidMarkException",
+        buffer->reset(),
+        InvalidMarkException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw IllegalArgumentException",
+        buffer->limit( buffer->capacity() + 1 ),
+        IllegalArgumentException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testMark() {
+
+    std::size_t oldPosition = buffer->position();
+    Buffer& ret = buffer->mark();
+    CPPUNIT_ASSERT( &ret == buffer );
+
+    buffer->mark();
+    buffer->position(buffer->limit());
+    buffer->reset();
+    CPPUNIT_ASSERT( buffer->position() == oldPosition);
+
+    buffer->mark();
+    buffer->position(buffer->limit());
+    buffer->reset();
+    CPPUNIT_ASSERT( buffer->position() == oldPosition);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testPosition() {
+
+    CPPUNIT_ASSERT( 0 == buffer->position() &&
+                    buffer->position() <= buffer->limit() &&
+                    buffer->limit() <= buffer->capacity() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testPositionInt() {
+
+    std::size_t oldPosition = buffer->position();
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw IllegalArgumentException",
+        buffer->position( buffer->limit() + 1 ),
+        IllegalArgumentException );
+
+    buffer->mark();
+    buffer->position(buffer->position());
+    buffer->reset();
+    CPPUNIT_ASSERT( buffer->position() == oldPosition );
+
+    buffer->position(0);
+    CPPUNIT_ASSERT( buffer->position() == 0 );
+    buffer->position(buffer->limit());
+    CPPUNIT_ASSERT( buffer->position() == buffer->limit() );
+
+    if (buffer->capacity() > 0) {
+        buffer->limit( buffer->capacity() );
+        buffer->position( buffer->limit() );
+        buffer->mark();
+        buffer->position( buffer->limit() - 1);
+        CPPUNIT_ASSERT( buffer->position() == buffer->limit() - 1 );
+
+        // mark should be invalid
+        CPPUNIT_ASSERT_THROW_MESSAGE(
+            "Should throw InvalidMarkException",
+            buffer->reset(),
+            InvalidMarkException );
+    }
+
+    Buffer& ret = buffer->position(0);
+    CPPUNIT_ASSERT( &ret == buffer );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testRemaining() {
+    CPPUNIT_ASSERT( buffer->remaining() == ( buffer->limit() - buffer->position()
) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testReset() {
+
+    std::size_t oldPosition = buffer->position();
+
+    buffer->mark();
+    buffer->position(buffer->limit());
+    buffer->reset();
+    CPPUNIT_ASSERT( buffer->position() == oldPosition );
+
+    buffer->mark();
+    buffer->position(buffer->limit());
+    buffer->reset();
+    CPPUNIT_ASSERT( buffer->position() == oldPosition );
+
+    Buffer& ret = buffer->reset();
+    CPPUNIT_ASSERT( &ret == buffer );
+
+    buffer->clear();
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw InvalidMarkException",
+        buffer->reset(),
+        InvalidMarkException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void BufferTest::testRewind() {
+
+    Buffer& ret = buffer->rewind();
+    CPPUNIT_ASSERT( buffer->position() == 0 );
+    CPPUNIT_ASSERT( &ret == buffer );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw InvalidMarkException",
+        buffer->reset(),
+        InvalidMarkException );
+}

Added: activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/BufferTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/BufferTest.h?rev=599562&view=auto
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/BufferTest.h (added)
+++ activemq/activemq-cpp/decaf/trunk/src/test/decaf/nio/BufferTest.h Thu Nov 29 11:47:01
2007
@@ -0,0 +1,98 @@
+/*
+ * 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_NIO_BUFFERTEST_H_
+#define _DECAF_NIO_BUFFERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/nio/Buffer.h>
+
+namespace decaf{
+namespace nio{
+
+    class BufferTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( BufferTest );
+        CPPUNIT_TEST( test );
+        CPPUNIT_TEST( testCapacity );
+        CPPUNIT_TEST( testClear );
+        CPPUNIT_TEST( testFlip );
+        CPPUNIT_TEST( testHasRemaining );
+        CPPUNIT_TEST( testIsReadOnly );
+        CPPUNIT_TEST( testLimit );
+        CPPUNIT_TEST( testLimitInt );
+        CPPUNIT_TEST( testMark );
+        CPPUNIT_TEST( testPosition );
+        CPPUNIT_TEST( testPositionInt );
+        CPPUNIT_TEST( testRemaining );
+        CPPUNIT_TEST( testReset );
+        CPPUNIT_TEST( testRewind );
+        CPPUNIT_TEST_SUITE_END();
+
+    private:
+
+        Buffer* buffer;
+
+        static const std::size_t DEFAULT_BUFFER_SIZE = 512;
+
+        class MyBuffer : public Buffer {
+        public:
+
+            MyBuffer( std::size_t capacity ) : Buffer( capacity ) {
+            }
+
+            virtual ~MyBuffer() {}
+
+            bool isReadOnly() const { return false; }
+        };
+
+    public:
+
+        BufferTest() {}
+        virtual ~BufferTest() {}
+
+        void setUp() {
+            buffer = new MyBuffer( DEFAULT_BUFFER_SIZE );
+        }
+
+        void tearDown() {
+            delete buffer;
+            buffer = NULL;
+        }
+
+        void test();
+        void testCapacity();
+        void testClear();
+        void testFlip();
+        void testHasRemaining();
+        void testIsReadOnly();
+        void testLimit();
+        void testLimitInt();
+        void testMark();
+        void testPosition();
+        void testPositionInt();
+        void testRemaining();
+        void testReset();
+        void testRewind();
+
+    };
+
+}}
+
+#endif /*_DECAF_NIO_BUFFERTEST_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=599562&r1=599561&r2=599562&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/test/testRegistry.cpp Thu Nov 29 11:47:01 2007
@@ -23,6 +23,8 @@
 #include <decaf/internal/nio/ByteArrayPerspectiveTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::internal::nio::ByteArrayPerspectiveTest );
 
+#include <decaf//nio/BufferTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::nio::BufferTest );
 #include <decaf//nio/ByteBufferTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::nio::ByteBufferTest );
 



Mime
View raw message