blob: 2a9be84c7760e060c254cc43e1311d1177dd6209 [file] [log] [blame]
Jacob Erlbeckae15a2c2013-08-06 14:29:14 +02001/* (C) 2013 by Jacob Erlbeck <jerlbeck@sysmocom.de>
2 * All Rights Reserved
3 *
4 * This program is iree software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 */
19
20#include <stdio.h>
21#include <string.h>
22
23#include <osmocom/core/talloc.h>
24#include <osmocom/core/logging.h>
25#include <osmocom/core/utils.h>
26#include <osmocom/vty/misc.h>
27
28static void test_cmd_string_from_valstr(void)
29{
30 char *cmd;
31 const struct value_string printf_seq_vs[] = {
32 { .value = 42, .str = "[foo%s%s%s%s%s]"},
33 { .value = 43, .str = "[bar%s%s%s%s%s]"},
34 { .value = 0, .str = NULL}
35 };
36
37 printf("Going to test vty_cmd_string_from_valstr()\n");
38
39 /* check against character strings that could break printf */
40
41 cmd = vty_cmd_string_from_valstr (NULL, printf_seq_vs, "[prefix%s%s%s%s%s]", "[sep%s%s%s%s%s]", "[end%s%s%s%s%s]", 1);
42 printf ("Tested with %%s-strings, resulting cmd = '%s'\n", cmd);
43 talloc_free (cmd);
44}
45
46int main(int argc, char **argv)
47{
48 test_cmd_string_from_valstr();
49 printf("All tests passed\n");
50
51 return 0;
52}