Add test for numbers
This commit is contained in:
parent
0565988d12
commit
b3e265eb84
1
test/.gitignore
vendored
1
test/.gitignore
vendored
@ -3,4 +3,5 @@ loads_dumps
|
||||
load_file_dump_file
|
||||
testlogs
|
||||
testprogs/test_array
|
||||
testprogs/test_number
|
||||
testprogs/test_object
|
||||
|
@ -1,6 +1,6 @@
|
||||
check_PROGRAMS = \
|
||||
loadf_dumpf loads_dumps load_file_dump_file \
|
||||
testprogs/test_object testprogs/test_array
|
||||
testprogs/test_array testprogs/test_number testprogs/test_object
|
||||
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/src
|
||||
AM_CFLAGS = -Wall -Werror
|
||||
|
44
test/testprogs/test_number.c
Normal file
44
test/testprogs/test_number.c
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Petri Lehtinen <petri@digip.org>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#include <jansson.h>
|
||||
#include "util.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
json_t *integer, *real;
|
||||
int i;
|
||||
double d;
|
||||
|
||||
integer = json_integer(5);
|
||||
real = json_real(100.1);
|
||||
|
||||
if(!integer)
|
||||
fail("unable to create integer");
|
||||
if(!real)
|
||||
fail("unable to create real");
|
||||
|
||||
i = json_integer_value(integer);
|
||||
if(i != 5)
|
||||
fail("wrong integer value");
|
||||
|
||||
d = json_real_value(real);
|
||||
if(d != 100.1)
|
||||
fail("wrong real value");
|
||||
|
||||
d = json_number_value(integer);
|
||||
if(d != 5.0)
|
||||
fail("wrong number value");
|
||||
d = json_number_value(real);
|
||||
if(d != 100.1)
|
||||
fail("wrong number value");
|
||||
|
||||
json_decref(integer);
|
||||
json_decref(real);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user