diff options
author | rsiddharth <s@ricketyspace.net> | 2019-12-16 20:52:05 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-04-17 20:56:36 -0400 |
commit | 8c164789ee0e7cbfc745f568791cd830bdebcd89 (patch) | |
tree | c94900ff0acd8808225e4881cdda01d9535f915f | |
parent | c6fe16189606f39ad31fac67a2a179a29bcf3b8f (diff) |
nserver: Flesh out process.
* nserver/src/ncmd.c (process): Initial version.
* nserver/src/ncmd.h (process): Update declaration.
* nserver/tests/ncmd_tests.c (test_process): Test for process.
(all_tests): Add test_process.
-rw-r--r-- | nserver/src/ncmd.c | 13 | ||||
-rw-r--r-- | nserver/src/ncmd.h | 2 | ||||
-rw-r--r-- | nserver/tests/ncmd_tests.c | 56 |
3 files changed, 63 insertions, 8 deletions
diff --git a/nserver/src/ncmd.c b/nserver/src/ncmd.c index 2b5ee22..ee6f9df 100644 --- a/nserver/src/ncmd.c +++ b/nserver/src/ncmd.c @@ -280,8 +280,7 @@ int call_function(int func, struct bstrList *cmd_parts, char *out) return -1; } -/* -int process(char *cmd, int sock) +int process(char *cmd, char *out) { // split cmd into parts. struct bstrList *parts = cmd_parts(cmd); @@ -289,15 +288,15 @@ int process(char *cmd, int sock) check(parts->qty > 0, "bstrList qty check failed"); // call find_function. + int FUNC = find_function(parts); + check(FUNC != -1, "find function failed"); // call call_function - - // barf result back to sock - - // done + int rc = call_function(FUNC, parts, out); + check(rc != -1, "call function failed"); return 0; error: return -1; } -*/ + diff --git a/nserver/src/ncmd.h b/nserver/src/ncmd.h index dff1c76..df84b70 100644 --- a/nserver/src/ncmd.h +++ b/nserver/src/ncmd.h @@ -29,6 +29,6 @@ struct bstrList *cmd_parts(char *cmd); int find_function(struct bstrList *cmd_parts); int call_function(int func, struct bstrList *cmd_parts, char *out); -int process(char *cmd, int sock); +int process(char *cmd, char *out); #endif diff --git a/nserver/tests/ncmd_tests.c b/nserver/tests/ncmd_tests.c index 8c545d1..14c765b 100644 --- a/nserver/tests/ncmd_tests.c +++ b/nserver/tests/ncmd_tests.c @@ -299,6 +299,61 @@ char *test_call_function() return NULL; } +char *test_process() +{ + char *out = (char *) calloc(RSP_SIZE + 1, sizeof(char)); + mu_assert(out != NULL, "out invalid"); + + char *bacon = "/create bacon"; + int rc = process(bacon, out); + mu_assert(rc == 0, "process failed"); + mu_assert(strcmp(out, "OK\n") == 0, "process failed"); + + char *ham = "/create ham"; + rc = process(ham, out); + mu_assert(rc == 0, "process failed"); + mu_assert(strcmp(out, "OK\n") == 0, "process failed"); + + char *beef = "/create beef"; + rc = process(beef, out); + mu_assert(rc == 0, "process failed"); + mu_assert(strcmp(out, "OK\n") == 0, "process failed"); + + char *bacon_sample = "/sample bacon 4.2"; + rc = process(bacon_sample, out); + mu_assert(rc == 0, "process failed"); + mu_assert(strcmp(out, "OK\n") == 0, "process failed"); + + bacon_sample = "/Sample bacon 6.9"; + rc = process(bacon_sample, out); + mu_assert(rc == 0, "process failed"); + mu_assert(strcmp(out, "OK\n") == 0, "process failed"); + + char *bacon_mean = "/mean bacon"; + rc = process(bacon_mean, out); + mu_assert(rc == 0, "process failed"); + mu_assert(strcmp(out, "Mean: 5.55\n") == 0, "process failed"); + + char *bacon_dump = "/dump bacon"; + rc = process(bacon_dump, out); + mu_assert(rc == 0, "process failed"); + mu_assert(strcmp(out, "sum: 11.100000, sumsq: 65.250000, n: 2, min: 4.200000, max: 6.900000, mean: 5.550000, stddev: 1.909188\n") == 0, "process failed"); + + char *bacon_delete = "/delete bacon"; + rc = process(bacon_delete, out); + mu_assert(rc == 0, "process failed"); + mu_assert(strcmp(out, "OK\n") == 0, "process failed"); + + char *list = "/list"; + rc = process(list, out); + mu_assert(rc == 0, "process failed"); + mu_assert(strcmp(out, "ham\nbeef\n") == 0 + || strcmp(out, "beef\nham\n") == 0, + "process failed"); + + return NULL; +} + char *all_tests() { mu_suite_start(); @@ -308,6 +363,7 @@ char *all_tests() mu_run_test(test_cmd_parts); mu_run_test(test_find_function); mu_run_test(test_call_function); + mu_run_test(test_process); return NULL; } |