#include "test.h"
-/* incrementd in handler, to check it is properly called once per
+/* incremented in handler, to check it is properly called once per
* key/value association */
static unsigned count;
return 0;
}
+/* test parsing. */
+static int test_kvargs_parsing(const char *args, unsigned int n)
+{
+ struct rte_kvargs *kvlist;
+
+ kvlist = rte_kvargs_parse(args, NULL);
+ if (kvlist == NULL) {
+ printf("rte_kvargs_parse() error: %s\n", args);
+ return -1;
+ }
+ if (kvlist->count != n) {
+ printf("invalid count value %d: %s\n", kvlist->count, args);
+ rte_kvargs_free(kvlist);
+ return -1;
+ }
+ rte_kvargs_free(kvlist);
+ return 0;
+}
+
/* test a valid case */
static int test_valid_kvargs(void)
{
const char *args;
const char *valid_keys_list[] = { "foo", "check", NULL };
const char **valid_keys;
+ static const struct {
+ unsigned int expected;
+ const char *input;
+ } valid_inputs[] = {
+ { 2, "foo=1,foo=" },
+ { 2, "foo=1,foo=" },
+ { 2, "foo=1,foo" },
+ { 2, "foo=1,=2" },
+ { 1, "foo=[1,2" },
+ { 1, ",=" },
+ { 1, "foo=[" },
+ };
+ unsigned int i;
/* empty args is valid */
args = "";
goto fail;
}
count = 0;
- /* call check_handler() for all entries with key="unexistant_key" */
- if (rte_kvargs_process(kvlist, "unexistant_key", check_handler, NULL) < 0) {
+ /* call check_handler() for all entries with key="nonexistent_key" */
+ if (rte_kvargs_process(kvlist, "nonexistent_key", check_handler, NULL) < 0) {
printf("rte_kvargs_process() error\n");
rte_kvargs_free(kvlist);
goto fail;
}
if (count != 0) {
- printf("invalid count value %d after rte_kvargs_process(unexistant_key)\n",
+ printf("invalid count value %d after rte_kvargs_process(nonexistent_key)\n",
count);
rte_kvargs_free(kvlist);
goto fail;
rte_kvargs_free(kvlist);
goto fail;
}
- /* count all entries with key="unexistant_key" */
- count = rte_kvargs_count(kvlist, "unexistant_key");
+ /* count all entries with key="nonexistent_key" */
+ count = rte_kvargs_count(kvlist, "nonexistent_key");
if (count != 0) {
- printf("invalid count value %d after rte_kvargs_count(unexistant_key)\n",
+ printf("invalid count value %d after rte_kvargs_count(nonexistent_key)\n",
count);
rte_kvargs_free(kvlist);
goto fail;
/* call check_handler() on all entries with key="check", it
* should fail as the value is not recognized by the handler */
if (rte_kvargs_process(kvlist, "check", check_handler, NULL) == 0) {
- printf("rte_kvargs_process() is success bu should not\n");
+ printf("rte_kvargs_process() is success but should not\n");
rte_kvargs_free(kvlist);
goto fail;
}
}
rte_kvargs_free(kvlist);
+ valid_keys = NULL;
+
+ for (i = 0; i < RTE_DIM(valid_inputs); ++i) {
+ args = valid_inputs[i].input;
+ if (test_kvargs_parsing(args, valid_inputs[i].expected))
+ goto fail;
+ }
+
return 0;
fail:
/* list of argument that should fail */
const char *args_list[] = {
"wrong-key=x", /* key not in valid_keys_list */
- "foo=1,foo=", /* empty value */
- "foo=1,foo", /* no value */
- "foo=1,=2", /* no key */
- "foo=[1,2", /* no closing bracket in value */
- ",=", /* also test with a smiley */
NULL };
const char **args;
const char *valid_keys_list[] = { "foo", "check", NULL };