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 "platform.h" 26 : #include "taler_json_lib.h" 27 : #include <gnunet/gnunet_curl_lib.h> 28 : #include "taler_signatures.h" 29 : #include "taler_testing_lib.h" 30 : 31 : 32 35712 : TALER_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_IMPL_SIMPLE_TRAIT) 33 : 34 23377 : TALER_TESTING_INDEXED_TRAITS (TALER_TESTING_MAKE_IMPL_INDEXED_TRAIT) 35 : 36 : 37 : /** 38 : * End a trait array. Usually, commands offer several traits, 39 : * and put them in arrays. 40 : */ 41 : struct TALER_TESTING_Trait 42 7276 : TALER_TESTING_trait_end () 43 : { 44 7276 : struct TALER_TESTING_Trait end = { 45 : .index = 0, 46 : .trait_name = NULL, 47 : .ptr = NULL 48 : }; 49 : 50 7276 : return end; 51 : } 52 : 53 : 54 : enum GNUNET_GenericReturnValue 55 7226 : TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits, 56 : const void **ret, 57 : const char *trait, 58 : unsigned int index) 59 : { 60 34247 : for (unsigned int i = 0; NULL != traits[i].trait_name; i++) 61 : { 62 33610 : if ( (0 == strcmp (trait, 63 33610 : traits[i].trait_name)) && 64 6669 : (index == traits[i].index) ) 65 : { 66 6589 : *ret = (void *) traits[i].ptr; 67 6589 : return GNUNET_OK; 68 : } 69 : } 70 637 : GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 71 : "Trait %s/%u not found.\n", 72 : trait, 73 : index); 74 637 : return GNUNET_SYSERR; 75 : } 76 : 77 : 78 : const char * 79 510 : TALER_TESTING_get_exchange_url (struct TALER_TESTING_Interpreter *is) 80 : { 81 : const char *exchange_url; 82 : const struct TALER_TESTING_Command *exchange_cmd; 83 : 84 : exchange_cmd 85 510 : = TALER_TESTING_interpreter_get_command (is, 86 : "exchange"); 87 510 : if (NULL == exchange_cmd) 88 : { 89 0 : GNUNET_break (0); 90 0 : TALER_TESTING_interpreter_fail (is); 91 0 : return NULL; 92 : } 93 510 : if (GNUNET_OK != 94 510 : TALER_TESTING_get_trait_exchange_url (exchange_cmd, 95 : &exchange_url)) 96 : { 97 0 : GNUNET_break (0); 98 0 : TALER_TESTING_interpreter_fail (is); 99 0 : return NULL; 100 : } 101 510 : return exchange_url; 102 : } 103 : 104 : 105 : struct TALER_EXCHANGE_Keys * 106 465 : TALER_TESTING_get_keys ( 107 : struct TALER_TESTING_Interpreter *is) 108 : { 109 : struct TALER_EXCHANGE_Keys *keys; 110 : const struct TALER_TESTING_Command *exchange_cmd; 111 : 112 : exchange_cmd 113 465 : = TALER_TESTING_interpreter_get_command (is, 114 : "exchange"); 115 465 : if (NULL == exchange_cmd) 116 : { 117 0 : GNUNET_break (0); 118 0 : TALER_TESTING_interpreter_fail (is); 119 0 : return NULL; 120 : } 121 465 : if (GNUNET_OK != 122 465 : TALER_TESTING_get_trait_keys (exchange_cmd, 123 : &keys)) 124 : { 125 0 : GNUNET_break (0); 126 0 : TALER_TESTING_interpreter_fail (is); 127 0 : return NULL; 128 : } 129 465 : return keys; 130 : } 131 : 132 : 133 : /* end of testing_api_traits.c */