summaryrefslogtreecommitdiff
path: root/src/json/test_json.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/json/test_json.c')
-rw-r--r--src/json/test_json.c100
1 files changed, 95 insertions, 5 deletions
diff --git a/src/json/test_json.c b/src/json/test_json.c
index e312a4ed3..fba72f84b 100644
--- a/src/json/test_json.c
+++ b/src/json/test_json.c
@@ -91,8 +91,8 @@ path_cb (void *cls,
static int
test_contract (void)
{
- struct GNUNET_HashCode h1;
- struct GNUNET_HashCode h2;
+ struct TALER_PrivateContractHashP h1;
+ struct TALER_PrivateContractHashP h2;
json_t *c1;
json_t *c2;
json_t *c3;
@@ -103,7 +103,8 @@ test_contract (void)
"k2", "n1", "n2",
/***/ "$forgettable", "n1", true);
GNUNET_assert (GNUNET_OK ==
- TALER_JSON_contract_seed_forgettable (c1));
+ TALER_JSON_contract_seed_forgettable (c1,
+ c1));
GNUNET_assert (GNUNET_OK ==
TALER_JSON_contract_hash (c1,
&h1));
@@ -160,7 +161,7 @@ test_contract (void)
GNUNET_assert (GNUNET_OK ==
TALER_JSON_contract_part_forget (c1,
"k2"));
- json_dumpf (c1, stderr, JSON_INDENT (2));
+ // json_dumpf (c1, stderr, JSON_INDENT (2));
GNUNET_assert (GNUNET_OK ==
TALER_JSON_contract_hash (c1,
&h2));
@@ -182,7 +183,7 @@ test_contract (void)
GNUNET_assert (GNUNET_OK ==
TALER_JSON_contract_hash (c1,
&h1));
- json_dumpf (c1, stderr, JSON_INDENT (2));
+ // json_dumpf (c1, stderr, JSON_INDENT (2));
json_decref (c1);
{
char *s;
@@ -330,6 +331,91 @@ test_contract (void)
}
+static int
+test_json_canon (void)
+{
+ {
+ json_t *c1;
+ char *canon;
+ c1 = json_pack ("{s:s}",
+ "k1", "Hello\nWorld");
+
+ canon = TALER_JSON_canonicalize (c1);
+ GNUNET_assert (NULL != canon);
+
+ printf ("canon: '%s'\n", canon);
+
+ GNUNET_assert (0 == strcmp (canon,
+ "{\"k1\":\"Hello\\nWorld\"}"));
+ }
+ {
+ json_t *c1;
+ char *canon;
+ c1 = json_pack ("{s:s}",
+ "k1", "Testing “unicode” characters");
+
+ canon = TALER_JSON_canonicalize (c1);
+ GNUNET_assert (NULL != canon);
+
+ printf ("canon: '%s'\n", canon);
+
+ GNUNET_assert (0 == strcmp (canon,
+ "{\"k1\":\"Testing “unicode” characters\"}"));
+ }
+ {
+ json_t *c1;
+ char *canon;
+ c1 = json_pack ("{s:s}",
+ "k1", "low range \x05 chars");
+
+ canon = TALER_JSON_canonicalize (c1);
+ GNUNET_assert (NULL != canon);
+
+ printf ("canon: '%s'\n", canon);
+
+ GNUNET_assert (0 == strcmp (canon,
+ "{\"k1\":\"low range \\u0005 chars\"}"));
+ }
+
+
+ return 0;
+}
+
+
+static int
+test_rfc8785 (void)
+{
+ struct TALER_PrivateContractHashP h1;
+ json_t *c1;
+
+ c1 = json_pack ("{s:s}",
+ "k1", "\x08\x0B\t\1\\\x0d");
+ GNUNET_assert (GNUNET_OK ==
+ TALER_JSON_contract_hash (c1,
+ &h1));
+ {
+ char *s;
+
+ s = GNUNET_STRINGS_data_to_string_alloc (&h1,
+ sizeof (h1));
+ if (0 !=
+ strcmp (s,
+ "531S33T8ZRGW6548G7T67PMDNGS4Z1D8A2GMB87G3PNKYTW6KGF7Q99XVCGXBKVA2HX6PR5ENJ1PQ5ZTYMMXQB6RM7S82VP7ZG2X5G8"))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid reference hash: %s\n",
+ s);
+ GNUNET_free (s);
+ json_decref (c1);
+ return 1;
+ }
+ GNUNET_free (s);
+ }
+ json_decref (c1);
+ return 0;
+}
+
+
int
main (int argc,
const char *const argv[])
@@ -343,6 +429,10 @@ main (int argc,
return 1;
if (0 != test_contract ())
return 2;
+ if (0 != test_json_canon ())
+ return 2;
+ if (0 != test_rfc8785 ())
+ return 2;
return 0;
}