From b3e265eb843328749b5d1a943377992034c49475 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Mon, 24 Aug 2009 20:54:40 +0300 Subject: [PATCH] Add test for numbers --- test/.gitignore | 1 + test/Makefile.am | 2 +- test/testprogs/test_number.c | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/testprogs/test_number.c 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; +}