1#include <gtest/gtest.h>
2
3#include <Common/PODArray.h>
4
5using namespace DB;
6
7TEST(Common, PODArray_Insert)
8{
9 std::string str = "test_string_abacaba";
10 PODArray<char> chars;
11 chars.insert(chars.end(), str.begin(), str.end());
12 EXPECT_EQ(str, std::string(chars.data(), chars.size()));
13
14 std::string insert_in_the_middle = "insert_in_the_middle";
15 auto pos = str.size() / 2;
16 str.insert(str.begin() + pos, insert_in_the_middle.begin(), insert_in_the_middle.end());
17 chars.insert(chars.begin() + pos, insert_in_the_middle.begin(), insert_in_the_middle.end());
18 EXPECT_EQ(str, std::string(chars.data(), chars.size()));
19
20 std::string insert_with_resize;
21 insert_with_resize.reserve(chars.capacity() * 2);
22 char cur_char = 'a';
23 while (insert_with_resize.size() < insert_with_resize.capacity())
24 {
25 insert_with_resize += cur_char;
26 if (cur_char == 'z')
27 cur_char = 'a';
28 else
29 ++cur_char;
30 }
31 str.insert(str.begin(), insert_with_resize.begin(), insert_with_resize.end());
32 chars.insert(chars.begin(), insert_with_resize.begin(), insert_with_resize.end());
33 EXPECT_EQ(str, std::string(chars.data(), chars.size()));
34}
35