LTP GCOV extension - code coverage report
Current view: directory - dblib/unittests - dbmorecmds.c
Test: FreeTDS coverage
Date: 2008-11-21 Instrumented lines: 76
Code covered: 89.5 % Executed lines: 68

       1                 : /* 
       2                 :  * Purpose: Test behaviour of dbmorecmds()
       3                 :  * Functions: dbmorecmds 
       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                 : static char software_version[] = "$Id: dbmorecmds.c,v 1.11 2005/07/15 11:52:18 freddy77 Exp $";
      26                 : static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
      27                 : 
      28                 : int failed = 0;
      29                 : const static char query[] = "select count(*) from sysusers\n"
      30                 :                             "select name from sysobjects compute count(name)\n";
      31                 : int
      32                 : main(int argc, char **argv)
      33               2 : {
      34               2 :         const int rows_to_add = 10;
      35                 :         LOGINREC *login;
      36                 :         DBPROCESS *dbproc;
      37                 :         int i, nresults;
      38                 : 
      39               2 :         set_malloc_options();
      40                 : 
      41               2 :         read_login_info(argc, argv);
      42               2 :         fprintf(stdout, "Start\n");
      43               2 :         add_bread_crumb();
      44                 : 
      45                 :         /* Fortify_EnterScope(); */
      46               2 :         dbinit();
      47                 : 
      48               2 :         add_bread_crumb();
      49               2 :         dberrhandle(syb_err_handler);
      50               2 :         dbmsghandle(syb_msg_handler);
      51                 : 
      52               2 :         fprintf(stdout, "About to logon\n");
      53                 : 
      54               2 :         add_bread_crumb();
      55                 : 
      56               2 :         fprintf(stdout, "after bread crumb\n");
      57                 : 
      58               2 :         login = dblogin();
      59               2 :         fprintf(stdout, "after dblogin\n");
      60               2 :         DBSETLPWD(login, PASSWORD);
      61               2 :         DBSETLUSER(login, USER);
      62               2 :         DBSETLAPP(login, "t0024");
      63                 : 
      64               2 :         fprintf(stdout, "About to open [%s]\n", USER);
      65                 : 
      66               2 :         add_bread_crumb();
      67                 : 
      68               2 :         fprintf(stdout, "After second bread crumb\n");
      69                 : 
      70               2 :         dbproc = dbopen(login, SERVER);
      71               2 :         fprintf(stdout, "After dbopen [%s]\n", SERVER);
      72                 : 
      73               2 :         if (strlen(DATABASE)) {
      74               2 :                 fprintf(stdout, "About to dbuse [%s]\n", DATABASE);
      75               2 :                 dbuse(dbproc, DATABASE);
      76                 :         }
      77               2 :         add_bread_crumb();
      78               2 :         dbloginfree(login);
      79               2 :         add_bread_crumb();
      80                 : 
      81               2 :         fprintf(stdout, "After dbuse [%s]\n", DATABASE);
      82               2 :         add_bread_crumb();
      83                 : 
      84               2 :         fprintf(stdout, "creating table\n");
      85               2 :         dbcmd(dbproc, "create table #dblib0024 (i int not null, s char(10) not null)");
      86               2 :         dbsqlexec(dbproc);
      87               4 :         while (dbresults(dbproc) != NO_MORE_RESULTS) {
      88                 :                 /* nop */
      89                 :         }
      90                 : 
      91               2 :         fprintf(stdout, "insert\n");
      92              22 :         for (i = 0; i < rows_to_add; i++) {
      93                 :                 char cmd[1024];
      94                 : 
      95              20 :                 sprintf(cmd, "insert into #dblib0024 values (%d, 'row %03d')", i, i);
      96              20 :                 fprintf(stdout, "%s\n", cmd);
      97              20 :                 dbcmd(dbproc, cmd);
      98              20 :                 dbsqlexec(dbproc);
      99              40 :                 while (dbresults(dbproc) != NO_MORE_RESULTS) {
     100                 :                         /* nop */
     101                 :                 }
     102                 :         }
     103                 : 
     104               2 :         fprintf(stdout, "select 1\n");
     105               2 :         dbcmd(dbproc, "select count(*) from #dblib0024 -- order by i");
     106               2 :         dbsqlexec(dbproc);
     107               2 :         add_bread_crumb();
     108                 : 
     109               2 :         nresults = 0;
     110                 : 
     111               2 :         if (dbresults(dbproc) == SUCCEED) {
     112                 :                 do {
     113               4 :                         while (dbnextrow(dbproc) != NO_MORE_ROWS);
     114               2 :                         nresults++;
     115               2 :                 } while (dbmorecmds(dbproc) == SUCCEED);
     116                 :         }
     117                 : 
     118                 :         /* dbmorecmds should return success 0 times for select 1 */
     119               2 :         if (nresults != 1) {
     120               0 :                 add_bread_crumb();
     121               0 :                 failed = 1;
     122               0 :                 fprintf(stdout, "Was expecting nresults == 1.\n");
     123               0 :                 exit(1);
     124                 :         }
     125                 : 
     126               2 :         dbcancel(dbproc);
     127                 : 
     128               2 :         fprintf(stdout, query);
     129               2 :         dbcmd(dbproc, query);
     130               2 :         dbsqlexec(dbproc);
     131                 : 
     132               2 :         nresults = 0;
     133                 : 
     134                 :         do {
     135               4 :                 if (dbresults(dbproc) == SUCCEED) {
     136              91 :                         while (dbnextrow(dbproc) != NO_MORE_ROWS);
     137               4 :                         nresults++;
     138                 :                 }
     139               4 :         } while (dbmorecmds(dbproc) == SUCCEED);
     140                 : 
     141                 : 
     142                 :         /* dbmorecmds should return success 2 times for select 2 */
     143               2 :         if (nresults != 2) {    /* two results sets plus a return code */
     144               0 :                 add_bread_crumb();
     145               0 :                 failed = 1;
     146               0 :                 fprintf(stdout, "nresults was %d; was expecting nresults = 2.\n", nresults);
     147               0 :                 exit(1);
     148                 :         }
     149                 : 
     150                 :         /* end of test processing */
     151                 : 
     152               2 :         add_bread_crumb();
     153               2 :         dbexit();
     154               2 :         add_bread_crumb();
     155                 : 
     156               2 :         fprintf(stdout, "dblib %s on %s\n", (failed ? "failed!" : "okay"), __FILE__);
     157               2 :         free_bread_crumb();
     158               2 :         return failed ? 1 : 0;
     159                 : }

Generated by: LTP GCOV extension version 1.6