LCOV - code coverage report
Current view: top level - challengerdb - test_challenger_db.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 31 40 77.5 %
Date: 2025-06-04 08:24:00 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of
       3             :   (C) 2023 Taler Systems SA
       4             : 
       5             :   Challenger is free software; you can redistribute it and/or modify it under the
       6             :   terms of the GNU Lesser General Public License as published by the Free Software
       7             :   Foundation; either version 3, or (at your option) any later version.
       8             : 
       9             :   Challenger is distributed in the hope that it will be useful, but WITHOUT ANY
      10             :   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
      11             :   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
      12             : 
      13             :   You should have received a copy of the GNU General Public License along with
      14             :   Challenger; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15             : */
      16             : /**
      17             :  * @file sync/test_sync_db.c
      18             :  * @brief testcase for sync postgres db plugin
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include <gnunet/gnunet_util_lib.h>
      23             : #include <taler/taler_util.h>
      24             : #include "challenger_database_plugin.h"
      25             : #include "challenger_database_lib.h"
      26             : #include "challenger_util.h"
      27             : 
      28             : 
      29             : #define FAILIF(cond)                            \
      30             :         do {                                          \
      31             :           if (! (cond)) { break;}                       \
      32             :           GNUNET_break (0);                           \
      33             :           goto drop;                                     \
      34             :         } while (0)
      35             : 
      36             : #define RND_BLK(ptr)                                                    \
      37             :         GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (* \
      38             :                                                                              ptr))
      39             : 
      40             : /**
      41             :  * Global return value for the test.  Initially -1, set to 0 upon
      42             :  * completion.   Other values indicate some kind of error.
      43             :  */
      44             : static int result;
      45             : 
      46             : /**
      47             :  * Handle to the plugin we are testing.
      48             :  */
      49             : static struct CHALLENGER_DatabasePlugin *plugin;
      50             : 
      51             : 
      52             : /**
      53             :  * Main function that will be run by the scheduler.
      54             :  *
      55             :  * @param cls closure with config
      56             :  */
      57             : static void
      58           1 : run (void *cls)
      59             : {
      60           1 :   struct GNUNET_CONFIGURATION_Handle *cfg = cls;
      61             : 
      62           1 :   if (NULL == (plugin = CHALLENGER_DB_plugin_load (cfg,
      63             :                                                    true)))
      64             :   {
      65           0 :     result = 77;
      66           0 :     return;
      67             :   }
      68           1 :   if (GNUNET_OK !=
      69           1 :       plugin->drop_tables (plugin->cls))
      70             :   {
      71           1 :     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
      72             :                 "Dropping tables failed\n");
      73             :   }
      74           1 :   if (GNUNET_OK !=
      75           1 :       plugin->create_tables (plugin->cls))
      76             :   {
      77           0 :     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
      78             :                 "Creating tables failed\n");
      79             :   }
      80           1 :   GNUNET_assert (GNUNET_OK ==
      81             :                  plugin->preflight (plugin->cls));
      82             :   {
      83           1 :     struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get ();
      84             : 
      85           1 :     FAILIF (0 >
      86             :             plugin->gc (plugin->cls,
      87             :                         ts));
      88             :   }
      89           1 :   result = 0;
      90           1 : drop:
      91           1 :   GNUNET_break (GNUNET_OK ==
      92             :                 plugin->drop_tables (plugin->cls));
      93           1 :   CHALLENGER_DB_plugin_unload (plugin);
      94           1 :   plugin = NULL;
      95             : }
      96             : 
      97             : 
      98             : int
      99           1 : main (int argc,
     100             :       char *const argv[])
     101             : {
     102             :   const char *plugin_name;
     103             :   char *config_filename;
     104             :   char *testname;
     105             :   struct GNUNET_CONFIGURATION_Handle *cfg;
     106             : 
     107             :   (void) argc;
     108           1 :   result = EXIT_FAILURE;
     109           1 :   if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
     110             :   {
     111           0 :     GNUNET_break (0);
     112           0 :     return EXIT_FAILURE;
     113             :   }
     114           1 :   GNUNET_log_setup (argv[0],
     115             :                     "DEBUG",
     116             :                     NULL);
     117           1 :   plugin_name++;
     118           1 :   (void) GNUNET_asprintf (&testname,
     119             :                           "%s",
     120             :                           plugin_name);
     121           1 :   (void) GNUNET_asprintf (&config_filename,
     122             :                           "test_challenger_db_%s.conf",
     123             :                           testname);
     124           1 :   cfg = GNUNET_CONFIGURATION_create (CHALLENGER_project_data ());
     125           1 :   if (GNUNET_OK !=
     126           1 :       GNUNET_CONFIGURATION_parse (cfg,
     127             :                                   config_filename))
     128             :   {
     129           0 :     GNUNET_break (0);
     130           0 :     GNUNET_free (config_filename);
     131           0 :     GNUNET_free (testname);
     132           0 :     return EXIT_NOTCONFIGURED;
     133             :   }
     134           1 :   GNUNET_SCHEDULER_run (&run, cfg);
     135           1 :   GNUNET_CONFIGURATION_destroy (cfg);
     136           1 :   GNUNET_free (config_filename);
     137           1 :   GNUNET_free (testname);
     138           1 :   return result;
     139             : }
     140             : 
     141             : 
     142             : /* end of test_challenger_db.c */

Generated by: LCOV version 1.16