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

          Line data    Source code
       1             : /*
       2             :  * Purpose: Test that using a not available client character set is reported
       3             :  * once and with the name of the character set.
       4             :  */
       5             : 
       6             : #include "common.h"
       7             : 
       8             : #define CHARSET "NOSUCHCHARSET"
       9             : 
      10             : static int charset_errors = 0;
      11             : static int wrong_errors = 0;
      12             : 
      13             : static int
      14          10 : err_handler(DBPROCESS *dbproc TDS_UNUSED, int severity TDS_UNUSED, int dberr, int oserr TDS_UNUSED, char *dberrstr,
      15             :             char *oserrstr TDS_UNUSED)
      16             : {
      17          10 :         if (dberr != SYBEICONVAVAIL) {
      18           0 :                 fprintf(stderr, "unexpected error %d: %s\n", dberr, dberrstr);
      19           0 :                 ++wrong_errors;
      20           0 :                 return INT_CANCEL;
      21             :         }
      22             : 
      23          10 :         printf("got expected error: %s\n", dberrstr);
      24          10 :         ++charset_errors;
      25          10 :         if (strstr(dberrstr, "'" CHARSET "'") == NULL) {
      26           0 :                 fprintf(stderr, "character set name not reported: %s\n", dberrstr);
      27           0 :                 ++wrong_errors;
      28             :         }
      29             :         return INT_CANCEL;
      30             : }
      31             : 
      32          10 : TEST_MAIN()
      33             : {
      34             :         LOGINREC *login;
      35             :         DBPROCESS *dbproc;
      36             : 
      37          10 :         set_malloc_options();
      38             : 
      39          10 :         read_login_info(argc, argv);
      40             : 
      41          10 :         dbinit();
      42             : 
      43          10 :         dberrhandle(err_handler);
      44          10 :         dbmsghandle(syb_msg_handler);
      45             : 
      46          10 :         login = dblogin();
      47          10 :         DBSETLPWD(login, PASSWORD);
      48          10 :         DBSETLUSER(login, USER);
      49          10 :         DBSETLAPP(login, "charset_error");
      50          10 :         DBSETLCHARSET(login, CHARSET);
      51             : 
      52          10 :         dbproc = dbopen(login, SERVER);
      53          10 :         dbloginfree(login);
      54             : 
      55          10 :         if (dbproc) {
      56           0 :                 fprintf(stderr, "error: connection should fail\n");
      57           0 :                 dbclose(dbproc);
      58           0 :                 return 1;
      59             :         }
      60             : 
      61          10 :         dbexit();
      62             : 
      63          10 :         if (wrong_errors || charset_errors != 1) {
      64           0 :                 fprintf(stderr, "error: wrong errors %d, character set errors %d\n", wrong_errors, charset_errors);
      65           0 :                 return 1;
      66             :         }
      67             : 
      68          10 :         printf("OK\n");
      69          10 :         return 0;
      70             : }

Generated by: LCOV version 1.13