activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r545819 - in /activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io: BufferedOutputStreamTest.cpp BufferedOutputStreamTest.h
Date Sun, 10 Jun 2007 00:13:59 GMT
Author: tabish
Date: Sat Jun  9 17:13:58 2007
New Revision: 545819

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

Building up the Decaf Library

Added:
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/BufferedOutputStreamTest.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/BufferedOutputStreamTest.h

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/BufferedOutputStreamTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/BufferedOutputStreamTest.cpp?view=auto&rev=545819
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/BufferedOutputStreamTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/BufferedOutputStreamTest.cpp Sat
Jun  9 17:13:58 2007
@@ -0,0 +1,74 @@
+/*
+ * 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 "BufferedOutputStreamTest.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::BufferedOutputStreamTest );
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::io;
+using namespace decaf::util;
+
+void BufferedOutputStreamTest::testSmallerBuffer(){
+
+    MyOutputStream myStream;
+    BufferedOutputStream bufStream( &myStream, (std::size_t)1 );
+
+    const char* buffer = myStream.getBuffer();
+
+    bufStream.write( (unsigned char)'T' );
+    // Should not be written yet.
+    CPPUNIT_ASSERT( strcmp( buffer, "" ) == 0 );
+
+    bufStream.write( (unsigned char)'E' );
+    // This time the T should have been written.
+    CPPUNIT_ASSERT( strcmp( buffer, "T" ) == 0 );
+
+    bufStream.write( (unsigned char*)"ST", 2 );
+    // This time the ES should have been written.
+    CPPUNIT_ASSERT( strcmp( buffer, "TES" ) == 0 );
+
+    bufStream.flush();
+    CPPUNIT_ASSERT( strcmp( buffer, "TEST" ) == 0 );
+}
+
+void BufferedOutputStreamTest::testBiggerBuffer(){
+
+    MyOutputStream myStream;
+    BufferedOutputStream bufStream( &myStream, (std::size_t)10 );
+
+    const char* buffer = myStream.getBuffer();
+
+    bufStream.write( (unsigned char*)"TEST", 4 );
+
+    // Should not be written yet.
+    CPPUNIT_ASSERT( strcmp( buffer, "" ) == 0 );
+
+    bufStream.flush();
+    CPPUNIT_ASSERT( strcmp( buffer, "TEST" ) == 0 );
+
+    bufStream.write( (unsigned char*)"TEST", 4 );
+    bufStream.write( (unsigned char*)"12345678910", 11);
+
+    CPPUNIT_ASSERT( strcmp( buffer, "TESTTEST123456" ) == 0 );
+
+    bufStream.flush();
+    CPPUNIT_ASSERT( strcmp( buffer, "TESTTEST12345678910" ) == 0 );
+
+}

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/BufferedOutputStreamTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/BufferedOutputStreamTest.h?view=auto&rev=545819
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/BufferedOutputStreamTest.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/io/BufferedOutputStreamTest.h Sat
Jun  9 17:13:58 2007
@@ -0,0 +1,107 @@
+/*
+ * 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_IO_BUFFEREDOUTPUTSTREAMTEST_H_
+#define _DECAF_IO_BUFFEREDOUTPUTSTREAMTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/io/BufferedOutputStream.h>
+#include <decaf/util/Config.h>
+#include <string.h>
+
+namespace decaf{
+namespace io{
+
+    class BufferedOutputStreamTest : public CppUnit::TestFixture {
+
+      CPPUNIT_TEST_SUITE( BufferedOutputStreamTest );
+      CPPUNIT_TEST( testSmallerBuffer );
+      CPPUNIT_TEST( testBiggerBuffer );
+      CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        class MyOutputStream : public OutputStream{
+        private:
+            char buffer[100];
+            std::size_t pos;
+        public:
+
+            MyOutputStream(){
+                pos = 0;
+                memset( buffer, 0, 100 );
+            }
+            virtual ~MyOutputStream(){}
+
+            const char* getBuffer() const{ return buffer; }
+
+            virtual void write( unsigned char c ) throw (IOException){
+                if( pos >= 100 ){
+                    throw IOException();
+                }
+
+                buffer[pos++] = c;
+            }
+
+            virtual void write( const unsigned char* buffer, std::size_t len ) throw (IOException){
+
+                if( (pos + len) > 100 ){
+                    throw IOException();
+                }
+
+                memcpy( this->buffer + pos, buffer, len );
+
+                pos += len;
+            }
+
+            virtual void flush() throw (IOException){
+            }
+
+            virtual void close() throw(lang::Exception){
+                // do nothing.
+            }
+
+            virtual void lock() throw(lang::Exception){
+            }
+            virtual void unlock() throw(lang::Exception){
+            }
+            virtual void wait() throw(lang::Exception){
+            }
+            virtual void wait(unsigned long millisecs DECAF_UNUSED) throw(lang::Exception){
+            }
+            virtual void notify() throw(lang::Exception){
+            }
+            virtual void notifyAll() throw(lang::Exception){
+            }
+        };
+
+    public:
+
+        virtual ~BufferedOutputStreamTest(){}
+        virtual void setUp(){}
+        virtual void tearDown(){}
+
+        void testSmallerBuffer();
+        void testBiggerBuffer();
+
+    };
+
+}}
+
+#endif /*_DECAF_IO_BUFFEREDOUTPUTSTREAMTEST_H_*/



Mime
View raw message