2
// This file contains common TUT test cases for myx_utils_function.c
6
//----------------------------------------------------------------------------------------------------------------------
9
#include "base/sqlstring.h"
10
#include "base/util_functions.h"
12
//----------------------------------------------------------------------------------------------------------------------
14
TEST_MODULE(base_library, "Common test suite, base library");
16
//----------------------------------------------------------------------------------------------------------------------
20
//----------------------------------------------------------------------------------------------------------------------
24
char* result= baseconv(0, 0);
25
ensure("Integer to string conversion", result == NULL);
27
result= baseconv(0, 100);
28
ensure("Integer to string conversion", result == NULL);
30
result= baseconv(0, 10);
31
ensure("Integer to string conversion", strcmp(result, "0") == 0);
35
result= baseconv(3, 2);
36
ensure("Integer to string conversion", strcmp(result, "11") == 0);
39
result= baseconv(3, 3);
40
ensure("Integer to string conversion", strcmp(result, "10") == 0);
43
result= baseconv(3, 4);
44
ensure("Integer to string conversion", strcmp(result, "3") == 0);
47
result= baseconv(3, 5);
48
ensure("Integer to string conversion", strcmp(result, "3") == 0);
51
result= baseconv(3, 6);
52
ensure("Integer to string conversion", strcmp(result, "3") == 0);
55
result= baseconv(3, 7);
56
ensure("Integer to string conversion", strcmp(result, "3") == 0);
59
result= baseconv(3, 8);
60
ensure("Integer to string conversion", strcmp(result, "3") == 0);
63
result= baseconv(3, 9);
64
ensure("Integer to string conversion", strcmp(result, "3") == 0);
67
result= baseconv(3, 10);
68
ensure("Integer to string conversion", strcmp(result, "3") == 0);
71
result= baseconv(3, 11);
72
ensure("Integer to string conversion", strcmp(result, "3") == 0);
75
result= baseconv(3, 12);
76
ensure("Integer to string conversion", strcmp(result, "3") == 0);
79
result= baseconv(3, 13);
80
ensure("Integer to string conversion", strcmp(result, "3") == 0);
83
result= baseconv(3, 14);
84
ensure("Integer to string conversion", strcmp(result, "3") == 0);
87
result= baseconv(3, 15);
88
ensure("Integer to string conversion", strcmp(result, "3") == 0);
91
result= baseconv(3, 16);
92
ensure("Integer to string conversion", strcmp(result, "3") == 0);
96
result= baseconv(1020389, 2);
97
ensure("Integer to string conversion", strcmp(result, "11111001000111100101") == 0);
100
result= baseconv(1020389, 3);
101
ensure("Integer to string conversion", strcmp(result, "1220211201012") == 0);
104
result= baseconv(1020389, 4);
105
ensure("Integer to string conversion", strcmp(result, "3321013211") == 0);
108
result= baseconv(1020389, 5);
109
ensure("Integer to string conversion", strcmp(result, "230123024") == 0);
112
result= baseconv(1020389, 6);
113
ensure("Integer to string conversion", strcmp(result, "33512005") == 0);
116
result= baseconv(1020389, 7);
117
ensure("Integer to string conversion", strcmp(result, "11446616") == 0);
120
result= baseconv(1020389, 8);
121
ensure("Integer to string conversion", strcmp(result, "3710745") == 0);
124
result= baseconv(1020389, 9);
125
ensure("Integer to string conversion", strcmp(result, "1824635") == 0);
128
result= baseconv(1020389, 10);
129
ensure("Integer to string conversion", strcmp(result, "1020389") == 0);
132
result= baseconv(1020389, 11);
133
ensure("Integer to string conversion", strcmp(result, "6376a7") == 0);
136
result= baseconv(1020389, 12);
137
ensure("Integer to string conversion", strcmp(result, "412605") == 0);
140
result= baseconv(1020389, 13);
141
ensure("Integer to string conversion", strcmp(result, "2995a6") == 0);
144
result= baseconv(1020389, 14);
145
ensure("Integer to string conversion", strcmp(result, "1c7c0d") == 0);
148
result= baseconv(1020389, 15);
149
ensure("Integer to string conversion", strcmp(result, "15250e") == 0);
152
result= baseconv(1020389, 16);
153
ensure("Integer to string conversion", strcmp(result, "f91e5") == 0);
156
// A straight big number.
157
result= baseconv(1000000, 2);
158
ensure("Integer to string conversion", strcmp(result, "11110100001001000000") == 0);
161
result= baseconv(1000000, 3);
162
ensure("Integer to string conversion", strcmp(result, "1212210202001") == 0);
165
result= baseconv(1000000, 4);
166
ensure("Integer to string conversion", strcmp(result, "3310021000") == 0);
169
result= baseconv(1000000, 5);
170
ensure("Integer to string conversion", strcmp(result, "224000000") == 0);
173
result= baseconv(1000000, 6);
174
ensure("Integer to string conversion", strcmp(result, "33233344") == 0);
177
result= baseconv(1000000, 7);
178
ensure("Integer to string conversion", strcmp(result, "11333311") == 0);
181
result= baseconv(1000000, 8);
182
ensure("Integer to string conversion", strcmp(result, "3641100") == 0);
185
result= baseconv(1000000, 9);
186
ensure("Integer to string conversion", strcmp(result, "1783661") == 0);
189
result= baseconv(1000000, 10);
190
ensure("Integer to string conversion", strcmp(result, "1000000") == 0);
193
result= baseconv(1000000, 11);
194
ensure("Integer to string conversion", strcmp(result, "623351") == 0);
197
result= baseconv(1000000, 12);
198
ensure("Integer to string conversion", strcmp(result, "402854") == 0);
201
result= baseconv(1000000, 13);
202
ensure("Integer to string conversion", strcmp(result, "290221") == 0);
205
result= baseconv(1000000, 14);
206
ensure("Integer to string conversion", strcmp(result, "1c0608") == 0);
209
result= baseconv(1000000, 15);
210
ensure("Integer to string conversion", strcmp(result, "14b46a") == 0);
213
result= baseconv(1000000, 16);
214
ensure("Integer to string conversion", strcmp(result, "f4240") == 0);
217
// A really big number (actually the biggest possible).
218
result= baseconv(18446744073709551615LL, 2);
219
ensure("Integer to string conversion", strcmp(result, "1111111111111111111111111111111111111111111111111111111111111111") == 0);
222
result= baseconv(18446744073709551615LL, 3);
223
ensure("Integer to string conversion", strcmp(result, "11112220022122120101211020120210210211220") == 0);
226
result= baseconv(18446744073709551615LL, 4);
227
ensure("Integer to string conversion", strcmp(result, "33333333333333333333333333333333") == 0);
230
result= baseconv(18446744073709551615LL, 5);
231
ensure("Integer to string conversion", strcmp(result, "2214220303114400424121122430") == 0);
234
result= baseconv(18446744073709551615LL, 6);
235
ensure("Integer to string conversion", strcmp(result, "3520522010102100444244423") == 0);
238
result= baseconv(18446744073709551615LL, 7);
239
ensure("Integer to string conversion", strcmp(result, "45012021522523134134601") == 0);
242
result= baseconv(18446744073709551615LL, 8);
243
ensure("Integer to string conversion", strcmp(result, "1777777777777777777777") == 0);
246
result= baseconv(18446744073709551615LL, 9);
247
ensure("Integer to string conversion", strcmp(result, "145808576354216723756") == 0);
250
result= baseconv(18446744073709551615LL, 10);
251
ensure("Integer to string conversion", strcmp(result, "18446744073709551615") == 0);
254
result= baseconv(18446744073709551615LL, 11);
255
ensure("Integer to string conversion", strcmp(result, "335500516a429071284") == 0);
258
result= baseconv(18446744073709551615LL, 12);
259
ensure("Integer to string conversion", strcmp(result, "839365134a2a240713") == 0);
262
result= baseconv(18446744073709551615LL, 13);
263
ensure("Integer to string conversion", strcmp(result, "219505a9511a867b72") == 0);
266
result= baseconv(18446744073709551615LL, 14);
267
ensure("Integer to string conversion", strcmp(result, "8681049adb03db171") == 0);
270
result= baseconv(18446744073709551615LL, 15);
271
ensure("Integer to string conversion", strcmp(result, "2c1d56b648c6cd110") == 0);
274
result= baseconv(18446744073709551615LL, 16);
275
ensure("Integer to string conversion", strcmp(result, "ffffffffffffffff") == 0);
279
//----------------------------------------------------------------------------------------------------------------------
286
ensure("Empty sqlstring", (std::string)sqlstring()=="");
288
ensure("With string cast", (std::string)sqlstring("hi", 0) == "hi");
291
tmp = sqlstring("hello", 0);
292
ensure_equals("Assignment", (std::string)tmp, "hello");
294
// must throw exception
296
std::string s = sqlstring("?", 0);
297
ensure("Insufficient args", false);
300
ensure("Insufficient args", true);
308
s = sqlstring("select", 0);
309
ensure_equals("nothing", (std::string)s, "select");
310
ensure("nothing check", s.done());
312
s = sqlstring("?", 0);
313
ensure_equals("unfinished", (std::string)s, "?");
314
ensure("unfinished check", !s.done());
316
s = sqlstring("?", 0);
318
ensure_equals("string", (std::string)s, "'xxx'");
319
ensure("string check", s.done());
321
s = sqlstring("?", 0) << "xxx";
322
ensure_equals("string2", (std::string)s, "'xxx'");
325
s = sqlstring("select ! from ! where x=? and y=?", 0);
327
s << std::string("table");
329
ensure("Format", (std::string)s == "select `col` from `table` where x=123 and y='hi'");
331
std::string str = sqlstring("? ! ? ? ?", 0) << "aa"
336
ensure_equals("Format alltogehter", str, "'aa' `col` 1 2.000000 NULL");
338
ensure_equals("Format NULL", (std::string)(sqlstring("?", 0) << sqlstring::null), "NULL");
343
//----------------------------------------------------------------------------------------------------------------------