X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ftest%2Ftest-json.c;h=b09131891cf581e24f460e9d03ace596c728210e;hb=764aad6258eec3bd4ae62ea341ea507bd69ce628;hp=8777cf7a401d060837a0976edd19ac4bd52e8ed1;hpb=e7eebcfc42f00aa481ef31abc8e7e243c16f5b2c;p=elogind.git diff --git a/src/test/test-json.c b/src/test/test-json.c index 8777cf7a4..b09131891 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -19,6 +19,8 @@ along with systemd; If not, see . ***/ +#include + #include "log.h" #include "util.h" #include "json.h" @@ -52,7 +54,7 @@ static void test_one(const char *data, ...) { double d; d = va_arg(ap, double); - assert_se(abs(d - v.real) < 0.001); + assert_se(fabs(d - v.real) < 0.001); } else if (t == JSON_INTEGER) { intmax_t i; @@ -96,6 +98,10 @@ int main(int argc, char *argv[]) { test_one("{\"foo\" : [true, false]}", JSON_OBJECT_OPEN, JSON_STRING, "foo", JSON_COLON, JSON_ARRAY_OPEN, JSON_BOOLEAN, true, JSON_COMMA, JSON_BOOLEAN, false, JSON_ARRAY_CLOSE, JSON_OBJECT_CLOSE, JSON_END); test_one("\"\xef\xbf\xbd\"", JSON_STRING, "\xef\xbf\xbd", JSON_END); test_one("\"\\ufffd\"", JSON_STRING, "\xef\xbf\xbd", JSON_END); + test_one("\"\\uf\"", -EINVAL); + test_one("\"\\ud800a\"", -EINVAL); + test_one("\"\\udc00\\udc00\"", -EINVAL); + test_one("\"\\ud801\\udc37\"", JSON_STRING, "\xf0\x90\x90\xb7", JSON_END); return 0; }