Line data Source code
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
14 8 : main(int argc, char **argv)
15 : {
16 8 : 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 8 : printf("Trying cs_config with CS_USERDATA\n\n");
25 : }
26 :
27 8 : if (cs_ctx_alloc(CS_VERSION_100, &ctx) != CS_SUCCEED) {
28 0 : fprintf(stderr, "cs_ctx_alloc() for first context failed\n");
29 : }
30 8 : if (ct_init(ctx, CS_VERSION_100) != CS_SUCCEED) {
31 0 : fprintf(stderr, "ct_init() for first context failed\n");
32 : }
33 :
34 8 : printf("Testing CS_SET/GET USERDATA with char array\n");
35 :
36 8 : strcpy(string_in,"FreeTDS");
37 :
38 8 : if (cs_config(ctx, CS_SET, CS_USERDATA, (CS_VOID *)string_in, CS_NULLTERM, NULL)
39 : != CS_SUCCEED) {
40 0 : fprintf(stderr, "cs_config() set failed\n");
41 0 : return 1;
42 : }
43 8 : if (cs_config(ctx, CS_GET, CS_USERDATA, (CS_VOID *)string_out, 16, &ret_len)
44 : != CS_SUCCEED) {
45 0 : fprintf(stderr, "cs_config() get failed\n");
46 0 : return 1;
47 : }
48 :
49 8 : if (strcmp(string_in, string_out)) {
50 0 : printf("returned value >%s< not as stored >%s<\n", (char *)string_out, (char *)string_in);
51 0 : return 1;
52 : }
53 8 : if (ret_len != (strlen(string_in) + 1)) {
54 0 : printf("returned length >%d< not as expected >%u<\n", ret_len, (unsigned int) (strlen(string_in) + 1));
55 0 : return 1;
56 : }
57 :
58 8 : printf("Testing CS_SET/GET USERDATA with char array\n");
59 :
60 8 : strcpy(string_in,"FreeTDS");
61 :
62 8 : if (cs_config(ctx, CS_SET, CS_USERDATA, (CS_VOID *)string_in, CS_NULLTERM, NULL)
63 : != CS_SUCCEED) {
64 0 : fprintf(stderr, "cs_config() set failed\n");
65 0 : return 1;
66 : }
67 :
68 8 : strcpy(string_out,"XXXXXXXXXXXXXXX");
69 :
70 8 : if (cs_config(ctx, CS_GET, CS_USERDATA, (CS_VOID *)string_out, 4, &ret_len)
71 : != CS_SUCCEED) {
72 0 : fprintf(stderr, "cs_config() get failed\n");
73 0 : return 1;
74 : }
75 :
76 8 : if (strcmp(string_out, "FreeXXXXXXXXXXX")) {
77 0 : printf("returned value >%s< not as expected >%s<\n", (char *)string_out, "FreeXXXXXXXXXXX");
78 0 : return 1;
79 : }
80 8 : if (ret_len != (strlen(string_in) + 1)) {
81 0 : printf("returned length >%d< not as expected >%u<\n", ret_len, (unsigned int) (strlen(string_in) + 1));
82 0 : return 1;
83 : }
84 :
85 8 : printf("Testing CS_SET/GET USERDATA with int\n");
86 :
87 8 : int_in = 255;
88 :
89 8 : if (cs_config(ctx, CS_SET, CS_USERDATA, (CS_VOID *)&int_in, sizeof(int), NULL)
90 : != CS_SUCCEED) {
91 0 : fprintf(stderr, "cs_config() set failed\n");
92 0 : return 1;
93 : }
94 8 : if (cs_config(ctx, CS_GET, CS_USERDATA, (CS_VOID *)&int_out, sizeof(int), &ret_len)
95 : != CS_SUCCEED) {
96 0 : fprintf(stderr, "cs_config() get failed\n");
97 0 : return 1;
98 : }
99 :
100 8 : if (int_in != int_out) {
101 0 : printf("returned value >%d< not as stored >%d<\n", int_out, int_in);
102 0 : return 1;
103 : }
104 8 : if (ret_len != (sizeof(int))) {
105 0 : printf("returned length >%d< not as expected >%u<\n", ret_len, (unsigned int) sizeof(int));
106 0 : return 1;
107 : }
108 :
109 8 : cs_ctx_drop(ctx);
110 :
111 8 : return 0;
112 : }
|