2008-06-29 14:29:36 +00:00
|
|
|
#include "GZipDecoder.h"
|
2010-11-11 02:56:24 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
#include "TestUtil.h"
|
2008-06-29 14:29:36 +00:00
|
|
|
#include "Exception.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2014-04-16 23:36:19 +00:00
|
|
|
#include "MessageDigest.h"
|
2008-06-29 14:29:36 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
class GZipDecoderTest : public CppUnit::TestFixture {
|
2008-06-29 14:29:36 +00:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(GZipDecoderTest);
|
|
|
|
CPPUNIT_TEST(testDecode);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
2015-12-27 09:39:47 +00:00
|
|
|
|
2008-06-29 14:29:36 +00:00
|
|
|
public:
|
|
|
|
void setUp() {}
|
|
|
|
|
|
|
|
void tearDown() {}
|
|
|
|
|
|
|
|
void testDecode();
|
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(GZipDecoderTest);
|
|
|
|
|
|
|
|
void GZipDecoderTest::testDecode()
|
|
|
|
{
|
|
|
|
GZipDecoder decoder;
|
|
|
|
decoder.init();
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
std::string outfile(A2_TEST_OUT_DIR "/aria2_GZipDecoderTest_testDecode");
|
2008-06-29 14:29:36 +00:00
|
|
|
|
2015-06-21 09:04:30 +00:00
|
|
|
char buf[4_k];
|
2015-12-27 09:39:47 +00:00
|
|
|
std::ifstream in(A2_TEST_DIR "/gzip_decode_test.gz", std::ios::binary);
|
2009-02-13 11:28:42 +00:00
|
|
|
std::ofstream out(outfile.c_str(), std::ios::binary);
|
2015-12-27 09:39:47 +00:00
|
|
|
while (in) {
|
2008-06-29 14:29:36 +00:00
|
|
|
in.read(buf, sizeof(buf));
|
|
|
|
|
2015-12-27 09:39:47 +00:00
|
|
|
std::string r = decoder.decode(reinterpret_cast<const unsigned char*>(buf),
|
|
|
|
in.gcount());
|
2008-06-29 14:29:36 +00:00
|
|
|
|
|
|
|
out.write(r.data(), r.size());
|
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT(decoder.finished());
|
|
|
|
decoder.release();
|
|
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("8b577b33c0411b2be9d4fa74c7402d54a8d21f96"),
|
2013-07-02 16:13:13 +00:00
|
|
|
fileHexDigest(MessageDigest::sha1().get(), outfile));
|
2008-06-29 14:29:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace aria2
|