LCOV - code coverage report
Current view: top level - src/ctlib/unittests - ct_options.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 33 46 71.7 %
Date: 2024-04-18 20:40:06 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include <config.h>
       2             : 
       3             : #if HAVE_STRING_H
       4             : #include <string.h>
       5             : #endif /* HAVE_STRING_H */
       6             : 
       7             : #include <stdio.h>
       8             : #include <ctpublic.h>
       9             : #include "common.h"
      10             : 
      11             : /* Testing: Set and get options with ct_options */
      12             : int
      13           8 : main(int argc, char *argv[])
      14             : {
      15           8 :         int verbose = 0;
      16             : 
      17             :         CS_CONTEXT *ctx;
      18             :         CS_CONNECTION *conn;
      19             :         CS_COMMAND *cmd;
      20             : 
      21           8 :         CS_INT datefirst = 0;
      22           8 :         CS_INT dateformat = 0;
      23           8 :         CS_BOOL truefalse = 999;
      24             : 
      25             :         if (verbose) {
      26             :                 printf("Trying login\n");
      27             :         }
      28             : 
      29           8 :         if (argc >= 5) {
      30           0 :                 common_pwd.initialized = argc;
      31           0 :                 strcpy(common_pwd.SERVER, argv[1]);
      32           0 :                 strcpy(common_pwd.DATABASE, argv[2]);
      33           0 :                 strcpy(common_pwd.USER, argv[3]);
      34           0 :                 strcpy(common_pwd.PASSWORD, argv[4]);
      35             :         }
      36             : 
      37           8 :         check_call(try_ctlogin, (&ctx, &conn, &cmd, verbose));
      38             : 
      39           8 :         printf("%s: Set/Retrieve DATEFIRST\n", __FILE__);
      40             : 
      41             :         /* DATEFIRST */
      42           8 :         datefirst = CS_OPT_WEDNESDAY;
      43           8 :         check_call(ct_options, (conn, CS_SET, CS_OPT_DATEFIRST, &datefirst, CS_UNUSED, NULL));
      44             : 
      45           8 :         datefirst = 999;
      46             : 
      47           8 :         check_call(ct_options, (conn, CS_GET, CS_OPT_DATEFIRST, &datefirst, CS_UNUSED, NULL));
      48           8 :         if (datefirst != CS_OPT_WEDNESDAY) {
      49           0 :                 fprintf(stderr, "ct_options(DATEFIRST) didn't work retrieved %d expected %d\n", datefirst, CS_OPT_WEDNESDAY);
      50           0 :                 return 1;
      51             :         }
      52             : 
      53           8 :         printf("%s: Set/Retrieve DATEFORMAT\n", __FILE__);
      54             : 
      55             :         /* DATEFORMAT */
      56           8 :         dateformat = CS_OPT_FMTMYD;
      57           8 :         check_call(ct_options, (conn, CS_SET, CS_OPT_DATEFORMAT, &dateformat, CS_UNUSED, NULL));
      58             : 
      59           8 :         dateformat = 999;
      60             : 
      61           8 :         check_call(ct_options, (conn, CS_GET, CS_OPT_DATEFORMAT, &dateformat, CS_UNUSED, NULL));
      62           8 :         if (dateformat != CS_OPT_FMTMYD) {
      63           0 :                 fprintf(stderr, "ct_options(DATEFORMAT) didn't work retrieved %d expected %d\n", dateformat, CS_OPT_FMTMYD);
      64           0 :                 return 1;
      65             :         }
      66             : 
      67           8 :         printf("%s: Set/Retrieve ANSINULL\n", __FILE__);
      68             :         /* ANSI NULLS */
      69           8 :         truefalse = CS_TRUE;
      70           8 :         check_call(ct_options, (conn, CS_SET, CS_OPT_ANSINULL, &truefalse, CS_UNUSED, NULL));
      71             : 
      72           8 :         truefalse = 999;
      73           8 :         check_call(ct_options, (conn, CS_GET, CS_OPT_ANSINULL, &truefalse, CS_UNUSED, NULL));
      74           8 :         if (truefalse != CS_TRUE) {
      75           0 :                 fprintf(stderr, "ct_options(ANSINULL) didn't work\n");
      76           0 :                 return 1;
      77             :         }
      78             : 
      79           8 :         printf("%s: Set/Retrieve CHAINXACTS\n", __FILE__);
      80             :         /* CHAINED XACT */
      81           8 :         truefalse = CS_TRUE;
      82           8 :         check_call(ct_options, (conn, CS_SET, CS_OPT_CHAINXACTS, &truefalse, CS_UNUSED, NULL));
      83             : 
      84           8 :         truefalse = 999;
      85           8 :         check_call(ct_options, (conn, CS_GET, CS_OPT_CHAINXACTS, &truefalse, CS_UNUSED, NULL));
      86           8 :         if (truefalse != CS_TRUE) {
      87           0 :                 fprintf(stderr, "ct_options(CHAINXACTS) didn't work\n");
      88           0 :                 return 1;
      89             :         }
      90             : 
      91             :         if (verbose) {
      92             :                 printf("Trying logout\n");
      93             :         }
      94           8 :         check_call(try_ctlogout, (ctx, conn, cmd, verbose));
      95             : 
      96           8 :         return 0;
      97             : }

Generated by: LCOV version 1.13