LCOV - code coverage report
Current view: top level - src/odbc/unittests - copydesc.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 23 25 92.0 %
Date: 2025-01-18 11:50:39 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : /* Test SQLCopyDesc and SQLAllocHandle(SQL_HANDLE_DESC) */
       4             : 
       5             : static void
       6          32 : check_alloc_type(SQLHDESC hdesc, SQLSMALLINT expected_alloc_type, const char *exp, int line)
       7             : {
       8             :         SQLSMALLINT alloc_type;
       9             :         SQLINTEGER ind;
      10             : 
      11          32 :         CHKGetDescField(hdesc, 0, SQL_DESC_ALLOC_TYPE, &alloc_type, sizeof(alloc_type), &ind, "S");
      12             : 
      13          32 :         if (alloc_type != expected_alloc_type) {
      14           0 :                 fprintf(stderr, "Wrong condition at line %d: SQL_DESC_ALLOC_TYPE expected %s(%d) got %d\n",
      15             :                         line, exp, expected_alloc_type, alloc_type);
      16           0 :                 exit(1);
      17             :         }
      18          32 : }
      19             : 
      20             : #define check_alloc_type(d,e) check_alloc_type(d, e, #e, __LINE__)
      21             : 
      22             : int
      23           8 : main(void)
      24             : {
      25             :         SQLHDESC ard, ard2, ard3;
      26             :         SQLINTEGER id;
      27             :         SQLLEN ind1, ind2;
      28             :         char name[64];
      29             : 
      30           8 :         odbc_connect();
      31             : 
      32           8 :         CHKGetStmtAttr(SQL_ATTR_APP_ROW_DESC, &ard, 0, NULL, "S");
      33           8 :         check_alloc_type(ard, SQL_DESC_ALLOC_AUTO);
      34             : 
      35           8 :         CHKBindCol(1, SQL_C_SLONG, &id, sizeof(SQLINTEGER), &ind1, "S");
      36           8 :         CHKBindCol(2, SQL_C_CHAR, name, sizeof(name), &ind2, "S");
      37             : 
      38           8 :         CHKAllocHandle(SQL_HANDLE_DESC, odbc_conn, &ard2, "S");
      39           8 :         check_alloc_type(ard2, SQL_DESC_ALLOC_USER);
      40             : 
      41             :         /*
      42             :          * this is an additional test to test additional allocation 
      43             :          * As of 0.64 for a bug in SQLAllocDesc we only allow to allocate one
      44             :          */
      45           8 :         CHKAllocHandle(SQL_HANDLE_DESC, odbc_conn, &ard3, "S");
      46           8 :         check_alloc_type(ard3, SQL_DESC_ALLOC_USER);
      47             : 
      48           8 :         CHKR(SQLCopyDesc, (ard, ard2), "S");
      49           8 :         check_alloc_type(ard2, SQL_DESC_ALLOC_USER);
      50             : 
      51           8 :         CHKFreeHandle(SQL_HANDLE_DESC, ard3, "S");
      52             : 
      53             :         /* check SQL_INVALID_HANDLE, twice to check a mutex condition */
      54           8 :         CHKR(SQLCopyDesc, (NULL, ard2), "V");
      55           8 :         CHKR(SQLCopyDesc, (ard2, NULL), "V");
      56           8 :         CHKR(SQLCopyDesc, (NULL, ard2), "V");
      57           8 :         CHKR(SQLCopyDesc, (ard2, NULL), "V");
      58             : 
      59           8 :         odbc_disconnect();
      60             : 
      61           8 :         printf("Done.\n");
      62             :         return 0;
      63             : }

Generated by: LCOV version 1.13