forked from heavyai/heavydb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpecialCharsTest.cpp
197 lines (164 loc) · 6.26 KB
/
SpecialCharsTest.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
* Copyright 2020 OmniSci, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "TestHelpers.h"
#include <gtest/gtest.h>
#include <codecvt>
#include <locale>
#include "QueryEngine/ResultSet.h"
#include "QueryRunner/QueryRunner.h"
#ifndef BASE_PATH
#define BASE_PATH "./tmp"
#endif
using QR = QueryRunner::QueryRunner;
using namespace TestHelpers;
bool g_keep_data{false};
bool skip_tests(const ExecutorDeviceType device_type) {
#ifdef HAVE_CUDA
return device_type == ExecutorDeviceType::GPU && !QR::get()->gpusPresent();
#else
return device_type == ExecutorDeviceType::GPU;
#endif
}
#define SKIP_NO_GPU() \
if (skip_tests(dt)) { \
CHECK(dt == ExecutorDeviceType::GPU); \
LOG(WARNING) << "GPU not available, skipping GPU tests"; \
continue; \
}
std::shared_ptr<ResultSet> run_multiple_agg(const std::string& query_str,
const ExecutorDeviceType device_type) {
return QR::get()->runSQL(query_str, device_type, true, true);
}
class UnicodeSpecialChars : public ::testing::Test {
public:
void SetUp() override {
QR::get()->runDDLStatement("DROP TABLE IF EXISTS special_chars;");
QR::get()->runDDLStatement(
"CREATE TABLE special_chars (x INT, str TEXT ENCODING DICT(32)) WITH "
"(FRAGMENT_SIZE=2);");
run_multiple_agg("INSERT INTO special_chars VALUES (1, '" +
UnicodeSpecialChars::getStringValue() + "');",
ExecutorDeviceType::CPU);
}
void TearDown() override {
if (!g_keep_data) {
QR::get()->runDDLStatement("DROP TABLE IF EXISTS special_chars;");
}
}
static std::string getStringValue() {
return std::string("妙高杉ノ原スキー場に来ています。天気良好。");
}
};
TEST_F(UnicodeSpecialChars, Basics) {
for (auto dt : {ExecutorDeviceType::CPU, ExecutorDeviceType::GPU}) {
SKIP_NO_GPU();
auto rows = run_multiple_agg("SELECT count(*) FROM special_chars WHERE str = '" +
UnicodeSpecialChars::getStringValue() + "';",
dt);
ASSERT_EQ(rows->rowCount(), size_t(1));
auto crt_row = rows->getNextRow(true, true);
ASSERT_EQ(crt_row.size(), size_t(1));
ASSERT_EQ(v<int64_t>(crt_row[0]), int64_t(1));
}
}
class EscapeSeqSpecialChars : public ::testing::Test {
public:
void SetUp() override {
QR::get()->runDDLStatement("DROP TABLE IF EXISTS special_chars;");
QR::get()->runDDLStatement(
"CREATE TABLE special_chars (x INT, str TEXT ENCODING DICT(32)) WITH "
"(FRAGMENT_SIZE=2);");
run_multiple_agg("INSERT INTO special_chars VALUES (1, '" +
EscapeSeqSpecialChars::getString1() + "');",
ExecutorDeviceType::CPU);
run_multiple_agg("INSERT INTO special_chars VALUES (2, '" +
EscapeSeqSpecialChars::getString2() + "');",
ExecutorDeviceType::CPU);
}
void TearDown() override {
if (!g_keep_data) {
QR::get()->runDDLStatement("DROP TABLE IF EXISTS special_chars;");
}
}
static std::string getString1() {
return std::string("\u001e"); // information separator two
}
static std::string getString2() {
return std::string("\u008D"); // reverse line feed
}
};
TEST_F(EscapeSeqSpecialChars, Basics) {
for (auto dt : {ExecutorDeviceType::CPU, ExecutorDeviceType::GPU}) {
SKIP_NO_GPU();
{
auto rows = run_multiple_agg("SELECT x FROM special_chars WHERE str = '" +
EscapeSeqSpecialChars::getString1() + "';",
dt);
ASSERT_EQ(rows->rowCount(), size_t(1));
auto crt_row = rows->getNextRow(true, true);
ASSERT_EQ(crt_row.size(), size_t(1));
ASSERT_EQ(v<int64_t>(crt_row[0]), int64_t(1));
}
{
auto rows = run_multiple_agg("SELECT x FROM special_chars WHERE str = '" +
EscapeSeqSpecialChars::getString2() + "';",
dt);
ASSERT_EQ(rows->rowCount(), size_t(1));
auto crt_row = rows->getNextRow(true, true);
ASSERT_EQ(crt_row.size(), size_t(1));
ASSERT_EQ(v<int64_t>(crt_row[0]), int64_t(2));
}
}
}
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
namespace po = boost::program_options;
po::options_description desc("Options");
// these two are here to allow passing correctly google testing parameters
desc.add_options()("gtest_list_tests", "list all tests");
desc.add_options()("gtest_filter", "filters tests, use --help for details");
desc.add_options()("keep-data",
"Don't drop tables at the end of the tests. Note that individual "
"tests may still create and drop tables. Use in combination with "
"--gtest_filter to preserve tables for a specific test group.");
desc.add_options()(
"test-help",
"Print all BumpAllocatorTest specific options (for gtest options use `--help`).");
logger::LogOptions log_options(argv[0]);
log_options.max_files_ = 0; // stderr only by default
desc.add(log_options.get_options());
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
po::notify(vm);
if (vm.count("test-help")) {
std::cout << "Usage: BumpAllocatorTest" << std::endl << std::endl;
std::cout << desc << std::endl;
return 0;
}
if (vm.count("keep-data")) {
g_keep_data = true;
}
logger::init(log_options);
QR::init(BASE_PATH);
int err{0};
try {
err = RUN_ALL_TESTS();
} catch (const std::exception& e) {
LOG(ERROR) << e.what();
}
QR::reset();
return err;
}