GZipDecoderTest.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #endif // ENABLE_MESSAGE_DIGEST
  11. namespace aria2 {
  12. class GZipDecoderTest:public CppUnit::TestFixture {
  13. CPPUNIT_TEST_SUITE(GZipDecoderTest);
  14. CPPUNIT_TEST(testDecode);
  15. CPPUNIT_TEST_SUITE_END();
  16. public:
  17. void setUp() {}
  18. void tearDown() {}
  19. void testDecode();
  20. };
  21. CPPUNIT_TEST_SUITE_REGISTRATION(GZipDecoderTest);
  22. void GZipDecoderTest::testDecode()
  23. {
  24. GZipDecoder decoder;
  25. decoder.init();
  26. std::string outfile(A2_TEST_OUT_DIR"/aria2_GZipDecoderTest_testDecode");
  27. char buf[4096];
  28. std::ifstream in(A2_TEST_DIR"/gzip_decode_test.gz", std::ios::binary);
  29. std::ofstream out(outfile.c_str(), std::ios::binary);
  30. while(in) {
  31. in.read(buf, sizeof(buf));
  32. std::string r = decoder.decode
  33. (reinterpret_cast<const unsigned char*>(buf), in.gcount());
  34. out.write(r.data(), r.size());
  35. }
  36. CPPUNIT_ASSERT(decoder.finished());
  37. decoder.release();
  38. out.close();
  39. #ifdef ENABLE_MESSAGE_DIGEST
  40. CPPUNIT_ASSERT_EQUAL(std::string("8b577b33c0411b2be9d4fa74c7402d54a8d21f96"),
  41. fileHexDigest(MessageDigest::sha1(), outfile));
  42. #endif // ENABLE_MESSAGE_DIGEST
  43. }
  44. } // namespace aria2