aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/streams/bzip2/bzip2_ut.cpp
blob: 69a98f296cd8da4f5357a53430ee1b12caba85b7 (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