exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit f75ce2f833008a5c437d7c0d1cfa5126a5917bf7
parent 21926ce1a64fcab4164b7a4a202df7472be4ce72
Author: Özgür Kesim <oec@codeblau.de>
Date:   Thu,  1 May 2025 20:43:47 +0200

[json] added unittest for TALER_JSON_spec_array_of_data

Diffstat:
Msrc/json/test_json.c | 45+++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+), 0 deletions(-)

diff --git a/src/json/test_json.c b/src/json/test_json.c @@ -418,6 +418,49 @@ test_rfc8785 (void) } +static int +test_array (void) +{ + struct _data + { + char chars[2]; + }; + struct _data *data; + size_t num_data; + struct GNUNET_JSON_Specification spec[] = { + TALER_JSON_spec_array_of_data ("nums", + sizeof(*data), + &num_data, + (void **) &data), + GNUNET_JSON_spec_end () + }; + json_t *d; + char *buf[] = {"01","02","03","04", + "Aa","Bb","Cc","Dd"}; + + d = json_pack ("{s:[s:s:s:s:s:s:s:s]}", + "nums", + "60RG","60S0","60SG","60T0", + "85GG","89H0","8DHG","8HJ0"); + GNUNET_assert (NULL != d); + printf ("sizeof(*data)=%ld\n", sizeof(*data)); + printf ("array:>>%s<<\n", json_dumps (d, JSON_INDENT (2))); + GNUNET_assert (GNUNET_OK == + GNUNET_JSON_parse (d, spec, + NULL, NULL)); + GNUNET_assert (sizeof(buf) / sizeof(*buf) == num_data); + for (uint8_t i = 0; i<num_data; i++) + { + printf ("buf[%d]=%s vs data[%d]=%c%c\n", + i, buf[i], + i, data[i].chars[0], data[i].chars[1]); + if (0 != memcmp (buf[i],&data[i], sizeof(*data))) + return 2; + } + return 0; +} + + int main (int argc, const char *const argv[]) @@ -435,6 +478,8 @@ main (int argc, return 2; if (0 != test_rfc8785 ()) return 2; + if (0 != test_array ()) + return 2; return 0; }