From: Alvaro Neira <alvaroneay@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: eric@regit.org
Subject: [libnftables PATCH 2/6] table : tests: test the table json parser support
Date: Thu, 25 Jul 2013 22:52:24 +0200 [thread overview]
Message-ID: <20130725205224.26223.16740.stgit@Ph0enix> (raw)
In-Reply-To: <20130725205215.26223.77001.stgit@Ph0enix>
From: Álvaro Neira Ayuso <alvaroneay@gmail.com>
Test the functions for parsing tables in JSON Support
Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
---
tests/Makefile.am | 2 +-
tests/jsonfiles/01-table.json | 1 +
tests/jsonfiles/02-table.json | 1 +
tests/nft-parsing-test.c | 49 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 52 insertions(+), 1 deletion(-)
create mode 100644 tests/jsonfiles/01-table.json
create mode 100644 tests/jsonfiles/02-table.json
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6941c3c..cfa4e8e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -3,4 +3,4 @@ include $(top_srcdir)/Make_global.am
check_PROGRAMS = nft-parsing-test
nft_parsing_test_SOURCES = nft-parsing-test.c
-nft_parsing_test_LDADD = ../src/libnftables.la ${LIBMNL_LIBS} ${LIBXML_LIBS}
+nft_parsing_test_LDADD = ../src/libnftables.la ${LIBMNL_LIBS} ${LIBXML_LIBS} ${LIBJSON_LIBS}
diff --git a/tests/jsonfiles/01-table.json b/tests/jsonfiles/01-table.json
new file mode 100644
index 0000000..ec496b9
--- /dev/null
+++ b/tests/jsonfiles/01-table.json
@@ -0,0 +1 @@
+{"table" : {"name" : "filter","version" : 0,"properties" : {"family" : "ip","table_flags" : 0}}}
diff --git a/tests/jsonfiles/02-table.json b/tests/jsonfiles/02-table.json
new file mode 100644
index 0000000..03f4d5a
--- /dev/null
+++ b/tests/jsonfiles/02-table.json
@@ -0,0 +1 @@
+{"table" : {"name" : "filter2","version" : 0,"properties" : {"family" : "ip6","table_flags" : 0}}}
diff --git a/tests/nft-parsing-test.c b/tests/nft-parsing-test.c
index 4fe60c3..83a627c 100644
--- a/tests/nft-parsing-test.c
+++ b/tests/nft-parsing-test.c
@@ -14,6 +14,47 @@
#include <mxml.h>
#endif
+#ifdef JSON_PARSING
+#include <jansson.h>
+#endif
+
+static int test_json(const char *filename)
+{
+#ifdef JSON_PARSING
+ int ret = -1;
+ struct nft_table *t = NULL;
+ json_t *root;
+ json_error_t error;
+ char *json = NULL;
+
+ root = json_load_file(filename, 0, &error);
+ if (!root) {
+ printf("Error on the line %d : %s", error.line, error.text);
+ return -1;
+ }
+
+ if (root == NULL)
+ return -1;
+
+ json = json_dumps(root, JSON_INDENT(0));
+
+ if (json_object_get(root, "table") != NULL) {
+ t = nft_table_alloc();
+ if (t != NULL) {
+ if (nft_table_parse(t, NFT_TABLE_PARSE_JSON, json) == 0)
+ ret = 0;
+
+ nft_table_free(t);
+ }
+ }
+
+ return ret;
+#else
+ errno = EOPNOTSUPP;
+ return -1;
+#endif
+}
+
static int test_xml(const char *filename)
{
#ifdef XML_PARSING
@@ -104,6 +145,14 @@ int main(int argc, char *argv[])
else
printf("\033[32mOK\e[0m\n");
}
+ if (strcmp(&dent->d_name[len-5], ".json") == 0) {
+ printf("parsing %s: ", path);
+ if (test_json(path) < 0)
+ printf("\033[31mFAILED\e[0m (%s)\n",
+ strerror(errno));
+ else
+ printf("\033[32mOK\e[0m\n");
+ }
}
closedir(d);
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2013-07-25 20:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-25 20:52 [libnftables PATCH 1/6] table: json: Add Json parser support Alvaro Neira
2013-07-25 20:52 ` Alvaro Neira [this message]
2013-07-25 21:07 ` [libnftables PATCH 2/6] table : tests: test the table json " Pablo Neira Ayuso
2013-07-25 20:52 ` [libnftables PATCH 3/6] examples: Add nft-table-json-add Alvaro Neira
2013-07-25 21:07 ` Pablo Neira Ayuso
2013-07-25 20:52 ` [libnftables PATCH 4/6] chain: json: add function for parsing chain Alvaro Neira
2013-07-25 21:13 ` Pablo Neira Ayuso
2013-07-25 20:52 ` [libnftables PATCH 5/6] chain: test: test the chain parser support Alvaro Neira
2013-07-25 20:52 ` [libnftables PATCH 6/6] examples: Add nft-chain-json-add Alvaro Neira
2013-07-25 21:07 ` [libnftables PATCH 1/6] table: json: Add Json parser support Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130725205224.26223.16740.stgit@Ph0enix \
--to=alvaroneay@gmail.com \
--cc=eric@regit.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox