summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-05-17 16:53:00 +0200
committerChristian Grothoff <christian@grothoff.org>2015-05-17 16:53:00 +0200
commit3817f83dd5b65fb7d475560b2637276a89f69087 (patch)
treebf9b12189c616ca421cc6036b355b17e472601c5 /src/util
parent25e530f37a09dd154d09e468cc724252524da6c6 (diff)
downloadexchange-3817f83dd5b65fb7d475560b2637276a89f69087.tar.gz
exchange-3817f83dd5b65fb7d475560b2637276a89f69087.tar.bz2
exchange-3817f83dd5b65fb7d475560b2637276a89f69087.zip
adding testcase for json-amount conversions, fixing typos and missing currency initialization
Diffstat (limited to 'src/util')
-rw-r--r--src/util/json.c5
-rw-r--r--src/util/test_json.c25
2 files changed, 29 insertions, 1 deletions
diff --git a/src/util/json.c b/src/util/json.c
index 1747cd927..90031faae 100644
--- a/src/util/json.c
+++ b/src/util/json.c
@@ -227,10 +227,13 @@ TALER_json_to_amount (json_t *json,
&error,
JSON_STRICT,
"{s:s, s:I, s:I}",
- "curreny", &currency,
+ "currency", &currency,
"value", &value,
"fraction", &fraction));
EXITIF (3 < strlen (currency));
+ EXITIF (TALER_CURRENCY_LEN <= strlen (currency));
+ strcpy (r_amount->currency,
+ currency);
r_amount->value = (uint32_t) value;
r_amount->fraction = (uint32_t) fraction;
return GNUNET_OK;
diff --git a/src/util/test_json.c b/src/util/test_json.c
index 9eb72fb8c..dd494c679 100644
--- a/src/util/test_json.c
+++ b/src/util/test_json.c
@@ -24,6 +24,29 @@
#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
main(int argc,
const char *const argv[])
@@ -31,6 +54,8 @@ main(int argc,
GNUNET_log_setup ("test-json",
"WARNING",
NULL);
+ if (0 != test_amount ())
+ return 1;
/* FIXME: implement test... */
return 0;
}