chiark / gitweb /
shared: utf8 - support ucs4 -> utf8
[elogind.git] / src / test / test-json.c
index 8777cf7a401d060837a0976edd19ac4bd52e8ed1..e53e8ed50f18d932ebd1c6bb03b29253a895434f 100644 (file)
@@ -19,6 +19,8 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include <math.h>
+
 #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,7 @@ 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);
 
         return 0;
 }