test json-raw conversion, fix assertion
This commit is contained in:
parent
b1401f93da
commit
2f67dbebc5
@ -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:
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user