blob: e980d05cf711ce48d154261d64dda94b4ef4243f (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
  | 
#include "aligned.h"
#include <library/cpp/testing/unittest/registar.h>
class TNastyInputStream: public IInputStream {
public:
    TNastyInputStream()
        : Pos_(0)
    {
    }
protected:
    size_t DoRead(void* buf, size_t len) override {
        if (len == 0) {
            return 0;
        }
        *static_cast<unsigned char*>(buf) = static_cast<unsigned char>(Pos_);
        ++Pos_;
        return 1;
    }
    size_t DoSkip(size_t len) override {
        if (len == 0) {
            return 0;
        }
        ++Pos_;
        return 1;
    }
private:
    size_t Pos_;
};
Y_UNIT_TEST_SUITE(TAlignedTest) {
    Y_UNIT_TEST(AlignInput) {
        TNastyInputStream input0;
        TAlignedInput alignedInput(&input0);
        char c = '\1';
        alignedInput.Align(2);
        alignedInput.ReadChar(c);
        UNIT_ASSERT_VALUES_EQUAL(c, '\x0');
        alignedInput.Align(2);
        alignedInput.ReadChar(c);
        UNIT_ASSERT_VALUES_EQUAL(c, '\x2');
        alignedInput.Align(4);
        alignedInput.ReadChar(c);
        UNIT_ASSERT_VALUES_EQUAL(c, '\x4');
        alignedInput.Align(16);
        alignedInput.ReadChar(c);
        UNIT_ASSERT_VALUES_EQUAL(c, '\x10');
        alignedInput.Align(128);
        alignedInput.ReadChar(c);
        UNIT_ASSERT_VALUES_EQUAL(c, '\x80');
    }
}
  |