74 lines
1.4 KiB
C
74 lines
1.4 KiB
C
#include "greatest.h"
|
|
#include "../exec.h"
|
|
|
|
#define mkfun(f, n) \
|
|
int f(struct libscomm_line *x __attribute__((unused))) { \
|
|
return n; \
|
|
}
|
|
|
|
mkfun(foo, LIBSCOMM_CMD_OK)
|
|
mkfun(bar, 1)
|
|
mkfun(ocmd, 2)
|
|
mkfun(baz, 3)
|
|
mkfun(quox, 4)
|
|
mkfun(test1, 5)
|
|
mkfun(apple, 6)
|
|
mkfun(under, 7)
|
|
mkfun(rex, 8)
|
|
mkfun(yan, 9)
|
|
mkfun(val, 10)
|
|
mkfun(cal, 11)
|
|
|
|
struct libscomm_cmd cmdarr[] = {
|
|
{"apple", apple}, {"bar", bar}, {"baz", baz}, {"cal", cal},
|
|
{"foo", foo}, {"ocmd", ocmd}, {"quox", quox}, {"rex", rex},
|
|
{"test1", test1}, {"under", under}, {"val", val}, {"yan", yan}
|
|
};
|
|
#define arrlen(x) (sizeof(x) / sizeof((x)[0]))
|
|
const struct libscomm_cmd_store cmds = {cmdarr, arrlen(cmdarr)};
|
|
|
|
TEST execute_one(void) {
|
|
struct libscomm_line x = {0};
|
|
x.buf[0] = "foo";
|
|
x.len = 1;
|
|
|
|
ASSERT_EQ(libscomm_exec(&cmds, &x), LIBSCOMM_CMD_OK);
|
|
PASS();
|
|
}
|
|
|
|
#define doexec(f, n) do{\
|
|
x.buf[0] = f; \
|
|
ASSERT_EQ(libscomm_exec(&cmds, &x), n); \
|
|
} while(0)
|
|
|
|
TEST execute_multiple(void) {
|
|
struct libscomm_line x = {0};
|
|
x.len = 1;
|
|
|
|
doexec("foo", LIBSCOMM_CMD_OK);
|
|
doexec("bar", 1);
|
|
doexec("ocmd", 2);
|
|
doexec("baz", 3);
|
|
doexec("quox", 4);
|
|
doexec("test1", 5);
|
|
doexec("apple", 6);
|
|
doexec("under", 7);
|
|
doexec("rex", 8);
|
|
doexec("yan", 9);
|
|
doexec("val", 10);
|
|
doexec("cal", 11);
|
|
|
|
PASS();
|
|
}
|
|
|
|
GREATEST_MAIN_DEFS();
|
|
|
|
int main(int argc, char *argv[]) {
|
|
GREATEST_MAIN_BEGIN();
|
|
|
|
RUN_TEST(execute_one);
|
|
RUN_TEST(execute_multiple);
|
|
|
|
GREATEST_MAIN_END();
|
|
}
|