Line data Source code
1 : #include "common.h"
2 :
3 : #include <cspublic.h>
4 :
5 : /*
6 : * ct_send SQL |select name = @@servername|
7 : * ct_bind variable
8 : * ct_fetch and print results
9 : */
10 10 : TEST_MAIN()
11 : {
12 10 : int verbose = 1;
13 : CS_CONTEXT *ctx;
14 : CS_RETCODE ret;
15 : CS_DATAFMT srcfmt;
16 10 : CS_INT src = 32768;
17 : CS_DATAFMT dstfmt;
18 : CS_SMALLINT dst;
19 : CS_DATETIME dst_date;
20 :
21 : int i;
22 :
23 : CS_INT num_msgs;
24 : CS_CLIENTMSG client_message;
25 :
26 10 : printf("%s: Testing context callbacks\n", __FILE__);
27 :
28 10 : srcfmt.datatype = CS_INT_TYPE;
29 10 : srcfmt.maxlength = sizeof(CS_INT);
30 10 : srcfmt.locale = NULL;
31 :
32 10 : dstfmt.datatype = CS_SMALLINT_TYPE;
33 10 : dstfmt.maxlength = sizeof(CS_SMALLINT);
34 10 : dstfmt.locale = NULL;
35 :
36 : if (verbose) {
37 10 : printf("Trying clientmsg_cb with context\n");
38 : }
39 10 : check_call(cs_ctx_alloc, (CS_VERSION_100, &ctx));
40 10 : check_call(ct_init, (ctx, CS_VERSION_100));
41 :
42 10 : check_call(cs_diag, (ctx, CS_INIT, CS_UNUSED, CS_UNUSED, NULL));
43 :
44 10 : if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst, NULL) == CS_SUCCEED) {
45 0 : fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
46 0 : return 1;
47 : }
48 :
49 10 : dstfmt.datatype = CS_DATETIME_TYPE;
50 10 : dstfmt.maxlength = sizeof(CS_DATETIME);
51 10 : dstfmt.locale = NULL;
52 :
53 10 : if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst_date, NULL) == CS_SUCCEED) {
54 0 : fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
55 0 : return 1;
56 : }
57 :
58 10 : check_call(cs_diag, (ctx, CS_STATUS, CS_CLIENTMSG_TYPE, CS_UNUSED, &num_msgs));
59 :
60 30 : for (i = 0; i < num_msgs; i++ ) {
61 20 : check_call(cs_diag, (ctx, CS_GET, CS_CLIENTMSG_TYPE, i + 1, &client_message));
62 :
63 20 : cslibmsg_cb(NULL, &client_message);
64 : }
65 :
66 10 : if ((ret = cs_diag(ctx, CS_GET, CS_CLIENTMSG_TYPE, i + 1, &client_message)) != CS_NOMSG) {
67 0 : fprintf(stderr, "cs_diag(CS_GET) did not fail with CS_NOMSG\n");
68 0 : return 1;
69 : }
70 :
71 10 : check_call(cs_diag, (ctx, CS_CLEAR, CS_CLIENTMSG_TYPE, CS_UNUSED, NULL));
72 :
73 10 : check_call(cs_diag, (ctx, CS_STATUS, CS_CLIENTMSG_TYPE, CS_UNUSED, &num_msgs));
74 10 : if (num_msgs != 0) {
75 0 : fprintf(stderr, "cs_diag(CS_CLEAR) failed there are still %d messages on queue\n", num_msgs);
76 0 : return 1;
77 : }
78 :
79 10 : check_call(ct_exit, (ctx, CS_UNUSED));
80 10 : check_call(cs_ctx_drop, (ctx));
81 :
82 10 : return 0;
83 : }
|