LCOV - code coverage report
Current view: top level - src/ctlib/unittests - cs_config.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 27 39 69.2 %
Date: 2025-01-18 11:50:39 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : #include <cspublic.h>
       4             : 
       5             : int
       6           8 : main(void)
       7             : {
       8           8 :         int verbose = 1;
       9             :         CS_CONTEXT *ctx;
      10             : 
      11             :         CS_CHAR string_in[16], string_out[16];
      12             :         CS_INT  int_in,        int_out;
      13             :         CS_INT ret_len;
      14             : 
      15             :         if (verbose) {
      16           8 :                 printf("Trying cs_config with CS_USERDATA\n\n");
      17             :         }
      18             : 
      19           8 :         check_call(cs_ctx_alloc, (CS_VERSION_100, &ctx));
      20           8 :         check_call(ct_init, (ctx, CS_VERSION_100));
      21             : 
      22           8 :         printf("Testing CS_SET/GET USERDATA with char array\n");
      23             : 
      24           8 :         strcpy(string_in,"FreeTDS");
      25             : 
      26           8 :         check_call(cs_config, (ctx, CS_SET, CS_USERDATA, (CS_VOID *)string_in,  CS_NULLTERM, NULL));
      27           8 :         strcpy(string_out,"XXXXXXXXXXXXXXX");
      28           8 :         check_call(cs_config, (ctx, CS_GET, CS_USERDATA, (CS_VOID *)string_out, 16, &ret_len));
      29             : 
      30           8 :         if (strcmp(string_out, "FreeTDSXXXXXXXX")) {
      31           0 :                 printf("returned value >%s< not as stored >%s<\n", (char *)string_out, (char *)string_in);
      32           0 :                 return 1;
      33             :         }
      34           8 :         if (ret_len < 0 || (CS_UINT) ret_len != strlen(string_in)) {
      35           0 :                 printf("returned length >%d< not as expected >%d<\n", ret_len, (int) strlen(string_in));
      36           0 :                 return 1;
      37             :         }
      38             : 
      39           8 :         printf("Testing CS_SET/GET USERDATA with char array\n");
      40             : 
      41           8 :         strcpy(string_in,"FreeTDS");
      42             : 
      43           8 :         check_call(cs_config, (ctx, CS_SET, CS_USERDATA, (CS_VOID *)string_in,  CS_NULLTERM, NULL));
      44             : 
      45           8 :         strcpy(string_out,"XXXXXXXXXXXXXXX");
      46             : 
      47           8 :         check_call(cs_config, (ctx, CS_GET, CS_USERDATA, (CS_VOID *)string_out, 7, &ret_len));
      48             : 
      49           8 :         if (strcmp(string_out, "FreeTDSXXXXXXXX")) {
      50           0 :                 printf("returned value >%s< not as expected >%s<\n", (char *)string_out, "FreeTDSXXXXXXXX");
      51           0 :                 return 1;
      52             :         }
      53           8 :         if (ret_len < 0 || (CS_UINT) ret_len != strlen(string_in)) {
      54           0 :                 printf("returned length >%d< not as expected >%d<\n", ret_len, (int) strlen(string_in));
      55           0 :                 return 1;
      56             :         }
      57             : 
      58           8 :         printf("Testing CS_SET/GET USERDATA with int\n");
      59             : 
      60           8 :         int_in = 255;
      61             : 
      62           8 :         check_call(cs_config, (ctx, CS_SET, CS_USERDATA, (CS_VOID *)&int_in,  sizeof(int), NULL));
      63           8 :         check_call(cs_config, (ctx, CS_GET, CS_USERDATA, (CS_VOID *)&int_out, sizeof(int), &ret_len));
      64             : 
      65           8 :         if (int_in != int_out) {
      66           0 :                 printf("returned value >%d< not as stored >%d<\n", int_out, int_in);
      67           0 :                 return 1;
      68             :         }
      69           8 :         if (ret_len != (sizeof(int))) {
      70           0 :                 printf("returned length >%d< not as expected >%u<\n", ret_len, (unsigned int) sizeof(int));
      71           0 :                 return 1;
      72             :         }
      73             : 
      74           8 :         cs_ctx_drop(ctx);
      75             : 
      76           8 :         return 0;
      77             : }

Generated by: LCOV version 1.13