LCOV - code coverage report
Current view: top level - src/tds/unittests - utf8_3.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 38 59 64.4 %
Date: 2025-02-21 09:36:06 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
       2             :  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005  Brian Bruns
       3             :  * Copyright (C) 2010 Frediano Ziglio
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or
       6             :  * modify it under the terms of the GNU Library General Public
       7             :  * License as published by the Free Software Foundation; either
       8             :  * version 2 of the License, or (at your option) any later version.
       9             :  *
      10             :  * This library is distributed in the hope that it will be useful,
      11             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13             :  * Library General Public License for more details.
      14             :  *
      15             :  * You should have received a copy of the GNU Library General Public
      16             :  * License along with this library; if not, write to the
      17             :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      18             :  * Boston, MA 02111-1307, USA.
      19             :  */
      20             : #include "common.h"
      21             : 
      22             : #include <freetds/utils/string.h>
      23             : #include <freetds/replacements.h>
      24             : #include <ctype.h>
      25             : #include <assert.h>
      26             : 
      27             : static TDSSOCKET *tds;
      28             : 
      29             : static void
      30         328 : test(const char *buf)
      31             : {
      32             :         char query[1024];
      33             :         char tmp[129 * 3];
      34             :         int rc;
      35             :         TDS_INT result_type;
      36             :         int done_flags;
      37             : 
      38         328 :         to_utf8(buf, tmp);
      39         328 :         sprintf(query, "SELECT 1 AS [%s]", tmp);
      40             : 
      41             :         /* do a select and check all results */
      42         328 :         rc = tds_submit_query(tds, query);
      43         328 :         if (rc != TDS_SUCCESS) {
      44           0 :                 fprintf(stderr, "tds_submit_query() failed\n");
      45           0 :                 exit(1);
      46             :         }
      47             : 
      48         328 :         if (tds_process_tokens(tds, &result_type, NULL, TDS_TOKEN_RESULTS) != TDS_SUCCESS) {
      49           0 :                 fprintf(stderr, "tds_process_tokens() failed\n");
      50           0 :                 exit(1);
      51             :         }
      52             : 
      53         328 :         if (result_type != TDS_ROWFMT_RESULT) {
      54           0 :                 fprintf(stderr, "expected row fmt() failed\n");
      55           0 :                 exit(1);
      56             :         }
      57             : 
      58         328 :         if (tds_process_tokens(tds, &result_type, NULL, TDS_TOKEN_RESULTS) != TDS_SUCCESS) {
      59           0 :                 fprintf(stderr, "tds_process_tokens() failed\n");
      60           0 :                 exit(1);
      61             :         }
      62             : 
      63         328 :         if (result_type != TDS_ROW_RESULT) {
      64           0 :                 fprintf(stderr, "expected row result() failed\n");
      65           0 :                 exit(1);
      66             :         }
      67             : 
      68         656 :         while ((rc = tds_process_tokens(tds, &result_type, NULL, TDS_STOPAT_ROWFMT|TDS_STOPAT_DONE|TDS_RETURN_ROW|TDS_RETURN_COMPUTE)) == TDS_SUCCESS) {
      69             : 
      70             :                 TDSCOLUMN *curcol;
      71             : 
      72         656 :                 if (result_type != TDS_ROW_RESULT)
      73             :                         break;
      74             : 
      75         328 :                 curcol = tds->current_results->columns[0];
      76             : 
      77         656 :                 if (strcmp(tmp, tds_dstr_cstr(&curcol->column_name)) != 0) {
      78           0 :                         strlcpy(query, tds_dstr_cstr(&curcol->column_name), sizeof(query));
      79           0 :                         fprintf(stderr, "Wrong result Got: '%s' len %u\n        Expected: '%s' len %u\n", query,
      80           0 :                                 (unsigned) tds_dstr_len(&curcol->column_name), tmp, (unsigned int) strlen(tmp));
      81           0 :                         exit(1);
      82             :                 }
      83             :         }
      84             : 
      85         328 :         if (rc != TDS_SUCCESS || result_type == TDS_ROW_RESULT || result_type == TDS_COMPUTE_RESULT) {
      86           0 :                 fprintf(stderr, "tds_process_tokens() unexpected return\n");
      87           0 :                 exit(1);
      88             :         }
      89             : 
      90         656 :         while ((rc = tds_process_tokens(tds, &result_type, &done_flags, TDS_TOKEN_RESULTS)) == TDS_SUCCESS) {
      91         328 :                 switch (result_type) {
      92             :                 case TDS_NO_MORE_RESULTS:
      93           0 :                         return;
      94             : 
      95         328 :                 case TDS_DONE_RESULT:
      96             :                 case TDS_DONEPROC_RESULT:
      97             :                 case TDS_DONEINPROC_RESULT:
      98         328 :                         if (!(done_flags & TDS_DONE_ERROR))
      99             :                                 break;
     100             : 
     101             :                 default:
     102           0 :                         fprintf(stderr, "tds_proces_tokens() unexpected result_type\n");
     103           0 :                         exit(1);
     104             :                         break;
     105             :                 }
     106         328 :         }
     107             : }
     108             : 
     109             : int
     110          10 : main(void)
     111             : {
     112             :         TDSLOGIN *login;
     113             :         int ret;
     114          10 :         int verbose = 0;
     115             : 
     116             :         /* use UTF-8 as our coding */
     117          10 :         strcpy(CHARSET, "UTF-8");
     118             : 
     119          10 :         ret = try_tds_login(&login, &tds, __FILE__, verbose);
     120          10 :         if (ret != TDS_SUCCESS) {
     121           0 :                 fprintf(stderr, "try_tds_login() failed\n");
     122           0 :                 return 1;
     123             :         }
     124             : 
     125          10 :         if (IS_TDS7_PLUS(tds->conn)) {
     126             :                 char buf[129 * 8];
     127             :                 int i;
     128             : 
     129             :                 /* build a string of length 128 */
     130           8 :                 strcpy(buf, "");
     131        1032 :                 for (i = 1; i <= 128; ++i) {
     132        1024 :                         sprintf(strchr(buf, 0), "&#x%04x;", 0x4000 + i);
     133             :                 }
     134             : 
     135             :                 /* do all test */
     136             :                 for (i = 1;;) {
     137         328 :                         printf("Testing len %d\n", i);
     138         328 :                         test(buf + 8 * (128 - i));
     139         328 :                         if (i == 128)
     140             :                                 break;
     141         320 :                         ++i;
     142         320 :                         if (i > 12)
     143         232 :                                 i += 3;
     144         320 :                         if (i >= 128)
     145           8 :                                 i = 128;
     146             :                 }
     147             :         }
     148             : 
     149          10 :         try_tds_logout(login, tds, verbose);
     150          10 :         return 0;
     151             : }

Generated by: LCOV version 1.13