core-lightning/common/test/run-json.c

49 lines
1.0 KiB
C
Raw Normal View History

#include "../json.c"
#include <common/utils.h>
#include <stdio.h>
/* AUTOGENERATED MOCKS START */
/* AUTOGENERATED MOCKS END */
// issue #577
static void do_json_tok_bitcoin_amount(const char* val, uint64_t expected)
{
uint64_t amount;
jsmntok_t tok;
tok.start = 0;
tok.end = strlen(val);
fprintf(stderr, "do_json_tok_bitcoin_amount(\"%s\", %"PRIu64"): ", val, expected);
assert(json_tok_bitcoin_amount(val, &tok, &amount) == true);
assert(amount == expected);
fprintf(stderr, "ok\n");
}
static int test_json_tok_bitcoin_amount(void)
{
do_json_tok_bitcoin_amount("0.00000001", 1);
do_json_tok_bitcoin_amount("0.00000007", 7);
do_json_tok_bitcoin_amount("0.00000008", 8);
do_json_tok_bitcoin_amount("0.00000010", 10);
do_json_tok_bitcoin_amount("0.12345678", 12345678);
do_json_tok_bitcoin_amount("0.01234567", 1234567);
do_json_tok_bitcoin_amount("123.45678900", 12345678900);
return 0;
}
int main(void)
{
setup_locale();
test_json_tok_bitcoin_amount();
assert(!taken_any());
take_cleanup();
}