forked from ydb-platform/nbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_buffer_ut.cpp
67 lines (57 loc) · 1.72 KB
/
block_buffer_ut.cpp
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
64
65
66
67
#include "block_buffer.h"
#include <library/cpp/testing/unittest/registar.h>
#include <util/random/random.h>
namespace NCloud::NFileStore::NStorage {
////////////////////////////////////////////////////////////////////////////////
Y_UNIT_TEST_SUITE(TBlockBufferTest)
{
struct TTest
{
TByteRange Range;
TByteRange AlignedRange;
TString Data;
IBlockBufferPtr BlockBuffer;
TString Out;
TTest(
ui64 offset,
ui64 length,
ui32 blockSize,
ui64 fileSize)
: Range(offset, length, blockSize)
, AlignedRange(Range.AlignedSuperRange())
{
Data.ReserveAndResize(AlignedRange.Length);
for (ui32 i = 0; i < Data.Size(); ++i) {
Data[i] = 'a' + RandomNumber<ui32>('z' - 'a' + 1);
}
BlockBuffer = CreateBlockBuffer(AlignedRange, Data);
CopyFileData(
"logtag",
Range,
AlignedRange,
fileSize,
*BlockBuffer,
&Out);
}
};
Y_UNIT_TEST(ShouldCopyFileDataAligned)
{
TTest test(100_KB, 8_KB, 4_KB, 200_KB);
UNIT_ASSERT_VALUES_EQUAL(test.Data, test.Out);
}
Y_UNIT_TEST(ShouldCopyFileDataUnaligned)
{
TTest test(101_KB, 10_KB, 4_KB, 107_KB);
UNIT_ASSERT_VALUES_EQUAL(
test.Data.substr(1_KB, 6_KB),
test.Out);
}
Y_UNIT_TEST(ShouldCopyFileDataUnalignedSmall)
{
TTest test(101_KB, 10_KB, 4_KB, 103_KB);
UNIT_ASSERT_VALUES_EQUAL(
test.Data.substr(1_KB, 2_KB),
test.Out);
}
}
} // namespace NCloud::NFileStore::NStorage