2020-07-08 05:56:27 +02:00
|
|
|
/*
|
2020-07-08 06:15:34 +02:00
|
|
|
* IXWebSocketPerMessageDeflateCodecTest.cpp
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2020 Machine Zone. All rights reserved.
|
|
|
|
*
|
|
|
|
* make build_test && build/test/ixwebsocket_unittest per-message-deflate-codec
|
2020-07-08 05:56:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "IXTest.h"
|
|
|
|
#include "catch.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
#include <ixwebsocket/IXWebSocketPerMessageDeflateCodec.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
using namespace ix;
|
|
|
|
|
|
|
|
namespace ix
|
|
|
|
{
|
2020-07-08 06:15:34 +02:00
|
|
|
std::string compressAndDecompress(const std::string& a)
|
2020-07-08 05:56:27 +02:00
|
|
|
{
|
2020-07-08 06:15:34 +02:00
|
|
|
std::string b, c;
|
2020-07-08 05:56:27 +02:00
|
|
|
|
2020-07-08 06:15:34 +02:00
|
|
|
WebSocketPerMessageDeflateCompressor compressor;
|
|
|
|
compressor.init(11, true);
|
|
|
|
compressor.compress(a, b);
|
2020-07-08 05:56:27 +02:00
|
|
|
|
2020-07-08 06:15:34 +02:00
|
|
|
WebSocketPerMessageDeflateDecompressor decompressor;
|
|
|
|
decompressor.init(11, true);
|
|
|
|
decompressor.decompress(b, c);
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
2020-07-08 05:56:27 +02:00
|
|
|
|
2020-07-08 03:17:44 +02:00
|
|
|
std::string compressAndDecompressVector(const std::string& a)
|
|
|
|
{
|
|
|
|
std::string b, c;
|
|
|
|
|
|
|
|
std::vector<uint8_t> vec(a.begin(), a.end());
|
|
|
|
|
|
|
|
WebSocketPerMessageDeflateCompressor compressor;
|
|
|
|
compressor.init(11, true);
|
|
|
|
compressor.compress(vec, b);
|
|
|
|
|
|
|
|
WebSocketPerMessageDeflateDecompressor decompressor;
|
|
|
|
decompressor.init(11, true);
|
|
|
|
decompressor.decompress(b, c);
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2020-07-08 06:15:34 +02:00
|
|
|
TEST_CASE("per-message-deflate-codec", "[zlib]")
|
|
|
|
{
|
2020-07-08 03:17:44 +02:00
|
|
|
SECTION("string api")
|
2020-07-08 06:15:34 +02:00
|
|
|
{
|
|
|
|
REQUIRE(compressAndDecompress("") == "");
|
|
|
|
REQUIRE(compressAndDecompress("foo") == "foo");
|
|
|
|
REQUIRE(compressAndDecompress("bar") == "bar");
|
|
|
|
REQUIRE(compressAndDecompress("asdcaseqw`21897dehqwed") == "asdcaseqw`21897dehqwed");
|
2020-07-08 19:39:46 +02:00
|
|
|
REQUIRE(compressAndDecompress("/usr/local/include/ixwebsocket/IXSocketAppleSSL.h") ==
|
|
|
|
"/usr/local/include/ixwebsocket/IXSocketAppleSSL.h");
|
2020-07-08 05:56:27 +02:00
|
|
|
}
|
2020-07-08 03:17:44 +02:00
|
|
|
|
|
|
|
SECTION("vector api")
|
|
|
|
{
|
|
|
|
REQUIRE(compressAndDecompressVector("") == "");
|
|
|
|
REQUIRE(compressAndDecompressVector("foo") == "foo");
|
|
|
|
REQUIRE(compressAndDecompressVector("bar") == "bar");
|
2020-07-08 19:39:46 +02:00
|
|
|
REQUIRE(compressAndDecompressVector("asdcaseqw`21897dehqwed") ==
|
|
|
|
"asdcaseqw`21897dehqwed");
|
|
|
|
REQUIRE(
|
|
|
|
compressAndDecompressVector("/usr/local/include/ixwebsocket/IXSocketAppleSSL.h") ==
|
|
|
|
"/usr/local/include/ixwebsocket/IXSocketAppleSSL.h");
|
2020-07-08 03:17:44 +02:00
|
|
|
}
|
2020-07-08 05:56:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ix
|