bzip2_ut.cpp 882 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "bzip2.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <util/stream/file.h>
  4. #include <util/system/tempfile.h>
  5. #define ZDATA "./zdata"
  6. Y_UNIT_TEST_SUITE(TBZipTest) {
  7. static const TString data = "8s7d5vc6s5vc67sa4c65ascx6asd4xcv76adsfxv76s";
  8. Y_UNIT_TEST(TestCompress) {
  9. TUnbufferedFileOutput o(ZDATA);
  10. TBZipCompress c(&o);
  11. c.Write(data.data(), data.size());
  12. c.Finish();
  13. o.Finish();
  14. }
  15. Y_UNIT_TEST(TestDecompress) {
  16. TTempFile tmp(ZDATA);
  17. {
  18. TUnbufferedFileInput i(ZDATA);
  19. TBZipDecompress d(&i);
  20. UNIT_ASSERT_EQUAL(d.ReadLine(), data);
  21. }
  22. }
  23. Y_UNIT_TEST(TestCorrupted) {
  24. TMemoryInput i("blablabla", 10);
  25. TBZipDecompress d(&i);
  26. UNIT_ASSERT_EXCEPTION(d.ReadLine(), TBZipDecompressError);
  27. }
  28. }
  29. #undef ZDATA