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-07-26 13:53:51 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.13