nserver

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 8c164789ee0e7cbfc745f568791cd830bdebcd89
parent c6fe16189606f39ad31fac67a2a179a29bcf3b8f
Author: rsiddharth <s@ricketyspace.net>
Date:   Mon, 16 Dec 2019 20:52:05 -0500

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.

Diffstat:
nserver/src/ncmd.c | 13++++++-------
nserver/src/ncmd.h | 2+-
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 @@ -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 @@ -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 @@ -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; }