LCOV - code coverage report
Current view: top level - tests - initialize.c (source / functions) Coverage Total Hit
Test: Code coverage Lines: 100.0 % 33 33
Test Date: 2025-12-04 16:15:14 Functions: 100.0 % 3 3
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 64.3 % 14 9

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * Negative test cases for failed initializations
       3                 :             :  *
       4                 :             :  * Copyright 2020 Red Hat, Inc.
       5                 :             :  *
       6                 :             :  * Authors:
       7                 :             :  *  Jakub Jelen <jjelen@redhat.com>
       8                 :             :  *
       9                 :             :  * This code is licensed under the GNU LGPL, version 2.1 or later.
      10                 :             :  * See the COPYING file in the top-level directory.
      11                 :             :  */
      12                 :             : #include <glib.h>
      13                 :             : #include <string.h>
      14                 :             : #include "libcacard.h"
      15                 :             : #include "src/common.h"
      16                 :             : 
      17                 :             : #define ARGS "db=\"sql:%s\" use_hw=no soft=(,Test,CAC,,cert1,cert2,cert3)"
      18                 :             : 
      19                 :           2 : static void test_already_initialized(void)
      20                 :             : {
      21         [ +  + ]:           2 :     if (g_test_subprocess ()) {
      22                 :             :         VCardEmulOptions *command_line_options = NULL;
      23                 :           1 :         gchar *dbdir = g_test_build_filename(G_TEST_DIST, "db", NULL);
      24                 :           1 :         gchar *args = g_strdup_printf(ARGS, dbdir);
      25                 :             :         VCardEmulError ret;
      26                 :             : 
      27         [ +  - ]:           1 :         g_assert(g_file_test(dbdir, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)));
      28                 :             : 
      29                 :           1 :         command_line_options = vcard_emul_options(args);
      30                 :           1 :         ret = vcard_emul_init(command_line_options);
      31         [ -  + ]:           1 :         g_assert_cmpint(ret, ==, VCARD_EMUL_OK);
      32                 :           1 :         ret = vcard_emul_init(command_line_options);
      33                 :             :         /* Is this correct, when the initialization failed ? */
      34         [ -  + ]:           1 :         g_assert_cmpint(ret, ==, VCARD_EMUL_INIT_ALREADY_INITED);
      35                 :             : 
      36                 :           1 :         g_free(args);
      37                 :           1 :         g_free(dbdir);
      38                 :             : 
      39                 :           1 :         return;
      40                 :             :     }
      41                 :             : 
      42                 :           1 :     g_test_trap_subprocess(NULL, 0, 0);
      43                 :           1 :     g_test_trap_assert_passed();
      44                 :             : }
      45                 :             : 
      46                 :           2 : static void test_invalid_db(void)
      47                 :             : {
      48         [ +  + ]:           2 :     if (g_test_subprocess ()) {
      49                 :             :         VCardEmulOptions *command_line_options = NULL;
      50                 :           1 :         gchar *dbdir = g_test_build_filename(G_TEST_DIST, "no-db", NULL);
      51                 :           1 :         gchar *args = g_strdup_printf(ARGS, dbdir);
      52                 :             :         VCardEmulError ret;
      53                 :             : 
      54         [ +  - ]:           1 :         g_assert(!g_file_test(dbdir, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)));
      55                 :             : 
      56                 :           1 :         command_line_options = vcard_emul_options(args);
      57                 :           1 :         ret = vcard_emul_init(command_line_options);
      58         [ -  + ]:           1 :         g_assert_cmpint(ret, ==, VCARD_EMUL_FAIL);
      59                 :             : 
      60                 :           1 :         g_free(args);
      61                 :           1 :         g_free(dbdir);
      62                 :             : 
      63                 :           1 :         return;
      64                 :             :     }
      65                 :             : 
      66                 :           1 :     g_test_trap_subprocess(NULL, 0, 0);
      67                 :           1 :     g_test_trap_assert_passed();
      68                 :             : }
      69                 :             : 
      70                 :           3 : int main(int argc, char *argv[])
      71                 :             : {
      72                 :           3 :     g_test_init(&argc, &argv, NULL);
      73                 :             : 
      74                 :           3 :     g_test_add_func("/initialize/invalid_db", test_invalid_db);
      75                 :           3 :     g_test_add_func("/initialize/already_initialized", test_already_initialized);
      76                 :             : 
      77                 :           3 :     return g_test_run();
      78                 :             : }
      79                 :             : 
      80                 :             : /* vim: set ts=4 sw=4 tw=0 noet expandtab: */
        

Generated by: LCOV version 2.0-1