Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 1 | /* |
Lucas De Marchi | e6b0e49 | 2013-01-16 11:27:21 -0200 | [diff] [blame] | 2 | * Copyright (C) 2012-2013 ProFUSION embedded systems |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 3 | * Copyright (C) 2012 Pedro Pedruzzi |
| 4 | * |
Lucas De Marchi | e1b1ab2 | 2012-07-10 09:42:24 -0300 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Lucas De Marchi | e1b1ab2 | 2012-07-10 09:42:24 -0300 | [diff] [blame] | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 14 | * |
Lucas De Marchi | e1b1ab2 | 2012-07-10 09:42:24 -0300 | [diff] [blame] | 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | #include <libkmod.h> |
| 24 | |
| 25 | #include "libkmod-util.h" |
| 26 | #include "testsuite.h" |
| 27 | |
| 28 | static int alias_1(const struct test *t) |
| 29 | { |
| 30 | static const char *input[] = { |
| 31 | "test1234", |
| 32 | "test[abcfoobar]2211", |
| 33 | "bar[aaa][bbbb]sss", |
| 34 | "kmod[p.b]lib", |
| 35 | "[az]1234[AZ]", |
| 36 | NULL, |
| 37 | }; |
| 38 | |
| 39 | char buf[PATH_MAX]; |
| 40 | size_t len; |
| 41 | const char **alias; |
| 42 | |
| 43 | for (alias = input; *alias != NULL; alias++) { |
| 44 | int ret; |
| 45 | |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 46 | ret = alias_normalize(*alias, buf, &len); |
| 47 | printf("input %s\n", *alias); |
| 48 | printf("return %d\n", ret); |
| 49 | |
| 50 | if (ret == 0) { |
| 51 | printf("len %zu\n", len); |
| 52 | printf("output %s\n", buf); |
| 53 | } |
| 54 | |
| 55 | printf("\n"); |
| 56 | } |
| 57 | |
| 58 | return EXIT_SUCCESS; |
| 59 | } |
Lucas De Marchi | c5d8198 | 2012-02-07 10:46:46 -0200 | [diff] [blame] | 60 | static DEFINE_TEST(alias_1, |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 61 | .description = "check if alias_normalize does the right thing", |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 62 | .config = { |
Lucas De Marchi | 807c601 | 2013-11-18 04:32:45 -0200 | [diff] [blame^] | 63 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-util/", |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 64 | }, |
| 65 | .need_spawn = true, |
| 66 | .output = { |
Lucas De Marchi | 807c601 | 2013-11-18 04:32:45 -0200 | [diff] [blame^] | 67 | .out = TESTSUITE_ROOTFS "test-util/alias-correct.txt", |
Lucas De Marchi | c5d8198 | 2012-02-07 10:46:46 -0200 | [diff] [blame] | 68 | }); |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 69 | |
| 70 | static const struct test *tests[] = { |
| 71 | &salias_1, |
| 72 | NULL, |
| 73 | }; |
| 74 | |
Lucas De Marchi | e9fa9de | 2012-02-07 10:09:20 -0200 | [diff] [blame] | 75 | TESTSUITE_MAIN(tests); |