From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ana Rey Subject: [libnftnl PATCH 3/3] tests: Add support to check a json or xml testfile. Date: Wed, 9 Apr 2014 10:54:01 +0200 Message-ID: <9b0c7906989fa0e37e60f30091205dbdf4744abf.1397032579.git.anarey@gmail.com> References: Cc: Ana Rey To: netfilter-devel@vger.kernel.org Return-path: Received: from mail-wi0-f182.google.com ([209.85.212.182]:64747 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752444AbaDIIyR (ORCPT ); Wed, 9 Apr 2014 04:54:17 -0400 Received: by mail-wi0-f182.google.com with SMTP id d1so2782470wiv.3 for ; Wed, 09 Apr 2014 01:54:16 -0700 (PDT) In-Reply-To: In-Reply-To: References: Sender: netfilter-devel-owner@vger.kernel.org List-ID: Add new command-line argument "-f " to check a json or xml testfile. ./nft-parsing-test -f Check this testfile. Signed-off-by: Ana Rey --- tests/nft-parsing-test.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/nft-parsing-test.c b/tests/nft-parsing-test.c index 3de343e..9cc68dc 100644 --- a/tests/nft-parsing-test.c +++ b/tests/nft-parsing-test.c @@ -240,6 +240,47 @@ static int execute_test(const char *dir_name) return 0; } +static int execute_test_file(const char *filename) +{ + char path[PATH_MAX]; + int ret = 0; + struct nft_parse_err *err; + + err = nft_parse_err_alloc(); + if (err == NULL) { + perror("error"); + exit(EXIT_FAILURE); + } + + snprintf(path, sizeof(path), "%s", filename); + + int len = strlen(filename); + if (strcmp(&filename[len-4], ".xml") == 0) { + if ((ret = test_xml(path, err)) == 0) { + if (!update) { + printf("parsing and validating %s: ", + path); + printf("\033[32mOK\e[0m\n"); + } + } + exit(EXIT_FAILURE); + } + if (strcmp(&filename[len-5], ".json") == 0) { + if ((ret = test_json(path, err)) == 0) { + if (!update) { + printf("parsing and validating %s: ", + path); + printf("\033[32mOK\e[0m\n"); + } + } + exit(EXIT_FAILURE); + } + + nft_parse_err_free(err); + + return 0; +} + static void show_help(const char *name) { printf( @@ -248,6 +289,7 @@ static void show_help(const char *name) "Options:\n" " -d/--dir Check test files from .\n" " -u/--update Update test files from .\n" +" -f/--file Check test file \n" "\n", name); } @@ -260,6 +302,7 @@ int main(int argc, char *argv[]) static struct option long_options[] = { { "dir", required_argument, 0, 'd' }, { "update", required_argument, 0, 'u' }, + { "file", required_argument, 0, 'f' }, { 0 } }; @@ -269,7 +312,7 @@ int main(int argc, char *argv[]) } while (1) { - val = getopt_long(argc, argv, "d:u:", long_options, + val = getopt_long(argc, argv, "d:u:f:", long_options, &option_index); if (val == -1) @@ -283,6 +326,9 @@ int main(int argc, char *argv[]) update = true; ret = execute_test(optarg); break; + case 'f': + ret = execute_test_file(optarg); + break; default: show_help(argv[0]); break; -- 1.9.0