aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/multi_ut.cpp
blob: 7f57c937ae45ea821a87f58059ced7c263e96991 (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
42
43
44
45
46
47
48
49
50
#include "mem.h"
#include "multi.h"
#include <library/cpp/testing/unittest/registar.h>

Y_UNIT_TEST_SUITE(TestMultiInput) {
    struct TTestCase {
        TMemoryInput Input1;
        TMemoryInput Input2;
        TMultiInput MultiInput;
        TTestCase(const TStringBuf in1, const TStringBuf in2)
            : Input1(in1)
            , Input2(in2)
            , MultiInput(&Input1, &Input2)
        {
        }
        void TestReadToResult(char c, size_t expectedRetval,
                              const TString& expectedValue,
                              const TString& initValue = "") {
            TString t = initValue;
            UNIT_ASSERT_VALUES_EQUAL(MultiInput.ReadTo(t, c), expectedRetval);
            UNIT_ASSERT_VALUES_EQUAL(t, expectedValue);
        }
    };

    Y_UNIT_TEST(TestReadTo) {
        TString t;

        TTestCase simpleCase("0123456789abc", "defghijk");
        simpleCase.TestReadToResult('7', 8, "0123456");
        simpleCase.TestReadToResult('f', 8, "89abcde");
        simpleCase.TestReadToResult('z', 5, "ghijk");
    }

    Y_UNIT_TEST(TestReadToBetweenStreams) {
        TTestCase case1("0123456789abc", "defghijk");
        case1.TestReadToResult('c', 13, "0123456789ab");
        case1.TestReadToResult('k', 8, "defghij");
        case1.TestReadToResult('z', 0, "TRASH", "TRASH");

        TTestCase case2("0123456789abc", "defghijk");
        case2.TestReadToResult('d', 14, "0123456789abc");
        case2.TestReadToResult('j', 6, "efghi");
        case2.TestReadToResult('k', 1, "", "TRASH");

        TTestCase case3("0123456789abc", "defghijk");
        case3.TestReadToResult('e', 15, "0123456789abcd");
        case3.TestReadToResult('j', 5, "fghi");
        case3.TestReadToResult('k', 1, "", "TRASH");
    }
} // Y_UNIT_TEST_SUITE(TestMultiInput)