On Fri, 2015-05-15 at 17:24 +0200, Lennart Poettering wrote: > On Thu, 07.05.15 17:47, Pavel Odvody (podv...@redhat.com) wrote: > > > Signed-off-by: Pavel Odvody <podv...@redhat.com> > > --- > > src/test/test-json.c | 16 ++++++++++++++++ > > 1 file changed, 16 insertions(+) > > > > diff --git a/src/test/test-json.c b/src/test/test-json.c > > index 24dc700..745eeb0 100644 > > --- a/src/test/test-json.c > > +++ b/src/test/test-json.c > > @@ -72,6 +72,17 @@ static void test_one(const char *data, ...) { > > va_end(ap); > > } > > > > +static void test_file(const char *data) { > > + json_variant *v = NULL; > > + int r = json_parse(data, &v); > > + > > + assert_se(r == 0); > > + assert_se(v != NULL); > > + assert_se(v->type == JSON_VARIANT_OBJECT); > > + > > + json_variant_unref(v); > > +} > > + > > int main(int argc, char *argv[]) { > > > > test_one("x", -EINVAL); > > @@ -102,5 +113,10 @@ int main(int argc, char *argv[]) { > > test_one("\"\\udc00\\udc00\"", -EINVAL); > > test_one("\"\\ud801\\udc37\"", JSON_STRING, "\xf0\x90\x90\xb7", > > JSON_END); > > > > + test_one("[1, 2]", JSON_ARRAY_OPEN, JSON_INTEGER, 1, JSON_COMMA, > > JSON_INTEGER, 2, JSON_ARRAY_CLOSE, JSON_END); > > + > > + test_file("{\"k\": \"v\", \"foo\": [1, 2, 3], \"bar\": {\"zap\": > > null}}"); > > + test_file("{\"mutant\": [1, null, \"1\", {\"1\": [1, \"1\"]}], > > \"blah\": 1.27}"); > > + > > Any chance you can extend the test to check the structure of the of > the object parsed for validity here? > > Lennart >
Yes, though I wonder how to write down the test specs. Something like this for the first test case? JSON_SCOPE, JSON_KEY, "k", JSON_VALUE, "v", JSON_KEY, "foo", JSON_VALUE, JSON_SCOPE, JSON_VALUE, 1, JSON_VALUE, 2, JSON_VALUE, 3, JSON_ENDSCOPE, JSON_KEY, "bar", JSON_VALUE, JSON_SCOPE, JSON_KEY, "zap", JSON_VALUE, NULL JSON_ENDSCOPE. JSON_ENDSCOPE -- Pavel Odvody <podv...@redhat.com> Software Engineer - EMEA ENG Developer Experience 5EC1 95C1 8E08 5BD9 9BBF 9241 3AFA 3A66 024F F68D Red Hat Czech s.r.o., Purkyňova 99/71, 612 45, Brno
signature.asc
Description: This is a digitally signed message part
_______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel