summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-05-17 17:10:38 +0200
committerChristian Grothoff <christian@grothoff.org>2015-05-17 17:10:38 +0200
commit2f67dbebc572f1c70c3bfcb39fec45591aea9bc8 (patch)
tree4ae3819d40efd9cf8a2ba2c60d1bcd2019a19016 /src/util
parentb1401f93da11d38d49a5117d4f717fec384e7176 (diff)
downloadexchange-2f67dbebc572f1c70c3bfcb39fec45591aea9bc8.tar.gz
exchange-2f67dbebc572f1c70c3bfcb39fec45591aea9bc8.tar.bz2
exchange-2f67dbebc572f1c70c3bfcb39fec45591aea9bc8.zip
test json-raw conversion, fix assertion
Diffstat (limited to 'src/util')
-rw-r--r--src/util/json.c2
-rw-r--r--src/util/test_json.c33
2 files changed, 34 insertions, 1 deletions
diff --git a/src/util/json.c b/src/util/json.c
index 8abcef1c9..3d702b7be 100644
--- a/src/util/json.c
+++ b/src/util/json.c
@@ -294,7 +294,7 @@ TALER_json_to_data (json_t *json,
EXITIF (NULL == (enc = json_string_value (json)));
len = strlen (enc);
- EXITIF ((((len * 5) / 8) + ((((len * 5) % 8) == 0) ? 0 : 1)) == out_size);
+ EXITIF (((len * 5) / 8) != out_size);
EXITIF (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, len, out, out_size));
return GNUNET_OK;
EXITIF_exit:
diff --git a/src/util/test_json.c b/src/util/test_json.c
index a1a5cd54f..42968ba90 100644
--- a/src/util/test_json.c
+++ b/src/util/test_json.c
@@ -88,6 +88,37 @@ test_time ()
}
+/**
+ * Test raw (binary) conversion from/to JSON.
+ *
+ * @return 0 on success
+ */
+static int
+test_raw ()
+{
+ char blob[256];
+ char blob2[256];
+ unsigned int i;
+ json_t *j;
+
+ for (i=0;i<=256;i++)
+ {
+ memset (blob, i, i);
+ j = TALER_json_from_data (blob, i);
+ GNUNET_assert (NULL != j);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_json_to_data (j,
+ blob2,
+ i));
+ GNUNET_assert (0 ==
+ memcmp (blob,
+ blob2,
+ i));
+ }
+ return 0;
+}
+
+
int
main(int argc,
const char *const argv[])
@@ -99,6 +130,8 @@ main(int argc,
return 1;
if (0 != test_time ())
return 1;
+ if (0 != test_raw ())
+ return 1;
/* FIXME: implement test... */
return 0;
}