adding testcase for json-amount conversions, fixing typos and missing currency initialization
This commit is contained in:
parent
25e530f37a
commit
3817f83dd5
@ -227,10 +227,13 @@ TALER_json_to_amount (json_t *json,
|
|||||||
&error,
|
&error,
|
||||||
JSON_STRICT,
|
JSON_STRICT,
|
||||||
"{s:s, s:I, s:I}",
|
"{s:s, s:I, s:I}",
|
||||||
"curreny", ¤cy,
|
"currency", ¤cy,
|
||||||
"value", &value,
|
"value", &value,
|
||||||
"fraction", &fraction));
|
"fraction", &fraction));
|
||||||
EXITIF (3 < strlen (currency));
|
EXITIF (3 < strlen (currency));
|
||||||
|
EXITIF (TALER_CURRENCY_LEN <= strlen (currency));
|
||||||
|
strcpy (r_amount->currency,
|
||||||
|
currency);
|
||||||
r_amount->value = (uint32_t) value;
|
r_amount->value = (uint32_t) value;
|
||||||
r_amount->fraction = (uint32_t) fraction;
|
r_amount->fraction = (uint32_t) fraction;
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
|
@ -24,6 +24,29 @@
|
|||||||
#include "taler_json_lib.h"
|
#include "taler_json_lib.h"
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
test_amount ()
|
||||||
|
{
|
||||||
|
json_t *j;
|
||||||
|
struct TALER_Amount a1;
|
||||||
|
struct TALER_Amount a2;
|
||||||
|
|
||||||
|
GNUNET_assert (GNUNET_OK ==
|
||||||
|
TALER_string_to_amount ("EUR:4.3",
|
||||||
|
&a1));
|
||||||
|
j = TALER_json_from_amount (&a1);
|
||||||
|
GNUNET_assert (NULL != j);
|
||||||
|
GNUNET_assert (GNUNET_OK ==
|
||||||
|
TALER_json_to_amount (j,
|
||||||
|
&a2));
|
||||||
|
GNUNET_assert (0 ==
|
||||||
|
TALER_amount_cmp (&a1,
|
||||||
|
&a2));
|
||||||
|
json_decref (j);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc,
|
main(int argc,
|
||||||
const char *const argv[])
|
const char *const argv[])
|
||||||
@ -31,6 +54,8 @@ main(int argc,
|
|||||||
GNUNET_log_setup ("test-json",
|
GNUNET_log_setup ("test-json",
|
||||||
"WARNING",
|
"WARNING",
|
||||||
NULL);
|
NULL);
|
||||||
|
if (0 != test_amount ())
|
||||||
|
return 1;
|
||||||
/* FIXME: implement test... */
|
/* FIXME: implement test... */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user