GZipDecoderTest.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "GZipDecoder.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <cppunit/extensions/HelperMacros.h>
  5. #include "TestUtil.h"
  6. #include "Exception.h"
  7. #include "util.h"
  8. #ifdef ENABLE_MESSAGE_DIGEST
  9. # include "MessageDigest.h"
  10. # include "MessageDigestHelper.h"
  11. #endif // ENABLE_MESSAGE_DIGEST
  12. namespace aria2 {
  13. class GZipDecoderTest:public CppUnit::TestFixture {
  14. CPPUNIT_TEST_SUITE(GZipDecoderTest);
  15. CPPUNIT_TEST(testDecode);
  16. CPPUNIT_TEST_SUITE_END();
  17. public:
  18. void setUp() {}
  19. void tearDown() {}
  20. void testDecode();
  21. };
  22. CPPUNIT_TEST_SUITE_REGISTRATION(GZipDecoderTest);
  23. void GZipDecoderTest::testDecode()
  24. {
  25. GZipDecoder decoder;
  26. decoder.init();
  27. std::string outfile("./aria2_GZipDecoderTest_testDecode");
  28. char buf[4096];
  29. std::ifstream in("gzip_decode_test.gz", std::ios::binary);
  30. std::ofstream out(outfile.c_str(), std::ios::binary);
  31. while(in) {
  32. in.read(buf, sizeof(buf));
  33. std::string r = decoder.decode
  34. (reinterpret_cast<const unsigned char*>(buf), in.gcount());
  35. out.write(r.data(), r.size());
  36. }
  37. CPPUNIT_ASSERT(decoder.finished());
  38. decoder.release();
  39. out.close();
  40. #ifdef ENABLE_MESSAGE_DIGEST
  41. CPPUNIT_ASSERT_EQUAL(std::string("8b577b33c0411b2be9d4fa74c7402d54a8d21f96"),
  42. fileHexDigest(MessageDigest::sha1(), outfile));
  43. #endif // ENABLE_MESSAGE_DIGEST
  44. }
  45. } // namespace aria2