activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r910686 [7/8] - in /activemq/activemq-cpp/trunk/activemq-cpp: ./ src/main/ src/main/decaf/internal/util/zip/ src/main/decaf/util/zip/ src/test/ src/test/decaf/util/zip/
Date Tue, 16 Feb 2010 20:54:11 GMT
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Inflater.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Inflater.h?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Inflater.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Inflater.h Tue Feb 16 20:54:08 2010
@@ -0,0 +1,334 @@
+/*
+ * 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_UTI_ZIP_INFLATER_H_
+#define _DECAF_UTI_ZIP_INFLATER_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
+#include <decaf/lang/exceptions/IllegalStateException.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+
+#include <decaf/util/zip/DataFormatException.h>
+
+#include <vector>
+
+namespace decaf {
+namespace util {
+namespace zip {
+
+    class InflaterData;
+
+    /**
+     * This class uncompresses data that was compressed using the <i>DEFLATE</i>
+     * algorithm (see <a href="http://www.gzip.org/algorithm.txt">specification</a>).
+     * <p>
+     * Basically this class is part of the API to the stream based ZLIB compression
+     * library and is used as such by {@code InflaterInputStream} and its
+     * descendants.
+     * <p>
+     * The typical usage of a {@code Inflater} outside this package consists of a
+     * specific call to one of its constructors before being passed to an instance
+     * of {@code InflaterInputStream}.
+     *
+     * @see InflaterInputStream
+     * @see Deflater
+     *
+     * @since 1.0
+     */
+    class DECAF_API Inflater {
+    private:
+
+        InflaterData* data;
+
+    public:
+
+        /**
+         * Creates a new decompressor.  This constructor defaults the inflater to use the ZLIB
+         * header and checksum fields.
+         */
+        Inflater();
+
+        /**
+         * Creates a new decompressor. If the parameter 'nowrap' is true then the ZLIB header
+         * and checksum fields will not be used. This provides compatibility with the compression
+         * format used by both GZIP and PKZIP.
+         *
+         * Note: When using the 'nowrap' option it is also necessary to provide an extra "dummy"
+         * byte as input. This is required by the ZLIB native library in order to support
+         * certain optimizations.
+         */
+        Inflater( bool nowrap );
+
+        virtual ~Inflater();
+
+        /**
+         * Sets input data for decompression. This should be called whenever needsInput() returns
+         * true indicating that more input data is required.
+         *
+         * @param buffer
+         *      The Buffer to read in for decompression.
+         * @param size
+         *      The size of the buffer passed in.
+         * @param offset
+         *      The position in the Buffer to start reading from.
+         * @param length
+         *      The number of bytes to read from the input buffer.
+         *
+         * @throws NullPointerException if buffer is NULL.
+         * @throws IndexOutOfBoundsException if the offset + length > size of the buffer.
+         * @throws IllegalStateException if in the end state.
+         */
+        void setInput( const unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Sets input data for decompression. This should be called whenever needsInput() returns
+         * true indicating that more input data is required.
+         *
+         * @param buffer
+         *      The Buffer to read in for decompression.
+         * @param offset
+         *      The position in the Buffer to start reading from.
+         * @param length
+         *      The number of bytes to read from the input buffer.
+         *
+         * @throws IndexOutOfBoundsException if the offset + length > size of the buffer.
+         * @throws IllegalStateException if in the end state.
+         */
+        void setInput( const std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Sets input data for decompression. This should be called whenever needsInput() returns
+         * true indicating that more input data is required.
+         *
+         * @param buffer
+         *      The Buffer to read in for decompression.
+         *
+         * @throws IllegalStateException if in the end state.
+         */
+        void setInput( const std::vector<unsigned char>& buffer )
+            throw( decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Returns the total number of bytes remaining in the input buffer. This can be used to
+         * find out what bytes still remain in the input buffer after decompression has finished.
+         *
+         * @returns the total number of bytes remaining in the input buffer
+         */
+        std::size_t getRemaining() const;
+
+        /**
+         * Sets the preset dictionary to the given array of bytes. Should be called when inflate()
+         * returns 0 and needsDictionary() returns true indicating that a preset dictionary is
+         * required. The method getAdler() can be used to get the Adler-32 value of the dictionary
+         * needed.
+         *
+         * @param buffer
+         *      The Buffer to read in for decompression.
+         * @param size
+         *      The size of the buffer passed in.
+         * @param offset
+         *      The position in the Buffer to start reading from.
+         * @param length
+         *      The number of bytes to read from the input buffer.
+         *
+         * @throws NullPointerException if buffer is NULL.
+         * @throws IndexOutOfBoundsException if the offset + length > size of the buffer.
+         * @throws IllegalStateException if in the end state.
+         * @throws IllegalArgumentException if the given dictionary doesn't match thre required
+         *         dictionaries checksum value.
+         */
+        void setDictionary( const unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::lang::exceptions::IllegalArgumentException,
+                   decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Sets the preset dictionary to the given array of bytes. Should be called when inflate()
+         * returns 0 and needsDictionary() returns true indicating that a preset dictionary is
+         * required. The method getAdler() can be used to get the Adler-32 value of the dictionary
+         * needed.
+         *
+         * @param buffer
+         *      The Buffer to read in for decompression.
+         * @param offset
+         *      The position in the Buffer to start reading from.
+         * @param length
+         *      The number of bytes to read from the input buffer.
+         *
+         * @throws IndexOutOfBoundsException if the offset + length > size of the buffer.
+         * @throws IllegalStateException if in the end state.
+         * @throws IllegalArgumentException if the given dictionary doesn't match thre required
+         *         dictionaries checksum value.
+         */
+        void setDictionary( const std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::lang::exceptions::IllegalArgumentException,
+                   decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Sets the preset dictionary to the given array of bytes. Should be called when inflate()
+         * returns 0 and needsDictionary() returns true indicating that a preset dictionary is
+         * required. The method getAdler() can be used to get the Adler-32 value of the dictionary
+         * needed.
+         *
+         * @param buffer
+         *      The Buffer to read in for decompression.
+         *
+         * @throws IllegalStateException if in the end state.
+         * @throws IllegalArgumentException if the given dictionary doesn't match thre required
+         *         dictionaries checksum value.
+         */
+        void setDictionary( const std::vector<unsigned char>& buffer )
+            throw( decaf::lang::exceptions::IllegalStateException,
+                   decaf::lang::exceptions::IllegalArgumentException );
+
+        /**
+         * @return true if the input data buffer is empty and setInput() should be called in
+         *         order to provide more input
+         */
+        bool needsInput() const;
+
+        /**
+         * @returns true if a preset dictionary is needed for decompression.
+         */
+        bool needsDictionary() const;
+
+        /**
+         * When called, indicates that decompression should end with the current contents of
+         * the input buffer.
+         */
+        void finish();
+
+        /**
+         * @return true if the end of the compressed data output stream has been reached.
+         */
+        bool finished() const;
+
+        /**
+         * Uncompresses bytes into specified buffer. Returns actual number of bytes uncompressed.
+         * A return value of 0 indicates that needsInput() or needsDictionary() should be called
+         * in order to determine if more input data or a preset dictionary is required. In the
+         * latter case, getAdler() can be used to get the Adler-32 value of the dictionary required.
+         *
+         * @param buffer
+         *      The Buffer to write the compressed data to.
+         * @param size
+         *      The size of the buffer passed in.
+         * @param offset
+         *      The position in the Buffer to start writing at.
+         * @param length
+         *      The maximum number of byte of data to write.
+         *
+         * @throws NullPointerException if buffer is NULL.
+         * @throws IllegalStateException if in the end state.
+         * @throws IndexOutOfBoundsException if the offset + length > size of the buffer.
+         * @throws DataFormatException if the compressed data format is invalid.
+         */
+        std::size_t inflate( unsigned char* buffer, std::size_t size, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IllegalStateException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::util::zip::DataFormatException );
+
+        /**
+         * Uncompresses bytes into specified buffer. Returns actual number of bytes uncompressed.
+         * A return value of 0 indicates that needsInput() or needsDictionary() should be called
+         * in order to determine if more input data or a preset dictionary is required. In the
+         * latter case, getAdler() can be used to get the Adler-32 value of the dictionary required.
+         *
+         * @param buffer
+         *      The Buffer to write the compressed data to.
+         * @param offset
+         *      The position in the Buffer to start writing at.
+         * @param length
+         *      The maximum number of byte of data to write.
+         *
+         * @throws IllegalStateException if in the end state.
+         * @throws IndexOutOfBoundsException if the offset + length > size of the buffer.
+         * @throws DataFormatException if the compressed data format is invalid.
+         */
+        std::size_t inflate( std::vector<unsigned char>& buffer, std::size_t offset, std::size_t length )
+            throw( decaf::lang::exceptions::IllegalStateException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::util::zip::DataFormatException );
+
+        /**
+         * Uncompresses bytes into specified buffer. Returns actual number of bytes uncompressed.
+         * A return value of 0 indicates that needsInput() or needsDictionary() should be called
+         * in order to determine if more input data or a preset dictionary is required. In the
+         * latter case, getAdler() can be used to get the Adler-32 value of the dictionary required.
+         *
+         * @param buffer
+         *      The Buffer to write the compressed data to.
+         *
+         * @throws IllegalStateException if in the end state.
+         * @throws DataFormatException if the compressed data format is invalid.
+         */
+        std::size_t inflate( std::vector<unsigned char>& buffer )
+            throw( decaf::lang::exceptions::IllegalStateException,
+                   decaf::util::zip::DataFormatException );
+
+        /**
+         * @returns the ADLER-32 value of the uncompressed data.
+         *
+         * @throws IllegalStateException if in the end state.
+         */
+        std::size_t getAdler() const throw( decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * @returns the total number of compressed bytes input so far.
+         *
+         * @throws IllegalStateException if in the end state.
+         */
+        long long getBytesRead() const throw( decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * @return the total number of decompressed bytes output so far.
+         *
+         * @throws IllegalStateException if in the end state.
+         */
+        long long getBytesWritten() const throw( decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Resets deflater so that a new set of input data can be processed. Keeps current decompression
+         * level and strategy settings.
+         *
+         * @throws IllegalStateException if in the end state.
+         */
+        void reset() throw( decaf::lang::exceptions::IllegalStateException );
+
+        /**
+         * Closes the decompressor and discards any unprocessed input. This method should be called
+         * when the decompressor is no longer being used, but will also be called automatically by the
+         * destructor. Once this method is called, the behavior of the Inflater object is undefined.
+         */
+        void end();
+
+    };
+
+}}}
+
+#endif /* _DECAF_UTI_ZIP_INFLATER_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/Inflater.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.cpp Tue Feb 16 20:54:08 2010
@@ -0,0 +1,35 @@
+/*
+ * 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 "InflaterInputStream.h"
+
+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;
+
+////////////////////////////////////////////////////////////////////////////////
+InflaterInputStream::InflaterInputStream( InputStream* inputStream, bool own ) :
+    FilterInputStream( inputStream, own ) {
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+InflaterInputStream::~InflaterInputStream() {
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.h Tue Feb 16 20:54:08 2010
@@ -0,0 +1,45 @@
+/*
+ * 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_INFLATERINPUTSTREAM_H_
+#define _DECAF_UTIL_ZIP_INFLATERINPUTSTREAM_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/io/FilterInputStream.h>
+#include <decaf/io/IOException.h>
+#include <decaf/util/zip/Inflater.h>
+
+namespace decaf {
+namespace util {
+namespace zip {
+
+    /**
+     *
+     */
+    class DECAF_API InflaterInputStream : public decaf::io::FilterInputStream {
+    public:
+
+        InflaterInputStream( decaf::io::InputStream* inputStream, bool own = false );
+
+        virtual ~InflaterInputStream();
+
+    };
+
+}}}
+
+#endif /* _DECAF_UTIL_ZIP_INFLATERINPUTSTREAM_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/InflaterInputStream.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/ZipException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/ZipException.h?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/ZipException.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/ZipException.h Tue Feb 16 20:54:08 2010
@@ -0,0 +1,124 @@
+/*
+ * 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_ZIPEXCEPTION_H_
+#define _DECAF_UTIL_ZIP_ZIPEXCEPTION_H_
+
+#include <decaf/io/IOException.h>
+
+namespace decaf{
+namespace util{
+namespace zip{
+
+    /*
+     * Signals that an End of File exception has occurred.
+     *
+     * @since 1.0
+     */
+    class DECAF_API ZipException : public io::IOException {
+    public:
+
+        /**
+         * Default Constructor
+         */
+        ZipException() throw(){}
+
+        /**
+         * Copy Constructor
+         * @param ex the exception to copy
+         */
+        ZipException( const lang::Exception& ex ) throw()
+        : IOException() {
+            *(lang::Exception*)this = ex;
+        }
+
+        /**
+         * Copy Constructor
+         * @param ex the exception to copy, which is an instance of this type
+         */
+        ZipException( const ZipException& ex ) throw()
+        : IOException() {
+            *(lang::Exception*)this = ex;
+        }
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occurred.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file The file name where exception occurs
+         * @param lineNumber The line number where the exception occurred.
+         * @param cause The exception that was the cause for this one to be thrown.
+         * @param msg The message to report
+         * @param ... list of primitives that are formatted into the message
+         */
+        ZipException( const char* file, const int lineNumber,
+                      const std::exception* cause,
+                      const char* msg, ... ) throw() : IOException( cause )
+        {
+            va_list vargs;
+            va_start( vargs, msg );
+            buildMessage( msg, vargs );
+
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+        }
+
+        /**
+         * Constructor
+         * @param cause Pointer to the exception that caused this one to
+         * be thrown, the object is cloned caller retains ownership.
+         */
+        ZipException( const std::exception* cause ) throw() : IOException( cause ) {}
+
+        /**
+         * Constructor
+         *
+         * @param file The file name where exception occurs
+         * @param lineNumber The line number where the exception occurred.
+         * @param msg The message to report
+         * @param ... list of primitives that are formatted into the message
+         */
+        ZipException( const char* file, const int lineNumber,
+                      const char* msg, ... ) throw()
+        : IOException()
+        {
+            va_list vargs;
+            va_start( vargs, msg );
+            buildMessage( msg, vargs );
+
+            // Set the first mark for this exception.
+            setMark( file, lineNumber );
+        }
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         *
+         * @return a new instance of an Exception that is a copy of this one.
+         */
+        virtual ZipException* clone() const{
+            return new ZipException( *this );
+        }
+
+        virtual ~ZipException() throw(){}
+
+    };
+
+}}}
+
+#endif /*_DECAF_UTIL_ZIP_ZIPEXCEPTION_H_*/

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/ZipException.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/zip/ZipException.h
------------------------------------------------------------------------------
    svn:executable = *

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=910686&r1=910685&r2=910686&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Tue Feb 16 20:54:08 2010
@@ -136,6 +136,10 @@
     decaf/util/concurrent/atomic/AtomicIntegerTest.cpp \
     decaf/util/concurrent/atomic/AtomicReferenceTest.cpp \
     decaf/util/concurrent/locks/LockSupportTest.cpp \
+    decaf/util/zip/Adler32Test.cpp \
+    decaf/util/zip/CRC32Test.cpp \
+    decaf/util/zip/DeflaterTest.cpp \
+    decaf/util/zip/InflaterTest.cpp \
     main.cpp \
     testRegistry.cpp \
     util/teamcity/TeamCityProgressListener.cpp
@@ -270,6 +274,10 @@
     decaf/util/concurrent/atomic/AtomicIntegerTest.h \
     decaf/util/concurrent/atomic/AtomicReferenceTest.h \
     decaf/util/concurrent/locks/LockSupportTest.h \
+    decaf/util/zip/Adler32Test.h \
+    decaf/util/zip/CRC32Test.h \
+    decaf/util/zip/DeflaterTest.h \
+    decaf/util/zip/InflaterTest.h \
     util/teamcity/TeamCityProgressListener.h
 
 

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/Adler32Test.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/Adler32Test.cpp?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/Adler32Test.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/Adler32Test.cpp Tue Feb 16 20:54:08 2010
@@ -0,0 +1,159 @@
+/*
+ * 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 "Adler32Test.h"
+
+#include <decaf/util/zip/Adler32.h>
+
+#include <decaf/lang/Integer.h>
+#include <decaf/lang/Long.h>
+
+#include <vector>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::util;
+using namespace decaf::util::zip;
+
+////////////////////////////////////////////////////////////////////////////////
+Adler32Test::Adler32Test() {
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Adler32Test::~Adler32Test() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Adler32Test::testConstructor() {
+    Adler32 adl;
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Constructor of adl32 failed", 1LL, adl.getValue() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Adler32Test::testGetValue() {
+
+    Adler32 adl;
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "GetValue should return a zero as a result of construction an object of Adler32",
+                                  1LL, adl.getValue() );
+
+    adl.reset();
+    adl.update( 1 );
+
+    // The value of the adl should be 131074
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(int) failed to update the checksum to the correct value ",
+                                  131074LL, adl.getValue());
+    adl.reset();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "reset failed to reset the checksum value to zero",
+                                  1LL, adl.getValue() );
+
+    adl.reset();
+    adl.update( Integer::MIN_VALUE );
+
+    // The value of the adl should be 65537
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(min) failed to update the checksum to the correct value ",
+                                  65537LL, adl.getValue() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Adler32Test::testReset() {
+
+    Adler32 adl;
+    adl.update( 1 );
+
+    // The value of the adl should be 131074
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(int) failed to update the checksum to the correct value ",
+                                  131074LL, adl.getValue() );
+    adl.reset();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "reset failed to reset the checksum value to zero",
+                                  1LL, adl.getValue() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Adler32Test::testUpdateI() {
+
+    Adler32 adl;
+    adl.update( 1 );
+    // The value of the adl should be 131074
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(int) failed to update the checksum to the correct value ",
+                                  131074LL, adl.getValue() );
+
+    adl.reset();
+    adl.update( Integer::MAX_VALUE );
+
+    // The value of the adl should be 16777472
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(max) failed to update the checksum to the correct value ",
+                                  16777472LL, adl.getValue() );
+
+    adl.reset();
+    adl.update( Integer::MIN_VALUE );
+
+    // The value of the adl should be 65537
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(min) failed to update the checksum to the correct value ",
+                                  65537LL, adl.getValue() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Adler32Test::testUpdateArray() {
+
+    unsigned char byteArray[] = { 1, 2 };
+    Adler32 adl;
+    adl.update( byteArray, 2, 0, 2 );
+
+    // The value of the adl should be 393220
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(unsigned char[]) failed to update the checksum to the correct value ",
+                                  393220LL, adl.getValue() );
+
+    adl.reset();
+    std::vector<unsigned char> byteEmpty( 10000, 0 );
+    adl.update( byteEmpty );
+
+    // The value of the adl should be 655360001
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(unsigned char[]) failed to update the checksum to the correct value ",
+                                  655360001LL, adl.getValue() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Adler32Test::testUpdateArrayIndexed() {
+
+    static const std::size_t SIZE = 3;
+    unsigned char byteArray[] = { 1, 2, 3 };
+
+    Adler32 adl;
+    std::size_t off = 2;// accessing the 2nd element of byteArray
+    std::size_t len = 1;
+    std::size_t lenError = 3;
+    std::size_t offError = 4;
+    adl.update( byteArray, SIZE, off, len );
+
+    // The value of the adl should be 262148
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(unsigned char[],std::size_t,std::size_t) failed to update the checksum to the correct value ",
+                                  262148LL, adl.getValue() );
+    std::size_t r = 0;
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown an IndexOutOfBoundsException for lenError",
+        adl.update( byteArray, SIZE, off, lenError ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown an IndexOutOfBoundsException for offError",
+        adl.update( byteArray, SIZE, offError, len ),
+        IndexOutOfBoundsException );
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/Adler32Test.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/Adler32Test.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/Adler32Test.h?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/Adler32Test.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/Adler32Test.h Tue Feb 16 20:54:08 2010
@@ -0,0 +1,55 @@
+/*
+ * 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_ADLER32TEST_H_
+#define _DECAF_UTIL_ZIP_ADLER32TEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf {
+namespace util {
+namespace zip {
+
+    class Adler32Test : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( Adler32Test );
+        CPPUNIT_TEST( testConstructor );
+        CPPUNIT_TEST( testGetValue );
+        CPPUNIT_TEST( testReset );
+        CPPUNIT_TEST( testUpdateI );
+        CPPUNIT_TEST( testUpdateArray );
+        CPPUNIT_TEST( testUpdateArrayIndexed );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        Adler32Test();
+        virtual ~Adler32Test();
+
+        void testConstructor();
+        void testGetValue();
+        void testReset();
+        void testUpdateI();
+        void testUpdateArray();
+        void testUpdateArrayIndexed();
+
+    };
+
+}}}
+
+#endif /* _DECAF_UTIL_ZIP_ADLER32TEST_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/Adler32Test.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/CRC32Test.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/CRC32Test.cpp?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/CRC32Test.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/CRC32Test.cpp Tue Feb 16 20:54:08 2010
@@ -0,0 +1,177 @@
+/*
+ * 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 "CRC32Test.h"
+
+#include <decaf/util/zip/CRC32.h>
+#include <decaf/lang/Integer.h>
+#include <decaf/lang/Long.h>
+
+#include <vector>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::util;
+using namespace decaf::util::zip;
+
+////////////////////////////////////////////////////////////////////////////////
+CRC32Test::CRC32Test() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CRC32Test::~CRC32Test() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CRC32Test::testConstructor() {
+
+    CRC32 crc;
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Constructor of CRC32 failed", 0LL, crc.getValue() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CRC32Test::testGetValue() {
+
+    // test methods of java.util.zip.crc32.getValue()
+    CRC32 crc;
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "getValue() should return a zero as a result of constructing a CRC32 instance",
+                                  0LL, crc.getValue() );
+
+    crc.reset();
+    crc.update( Integer::MAX_VALUE );
+
+    // Ran JDK and discovered that the value of the CRC should be
+    // 4278190080
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(max) failed to update the checksum to the correct value ",
+                                  4278190080LL, crc.getValue() );
+
+    crc.reset();
+    std::vector<unsigned char> byteEmpty( 10000, 0 );
+    crc.update( byteEmpty );
+
+    // Ran JDK and discovered that the value of the CRC should be
+    // 1295764014
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(byte[]) failed to update the checksum to the correct value ",
+                                  1295764014LL, crc.getValue() );
+
+    crc.reset();
+    crc.update( 1 );
+
+    // Ran JDK and discovered that the value of the CRC should be
+    // 2768625435
+    // CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(int) failed to update the checksum to the correct
+    // value ",2768625435L, crc.getValue());
+    crc.reset();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "reset failed to reset the checksum value to zero",
+                                  0LL, crc.getValue());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CRC32Test::testReset() {
+
+    CRC32 crc;
+    crc.update( 1 );
+
+    // Ran JDK and discovered that the value of the CRC should be
+    // 2768625435
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(int) failed to update the checksum to the correct value ",
+                                  2768625435LL, crc.getValue() );
+    crc.reset();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "reset failed to reset the checksum value to zero",
+                                  0LL, crc.getValue() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CRC32Test::testUpdateI() {
+
+    CRC32 crc;
+    crc.update( 1 );
+
+    // Ran JDK and discovered that the value of the CRC should be
+    // 2768625435
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(1) failed to update the checksum to the correct value ",
+                                  2768625435LL, crc.getValue() );
+
+    crc.reset();
+    crc.update( Integer::MAX_VALUE );
+
+    // Ran JDK and discovered that the value of the CRC should be
+    // 4278190080
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(max) failed to update the checksum to the correct value ",
+                                  4278190080LL, crc.getValue() );
+
+    crc.reset();
+    crc.update( Integer::MIN_VALUE );
+
+    // Ran JDK and discovered that the value of the CRC should be
+    // 3523407757
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(min) failed to update the checksum to the correct value ",
+                                  3523407757LL, crc.getValue() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CRC32Test::testUpdateArray() {
+
+    unsigned char byteArray[] = { 1, 2 };
+    CRC32 crc;
+    crc.update( byteArray, 2, 0, 2 );
+
+    // Ran JDK and discovered that the value of the CRC should be
+    // 3066839698
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(unsigned char[]) failed to update the checksum to the correct value ",
+                                  3066839698LL, crc.getValue() );
+
+    crc.reset();
+    std::vector<unsigned char> byteEmpty( 10000, 0 );
+    crc.update( byteEmpty );
+
+    // Ran JDK and discovered that the value of the CRC should be
+    // 1295764014
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(unsigned char[]) failed to update the checksum to the correct value ",
+                                  1295764014LL, crc.getValue() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CRC32Test::testUpdateArrayIndexed() {
+
+    static const std::size_t SIZE = 3;
+    unsigned char byteArray[] = {1, 2, 3};
+    CRC32 crc;
+
+    std::size_t off = 2;// accessing the 2nd element of byteArray
+    std::size_t len = 1;
+    std::size_t lenError = 3;
+    std::size_t offError = 4;
+    crc.update( byteArray, SIZE, off, len );
+
+    // Ran JDK and discovered that the value of the CRC should be
+    // 1259060791
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(unsigned char[],std::size_t,std::size_t) failed to update the checksum to the correct value ",
+                                  1259060791LL, crc.getValue() );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown an IndexOutOfBoundsException for lenError",
+        crc.update( byteArray, SIZE, off, lenError ),
+        IndexOutOfBoundsException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown an IndexOutOfBoundsException for offError",
+        crc.update( byteArray, SIZE, offError, len ),
+        IndexOutOfBoundsException );
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/CRC32Test.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/CRC32Test.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/CRC32Test.h?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/CRC32Test.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/CRC32Test.h Tue Feb 16 20:54:08 2010
@@ -0,0 +1,55 @@
+/*
+ * 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_CRC32TEST_H_
+#define _DECAF_UTIL_ZIP_CRC32TEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf {
+namespace util {
+namespace zip {
+
+    class CRC32Test : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( CRC32Test );
+        CPPUNIT_TEST( testConstructor );
+        CPPUNIT_TEST( testGetValue );
+        CPPUNIT_TEST( testReset );
+        CPPUNIT_TEST( testUpdateI );
+        CPPUNIT_TEST( testUpdateArray );
+        CPPUNIT_TEST( testUpdateArrayIndexed );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        CRC32Test();
+        virtual ~CRC32Test();
+
+        void testConstructor();
+        void testGetValue();
+        void testReset();
+        void testUpdateI();
+        void testUpdateArray();
+        void testUpdateArrayIndexed();
+
+    };
+
+}}}
+
+#endif /* _DECAF_UTIL_ZIP_CRC32TEST_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/CRC32Test.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterTest.cpp?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterTest.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterTest.cpp Tue Feb 16 20:54:08 2010
@@ -0,0 +1,1024 @@
+/*
+ * 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 "DeflaterTest.h"
+
+#include <decaf/util/zip/Deflater.h>
+#include <decaf/util/zip/Inflater.h>
+#include <decaf/util/zip/Adler32.h>
+#include <decaf/util/zip/CRC32.h>
+
+#include <decaf/lang/Integer.h>
+
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+#include <vector>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::util;
+using namespace decaf::util::zip;
+
+////////////////////////////////////////////////////////////////////////////////
+DeflaterTest::DeflaterTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DeflaterTest::~DeflaterTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testDeflateVector() {
+
+    unsigned char byteArray[5] = { 1, 3, 4, 7, 8 };
+
+    std::vector<unsigned char> outPutBuf( 50 );
+    std::vector<unsigned char> outPutInf( 50 );
+
+    std::size_t x = 0;
+
+    Deflater defl;
+    defl.setInput( byteArray, 5, 0, 5 );
+    defl.finish();
+
+    while( !defl.finished() ) {
+        x += defl.deflate( outPutBuf );
+    }
+
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Deflater at end of stream, should return 0",
+                                  0, (int)defl.deflate( outPutBuf ) );
+
+    long long totalOut = defl.getBytesWritten();
+    long long totalIn = defl.getBytesRead();
+
+    CPPUNIT_ASSERT_EQUAL( (long long)x, totalOut );
+    CPPUNIT_ASSERT_EQUAL( 5LL, totalIn );
+
+    defl.end();
+
+    Inflater infl;
+    try {
+        infl.setInput( outPutBuf );
+        while( !infl.finished() ) {
+            infl.inflate( outPutInf );
+        }
+    } catch( DataFormatException& e ) {
+        CPPUNIT_FAIL("Invalid input to be decompressed");
+    }
+
+    CPPUNIT_ASSERT_EQUAL( totalIn, infl.getBytesWritten() );
+    CPPUNIT_ASSERT_EQUAL( totalOut, infl.getBytesRead() );
+
+    for( int i = 0; i < 5; i++ ) {
+        CPPUNIT_ASSERT_EQUAL( byteArray[i], outPutInf[i] );
+    }
+
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Final decompressed data contained more bytes than original",
+                                  (unsigned char) 0, outPutInf[5] );
+
+    infl.end();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testDeflateArray() {
+
+    static const std::size_t BUFFER_SIZE = 50;
+    static const std::size_t INPUT_SIZE = 5;
+
+    unsigned char outPutBuf[BUFFER_SIZE];
+    unsigned char byteArray[] = { 5, 2, 3, 7, 8 };
+    unsigned char outPutInf[BUFFER_SIZE];
+
+    std::size_t offSet = 1;
+    std::size_t length = BUFFER_SIZE - 1;
+    std::size_t x = 0;
+
+    Deflater defl;
+
+    defl.setInput( byteArray, 5, 0, 5 );
+    defl.finish();
+
+    while( !defl.finished() ) {
+        x += defl.deflate( outPutBuf, BUFFER_SIZE, offSet, length );
+    }
+
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Deflater at end of stream, should return 0",
+                                  0, (int)defl.deflate( outPutBuf, BUFFER_SIZE, offSet, length ) );
+
+    long long totalOut = defl.getBytesWritten();
+    long long totalIn = defl.getBytesRead();
+    CPPUNIT_ASSERT_EQUAL( x, (std::size_t)totalOut );
+    CPPUNIT_ASSERT_EQUAL( INPUT_SIZE, (std::size_t)totalIn );
+    defl.end();
+
+    Inflater infl;
+    try {
+        infl.setInput( outPutBuf, BUFFER_SIZE, offSet, length );
+        while( !infl.finished() ) {
+            infl.inflate( outPutInf, BUFFER_SIZE, 0, BUFFER_SIZE );
+        }
+    } catch( DataFormatException& e ) {
+        CPPUNIT_FAIL("Invalid input to be decompressed");
+    }
+
+    CPPUNIT_ASSERT_EQUAL( totalIn, infl.getBytesWritten() );
+    CPPUNIT_ASSERT_EQUAL( totalOut, infl.getBytesRead() );
+    for( std::size_t i = 0; i < INPUT_SIZE; i++ ) {
+        CPPUNIT_ASSERT_EQUAL( byteArray[i], outPutInf[i] );
+    }
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Final decompressed data contained more bytes than original",
+                                  0, (int) outPutInf[BUFFER_SIZE] );
+    infl.end();
+
+    // Set of tests testing the boundaries of the offSet/length
+    Deflater deflater;
+    static const int SIZE = 100;
+    unsigned char outPutBuf2[SIZE];
+    deflater.setInput( byteArray, 5, 0, 5 );
+
+    for( int i = 0; i < 2; i++ ) {
+
+        if( i == 0 ) {
+            offSet = SIZE + 1;
+            length = SIZE;
+        } else {
+            offSet = 0;
+            length = SIZE + 1;
+        }
+
+        CPPUNIT_ASSERT_THROW_MESSAGE(
+            "Should have thrown an IndexOutOfBoundsException",
+            deflater.deflate( outPutBuf2, SIZE, offSet, length ),
+            IndexOutOfBoundsException );
+    }
+
+    defl.end();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testEnd() {
+
+    unsigned char byteArray[] = { 5, 2, 3, 7, 8 };
+    std::vector<unsigned char> outPutBuf(100);
+
+    Deflater defl;
+
+    defl.setInput( byteArray, 5, 0, 5 );
+    defl.finish();
+
+    while( !defl.finished() ) {
+        defl.deflate( outPutBuf );
+    }
+
+    defl.end();
+
+    helperEndTest( defl, "end" );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testFinish() {
+
+    // This test already here, its the same as test_deflate()
+    unsigned char byteArray[] = { 5, 2, 3, 7, 8 };
+    std::vector<unsigned char> outPutBuf(100);
+    std::vector<unsigned char> outPutInf(100);
+
+    std::size_t x = 0;
+    Deflater defl;
+    defl.setInput( byteArray, 5, 0, 5 );
+    defl.finish();
+
+    while( !defl.finished() ) {
+        x += defl.deflate( outPutBuf );
+    }
+
+    long long totalOut = defl.getBytesWritten();
+    long long totalIn = defl.getBytesRead();
+    CPPUNIT_ASSERT_EQUAL( (long long)x, totalOut);
+    CPPUNIT_ASSERT_EQUAL( 5LL, totalIn );
+    defl.end();
+
+    Inflater infl;
+    infl.setInput( outPutBuf );
+    while( !infl.finished() ) {
+        infl.inflate( outPutInf );
+    }
+    CPPUNIT_ASSERT_EQUAL( totalIn, infl.getBytesWritten() );
+    CPPUNIT_ASSERT_EQUAL( totalOut, infl.getBytesRead() );
+    for( int i = 0; i < 5; i++ ) {
+        CPPUNIT_ASSERT_EQUAL( byteArray[i], outPutInf[i] );
+    }
+
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "Final decompressed data contained more bytes than original",
+                                  0, (int)outPutInf[5] );
+    infl.end();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testFinished() {
+
+    unsigned char byteArray[] = { 5, 2, 3, 7, 8 };
+    std::vector<unsigned char> outPutBuf( 100 );
+    Deflater defl;
+
+    CPPUNIT_ASSERT_MESSAGE( "Test 1: Deflater should not be finished.", !defl.finished() );
+    defl.setInput( byteArray, 5, 0, 5 );
+    CPPUNIT_ASSERT_MESSAGE( "Test 2: Deflater should not be finished.", !defl.finished() );
+    defl.finish();
+    CPPUNIT_ASSERT_MESSAGE( "Test 3: Deflater should not be finished.", !defl.finished() );
+    while( !defl.finished() ) {
+        defl.deflate( outPutBuf );
+    }
+    CPPUNIT_ASSERT_MESSAGE( "Test 4: Deflater should be finished.", defl.finished() );
+    defl.end();
+    CPPUNIT_ASSERT_MESSAGE( "Test 5: Deflater should be finished.", defl.finished() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testGetAdler() {
+
+    unsigned char byteArray[] = { 'a', 'b', 'c', 1, 2, 3 };
+    std::vector<unsigned char> outPutBuf( 100 );
+    Deflater defl;
+
+    // getting the checkSum value using the Adler
+    defl.setInput( byteArray, 5, 0, 5 );
+    defl.finish();
+    while( !defl.finished() ) {
+        defl.deflate( outPutBuf );
+    }
+    long long checkSumD = defl.getAdler();
+    defl.end();
+
+    // getting the checkSum value through the Adler32 class
+    Adler32 adl;
+    adl.update( byteArray, 5, 0, 5 );
+    long long checkSumR = adl.getValue();
+
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( std::string() +
+                                  "The checksum value returned by getAdler() is not the same " +
+                                  "as the checksum returned by creating the adler32 instance",
+                                  checkSumD, checkSumR );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testNeedsInput() {
+
+    Deflater defl;
+    CPPUNIT_ASSERT_MESSAGE( "needsInput give the wrong boolean value as a result of no input buffer",
+                            defl.needsInput() );
+    unsigned char byteArray[] = { 1, 2, 3 };
+    defl.setInput( byteArray, 3, 0, 3 );
+    CPPUNIT_ASSERT_MESSAGE( "needsInput give wrong boolean value as a result of a full input buffer",
+                            !defl.needsInput() );
+    std::vector<unsigned char> outPutBuf( 100 );
+    while( !defl.needsInput() ) {
+        defl.deflate( outPutBuf );
+    }
+    std::vector<unsigned char> emptyByteArray( 0 );
+    defl.setInput( emptyByteArray );
+    CPPUNIT_ASSERT_MESSAGE( "needsInput give wrong boolean value as a result of an empty input buffer",
+                            defl.needsInput() );
+    defl.setInput( byteArray, 3, 0, 3 );
+    defl.finish();
+    while( !defl.finished() ) {
+        defl.deflate( outPutBuf );
+    }
+    defl.end();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testReset() {
+
+    std::vector<unsigned char> outPutBuf( 100 );
+    std::vector<unsigned char> outPutInf( 100 );
+
+    unsigned char curArray[5];
+    unsigned char byteArray[] = { 1, 3, 4, 7, 8 };
+    unsigned char byteArray2[] = { 8, 7, 4, 3, 1 };
+
+    std::size_t x = 0;
+    std::size_t orgValue = 0;
+    Deflater defl;
+
+    for( std::size_t i = 0; i < 3; i++ ) {
+
+        if( i == 0 ) {
+            memcpy( curArray, byteArray, 5 );
+        } else if( i == 1 ) {
+            memcpy( curArray, byteArray2, 5 );
+        } else {
+            defl.reset();
+        }
+
+        defl.setInput( curArray, 5, 0, 5 );
+        defl.finish();
+        while( !defl.finished() ) {
+            x += defl.deflate( outPutBuf );
+        }
+
+        if( i == 0 ) {
+            CPPUNIT_ASSERT_EQUAL( x, (std::size_t)defl.getBytesWritten() );
+        } else if( i == 1 ) {
+            CPPUNIT_ASSERT_EQUAL( x, orgValue );
+        } else {
+            CPPUNIT_ASSERT_EQUAL( x, orgValue * 2 );
+        }
+
+        if( i == 0 ) {
+            orgValue = x;
+        }
+
+        try {
+            Inflater infl;
+            infl.setInput( outPutBuf );
+            while( !infl.finished() ) {
+                infl.inflate( outPutInf );
+            }
+            infl.end();
+        } catch( DataFormatException e ) {
+            CPPUNIT_FAIL( std::string( "Test " ) + Integer::toString( i ) +
+                          ": Invalid input to be decompressed" );
+        }
+
+        if( i == 1 ) {
+            memcpy( curArray, byteArray, 5 );
+        }
+
+        for( std::size_t j = 0; j < 5; j++ ) {
+            CPPUNIT_ASSERT_EQUAL( curArray[j], outPutInf[j] );
+        }
+
+        CPPUNIT_ASSERT_EQUAL( 0, (int)outPutInf[5] );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testSetDictionaryVector() {
+
+    static const int DICT_SIZE = 7;
+    static const int ARRAY_SIZE = 15;
+
+    // This test is very close to getAdler()
+    std::vector<unsigned char> dictionary( DICT_SIZE );
+    dictionary[0] = 'e';
+    dictionary[1] = 'r';
+    dictionary[2] = 't';
+    dictionary[3] = 'a';
+    dictionary[4] = 'b';
+    dictionary[5] = 2;
+    dictionary[6] = 3;
+
+    unsigned char byteArray[] = { 4, 5, 3, 2, 'a', 'b', 6, 7, 8, 9, 0, 's', '3', 'w', 'r' };
+    std::vector<unsigned char> outPutBuf( 100 );
+
+    Deflater defl;
+    long long deflAdler = defl.getAdler();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "No dictionary set, no data deflated, getAdler should return 1",
+                                  1LL, deflAdler );
+    defl.setDictionary( dictionary, 0, DICT_SIZE );
+    deflAdler = defl.getAdler();
+
+    // getting the checkSum value through the Adler32 class
+    Adler32 adl;
+    adl.update( dictionary, 0, DICT_SIZE );
+    long long realAdler = adl.getValue();
+    CPPUNIT_ASSERT_EQUAL( deflAdler, realAdler );
+
+    defl.setInput( byteArray, ARRAY_SIZE, 0, ARRAY_SIZE );
+    defl.finish();
+    while( !defl.finished() ) {
+        defl.deflate( outPutBuf );
+    }
+    deflAdler = defl.getAdler();
+    Adler32 adl2;
+    adl2.update( byteArray, ARRAY_SIZE, 0, ARRAY_SIZE );
+    realAdler = adl2.getValue();
+    // Deflate is finished and there were bytes deflated that did not occur
+    // in the dictionaryArray, therefore a new dictionary was automatically
+    // set.
+    CPPUNIT_ASSERT_EQUAL( realAdler, deflAdler );
+    defl.end();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testSetDictionaryBIII() {
+
+    static const int DICT_SIZE = 9;
+    static const int ARRAY_SIZE = 23;
+
+    // This test is very close to getAdler()
+    unsigned char dictionaryArray[] = { 'e', 'r', 't', 'a', 'b', 2, 3, 'o', 't' };
+    unsigned char byteArray[] = { 4, 5, 3, 2, 'a', 'b', 6, 7, 8, 9, 0, 's',
+                                  '3', 'w', 'r', 't', 'u', 'i', 'o', 4, 5, 6, 7 };
+    std::vector<unsigned char> outPutBuf( 100 );
+
+    std::size_t offSet = 4;
+    std::size_t length = 5;
+
+    Deflater defl;
+    long long deflAdler = defl.getAdler();
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "No dictionary set, no data deflated, getAdler should return 1",
+                                  1LL, deflAdler );
+    defl.setDictionary( dictionaryArray, DICT_SIZE, offSet, length );
+    deflAdler = defl.getAdler();
+
+    // getting the checkSum value through the Adler32 class
+    Adler32 adl;
+    adl.update( dictionaryArray, DICT_SIZE, offSet, length );
+    long long realAdler = adl.getValue();
+    CPPUNIT_ASSERT_EQUAL( deflAdler, realAdler );
+
+    defl.setInput( byteArray, ARRAY_SIZE, 0, ARRAY_SIZE );
+    while( !defl.needsInput() ) {
+        defl.deflate( outPutBuf );
+    }
+    deflAdler = defl.getAdler();
+    Adler32 adl2;
+    adl2.update( byteArray, ARRAY_SIZE, 0, ARRAY_SIZE );
+    realAdler = adl2.getValue();
+    // Deflate is finished and there were bytes deflated that did not occur
+    // in the dictionaryArray, therefore a new dictionary was automatically
+    // set.
+    CPPUNIT_ASSERT_EQUAL( realAdler, deflAdler );
+    defl.end();
+
+    // boundary check
+    Deflater defl2;
+    for( std::size_t i = 0; i < 2; i++ ) {
+
+        if( i == 0 ) {
+            offSet = 0;
+            length = DICT_SIZE + 1;
+        } else {
+            offSet = DICT_SIZE + 1;
+            length = 1;
+        }
+
+        try {
+            defl2.setDictionary( dictionaryArray, DICT_SIZE, offSet, length );
+            CPPUNIT_FAIL( std::string( "Test " ) + Integer::toString( i ) +
+                          ": boundary check for setDictionary CPPUNIT_FAILed for offset " +
+                          Integer::toString( offSet ) + " and length " +
+                          Integer::toString( length ) );
+        } catch( IndexOutOfBoundsException& e ) {
+        }
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testSetInputVector() {
+
+    std::vector<unsigned char> byteVector( 3 );
+    std::vector<unsigned char> outPutBuf( 100 );
+    std::vector<unsigned char> outPutInf( 100 );
+
+    byteVector[0] = 1;
+    byteVector[1] = 2;
+    byteVector[2] = 3;
+
+    Deflater defl;
+    defl.setInput( byteVector );
+    CPPUNIT_ASSERT_MESSAGE( "the array buffer in setInput() is empty",
+                    !defl.needsInput());
+    // The second setInput() should be ignored since needsInput() return
+    // false
+    defl.setInput( byteVector );
+    defl.finish();
+    while( !defl.finished() ) {
+        defl.deflate( outPutBuf );
+    }
+    defl.end();
+
+    Inflater infl;
+    try {
+        infl.setInput( outPutBuf );
+        while( !infl.finished() ) {
+            infl.inflate( outPutInf );
+        }
+    } catch( DataFormatException e ) {
+        CPPUNIT_FAIL("Invalid input to be decompressed");
+    }
+
+    for( std::size_t i = 0; i < byteVector.size(); i++ ) {
+        CPPUNIT_ASSERT_EQUAL( byteVector[i], outPutInf[i] );
+    }
+    CPPUNIT_ASSERT_EQUAL( byteVector.size(), (std::size_t)infl.getBytesWritten() );
+    infl.end();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testSetInputBIII() {
+
+    static const int SIZE = 5;
+
+    unsigned char byteArray[] = { 1, 2, 3, 4, 5 };
+    std::vector<unsigned char> outPutBuf( 50 );
+    std::vector<unsigned char> outPutInf( 50 );
+
+    std::size_t offSet = 1;
+    std::size_t length = 3;
+
+    Deflater defl;
+    defl.setInput( byteArray, SIZE, offSet, length);
+
+    CPPUNIT_ASSERT_MESSAGE( "the array buffer in setInput() is empty", !defl.needsInput() );
+
+    // The second setInput() should be ignored since needsInput() return
+    // false
+    defl.setInput( byteArray, SIZE, offSet, length );
+    defl.finish();
+
+    while( !defl.finished() ) {
+        defl.deflate( outPutBuf );
+    }
+    defl.end();
+
+    Inflater infl;
+    infl.setInput( outPutBuf );
+    while( !infl.finished() ) {
+        infl.inflate( outPutInf );
+    }
+
+    for( std::size_t i = 0; i < length; i++ ) {
+        CPPUNIT_ASSERT_EQUAL( byteArray[i + offSet], outPutInf[i] );
+    }
+    CPPUNIT_ASSERT_EQUAL( length, (std::size_t)infl.getBytesWritten() );
+    infl.end();
+
+    // boundary check
+    Deflater defl2;
+    for( std::size_t i = 0; i < 2; i++ ) {
+
+        if( i == 0 ) {
+            offSet = 0;
+            length = SIZE + 1;
+        } else {
+            offSet = SIZE + 1;
+            length = 1;
+        }
+
+        try {
+            defl2.setInput( byteArray, SIZE, offSet, length );
+            CPPUNIT_FAIL( std::string( "Test " ) + Integer::toString( i ) +
+                          ": boundary check for setInput CPPUNIT_FAILed for offset " +
+                          Integer::toString( offSet ) + " and length " +
+                          Integer::toString( length ) );
+        } catch( IndexOutOfBoundsException& e ) {
+        }
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testSetLevel() {
+
+    std::vector<unsigned char> byteArray( 100 );
+    for( std::size_t ix = 0; ix < 100; ++ix ) {
+        byteArray[ix] = ix + 1;
+    }
+
+    std::vector<unsigned char> outPutBuf( 500 );
+
+    long long totalOut;
+    for( std::size_t i = 0; i < 10; i++ ) {
+
+        {
+            Deflater defl;
+            defl.setLevel( i );
+            outPutBuf.assign( outPutBuf.size(), 0 );
+            defl.setInput( byteArray );
+            while( !defl.needsInput() ) {
+                defl.deflate( outPutBuf );
+            }
+            defl.finish();
+            while( !defl.finished() ) {
+                defl.deflate( outPutBuf );
+            }
+            totalOut = defl.getBytesWritten();
+            defl.end();
+        }
+        {
+            outPutBuf.assign( outPutBuf.size(), 0 );
+            Deflater defl( i );
+            defl.setInput( byteArray );
+            while( !defl.needsInput() ) {
+                defl.deflate( outPutBuf );
+            }
+            defl.finish();
+            while( !defl.finished() ) {
+                defl.deflate( outPutBuf );
+            }
+            CPPUNIT_ASSERT_EQUAL( totalOut, defl.getBytesWritten() );
+            defl.end();
+        }
+    }
+
+    Deflater boundDefl;
+
+    // testing boundaries
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "IllegalArgumentException not thrown when setting level to a number < 0.",
+        boundDefl.setLevel( -2 ),
+        IllegalArgumentException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "IllegalArgumentException not thrown when setting level to a number > 9.",
+        boundDefl.setLevel( 10 ),
+        IllegalArgumentException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testSetStrategy() {
+
+    std::vector<unsigned char> byteArray( 100 );
+    for( std::size_t ix = 0; ix < 100; ++ix ) {
+        byteArray[ix] = ix + 1;
+    }
+
+    for( std::size_t i = 0; i < 3; i++ ) {
+
+        std::vector<unsigned char> outPutBuf( 500 );
+        Deflater mdefl;
+
+        if( i == 0 ) {
+            mdefl.setStrategy( Deflater::DEFAULT_STRATEGY );
+        } else if( i == 1 ) {
+            mdefl.setStrategy( Deflater::HUFFMAN_ONLY );
+        } else {
+            mdefl.setStrategy( Deflater::FILTERED );
+        }
+
+        mdefl.setInput( byteArray );
+        while( !mdefl.needsInput() ) {
+            mdefl.deflate( outPutBuf );
+        }
+        mdefl.finish();
+        while( !mdefl.finished() ) {
+            mdefl.deflate( outPutBuf );
+        }
+
+        if( i == 0 ) {
+            CPPUNIT_ASSERT_MESSAGE( "getBytesWritten() for the default strategy did not produce data",
+                                    0LL != mdefl.getBytesWritten() );
+        } else if( i == 1 ) {
+            CPPUNIT_ASSERT_MESSAGE( "getBytesWritten() for the Huffman strategy did not produce data",
+                                    0LL != mdefl.getBytesWritten() );
+        } else {
+            CPPUNIT_ASSERT_MESSAGE( "getBytesWritten for the Filtered strategy did not produce data",
+                                    0LL != mdefl.getBytesWritten() );
+        }
+        mdefl.end();
+    }
+
+    // Attempting to setStrategy to an invalid value
+    Deflater boundDefl;
+
+    // testing boundaries
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "IllegalArgumentException not thrown when setting strategy to an invalid value.",
+        boundDefl.setStrategy( 424 ),
+        IllegalArgumentException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testConstructor() {
+
+    std::vector<unsigned char> byteArray( 100 );
+    for( std::size_t ix = 0; ix < 100; ++ix ) {
+        byteArray[ix] = ix + 1;
+    }
+
+    Deflater defl;
+    std::vector<unsigned char> outPutBuf( 500 );
+    defl.setInput( byteArray, 0, 100 );
+    while( !defl.needsInput() ) {
+        defl.deflate( outPutBuf );
+    }
+    defl.finish();
+    while( !defl.finished() ) {
+        defl.deflate( outPutBuf );
+    }
+    long long totalOut = defl.getBytesWritten();
+    defl.end();
+
+    // creating a Deflater using the DEFAULT_COMPRESSION as the int
+    Deflater mdefl( 6 );
+    outPutBuf.assign( outPutBuf.size(), 0 );
+    mdefl.setInput( byteArray );
+    while( !mdefl.needsInput() ) {
+        mdefl.deflate( outPutBuf );
+    }
+    mdefl.finish();
+    while( !mdefl.finished() ) {
+        mdefl.deflate( outPutBuf );
+    }
+    CPPUNIT_ASSERT_EQUAL( totalOut, mdefl.getBytesWritten() );
+    mdefl.end();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testConstructorIB() {
+
+    static const std::size_t ARRAY_SIZE = 15;
+
+    unsigned char byteArray[] = { 4, 5, 3, 2, 'a', 'b', 6, 7, 8, 9, 0, 's', '3', 'w', 'r' };
+
+    Deflater defl;
+    std::vector<unsigned char> outPutBuf( 500 );
+    defl.setLevel( 2 );
+    defl.setInput( byteArray, ARRAY_SIZE, 0, ARRAY_SIZE );
+    while( !defl.needsInput() ) {
+        defl.deflate( outPutBuf );
+    }
+    defl.finish();
+    while( !defl.finished() ) {
+        defl.deflate( outPutBuf );
+    }
+    long long totalOut = defl.getBytesWritten();
+    defl.end();
+
+    {
+        outPutBuf.assign( outPutBuf.size(), 0 );
+        Deflater defl( 2, false );
+        defl.setInput( byteArray, ARRAY_SIZE, 0, ARRAY_SIZE );
+        while( !defl.needsInput() ) {
+            defl.deflate( outPutBuf );
+        }
+        defl.finish();
+        while( !defl.finished() ) {
+            defl.deflate( outPutBuf );
+        }
+        CPPUNIT_ASSERT_EQUAL( totalOut, defl.getBytesWritten() );
+        defl.end();
+    }
+
+    {
+        outPutBuf.assign( outPutBuf.size(), 0 );
+        Deflater defl( 2, true );
+        defl.setInput( byteArray, ARRAY_SIZE, 0, ARRAY_SIZE );
+        while( !defl.needsInput() ) {
+            defl.deflate( outPutBuf );
+        }
+        defl.finish();
+        while( !defl.finished() ) {
+            defl.deflate( outPutBuf );
+        }
+        CPPUNIT_ASSERT_MESSAGE( "getBytesWritten() should not be equal comparing two Deflaters with different header options.",
+                                defl.getBytesWritten() != totalOut );
+        defl.end();
+    }
+
+    std::vector<unsigned char> outPutInf( 500 );
+    Inflater infl( true );
+    while( !infl.finished() ) {
+        if( infl.needsInput() ) {
+            infl.setInput( outPutBuf );
+        }
+        infl.inflate( outPutInf );
+    }
+    for( std::size_t i = 0; i < ARRAY_SIZE; i++ ) {
+        CPPUNIT_ASSERT_EQUAL( byteArray[i], outPutInf[i] );
+    }
+    CPPUNIT_ASSERT_EQUAL_MESSAGE( "final decompressed data contained more bytes than original - constructorIZ",
+                                  0, (int)outPutInf[ARRAY_SIZE] );
+    infl.end();
+
+    {
+        Inflater infl( false );
+        outPutBuf.assign( outPutBuf.size(), 0 );
+        std::size_t r = 0;
+        try {
+            while( !infl.finished() ) {
+                if( infl.needsInput() ) {
+                    infl.setInput( outPutBuf );
+                }
+                infl.inflate( outPutInf );
+            }
+        } catch( DataFormatException e ) {
+            r = 1;
+        }
+        CPPUNIT_ASSERT_EQUAL_MESSAGE( "header option did not correspond", 1, (int)r );
+    }
+
+    Deflater boundDefl;
+
+    // testing boundaries
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "IllegalArgumentException not thrown when setting level to a number < 0.",
+        boundDefl.setLevel( -2 ),
+        IllegalArgumentException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "IllegalArgumentException not thrown when setting level to a number > 9.",
+        boundDefl.setLevel( 10 ),
+        IllegalArgumentException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testConstructorI() {
+
+    std::vector<unsigned char> byteArray( 100 );
+    for( std::size_t ix = 0; ix < 100; ++ix ) {
+        byteArray[ix] = ix + 1;
+    }
+
+    std::vector<unsigned char> outPutBuf( 500 );
+    Deflater defl( 3 );
+
+    defl.setInput( byteArray );
+    while( !defl.needsInput() ) {
+        defl.deflate( outPutBuf );
+    }
+
+    defl.finish();
+    while( !defl.finished() ) {
+        defl.deflate( outPutBuf );
+    }
+
+    long long totalOut = defl.getBytesWritten();
+    defl.end();
+
+    // test to see if the compression ratio is the same as setting the level
+    // on a deflater
+    outPutBuf.assign( outPutBuf.size(), 0 );
+    Deflater defl2;
+    defl2.setLevel( 3 );
+    defl2.setInput( byteArray );
+    while( !defl2.needsInput() ) {
+        defl2.deflate( outPutBuf );
+    }
+
+    defl2.finish();
+    while( !defl2.finished() ) {
+        defl2.deflate( outPutBuf );
+    }
+    CPPUNIT_ASSERT_EQUAL( totalOut, defl2.getBytesWritten() );
+    defl2.end();
+
+    Deflater boundDefl;
+
+    // testing boundaries
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "IllegalArgumentException not thrown when setting level to a number < 0.",
+        boundDefl.setLevel( -2 ),
+        IllegalArgumentException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "IllegalArgumentException not thrown when setting level to a number > 9.",
+        boundDefl.setLevel( 10 ),
+        IllegalArgumentException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::helperEndTest( Deflater& defl, const std::string& desc ) {
+
+    // Help tests for test_end() and test_reset().
+    unsigned char byteArray[] = { 5, 2, 3, 7, 8 };
+
+    // Methods where we expect IllegalStateException or NullPointerException
+    // to be thrown
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        std::string() + "defl.getBytesWritten() can still be used after " + desc
+                      + " is called in test_" + desc,
+        defl.getBytesWritten(),
+        IllegalStateException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        std::string() + "defl.getAdler() can still be used after " + desc
+                      + " is called in test_" + desc,
+        defl.getAdler(),
+        IllegalStateException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        std::string() + "defl.getBytesRead() can still be used after " + desc
+                      + " is called in test_" + desc,
+        defl.getBytesRead(),
+        IllegalStateException );
+
+    unsigned char dict[] = {'a', 'b', 'c'};
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        std::string() + "defl.setDictionary() can still be used after " + desc
+                      + " is called in test_" + desc,
+        defl.setDictionary( dict, 3, 0, 3 ),
+        IllegalStateException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        std::string() + "defl.deflate() can still be used after " + desc
+                      + " is called in test_" + desc,
+        defl.deflate( byteArray, 5, 0, 5 ),
+        IllegalStateException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        std::string() + "defl.setInput() can still be used after " + desc
+                      + " is called in test_" + desc,
+        defl.setInput( byteArray, 5, 0, 5 ),
+        IllegalStateException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        std::string() + "defl.reset() can still be used after " + desc
+                      + " is called in test_" + desc,
+        defl.reset(),
+        IllegalStateException );
+
+    // Methods that should be allowed to be called after end() is called
+    defl.needsInput();
+    defl.setStrategy( 1 );
+    defl.setLevel( 1 );
+    defl.end();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testInitialState() {
+
+    Deflater inf;
+    CPPUNIT_ASSERT_EQUAL( false, inf.finished() );
+    CPPUNIT_ASSERT_EQUAL( 0LL, inf.getBytesRead() );
+    CPPUNIT_ASSERT_EQUAL( 0LL, inf.getBytesWritten() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testGetBytesRead() {
+
+    Deflater def;
+    CPPUNIT_ASSERT_EQUAL( 0LL, def.getBytesRead() );
+    CPPUNIT_ASSERT_EQUAL( 0LL, def.getBytesWritten() );
+
+    // Encode a String into bytes
+    std::string inputString = "blahblahblah??";
+
+    // Compress the bytes
+    std::vector<unsigned char> output( 100 );
+
+    def.setInput( (unsigned char*)inputString.c_str(), inputString.size(), 0, inputString.size() );
+    def.finish();
+
+    long long compressedDataLength = (long long)def.deflate( output );
+
+    CPPUNIT_ASSERT_EQUAL( 14LL, def.getBytesRead() );
+    CPPUNIT_ASSERT_EQUAL( compressedDataLength, def.getBytesWritten() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testGetBytesWritten() {
+
+    Deflater def;
+    CPPUNIT_ASSERT_EQUAL( 0LL, def.getBytesRead() );
+    CPPUNIT_ASSERT_EQUAL( 0LL, def.getBytesWritten() );
+
+    // Encode a String into bytes
+    std::string inputString = "blahblahblah??";
+
+    // Compress the bytes
+    std::vector<unsigned char> output( 100 );
+
+    def.setInput( (unsigned char*)inputString.c_str(), inputString.size(), 0, inputString.size() );
+    def.finish();
+
+    long long compressedDataLength = (long long)def.deflate( output );
+
+    CPPUNIT_ASSERT_EQUAL( 14LL, def.getBytesRead() );
+    CPPUNIT_ASSERT_EQUAL( compressedDataLength, def.getBytesWritten() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void DeflaterTest::testDeflateBeforeSetInput() {
+
+    Deflater deflater;
+    deflater.finish();
+
+    std::vector<unsigned char> buffer( 1024 );
+
+    CPPUNIT_ASSERT_EQUAL( 8, (int)deflater.deflate( buffer ) );
+
+    unsigned char expectedBytes[] = { 120, -100, 3, 0, 0, 0, 0, 1 };
+
+    for( int i = 0; i < 8; i++ ) {
+        CPPUNIT_ASSERT_EQUAL( expectedBytes[i], buffer[i] );
+    }
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterTest.h?rev=910686&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterTest.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterTest.h Tue Feb 16 20:54:08 2010
@@ -0,0 +1,91 @@
+/*
+ * 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_DEFLATERTEST_H_
+#define _DECAF_UTIL_ZIP_DEFLATERTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/util/zip/Deflater.h>
+
+namespace decaf {
+namespace util {
+namespace zip {
+
+    class DeflaterTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( DeflaterTest );
+        CPPUNIT_TEST( testDeflateVector );
+        CPPUNIT_TEST( testDeflateArray );
+        CPPUNIT_TEST( testEnd );
+        CPPUNIT_TEST( testInitialState );
+        CPPUNIT_TEST( testDeflateBeforeSetInput );
+        CPPUNIT_TEST( testGetBytesRead );
+        CPPUNIT_TEST( testGetBytesWritten );
+        CPPUNIT_TEST( testFinish );
+        CPPUNIT_TEST( testFinished );
+        CPPUNIT_TEST( testGetAdler );
+        CPPUNIT_TEST( testNeedsInput );
+        CPPUNIT_TEST( testReset );
+        CPPUNIT_TEST( testConstructor );
+        CPPUNIT_TEST( testConstructorI );
+        CPPUNIT_TEST( testConstructorIB );
+        CPPUNIT_TEST( testSetDictionaryVector );
+        CPPUNIT_TEST( testSetDictionaryBIII );
+        CPPUNIT_TEST( testSetInputVector );
+        CPPUNIT_TEST( testSetInputBIII );
+        CPPUNIT_TEST( testSetLevel );
+        CPPUNIT_TEST( testSetStrategy );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        DeflaterTest();
+        virtual ~DeflaterTest();
+
+        void testDeflateVector();
+        void testDeflateArray();
+        void testEnd();
+        void testInitialState();
+        void testDeflateBeforeSetInput();
+        void testGetBytesRead();
+        void testGetBytesWritten();
+        void testFinish();
+        void testFinished();
+        void testGetAdler();
+        void testNeedsInput();
+        void testReset();
+        void testConstructor();
+        void testConstructorI();
+        void testConstructorIB();
+        void testSetDictionaryVector();
+        void testSetDictionaryBIII();
+        void testSetInputVector();
+        void testSetInputBIII();
+        void testSetLevel();
+        void testSetStrategy();
+
+    private:
+
+        void helperEndTest( Deflater& defl, const std::string& testName );
+
+    };
+
+}}}
+
+#endif /* _DECAF_UTIL_ZIP_DEFLATERTEST_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/zip/DeflaterTest.h
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message