2 * Copyright (c) 2009-2011 Petri Lehtinen <petri@digip.org>
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.
19 static const char my_str[] = "[\"A\", {\"B\": \"C\", \"e\": false}, 1, null, \"foo\"]";
21 static int greedy_reader(void *buf, size_t buflen, void *arg)
23 struct my_source *s = arg;
24 if (buflen > s->cap - s->off)
25 buflen = s->cap - s->off;
27 memcpy(buf, s->buf + s->off, buflen);
35 static void run_tests()
42 s.cap = strlen(my_str);
45 json = json_load_callback(greedy_reader, &s, 0, &error);
48 fail("json_load_callback failed on a valid callback");
52 s.cap = strlen(my_str) - 1;
55 json = json_load_callback(greedy_reader, &s, 0, &error);
58 fail("json_load_callback should have failed on an incomplete stream, but it didn't");
60 if (strcmp(error.source, "<callback>") != 0) {
61 fail("json_load_callback returned an invalid error source");
63 if (strcmp(error.text, "']' expected near end of file") != 0) {
64 fail("json_load_callback returned an invalid error message for an unclosed top-level array");
67 json = json_load_callback(NULL, NULL, 0, &error);
70 fail("json_load_callback should have failed on NULL load callback, but it didn't");
72 if (strcmp(error.text, "wrong arguments") != 0) {
73 fail("json_load_callback returned an invalid error message for a NULL load callback");