3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-23 22:42:37 +01:00

unit: add client token finder test

This commit is contained in:
Tim Kourt 2018-07-24 16:17:25 -07:00 committed by Denis Kenzior
parent c5cf3b083f
commit 243a574d75

View File

@ -28,9 +28,11 @@
#include <string.h>
#include <assert.h>
#include <ell/ell.h>
#include <readline/readline.h>
#include "client/dbus-proxy.h"
#include "client/network.h"
#include "client/command.h"
struct network_args_data {
const char *args;
@ -89,6 +91,41 @@ static void network_parse_args_test(const void *data)
}
}
struct command_line_data {
const char *command_line;
const char *token;
int tokens_to_compare;
bool found;
};
static const struct command_line_data command_line_data_1[] = {
{ "Token", "Token", 1, true },
{ "Token ", "Token", 1, true },
{ " Token", "Token", 1, true },
{ "Token1 Token2", "Token1", 2, true },
{ " Token1 Token2 ", "Token1", 2, true },
{ "Token1 Token2", "Token3", 2, false },
{ "Token1 Token2", "Token1", 1, false },
{ }
};
static void command_line_find_tokens_test(const void *data)
{
const struct command_line_data *validation_list = data;
size_t i;
bool found;
for (i = 0; validation_list[i].command_line; i++) {
rl_replace_line(validation_list[i].command_line, 0);
rl_point = strlen(validation_list[i].command_line);
found = command_line_find_token(validation_list[i].token,
validation_list[i].tokens_to_compare);
assert(found == validation_list[i].found);
}
}
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
@ -98,5 +135,8 @@ int main(int argc, char *argv[])
l_test_add("/Network/Parse args", network_parse_args_test,
&network_args_data_2);
l_test_add("/Command/Find tokens", command_line_find_tokens_test,
&command_line_data_1);
return l_test_run();
}