diff options
Diffstat (limited to 'Swiften/Compress')
-rw-r--r-- | Swiften/Compress/UnitTest/ZLibCompressorTest.cpp | 34 | ||||
-rw-r--r-- | Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp | 112 | ||||
-rw-r--r-- | Swiften/Compress/ZLibCodecompressor.cpp | 48 | ||||
-rw-r--r-- | Swiften/Compress/ZLibCodecompressor.h | 20 | ||||
-rw-r--r-- | Swiften/Compress/ZLibCodecompressor_Private.h | 6 | ||||
-rw-r--r-- | Swiften/Compress/ZLibCompressor.cpp | 10 | ||||
-rw-r--r-- | Swiften/Compress/ZLibCompressor.h | 16 | ||||
-rw-r--r-- | Swiften/Compress/ZLibDecompressor.cpp | 10 | ||||
-rw-r--r-- | Swiften/Compress/ZLibDecompressor.h | 12 | ||||
-rw-r--r-- | Swiften/Compress/ZLibException.h | 8 |
10 files changed, 138 insertions, 138 deletions
diff --git a/Swiften/Compress/UnitTest/ZLibCompressorTest.cpp b/Swiften/Compress/UnitTest/ZLibCompressorTest.cpp index 584a4f7..ca99201 100644 --- a/Swiften/Compress/UnitTest/ZLibCompressorTest.cpp +++ b/Swiften/Compress/UnitTest/ZLibCompressorTest.cpp @@ -17,28 +17,28 @@ using namespace Swift; class ZLibCompressorTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ZLibCompressorTest); - CPPUNIT_TEST(testProcess); - CPPUNIT_TEST(testProcess_Twice); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(ZLibCompressorTest); + CPPUNIT_TEST(testProcess); + CPPUNIT_TEST(testProcess_Twice); + CPPUNIT_TEST_SUITE_END(); - public: - ZLibCompressorTest() {} + public: + ZLibCompressorTest() {} - void testProcess() { - ZLibCompressor testling; - SafeByteArray result = testling.process(createSafeByteArray("foo")); + void testProcess() { + ZLibCompressor testling; + SafeByteArray result = testling.process(createSafeByteArray("foo")); - CPPUNIT_ASSERT_EQUAL(createSafeByteArray("\x78\xda\x4a\xcb\xcf\x07\x00\x00\x00\xff\xff", 11), result); - } + CPPUNIT_ASSERT_EQUAL(createSafeByteArray("\x78\xda\x4a\xcb\xcf\x07\x00\x00\x00\xff\xff", 11), result); + } - void testProcess_Twice() { - ZLibCompressor testling; - testling.process(createSafeByteArray("foo")); - SafeByteArray result = testling.process(createSafeByteArray("bar")); + void testProcess_Twice() { + ZLibCompressor testling; + testling.process(createSafeByteArray("foo")); + SafeByteArray result = testling.process(createSafeByteArray("bar")); - CPPUNIT_ASSERT_EQUAL(createSafeByteArray("\x4a\x4a\x2c\x02\x00\x00\x00\xff\xff",9), result); - } + CPPUNIT_ASSERT_EQUAL(createSafeByteArray("\x4a\x4a\x2c\x02\x00\x00\x00\xff\xff",9), result); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ZLibCompressorTest); diff --git a/Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp b/Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp index 7e57676..5873c0e 100644 --- a/Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp +++ b/Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp @@ -19,62 +19,62 @@ using namespace Swift; class ZLibDecompressorTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ZLibDecompressorTest); - CPPUNIT_TEST(testProcess); - CPPUNIT_TEST(testProcess_Twice); - CPPUNIT_TEST(testProcess_Invalid); - CPPUNIT_TEST(testProcess_Huge); - CPPUNIT_TEST(testProcess_ChunkSize); - CPPUNIT_TEST_SUITE_END(); - - public: - ZLibDecompressorTest() {} - - void testProcess() { - ZLibDecompressor testling; - SafeByteArray result = testling.process(createSafeByteArray("\x78\xda\x4a\xcb\xcf\x07\x00\x00\x00\xff\xff", 11)); - - CPPUNIT_ASSERT_EQUAL(createSafeByteArray("foo"), result); - } - - void testProcess_Twice() { - ZLibDecompressor testling; - testling.process(createSafeByteArray("\x78\xda\x4a\xcb\xcf\x07\x00\x00\x00\xff\xff", 11)); - SafeByteArray result = testling.process(createSafeByteArray("\x4a\x4a\x2c\x02\x00\x00\x00\xff\xff", 9)); - - CPPUNIT_ASSERT_EQUAL(createSafeByteArray("bar"), result); - } - - void testProcess_Invalid() { - ZLibDecompressor testling; - CPPUNIT_ASSERT_THROW(testling.process(createSafeByteArray("invalid")), ZLibException); - } - - void testProcess_Huge() { - std::vector<char> data; - data.reserve(2048); - for (unsigned int i = 0; i < 2048; ++i) { - data.push_back(static_cast<char>(i)); - } - SafeByteArray original(createSafeByteArray(&data[0], data.size())); - SafeByteArray compressed = ZLibCompressor().process(original); - SafeByteArray decompressed = ZLibDecompressor().process(compressed); - - CPPUNIT_ASSERT_EQUAL(original, decompressed); - } - - void testProcess_ChunkSize() { - std::vector<char> data; - data.reserve(1024); - for (unsigned int i = 0; i < 1024; ++i) { - data.push_back(static_cast<char>(i)); - } - SafeByteArray original(createSafeByteArray(&data[0], data.size())); - SafeByteArray compressed = ZLibCompressor().process(original); - SafeByteArray decompressed = ZLibDecompressor().process(compressed); - - CPPUNIT_ASSERT_EQUAL(original, decompressed); - } + CPPUNIT_TEST_SUITE(ZLibDecompressorTest); + CPPUNIT_TEST(testProcess); + CPPUNIT_TEST(testProcess_Twice); + CPPUNIT_TEST(testProcess_Invalid); + CPPUNIT_TEST(testProcess_Huge); + CPPUNIT_TEST(testProcess_ChunkSize); + CPPUNIT_TEST_SUITE_END(); + + public: + ZLibDecompressorTest() {} + + void testProcess() { + ZLibDecompressor testling; + SafeByteArray result = testling.process(createSafeByteArray("\x78\xda\x4a\xcb\xcf\x07\x00\x00\x00\xff\xff", 11)); + + CPPUNIT_ASSERT_EQUAL(createSafeByteArray("foo"), result); + } + + void testProcess_Twice() { + ZLibDecompressor testling; + testling.process(createSafeByteArray("\x78\xda\x4a\xcb\xcf\x07\x00\x00\x00\xff\xff", 11)); + SafeByteArray result = testling.process(createSafeByteArray("\x4a\x4a\x2c\x02\x00\x00\x00\xff\xff", 9)); + + CPPUNIT_ASSERT_EQUAL(createSafeByteArray("bar"), result); + } + + void testProcess_Invalid() { + ZLibDecompressor testling; + CPPUNIT_ASSERT_THROW(testling.process(createSafeByteArray("invalid")), ZLibException); + } + + void testProcess_Huge() { + std::vector<char> data; + data.reserve(2048); + for (unsigned int i = 0; i < 2048; ++i) { + data.push_back(static_cast<char>(i)); + } + SafeByteArray original(createSafeByteArray(&data[0], data.size())); + SafeByteArray compressed = ZLibCompressor().process(original); + SafeByteArray decompressed = ZLibDecompressor().process(compressed); + + CPPUNIT_ASSERT_EQUAL(original, decompressed); + } + + void testProcess_ChunkSize() { + std::vector<char> data; + data.reserve(1024); + for (unsigned int i = 0; i < 1024; ++i) { + data.push_back(static_cast<char>(i)); + } + SafeByteArray original(createSafeByteArray(&data[0], data.size())); + SafeByteArray compressed = ZLibCompressor().process(original); + SafeByteArray decompressed = ZLibDecompressor().process(compressed); + + CPPUNIT_ASSERT_EQUAL(original, decompressed); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ZLibDecompressorTest); diff --git a/Swiften/Compress/ZLibCodecompressor.cpp b/Swiften/Compress/ZLibCodecompressor.cpp index 7c413b7..fd6d3b0 100644 --- a/Swiften/Compress/ZLibCodecompressor.cpp +++ b/Swiften/Compress/ZLibCodecompressor.cpp @@ -23,36 +23,36 @@ static const size_t CHUNK_SIZE = 1024; // If you change this, also change the un ZLibCodecompressor::ZLibCodecompressor() : p(boost::make_shared<Private>()) { - memset(&p->stream, 0, sizeof(z_stream)); - p->stream.zalloc = Z_NULL; - p->stream.zfree = Z_NULL; - p->stream.opaque = Z_NULL; + memset(&p->stream, 0, sizeof(z_stream)); + p->stream.zalloc = Z_NULL; + p->stream.zfree = Z_NULL; + p->stream.opaque = Z_NULL; } ZLibCodecompressor::~ZLibCodecompressor() { } SafeByteArray ZLibCodecompressor::process(const SafeByteArray& input) { - SafeByteArray output; - p->stream.avail_in = static_cast<unsigned int>(input.size()); - p->stream.next_in = reinterpret_cast<Bytef*>(const_cast<unsigned char*>(vecptr(input))); - size_t outputPosition = 0; - do { - output.resize(outputPosition + CHUNK_SIZE); - p->stream.avail_out = CHUNK_SIZE; - p->stream.next_out = reinterpret_cast<Bytef*>(vecptr(output) + outputPosition); - int result = processZStream(); - if (result != Z_OK && result != Z_BUF_ERROR) { - throw ZLibException(/* p->stream.msg */); - } - outputPosition += CHUNK_SIZE; - } - while (p->stream.avail_out == 0); - if (p->stream.avail_in != 0) { - throw ZLibException(); - } - output.resize(outputPosition - p->stream.avail_out); - return output; + SafeByteArray output; + p->stream.avail_in = static_cast<unsigned int>(input.size()); + p->stream.next_in = reinterpret_cast<Bytef*>(const_cast<unsigned char*>(vecptr(input))); + size_t outputPosition = 0; + do { + output.resize(outputPosition + CHUNK_SIZE); + p->stream.avail_out = CHUNK_SIZE; + p->stream.next_out = reinterpret_cast<Bytef*>(vecptr(output) + outputPosition); + int result = processZStream(); + if (result != Z_OK && result != Z_BUF_ERROR) { + throw ZLibException(/* p->stream.msg */); + } + outputPosition += CHUNK_SIZE; + } + while (p->stream.avail_out == 0); + if (p->stream.avail_in != 0) { + throw ZLibException(); + } + output.resize(outputPosition - p->stream.avail_out); + return output; } } diff --git a/Swiften/Compress/ZLibCodecompressor.h b/Swiften/Compress/ZLibCodecompressor.h index 3907258..253c34a 100644 --- a/Swiften/Compress/ZLibCodecompressor.h +++ b/Swiften/Compress/ZLibCodecompressor.h @@ -10,16 +10,16 @@ #include <Swiften/Base/SafeByteArray.h> namespace Swift { - class SWIFTEN_API ZLibCodecompressor { - public: - ZLibCodecompressor(); - virtual ~ZLibCodecompressor(); + class SWIFTEN_API ZLibCodecompressor { + public: + ZLibCodecompressor(); + virtual ~ZLibCodecompressor(); - SafeByteArray process(const SafeByteArray& data); - virtual int processZStream() = 0; + SafeByteArray process(const SafeByteArray& data); + virtual int processZStream() = 0; - protected: - struct Private; - boost::shared_ptr<Private> p; - }; + protected: + struct Private; + boost::shared_ptr<Private> p; + }; } diff --git a/Swiften/Compress/ZLibCodecompressor_Private.h b/Swiften/Compress/ZLibCodecompressor_Private.h index db761c3..2adc4b6 100644 --- a/Swiften/Compress/ZLibCodecompressor_Private.h +++ b/Swiften/Compress/ZLibCodecompressor_Private.h @@ -11,7 +11,7 @@ #include <Swiften/Compress/ZLibCodecompressor.h> namespace Swift { - struct ZLibCodecompressor::Private { - z_stream stream; - }; + struct ZLibCodecompressor::Private { + z_stream stream; + }; } diff --git a/Swiften/Compress/ZLibCompressor.cpp b/Swiften/Compress/ZLibCompressor.cpp index 8887c46..a2fef15 100644 --- a/Swiften/Compress/ZLibCompressor.cpp +++ b/Swiften/Compress/ZLibCompressor.cpp @@ -16,17 +16,17 @@ namespace Swift { ZLibCompressor::ZLibCompressor() { - int result = deflateInit(&p->stream, COMPRESSION_LEVEL); - assert(result == Z_OK); - (void) result; + int result = deflateInit(&p->stream, COMPRESSION_LEVEL); + assert(result == Z_OK); + (void) result; } ZLibCompressor::~ZLibCompressor() { - deflateEnd(&p->stream); + deflateEnd(&p->stream); } int ZLibCompressor::processZStream() { - return deflate(&p->stream, Z_SYNC_FLUSH); + return deflate(&p->stream, Z_SYNC_FLUSH); } } diff --git a/Swiften/Compress/ZLibCompressor.h b/Swiften/Compress/ZLibCompressor.h index c92b8c0..59ebbb9 100644 --- a/Swiften/Compress/ZLibCompressor.h +++ b/Swiften/Compress/ZLibCompressor.h @@ -10,14 +10,14 @@ #include <Swiften/Compress/ZLibCodecompressor.h> namespace Swift { - class SWIFTEN_API ZLibCompressor : public ZLibCodecompressor { - public: - ZLibCompressor(); - virtual ~ZLibCompressor(); + class SWIFTEN_API ZLibCompressor : public ZLibCodecompressor { + public: + ZLibCompressor(); + virtual ~ZLibCompressor(); - virtual int processZStream(); + virtual int processZStream(); - private: - static const int COMPRESSION_LEVEL = 9; - }; + private: + static const int COMPRESSION_LEVEL = 9; + }; } diff --git a/Swiften/Compress/ZLibDecompressor.cpp b/Swiften/Compress/ZLibDecompressor.cpp index 3024150..adc40c5 100644 --- a/Swiften/Compress/ZLibDecompressor.cpp +++ b/Swiften/Compress/ZLibDecompressor.cpp @@ -16,17 +16,17 @@ namespace Swift { ZLibDecompressor::ZLibDecompressor() { - int result = inflateInit(&p->stream); - assert(result == Z_OK); - (void) result; + int result = inflateInit(&p->stream); + assert(result == Z_OK); + (void) result; } ZLibDecompressor::~ZLibDecompressor() { - inflateEnd(&p->stream); + inflateEnd(&p->stream); } int ZLibDecompressor::processZStream() { - return inflate(&p->stream, Z_SYNC_FLUSH); + return inflate(&p->stream, Z_SYNC_FLUSH); } } diff --git a/Swiften/Compress/ZLibDecompressor.h b/Swiften/Compress/ZLibDecompressor.h index b758be3..9c2dd4f 100644 --- a/Swiften/Compress/ZLibDecompressor.h +++ b/Swiften/Compress/ZLibDecompressor.h @@ -10,11 +10,11 @@ #include <Swiften/Compress/ZLibCodecompressor.h> namespace Swift { - class SWIFTEN_API ZLibDecompressor : public ZLibCodecompressor { - public: - ZLibDecompressor(); - virtual ~ZLibDecompressor(); + class SWIFTEN_API ZLibDecompressor : public ZLibCodecompressor { + public: + ZLibDecompressor(); + virtual ~ZLibDecompressor(); - virtual int processZStream(); - }; + virtual int processZStream(); + }; } diff --git a/Swiften/Compress/ZLibException.h b/Swiften/Compress/ZLibException.h index e73bcec..2201e62 100644 --- a/Swiften/Compress/ZLibException.h +++ b/Swiften/Compress/ZLibException.h @@ -7,8 +7,8 @@ #pragma once namespace Swift { - class ZLibException { - public: - ZLibException() {} - }; + class ZLibException { + public: + ZLibException() {} + }; } |