LCOV - code coverage report
Current view: top level - testing - testing_api_traits.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 68.4 % 38 26
Test Date: 2026-04-14 15:39:31 Functions: 68.4 % 174 119

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2018, 2021 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_traits.c
      21              :  * @brief loop for trait resolution
      22              :  * @author Christian Grothoff
      23              :  * @author Marcello Stanisci
      24              :  */
      25              : #include "taler/taler_json_lib.h"
      26              : #include <gnunet/gnunet_curl_lib.h>
      27              : #include "taler/taler_testing_lib.h"
      28              : 
      29              : 
      30        39667 : TALER_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_IMPL_SIMPLE_TRAIT)
      31              : 
      32        29021 : TALER_TESTING_INDEXED_TRAITS (TALER_TESTING_MAKE_IMPL_INDEXED_TRAIT)
      33              : 
      34              : 
      35              : /**
      36              :  * End a trait array.  Usually, commands offer several traits,
      37              :  * and put them in arrays.
      38              :  */
      39              : struct TALER_TESTING_Trait
      40         7683 : TALER_TESTING_trait_end ()
      41              : {
      42         7683 :   struct TALER_TESTING_Trait end = {
      43              :     .index = 0,
      44              :     .trait_name = NULL,
      45              :     .ptr = NULL
      46              :   };
      47              : 
      48         7683 :   return end;
      49              : }
      50              : 
      51              : 
      52              : enum GNUNET_GenericReturnValue
      53         7633 : TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits,
      54              :                          const void **ret,
      55              :                          const char *trait,
      56              :                          unsigned int index)
      57              : {
      58        36910 :   for (unsigned int i = 0; NULL != traits[i].trait_name; i++)
      59              :   {
      60        36281 :     if ( (0 == strcmp (trait,
      61        36281 :                        traits[i].trait_name)) &&
      62         7112 :          (index == traits[i].index) )
      63              :     {
      64         7004 :       *ret = (void *) traits[i].ptr;
      65         7004 :       return GNUNET_OK;
      66              :     }
      67              :   }
      68          629 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
      69              :               "Trait %s/%u not found.\n",
      70              :               trait,
      71              :               index);
      72          629 :   return GNUNET_SYSERR;
      73              : }
      74              : 
      75              : 
      76              : const char *
      77          510 : TALER_TESTING_get_exchange_url (struct TALER_TESTING_Interpreter *is)
      78              : {
      79              :   const char *exchange_url;
      80              :   const struct TALER_TESTING_Command *exchange_cmd;
      81              : 
      82              :   exchange_cmd
      83          510 :     = TALER_TESTING_interpreter_get_command (is,
      84              :                                              "exchange");
      85          510 :   if (NULL == exchange_cmd)
      86              :   {
      87            0 :     GNUNET_break (0);
      88            0 :     TALER_TESTING_interpreter_fail (is);
      89            0 :     return NULL;
      90              :   }
      91          510 :   if (GNUNET_OK !=
      92          510 :       TALER_TESTING_get_trait_exchange_url (exchange_cmd,
      93              :                                             &exchange_url))
      94              :   {
      95            0 :     GNUNET_break (0);
      96            0 :     TALER_TESTING_interpreter_fail (is);
      97            0 :     return NULL;
      98              :   }
      99          510 :   return exchange_url;
     100              : }
     101              : 
     102              : 
     103              : struct TALER_EXCHANGE_Keys *
     104          465 : TALER_TESTING_get_keys (
     105              :   struct TALER_TESTING_Interpreter *is)
     106              : {
     107              :   struct TALER_EXCHANGE_Keys *keys;
     108              :   const struct TALER_TESTING_Command *exchange_cmd;
     109              : 
     110              :   exchange_cmd
     111          465 :     = TALER_TESTING_interpreter_get_command (is,
     112              :                                              "exchange");
     113          465 :   if (NULL == exchange_cmd)
     114              :   {
     115            0 :     GNUNET_break (0);
     116            0 :     TALER_TESTING_interpreter_fail (is);
     117            0 :     return NULL;
     118              :   }
     119          465 :   if (GNUNET_OK !=
     120          465 :       TALER_TESTING_get_trait_keys (exchange_cmd,
     121              :                                     &keys))
     122              :   {
     123            0 :     GNUNET_break (0);
     124            0 :     TALER_TESTING_interpreter_fail (is);
     125            0 :     return NULL;
     126              :   }
     127          465 :   return keys;
     128              : }
     129              : 
     130              : 
     131              : /* end of testing_api_traits.c */
        

Generated by: LCOV version 2.0-1