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