You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
#include "../src/common.h" |
|
#include "../src/buf.h" |
|
#include "../src/commands.h" |
|
|
|
int main() { |
|
f2b_cmd_t cmd; |
|
f2b_cmd_t *c; |
|
|
|
assert(f2b_cmd_parse(&cmd, "") == false); |
|
assert(f2b_cmd_parse(&cmd, " ") == false); |
|
|
|
assert(f2b_cmd_parse(&cmd, "status") == true); |
|
assert(cmd.type = CMD_STATUS); |
|
assert(cmd.argc == 1); |
|
assert(strcmp(cmd.args[0], "status") == 0); |
|
assert(cmd.data.used == 6); /* "status" */ |
|
f2b_buf_free(&cmd.data); |
|
|
|
assert(f2b_cmd_parse(&cmd, "stat") == false); /* no such command */ |
|
assert(cmd.type == CMD_UNKNOWN); |
|
|
|
assert(f2b_cmd_parse(&cmd, "jail test") == false); /* incomplete command */ |
|
assert(cmd.type == CMD_UNKNOWN); |
|
|
|
assert(f2b_cmd_parse(&cmd, "jail test status") == true); |
|
assert(cmd.type == CMD_JAIL_STATUS); |
|
assert(cmd.argc == 3); |
|
assert(strcmp(cmd.args[0], "jail") == 0); |
|
assert(strcmp(cmd.args[1], "test") == 0); |
|
assert(strcmp(cmd.args[2], "status") == 0); |
|
assert(cmd.data.used == 16); /* "jail\0test\0status" */ |
|
f2b_buf_free(&cmd.data); |
|
|
|
assert(f2b_cmd_parse(&cmd, "jail test set bantime 7200") == true); |
|
assert(cmd.type == CMD_JAIL_SET); |
|
assert(cmd.argc == 5); |
|
assert(strcmp(cmd.args[0], "jail") == 0); |
|
assert(strcmp(cmd.args[1], "test") == 0); |
|
assert(strcmp(cmd.args[2], "set") == 0); |
|
assert(strcmp(cmd.args[3], "bantime") == 0); |
|
assert(strcmp(cmd.args[4], "7200") == 0); |
|
f2b_buf_free(&cmd.data); |
|
|
|
c = f2b_cmd_create(""); |
|
assert(c == NULL); |
|
c = f2b_cmd_create(" "); |
|
assert(c == NULL); |
|
c = f2b_cmd_create("\n\r\n"); |
|
assert(c == NULL); |
|
c = f2b_cmd_create("test"); |
|
assert(c == NULL); /* no such command */ |
|
c = f2b_cmd_create("help"); |
|
assert(c != NULL); |
|
f2b_cmd_destroy(c); |
|
|
|
f2b_buf_free(&cmd.data); |
|
|
|
return EXIT_SUCCESS; |
|
}
|
|
|