LCOV - code coverage report
Current view: top level - src/ctlib/unittests - all_types.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 39 45 86.7 %
Date: 2026-11-07 23:58:45 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* try all types from server */
       2             : 
       3             : #include "common.h"
       4             : 
       5             : #include <ctlib.h>
       6             : 
       7             : #include <freetds/tds/all_types.h>
       8             : 
       9             : static CS_CONTEXT *ctx = NULL;
      10             : 
      11             : static void
      12        1210 : test_type(TDSSOCKET *tds TDS_UNUSED, TDSCOLUMN *col)
      13             : {
      14             :         TDSRESULTINFO *resinfo, *bindinfo;
      15             :         TDSCOLUMN *oldcol, *bindcol;
      16             :         char out_buf[256];
      17             :         CS_INT len;
      18             : 
      19             :         /* we should be able to support a type coming from server */
      20        1210 :         if (_ct_get_client_type(col, false) == CS_ILLEGAL_TYPE) {
      21           0 :                 fprintf(stderr, "not supported\n");
      22           0 :                 assert(0);
      23             :         }
      24             : 
      25             :         /* try to convert anyway, this should succeed */
      26        1210 :         resinfo = tds_alloc_results(1);
      27        1210 :         assert(resinfo);
      28        1210 :         bindinfo = tds_alloc_results(1);
      29        1210 :         assert(bindinfo);
      30             : 
      31             :         /* hack to pass our column to _ct_bind_data */
      32        1210 :         oldcol = resinfo->columns[0];
      33        1210 :         resinfo->columns[0] = col;
      34             : 
      35        1210 :         memset(out_buf, '-', sizeof(out_buf));
      36        1210 :         bindcol = bindinfo->columns[0];
      37        1210 :         bindcol->column_varaddr = out_buf;
      38        1210 :         bindcol->column_bindlen = sizeof(out_buf);
      39        1210 :         bindcol->column_bindtype = CS_CHAR_TYPE;
      40        1210 :         bindcol->column_bindfmt = CS_FMT_NULLTERM;
      41        1210 :         len = -1;
      42        1210 :         bindcol->column_lenbind = &len;
      43             : 
      44             :         /* every column should be at least be convertible to something */
      45        1210 :         if (_ct_bind_data(ctx, resinfo, bindinfo, 0)) {
      46           0 :                 fprintf(stderr, "conversion failed\n");
      47           0 :                 assert(0);
      48             :         }
      49             : 
      50             :         /* just safety, we use small data for now */
      51        1210 :         assert(len < sizeof(out_buf));
      52             : 
      53             :         /* we said terminated, check for terminator */
      54        1210 :         assert(len >= 1 && len < sizeof(out_buf));
      55        1210 :         assert(out_buf[len - 1] == 0);
      56        1210 :         printf("output (%d): %s\n", len, out_buf);
      57             : 
      58        1210 :         resinfo->columns[0] = oldcol;
      59        1210 :         tds_free_results(resinfo);
      60        1210 :         tds_free_results(bindinfo);
      61        1210 : }
      62             : 
      63          10 : TEST_MAIN()
      64             : {
      65             :         TDSCONTEXT *tds_ctx;
      66             :         TDSSOCKET *tds;
      67             : 
      68          10 :         tdsdump_topen(tds_dir_getenv(TDS_DIR("TDSDUMP")));
      69             : 
      70          10 :         check_call(cs_ctx_alloc, (CS_VERSION_100, &ctx));
      71             : 
      72          10 :         tds_ctx = tds_alloc_context(NULL);
      73          10 :         assert(tds_ctx);
      74          10 :         tds = tds_alloc_socket(tds_ctx, 512);
      75          10 :         assert(tds);
      76          10 :         tds->conn->use_iconv_in = 0;
      77          10 :         if (TDS_FAILED(tds_iconv_open(tds->conn, "UTF-8", 1))) {
      78           0 :                 fprintf(stderr, "Failed to initialize iconv\n");
      79           0 :                 return 1;
      80             :         }
      81             : 
      82          10 :         tds_all_types(tds, test_type);
      83             : 
      84          10 :         tds_free_socket(tds);
      85          10 :         tds_free_context(tds_ctx);
      86             : 
      87          10 :         cs_ctx_drop(ctx);
      88             : 
      89          10 :         return 0;
      90             : }

Generated by: LCOV version 1.13