jansson/test/suites/api/test_number.c
Petri Lehtinen d7ddbf3661 Make real number encoding and decoding work under all locales
The decimal point '.' is changed to locale's decimal point
before/after JSON conversion to make C standard library's
locale-specific string conversion functions work correctly.

All the tests now call setlocale(LC_ALL, "") on startup to use the
locale set in the environment.

Fixes GH-32.
2011-10-02 21:31:17 +03:00

43 lines
903 B
C

/*
* Copyright (c) 2009-2011 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"
static void run_tests()
{
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);
}