diff --git a/test/.gitignore b/test/.gitignore index f2f34d3..a31f16f 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -3,4 +3,5 @@ loads_dumps load_file_dump_file testlogs testprogs/test_array +testprogs/test_number testprogs/test_object diff --git a/test/Makefile.am b/test/Makefile.am index 9789365..eedf8de 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -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 diff --git a/test/testprogs/test_number.c b/test/testprogs/test_number.c new file mode 100644 index 0000000..a634125 --- /dev/null +++ b/test/testprogs/test_number.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009 Petri Lehtinen + * + * Jansson is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ + +#include +#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; +}