~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to library/base/unit-tests/base_test.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
// This file contains common TUT test cases for myx_utils_function.c
 
3
//
 
4
//
 
5
 
 
6
//----------------------------------------------------------------------------------------------------------------------
 
7
 
 
8
#include "test.h"
 
9
#include "base/sqlstring.h"
 
10
#include "base/util_functions.h"
 
11
 
 
12
//----------------------------------------------------------------------------------------------------------------------
 
13
 
 
14
TEST_MODULE(base_library, "Common test suite, base library");
 
15
 
 
16
//----------------------------------------------------------------------------------------------------------------------
 
17
 
 
18
using namespace base;
 
19
 
 
20
//----------------------------------------------------------------------------------------------------------------------
 
21
 
 
22
TEST_FUNCTION(10)
 
23
{
 
24
  char* result= baseconv(0, 0);
 
25
  ensure("Integer to string conversion", result == NULL);
 
26
 
 
27
  result= baseconv(0, 100);
 
28
  ensure("Integer to string conversion", result == NULL);
 
29
 
 
30
  result= baseconv(0, 10);
 
31
  ensure("Integer to string conversion", strcmp(result, "0") == 0);
 
32
  g_free(result);
 
33
 
 
34
  // A small number.
 
35
  result= baseconv(3, 2);
 
36
  ensure("Integer to string conversion", strcmp(result, "11") == 0);
 
37
  g_free(result);
 
38
 
 
39
  result= baseconv(3, 3);
 
40
  ensure("Integer to string conversion", strcmp(result, "10") == 0);
 
41
  g_free(result);
 
42
 
 
43
  result= baseconv(3, 4);
 
44
  ensure("Integer to string conversion", strcmp(result, "3") == 0);
 
45
  g_free(result);
 
46
 
 
47
  result= baseconv(3, 5);
 
48
  ensure("Integer to string conversion", strcmp(result, "3") == 0);
 
49
  g_free(result);
 
50
 
 
51
  result= baseconv(3, 6);
 
52
  ensure("Integer to string conversion", strcmp(result, "3") == 0);
 
53
  g_free(result);
 
54
 
 
55
  result= baseconv(3, 7);
 
56
  ensure("Integer to string conversion", strcmp(result, "3") == 0);
 
57
  g_free(result);
 
58
 
 
59
  result= baseconv(3, 8);
 
60
  ensure("Integer to string conversion", strcmp(result, "3") == 0);
 
61
  g_free(result);
 
62
 
 
63
  result= baseconv(3, 9);
 
64
  ensure("Integer to string conversion", strcmp(result, "3") == 0);
 
65
  g_free(result);
 
66
 
 
67
  result= baseconv(3, 10);
 
68
  ensure("Integer to string conversion", strcmp(result, "3") == 0);
 
69
  g_free(result);
 
70
 
 
71
  result= baseconv(3, 11);
 
72
  ensure("Integer to string conversion", strcmp(result, "3") == 0);
 
73
  g_free(result);
 
74
 
 
75
  result= baseconv(3, 12);
 
76
  ensure("Integer to string conversion", strcmp(result, "3") == 0);
 
77
  g_free(result);
 
78
 
 
79
  result= baseconv(3, 13);
 
80
  ensure("Integer to string conversion", strcmp(result, "3") == 0);
 
81
  g_free(result);
 
82
 
 
83
  result= baseconv(3, 14);
 
84
  ensure("Integer to string conversion", strcmp(result, "3") == 0);
 
85
  g_free(result);
 
86
 
 
87
  result= baseconv(3, 15);
 
88
  ensure("Integer to string conversion", strcmp(result, "3") == 0);
 
89
  g_free(result);
 
90
 
 
91
  result= baseconv(3, 16);
 
92
  ensure("Integer to string conversion", strcmp(result, "3") == 0);
 
93
  g_free(result);
 
94
 
 
95
  // A prime number.
 
96
  result= baseconv(1020389, 2);
 
97
  ensure("Integer to string conversion", strcmp(result, "11111001000111100101") == 0);
 
98
  g_free(result);
 
99
 
 
100
  result= baseconv(1020389, 3);
 
101
  ensure("Integer to string conversion", strcmp(result, "1220211201012") == 0);
 
102
  g_free(result);
 
103
 
 
104
  result= baseconv(1020389, 4);
 
105
  ensure("Integer to string conversion", strcmp(result, "3321013211") == 0);
 
106
  g_free(result);
 
107
 
 
108
  result= baseconv(1020389, 5);
 
109
  ensure("Integer to string conversion", strcmp(result, "230123024") == 0);
 
110
  g_free(result);
 
111
 
 
112
  result= baseconv(1020389, 6);
 
113
  ensure("Integer to string conversion", strcmp(result, "33512005") == 0);
 
114
  g_free(result);
 
115
 
 
116
  result= baseconv(1020389, 7);
 
117
  ensure("Integer to string conversion", strcmp(result, "11446616") == 0);
 
118
  g_free(result);
 
119
 
 
120
  result= baseconv(1020389, 8);
 
121
  ensure("Integer to string conversion", strcmp(result, "3710745") == 0);
 
122
  g_free(result);
 
123
 
 
124
  result= baseconv(1020389, 9);
 
125
  ensure("Integer to string conversion", strcmp(result, "1824635") == 0);
 
126
  g_free(result);
 
127
 
 
128
  result= baseconv(1020389, 10);
 
129
  ensure("Integer to string conversion", strcmp(result, "1020389") == 0);
 
130
  g_free(result);
 
131
 
 
132
  result= baseconv(1020389, 11);
 
133
  ensure("Integer to string conversion", strcmp(result, "6376a7") == 0);
 
134
  g_free(result);
 
135
 
 
136
  result= baseconv(1020389, 12);
 
137
  ensure("Integer to string conversion", strcmp(result, "412605") == 0);
 
138
  g_free(result);
 
139
 
 
140
  result= baseconv(1020389, 13);
 
141
  ensure("Integer to string conversion", strcmp(result, "2995a6") == 0);
 
142
  g_free(result);
 
143
 
 
144
  result= baseconv(1020389, 14);
 
145
  ensure("Integer to string conversion", strcmp(result, "1c7c0d") == 0);
 
146
  g_free(result);
 
147
 
 
148
  result= baseconv(1020389, 15);
 
149
  ensure("Integer to string conversion", strcmp(result, "15250e") == 0);
 
150
  g_free(result);
 
151
 
 
152
  result= baseconv(1020389, 16);
 
153
  ensure("Integer to string conversion", strcmp(result, "f91e5") == 0);
 
154
  g_free(result);
 
155
 
 
156
  // A straight big number.
 
157
  result= baseconv(1000000, 2);
 
158
  ensure("Integer to string conversion", strcmp(result, "11110100001001000000") == 0);
 
159
  g_free(result);
 
160
 
 
161
  result= baseconv(1000000, 3);
 
162
  ensure("Integer to string conversion", strcmp(result, "1212210202001") == 0);
 
163
  g_free(result);
 
164
 
 
165
  result= baseconv(1000000, 4);
 
166
  ensure("Integer to string conversion", strcmp(result, "3310021000") == 0);
 
167
  g_free(result);
 
168
 
 
169
  result= baseconv(1000000, 5);
 
170
  ensure("Integer to string conversion", strcmp(result, "224000000") == 0);
 
171
  g_free(result);
 
172
 
 
173
  result= baseconv(1000000, 6);
 
174
  ensure("Integer to string conversion", strcmp(result, "33233344") == 0);
 
175
  g_free(result);
 
176
 
 
177
  result= baseconv(1000000, 7);
 
178
  ensure("Integer to string conversion", strcmp(result, "11333311") == 0);
 
179
  g_free(result);
 
180
 
 
181
  result= baseconv(1000000, 8);
 
182
  ensure("Integer to string conversion", strcmp(result, "3641100") == 0);
 
183
  g_free(result);
 
184
 
 
185
  result= baseconv(1000000, 9);
 
186
  ensure("Integer to string conversion", strcmp(result, "1783661") == 0);
 
187
  g_free(result);
 
188
 
 
189
  result= baseconv(1000000, 10);
 
190
  ensure("Integer to string conversion", strcmp(result, "1000000") == 0);
 
191
  g_free(result);
 
192
 
 
193
  result= baseconv(1000000, 11);
 
194
  ensure("Integer to string conversion", strcmp(result, "623351") == 0);
 
195
  g_free(result);
 
196
 
 
197
  result= baseconv(1000000, 12);
 
198
  ensure("Integer to string conversion", strcmp(result, "402854") == 0);
 
199
  g_free(result);
 
200
 
 
201
  result= baseconv(1000000, 13);
 
202
  ensure("Integer to string conversion", strcmp(result, "290221") == 0);
 
203
  g_free(result);
 
204
 
 
205
  result= baseconv(1000000, 14);
 
206
  ensure("Integer to string conversion", strcmp(result, "1c0608") == 0);
 
207
  g_free(result);
 
208
 
 
209
  result= baseconv(1000000, 15);
 
210
  ensure("Integer to string conversion", strcmp(result, "14b46a") == 0);
 
211
  g_free(result);
 
212
 
 
213
  result= baseconv(1000000, 16);
 
214
  ensure("Integer to string conversion", strcmp(result, "f4240") == 0);
 
215
  g_free(result);
 
216
 
 
217
  // A really big number (actually the biggest possible).
 
218
  result= baseconv(18446744073709551615LL, 2);
 
219
  ensure("Integer to string conversion", strcmp(result, "1111111111111111111111111111111111111111111111111111111111111111") == 0);
 
220
  g_free(result);
 
221
 
 
222
  result= baseconv(18446744073709551615LL, 3);
 
223
  ensure("Integer to string conversion", strcmp(result, "11112220022122120101211020120210210211220") == 0);
 
224
  g_free(result);
 
225
 
 
226
  result= baseconv(18446744073709551615LL, 4);
 
227
  ensure("Integer to string conversion", strcmp(result, "33333333333333333333333333333333") == 0);
 
228
  g_free(result);
 
229
 
 
230
  result= baseconv(18446744073709551615LL, 5);
 
231
  ensure("Integer to string conversion", strcmp(result, "2214220303114400424121122430") == 0);
 
232
  g_free(result);
 
233
 
 
234
  result= baseconv(18446744073709551615LL, 6);
 
235
  ensure("Integer to string conversion", strcmp(result, "3520522010102100444244423") == 0);
 
236
  g_free(result);
 
237
 
 
238
  result= baseconv(18446744073709551615LL, 7);
 
239
  ensure("Integer to string conversion", strcmp(result, "45012021522523134134601") == 0);
 
240
  g_free(result);
 
241
 
 
242
  result= baseconv(18446744073709551615LL, 8);
 
243
  ensure("Integer to string conversion", strcmp(result, "1777777777777777777777") == 0);
 
244
  g_free(result);
 
245
 
 
246
  result= baseconv(18446744073709551615LL, 9);
 
247
  ensure("Integer to string conversion", strcmp(result, "145808576354216723756") == 0);
 
248
  g_free(result);
 
249
 
 
250
  result= baseconv(18446744073709551615LL, 10);
 
251
  ensure("Integer to string conversion", strcmp(result, "18446744073709551615") == 0);
 
252
  g_free(result);
 
253
 
 
254
  result= baseconv(18446744073709551615LL, 11);
 
255
  ensure("Integer to string conversion", strcmp(result, "335500516a429071284") == 0);
 
256
  g_free(result);
 
257
 
 
258
  result= baseconv(18446744073709551615LL, 12);
 
259
  ensure("Integer to string conversion", strcmp(result, "839365134a2a240713") == 0);
 
260
  g_free(result);
 
261
 
 
262
  result= baseconv(18446744073709551615LL, 13);
 
263
  ensure("Integer to string conversion", strcmp(result, "219505a9511a867b72") == 0);
 
264
  g_free(result);
 
265
 
 
266
  result= baseconv(18446744073709551615LL, 14);
 
267
  ensure("Integer to string conversion", strcmp(result, "8681049adb03db171") == 0);
 
268
  g_free(result);
 
269
 
 
270
  result= baseconv(18446744073709551615LL, 15);
 
271
  ensure("Integer to string conversion", strcmp(result, "2c1d56b648c6cd110") == 0);
 
272
  g_free(result);
 
273
 
 
274
  result= baseconv(18446744073709551615LL, 16);
 
275
  ensure("Integer to string conversion", strcmp(result, "ffffffffffffffff") == 0);
 
276
  g_free(result);
 
277
}
 
278
 
 
279
//----------------------------------------------------------------------------------------------------------------------
 
280
 
 
281
// sqlstring
 
282
TEST_FUNCTION(20)
 
283
{
 
284
  // test constructors
 
285
 
 
286
  ensure("Empty sqlstring", (std::string)sqlstring()=="");
 
287
  
 
288
  ensure("With string cast", (std::string)sqlstring("hi", 0) == "hi");
 
289
 
 
290
  sqlstring tmp;
 
291
  tmp = sqlstring("hello", 0);
 
292
  ensure_equals("Assignment", (std::string)tmp, "hello");
 
293
 
 
294
  // must throw exception
 
295
  try { 
 
296
    std::string s = sqlstring("?", 0); 
 
297
    ensure("Insufficient args", false);
 
298
  }
 
299
  catch (...) { 
 
300
    ensure("Insufficient args", true);
 
301
  }
 
302
}
 
303
 
 
304
 
 
305
TEST_FUNCTION(21)
 
306
{
 
307
  sqlstring s;
 
308
  s = sqlstring("select", 0);
 
309
  ensure_equals("nothing", (std::string)s, "select");
 
310
  ensure("nothing check", s.done());
 
311
 
 
312
  s = sqlstring("?", 0);
 
313
  ensure_equals("unfinished", (std::string)s, "?");
 
314
  ensure("unfinished check", !s.done());
 
315
 
 
316
  s = sqlstring("?", 0);
 
317
  s << "xxx";
 
318
  ensure_equals("string", (std::string)s, "'xxx'");
 
319
  ensure("string check", s.done());
 
320
 
 
321
  s = sqlstring("?", 0) << "xxx";
 
322
  ensure_equals("string2", (std::string)s, "'xxx'");
 
323
 
 
324
 
 
325
  s = sqlstring("select ! from ! where x=? and y=?", 0);
 
326
  s << "col";
 
327
  s << std::string("table");
 
328
  s << 123 << "hi";
 
329
  ensure("Format", (std::string)s == "select `col` from `table` where x=123 and y='hi'");
 
330
 
 
331
  std::string str = sqlstring("? ! ? ? ?", 0) << "aa" 
 
332
    << "col"
 
333
    << 1 
 
334
    << 2.0 
 
335
    << sqlstring::null;
 
336
  ensure_equals("Format alltogehter", str, "'aa' `col` 1 2.000000 NULL");
 
337
 
 
338
  ensure_equals("Format NULL", (std::string)(sqlstring("?", 0) << sqlstring::null), "NULL");
 
339
}
 
340
 
 
341
END_TESTS;
 
342
 
 
343
//----------------------------------------------------------------------------------------------------------------------
 
344