LCOV - code coverage report
Current view: top level - src/ctlib/unittests - has_for_update.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 16 18 88.9 %
Date: 2025-07-02 09:40:27 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Purpose: Test internal query_has_for_update function
       3             :  */
       4             : 
       5             : #include "common.h"
       6             : #include <ctlib.h>
       7             : 
       8             : #if ENABLE_EXTRA_CHECKS
       9             : 
      10             : static CS_CONTEXT *ctx;
      11             : static bool (*query_has_for_update)(const char *query);
      12             : 
      13             : static void
      14          60 : test(const char *query, bool expected, int line)
      15             : {
      16          60 :         bool res = query_has_for_update(query);
      17          60 :         if (res == expected)
      18          60 :                 return;
      19             : 
      20           0 :         fprintf(stderr, "%d:Wrong result: %s instead of %s\nQuery: %s\n",
      21             :                 line,
      22             :                 res ? "true": "false",
      23             :                 expected ? "true": "false",
      24             :                 query);
      25           0 :         exit(1);
      26             : }
      27             : 
      28             : #define test(query, expected) test(query, expected, __LINE__)
      29             : 
      30          10 : TEST_MAIN()
      31             : {
      32          10 :         check_call(cs_ctx_alloc, (CS_VERSION_100, &ctx));
      33             : 
      34          10 :         check_call(ct_callback, (ctx, NULL, CS_GET, CS_QUERY_HAS_FOR_UPDATE, &query_has_for_update));
      35             : 
      36          10 :         test("", false);
      37          10 :         test("SELECT * FROM table FOR UPDATE", true);
      38          10 :         test("SELECT * FROM table FOR dummy UPDATE", false);
      39          10 :         test("SELECT * FROM table FOR/* comment */UPDATE", true);
      40          10 :         test("SELECT * FROM table FOR--xxx\nUPDATE", true);
      41          10 :         test("SELECT * FROM table /* FOR UPDATE */", false);
      42             : 
      43          10 :         check_call(ct_exit, (ctx, CS_UNUSED));
      44          10 :         check_call(cs_ctx_drop,(ctx));
      45             : 
      46          10 :         return 0;
      47             : }
      48             : 
      49             : #else
      50             : 
      51             : TEST_MAIN()
      52             : {
      53             :         return 0;
      54             : }
      55             : 
      56             : #endif
      57             : 

Generated by: LCOV version 1.13