LCOV - code coverage report
Current view: top level - src/ctlib/unittests - cs_diag.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 29 51 56.9 %
Date: 2024-03-23 09:12:27 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include <config.h>
       2             : 
       3             : #include <stdio.h>
       4             : #include <cspublic.h>
       5             : #include <ctpublic.h>
       6             : #include "common.h"
       7             : 
       8             : /*
       9             :  * ct_send SQL |select name = @@servername|
      10             :  * ct_bind variable
      11             :  * ct_fetch and print results
      12             :  */
      13             : int
      14           8 : main(int argc, char **argv)
      15             : {
      16           8 :         int verbose = 1;
      17             :         CS_CONTEXT *ctx;
      18             :         CS_RETCODE ret;
      19             :         CS_DATAFMT srcfmt;
      20           8 :         CS_INT src = 32768;
      21             :         CS_DATAFMT dstfmt;
      22             :         CS_SMALLINT dst;
      23             :         CS_DATETIME dst_date;
      24             : 
      25             :         int i;
      26             : 
      27             :         CS_INT num_msgs;
      28             :         CS_CLIENTMSG client_message;
      29             : 
      30           8 :         printf("%s: Testing context callbacks\n", __FILE__);
      31             : 
      32           8 :         srcfmt.datatype = CS_INT_TYPE;
      33           8 :         srcfmt.maxlength = sizeof(CS_INT);
      34           8 :         srcfmt.locale = NULL;
      35             : 
      36           8 :         dstfmt.datatype = CS_SMALLINT_TYPE;
      37           8 :         dstfmt.maxlength = sizeof(CS_SMALLINT);
      38           8 :         dstfmt.locale = NULL;
      39             : 
      40             :         if (verbose) {
      41           8 :                 printf("Trying clientmsg_cb with context\n");
      42             :         }
      43           8 :         if (cs_ctx_alloc(CS_VERSION_100, &ctx) != CS_SUCCEED) {
      44           0 :                 fprintf(stderr, "cs_ctx_alloc() failed\n");
      45             :         }
      46           8 :         if (ct_init(ctx, CS_VERSION_100) != CS_SUCCEED) {
      47           0 :                 fprintf(stderr, "ct_init() failed\n");
      48             :         }
      49             : 
      50           8 :         if (cs_diag(ctx, CS_INIT, CS_UNUSED, CS_UNUSED, NULL) != CS_SUCCEED) {
      51           0 :                 fprintf(stderr, "cs_diag(CS_INIT) failed\n");
      52           0 :                 return 1;
      53             :         }
      54             : 
      55           8 :         if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst, NULL) == CS_SUCCEED) {
      56           0 :                 fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
      57           0 :                 return 1;
      58             :         }
      59             : 
      60           8 :         dstfmt.datatype = CS_DATETIME_TYPE;
      61           8 :         dstfmt.maxlength = sizeof(CS_DATETIME);
      62           8 :         dstfmt.locale = NULL;
      63             : 
      64           8 :         if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst_date, NULL) == CS_SUCCEED) {
      65           0 :                 fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
      66           0 :                 return 1;
      67             :         }
      68             : 
      69           8 :         if (cs_diag(ctx, CS_STATUS, CS_CLIENTMSG_TYPE, CS_UNUSED, &num_msgs) != CS_SUCCEED) {
      70           0 :                 fprintf(stderr, "cs_diag(CS_STATUS) failed\n");
      71           0 :                 return 1;
      72             :         }
      73             : 
      74          16 :         for (i = 0; i < num_msgs; i++ ) {
      75             : 
      76          16 :                 if (cs_diag(ctx, CS_GET, CS_CLIENTMSG_TYPE, i + 1, &client_message) != CS_SUCCEED) {
      77           0 :                         fprintf(stderr, "cs_diag(CS_GET) failed\n");
      78           0 :                         return 1;
      79             :                 }
      80             :         
      81          16 :             cslibmsg_cb(NULL, &client_message);
      82             :         
      83             :         }
      84             : 
      85           8 :         if ((ret = cs_diag(ctx, CS_GET, CS_CLIENTMSG_TYPE, i + 1, &client_message)) != CS_NOMSG) {
      86           0 :                 fprintf(stderr, "cs_diag(CS_GET) did not fail with CS_NOMSG\n");
      87           0 :                 return 1;
      88             :         }
      89             : 
      90           8 :         if (cs_diag(ctx, CS_CLEAR, CS_CLIENTMSG_TYPE, CS_UNUSED, NULL) != CS_SUCCEED) {
      91           0 :                 fprintf(stderr, "cs_diag(CS_CLEAR) failed\n");
      92           0 :                 return 1;
      93             :         }
      94             : 
      95           8 :         if (cs_diag(ctx, CS_STATUS, CS_CLIENTMSG_TYPE, CS_UNUSED, &num_msgs) != CS_SUCCEED) {
      96           0 :                 fprintf(stderr, "cs_diag(CS_STATUS) failed\n");
      97           0 :                 return 1;
      98             :         }
      99           8 :         if (num_msgs != 0) {
     100           0 :                 fprintf(stderr, "cs_diag(CS_CLEAR) failed there are still %d messages on queue\n", num_msgs);
     101           0 :                 return 1;
     102             :         }
     103             : 
     104           8 :         if (ct_exit(ctx, CS_UNUSED) != CS_SUCCEED) {
     105           0 :                 fprintf(stderr, "ct_exit() failed\n");
     106             :         }
     107           8 :         if (cs_ctx_drop(ctx) != CS_SUCCEED) {
     108           0 :                 fprintf(stderr, "cx_ctx_drop() failed\n");
     109             :         }
     110             : 
     111             :         return 0;
     112             : }

Generated by: LCOV version 1.13