testing_api_traits.c (3336B)
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 TALER_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_IMPL_SIMPLE_TRAIT) 31 32 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 TALER_TESTING_trait_end () 41 { 42 struct TALER_TESTING_Trait end = { 43 .index = 0, 44 .trait_name = NULL, 45 .ptr = NULL 46 }; 47 48 return end; 49 } 50 51 52 enum GNUNET_GenericReturnValue 53 TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits, 54 const void **ret, 55 const char *trait, 56 unsigned int index) 57 { 58 for (unsigned int i = 0; NULL != traits[i].trait_name; i++) 59 { 60 if ( (0 == strcmp (trait, 61 traits[i].trait_name)) && 62 (index == traits[i].index) ) 63 { 64 *ret = (void *) traits[i].ptr; 65 return GNUNET_OK; 66 } 67 } 68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 69 "Trait %s/%u not found.\n", 70 trait, 71 index); 72 return GNUNET_SYSERR; 73 } 74 75 76 const char * 77 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 = TALER_TESTING_interpreter_get_command (is, 84 "exchange"); 85 if (NULL == exchange_cmd) 86 { 87 GNUNET_break (0); 88 TALER_TESTING_interpreter_fail (is); 89 return NULL; 90 } 91 if (GNUNET_OK != 92 TALER_TESTING_get_trait_exchange_url (exchange_cmd, 93 &exchange_url)) 94 { 95 GNUNET_break (0); 96 TALER_TESTING_interpreter_fail (is); 97 return NULL; 98 } 99 return exchange_url; 100 } 101 102 103 struct TALER_EXCHANGE_Keys * 104 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 = TALER_TESTING_interpreter_get_command (is, 112 "exchange"); 113 if (NULL == exchange_cmd) 114 { 115 GNUNET_break (0); 116 TALER_TESTING_interpreter_fail (is); 117 return NULL; 118 } 119 if (GNUNET_OK != 120 TALER_TESTING_get_trait_keys (exchange_cmd, 121 &keys)) 122 { 123 GNUNET_break (0); 124 TALER_TESTING_interpreter_fail (is); 125 return NULL; 126 } 127 return keys; 128 } 129 130 131 /* end of testing_api_traits.c */