LTP GCOV extension - code coverage report
Current view: directory - dblib/unittests - t0008.c
Test: FreeTDS coverage
Date: 2008-11-21 Instrumented lines: 97
Code covered: 77.3 % Executed lines: 75

       1                 : /* 
       2                 :  * Purpose: Test buffering.  As of April 2005, jkl believes this test is broken. 
       3                 :  * Functions: dbclrbuf dbsetopt 
       4                 :  */
       5                 : 
       6                 : #if HAVE_CONFIG_H
       7                 : #include <config.h>
       8                 : #endif /* HAVE_CONFIG_H */
       9                 : 
      10                 : #include <stdio.h>
      11                 : 
      12                 : #if HAVE_STDLIB_H
      13                 : #include <stdlib.h>
      14                 : #endif /* HAVE_STDLIB_H */
      15                 : 
      16                 : #if HAVE_STRING_H
      17                 : #include <string.h>
      18                 : #endif /* HAVE_STRING_H */
      19                 : 
      20                 : #include <sqlfront.h>
      21                 : #include <sqldb.h>
      22                 : 
      23                 : #include "common.h"
      24                 : 
      25                 : 
      26                 : 
      27                 : static char software_version[] = "$Id: t0008.c,v 1.13 2005/05/23 08:06:25 freddy77 Exp $";
      28                 : static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
      29                 : 
      30                 : 
      31                 : 
      32                 : int
      33                 : main(int argc, char **argv)
      34               2 : {
      35               2 :         const int rows_to_add = 50;
      36                 :         LOGINREC *login;
      37                 :         DBPROCESS *dbproc;
      38                 :         int i;
      39                 :         char teststr[1024];
      40                 :         DBINT testint;
      41               2 :         DBINT last_read = -1;
      42                 : 
      43               2 :         set_malloc_options();
      44                 : 
      45               2 :         read_login_info(argc, argv);
      46                 : 
      47               2 :         fprintf(stdout, "Start\n");
      48               2 :         add_bread_crumb();
      49                 : 
      50                 :         /* Fortify_EnterScope(); */
      51               2 :         dbinit();
      52                 : 
      53               2 :         add_bread_crumb();
      54               2 :         dberrhandle(syb_err_handler);
      55               2 :         dbmsghandle(syb_msg_handler);
      56                 : 
      57               2 :         fprintf(stdout, "About to logon\n");
      58                 : 
      59               2 :         add_bread_crumb();
      60               2 :         login = dblogin();
      61               2 :         DBSETLPWD(login, PASSWORD);
      62               2 :         DBSETLUSER(login, USER);
      63               2 :         DBSETLAPP(login, "t0008");
      64               2 :         DBSETLHOST(login, "ntbox.dntis.ro");
      65                 : 
      66               2 :         fprintf(stdout, "About to open\n");
      67                 : 
      68               2 :         add_bread_crumb();
      69               2 :         dbproc = dbopen(login, SERVER);
      70               2 :         if (strlen(DATABASE))
      71               2 :                 dbuse(dbproc, DATABASE);
      72               2 :         add_bread_crumb();
      73               2 :         dbloginfree(login);
      74               2 :         add_bread_crumb();
      75                 : 
      76                 : #ifdef MICROSOFT_DBLIB
      77                 :         dbsetopt(dbproc, DBBUFFER, "25");
      78                 : #else
      79               2 :         dbsetopt(dbproc, DBBUFFER, "25", 0);
      80                 : #endif
      81               2 :         add_bread_crumb();
      82                 : 
      83               2 :         fprintf(stdout, "creating table\n");
      84               2 :         dbcmd(dbproc, "create table #dblib0008 (i int not null, s char(10) not null)");
      85               2 :         dbsqlexec(dbproc);
      86               4 :         while (dbresults(dbproc) != NO_MORE_RESULTS) {
      87                 :                 /* nop */
      88                 :         }
      89                 : 
      90               2 :         fprintf(stdout, "insert\n");
      91             100 :         for (i = 1; i < rows_to_add; i++) {
      92                 :         char cmd[1024];
      93                 : 
      94              98 :                 sprintf(cmd, "insert into #dblib0008 values (%d, 'row %03d')", i, i);
      95              98 :                 dbcmd(dbproc, cmd);
      96              98 :                 dbsqlexec(dbproc);
      97             196 :                 while (dbresults(dbproc) != NO_MORE_RESULTS) {
      98                 :                         /* nop */
      99                 :                 }
     100                 :         }
     101                 : 
     102               2 :         fprintf(stdout, "select\n");
     103               2 :         dbcmd(dbproc, "select * from #dblib0008 order by i");
     104               2 :         dbsqlexec(dbproc);
     105               2 :         add_bread_crumb();
     106                 : 
     107                 : 
     108               2 :         if (dbresults(dbproc) != SUCCEED) {
     109               0 :                 add_bread_crumb();
     110               0 :                 fprintf(stdout, "Was expecting a result set.");
     111               0 :                 exit(1);
     112                 :         }
     113               2 :         add_bread_crumb();
     114                 : 
     115               6 :         for (i = 1; i <= dbnumcols(dbproc); i++) {
     116               4 :                 add_bread_crumb();
     117               4 :                 printf("col %d is %s\n", i, dbcolname(dbproc, i));
     118               4 :                 add_bread_crumb();
     119                 :         }
     120                 : 
     121               2 :         add_bread_crumb();
     122               2 :         dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & testint);
     123               2 :         add_bread_crumb();
     124               2 :         dbbind(dbproc, 2, STRINGBIND, -1, (BYTE *) teststr);
     125               2 :         add_bread_crumb();
     126                 : 
     127               2 :         add_bread_crumb();
     128                 : 
     129             100 :         for (i = 1; i < rows_to_add; i++) {
     130                 :         char expected[1024];
     131                 : 
     132              98 :                 sprintf(expected, "row %03d", i);
     133                 : 
     134              98 :                 add_bread_crumb();
     135                 : 
     136              98 :                 if (i % 25 == 0) {
     137               2 :                         dbclrbuf(dbproc, 25);
     138                 :                 }
     139                 : 
     140              98 :                 add_bread_crumb();
     141              98 :                 if (REG_ROW != dbnextrow(dbproc)) {
     142               0 :                         fprintf(stderr, "dblib failed for %s\n", __FILE__);
     143               0 :                         add_bread_crumb();
     144               0 :                         dbexit();
     145               0 :                         add_bread_crumb();
     146                 : 
     147               0 :                         free_bread_crumb();
     148               0 :                         return 1;
     149                 :                 }
     150              98 :                 add_bread_crumb();
     151              98 :                 last_read = testint;
     152              98 :                 if (testint < 1 || testint > rows_to_add) {
     153               0 :                         fprintf(stderr, "dblib failed for %s\n", __FILE__);
     154               0 :                         exit(1);
     155                 :                 }
     156              98 :                 if (testint != i) {
     157               0 :                         fprintf(stderr, "Failed.  Expected i to be %d, was %d\n", i, (int) testint);
     158               0 :                         abort();
     159                 :                 }
     160              98 :                 if (0 != strncmp(teststr, expected, strlen(expected))) {
     161               0 :                         fprintf(stdout, "Failed.  Expected s to be |%s|, was |%s|\n", expected, teststr);
     162               0 :                         abort();
     163                 :                 }
     164              98 :                 printf("Read a row of data -> %d %s\n", (int) testint, teststr);
     165                 :         }
     166                 : 
     167               2 :         if (REG_ROW == dbnextrow(dbproc)) {
     168               0 :                 fprintf(stderr, "dblib failed for %s\n", __FILE__);
     169               0 :                 add_bread_crumb();
     170               0 :                 dbexit();
     171               0 :                 add_bread_crumb();
     172                 : 
     173               0 :                 free_bread_crumb();
     174               0 :                 return 1;
     175                 :         }
     176                 : 
     177               2 :         add_bread_crumb();
     178               2 :         dbexit();
     179               2 :         add_bread_crumb();
     180                 : 
     181               2 :         if (last_read == rows_to_add - 1)
     182               2 :                 printf("dblib okay for %s\n", __FILE__);
     183                 :         else
     184               0 :                 fprintf(stderr, "dblib failed for %s\n", __FILE__);
     185               2 :         free_bread_crumb();
     186               2 :         return (last_read == rows_to_add - 1) ? 0 : 1;
     187                 : }

Generated by: LTP GCOV extension version 1.6