]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
tests: set: add json parsing support
authorÁlvaro Neira Ayuso <alvaroneay@gmail.com>
Tue, 27 Aug 2013 18:10:55 +0000 (20:10 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 27 Aug 2013 22:21:32 +0000 (00:21 +0200)
Test the functions for parsing set in JSON.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
tests/jsonfiles/62-set.json [new file with mode: 0644]
tests/jsonfiles/63-set.json [new file with mode: 0644]
tests/nft-parsing-test.c

diff --git a/tests/jsonfiles/62-set.json b/tests/jsonfiles/62-set.json
new file mode 100644 (file)
index 0000000..c5200eb
--- /dev/null
@@ -0,0 +1 @@
+{ "set": { "name": "set0","table": "filter","flags": 3,"family": "ip","key_type": 12,"key_len": 2,"set_elem": [{"flags": 0,"key": {"data_reg": { "type" : "value", "len" : 2, "data0" : "0x00001700"}}}, {"flags": 0,"key": {"data_reg": { "type" : "value", "len" : 2, "data0" : "0x00001600"}}}]}}
diff --git a/tests/jsonfiles/63-set.json b/tests/jsonfiles/63-set.json
new file mode 100644 (file)
index 0000000..be3e564
--- /dev/null
@@ -0,0 +1 @@
+{ "set": { "name": "map0","table": "filter","flags": 11,"family": "ip","key_type": 12,"key_len": 2,"data_type": 4294967040,"data_len": 16,"set_elem": [{"flags": 0,"key": {"data_reg": { "type" : "value", "len" : 2, "data0" : "0x00001700"}},"data": {"data_reg": { "type" : "chain", "chain" : "forward"}}}, {"flags": 0,"key": {"data_reg": { "type" : "value", "len" : 2, "data0" : "0x00001600"}},"data": {"data_reg": { "type" : "chain", "chain" : "chain1"}}}]}}
index 648ed368250aa6d4ec010a1ee69236c1b1231b70..ecde0e27544a7c932aad66bc3004afb78adf8b69 100644 (file)
@@ -158,6 +158,7 @@ static int test_json(const char *filename)
        struct nft_table *t;
        struct nft_chain *c;
        struct nft_rule *r;
+       struct nft_set *s;
        json_t *root;
        json_error_t error;
        char *json;
@@ -200,6 +201,16 @@ static int test_json(const char *filename)
 
                        nft_rule_free(r);
                }
+       } else if (json_object_get(root, "set") != NULL) {
+               s = nft_set_alloc();
+               if (s != NULL) {
+                       if (nft_set_parse(s, NFT_SET_PARSE_JSON, json) == 0)
+                               ret = compare_test(TEST_JSON_SET, s, filename);
+                       else
+                               goto failparsing;
+
+                       nft_set_free(s);
+                       }
        }
 
        free(json);