1 #include <config.h>
2
3 #include <stdio.h>
4
5 #ifdef HAVE_STRING_H
6 #include <string.h>
7 #endif
8
9 #include <cspublic.h>
10 #include <ctpublic.h>
11 #include "common.h"
12
13 int
main(int argc,char ** argv)14 main(int argc, char **argv)
15 {
16 int verbose = 1;
17 CS_CONTEXT *ctx;
18
19 CS_CHAR string_in[16], string_out[16];
20 CS_INT int_in, int_out;
21 CS_INT ret_len;
22
23 if (verbose) {
24 printf("Trying cs_config with CS_USERDATA\n\n");
25 }
26
27 if (cs_ctx_alloc(CS_VERSION_100, &ctx) != CS_SUCCEED) {
28 fprintf(stderr, "cs_ctx_alloc() for first context failed\n");
29 }
30 if (ct_init(ctx, CS_VERSION_100) != CS_SUCCEED) {
31 fprintf(stderr, "ct_init() for first context failed\n");
32 }
33
34 printf("Testing CS_SET/GET USERDATA with char array\n");
35
36 strcpy(string_in,"FreeTDS");
37
38 if (cs_config(ctx, CS_SET, CS_USERDATA, (CS_VOID *)string_in, CS_NULLTERM, NULL)
39 != CS_SUCCEED) {
40 fprintf(stderr, "cs_config() set failed\n");
41 return 1;
42 }
43 if (cs_config(ctx, CS_GET, CS_USERDATA, (CS_VOID *)string_out, 16, &ret_len)
44 != CS_SUCCEED) {
45 fprintf(stderr, "cs_config() get failed\n");
46 return 1;
47 }
48
49 if (strcmp(string_in, string_out)) {
50 printf("returned value >%s< not as stored >%s<\n", (char *)string_out, (char *)string_in);
51 return 1;
52 }
53 if (ret_len != (strlen(string_in) + 1)) {
54 printf("returned length >%d< not as expected >%u<\n", ret_len, (unsigned int) (strlen(string_in) + 1));
55 return 1;
56 }
57
58 printf("Testing CS_SET/GET USERDATA with char array\n");
59
60 strcpy(string_in,"FreeTDS");
61
62 if (cs_config(ctx, CS_SET, CS_USERDATA, (CS_VOID *)string_in, CS_NULLTERM, NULL)
63 != CS_SUCCEED) {
64 fprintf(stderr, "cs_config() set failed\n");
65 return 1;
66 }
67
68 strcpy(string_out,"XXXXXXXXXXXXXXX");
69
70 if (cs_config(ctx, CS_GET, CS_USERDATA, (CS_VOID *)string_out, 4, &ret_len)
71 != CS_SUCCEED) {
72 fprintf(stderr, "cs_config() get failed\n");
73 return 1;
74 }
75
76 if (strcmp(string_out, "FreeXXXXXXXXXXX")) {
77 printf("returned value >%s< not as expected >%s<\n", (char *)string_out, "FreeXXXXXXXXXXX");
78 return 1;
79 }
80 if (ret_len != (strlen(string_in) + 1)) {
81 printf("returned length >%d< not as expected >%u<\n", ret_len, (unsigned int) (strlen(string_in) + 1));
82 return 1;
83 }
84
85 printf("Testing CS_SET/GET USERDATA with int\n");
86
87 int_in = 255;
88
89 if (cs_config(ctx, CS_SET, CS_USERDATA, (CS_VOID *)&int_in, sizeof(int), NULL)
90 != CS_SUCCEED) {
91 fprintf(stderr, "cs_config() set failed\n");
92 return 1;
93 }
94 if (cs_config(ctx, CS_GET, CS_USERDATA, (CS_VOID *)&int_out, sizeof(int), &ret_len)
95 != CS_SUCCEED) {
96 fprintf(stderr, "cs_config() get failed\n");
97 return 1;
98 }
99
100 if (int_in != int_out) {
101 printf("returned value >%d< not as stored >%d<\n", int_out, int_in);
102 return 1;
103 }
104 if (ret_len != (sizeof(int))) {
105 printf("returned length >%d< not as expected >%u<\n", ret_len, (unsigned int) sizeof(int));
106 return 1;
107 }
108
109 cs_ctx_drop(ctx);
110
111 return 0;
112 }
113