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: 2026-11-07 23:58:45 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             : 
      18          60 :         if (res == expected)
      19          60 :                 return;
      20             : 
      21           0 :         fprintf(stderr, "%d:Wrong result: %s instead of %s\nQuery: %s\n",
      22             :                 line, res ? "true" : "false", expected ? "true" : "false", query);
      23           0 :         exit(1);
      24             : }
      25             : 
      26             : #define test(query, expected) test(query, expected, __LINE__)
      27             : 
      28          10 : TEST_MAIN()
      29             : {
      30          10 :         check_call(cs_ctx_alloc, (CS_VERSION_100, &ctx));
      31             : 
      32          10 :         check_call(ct_callback, (ctx, NULL, CS_GET, CS_QUERY_HAS_FOR_UPDATE, &query_has_for_update));
      33             : 
      34          10 :         test("", false);
      35          10 :         test("SELECT * FROM table FOR UPDATE", true);
      36          10 :         test("SELECT * FROM table FOR dummy UPDATE", false);
      37          10 :         test("SELECT * FROM table FOR/* comment */UPDATE", true);
      38          10 :         test("SELECT * FROM table FOR--xxx\nUPDATE", true);
      39          10 :         test("SELECT * FROM table /* FOR UPDATE */", false);
      40             : 
      41          10 :         check_call(ct_exit, (ctx, CS_UNUSED));
      42          10 :         check_call(cs_ctx_drop, (ctx));
      43             : 
      44          10 :         return 0;
      45             : }
      46             : 
      47             : #else
      48             : 
      49             : TEST_MAIN()
      50             : {
      51             :         return 0;
      52             : }
      53             : 
      54             : #endif

Generated by: LCOV version 1.13