test-client.c (2222B)
1 /* 2 * 3 * Wireless daemon for Linux 4 * 5 * Copyright (C) 2017-2019 Intel Corporation. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 * 21 */ 22 23 #ifdef HAVE_CONFIG_H 24 #include <config.h> 25 #endif 26 27 #include <stdio.h> 28 #include <string.h> 29 #include <assert.h> 30 #include <ell/ell.h> 31 #include <readline/readline.h> 32 33 #include "client/dbus-proxy.h" 34 #include "client/network.h" 35 #include "client/command.h" 36 37 struct command_line_data { 38 const char *command_line; 39 const char *token; 40 int tokens_to_compare; 41 bool found; 42 }; 43 44 static const struct command_line_data command_line_data_1[] = { 45 { "Token", "Token", 1, true }, 46 { "Token ", "Token", 1, true }, 47 { " Token", "Token", 1, true }, 48 { "Token1 Token2", "Token1", 2, true }, 49 { " Token1 Token2 ", "Token1", 2, true }, 50 { "Token1 Token2", "Token3", 2, false }, 51 { "Token1 Token2", "Token1", 1, false }, 52 { } 53 }; 54 55 static void command_line_find_tokens_test(const void *data) 56 { 57 const struct command_line_data *validation_list = data; 58 size_t i; 59 bool found; 60 61 for (i = 0; validation_list[i].command_line; i++) { 62 rl_replace_line(validation_list[i].command_line, 0); 63 rl_point = strlen(validation_list[i].command_line); 64 65 found = command_line_find_token(validation_list[i].token, 66 validation_list[i].tokens_to_compare); 67 68 assert(found == validation_list[i].found); 69 } 70 } 71 72 int main(int argc, char *argv[]) 73 { 74 l_test_init(&argc, &argv); 75 76 l_test_add("/Command/Find tokens", command_line_find_tokens_test, 77 &command_line_data_1); 78 79 return l_test_run(); 80 }