[systemd-devel] [PATCH 3/5] test/test-json: Tests for the JSON parser and the tokenizer bugfix

Pavel Odvody podvody at redhat.com
Mon May 18 02:04:49 PDT 2015


On Fri, 2015-05-15 at 17:24 +0200, Lennart Poettering wrote:
> On Thu, 07.05.15 17:47, Pavel Odvody (podvody at redhat.com) wrote:
> 
> > Signed-off-by: Pavel Odvody <podvody at 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 <podvody at 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150518/3eb077c5/attachment.sig>


More information about the systemd-devel mailing list