1 /* 2 * Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org> 3 * 4 * Jansson is free software; you can redistribute it and/or modify 5 * it under the terms of the MIT license. See LICENSE for details. 6 */ 7 8 #include <math.h> 9 #include <jansson.h> 10 #include "util.h" 11 12 #ifdef INFINITY 13 // This test triggers "warning C4756: overflow in constant arithmetic" 14 // in Visual Studio. This warning is triggered here by design, so disable it. 15 // (This can only be done on function level so we keep these tests separate) 16 #ifdef _MSC_VER 17 #pragma warning(push) 18 #pragma warning (disable: 4756) 19 #endif test_inifity()20static void test_inifity() 21 { 22 json_t *real = json_real(INFINITY); 23 if (real != NULL) 24 fail("could construct a real from Inf"); 25 26 real = json_real(1.0); 27 if (json_real_set(real, INFINITY) != -1) 28 fail("could set a real to Inf"); 29 30 if (json_real_value(real) != 1.0) 31 fail("real value changed unexpectedly"); 32 33 json_decref(real); 34 #ifdef _MSC_VER 35 #pragma warning(pop) 36 #endif 37 } 38 #endif // INFINITY 39 run_tests()40static void run_tests() 41 { 42 json_t *integer, *real; 43 json_int_t i; 44 double d; 45 46 integer = json_integer(5); 47 real = json_real(100.1); 48 49 if(!integer) 50 fail("unable to create integer"); 51 if(!real) 52 fail("unable to create real"); 53 54 i = json_integer_value(integer); 55 if(i != 5) 56 fail("wrong integer value"); 57 58 d = json_real_value(real); 59 if(d != 100.1) 60 fail("wrong real value"); 61 62 d = json_number_value(integer); 63 if(d != 5.0) 64 fail("wrong number value"); 65 d = json_number_value(real); 66 if(d != 100.1) 67 fail("wrong number value"); 68 69 json_decref(integer); 70 json_decref(real); 71 72 #ifdef NAN 73 real = json_real(NAN); 74 if(real != NULL) 75 fail("could construct a real from NaN"); 76 77 real = json_real(1.0); 78 if(json_real_set(real, NAN) != -1) 79 fail("could set a real to NaN"); 80 81 if(json_real_value(real) != 1.0) 82 fail("real value changed unexpectedly"); 83 84 json_decref(real); 85 #endif 86 87 #ifdef INFINITY 88 test_inifity(); 89 #endif 90 } 91