LCOV - code coverage report
Current view: top level - src/odbc/unittests - utf8_4.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 39 46 84.8 %
Date: 2025-04-20 18:15:36 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : #include <assert.h>
       3             : #include <freetds/utils/string.h>
       4             : #include <freetds/odbc.h>
       5             : 
       6             : /* test some internal funcions */
       7             : 
       8             : #ifdef ENABLE_ODBC_WIDE
       9             : static void
      10         170 : wide_test(const SQLWCHAR* input, size_t input_len, const char *exp, int line)
      11             : {
      12         170 :         DSTR s = DSTR_INITIALIZER;
      13             :         SQLWCHAR outbuf[16];
      14             :         SQLINTEGER outlen;
      15             : 
      16         170 :         odbc_dstr_copy_flag((TDS_DBC *) odbc_conn, &s, (int) input_len, (ODBC_CHAR*) input, 1);
      17         510 :         if (strlen(exp) != tds_dstr_len(&s) || strcmp(exp, tds_dstr_cstr(&s)) != 0) {
      18           0 :                 fprintf(stderr, "%d: Wrong, len %u: %s\n", line,
      19           0 :                         (unsigned) tds_dstr_len(&s), tds_dstr_cstr(&s));
      20           0 :                 exit(1);
      21             :         }
      22         170 :         outlen = -1;
      23         170 :         odbc_set_string_flag((TDS_DBC *) odbc_conn, outbuf, TDS_VECTOR_SIZE(outbuf), &outlen,
      24         170 :                              tds_dstr_cstr(&s), (int) tds_dstr_len(&s), 0x11);
      25         170 :         if (outlen < 0 || outlen !=input_len
      26         170 :             || memcmp(outbuf, input, input_len * sizeof(input[0])) != 0) {
      27           0 :                 fprintf(stderr, "%d: out_len %u %x %x %x\n", line, (unsigned) outlen, outbuf[0], outbuf[1], outbuf[2]);
      28           0 :                 exit(1);
      29             :         }
      30         170 :         tds_dstr_free(&s);
      31         170 : }
      32             : #endif
      33             : 
      34          10 : TEST_MAIN()
      35             : {
      36             : #ifdef ENABLE_ODBC_WIDE
      37          10 :         DSTR s = DSTR_INITIALIZER;
      38             : 
      39             :         /* just allocate handles, we don't need to connect */
      40          10 :         CHKAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &odbc_env, "S");
      41          10 :         SQLSetEnvAttr(odbc_env, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) (SQL_OV_ODBC3), SQL_IS_UINTEGER);
      42          10 :         CHKAllocHandle(SQL_HANDLE_DBC, odbc_env, &odbc_conn, "S");
      43             : 
      44             :         /* check is FreeTDS, if not just return */
      45          10 :         if (!odbc_driver_is_freetds()) {
      46           0 :                 odbc_disconnect();
      47           0 :                 return 0;
      48             :         }
      49             : 
      50          10 :         odbc_dstr_copy_flag((TDS_DBC *) odbc_conn, &s, 3, (ODBC_CHAR*) "foo", 0);
      51          20 :         assert(strcmp("foo", tds_dstr_cstr(&s)) == 0);
      52             : 
      53             : #define WIDE_TEST(chars, exp) do { \
      54             :         static const SQLWCHAR input[] = chars; \
      55             :         wide_test(input, TDS_VECTOR_SIZE(input), exp, __LINE__); \
      56             : } while(0)
      57             : #define SEP ,
      58             : 
      59          10 :         WIDE_TEST({ 'f' SEP 'o' SEP 'o' }, "foo");
      60          10 :         WIDE_TEST({ 0x41 }, "A");
      61          10 :         WIDE_TEST({ 0xA1 }, "\xc2\xA1");
      62          10 :         WIDE_TEST({ 0x81 }, "\xc2\x81");
      63          10 :         WIDE_TEST({ 0x101 }, "\xc4\x81");
      64          10 :         WIDE_TEST({ 0x201 }, "\xc8\x81");
      65          10 :         WIDE_TEST({ 0x401 }, "\xd0\x81");
      66          10 :         WIDE_TEST({ 0x801 }, "\xe0\xa0\x81");
      67          10 :         WIDE_TEST({ 0x1001 }, "\xe1\x80\x81");
      68          10 :         WIDE_TEST({ 0x2001 }, "\xe2\x80\x81");
      69          10 :         WIDE_TEST({ 0x4001 }, "\xe4\x80\x81");
      70          10 :         WIDE_TEST({ 0x8001 }, "\xe8\x80\x81");
      71             : #if SIZEOF_SQLWCHAR == 2
      72          10 :         WIDE_TEST({ 0xd800 SEP 0xdc01 }, "\xf0\x90\x80\x81");
      73          10 :         WIDE_TEST({ 0xd800 SEP 0xdd01 }, "\xf0\x90\x84\x81");
      74          10 :         WIDE_TEST({ 0xd840 SEP 0xdd01 }, "\xf0\xa0\x84\x81");
      75          10 :         WIDE_TEST({ 0xd8c0 SEP 0xdd01 }, "\xf1\x80\x84\x81");
      76          10 :         WIDE_TEST({ 0xd9c0 SEP 0xdd01 }, "\xf2\x80\x84\x81");
      77             : #else
      78             :         WIDE_TEST({ 0x10001 }, "\xf0\x90\x80\x81");
      79             : #endif
      80             : 
      81          10 :         tds_dstr_free(&s);
      82          10 :         odbc_disconnect();
      83             : #endif
      84          10 :         return 0;
      85             : }
      86             : 

Generated by: LCOV version 1.13