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