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-01-18 12:13:41 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.13