LCOV - code coverage report
Current view: top level - src/odbc/unittests - describecol2.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 30 32 93.8 %
Date: 2025-05-13 09:49:23 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : #include <ctype.h>
       3             : 
       4             : /*
       5             :  * SQLDescribeCol test
       6             :  */
       7             : static int g_result = 0;
       8             : 
       9             : static void
      10             : do_check(int c, const char *test, int line)
      11             : {
      12          30 :         if (c)
      13             :                 return;
      14             : 
      15           0 :         fprintf(stderr, "Failed check %s at line %d\n", test, line);
      16           0 :         g_result = 1;
      17             : }
      18             : 
      19             : #define check(s) do_check(s, #s, __LINE__)
      20             : 
      21          10 : TEST_MAIN()
      22             : {
      23             :         SQLSMALLINT len, type;
      24             :         SQLTCHAR name[128];
      25             : 
      26          10 :         odbc_connect();
      27          10 :         odbc_command("create table #dc (col_name int, name2 varchar(100))");
      28             : 
      29          10 :         odbc_command("select * from #dc");
      30             : 
      31          10 :         len = 0x1234;
      32          10 :         CHKDescribeCol(1, NULL, 0, &len, &type, NULL, NULL, NULL, "S");
      33          20 :         check(len == 8);
      34             : 
      35          10 :         len = 0x1234;
      36          10 :         CHKDescribeCol(2, name, 0, &len, &type, NULL, NULL, NULL, "I");
      37          20 :         check(len == 5);
      38             : 
      39          10 :         len = 0x1234;
      40          10 :         CHKDescribeCol(1, NULL, 2, &len, &type, NULL, NULL, NULL, "S");
      41          20 :         check(len == 8);
      42             : 
      43          10 :         len = 0x1234;
      44          10 :         strcpy((char *) name, "xxx");
      45          10 :         CHKDescribeCol(2, name, 3, &len, &type, NULL, NULL, NULL, "I");
      46          20 :         check(len == 5 && strcmp(C(name), "na") == 0);
      47             : 
      48          10 :         len = 0x1234;
      49          10 :         strcpy((char *) name, "xxx");
      50          10 :         CHKDescribeCol(1, name, 1, &len, &type, NULL, NULL, NULL, "I");
      51          20 :         check(len == 8 && strcmp(C(name), "") == 0);
      52             : 
      53          10 :         len = 0x1234;
      54          10 :         strcpy((char *) name, "xxx");
      55          10 :         CHKDescribeCol(2, name, 6, &len, &type, NULL, NULL, NULL, "S");
      56          20 :         check(len == 5 && strcmp(C(name), "name2") == 0);
      57             : 
      58          10 :         odbc_disconnect();
      59             : 
      60          10 :         if (g_result == 0)
      61          10 :                 printf("Done.\n");
      62          10 :         return g_result;
      63             : }

Generated by: LCOV version 1.13