LCOV - code coverage report
Current view: top level - src/ctlib/unittests - rpc_fail.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 25 64 39.1 %
Date: 2025-01-18 12:13:41 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include <config.h>
       2             : 
       3             : #include <stdio.h>
       4             : 
       5             : #if HAVE_STDLIB_H
       6             : #include <stdlib.h>
       7             : #endif /* HAVE_STDLIB_H */
       8             : 
       9             : #if HAVE_STRING_H
      10             : #include <string.h>
      11             : #endif /* HAVE_STRING_H */
      12             : 
      13             : #include <ctpublic.h>
      14             : #include "common.h"
      15             : 
      16             : static const char *printable_ret(CS_RETCODE ret)
      17             : {
      18             : #define CASE(x) case x: return #x;
      19          18 :         switch (ret) {
      20             :         CASE(CS_STATUS_RESULT)
      21           0 :         CASE(CS_ROW_RESULT)
      22           0 :         CASE(CS_PARAM_RESULT)
      23           0 :         CASE(CS_CMD_SUCCEED)
      24           0 :         CASE(CS_MSG_RESULT)
      25           8 :         CASE(CS_CMD_DONE)
      26           8 :         CASE(CS_CMD_FAIL)
      27           0 :         default:
      28             :                 return "Unknown";
      29             :         }
      30             : }
      31             : 
      32             : int
      33           8 : main(int argc, char *argv[])
      34             : {
      35             :         CS_CONTEXT *ctx;
      36             :         CS_CONNECTION *conn;
      37             :         CS_COMMAND *cmd;
      38           8 :         int verbose = 0;
      39             :         CS_RETCODE ret;
      40             :         CS_INT res_type;
      41             :         CS_SMALLINT msg_id;
      42           8 :         int got_failure = 0;
      43           8 :         int got_done = 0;
      44             :         CS_INT rows_read;
      45             : 
      46           8 :         printf("%s: submit a not existing stored procedure\n", __FILE__);
      47           8 :         ret = try_ctlogin(&ctx, &conn, &cmd, verbose);
      48           8 :         if (ret != CS_SUCCEED) {
      49           0 :                 fprintf(stderr, "Login failed\n");
      50           0 :                 return 1;
      51             :         }
      52             : 
      53           8 :         if ((ret = ct_command(cmd, CS_RPC_CMD, "IDoNotExist", CS_NULLTERM, CS_NO_RECOMPILE)) != CS_SUCCEED) {
      54           0 :                 fprintf(stderr, "ct_command(CS_RPC_CMD) failed");
      55           0 :                 return 1;
      56             :         }
      57             : 
      58           8 :         if (ct_send(cmd) != CS_SUCCEED) {
      59           0 :                 fprintf(stderr, "ct_send(RPC) failed");
      60           0 :                 return 1;
      61             :         }
      62             : 
      63          26 :         while ((ret = ct_results(cmd, &res_type)) == CS_SUCCEED) {
      64          36 :                 printf("ct_results returned %s\n", printable_ret(res_type));
      65          18 :                 switch ((int) res_type) {
      66             :                 case CS_STATUS_RESULT:
      67           4 :                         while (ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read) == CS_SUCCEED)
      68           2 :                                 continue;
      69             :                         break;
      70             : 
      71           0 :                 case CS_CMD_SUCCEED:
      72           0 :                         fprintf(stderr, "a success was not expected from ct_results.\n");
      73           0 :                         return 1;
      74             : 
      75           0 :                 case CS_ROW_RESULT:
      76             :                 case CS_PARAM_RESULT:
      77           0 :                         fprintf(stderr, "Only status results are expected\n");
      78           0 :                         return 1;
      79             : 
      80           0 :                 case CS_MSG_RESULT:
      81           0 :                         ret = ct_res_info(cmd, CS_MSGTYPE, (CS_VOID *) & msg_id, CS_UNUSED, NULL);
      82           0 :                         if (ret != CS_SUCCEED) {
      83           0 :                                 fprintf(stderr, "ct_res_info(msg_id) failed");
      84           0 :                                 return 1;
      85             :                         }
      86           0 :                         printf("ct_result returned CS_MSG_RESULT where msg id = %d.\n", msg_id);
      87           0 :                         break;
      88             : 
      89             :                 case CS_CMD_DONE:
      90             :                         got_done = 1;
      91             :                         break;
      92             : 
      93           8 :                 case CS_CMD_FAIL:
      94           8 :                         got_failure = 1;
      95           8 :                         break;
      96             : 
      97           0 :                 default:
      98           0 :                         fprintf(stderr, "ct_results returned unexpected result type.\n");
      99           0 :                         return 1;
     100             :                 }
     101             :         }
     102             : 
     103           8 :         if (!got_failure) {
     104           0 :                 fprintf(stderr, "a failure was expected from ct_results.\n");
     105           0 :                 return 1;
     106             :         }
     107           8 :         if (!got_done) {
     108           0 :                 fprintf(stderr, "a done result was expected from ct_results.\n");
     109           0 :                 return 1;
     110             :         }
     111             : 
     112           8 :         switch ((int) ret) {
     113             :         case CS_END_RESULTS:
     114             :                 break;
     115             : 
     116           0 :         case CS_FAIL:
     117           0 :                 fprintf(stderr, "ct_results failed.");
     118           0 :                 return 1;
     119             : 
     120           0 :         default:
     121           0 :                 fprintf(stderr, "ct_results returned unexpected result type.");
     122           0 :                 return 1;
     123             :         }
     124             : 
     125           8 :         ret = try_ctlogout(ctx, conn, cmd, verbose);
     126           8 :         if (ret != CS_SUCCEED) {
     127           0 :                 fprintf(stderr, "Logout failed\n");
     128           0 :                 return 1;
     129             :         }
     130             : 
     131             :         return 0;
     132             : }

Generated by: LCOV version 1.13