GZipDecoderTest.cc 1.3 KB

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