[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH V4 2/3] tests: add tests for virJSONStringCompare
Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx> --- This patch is new to V4. tests/jsontest.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/tests/jsontest.c b/tests/jsontest.c index a2a42e3..5d5f619 100644 --- a/tests/jsontest.c +++ b/tests/jsontest.c @@ -12,6 +12,7 @@ struct testInfo { const char *doc; const char *expect; + const char **ignore_contexts; bool pass; }; @@ -131,22 +132,45 @@ testJSONAddRemove(const void *data) static int +testJSONCompare(const void *data) +{ + const struct testInfo *info = data; + bool ret; + + ret = virJSONStringCompare(info->expect, + info->doc, + info->ignore_contexts, + 0); + + if (ret == info->pass) + return 0; + else + return -1; +} + + +static int mymain(void) { int ret = 0; + const char *ignore_paths[] = { + "/dict1/key3", + "/key4", + NULL + }; -#define DO_TEST_FULL(name, cmd, doc, expect, pass) \ +#define DO_TEST_FULL(name, cmd, doc, expect, ignore_ctx, pass) \ do { \ - struct testInfo info = { doc, expect, pass }; \ + struct testInfo info = { doc, expect, ignore_ctx, pass }; \ if (virtTestRun(name, testJSON ## cmd, &info) < 0) \ ret = -1; \ } while (0) #define DO_TEST_PARSE(name, doc) \ - DO_TEST_FULL(name, FromString, doc, NULL, true) + DO_TEST_FULL(name, FromString, doc, NULL, NULL, true) #define DO_TEST_PARSE_FAIL(name, doc) \ - DO_TEST_FULL(name, FromString, doc, NULL, false) + DO_TEST_FULL(name, FromString, doc, NULL, NULL, false) DO_TEST_PARSE("Simple", "{\"return\": {}, \"id\": \"libvirt-1\"}"); @@ -188,9 +212,10 @@ mymain(void) DO_TEST_FULL("add and remove", AddRemove, "{\"name\": \"sample\", \"value\": true}", "{\"value\":true,\"newname\":\"foo\"}", + NULL, true); DO_TEST_FULL("add and remove", AddRemove, - "[ 1 ]", NULL, false); + "[ 1 ]", NULL, NULL, false); DO_TEST_PARSE("almost nothing", "[]"); @@ -214,6 +239,34 @@ mymain(void) "[ {[\"key1\", \"key2\"]: \"value\"} ]"); DO_TEST_PARSE_FAIL("object with unterminated key", "{ \"key:7 }"); + DO_TEST_FULL("Compare identical docs", Compare, + "{ \"key1\" : \"value1\", \"key2\" : \"value2\"}", + "{ \"key1\" : \"value1\", \"key2\" : \"value2\"}", + NULL, true); + + DO_TEST_FULL("Compare different docs", Compare, + "{\"dict1\" : { \"key1\" : \"value1\", \"key2\" : \"value2\", " + "\"key3\" : [\"elem1\", \"elemfoo\"]}}", + "{\"dict1\" : { \"key1\" : \"value1\", \"key2\" : \"value2\", " + "\"key3\" : [\"elem1\", \"elem2\"]}}", + NULL, false); + + DO_TEST_FULL("Compare docs and ignore differing contexts", Compare, + "{\"dict1\" : { \"key1\" : \"value1\", \"key2\" : \"value2\", " + "\"key3\" : \"valuefoo\"}, \"key4\" : \"valuebar\"}", + "{\"dict1\" : { \"key1\" : \"value1\", \"key2\" : \"value2\", " + "\"key3\" : \"value3\"}, \"key4\" : \"value4\"}", + ignore_paths, true); + + DO_TEST_FULL("Compare docs with insufficient ignored contexts", Compare, + "{\"dict1\" : { \"key1\" : \"value1\", \"key2\" : \"value2\", " + "\"key3\" : \"valuefoo\"}, \"key4\" : \"valuebar\", " + "\"key5\" : \"valuebaz\"}", + "{\"dict1\" : { \"key1\" : \"value1\", \"key2\" : \"value2\", " + "\"key3\" : \"value3\"}, \"key4\" : \"value4\", " + "\"key5\" : \"value5\"}", + ignore_paths, false); + return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } -- 1.8.4.5 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |