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_CONNECTION *conn;
15 : CS_COMMAND *cmd;
16 : CS_DATAFMT srcfmt;
17 10 : CS_INT src = 32768;
18 : CS_DATAFMT dstfmt;
19 : CS_DATETIME dst;
20 :
21 10 : printf("%s: Testing context callbacks\n", __FILE__);
22 10 : srcfmt.datatype = CS_INT_TYPE;
23 10 : srcfmt.maxlength = sizeof(CS_INT);
24 10 : srcfmt.locale = NULL;
25 :
26 10 : dstfmt.datatype = CS_DATETIME_TYPE;
27 10 : dstfmt.maxlength = sizeof(CS_SMALLINT);
28 10 : dstfmt.locale = NULL;
29 :
30 : if (verbose) {
31 10 : printf("Trying clientmsg_cb with context\n");
32 : }
33 10 : check_call(cs_ctx_alloc, (CS_VERSION_100, &ctx));
34 10 : check_call(ct_init, (ctx, CS_VERSION_100));
35 :
36 10 : check_call(ct_callback, (ctx, NULL, CS_SET, CS_CLIENTMSG_CB, (CS_VOID*) clientmsg_cb));
37 10 : clientmsg_cb_invoked = 0;
38 10 : if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst, NULL) == CS_SUCCEED) {
39 0 : fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
40 0 : return 1;
41 : }
42 10 : if (clientmsg_cb_invoked != 0) {
43 0 : fprintf(stderr, "clientmsg_cb was invoked!\n");
44 0 : return 1;
45 : }
46 :
47 : if (verbose) {
48 10 : printf("Trying cslibmsg_cb\n");
49 : }
50 10 : check_call(cs_config, (ctx, CS_SET, CS_MESSAGE_CB, (CS_VOID*) cslibmsg_cb, CS_UNUSED, NULL));
51 10 : cslibmsg_cb_invoked = 0;
52 10 : if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst, NULL) == CS_SUCCEED) {
53 0 : fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
54 0 : return 1;
55 : }
56 10 : if (cslibmsg_cb_invoked == 0) {
57 0 : fprintf(stderr, "cslibmsg_cb was not invoked!\n");
58 0 : return 1;
59 : }
60 :
61 10 : check_call(ct_exit, (ctx, CS_UNUSED));
62 10 : check_call(cs_ctx_drop, (ctx));
63 :
64 : if (verbose) {
65 10 : printf("Trying login\n");
66 : }
67 10 : check_call(try_ctlogin, (&ctx, &conn, &cmd, verbose));
68 :
69 : if (verbose) {
70 10 : printf("Trying clientmsg_cb with connection\n");
71 : }
72 10 : check_call(ct_callback, (NULL, conn, CS_SET, CS_CLIENTMSG_CB, (CS_VOID *) clientmsg_cb));
73 10 : clientmsg_cb_invoked = 0;
74 10 : run_command(cmd, ".");
75 10 : if (clientmsg_cb_invoked) {
76 0 : fprintf(stderr, "clientmsg_cb was invoked!\n");
77 0 : return 1;
78 : }
79 :
80 : if (verbose) {
81 10 : printf("Trying servermsg_cb with connection\n");
82 : }
83 10 : check_call(ct_callback, (NULL, conn, CS_SET, CS_SERVERMSG_CB, (CS_VOID *) servermsg_cb));
84 10 : servermsg_cb_invoked = 0;
85 : #if 0
86 : check_call(run_command, (cmd, "raiserror 99999 'This is a test'"));
87 : check_call(run_command, (cmd, "raiserror('This is a test', 17, 1)"));
88 : #else
89 10 : check_call(run_command, (cmd, "print 'This is a test'"));
90 : #endif
91 10 : if (servermsg_cb_invoked == 0) {
92 0 : fprintf(stderr, "servermsg_cb was not invoked!\n");
93 0 : return 1;
94 : }
95 :
96 : if (verbose) {
97 10 : printf("Trying logout\n");
98 : }
99 10 : check_call(try_ctlogout, (ctx, conn, cmd, verbose));
100 :
101 10 : return 0;
102 : }
|