Line data Source code
1 : /*
2 : * Try usage of callbacks to get errors and messages from library.
3 : */
4 : #include "common.h"
5 :
6 : #include <bkpublic.h>
7 :
8 : #define ALL_TESTS \
9 : TEST(ct_callback) \
10 : TEST(ct_res_info) \
11 : TEST(ct_send) \
12 : TEST(cs_config) \
13 : TEST(blk_init) \
14 : TEST(cs_loc_alloc) \
15 : TEST(cs_loc_drop) \
16 : TEST(cs_locale) \
17 : TEST(ct_dynamic) \
18 : TEST(ct_connect) \
19 : TEST(ct_command) \
20 : TEST(ct_cursor) \
21 : TEST(ct_con_props) \
22 : TEST(ct_cmd_props) \
23 : TEST(cs_convert) \
24 : TEST(cs_dt_info)
25 :
26 : /* forward declare all tests */
27 : #undef TEST
28 : #define TEST(name) static void test_ ## name(void);
29 : ALL_TESTS
30 :
31 : static void
32 0 : report_wrong_error(int line)
33 : {
34 0 : fprintf(stderr, "%d:Wrong error type %d number %d (%#x)\n", line,
35 0 : ct_last_message.type, ct_last_message.number, ct_last_message.number);
36 0 : exit(1);
37 : }
38 :
39 : static CS_CONTEXT *ctx;
40 : static CS_CONNECTION *conn;
41 : static CS_COMMAND *cmd;
42 :
43 10 : TEST_MAIN()
44 : {
45 10 : int verbose = 1;
46 :
47 10 : printf("%s: Testing message callbacks\n", __FILE__);
48 : if (verbose) {
49 10 : printf("Trying login\n");
50 : }
51 10 : check_call(try_ctlogin, (&ctx, &conn, &cmd, verbose));
52 :
53 10 : check_call(cs_config, (ctx, CS_SET, CS_MESSAGE_CB, (CS_VOID*) cslibmsg_cb, CS_UNUSED, NULL));
54 :
55 : /* set different callback for the connection */
56 10 : check_call(ct_callback, (NULL, conn, CS_SET, CS_CLIENTMSG_CB, (CS_VOID*) clientmsg_cb2));
57 :
58 : /* call all tests */
59 : #undef TEST
60 : #define TEST(name) test_ ## name();
61 10 : ALL_TESTS
62 :
63 : if (verbose) {
64 10 : printf("Trying logout\n");
65 : }
66 10 : check_call(try_ctlogout, (ctx, conn, cmd, verbose));
67 :
68 : if (verbose) {
69 10 : printf("Test succeeded\n");
70 : }
71 10 : return 0;
72 : }
73 :
74 : static void
75 830 : _check_fail(const char *name, CS_RETCODE ret, int line)
76 : {
77 830 : if (ret != CS_FAIL) {
78 0 : fprintf(stderr, "%s():%d: succeeded\n", name, line);
79 0 : exit(1);
80 : }
81 830 : }
82 : #define check_fail(func, args) do { \
83 : ct_reset_last_message(); \
84 : _check_fail(#func, func args, __LINE__); \
85 : } while(0)
86 :
87 : static void
88 830 : _check_last_message(ct_message_type type, CS_INT number, const char *msg, int line)
89 : {
90 830 : bool type_ok = true, number_ok = true, msg_ok = true;
91 :
92 830 : if (type == CTMSG_NONE && ct_last_message.type == type)
93 : return;
94 :
95 770 : type_ok = (ct_last_message.type == type);
96 770 : number_ok = (ct_last_message.number == number);
97 770 : if (msg && msg[0])
98 760 : msg_ok = (strstr(ct_last_message.text, msg) != NULL);
99 770 : if (!type_ok || !number_ok || !msg_ok)
100 0 : report_wrong_error(line);
101 : }
102 : #define check_last_message(type, number, msg) \
103 : _check_last_message(type, number, msg, __LINE__)
104 :
105 : static void
106 10 : test_ct_callback(void)
107 : {
108 : void *ptr;
109 :
110 : /* this should fail, context or connection should be not NULL */
111 10 : check_fail(ct_callback, (NULL, NULL, CS_SET, CS_SERVERMSG_CB, servermsg_cb));
112 10 : check_last_message(CTMSG_NONE, 0, NULL);
113 :
114 : /* this should fail, context and connection cannot be both not NULL */
115 10 : check_fail(ct_callback, (ctx, conn, CS_SET, CS_SERVERMSG_CB, servermsg_cb));
116 10 : check_last_message(CTMSG_CLIENT2, 0x01010133, NULL);
117 :
118 : /* this should fail, invalid action */
119 10 : check_fail(ct_callback, (ctx, NULL, 3, CS_SERVERMSG_CB, servermsg_cb));
120 10 : check_last_message(CTMSG_CLIENT, 0x01010105, "action");
121 :
122 : /* this should fail, invalid action */
123 10 : check_fail(ct_callback, (NULL, conn, 3, CS_SERVERMSG_CB, servermsg_cb));
124 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, "action");
125 :
126 : /* this should fail, invalid type */
127 10 : check_fail(ct_callback, (ctx, NULL, CS_SET, 20, servermsg_cb));
128 10 : check_last_message(CTMSG_CLIENT, 0x01010105, "type");
129 :
130 : /* this should fail, invalid type */
131 10 : check_fail(ct_callback, (NULL, conn, CS_SET, 20, servermsg_cb));
132 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, "type");
133 :
134 : /* NULL func getting it */
135 10 : check_fail(ct_callback, (NULL, conn, CS_GET, CS_CLIENTMSG_CB, NULL));
136 10 : check_last_message(CTMSG_CLIENT2, 0x01010103, "The parameter func cannot be NULL");
137 :
138 10 : check_fail(ct_callback, (NULL, conn, CS_GET, CS_SERVERMSG_CB, NULL));
139 10 : check_last_message(CTMSG_CLIENT2, 0x01010103, "The parameter func cannot be NULL");
140 :
141 : /* invalid type with action CS_GET */
142 10 : check_fail(ct_callback, (NULL, conn, CS_GET, 20, NULL));
143 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, "An illegal value of 20 given for parameter type");
144 :
145 10 : ptr = (char*)0 + 123;
146 10 : check_fail(ct_callback, (NULL, conn, CS_GET, 20, &ptr));
147 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, "An illegal value of 20 given for parameter type");
148 10 : if (ptr != (char*)0 + 123) {
149 0 : fprintf(stderr, "Invalid pointer %p\n", ptr);
150 0 : exit(1);
151 : }
152 10 : }
153 :
154 : static void
155 10 : test_ct_res_info(void)
156 : {
157 : CS_RETCODE ret;
158 : CS_INT result_type;
159 : CS_INT num_cols;
160 : CS_INT count;
161 :
162 10 : check_call(ct_command, (cmd, CS_LANG_CMD, "SELECT 'hi' AS greeting", CS_NULLTERM, CS_UNUSED));
163 10 : check_call(ct_send, (cmd));
164 :
165 10 : while ((ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
166 20 : switch (result_type) {
167 : case CS_CMD_SUCCEED:
168 : case CS_CMD_DONE:
169 : break;
170 10 : case CS_ROW_RESULT:
171 : /* this should fail, invalid number */
172 10 : check_fail(ct_res_info, (cmd, 1234, &num_cols, CS_UNUSED, NULL));
173 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, "operation");
174 :
175 30 : while ((ret = ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &count)) == CS_SUCCEED)
176 10 : continue;
177 :
178 10 : if (ret != CS_END_DATA) {
179 0 : fprintf(stderr, "ct_fetch() unexpected return %d.\n", (int) ret);
180 0 : exit(1);
181 : }
182 : break;
183 0 : default:
184 0 : fprintf(stderr, "ct_results() unexpected result_type %d.\n", (int) result_type);
185 0 : exit(1);
186 : }
187 : }
188 10 : if (ret != CS_END_RESULTS) {
189 0 : fprintf(stderr, "ct_results() unexpected return %d.\n", (int) ret);
190 0 : exit(1);
191 : }
192 10 : }
193 :
194 : static void
195 10 : test_ct_send(void)
196 : {
197 : /* reset command to idle state */
198 10 : check_call(ct_cmd_drop, (cmd));
199 10 : check_call(ct_cmd_alloc, (conn, &cmd));
200 :
201 : /* this should fail, invalid command state */
202 10 : check_fail(ct_send, (cmd));
203 10 : check_last_message(CTMSG_CLIENT2, 0x0101019b, "idle");
204 10 : }
205 :
206 : static void
207 10 : test_cs_config(void)
208 : {
209 : /* a set of invalid, not accepted values */
210 : static const CS_INT invalid_values[] = {
211 : -1,
212 : -5,
213 : -200,
214 : CS_WILDCARD,
215 : CS_NO_LIMIT,
216 : CS_UNUSED,
217 : 0 /* terminator */
218 : };
219 : const CS_INT *p_invalid;
220 : CS_INT out_len;
221 : char out_buf[8];
222 :
223 10 : check_call(cs_config, (ctx, CS_SET, CS_USERDATA, (CS_VOID *)"test", CS_NULLTERM, NULL));
224 :
225 : /* check that value written does not have the NUL terminator */
226 10 : strcpy(out_buf, "123456");
227 10 : check_call(cs_config, (ctx, CS_GET, CS_USERDATA, (CS_VOID *)out_buf, 8, NULL));
228 10 : if (strcmp(out_buf, "test56") != 0) {
229 0 : fprintf(stderr, "Wrong output buffer '%s'\n", out_buf);
230 0 : exit(1);
231 : }
232 :
233 10 : check_call(cs_config, (ctx, CS_SET, CS_USERDATA, (CS_VOID *)"test123", 4, NULL));
234 :
235 : /* check that value written does not have more characters */
236 10 : strcpy(out_buf, "123456");
237 10 : check_call(cs_config, (ctx, CS_GET, CS_USERDATA, (CS_VOID *)out_buf, 8, NULL));
238 10 : if (strcmp(out_buf, "test56") != 0) {
239 0 : fprintf(stderr, "Wrong output buffer '%s'\n", out_buf);
240 0 : exit(1);
241 : }
242 :
243 60 : for (p_invalid = invalid_values; *p_invalid != 0; ++p_invalid) {
244 60 : check_fail(cs_config, (ctx, CS_SET, CS_USERDATA, (CS_VOID *)"test", *p_invalid, NULL));
245 60 : check_last_message(CTMSG_CSLIB, 0x02010106, "buflen");
246 : }
247 :
248 : /* wrong action */
249 10 : check_fail(cs_config, (ctx, 1000, CS_USERDATA, (CS_VOID *)"test", 4, NULL));
250 10 : check_last_message(CTMSG_CSLIB, 0x02010106, "action");
251 :
252 : /* wrong property */
253 10 : check_fail(cs_config, (ctx, CS_SET, 100000, NULL, CS_UNUSED, NULL));
254 10 : check_last_message(CTMSG_CSLIB, 0x02010106, "property");
255 :
256 : /* read exactly expected bytes */
257 10 : check_call(cs_config, (ctx, CS_GET, CS_USERDATA, (CS_VOID *)out_buf, 4, NULL));
258 :
259 : /* wrong buflen getting value */
260 10 : out_len = -123;
261 10 : check_fail(cs_config, (ctx, CS_GET, CS_USERDATA, (CS_VOID *)out_buf, CS_NULLTERM, &out_len));
262 10 : check_last_message(CTMSG_CSLIB, 0x02010106, "buflen");
263 10 : if (out_len != -123) {
264 0 : fprintf(stderr, "Wrong buffer length returned\n");
265 0 : exit(1);
266 : }
267 :
268 : /* shorter buffer */
269 10 : out_len = -123;
270 10 : strcpy(out_buf, "123456");
271 10 : check_fail(cs_config, (ctx, CS_GET, CS_USERDATA, (CS_VOID *)out_buf, 2, &out_len));
272 10 : check_last_message(CTMSG_CSLIB, 0x02010102, " 2 bytes");
273 10 : if (out_len != 4) {
274 0 : fprintf(stderr, "Wrong buffer length returned\n");
275 0 : exit(1);
276 : }
277 10 : if (strcmp(out_buf, "123456") != 0) {
278 0 : fprintf(stderr, "Wrong buffer returned\n");
279 0 : exit(1);
280 : }
281 10 : }
282 :
283 : static void
284 10 : test_blk_init(void)
285 : {
286 : CS_BLKDESC *blkdesc;
287 10 : check_call(blk_alloc, (conn, BLK_VERSION_100, &blkdesc));
288 :
289 : /* invalid direction */
290 10 : check_fail(blk_init, (blkdesc, 100, "testname", CS_NULLTERM));
291 10 : check_last_message(CTMSG_CLIENT2, 0x0101010f, "CS_BLK_IN or CS_BLK_OUT");
292 :
293 : /* invalid tablename */
294 10 : check_fail(blk_init, (blkdesc, CS_BLK_IN, NULL, CS_NULLTERM));
295 10 : check_last_message(CTMSG_CLIENT2, 0x01010106, "tblname cannot be NULL");
296 :
297 : /* invalid tablename length */
298 10 : check_fail(blk_init, (blkdesc, CS_BLK_IN, "testname", -4));
299 10 : check_last_message(CTMSG_CLIENT2, 0x01010104, "tblnamelen has an illegal value of -4");
300 :
301 10 : check_call(blk_drop, (blkdesc));
302 10 : }
303 :
304 : static void
305 10 : test_cs_loc_alloc(void)
306 : {
307 : /* no context or locale */
308 10 : check_fail(cs_loc_alloc, (NULL, NULL));
309 10 : check_last_message(CTMSG_NONE, 0, NULL);
310 :
311 : /* no locale */
312 10 : check_fail(cs_loc_alloc, (ctx, NULL));
313 10 : check_last_message(CTMSG_CSLIB, 0x02010104, " loc_pointer cannot be NULL");
314 10 : }
315 :
316 : static void
317 10 : test_cs_loc_drop(void)
318 : {
319 : /* no context or locale */
320 10 : check_fail(cs_loc_drop, (NULL, NULL));
321 10 : check_last_message(CTMSG_NONE, 0, NULL);
322 :
323 : /* no locale */
324 10 : check_fail(cs_loc_drop, (ctx, NULL));
325 10 : check_last_message(CTMSG_CSLIB, 0x02010104, " locale cannot be NULL");
326 10 : }
327 :
328 : static void
329 10 : test_cs_locale(void)
330 : {
331 : CS_LOCALE *locale;
332 :
333 10 : check_call(cs_loc_alloc, (ctx, &locale));
334 :
335 10 : check_call(cs_locale, (ctx, CS_SET, locale, CS_SYB_CHARSET, "utf8", 4, NULL));
336 :
337 : /* no context */
338 10 : check_fail(cs_locale, (NULL, CS_SET, locale, CS_SYB_CHARSET, "utf8", 4, NULL));
339 10 : check_last_message(CTMSG_NONE, 0, NULL);
340 :
341 : /* no locale */
342 10 : check_fail(cs_locale, (ctx, CS_SET, NULL, CS_SYB_CHARSET, "utf8", 4, NULL));
343 10 : check_last_message(CTMSG_CSLIB, 0x02010104, " locale cannot be NULL");
344 :
345 : /* wrong action */
346 10 : check_fail(cs_locale, (ctx, 1000, locale, CS_SYB_CHARSET, "utf8", 4, NULL));
347 10 : check_last_message(CTMSG_CSLIB, 0x02010106, " 1000 was given for parameter action");
348 :
349 : /* wrong type */
350 10 : check_fail(cs_locale, (ctx, CS_SET, locale, 1000, "utf8", 4, NULL));
351 10 : check_last_message(CTMSG_CSLIB, 0x02010106, " 1000 was given for parameter type");
352 :
353 : /* wrong length */
354 10 : check_fail(cs_locale, (ctx, CS_SET, locale, CS_SYB_CHARSET, "utf8", -4, NULL));
355 10 : check_last_message(CTMSG_CSLIB, 0x02010106, " -4 was given for parameter buflen");
356 :
357 10 : check_call(cs_loc_drop, (ctx, locale));
358 10 : }
359 :
360 : static void
361 10 : test_ct_dynamic(void)
362 : {
363 : /* wrong type */
364 10 : check_fail(ct_dynamic, (cmd, 10000, "test", CS_NULLTERM, "query", CS_NULLTERM));
365 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, " 10000 given for parameter type");
366 :
367 : /* wrong id length */
368 10 : check_fail(ct_dynamic, (cmd, CS_PREPARE, "test", -5, "query", CS_NULLTERM));
369 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, " -5 given for parameter idlen");
370 :
371 : /* wrong query length */
372 10 : check_fail(ct_dynamic, (cmd, CS_PREPARE, "test", CS_NULLTERM, "query", -6));
373 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, " -6 given for parameter buflen");
374 :
375 : /* wrong id and query length */
376 10 : check_fail(ct_dynamic, (cmd, CS_PREPARE, "test", -5, "query", -6));
377 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, " -5 given for parameter idlen");
378 :
379 : /* id not existing */
380 10 : check_fail(ct_dynamic, (cmd, CS_DEALLOC, "notexisting", CS_NULLTERM, NULL, CS_UNUSED));
381 10 : check_last_message(CTMSG_CLIENT2, 0x01010187, " specified id does not exist ");
382 :
383 : /* wrong id length */
384 10 : check_fail(ct_dynamic, (cmd, CS_DEALLOC, "notexisting", -7, NULL, CS_UNUSED));
385 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, " -7 given for parameter idlen");
386 10 : }
387 :
388 : static void
389 10 : test_ct_connect(void)
390 : {
391 : CS_CONNECTION *conn;
392 :
393 10 : check_call(ct_con_alloc, (ctx, &conn));
394 :
395 : /* wrong server name length */
396 10 : check_fail(ct_connect, (conn, "test", -5));
397 10 : check_last_message(CTMSG_CLIENT, 0x01010105, " -5 given for parameter snamelen");
398 :
399 10 : check_call(ct_con_drop, (conn));
400 10 : }
401 :
402 : static void
403 10 : test_ct_command(void)
404 : {
405 : /* wrong query length, CS_UNUSED, this was behaving differently */
406 10 : check_fail(ct_command, (cmd, CS_LANG_CMD, "test", CS_UNUSED, CS_UNUSED));
407 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, " given for parameter buflen");
408 :
409 : /* wrong query length */
410 10 : check_fail(ct_command, (cmd, CS_LANG_CMD, "test", -7, CS_UNUSED));
411 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, " -7 given for parameter buflen");
412 :
413 : /* wrong query length, RPC */
414 10 : check_fail(ct_command, (cmd, CS_RPC_CMD, "test", -3, CS_UNUSED));
415 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, " -3 given for parameter buflen");
416 10 : }
417 :
418 : static void
419 10 : test_ct_cursor(void)
420 : {
421 : /* wrong name length */
422 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_DECLARE, "test", -4, "query", CS_NULLTERM, CS_UNUSED));
423 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, " -4 given for parameter namelen");
424 :
425 : /* wrong query length */
426 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_DECLARE, "test", CS_NULLTERM, "query", -3, CS_UNUSED));
427 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, " -3 given for parameter tlen");
428 :
429 : /* wrong name and query length */
430 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_DECLARE, "test", -11, "query", -3, CS_UNUSED));
431 10 : check_last_message(CTMSG_CLIENT2, 0x01010105, " -11 given for parameter namelen");
432 :
433 : /* name present without cursor, priority to name */
434 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_ROWS, "name", CS_NULLTERM, NULL, CS_UNUSED, (CS_INT) 1));
435 10 : check_last_message(CTMSG_CLIENT2, 0x01010108, "The name parameter must be NULL");
436 :
437 : /* no cursor */
438 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_ROWS, NULL, CS_UNUSED, NULL, CS_UNUSED, (CS_INT) 1));
439 10 : check_last_message(CTMSG_CLIENT2, 0x01010112, "A cursor must be declared before this command type can be initialized");
440 :
441 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_CLOSE, NULL, CS_UNUSED, NULL, CS_UNUSED, CS_DEALLOC));
442 10 : check_last_message(CTMSG_CLIENT2, 0x010101ab, "A cursor must be opened before this command type can be initialized.");
443 :
444 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_DEALLOC, NULL, CS_UNUSED, NULL, CS_UNUSED, CS_UNUSED));
445 10 : check_last_message(CTMSG_CLIENT2, 0x01010112, "A cursor must be declared before this command type can be initialized");
446 :
447 : /* declare the cursor to allow following commands */
448 10 : check_call(ct_cursor, (cmd, CS_CURSOR_DECLARE, "test", CS_NULLTERM, "query", CS_NULLTERM, CS_UNUSED));
449 :
450 : /* name present */
451 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_ROWS, "name", CS_NULLTERM, "text", CS_NULLTERM, (CS_INT) 1));
452 10 : check_last_message(CTMSG_CLIENT2, 0x01010108, "The name parameter must be NULL");
453 :
454 : /* invalid name length */
455 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_ROWS, NULL, CS_NULLTERM, "text", CS_NULLTERM, (CS_INT) 1));
456 10 : check_last_message(CTMSG_CLIENT2, 0x01010109, "The namelen parameter must be set to CS_UNUSED");
457 :
458 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_ROWS, NULL, CS_UNUSED, "text", CS_NULLTERM, (CS_INT) 1));
459 10 : check_last_message(CTMSG_CLIENT2, 0x01010108, "The text parameter must be NULL");
460 :
461 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_ROWS, NULL, CS_UNUSED, NULL, CS_NULLTERM, (CS_INT) 1));
462 10 : check_last_message(CTMSG_CLIENT2, 0x01010109, "The tlen parameter must be set to CS_UNUSED");
463 :
464 : /* name present */
465 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_OPEN, "name", CS_NULLTERM, "text", CS_NULLTERM, CS_UNUSED));
466 10 : check_last_message(CTMSG_CLIENT2, 0x01010108, "The name parameter must be NULL");
467 :
468 : /* name length present */
469 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_OPEN, NULL, CS_NULLTERM, "text", CS_NULLTERM, CS_UNUSED));
470 10 : check_last_message(CTMSG_CLIENT2, 0x01010109, "The namelen parameter must be set to CS_UNUSED");
471 :
472 : /* text present */
473 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_OPEN, NULL, CS_UNUSED, "text", CS_NULLTERM, CS_UNUSED));
474 10 : check_last_message(CTMSG_CLIENT2, 0x01010108, "The text parameter must be NULL");
475 :
476 : /* text length present */
477 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_OPEN, NULL, CS_UNUSED, NULL, CS_NULLTERM, CS_UNUSED));
478 10 : check_last_message(CTMSG_CLIENT2, 0x01010109, "The tlen parameter must be set to CS_UNUSED");
479 :
480 : /* name, name length, text, text length all present */
481 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_CLOSE, "name", CS_NULLTERM, "text", CS_NULLTERM, CS_DEALLOC));
482 10 : check_last_message(CTMSG_CLIENT2, 0x01010108, "The name parameter must be NULL");
483 :
484 : /* name length present */
485 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_CLOSE, NULL, CS_NULLTERM, "text", CS_NULLTERM, CS_DEALLOC));
486 10 : check_last_message(CTMSG_CLIENT2, 0x01010109, "The namelen parameter must be set to CS_UNUSED");
487 :
488 : /* text present */
489 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_CLOSE, NULL, CS_UNUSED, "text", CS_NULLTERM, CS_DEALLOC));
490 10 : check_last_message(CTMSG_CLIENT2, 0x01010108, "The text parameter must be NULL");
491 :
492 : /* text length present */
493 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_CLOSE, NULL, CS_UNUSED, NULL, CS_NULLTERM, CS_DEALLOC));
494 10 : check_last_message(CTMSG_CLIENT2, 0x01010109, "The tlen parameter must be set to CS_UNUSED");
495 :
496 : /* name, name length, text, text length all present */
497 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_DEALLOC, "name", CS_NULLTERM, "text", CS_NULLTERM, CS_UNUSED));
498 10 : check_last_message(CTMSG_CLIENT2, 0x01010108, "The name parameter must be NULL");
499 :
500 : /* name length present */
501 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_DEALLOC, NULL, CS_NULLTERM, "text", CS_NULLTERM, CS_UNUSED));
502 10 : check_last_message(CTMSG_CLIENT2, 0x01010109, "The namelen parameter must be set to CS_UNUSED");
503 :
504 : /* text present */
505 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_DEALLOC, NULL, CS_UNUSED, "text", CS_NULLTERM, CS_UNUSED));
506 10 : check_last_message(CTMSG_CLIENT2, 0x01010108, "The text parameter must be NULL");
507 :
508 : /* text length present */
509 10 : check_fail(ct_cursor, (cmd, CS_CURSOR_DEALLOC, NULL, CS_UNUSED, NULL, CS_NULLTERM, CS_UNUSED));
510 10 : check_last_message(CTMSG_CLIENT2, 0x01010109, "The tlen parameter must be set to CS_UNUSED");
511 :
512 10 : }
513 :
514 : static void
515 10 : test_ct_con_props(void)
516 : {
517 : CS_CONNECTION *conn;
518 :
519 10 : check_call(ct_con_alloc, (ctx, &conn));
520 :
521 : /* wrong buffer length */
522 10 : check_fail(ct_con_props, (conn, CS_SET, CS_APPNAME, "app", -3, NULL));
523 10 : check_last_message(CTMSG_CLIENT, 0x01010105, " -3 given for parameter buflen");
524 :
525 : /* wrong buffer length, CS_UNUSED, it had a different behaviour */
526 10 : check_fail(ct_con_props, (conn, CS_SET, CS_APPNAME, "app", CS_UNUSED, NULL));
527 10 : check_last_message(CTMSG_CLIENT, 0x01010105, " given for parameter buflen");
528 :
529 10 : check_call(ct_con_drop, (conn));
530 :
531 10 : check_fail(ct_con_props, (NULL, CS_SET, CS_APPNAME, "app", 3, NULL));
532 10 : check_last_message(CTMSG_NONE, 0, NULL);
533 10 : }
534 :
535 : static void
536 10 : test_ct_cmd_props(void)
537 : {
538 : CS_INT props_value;
539 :
540 : /* wrong buffer length */
541 10 : check_fail(ct_cmd_props, (cmd, CS_GET, CS_CUR_STATUS, &props_value, sizeof(CS_INT), NULL));
542 10 : check_last_message(CTMSG_CLIENT2, 0x01010109, "The buflen parameter must be set to CS_UNUSED");
543 10 : }
544 :
545 : static void
546 10 : test_cs_convert(void)
547 : {
548 : CS_INT retlen;
549 : char outbuf[32];
550 :
551 : CS_DATAFMT destfmt, srcfmt;
552 10 : memset(&srcfmt, 0, sizeof(srcfmt));
553 10 : memset(&destfmt, 0, sizeof(destfmt));
554 :
555 : /* destdata == NULL */
556 10 : check_fail(cs_convert, (ctx, &srcfmt, "src", &destfmt, NULL, &retlen));
557 10 : check_last_message(CTMSG_CSLIB, 0x2010104, "The parameter destdata cannot be NULL");
558 :
559 : /* destfmt == NULL */
560 10 : check_fail(cs_convert, (ctx, &srcfmt, "src", NULL, outbuf, &retlen));
561 10 : check_last_message(CTMSG_CSLIB, 0x2010104, "The parameter destfmt cannot be NULL");
562 :
563 : /* destdata == NULL && destfmt == NULL */
564 10 : check_fail(cs_convert, (ctx, &srcfmt, "src", NULL, NULL, &retlen));
565 10 : check_last_message(CTMSG_CSLIB, 0x2010104, "The parameter destfmt cannot be NULL");
566 :
567 : /* invalid source type */
568 10 : srcfmt.datatype = 1234;
569 10 : check_fail(cs_convert, (ctx, &srcfmt, "src", &destfmt, outbuf, &retlen));
570 10 : check_last_message(CTMSG_CSLIB, 0x2010110, "Conversion between 1234 and 0 datatypes is not supported");
571 10 : srcfmt.datatype = 0;
572 :
573 : /* invalid destination type */
574 10 : destfmt.datatype = 1234;
575 10 : check_fail(cs_convert, (ctx, &srcfmt, "src", &destfmt, outbuf, &retlen));
576 10 : check_last_message(CTMSG_CSLIB, 0x2010110, "Conversion between 0 and 1234 datatypes is not supported");
577 10 : destfmt.datatype = 0;
578 :
579 : /* not fixed and maxlength == 0 */
580 10 : check_call(cs_convert, (ctx, &srcfmt, "src", &destfmt, outbuf, &retlen));
581 :
582 : /* not fixed and maxlength <= 0 */
583 10 : destfmt.maxlength = -1;
584 10 : check_fail(cs_convert, (ctx, &srcfmt, "src", &destfmt, outbuf, &retlen));
585 10 : check_last_message(CTMSG_CSLIB, 0x2010112,
586 : "An illegal value of -1 was placed in the maxlength field of the CS_DATAFMT structure");
587 : destfmt.maxlength = 0;
588 10 : }
589 :
590 : static void
591 10 : test_cs_dt_info(void)
592 : {
593 : CS_LOCALE *locale;
594 10 : CS_INT i_value = CS_DATES_SHORT;
595 : CS_INT len;
596 :
597 10 : check_call(cs_loc_alloc, (ctx, &locale));
598 :
599 10 : check_call(cs_dt_info, (ctx, CS_SET, locale, CS_DT_CONVFMT, CS_UNUSED, &i_value, sizeof(i_value), NULL));
600 :
601 : /* no context */
602 10 : check_fail(cs_dt_info, (NULL, CS_SET, locale, CS_DT_CONVFMT, CS_UNUSED, &i_value, sizeof(i_value), NULL));
603 10 : check_last_message(CTMSG_NONE, 0, NULL);
604 :
605 : /* wrong action */
606 10 : check_fail(cs_dt_info, (ctx, 1000, locale, CS_DT_CONVFMT, CS_UNUSED, &i_value, sizeof(i_value), NULL));
607 10 : check_last_message(CTMSG_CSLIB, 0x02010106, " 1000 was given for parameter action");
608 :
609 : /* wrong type, set */
610 10 : check_fail(cs_dt_info, (ctx, CS_SET, locale, 1000, CS_UNUSED, &i_value, sizeof(i_value), NULL));
611 10 : check_last_message(CTMSG_CSLIB, 0x02010106, " 1000 was given for parameter type");
612 :
613 : /* wrong type, get */
614 10 : len = sizeof(i_value);
615 10 : check_fail(cs_dt_info, (ctx, CS_GET, locale, 1000, CS_UNUSED, &i_value, sizeof(i_value), &len));
616 10 : check_last_message(CTMSG_CSLIB, 0x02010106, " 1000 was given for parameter type");
617 :
618 : /* wrong length */
619 10 : check_fail(cs_dt_info, (ctx, CS_SET, locale, CS_DT_CONVFMT, CS_UNUSED, &i_value, -4, NULL));
620 10 : check_last_message(CTMSG_CSLIB, 0x02010106, " -4 was given for parameter buflen");
621 :
622 : /* CS_NULLTERM as length is not accepted */
623 10 : check_fail(cs_dt_info, (ctx, CS_SET, locale, CS_DT_CONVFMT, CS_UNUSED, &i_value, CS_NULLTERM, NULL));
624 10 : check_last_message(CTMSG_CSLIB, 0x02010106, " -9 was given for parameter buflen");
625 :
626 : /* any other length seems accepted */
627 10 : check_call(cs_dt_info, (ctx, CS_SET, locale, CS_DT_CONVFMT, CS_UNUSED, &i_value, 0, NULL));
628 10 : check_call(cs_dt_info, (ctx, CS_SET, locale, CS_DT_CONVFMT, CS_UNUSED, &i_value, 1, NULL));
629 10 : check_call(cs_dt_info, (ctx, CS_SET, locale, CS_DT_CONVFMT, CS_UNUSED, &i_value, 100, NULL));
630 :
631 : /* invalid values are also accepted */
632 10 : i_value = -10000;
633 10 : check_call(cs_dt_info, (ctx, CS_SET, locale, CS_DT_CONVFMT, CS_UNUSED, &i_value, sizeof(i_value), NULL));
634 :
635 10 : check_call(cs_loc_drop, (ctx, locale));
636 10 : }
|