Add test for numbers

This commit is contained in:
Petri Lehtinen 2009-08-24 20:54:40 +03:00
parent 0565988d12
commit b3e265eb84
3 changed files with 46 additions and 1 deletions

1
test/.gitignore vendored
View File

@ -3,4 +3,5 @@ loads_dumps
load_file_dump_file load_file_dump_file
testlogs testlogs
testprogs/test_array testprogs/test_array
testprogs/test_number
testprogs/test_object testprogs/test_object

View File

@ -1,6 +1,6 @@
check_PROGRAMS = \ check_PROGRAMS = \
loadf_dumpf loads_dumps load_file_dump_file \ 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_CPPFLAGS = -I$(top_srcdir)/src
AM_CFLAGS = -Wall -Werror AM_CFLAGS = -Wall -Werror

View 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;
}