summaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/mkql_string_util_ut.cpp
blob: ad94f3bd3505655897a7ec77be051156edba4ef8 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "mkql_alloc.h"
#include "mkql_string_util.h"

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

using namespace NYql;
using namespace NKikimr::NMiniKQL;

Y_UNIT_TEST_SUITE(TMiniKQLStringUtils) {
Y_UNIT_TEST(SubstringWithLargeOffset) {
    TScopedAlloc alloc(__LOCATION__);
    const auto big = MakeStringNotFilled(/*size=*/NUdf::TUnboxedValuePod::OffsetLimit << 1U);
    const auto sub0 = NUdf::TUnboxedValue(SubString(big, 1U, 42U));
    const auto sub1 = NUdf::TUnboxedValue(SubString(big, NUdf::TUnboxedValuePod::OffsetLimit - 1U, 42U));
    const auto sub2 = NUdf::TUnboxedValue(SubString(big, NUdf::TUnboxedValuePod::OffsetLimit, 42U));

    UNIT_ASSERT(sub0.AsStringValue().Data() == sub1.AsStringValue().Data());
    UNIT_ASSERT(sub1.AsStringValue().Data() != sub2.AsStringValue().Data());
}

Y_UNIT_TEST(MakeStringWithPad) {
    TScopedAlloc alloc(__LOCATION__);

    {
        const auto buf = MakeStringNotFilled(NUdf::TUnboxedValuePod::InternalBufferSize - 1U, 1U);
        UNIT_ASSERT(buf.IsEmbedded());
        UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), NUdf::TUnboxedValuePod::InternalBufferSize - 1U);
    }

    {
        const auto buf = MakeStringNotFilled(NUdf::TUnboxedValuePod::InternalBufferSize, 1U);
        UNIT_ASSERT(buf.IsString());
        UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), NUdf::TUnboxedValuePod::InternalBufferSize);
        UNIT_ASSERT_VALUES_EQUAL(buf.AsStringValue().Size(), NUdf::TUnboxedValuePod::InternalBufferSize + 1U);
    }
}

// Disable test since it produces too much memory for msan.
#if !defined(_msan_enabled_)
Y_UNIT_TEST(MakeLargeString) {
    TScopedAlloc alloc(__LOCATION__);

    {
        const auto buf = MakeStringNotFilled(0xFFFFFFFFU);
        UNIT_ASSERT(buf.IsString());
        UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), 0xFFFFFFFFU);
        const auto& value = buf.AsStringValue();
        UNIT_ASSERT_VALUES_EQUAL(value.Size(), 0xFFFFFFFFU);
        UNIT_ASSERT_VALUES_EQUAL(value.Capacity(), 0x100000000ULL);
    }

    {
        const auto buf = MakeStringNotFilled(0xFFFFFFF1U);
        UNIT_ASSERT(buf.IsString());
        UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), 0xFFFFFFF1U);
        const auto& value = buf.AsStringValue();
        UNIT_ASSERT_VALUES_EQUAL(value.Size(), 0xFFFFFFF1U);
        UNIT_ASSERT_VALUES_EQUAL(value.Capacity(), 0x100000000ULL);
    }

    {
        const auto buf = MakeStringNotFilled(0xFFFFFFF0U);
        UNIT_ASSERT(buf.IsString());
        UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), 0xFFFFFFF0U);
        const auto& value = buf.AsStringValue();
        UNIT_ASSERT_VALUES_EQUAL(value.Size(), 0xFFFFFFF0U);
        UNIT_ASSERT_VALUES_EQUAL(value.Capacity(), 0xFFFFFFF0ULL);
    }
}
#endif

// Disable test since it produces too much memory for msan.
#if !defined(_msan_enabled_)
Y_UNIT_TEST(ConcatLargeString) {
    TScopedAlloc alloc(__LOCATION__);

    const NUdf::TUnboxedValue buf = MakeStringNotFilled(0x80000000U);
    try {
        ConcatStrings(buf, buf);
        UNIT_FAIL("No exception!");
    } catch (const yexception&) {
    }

    try {
        PrependString(buf.AsStringRef(), buf);
        UNIT_FAIL("No exception!");
    } catch (const yexception&) {
    }

    try {
        AppendString(buf, buf.AsStringRef());
        UNIT_FAIL("No exception!");
    } catch (const yexception&) {
    }
}
#endif

} // Y_UNIT_TEST_SUITE(TMiniKQLStringUtils)