test json-raw conversion, fix assertion

This commit is contained in:
Christian Grothoff 2015-05-17 17:10:38 +02:00
parent b1401f93da
commit 2f67dbebc5
2 changed files with 34 additions and 1 deletions

View File

@ -294,7 +294,7 @@ TALER_json_to_data (json_t *json,
EXITIF (NULL == (enc = json_string_value (json))); EXITIF (NULL == (enc = json_string_value (json)));
len = strlen (enc); 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)); EXITIF (GNUNET_OK != GNUNET_STRINGS_string_to_data (enc, len, out, out_size));
return GNUNET_OK; return GNUNET_OK;
EXITIF_exit: EXITIF_exit:

View File

@ -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 int
main(int argc, main(int argc,
const char *const argv[]) const char *const argv[])
@ -99,6 +130,8 @@ main(int argc,
return 1; return 1;
if (0 != test_time ()) if (0 != test_time ())
return 1; return 1;
if (0 != test_raw ())
return 1;
/* FIXME: implement test... */ /* FIXME: implement test... */
return 0; return 0;
} }