2019-11-15 14:36:52 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include <Common/PODArray.h>
|
|
|
|
|
|
|
|
using namespace DB;
|
|
|
|
|
2020-03-09 02:10:20 +00:00
|
|
|
TEST(Common, PODArrayInsert)
|
2019-11-15 14:36:52 +00:00
|
|
|
{
|
|
|
|
std::string str = "test_string_abacaba";
|
|
|
|
PODArray<char> chars;
|
|
|
|
chars.insert(chars.end(), str.begin(), str.end());
|
|
|
|
EXPECT_EQ(str, std::string(chars.data(), chars.size()));
|
|
|
|
|
|
|
|
std::string insert_in_the_middle = "insert_in_the_middle";
|
|
|
|
auto pos = str.size() / 2;
|
|
|
|
str.insert(str.begin() + pos, insert_in_the_middle.begin(), insert_in_the_middle.end());
|
|
|
|
chars.insert(chars.begin() + pos, insert_in_the_middle.begin(), insert_in_the_middle.end());
|
|
|
|
EXPECT_EQ(str, std::string(chars.data(), chars.size()));
|
|
|
|
|
|
|
|
std::string insert_with_resize;
|
|
|
|
insert_with_resize.reserve(chars.capacity() * 2);
|
2019-11-15 15:00:10 +00:00
|
|
|
char cur_char = 'a';
|
2019-11-15 14:36:52 +00:00
|
|
|
while (insert_with_resize.size() < insert_with_resize.capacity())
|
|
|
|
{
|
2019-11-15 15:00:10 +00:00
|
|
|
insert_with_resize += cur_char;
|
|
|
|
if (cur_char == 'z')
|
|
|
|
cur_char = 'a';
|
2019-11-15 14:36:52 +00:00
|
|
|
else
|
2019-11-15 15:00:10 +00:00
|
|
|
++cur_char;
|
2019-11-15 14:36:52 +00:00
|
|
|
}
|
|
|
|
str.insert(str.begin(), insert_with_resize.begin(), insert_with_resize.end());
|
|
|
|
chars.insert(chars.begin(), insert_with_resize.begin(), insert_with_resize.end());
|
|
|
|
EXPECT_EQ(str, std::string(chars.data(), chars.size()));
|
|
|
|
}
|
2020-06-19 13:21:54 +00:00
|
|
|
|
|
|
|
TEST(Common, PODPushBackRawMany)
|
|
|
|
{
|
|
|
|
PODArray<char> chars;
|
|
|
|
chars.push_back_raw_many(5, "first");
|
|
|
|
EXPECT_EQ(std::string("first"), std::string(chars.data(), chars.size()));
|
|
|
|
EXPECT_EQ(5, chars.size());
|
|
|
|
EXPECT_LE(chars.capacity() - chars.size() < 10);
|
|
|
|
chars.push_back_raw_many(10, "0123456789");
|
|
|
|
EXPECT_EQ(15, chars.size());
|
|
|
|
EXPECT_EQ(std::string("first0123456789"), std::string(chars.data(), chars.size()));
|
|
|
|
}
|