diff --git a/ut/abnormal_column_names_test.cpp b/ut/abnormal_column_names_test.cpp index 885ed0be..11868f73 100644 --- a/ut/abnormal_column_names_test.cpp +++ b/ut/abnormal_column_names_test.cpp @@ -1,60 +1,64 @@ -#include "abnormal_column_names_test.h" -#include "utils.h" #include #include + +#include "utils.h" + +#include + #include #include namespace { - using namespace clickhouse; -} +using namespace clickhouse; -void AbnormalColumnNamesClientTest::SetUp() { - client_ = std::make_unique(std::get<0>(GetParam())); -} +std::string getColumnNames(const Block& block) { + std::string result; + for (size_t i = 0; i < block.GetColumnCount(); ++i) { + result += block.GetColumnName(i); + if (i != block.GetColumnCount() - 1) + result += ','; + } -void AbnormalColumnNamesClientTest::TearDown() { - client_.reset(); + return result; } +} + +struct AbnormalColumnNamesClientTestCase { + ClientOptions client_options; + std::vector queries; + std::vector expected_names; +}; + +class AbnormalColumnNamesClientTest : public testing::TestWithParam { +protected: + void SetUp() override { + client_ = std::make_unique(GetParam().client_options); + } + void TearDown() override { + client_.reset(); + } + + std::unique_ptr client_; +}; + -// Sometimes gtest fails to detect that this test is instantiated elsewhere, suppress the error explicitly. -GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AbnormalColumnNamesClientTest); TEST_P(AbnormalColumnNamesClientTest, Select) { - // TODO(vnemkov): move expected results into the test parameters, also get rid of PrettyPrintBlock - static const std::vector expect_results { - "+-------+-------+-------+\n"\ - "| 123 | 231 | 113 |\n"\ - "+-------+-------+-------+\n"\ - "| UInt8 | UInt8 | UInt8 |\n"\ - "+-------+-------+-------+\n"\ - "| 123 | 231 | 113 |\n"\ - "+-------+-------+-------+\n", - "+--------+--------+--------+--------+\n"\ - "| 'ABC' | 'AAA' | 'BBB' | 'CCC' |\n"\ - "+--------+--------+--------+--------+\n"\ - "| String | String | String | String |\n"\ - "+--------+--------+--------+--------+\n"\ - "| ABC | AAA | BBB | CCC |\n"\ - "+--------+--------+--------+--------+\n" - }; - const auto & queries = std::get<1>(GetParam()); + const auto & queries = GetParam().queries; for (size_t i = 0; i < queries.size(); ++i) { + const auto & query = queries.at(i); - client_->Select(query, - [& queries, i](const Block& block) { - if (block.GetRowCount() == 0 || block.GetColumnCount() == 0) - return; - EXPECT_EQ(1UL, block.GetRowCount()); - EXPECT_EQ(i == 0 ? 3UL: 4UL, block.GetColumnCount()); - - std::stringstream sstr; - sstr << PrettyPrintBlock{block}; - auto result = sstr.str(); - std::cout << "query => " << queries.at(i) <<"\n" << PrettyPrintBlock{block}; - ASSERT_EQ(expect_results.at(i), result); - } - ); + const auto & expected = GetParam().expected_names[i]; + + client_->Select(query, [query, expected](const Block& block) { + if (block.GetRowCount() == 0 || block.GetColumnCount() == 0) + return; + + EXPECT_EQ(1UL, block.GetRowCount()); + + EXPECT_EQ(expected, getColumnNames(block)) + << "For query: " << query; + }); } } @@ -70,7 +74,8 @@ INSTANTIATE_TEST_SUITE_P(ClientColumnNames, AbnormalColumnNamesClientTest, .SetSendRetries(1) .SetPingBeforeQuery(true) .SetCompressionMethod(CompressionMethod::None), - {"select 123,231,113", "select 'ABC','AAA','BBB','CCC'"} + {"select 123,231,113", "select 'ABC','AAA','BBB','CCC'"}, + {"123,231,113", "'ABC','AAA','BBB','CCC'"}, } )); diff --git a/ut/abnormal_column_names_test.h b/ut/abnormal_column_names_test.h deleted file mode 100644 index b0f56c62..00000000 --- a/ut/abnormal_column_names_test.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include - -#include - -#include -#include -#include - -class AbnormalColumnNamesClientTest : public testing::TestWithParam< - std::tuple > /*queries*/> { -protected: - void SetUp() override; - void TearDown() override; - - std::unique_ptr client_; -};