LCOV - code coverage report
Current view: top level - testing - testing_api_helpers_auditor.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 42 0.0 %
Date: 2022-08-25 06:15:09 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2018 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify
       6             :   it under the terms of the GNU General Public License as
       7             :   published by the Free Software Foundation; either version 3, or
       8             :   (at your option) any later version.
       9             : 
      10             :   TALER is distributed in the hope that it will be useful, but
      11             :   WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :   GNU General Public License for more details.
      14             : 
      15             :   You should have received a copy of the GNU General Public
      16             :   License along with TALER; see the file COPYING.  If not, see
      17             :   <http://www.gnu.org/licenses/>
      18             : */
      19             : /**
      20             :  * @file testing/testing_api_helpers_auditor.c
      21             :  * @brief helper functions
      22             :  * @author Christian Grothoff
      23             :  */
      24             : #include "platform.h"
      25             : #include "taler_json_lib.h"
      26             : #include <gnunet/gnunet_curl_lib.h>
      27             : #include "taler_testing_lib.h"
      28             : #include "taler_auditor_service.h"
      29             : 
      30             : 
      31             : /**
      32             :  * Closure for #cleanup_auditor.
      33             :  */
      34             : struct CleanupContext
      35             : {
      36             :   /**
      37             :    * Where we find the state to clean up.
      38             :    */
      39             :   struct TALER_TESTING_Interpreter *is;
      40             : 
      41             :   /**
      42             :    * Next cleanup routine to call, NULL for none.
      43             :    */
      44             :   GNUNET_SCHEDULER_TaskCallback fcb;
      45             : 
      46             :   /**
      47             :    * Closure for @e fcb
      48             :    */
      49             :   void *fcb_cls;
      50             : };
      51             : 
      52             : 
      53             : /**
      54             :  * Function to clean up the auditor connection.
      55             :  *
      56             :  * @param cls a `struct CleanupContext`
      57             :  */
      58             : static void
      59           0 : cleanup_auditor (void *cls)
      60             : {
      61           0 :   struct CleanupContext *cc = cls;
      62           0 :   struct TALER_TESTING_Interpreter *is = cc->is;
      63             : 
      64           0 :   TALER_AUDITOR_disconnect (is->auditor);
      65           0 :   is->auditor = NULL;
      66           0 :   if (NULL != cc->fcb)
      67           0 :     cc->fcb (cc->fcb_cls);
      68           0 :   GNUNET_free (cc);
      69           0 : }
      70             : 
      71             : 
      72             : /**
      73             :  * Closure for #auditor_main_wrapper()
      74             :  */
      75             : struct MainWrapperContext
      76             : {
      77             :   /**
      78             :    * Main function to launch.
      79             :    */
      80             :   TALER_TESTING_Main main_cb;
      81             : 
      82             :   /**
      83             :    * Closure for @e main_cb.
      84             :    */
      85             :   void *main_cb_cls;
      86             : 
      87             :   /**
      88             :    * Configuration we use.
      89             :    */
      90             :   const struct GNUNET_CONFIGURATION_Handle *cfg;
      91             : 
      92             :   /**
      93             :    * Name of the configuration file.
      94             :    */
      95             :   const char *config_filename;
      96             : 
      97             : };
      98             : 
      99             : 
     100             : /**
     101             :  * Function called with information about the auditor.
     102             :  *
     103             :  * @param cls closure
     104             :  * @param hr http response details
     105             :  * @param vi basic information about the auditor
     106             :  * @param compat protocol compatibility information
     107             :  */
     108             : static void
     109           0 : auditor_version_cb (void *cls,
     110             :                     const struct TALER_AUDITOR_HttpResponse *hr,
     111             :                     const struct TALER_AUDITOR_VersionInformation *vi,
     112             :                     enum TALER_AUDITOR_VersionCompatibility compat)
     113             : {
     114           0 :   struct TALER_TESTING_Interpreter *is = cls;
     115             : 
     116             :   (void) hr;
     117             :   (void) vi;
     118           0 :   if (TALER_AUDITOR_VC_MATCH != compat)
     119             :   {
     120           0 :     TALER_TESTING_interpreter_fail (is);
     121           0 :     return;
     122             :   }
     123           0 :   is->auditor_working = GNUNET_YES;
     124             : }
     125             : 
     126             : 
     127             : /**
     128             :  * Setup the @a is 'auditor' member before running the main test loop.
     129             :  *
     130             :  * @param cls must be a `struct MainWrapperContext *`
     131             :  * @param[in,out] is interpreter state to setup
     132             :  */
     133             : static void
     134           0 : auditor_main_wrapper (void *cls,
     135             :                       struct TALER_TESTING_Interpreter *is)
     136             : {
     137           0 :   struct MainWrapperContext *mwc = cls;
     138             :   struct CleanupContext *cc;
     139             :   char *auditor_base_url;
     140             : 
     141           0 :   if (GNUNET_OK !=
     142           0 :       GNUNET_CONFIGURATION_get_value_string (mwc->cfg,
     143             :                                              "auditor",
     144             :                                              "BASE_URL",
     145             :                                              &auditor_base_url))
     146             :   {
     147           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     148             :                                "auditor",
     149             :                                "BASE_URL");
     150           0 :     return;
     151             :   }
     152             : 
     153           0 :   is->auditor = TALER_AUDITOR_connect (is->ctx,
     154             :                                        auditor_base_url,
     155             :                                        &auditor_version_cb,
     156             :                                        is);
     157           0 :   GNUNET_free (auditor_base_url);
     158             : 
     159           0 :   if (NULL == is->auditor)
     160             :   {
     161           0 :     GNUNET_break (0);
     162           0 :     return;
     163             :   }
     164             : 
     165           0 :   cc = GNUNET_new (struct CleanupContext);
     166           0 :   cc->is = is;
     167           0 :   cc->fcb = is->final_cleanup_cb;
     168           0 :   cc->fcb_cls = is->final_cleanup_cb_cls;
     169           0 :   is->final_cleanup_cb = cleanup_auditor;
     170           0 :   is->final_cleanup_cb_cls = cc;
     171           0 :   mwc->main_cb (mwc->main_cb_cls,
     172             :                 is);
     173             : }
     174             : 
     175             : 
     176             : /**
     177             :  * Install signal handlers plus schedules the main wrapper
     178             :  * around the "run" method.
     179             :  *
     180             :  * @param cls our `struct MainWrapperContext`
     181             :  * @param cfg configuration we use
     182             :  * @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
     183             :  *         non-GNUNET_OK codes are #GNUNET_SYSERR most of the
     184             :  *         times.
     185             :  */
     186             : static int
     187           0 : setup_with_cfg (void *cls,
     188             :                 const struct GNUNET_CONFIGURATION_Handle *cfg)
     189             : {
     190           0 :   struct MainWrapperContext *mwc = cls;
     191           0 :   struct TALER_TESTING_SetupContext setup_ctx = {
     192           0 :     .config_filename = mwc->config_filename,
     193             :     .main_cb = &auditor_main_wrapper,
     194             :     .main_cb_cls = mwc
     195             :   };
     196             : 
     197           0 :   mwc->cfg = cfg;
     198           0 :   return TALER_TESTING_setup_with_auditor_and_exchange_cfg (&setup_ctx,
     199             :                                                             cfg);
     200             : }
     201             : 
     202             : 
     203             : /**
     204             :  * Install signal handlers plus schedules the main wrapper
     205             :  * around the "run" method.
     206             :  *
     207             :  * @param main_cb the "run" method which contains all the
     208             :  *        commands.
     209             :  * @param main_cb_cls a closure for "run", typically NULL.
     210             :  * @param config_filename configuration filename.
     211             :  * @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
     212             :  *         non-GNUNET_OK codes are #GNUNET_SYSERR most of the
     213             :  *         times.
     214             :  */
     215             : int
     216           0 : TALER_TESTING_auditor_setup (TALER_TESTING_Main main_cb,
     217             :                              void *main_cb_cls,
     218             :                              const char *config_filename)
     219             : {
     220           0 :   struct MainWrapperContext mwc = {
     221             :     .main_cb = main_cb,
     222             :     .main_cb_cls = main_cb_cls,
     223             :     .config_filename = config_filename
     224             :   };
     225             : 
     226           0 :   return GNUNET_CONFIGURATION_parse_and_run (config_filename,
     227             :                                              &setup_with_cfg,
     228             :                                              &mwc);
     229             : }
     230             : 
     231             : 
     232             : /* end of testing_auditor_api_helpers.c */

Generated by: LCOV version 1.14