static void json_string (struct sprinter *sp, const char *val) { if (val == NULL) val = ""; json_string_len (sp, val, strlen (val)); }
static void test_equal_simple() { json_t *value1, *value2; if(json_equal(NULL, NULL)) fail("json_equal fails for two NULLs"); value1 = json_true(); if(json_equal(value1, NULL) || json_equal(NULL, value1)) fail("json_equal fails for NULL"); /* this covers true, false and null as they are singletons */ if(!json_equal(value1, value1)) fail("identical objects are not equal"); json_decref(value1); /* integer */ value1 = json_integer(1); value2 = json_integer(1); if(!value1 || !value2) fail("unable to create integers"); if(!json_equal(value1, value2)) fail("json_equal fails for two equal integers"); json_decref(value2); value2 = json_integer(2); if(!value2) fail("unable to create an integer"); if(json_equal(value1, value2)) fail("json_equal fails for two inequal integers"); json_decref(value1); json_decref(value2); /* real */ value1 = json_real(1.2); value2 = json_real(1.2); if(!value1 || !value2) fail("unable to create reals"); if(!json_equal(value1, value2)) fail("json_equal fails for two equal reals"); json_decref(value2); value2 = json_real(3.141592); if(!value2) fail("unable to create an real"); if(json_equal(value1, value2)) fail("json_equal fails for two inequal reals"); json_decref(value1); json_decref(value2); /* string */ value1 = json_string("foo"); value2 = json_string_ex("foo",sizeof("foo")-1,JSON_LITERAL); if(!value1 || !value2) fail("unable to create strings"); if(!json_equal(value1, value2)) fail("json_equal fails for two equal strings"); if(json_string_set_ex(value2, "bar2", sizeof("bar2")-1, 0)) fail("unable to reassign a string"); if(json_string_len(value2) != sizeof("bar2")-1) fail("wrong len after assignation"); if(json_equal(value1, value2)) fail("json_equal fails for two inequal strings"); json_decref(value1); json_decref(value2); }