summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Compress')
-rw-r--r--Swiften/Compress/UnitTest/ZLibCompressorTest.cpp15
-rw-r--r--Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp33
-rw-r--r--Swiften/Compress/ZLibCodecompressor.cpp15
-rw-r--r--Swiften/Compress/ZLibCodecompressor.h9
-rw-r--r--Swiften/Compress/ZLibCompressor.cpp4
-rw-r--r--Swiften/Compress/ZLibCompressor.h6
-rw-r--r--Swiften/Compress/ZLibDecompressor.cpp4
-rw-r--r--Swiften/Compress/ZLibDecompressor.h6
-rw-r--r--Swiften/Compress/ZLibException.h6
9 files changed, 48 insertions, 50 deletions
diff --git a/Swiften/Compress/UnitTest/ZLibCompressorTest.cpp b/Swiften/Compress/UnitTest/ZLibCompressorTest.cpp
index 0b2fa5a..1de9322 100644
--- a/Swiften/Compress/UnitTest/ZLibCompressorTest.cpp
+++ b/Swiften/Compress/UnitTest/ZLibCompressorTest.cpp
@@ -4,12 +4,13 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "Swiften/Base/ByteArray.h"
+#include <Swiften/Base/SafeByteArray.h>
+#include <QA/Checker/IO.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include "Swiften/Compress/ZLibCompressor.h"
+#include <Swiften/Compress/ZLibCompressor.h>
using namespace Swift;
@@ -26,17 +27,17 @@ class ZLibCompressorTest : public CppUnit::TestFixture
void testProcess() {
ZLibCompressor testling;
- ByteArray result = testling.process("foo");
+ SafeByteArray result = testling.process(createSafeByteArray("foo"));
- CPPUNIT_ASSERT_EQUAL(ByteArray("\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("foo");
- ByteArray result = testling.process("bar");
+ testling.process(createSafeByteArray("foo"));
+ SafeByteArray result = testling.process(createSafeByteArray("bar"));
- CPPUNIT_ASSERT_EQUAL(ByteArray("\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);
}
};
diff --git a/Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp b/Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp
index 3ee5c4f..906c2dd 100644
--- a/Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp
+++ b/Swiften/Compress/UnitTest/ZLibDecompressorTest.cpp
@@ -4,14 +4,15 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "Swiften/Base/ByteArray.h"
+#include <Swiften/Base/ByteArray.h>
+#include <QA/Checker/IO.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include "Swiften/Compress/ZLibDecompressor.h"
-#include "Swiften/Compress/ZLibCompressor.h"
-#include "Swiften/Compress/ZLibException.h"
+#include <Swiften/Compress/ZLibDecompressor.h>
+#include <Swiften/Compress/ZLibCompressor.h>
+#include <Swiften/Compress/ZLibException.h>
using namespace Swift;
@@ -31,22 +32,22 @@ class ZLibDecompressorTest : public CppUnit::TestFixture
void testProcess() {
ZLibDecompressor testling;
- ByteArray result = testling.process(ByteArray("\x78\xda\x4a\xcb\xcf\x07\x00\x00\x00\xff\xff", 11));
+ SafeByteArray result = testling.process(createSafeByteArray("\x78\xda\x4a\xcb\xcf\x07\x00\x00\x00\xff\xff", 11));
- CPPUNIT_ASSERT_EQUAL(ByteArray("foo"), result);
+ CPPUNIT_ASSERT_EQUAL(createSafeByteArray("foo"), result);
}
void testProcess_Twice() {
ZLibDecompressor testling;
- testling.process(ByteArray("\x78\xda\x4a\xcb\xcf\x07\x00\x00\x00\xff\xff", 11));
- ByteArray result = testling.process(ByteArray("\x4a\x4a\x2c\x02\x00\x00\x00\xff\xff", 9));
+ 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(ByteArray("bar"), result);
+ CPPUNIT_ASSERT_EQUAL(createSafeByteArray("bar"), result);
}
void testProcess_Invalid() {
ZLibDecompressor testling;
- CPPUNIT_ASSERT_THROW(testling.process(ByteArray("invalid")), ZLibException);
+ CPPUNIT_ASSERT_THROW(testling.process(createSafeByteArray("invalid")), ZLibException);
}
void testProcess_Huge() {
@@ -55,9 +56,9 @@ class ZLibDecompressorTest : public CppUnit::TestFixture
for (unsigned int i = 0; i < 2048; ++i) {
data.push_back(static_cast<char>(i));
}
- ByteArray original(&data[0], data.size());
- ByteArray compressed = ZLibCompressor().process(original);
- ByteArray decompressed = ZLibDecompressor().process(compressed);
+ SafeByteArray original(createSafeByteArray(&data[0], data.size()));
+ SafeByteArray compressed = ZLibCompressor().process(original);
+ SafeByteArray decompressed = ZLibDecompressor().process(compressed);
CPPUNIT_ASSERT_EQUAL(original, decompressed);
}
@@ -68,9 +69,9 @@ class ZLibDecompressorTest : public CppUnit::TestFixture
for (unsigned int i = 0; i < 1024; ++i) {
data.push_back(static_cast<char>(i));
}
- ByteArray original(&data[0], data.size());
- ByteArray compressed = ZLibCompressor().process(original);
- ByteArray decompressed = ZLibDecompressor().process(compressed);
+ SafeByteArray original(createSafeByteArray(&data[0], data.size()));
+ SafeByteArray compressed = ZLibCompressor().process(original);
+ SafeByteArray decompressed = ZLibDecompressor().process(compressed);
CPPUNIT_ASSERT_EQUAL(original, decompressed);
}
diff --git a/Swiften/Compress/ZLibCodecompressor.cpp b/Swiften/Compress/ZLibCodecompressor.cpp
index c093fb3..0869d6b 100644
--- a/Swiften/Compress/ZLibCodecompressor.cpp
+++ b/Swiften/Compress/ZLibCodecompressor.cpp
@@ -4,11 +4,12 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "Swiften/Compress/ZLibCodecompressor.h"
+#include <Swiften/Compress/ZLibCodecompressor.h>
#include <cassert>
+#include <string.h>
-#include "Swiften/Compress/ZLibException.h"
+#include <Swiften/Compress/ZLibException.h>
namespace Swift {
@@ -24,15 +25,15 @@ ZLibCodecompressor::ZLibCodecompressor() {
ZLibCodecompressor::~ZLibCodecompressor() {
}
-ByteArray ZLibCodecompressor::process(const ByteArray& input) {
- ByteArray output;
- stream_.avail_in = input.getSize();
- stream_.next_in = reinterpret_cast<Bytef*>(const_cast<unsigned char*>(input.getData()));
+SafeByteArray ZLibCodecompressor::process(const SafeByteArray& input) {
+ SafeByteArray output;
+ stream_.avail_in = input.size();
+ stream_.next_in = reinterpret_cast<Bytef*>(const_cast<unsigned char*>(vecptr(input)));
int outputPosition = 0;
do {
output.resize(outputPosition + CHUNK_SIZE);
stream_.avail_out = CHUNK_SIZE;
- stream_.next_out = reinterpret_cast<Bytef*>(output.getData() + outputPosition);
+ stream_.next_out = reinterpret_cast<Bytef*>(vecptr(output) + outputPosition);
int result = processZStream();
if (result != Z_OK && result != Z_BUF_ERROR) {
throw ZLibException(/* stream_.msg */);
diff --git a/Swiften/Compress/ZLibCodecompressor.h b/Swiften/Compress/ZLibCodecompressor.h
index 289704d..93babf0 100644
--- a/Swiften/Compress/ZLibCodecompressor.h
+++ b/Swiften/Compress/ZLibCodecompressor.h
@@ -4,12 +4,11 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFTEN_ZLibCodecompressor_H
-#define SWIFTEN_ZLibCodecompressor_H
+#pragma once
#include <zlib.h>
-#include "Swiften/Base/ByteArray.h"
+#include <Swiften/Base/SafeByteArray.h>
namespace Swift {
class ZLibCodecompressor {
@@ -17,12 +16,10 @@ namespace Swift {
ZLibCodecompressor();
virtual ~ZLibCodecompressor();
- ByteArray process(const ByteArray& data);
+ SafeByteArray process(const SafeByteArray& data);
virtual int processZStream() = 0;
protected:
z_stream stream_;
};
}
-
-#endif
diff --git a/Swiften/Compress/ZLibCompressor.cpp b/Swiften/Compress/ZLibCompressor.cpp
index 7e3116e..5d98e38 100644
--- a/Swiften/Compress/ZLibCompressor.cpp
+++ b/Swiften/Compress/ZLibCompressor.cpp
@@ -4,7 +4,9 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "Swiften/Compress/ZLibCompressor.h"
+#include <Swiften/Compress/ZLibCompressor.h>
+
+#include <cassert>
#pragma GCC diagnostic ignored "-Wold-style-cast"
diff --git a/Swiften/Compress/ZLibCompressor.h b/Swiften/Compress/ZLibCompressor.h
index 7fe5387..1add725 100644
--- a/Swiften/Compress/ZLibCompressor.h
+++ b/Swiften/Compress/ZLibCompressor.h
@@ -6,10 +6,8 @@
#pragma once
-#include <cassert>
-
-#include "Swiften/Compress/ZLibCodecompressor.h"
-#include "Swiften/Base/ByteArray.h"
+#include <Swiften/Compress/ZLibCodecompressor.h>
+#include <Swiften/Base/ByteArray.h>
namespace Swift {
class ZLibCompressor : public ZLibCodecompressor {
diff --git a/Swiften/Compress/ZLibDecompressor.cpp b/Swiften/Compress/ZLibDecompressor.cpp
index af7349b..ab954f4 100644
--- a/Swiften/Compress/ZLibDecompressor.cpp
+++ b/Swiften/Compress/ZLibDecompressor.cpp
@@ -4,7 +4,9 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "Swiften/Compress/ZLibDecompressor.h"
+#include <Swiften/Compress/ZLibDecompressor.h>
+
+#include <cassert>
#pragma GCC diagnostic ignored "-Wold-style-cast"
diff --git a/Swiften/Compress/ZLibDecompressor.h b/Swiften/Compress/ZLibDecompressor.h
index ec08a4f..67994d1 100644
--- a/Swiften/Compress/ZLibDecompressor.h
+++ b/Swiften/Compress/ZLibDecompressor.h
@@ -6,10 +6,8 @@
#pragma once
-#include <cassert>
-
-#include "Swiften/Compress/ZLibCodecompressor.h"
-#include "Swiften/Base/ByteArray.h"
+#include <Swiften/Compress/ZLibCodecompressor.h>
+#include <Swiften/Base/ByteArray.h>
namespace Swift {
class ZLibDecompressor : public ZLibCodecompressor {
diff --git a/Swiften/Compress/ZLibException.h b/Swiften/Compress/ZLibException.h
index 8e9fdb3..8e60aa3 100644
--- a/Swiften/Compress/ZLibException.h
+++ b/Swiften/Compress/ZLibException.h
@@ -4,8 +4,8 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFTEN_ZLIBEXCEPTION_H
-#define SWIFTEN_ZLIBEXCEPTION_H
+#pragma once
+
namespace Swift {
class ZLibException {
@@ -13,5 +13,3 @@ namespace Swift {
ZLibException() {}
};
}
-
-#endif