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

Generated by: LCOV version 1.13