From 7501d9372b1fd34c5d144574d8017ee886dd3cce Mon Sep 17 00:00:00 2001 From: Tim Kourt Date: Wed, 28 Mar 2018 09:26:32 -0700 Subject: [PATCH] unit: network args parser validation --- Makefile.am | 11 ++++- unit/test-client.c | 101 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 unit/test-client.c diff --git a/Makefile.am b/Makefile.am index 43caed1a..94fc3ec8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -177,7 +177,7 @@ unit_tests = unit/test-cmac-aes \ unit/test-crypto unit/test-eapol unit/test-mpdu \ unit/test-ie unit/test-ssid-to-utf8 unit/test-ssid-security \ unit/test-arc4 unit/test-wsc unit/test-eap-mschapv2 \ - unit/test-eap-sim + unit/test-eap-sim unit/test-client ell_pem_files = cert-ca-key.pem cert-client-key.pem cert-client-key-pkcs8.pem \ cert-server-key.pem cert-server-key-pkcs8.pem \ @@ -278,6 +278,15 @@ unit_test_eap_mschapv2_SOURCES = src/eap-mschapv2.h src/eap-mschapv2.c \ unit_test_eap_mschapv2_LDADD = ell/libell-internal.la +unit_test_client_SOURCES = unit/test-client.c \ + readline/readline.h readline/history.h \ + client/adapter.c \ + client/command.h client/command.c \ + client/dbus-proxy.h client/dbus-proxy.c \ + client/display.h client/display.c \ + client/network.h client/network.c +unit_test_client_LDADD = ell/libell-internal.la -lreadline + TESTS = $(unit_tests) manual_pages = doc/iwmon.1 diff --git a/unit/test-client.c b/unit/test-client.c new file mode 100644 index 00000000..7dc958f6 --- /dev/null +++ b/unit/test-client.c @@ -0,0 +1,101 @@ +/* + * + * Wireless daemon for Linux + * + * Copyright (C) 2017 Intel Corporation. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#include "client/network.h" + +struct network_args_data { + const char *args; + const char *name; + const char *type; +}; + +static const struct network_args_data network_args_data_1[] = { + { "" }, + { "\0" }, + { } +}; + +static const struct network_args_data network_args_data_2[] = { + { "network psk", "network", "psk" }, + { " network psk", "network", "psk" }, + { "network ", "network"}, + { "\" psk", "\"", "psk" }, + { "\"network psk", "\"network", "psk" }, + { "\"network name\"", "network name" }, + { "\"network \"name\"", "network \"name" }, + { "\"network \"psk", "network ", "psk"}, + { "\"network name\" psk", "network name", "psk" }, + { } +}; + +static void network_parse_no_args_test(const void *data) +{ + const struct network_args_data *validation_list = data; + size_t i; + struct network_args *network_args; + + for (i = 0; validation_list[i].args; i++) { + network_args = network_parse_args(validation_list[i].args); + assert(!network_args); + } +} + +static void network_parse_args_test(const void *data) +{ + const struct network_args_data *validation_list = data; + size_t i; + struct network_args *network_args; + + for (i = 0; validation_list[i].args; i++) { + network_args = network_parse_args(validation_list[i].args); + + assert(network_args); + assert(!strcmp(network_args->name, validation_list[i].name)); + + if (validation_list[i].type) + assert(!strcmp(network_args->type, + validation_list[i].type)); + + network_args_destroy(network_args); + } +} + +int main(int argc, char *argv[]) +{ + l_test_init(&argc, &argv); + + l_test_add("/Network/Parse no args", + network_parse_no_args_test, &network_args_data_1); + l_test_add("/Network/Parse args", network_parse_args_test, + &network_args_data_2); + + return l_test_run(); +}