aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/streams/bzip2/bzip2_ut.cpp
blob: ac2646dbac6d1f188591937a66e125ec553b1f56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "bzip2.h"

#include <library/cpp/testing/unittest/registar.h>

#include <util/stream/file.h>
#include <util/system/tempfile.h>

#define ZDATA "./zdata"

Y_UNIT_TEST_SUITE(TBZipTest) {
    static const TString data = "8s7d5vc6s5vc67sa4c65ascx6asd4xcv76adsfxv76s";

    Y_UNIT_TEST(TestCompress) {
        TUnbufferedFileOutput o(ZDATA);
        TBZipCompress c(&o);

        c.Write(data.data(), data.size()); 
        c.Finish();
        o.Finish();
    }

    Y_UNIT_TEST(TestDecompress) {
        TTempFile tmp(ZDATA);

        {
            TUnbufferedFileInput i(ZDATA);
            TBZipDecompress d(&i);

            UNIT_ASSERT_EQUAL(d.ReadLine(), data);
        }
    }

    Y_UNIT_TEST(TestCorrupted) {
        TMemoryInput i("blablabla", 10);
        TBZipDecompress d(&i);

        UNIT_ASSERT_EXCEPTION(d.ReadLine(), TBZipDecompressError);
    }
}

#undef ZDATA