GZipDecoderTest.cc 1.2 KB

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