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-02-21 09:36:06 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             : int
      22          10 : main(void)
      23             : {
      24             :         SQLSMALLINT len, type;
      25             :         SQLTCHAR name[128];
      26             : 
      27          10 :         odbc_connect();
      28          10 :         odbc_command("create table #dc (col_name int, name2 varchar(100))");
      29             : 
      30          10 :         odbc_command("select * from #dc");
      31             : 
      32          10 :         len = 0x1234;
      33          10 :         CHKDescribeCol(1, NULL, 0, &len, &type, NULL, NULL, NULL, "S");
      34          20 :         check(len == 8);
      35             : 
      36          10 :         len = 0x1234;
      37          10 :         CHKDescribeCol(2, name, 0, &len, &type, NULL, NULL, NULL, "I");
      38          20 :         check(len == 5);
      39             : 
      40          10 :         len = 0x1234;
      41          10 :         CHKDescribeCol(1, NULL, 2, &len, &type, NULL, NULL, NULL, "S");
      42          20 :         check(len == 8);
      43             : 
      44          10 :         len = 0x1234;
      45          10 :         strcpy((char *) name, "xxx");
      46          10 :         CHKDescribeCol(2, name, 3, &len, &type, NULL, NULL, NULL, "I");
      47          20 :         check(len == 5 && strcmp(C(name), "na") == 0);
      48             : 
      49          10 :         len = 0x1234;
      50          10 :         strcpy((char *) name, "xxx");
      51          10 :         CHKDescribeCol(1, name, 1, &len, &type, NULL, NULL, NULL, "I");
      52          20 :         check(len == 8 && strcmp(C(name), "") == 0);
      53             : 
      54          10 :         len = 0x1234;
      55          10 :         strcpy((char *) name, "xxx");
      56          10 :         CHKDescribeCol(2, name, 6, &len, &type, NULL, NULL, NULL, "S");
      57          20 :         check(len == 5 && strcmp(C(name), "name2") == 0);
      58             : 
      59          10 :         odbc_disconnect();
      60             : 
      61          10 :         if (g_result == 0)
      62          10 :                 printf("Done.\n");
      63          10 :         return g_result;
      64             : }

Generated by: LCOV version 1.13