Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 43654 invoked from network); 27 Feb 2010 17:31:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Feb 2010 17:31:20 -0000 Received: (qmail 6014 invoked by uid 500); 27 Feb 2010 17:31:20 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 5952 invoked by uid 500); 27 Feb 2010 17:31:19 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 5945 invoked by uid 99); 27 Feb 2010 17:31:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Feb 2010 17:31:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Feb 2010 17:31:15 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id CFE6323888CF; Sat, 27 Feb 2010 17:30:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r916996 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/decaf/util/zip/ test/ test/decaf/util/zip/ Date: Sat, 27 Feb 2010 17:30:53 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100227173053.CFE6323888CF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Sat Feb 27 17:30:53 2010 New Revision: 916996 URL: http://svn.apache.org/viewvc?rev=916996&view=rev Log: http://issues.apache.org/activemq/browse/AMQCPP-287 Mostly working DeflaterOutputStream and InflaterInputStream classes, some unit tests not yet passing. Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterOutputStreamTest.cpp (with props) activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterOutputStreamTest.h (with props) activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/InflaterInputStreamTest.cpp (with props) activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/InflaterInputStreamTest.h (with props) Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.h activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.h activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.cpp?rev=916996&r1=916995&r2=916996&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.cpp Sat Feb 27 17:30:53 2010 @@ -25,10 +25,179 @@ using namespace decaf::util::zip; //////////////////////////////////////////////////////////////////////////////// +const std::size_t DeflaterOutputStream::DEFAULT_BUFFER_SIZE = 512; + +//////////////////////////////////////////////////////////////////////////////// DeflaterOutputStream::DeflaterOutputStream( OutputStream* outputStream, bool own ) : FilterOutputStream( outputStream, own ) { + + this->deflater = new Deflater(); + this->ownDeflater = true; + this->buf.resize( DEFAULT_BUFFER_SIZE ); + this->isDone = false; +} + +//////////////////////////////////////////////////////////////////////////////// +DeflaterOutputStream::DeflaterOutputStream( OutputStream* outputStream, Deflater* deflater, bool own ) + : FilterOutputStream( outputStream, own ) { + + if( deflater == NULL ) { + throw NullPointerException( + __FILE__, __LINE__, "Deflater passed was NULL." ); + } + + this->deflater = deflater; + this->ownDeflater = false; + this->buf.resize( DEFAULT_BUFFER_SIZE ); + this->isDone = false; +} + +//////////////////////////////////////////////////////////////////////////////// +DeflaterOutputStream::DeflaterOutputStream( OutputStream* outputStream, Deflater* deflater, + std::size_t bufferSize, bool own ) + : FilterOutputStream( outputStream, own ) { + + if( deflater == NULL ) { + throw NullPointerException( + __FILE__, __LINE__, "Deflater passed was NULL." ); + } + + if( bufferSize == 0 ) { + throw IllegalArgumentException( + __FILE__, __LINE__, "Cannot create a zero sized buffer." ); + } + + this->deflater = deflater; + this->ownDeflater = false; + this->buf.resize( bufferSize ); + this->isDone = false; } //////////////////////////////////////////////////////////////////////////////// DeflaterOutputStream::~DeflaterOutputStream() { + try{ + + this->close(); + + if( ownDeflater ) { + delete this->deflater; + } + } + DECAF_CATCH_NOTHROW( Exception ) + DECAF_CATCHALL_NOTHROW() +} + +//////////////////////////////////////////////////////////////////////////////// +void DeflaterOutputStream::finish() throw ( decaf::io::IOException ) { + + try{ + + if( isDone ) { + return; + } + + std::size_t result; + this->deflater->finish(); + + while( !this->deflater->finished() ) { + + if( this->deflater->needsInput() ) { + this->deflater->setInput( buf, 0, 0 ); + } + result = this->deflater->deflate( &buf[0], buf.size(), 0, buf.size() ); + this->outputStream->write( &buf[0], buf.size(), 0, result ); + } + + this->isDone = true; + } + DECAF_CATCH_RETHROW( IOException ) + DECAF_CATCHALL_THROW( IOException ) +} + +//////////////////////////////////////////////////////////////////////////////// +void DeflaterOutputStream::close() throw ( decaf::io::IOException ) { + + try{ + + if( !this->deflater->finished() ) { + this->finish(); + } + this->deflater->end(); + FilterOutputStream::close(); + } + DECAF_CATCH_RETHROW( IOException ) + DECAF_CATCHALL_THROW( IOException ) +} + +//////////////////////////////////////////////////////////////////////////////// +void DeflaterOutputStream::doWriteByte( unsigned char value ) throw ( decaf::io::IOException ) { + + try{ + this->doWriteArrayBounded( &value, 1, 0, 1 ); + } + DECAF_CATCH_RETHROW( IOException ) + DECAF_CATCHALL_THROW( IOException ) +} + +//////////////////////////////////////////////////////////////////////////////// +void DeflaterOutputStream::doWriteArrayBounded( const unsigned char* buffer, std::size_t size, + std::size_t offset, std::size_t length ) + throw ( decaf::io::IOException, + decaf::lang::exceptions::NullPointerException, + decaf::lang::exceptions::IndexOutOfBoundsException ) { + + try{ + + if( isDone ) { + throw IOException( + __FILE__, __LINE__, "Finish was already called on this DeflaterOutputStream." ); + } + + if( buffer == NULL ) { + throw NullPointerException( + __FILE__, __LINE__, "Buffer passed was NULL." ); + } + + if( offset + length > size ) { + throw IndexOutOfBoundsException( + __FILE__, __LINE__, "Offset + length exceeds the buffer size." ); + } + + if( length == 0 ) { + return; + } + + if( isClosed() ) { + throw IOException( + __FILE__, __LINE__, "The stream is already closed." ); + } + + if( !this->deflater->needsInput() ) { + throw IOException( + __FILE__, __LINE__, "The Deflater is in an Invalid State." ); + } + + this->deflater->setInput( buffer, size, offset, length ); + + this->deflate(); + } + DECAF_CATCH_RETHROW( IOException ) + DECAF_CATCH_RETHROW( NullPointerException ) + DECAF_CATCH_RETHROW( IndexOutOfBoundsException ) + DECAF_CATCHALL_THROW( IOException ) +} + +//////////////////////////////////////////////////////////////////////////////// +void DeflaterOutputStream::deflate() throw ( decaf::io::IOException ) { + + try{ + + std::size_t result; + do{ + result = this->deflater->deflate( &buf[0], buf.size(), 0, buf.size() ); + this->outputStream->write( &buf[0], buf.size(), 0, result ); + } while( !this->deflater->needsInput() ); + } + DECAF_CATCH_RETHROW( IOException ) + DECAF_CATCHALL_THROW( IOException ) } Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.h?rev=916996&r1=916995&r2=916996&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/DeflaterOutputStream.h Sat Feb 27 17:30:53 2010 @@ -24,20 +24,118 @@ #include #include +#include + namespace decaf { namespace util { namespace zip { /** + * Provides a FilterOutputStream instance that compresses the data before writing it + * to the wrapped OutputStream. * + * @since 1.0 */ class DECAF_API DeflaterOutputStream : public decaf::io::FilterOutputStream { + protected: + + /** + * The Deflater for this stream. + */ + Deflater* deflater; + + /** + * The Buffer to use for + */ + std::vector buf; + + bool ownDeflater; + bool isDone; + + static const std::size_t DEFAULT_BUFFER_SIZE; + public: + /** + * Creates a new DeflateOutputStream with a Default Deflater and buffer size. + * + * @param outputStream + * The OutputStream instance to wrap. + * @param own + * Should this filter take ownership of the OutputStream pointer (default is false). + */ DeflaterOutputStream( decaf::io::OutputStream* outputStream, bool own = false ); + /** + * Creates a new DeflateOutputStream with a user supplied Deflater and a default buffer size. + * When the user supplied a Deflater instance the DeflaterOutpotStream does not take ownership + * of the Deflater pointer, the caller is still responsible for deleting the Deflater. + * + * @param outputStream + * The OutputStream instance to wrap. + * @param deflater + * The user supplied Deflater to use for compression. ( + * @param own + * Should this filter take ownership of the OutputStream pointer (default is false). + * + * @throws NullPointerException if the Deflater given is NULL. + */ + DeflaterOutputStream( decaf::io::OutputStream* outputStream, Deflater* deflater, bool own = false ); + + /** + * Creates a new DeflateOutputStream with a user supplied Deflater and specified buffer size. + * When the user supplied a Deflater instance the DeflaterOutpotStream does not take ownership + * of the Deflater pointer, the caller is still responsible for deleting the Deflater. + * + * @param outputStream + * The OutputStream instance to wrap. + * @param deflater + * The user supplied Deflater to use for compression. + * @param bufferSize + * The size of the input buffer. + * @param own + * Should this filter take ownership of the OutputStream pointer (default is false). + * + * @throws NullPointerException if the Deflater given is NULL. + * @throws IllegalArgumentException if bufferSize is 0. + */ + DeflaterOutputStream( decaf::io::OutputStream* outputStream, Deflater* deflater, + std::size_t bufferSize, bool own = false ); + virtual ~DeflaterOutputStream(); + /** + * Finishes writing any remaining data to the wrapped OutputStream but does not close + * it upon completion. + * + * @throws IOException if an I/O error occurs. + */ + virtual void finish() throw ( decaf::io::IOException ); + + /** + * {@inheritDoc} + * + * Finishes writing any remaining data to the OutputStream then closes the stream. + */ + virtual void close() throw ( decaf::io::IOException ); + + protected: + + virtual void doWriteByte( unsigned char value ) throw ( decaf::io::IOException ); + + virtual void doWriteArrayBounded( const unsigned char* buffer, std::size_t size, + std::size_t offset, std::size_t length ) + throw ( decaf::io::IOException, + decaf::lang::exceptions::NullPointerException, + decaf::lang::exceptions::IndexOutOfBoundsException ); + + protected: + + /** + * Writes a buffers worth of compressed data to the wrapped OutputStream. + */ + virtual void deflate() throw( decaf::io::IOException ); + }; }}} Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.cpp?rev=916996&r1=916995&r2=916996&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.cpp Sat Feb 27 17:30:53 2010 @@ -17,6 +17,9 @@ #include "InflaterInputStream.h" +#include +#include + using namespace decaf; using namespace decaf::io; using namespace decaf::lang; @@ -25,11 +28,256 @@ using namespace decaf::util::zip; //////////////////////////////////////////////////////////////////////////////// +const std::size_t InflaterInputStream::DEFAULT_BUFFER_SIZE = 512; + +//////////////////////////////////////////////////////////////////////////////// InflaterInputStream::InflaterInputStream( InputStream* inputStream, bool own ) : FilterInputStream( inputStream, own ) { + this->atEOF = false; + this->ownInflater = true; + this->inflater = new Inflater(); + this->buff.resize( DEFAULT_BUFFER_SIZE ); +} + +//////////////////////////////////////////////////////////////////////////////// +InflaterInputStream::InflaterInputStream( InputStream* inputStream, Inflater* inflater, bool own ) + : FilterInputStream( inputStream, own ) { + + if( inflater == NULL ) { + throw NullPointerException( + __FILE__, __LINE__, "Inflater passed was NULL." ); + } + + this->inflater = inflater; + this->ownInflater = false; + this->buff.resize( DEFAULT_BUFFER_SIZE ); + this->atEOF = false; +} + +//////////////////////////////////////////////////////////////////////////////// +InflaterInputStream::InflaterInputStream( InputStream* inputStream, Inflater* inflater, + std::size_t bufferSize, bool own ) + : FilterInputStream( inputStream, own ) { + + if( inflater == NULL ) { + throw NullPointerException( + __FILE__, __LINE__, "Inflater passed was NULL." ); + } + + if( bufferSize == 0 ) { + throw IllegalArgumentException( + __FILE__, __LINE__, "Cannot create a zero sized buffer." ); + } + + this->inflater = inflater; + this->ownInflater = false; + this->buff.resize( bufferSize ); + this->atEOF = false; } //////////////////////////////////////////////////////////////////////////////// InflaterInputStream::~InflaterInputStream() { + try{ + this->close(); + + if( ownInflater ) { + delete inflater; + } + } + DECAF_CATCH_NOTHROW( Exception ) + DECAF_CATCHALL_NOTHROW() +} + +//////////////////////////////////////////////////////////////////////////////// +bool InflaterInputStream::markSupported() const { + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStream::reset() throw ( decaf::io::IOException ) { + throw IOException( + __FILE__, __LINE__, "Not Supported for this class." ); +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStream::mark( int readLimit DECAF_UNUSED ) { + // No-op +} + +//////////////////////////////////////////////////////////////////////////////// +std::size_t InflaterInputStream::skip( std::size_t num ) + throw ( decaf::io::IOException, + decaf::lang::exceptions::UnsupportedOperationException ) { + + try{ + + std::size_t count = 0; + std::size_t remaining = Math::min( (long long)num, (long long)buff.size() ); + + while( count < num ) { + int x = read( &buff[0], buff.size() , 0, remaining ); + if( x == -1 ) { + return count; + } + count += x; + remaining = ( num - count ) < buff.size() ? num - count : buff.size(); + } + + return count; + } + DECAF_CATCH_RETHROW( IOException ) + DECAF_CATCHALL_THROW( IOException ) +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStream::close() throw ( decaf::io::IOException ) { + + try{ + + if( !isClosed() ) { + inflater->end(); + this->atEOF = true; + FilterInputStream::close(); + } + } + DECAF_CATCH_RETHROW( IOException ) + DECAF_CATCHALL_THROW( IOException ) +} + +//////////////////////////////////////////////////////////////////////////////// +std::size_t InflaterInputStream::available() const throw ( decaf::io::IOException ) { + + try{ + + if( isClosed() ) { + throw IOException( + __FILE__, __LINE__, "Stream already closed." ); + } + + if( atEOF ) { + return 0; + } + + return 1; + } + DECAF_CATCH_RETHROW( IOException ) + DECAF_CATCHALL_THROW( IOException ) +} + +//////////////////////////////////////////////////////////////////////////////// +int InflaterInputStream::doReadByte() throw ( decaf::io::IOException ) { + + try{ + + unsigned char buffer[1]; + if( doReadArrayBounded( buffer, 1, 0, 1 ) < 0 ) { + return -1; + } + + return (int)buffer[0]; + } + DECAF_CATCH_RETHROW( IOException ) + DECAF_CATCHALL_THROW( IOException ) +} + +//////////////////////////////////////////////////////////////////////////////// +int InflaterInputStream::doReadArrayBounded( unsigned char* buffer, std::size_t size, + std::size_t offset, std::size_t length ) + throw ( decaf::io::IOException, + decaf::lang::exceptions::IndexOutOfBoundsException, + decaf::lang::exceptions::NullPointerException ) { + + try{ + + if( buffer == NULL ) { + throw NullPointerException( + __FILE__, __LINE__, "Buffer passed was NULL." ); + } + + if( offset + length > size ) { + throw IndexOutOfBoundsException( + __FILE__, __LINE__, "Offset plus Length exceeds Buffer Size." ); + } + + if( length == 0 ) { + return 0; + } + + if( isClosed() ) { + throw IOException( + __FILE__, __LINE__, "Stream already closed." ); + } + + if( atEOF ) { + return -1; + } + + do { + + if( inflater->needsInput() ) { + this->fill(); + } + + // Invariant: if reading returns -1 or throws, eof must be true. + // It may also be true if the next read() should return -1. + try { + + int result = inflater->inflate( buffer, size, offset, length ); + + atEOF = inflater->finished(); + + if( result > 0 ) { + return result; + } else if( atEOF ) { + return -1; + } else if( inflater->needsDictionary() ) { + atEOF = true; + return -1; + } else if( this->length == -1 ) { + atEOF = true; + throw EOFException( + __FILE__, __LINE__, "Reached end of Input." ); + } + + } catch( DataFormatException& e ) { + + atEOF = true; + if( this->length == -1 ) { + throw EOFException( + __FILE__, __LINE__, "Reached end of Input." ); + } + + IOException ex( __FILE__, __LINE__, "Error from Inflater" ); + ex.initCause( e.clone() ); + throw ex; + } + + } while(true); + } + DECAF_CATCH_RETHROW( IOException ) + DECAF_CATCH_RETHROW( IndexOutOfBoundsException ) + DECAF_CATCH_RETHROW( NullPointerException ) + DECAF_CATCHALL_THROW( IOException ) +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStream::fill() throw ( decaf::io::IOException ) { + + try{ + + if( isClosed() ) { + throw IOException( + __FILE__, __LINE__, "Stream already closed." ); + } + + // Try and fill the input buffer, whatever we get goes into the inflater. + length = inputStream->read( &buff[0], buff.size(), 0, buff.size() ); + + if( length > 0 ) { + inflater->setInput( &buff[0], buff.size(), 0, length ); + } + } + DECAF_CATCH_RETHROW( IOException ) + DECAF_CATCHALL_THROW( IOException ) } Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.h?rev=916996&r1=916995&r2=916996&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.h Sat Feb 27 17:30:53 2010 @@ -24,20 +24,153 @@ #include #include +#include + namespace decaf { namespace util { namespace zip { /** + * A FilterInputStream that decompresses data read from the wrapped InputStream instance. * + * @since 1.0 */ class DECAF_API InflaterInputStream : public decaf::io::FilterInputStream { + protected: + + /** + * The Inflater instance to use. + */ + Inflater* inflater; + + /** + * The buffer to hold chunks of data read from the stream before inflation. + */ + std::vector buff; + + /** + * The amount of data currently stored in the input buffer. + */ + int length; + + bool ownInflater; + bool atEOF; + + static const std::size_t DEFAULT_BUFFER_SIZE; + public: + /** + * Create an instance of this class with a default inflater and buffer size. + * + * @param inputStream + * The InputStream instance to wrap. + * @param own + * Should this Filter take ownership of the InputStream pointer (defaults to false). + */ InflaterInputStream( decaf::io::InputStream* inputStream, bool own = false ); + /** + * Creates a new InflaterInputStream with a user supplied Inflater and a default buffer size. + * When the user supplied a Inflater instance the InflaterInputStream does not take ownership + * of the Inflater pointer, the caller is still responsible for deleting the Inflater. + * + * @param inputStream + * The InputStream instance to wrap. + * @param inflater + * The user supplied Inflater to use for decompression. ( + * @param own + * Should this filter take ownership of the InputStream pointer (default is false). + * + * @throws NullPointerException if the Inflater given is NULL. + */ + InflaterInputStream( decaf::io::InputStream* inputStream, Inflater* inflater, bool own = false ); + + /** + * Creates a new DeflateOutputStream with a user supplied Inflater and specified buffer size. + * When the user supplied a Inflater instance the InflaterInputStream does not take ownership + * of the Inflater pointer, the caller is still responsible for deleting the Inflater. + * + * @param inputStream + * The InputStream instance to wrap. + * @param inflater + * The user supplied Inflater to use for decompression. + * @param bufferSize + * The size of the input buffer. + * @param own + * Should this filter take ownership of the InputStream pointer (default is false). + * + * @throws NullPointerException if the Inflater given is NULL. + * @throws IllegalArgumentException if the bufferSize value is zero. + */ + InflaterInputStream( decaf::io::InputStream* inputStream, Inflater* inflater, + std::size_t bufferSize, bool own = false ); + virtual ~InflaterInputStream(); + /** + * {@inheritDoc} + * + * Until EOF this method always returns 1, thereafter it always returns 0. + */ + virtual std::size_t available() const throw ( decaf::io::IOException ); + + /** + * {@inheritDoc} + * + * Closes any resources associated with this InflaterInputStream. + */ + virtual void close() throw ( decaf::io::IOException ); + + /** + * {@inheritDoc} + * + * Skips the specified amount of uncompressed input data. + */ + virtual std::size_t skip( std::size_t num ) + throw ( decaf::io::IOException, + decaf::lang::exceptions::UnsupportedOperationException ); + + /** + * {@inheritDoc} + * + * Does nothing. + */ + virtual void mark( int readLimit ); + + /** + * {@inheritDoc} + * + * Always throws an IOException when called. + */ + virtual void reset() throw ( decaf::io::IOException ); + + /** + * {@inheritDoc} + * + * Always returns false. + */ + virtual bool markSupported() const; + + protected: + + /** + * Fills the input buffer with the next chunk of data. + * + * @throws IOException if an I/O error occurs. + */ + virtual void fill() throw( decaf::io::IOException ); + + protected: + + virtual int doReadByte() throw ( decaf::io::IOException ); + + virtual int doReadArrayBounded( unsigned char* buffer, std::size_t size, + std::size_t offset, std::size_t length ) + throw ( decaf::io::IOException, + decaf::lang::exceptions::IndexOutOfBoundsException, + decaf::lang::exceptions::NullPointerException ); + }; }}} Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am?rev=916996&r1=916995&r2=916996&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Sat Feb 27 17:30:53 2010 @@ -143,7 +143,9 @@ decaf/util/zip/CRC32Test.cpp \ decaf/util/zip/CheckedInputStreamTest.cpp \ decaf/util/zip/CheckedOutputStreamTest.cpp \ + decaf/util/zip/DeflaterOutputStreamTest.cpp \ decaf/util/zip/DeflaterTest.cpp \ + decaf/util/zip/InflaterInputStreamTest.cpp \ decaf/util/zip/InflaterTest.cpp \ main.cpp \ testRegistry.cpp \ @@ -286,7 +288,9 @@ decaf/util/zip/CRC32Test.h \ decaf/util/zip/CheckedInputStreamTest.h \ decaf/util/zip/CheckedOutputStreamTest.h \ + decaf/util/zip/DeflaterOutputStreamTest.h \ decaf/util/zip/DeflaterTest.h \ + decaf/util/zip/InflaterInputStreamTest.h \ decaf/util/zip/InflaterTest.h \ util/teamcity/TeamCityProgressListener.h Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterOutputStreamTest.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterOutputStreamTest.cpp?rev=916996&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterOutputStreamTest.cpp (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterOutputStreamTest.cpp Sat Feb 27 17:30:53 2010 @@ -0,0 +1,364 @@ +/* + * 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 "DeflaterOutputStreamTest.h" + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include + +#include + +#include + +using namespace std; +using namespace decaf; +using namespace decaf::io; +using namespace decaf::lang; +using namespace decaf::lang::exceptions; +using namespace decaf::util; +using namespace decaf::util::zip; + +//////////////////////////////////////////////////////////////////////////////// +namespace{ + + class MyDeflaterOutputStream : public DeflaterOutputStream { + private: + + bool deflateFlag; + + public: + + MyDeflaterOutputStream( OutputStream* out ) : DeflaterOutputStream( out ) { + this->deflateFlag = false; + } + + MyDeflaterOutputStream( OutputStream* out, Deflater* defl ) : + DeflaterOutputStream( out, defl ) { + + this->deflateFlag = false; + } + + MyDeflaterOutputStream( OutputStream* out, Deflater* defl, std::size_t size ) : + DeflaterOutputStream( out, defl, size ) { + + this->deflateFlag = false; + } + + std::vector& getProtectedBuf() { + return buf; + } + + bool getDaflateFlag() const { + return deflateFlag; + } + + protected: + + void deflate() throw( IOException ) { + deflateFlag = true; + DeflaterOutputStream::deflate(); + } + + }; + +} + +//////////////////////////////////////////////////////////////////////////////// +DeflaterOutputStreamTest::DeflaterOutputStreamTest() { +} + +//////////////////////////////////////////////////////////////////////////////// +DeflaterOutputStreamTest::~DeflaterOutputStreamTest() { +} + +//////////////////////////////////////////////////////////////////////////////// +void DeflaterOutputStreamTest::tearDown() { + + this->outputBuffer.clear(); +} + +//////////////////////////////////////////////////////////////////////////////// +void DeflaterOutputStreamTest::setUp() { + + this->outputBuffer.clear(); + this->outputBuffer.resize( 500 ); + + // setting up a deflater to be used + unsigned char byteArray[] = { 1, 3, 4, 7, 8 }; + int x = 0; + Deflater deflate( 1 ); + deflate.setInput( byteArray, 5, 0, 5 ); + + while( !( deflate.needsInput() ) ) { + x += deflate.deflate( outputBuffer, x, outputBuffer.size() - x ); + } + + deflate.finish(); + + while( !( deflate.finished() ) ) { + x = x + deflate.deflate( outputBuffer, x, outputBuffer.size() - x ); + } + + deflate.end(); +} + +//////////////////////////////////////////////////////////////////////////////// +void DeflaterOutputStreamTest::testConstructorOutputStreamDeflater() { + + unsigned char byteArray[] = { 1, 3, 4, 7, 8 }; + + ByteArrayOutputStream baos; + Deflater* nullDeflater = NULL; + + CPPUNIT_ASSERT_THROW_MESSAGE( + "Should have thrown a NullPointerException", + DeflaterOutputStream( &baos, nullDeflater ), + NullPointerException ); + + Deflater defl; + MyDeflaterOutputStream dos( &baos, &defl ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Buffer Size for new DeflaterOutputStream", + (std::size_t)512, dos.getProtectedBuf().size() ); + + dos.write( byteArray, 5 ); + dos.close(); +} + +//////////////////////////////////////////////////////////////////////////////// +void DeflaterOutputStreamTest::testConstructorOutputStream() { + + ByteArrayOutputStream baos; + MyDeflaterOutputStream dos( &baos ); + + // Test to see if DeflaterOutputStream was created with the correct + // buffer. + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Buffer Size", + (std::size_t)512, dos.getProtectedBuf().size() ); + + dos.write( &outputBuffer[0], outputBuffer.size() ); + dos.close(); +} + +//////////////////////////////////////////////////////////////////////////////// +void DeflaterOutputStreamTest::testConstructorOutputStreamDeflaterI() { + + std::size_t buf = 5; + std::size_t zeroBuf = 0; + + unsigned char byteArray[] = { 1, 3, 4, 7, 8, 3, 6 }; + ByteArrayOutputStream baos; + Deflater* nullDeflater = NULL; + + // Test for a null Deflater. + CPPUNIT_ASSERT_THROW_MESSAGE( + "Should have thrown a NullPointerException", + DeflaterOutputStream( &baos, nullDeflater, buf ), + NullPointerException ); + + Deflater defl; + + // Test for a zero buf. + CPPUNIT_ASSERT_THROW_MESSAGE( + "Should have thrown a IllegalArgumentException", + DeflaterOutputStream( &baos, &defl, zeroBuf ), + IllegalArgumentException ); + + // Test to see if DeflaterOutputStream was created with the correct + // buffer. + MyDeflaterOutputStream dos( &baos, &defl, buf ); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Buffer Size for new DeflaterOutputStream", + (std::size_t)5, dos.getProtectedBuf().size() ); + + dos.write( byteArray, 7, 0, 7 ); + dos.close(); +} + +//////////////////////////////////////////////////////////////////////////////// +void DeflaterOutputStreamTest::testClose() { + + ByteArrayOutputStream baos; + DeflaterOutputStream dos( &baos ); + unsigned char byteArray[] = { 1, 3, 4, 6 }; + dos.write( byteArray, 4 ); + dos.close(); + + ByteArrayInputStream bais( baos.toByteArrayRef() ); + InflaterInputStream iis( &bais ); + + // Test to see if the finish method wrote the bytes to the file. + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned.", 1, iis.read()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned.", 3, iis.read()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned.", 4, iis.read()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned.", 6, iis.read()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned.", -1, iis.read()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned.", -1, iis.read()); + iis.close(); + + // Test for a zero buf. + CPPUNIT_ASSERT_THROW_MESSAGE( + "Should have thrown a IOException", + dos.write( 5 ), + IOException ); + + // Test to write to a ByteArrayOutputStream that should have been closed + // by the DeflaterOutputStream. + CPPUNIT_ASSERT_THROW_MESSAGE( + "Should have thrown a IOException", + baos.write( 5 ), + IOException ); +} + +//////////////////////////////////////////////////////////////////////////////// +void DeflaterOutputStreamTest::testFinish() { + + ByteArrayOutputStream baos; + DeflaterOutputStream dos( &baos ); + unsigned char byteArray[] = { 1, 3, 4, 6 }; + dos.write( byteArray, 4 ); + dos.finish(); + + // Test to see if the same FileOutputStream can be used with the + // DeflaterOutputStream after finish is called. + CPPUNIT_ASSERT_THROW_MESSAGE( + "Should have thrown an IOException", + dos.write( 1 ), + IOException ); +} + +//void testWriteI() { +// File f1 = new File("writeI1.tst"); +// FileOutputStream fos = new FileOutputStream(f1); +// DeflaterOutputStream dos = new DeflaterOutputStream(fos); +// for (int i = 0; i < 3; i++) { +// dos.write(i); +// } +// dos.close(); +// FileInputStream fis = new FileInputStream(f1); +// InflaterInputStream iis = new InflaterInputStream(fis); +// for (int i = 0; i < 3; i++) { +// CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned.", i, iis.read()); +// } +// CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned (EOF).", -1, iis.read()); +// CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned (EOF).", -1, iis.read()); +// iis.close(); +// +// // Not sure if this test is that important. +// // Checks to see if you can write using the DeflaterOutputStream +// // after +// // the FileOutputStream has been closed. +// FileOutputStream fos2 = new FileOutputStream(f1); +// DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2); +// fos2.close(); +// try { +// dos2.write(2); +// CPPUNIT_FAIL("IOException not thrown"); +// } catch (IOException e) { +// } +// +//} +// +//void testWriteBIII() { +// unsigned char byteArray[] = { 1, 3, 4, 7, 8, 3, 6 }; +// +// // Test to see if the correct bytes are saved. +// File f1 = new File("writeBII.tst"); +// FileOutputStream fos1 = new FileOutputStream(f1); +// DeflaterOutputStream dos1 = new DeflaterOutputStream(fos1); +// dos1.write(byteArray, 2, 3); +// dos1.close(); +// FileInputStream fis = new FileInputStream(f1); +// InflaterInputStream iis = new InflaterInputStream(fis); +// CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned.", 4, iis.read()); +// CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned.", 7, iis.read()); +// CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned.", 8, iis.read()); +// CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned (EOF).", -1, iis.read()); +// CPPUNIT_ASSERT_EQUAL_MESSAGE( "Incorrect Byte Returned (EOF).", -1, iis.read()); +// iis.close(); +// f1.delete(); +// +// // Test for trying to write more bytes than available from the array +// File f2 = new File("writeBII2.tst"); +// FileOutputStream fos2 = new FileOutputStream(f2); +// DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2); +// try { +// dos2.write(byteArray, 2, 10); +// CPPUNIT_FAIL("IndexOutOfBoundsException not thrown"); +// } catch (IndexOutOfBoundsException e) { +// } +// +// // Test for trying to write a negative number of bytes. +// try { +// dos2.write(byteArray, 2, Integer.MIN_VALUE); +// CPPUNIT_FAIL("IndexOutOfBoundsException not thrown"); +// } catch (IndexOutOfBoundsException e) { +// } +// +// // Test for trying to start writing from a unsigned char < 0 from the array. +// try { +// dos2.write(byteArray, Integer.MIN_VALUE, 2); +// CPPUNIT_FAIL("IndexOutOfBoundsException not thrown"); +// } catch (IndexOutOfBoundsException e) { +// } +// +// // Test for trying to start writing from a unsigned char > than the array +// // size. +// try { +// dos2.write(byteArray, 10, 2); +// CPPUNIT_FAIL("IndexOutOfBoundsException not thrown"); +// } catch (IndexOutOfBoundsException e) { +// } +// dos2.close(); +// +// // Not sure if this test is that important. +// // Checks to see if you can write using the DeflaterOutputStream +// // after +// // the FileOutputStream has been closed. +// FileOutputStream fos3 = new FileOutputStream(f2); +// DeflaterOutputStream dos3 = new DeflaterOutputStream(fos3); +// fos3.close(); +// try { +// dos3.write(byteArray, 2, 3); +// CPPUNIT_FAIL("IOException not thrown"); +// } catch (IOException e) { +// } +// +//} + +//////////////////////////////////////////////////////////////////////////////// +void DeflaterOutputStreamTest::testDeflate() { + + ByteArrayOutputStream baos; + MyDeflaterOutputStream dos( &baos ); + CPPUNIT_ASSERT( !dos.getDaflateFlag() ); + for( int i = 0; i < 3; i++ ) { + dos.write( i ); + } + CPPUNIT_ASSERT( dos.getDaflateFlag() ); + dos.close(); +} Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterOutputStreamTest.cpp ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterOutputStreamTest.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterOutputStreamTest.h?rev=916996&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterOutputStreamTest.h (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterOutputStreamTest.h Sat Feb 27 17:30:53 2010 @@ -0,0 +1,64 @@ +/* + * 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_UTIL_ZIP_DEFLATEROUTPUTSTREAMTEST_H_ +#define _DECAF_UTIL_ZIP_DEFLATEROUTPUTSTREAMTEST_H_ + +#include +#include + +#include + +namespace decaf { +namespace util { +namespace zip { + + class DeflaterOutputStreamTest : public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE( DeflaterOutputStreamTest ); + CPPUNIT_TEST( testConstructorOutputStreamDeflater ); + CPPUNIT_TEST( testConstructorOutputStreamDeflaterI ); + CPPUNIT_TEST( testConstructorOutputStream ); + CPPUNIT_TEST( testClose ); + CPPUNIT_TEST( testFinish ); + CPPUNIT_TEST( testDeflate ); + CPPUNIT_TEST_SUITE_END(); + + private: + + std::vector outputBuffer; + + public: + + DeflaterOutputStreamTest(); + virtual ~DeflaterOutputStreamTest(); + + virtual void setUp(); + virtual void tearDown(); + + void testConstructorOutputStreamDeflater(); + void testConstructorOutputStream(); + void testConstructorOutputStreamDeflaterI(); + void testClose(); + void testFinish(); + void testDeflate(); + + }; + +}}} + +#endif /* _DECAF_UTIL_ZIP_DEFLATEROUTPUTSTREAMTEST_H_ */ Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterOutputStreamTest.h ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/InflaterInputStreamTest.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/InflaterInputStreamTest.cpp?rev=916996&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/InflaterInputStreamTest.cpp (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/InflaterInputStreamTest.cpp Sat Feb 27 17:30:53 2010 @@ -0,0 +1,449 @@ +/* + * 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 "InflaterInputStreamTest.h" + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include + +#include + +#include + +using namespace std; +using namespace decaf; +using namespace decaf::io; +using namespace decaf::lang; +using namespace decaf::lang::exceptions; +using namespace decaf::util; +using namespace decaf::util::zip; + +//////////////////////////////////////////////////////////////////////////////// +const std::string InflaterInputStreamTest::testString = + "Test_All_Tests\nTest_BufferedInputStream\nTest_java_io_BufferedOutputStream\n" + "Test_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\n" + "Test_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\n" + "Test_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\n" + "Test_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\n" + "Test_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\n" + "Test_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\n" + "Test_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\n" + "Test_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\n" + "Test_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\n" + "Test_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\n" + "Test_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\n" + "Test_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\n" + "Test_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\n" + "Test_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\n" + "Test_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\n" + "Test_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\n" + "Test_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\n" + "Test_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\n" + "Test_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\n" + "Test_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\n" + "Test_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\n" + "Test_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\n" + "Test_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\n" + "Test_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\n" + "Test_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\n" + "Test_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\n" + "Test_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\n" + "Test_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\n" + "Test_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\n" + "Test_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\n" + "Test_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\n" + "Test_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\n" + "Test_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\n" + "Test_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\n" + "Test_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\n" + "Test_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\n" + "Test_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n"; + +//////////////////////////////////////////////////////////////////////////////// +namespace { + + class MyInflaterInputStream : public InflaterInputStream { + + MyInflaterInputStream( InputStream* in ) : InflaterInputStream( in ) { + } + + MyInflaterInputStream( InputStream* in, Inflater* infl ) : InflaterInputStream( in, infl ) { + } + + MyInflaterInputStream( InputStream* in, Inflater* infl, std::size_t size ) + : InflaterInputStream( in, infl, size ) { + } + + void myFill() { + fill(); + } + }; +} + +//////////////////////////////////////////////////////////////////////////////// +InflaterInputStreamTest::InflaterInputStreamTest() { +} + +//////////////////////////////////////////////////////////////////////////////// +InflaterInputStreamTest::~InflaterInputStreamTest() { +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::setUp() { + + this->inputBuffer.clear(); + this->inputBuffer.resize( 500 ); + this->deflatedData.clear(); + this->deflatedData.resize( testString.size() + 100 ); + + Deflater deflater; + + deflater.setInput( (const unsigned char*)testString.c_str(), testString.size(), 0, testString.size() ); + deflater.finish(); + + int x = 0; + while( !deflater.finished() ) { + x += deflater.deflate( deflatedData, x, deflatedData.size() - x ); + } + + this->deflatedData.resize( x ); + + deflater.end(); +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::testConstructorInputStreamInflater() { + + unsigned char byteArray[100]; + ByteArrayInputStream bais( deflatedData ); + + Inflater inflate; + InflaterInputStream inflatIP( &bais, &inflate ); + + CPPUNIT_ASSERT( inflatIP.read( byteArray, 100 , 0, 5 ) == 5 ); + inflatIP.close(); +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::testConstructorInputStreamInflaterI() { + + int result = 0; + + ByteArrayInputStream bais( deflatedData ); + Inflater inflate; + InflaterInputStream inflatIP( &bais, &inflate, (std::size_t)1 ); + + int i = 0; + while( ( result = inflatIP.read() ) != -1 ) { + CPPUNIT_ASSERT( testString[i] == (char)result ); + i++; + } + + inflatIP.close(); +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::testMark() { + + ByteArrayInputStream bais( deflatedData ); + InflaterInputStream iis( &bais ); + + // mark do nothing, do no check + iis.mark( 0 ); + iis.mark( 10000000 ); +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::testMarkSupported() { + + ByteArrayInputStream bais( deflatedData ); + InflaterInputStream iis( &bais ); + + CPPUNIT_ASSERT( !iis.markSupported() ); + CPPUNIT_ASSERT( bais.markSupported() ); +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::testRead() { + + int result = 0; + ByteArrayInputStream bais( deflatedData ); + Inflater inflate; + InflaterInputStream inflatIP( &bais, &inflate, (std::size_t)1 ); + + int i = 0; + while( ( result = inflatIP.read() ) != -1 ) { + CPPUNIT_ASSERT( testString[i] == (char)result ); + i++; + } + + inflatIP.close(); +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::testAvailableNonEmptySource() { + + // this unsigned char[] is a deflation of these bytes: { 1, 3, 4, 6 } + unsigned char deflated[] = {72, -119, 99, 100, 102, 97, 3, 0, 0, 31, 0, 15, 0}; + + ByteArrayInputStream bais( deflated, 13 ); + InflaterInputStream in( &bais ); + + // InflaterInputStream.available() returns either 1 or 0, even though + // that contradicts the behavior defined in InputStream.available() + CPPUNIT_ASSERT_EQUAL( 1, in.read() ); + CPPUNIT_ASSERT_EQUAL( 1, (int)in.available() ); + CPPUNIT_ASSERT_EQUAL( 3, in.read() ); + CPPUNIT_ASSERT_EQUAL( 1, (int)in.available() ); + CPPUNIT_ASSERT_EQUAL( 4, in.read() ); + CPPUNIT_ASSERT_EQUAL( 1, (int)in.available() ); + CPPUNIT_ASSERT_EQUAL( 6, in.read() ); + CPPUNIT_ASSERT_EQUAL( 0, (int)in.available() ); + CPPUNIT_ASSERT_EQUAL( -1, in.read() ); + CPPUNIT_ASSERT_EQUAL( -1, in.read() ); +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::testAvailableSkip() { + + // this unsigned char[] is a deflation of these bytes: { 1, 3, 4, 6 } + unsigned char deflated[] = { 72, -119, 99, 100, 102, 97, 3, 0, 0, 31, 0, 15, 0 }; + ByteArrayInputStream bais( deflated, 13 ); + InflaterInputStream in( &bais ); + + CPPUNIT_ASSERT_EQUAL( 1, (int)in.available() ); + CPPUNIT_ASSERT_EQUAL( 4, (int)in.skip( 4 ) ); + CPPUNIT_ASSERT_EQUAL( 0, (int)in.available() ); +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::testAvailableEmptySource() { + + // this unsigned char[] is a deflation of the empty file + unsigned char deflated[] = { 120, -100, 3, 0, 0, 0, 0, 1 }; + ByteArrayInputStream bais( deflated, 13 ); + InflaterInputStream in( &bais ); + + CPPUNIT_ASSERT_EQUAL( -1, in.read() ); + CPPUNIT_ASSERT_EQUAL( -1, in.read() ); + CPPUNIT_ASSERT_EQUAL( 0, (int)in.available() ); +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::testReadBIII() { + + unsigned char test[507]; + for( int i = 0; i < 256; i++ ) { + test[i] = (unsigned char)i; + } + for( int i = 256; i < 507; i++ ) { + test[i] = (unsigned char)( 256 - i ); + } + + ByteArrayOutputStream baos; + DeflaterOutputStream dos( &baos ); + dos.write( test, (std::size_t)507 ); + dos.close(); + + ByteArrayInputStream bais( baos.toByteArrayRef() ); + InflaterInputStream iis( &bais ); + unsigned char outBuf[530]; + + int result = 0; + while( true ) { + result = iis.read( outBuf, 530, 0, 5 ); + if( result == -1 ) { + //"EOF was reached"; + break; + } + } +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::testReadBIII2() { + + ByteArrayInputStream bais( deflatedData ); + InflaterInputStream iis( &bais ); + unsigned char outBuf[530]; + iis.close(); + + CPPUNIT_ASSERT_THROW_MESSAGE( + "Should have thrown an IOException", + iis.read( outBuf, 530, 0, 5 ), + IOException ); +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::testReadBIII3() { + + unsigned char byteArray[] = { 45, 6, 1, 0, 12, 56, 125 }; + ByteArrayInputStream bais( byteArray, 7 ); + InflaterInputStream iis( &bais ); + unsigned char outBuf[530]; + + CPPUNIT_ASSERT_THROW_MESSAGE( + "Should have thrown an IOException", + iis.read( outBuf, 530, 0, 5 ), + IOException ); +} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::testReset() { + + ByteArrayInputStream bais( deflatedData ); + InflaterInputStream iis( &bais ); + + CPPUNIT_ASSERT_THROW_MESSAGE( + "Should have thrown an IOException", + iis.reset(), + IOException ); +} + +//void testSkip() { +// InputStream is = Support_Resources.getStream("hyts_available.tst"); +// InflaterInputStream iis = new InflaterInputStream(is); +// +// // Tests for skipping a negative number of bytes. +// try { +// iis.skip(-3); +// fail("IllegalArgumentException not thrown"); +// } catch (IllegalArgumentException e) { +// // Expected +// } +// CPPUNIT_ASSERT_EQUAL("Incorrect Byte Returned.", 5, iis.read()); +// +// try { +// iis.skip(Integer.MIN_VALUE); +// fail("IllegalArgumentException not thrown"); +// } catch (IllegalArgumentException e) { +// // Expected +// } +// CPPUNIT_ASSERT_EQUAL("Incorrect Byte Returned.", 4, iis.read()); +// +// // Test to make sure the correct number of bytes were skipped +// CPPUNIT_ASSERT_EQUAL("Incorrect Number Of Bytes Skipped.", 3, iis.skip(3)); +// +// // Test to see if the number of bytes skipped returned is true. +// CPPUNIT_ASSERT_EQUAL("Incorrect Byte Returned.", 7, iis.read()); +// +// CPPUNIT_ASSERT_EQUAL("Incorrect Number Of Bytes Skipped.", 0, iis.skip(0)); +// CPPUNIT_ASSERT_EQUAL("Incorrect Byte Returned.", 0, iis.read()); +// +// // Test for skipping more bytes than available in the stream +// CPPUNIT_ASSERT_EQUAL("Incorrect Number Of Bytes Skipped.", 2, iis.skip(4)); +// CPPUNIT_ASSERT_EQUAL("Incorrect Byte Returned.", -1, iis.read()); +// iis.close(); +//} +// +//void testSkip2() { +// int result = 0; +// int buffer[] = new int[100]; +// unsigned char orgBuffer[] = { 1, 3, 4, 7, 8 }; +// +// // testing for negative input to skip +// InputStream infile = Support_Resources +// .getStream("hyts_constru(OD).txt"); +// Inflater inflate = new Inflater(); +// InflaterInputStream inflatIP = new InflaterInputStream(infile, +// inflate, 10); +// long skip; +// try { +// skip = inflatIP.skip(Integer.MIN_VALUE); +// fail("Expected IllegalArgumentException when skip() is called with negative parameter"); +// } catch (IllegalArgumentException e) { +// // Expected +// } +// inflatIP.close(); +// +// // testing for number of bytes greater than input. +// InputStream infile2 = Support_Resources +// .getStream("hyts_constru(OD).txt"); +// InflaterInputStream inflatIP2 = new InflaterInputStream(infile2); +// +// // looked at how many bytes the skip skipped. It is +// // 5 and its supposed to be the entire input stream. +// +// skip = inflatIP2.skip(Integer.MAX_VALUE); +// // System.out.println(skip); +// CPPUNIT_ASSERT_EQUAL("method skip() returned wrong number of bytes skipped", +// 5, skip); +// +// // test for skipping of 2 bytes +// InputStream infile3 = Support_Resources +// .getStream("hyts_constru(OD).txt"); +// InflaterInputStream inflatIP3 = new InflaterInputStream(infile3); +// skip = inflatIP3.skip(2); +// CPPUNIT_ASSERT_EQUAL("the number of bytes returned by skip did not correspond with its input parameters", +// 2, skip); +// int i = 0; +// result = 0; +// while ((result = inflatIP3.read()) != -1) { +// buffer[i] = result; +// i++; +// } +// inflatIP2.close(); +// +// for (int j = 2; j < orgBuffer.length; j++) { +// assertTrue( +// "original compressed data did not equal decompressed data", +// buffer[j - 2] == orgBuffer[j]); +// } +//} +// +//void testAvailable() { +// InputStream is = Support_Resources.getStream("hyts_available.tst"); +// InflaterInputStream iis = new InflaterInputStream(is); +// +// int available; +// for (int i = 0; i < 11; i++) { +// iis.read(); +// available = iis.available(); +// if (available == 0) { +// CPPUNIT_ASSERT_EQUAL_MESSAGE("Expected no more bytes to read", -1, iis.read()); +// } else { +// CPPUNIT_ASSERT_EQUAL_MESSAGE("Bytes Available Should Return 1.", 1, available); +// } +// } +// +// iis.close(); +// try { +// iis.available(); +// fail("available after close should throw IOException."); +// } catch (IOException e) { +// // Expected +// } +//} + +//////////////////////////////////////////////////////////////////////////////// +void InflaterInputStreamTest::testClose() { + + ByteArrayInputStream bais( deflatedData ); + InflaterInputStream iin( &bais ); + iin.close(); + // test for exception + iin.close(); +} Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/InflaterInputStreamTest.cpp ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/InflaterInputStreamTest.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/InflaterInputStreamTest.h?rev=916996&view=auto ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/InflaterInputStreamTest.h (added) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/InflaterInputStreamTest.h Sat Feb 27 17:30:53 2010 @@ -0,0 +1,78 @@ +/* + * 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_UTIL_ZIP_INFLATERINPUTSTREAMTEST_H_ +#define _DECAF_UTIL_ZIP_INFLATERINPUTSTREAMTEST_H_ + +#include +#include + +namespace decaf { +namespace util { +namespace zip { + + class InflaterInputStreamTest : public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE( InflaterInputStreamTest ); + CPPUNIT_TEST( testConstructorInputStreamInflater ); + CPPUNIT_TEST( testConstructorInputStreamInflaterI ); + CPPUNIT_TEST( testMark ); + CPPUNIT_TEST( testMarkSupported ); + CPPUNIT_TEST( testRead ); + CPPUNIT_TEST( testAvailableNonEmptySource ); + CPPUNIT_TEST( testAvailableSkip ); + CPPUNIT_TEST( testAvailableEmptySource ); + CPPUNIT_TEST( testReadBIII ); + CPPUNIT_TEST( testReadBIII2 ); + CPPUNIT_TEST( testReadBIII3 ); + CPPUNIT_TEST( testReset ); + CPPUNIT_TEST( testClose ); + CPPUNIT_TEST_SUITE_END(); + + private: + + static const std::string testString; + + std::vector deflatedData; + std::vector inputBuffer; + + public: + + InflaterInputStreamTest(); + virtual ~InflaterInputStreamTest(); + + void setUp(); + + void testConstructorInputStreamInflater(); + void testConstructorInputStreamInflaterI(); + void testMark(); + void testMarkSupported(); + void testRead(); + void testAvailableNonEmptySource(); + void testAvailableSkip(); + void testAvailableEmptySource(); + void testReadBIII(); + void testReadBIII2(); + void testReadBIII3(); + void testReset(); + void testClose(); + + }; + +}}} + +#endif /* _DECAF_UTIL_ZIP_INFLATERINPUTSTREAMTEST_H_ */ Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/InflaterInputStreamTest.h ------------------------------------------------------------------------------ svn:eol-style = native Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp?rev=916996&r1=916995&r2=916996&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp Sat Feb 27 17:30:53 2010 @@ -172,22 +172,22 @@ //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::InputStreamTest ); //#include //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::OutputStreamTest ); -#include -CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::FilterInputStreamTest ); +//#include +//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::FilterInputStreamTest ); //#include //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::FilterOutputStreamTest ); -#include -CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::BufferedInputStreamTest ); +//#include +//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::BufferedInputStreamTest ); //#include //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::BufferedOutputStreamTest ); //#include //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::ByteArrayInputStreamTest ); //#include //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::ByteArrayOutputStreamTest ); -#include -CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::PushbackInputStreamTest ); -#include -CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::DataInputStreamTest ); +//#include +//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::PushbackInputStreamTest ); +//#include +//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::DataInputStreamTest ); //#include //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::DataOutputStreamTest ); //#include @@ -291,10 +291,14 @@ //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::zip::Adler32Test ); //#include //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::zip::CRC32Test ); -#include -CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::zip::CheckedInputStreamTest ); -#include -CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::zip::CheckedOutputStreamTest ); +//#include +//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::zip::CheckedInputStreamTest ); +//#include +//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::zip::CheckedOutputStreamTest ); +#include +CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::zip::DeflaterOutputStreamTest ); +#include +CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::zip::InflaterInputStreamTest ); //////////////////////////////////////////////////////////////////////////////////////////////////////////// // Marshaler Tests