LTP GCOV extension - code coverage report
Current view: directory - tds/unittests - t0004.c
Test: FreeTDS coverage
Date: 2009-01-08 Instrumented lines: 50
Code covered: 58.0 % Executed lines: 29

       1                 : /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
       2                 :  * Copyright (C) 1998-1999  Brian Bruns
       3                 :  *
       4                 :  * This library is free software; you can redistribute it and/or
       5                 :  * modify it under the terms of the GNU Library General Public
       6                 :  * License as published by the Free Software Foundation; either
       7                 :  * version 2 of the License, or (at your option) any later version.
       8                 :  *
       9                 :  * This library is distributed in the hope that it will be useful,
      10                 :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11                 :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12                 :  * Library General Public License for more details.
      13                 :  *
      14                 :  * You should have received a copy of the GNU Library General Public
      15                 :  * License along with this library; if not, write to the
      16                 :  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      17                 :  * Boston, MA 02111-1307, USA.
      18                 :  */
      19                 : #include "common.h"
      20                 : 
      21                 : static char software_version[] = "$Id: t0004.c,v 1.19 2005/04/14 11:35:47 freddy77 Exp $";
      22                 : static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
      23                 : 
      24                 : char *varchar_as_string(TDSSOCKET * tds, int col_idx);
      25                 : 
      26                 : char *
      27                 : varchar_as_string(TDSSOCKET * tds, int col_idx)
      28               0 : {
      29                 :         static char result[256];
      30               0 :         const unsigned char *row = tds->res_info->current_row;
      31               0 :         const int offset = tds->res_info->columns[col_idx]->column_offset;
      32               0 :         const void *value = (row + offset);
      33                 : 
      34               0 :         strncpy(result, (const char *) value, sizeof(result) - 1);
      35               0 :         result[sizeof(result) - 1] = '\0';
      36               0 :         return result;
      37                 : }
      38                 : 
      39                 : 
      40                 : int
      41                 : main(int argc, char **argv)
      42               2 : {
      43                 :         TDSLOGIN *login;
      44                 :         TDSSOCKET *tds;
      45               2 :         int verbose = 0;
      46                 :         int rc;
      47                 : 
      48                 :         int result_type;
      49               2 :         int rows_returned = 0;
      50                 : 
      51                 :         const char *len200 =
      52               2 :                 "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
      53                 :         char long_query[1000];
      54                 : 
      55               2 :         sprintf(long_query,
      56                 :                 "SELECT name FROM #longquerytest WHERE (name = 'A%s' OR name = 'B%s' OR name = 'C%s' OR name = 'correct')", len200,
      57                 :                 len200, len200);
      58                 : 
      59               2 :         fprintf(stdout, "%s: Test large (>512 bytes) queries\n", __FILE__);
      60               2 :         rc = try_tds_login(&login, &tds, __FILE__, verbose);
      61               2 :         if (rc != TDS_SUCCEED) {
      62               0 :                 fprintf(stderr, "try_tds_login() failed\n");
      63               0 :                 return 1;
      64                 :         }
      65                 : 
      66                 :         /* do not check error here, if TABLE is not create this give error */
      67               2 :         rc = run_query(tds, "DROP TABLE #longquerytest");
      68               2 :         rc = run_query(tds, "CREATE TABLE #longquerytest (name varchar(255))");
      69               2 :         if (rc != TDS_SUCCEED) {
      70               0 :                 return 1;
      71                 :         }
      72               2 :         rc = run_query(tds, "INSERT #longquerytest (name) VALUES ('incorrect')");
      73               2 :         if (rc != TDS_SUCCEED) {
      74               0 :                 return 1;
      75                 :         }
      76               2 :         rc = run_query(tds, "INSERT #longquerytest (name) VALUES ('correct')");
      77               2 :         if (rc != TDS_SUCCEED) {
      78               0 :                 return 1;
      79                 :         }
      80                 : 
      81                 :         /*
      82                 :          * The heart of the test
      83                 :          */
      84               2 :         if (verbose) {
      85               0 :                 fprintf(stdout, "block size %d\n", tds->env.block_size);
      86                 :         }
      87               2 :         rc = tds_submit_query(tds, long_query);
      88               8 :         while ((rc = tds_process_tokens(tds, &result_type, NULL, TDS_RETURN_ROWFMT|TDS_RETURN_ROW)) == TDS_SUCCEED) {
      89               4 :                 switch (result_type) {
      90                 :                 case TDS_ROWFMT_RESULT:
      91               2 :                         if (tds->res_info->columns[0]->column_type != SYBVARCHAR) {
      92               0 :                                 fprintf(stderr, "Wrong column_type in %s\n", __FILE__);
      93               0 :                                 return 1;
      94                 :                         }
      95               2 :                         break;
      96                 :                 case TDS_ROW_RESULT:
      97               2 :                         ++rows_returned;
      98               2 :                         if (verbose) {
      99               0 :                                 printf("col 0 is %s\n", varchar_as_string(tds, 0));
     100                 :                         }
     101                 :                         break;
     102                 :                 default:
     103                 :                         break;
     104                 :                 }
     105                 :         }
     106               2 :         if (rc == TDS_FAIL) {
     107               0 :                 fprintf(stderr, "tds_process_tokens() returned TDS_FAIL for long query\n");
     108               0 :                 return 1;
     109               2 :         } else if (rc != TDS_NO_MORE_RESULTS) {
     110               0 :                 fprintf(stderr, "tds_process_tokens() unexpected return\n");
     111                 :         }
     112                 : 
     113               2 :         if (rows_returned != 1) {
     114               0 :                 fprintf(stderr, "%d rows returned, 1 expected\n", rows_returned);
     115               0 :                 return 1;
     116                 :         }
     117                 : 
     118                 :         /* do not check error here, if TABLE is not create this give error */
     119               2 :         rc = run_query(tds, "DROP TABLE #longquerytest");
     120                 : 
     121               2 :         try_tds_logout(login, tds, verbose);
     122               2 :         return 0;
     123                 : }

Generated by: LTP GCOV extension version 1.6