From a74093f534fe922829f07d52a543086d65d07271 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Mon, 31 Mar 2014 23:18:37 +0200 Subject: [PATCH] parser_test: Check the node's command type. --- t/frontend/parser_test.c | 48 ++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/t/frontend/parser_test.c b/t/frontend/parser_test.c index acd8ee6..8526514 100644 --- a/t/frontend/parser_test.c +++ b/t/frontend/parser_test.c @@ -42,33 +42,37 @@ START_TEST(test_parse) const char *query; int len; int expected; + int expected_cmd; } golden_data[] = { /* empty commands */ - { NULL, -1, -1 }, - { "", -1, 0 }, - { ";", -1, 0 }, - { ";;", -1, 0 }, + { NULL, -1, -1, 0 }, + { "", -1, 0, 0 }, + { ";", -1, 0, 0 }, + { ";;", -1, 0, 0 }, /* valid commands */ - { "LIST", -1, 1 }, - { "LIST -- comment", -1, 1 }, - { "LIST;", -1, 1 }, - { "LIST; INVALID", 5, 1 }, + { "FETCH host", -1, 1, CONNECTION_FETCH }, + { "LIST", -1, 1, CONNECTION_LIST }, + { "LIST -- comment", -1, 1, CONNECTION_LIST }, + { "LIST;", -1, 1, CONNECTION_LIST }, + { "LIST; INVALID", 5, 1, CONNECTION_LIST }, /* comments */ - { "/* some comment */", -1, 0 }, - { "-- another comment", -1, 0 }, + { "/* some comment */", -1, 0, 0 }, + { "-- another comment", -1, 0, 0 }, /* syntax errors */ - { "INVALID", -1, -1 }, - { "LIST; INVALID", 8, -1 }, - { "/* some incomplete", -1, -1 }, + { "INVALID", -1, -1, 0 }, + { "FETCH $%&#", -1, -1, 0 }, + { "LIST; INVALID", 8, -1, 0 }, + { "/* some incomplete", -1, -1, 0 }, }; size_t i; sdb_llist_t *check; for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { + sdb_object_t *obj; _Bool ok; check = sdb_fe_parse(golden_data[i].query, golden_data[i].len); @@ -84,16 +88,18 @@ START_TEST(test_parse) if (! check) continue; - if ((! strcmp(golden_data[i].query, "LIST")) - || (! strcmp(golden_data[i].query, "LIST;"))) { - sdb_object_t *obj = sdb_llist_get(check, 0); - fail_unless(SDB_CONN_NODE(obj)->cmd == CONNECTION_LIST, - "sdb_fe_parse(LIST)->cmd = %i; expected: %d " - "(CONNECTION_LIST)", SDB_CONN_NODE(obj)->cmd, - CONNECTION_LIST); - sdb_object_deref(obj); + if ((! golden_data[i].expected_cmd) + || (golden_data[i].expected <= 0)) { + sdb_llist_destroy(check); + continue; } + obj = sdb_llist_get(check, 0); + fail_unless(SDB_CONN_NODE(obj)->cmd == golden_data[i].expected_cmd, + "sdb_fe_parse(%s)->cmd = %i; expected: %d", + golden_data[i].query, SDB_CONN_NODE(obj)->cmd, + golden_data[i].expected_cmd); + sdb_object_deref(obj); sdb_llist_destroy(check); } } -- 2.30.2