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 | |
Lucas De Marchi | 96573a0 | 2014-10-03 00:01:35 -0300 | [diff] [blame] | 25 | #include <shared/util.h> |
| 26 | |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 27 | #include "libkmod-util.h" |
| 28 | #include "testsuite.h" |
| 29 | |
| 30 | static int alias_1(const struct test *t) |
| 31 | { |
| 32 | static const char *input[] = { |
| 33 | "test1234", |
| 34 | "test[abcfoobar]2211", |
| 35 | "bar[aaa][bbbb]sss", |
| 36 | "kmod[p.b]lib", |
| 37 | "[az]1234[AZ]", |
| 38 | NULL, |
| 39 | }; |
| 40 | |
| 41 | char buf[PATH_MAX]; |
| 42 | size_t len; |
| 43 | const char **alias; |
| 44 | |
| 45 | for (alias = input; *alias != NULL; alias++) { |
| 46 | int ret; |
| 47 | |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 48 | ret = alias_normalize(*alias, buf, &len); |
| 49 | printf("input %s\n", *alias); |
| 50 | printf("return %d\n", ret); |
| 51 | |
| 52 | if (ret == 0) { |
| 53 | printf("len %zu\n", len); |
| 54 | printf("output %s\n", buf); |
| 55 | } |
| 56 | |
| 57 | printf("\n"); |
| 58 | } |
| 59 | |
| 60 | return EXIT_SUCCESS; |
| 61 | } |
Lucas De Marchi | c5d8198 | 2012-02-07 10:46:46 -0200 | [diff] [blame] | 62 | static DEFINE_TEST(alias_1, |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 63 | .description = "check if alias_normalize does the right thing", |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 64 | .config = { |
Lucas De Marchi | 807c601 | 2013-11-18 04:32:45 -0200 | [diff] [blame] | 65 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-util/", |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 66 | }, |
| 67 | .need_spawn = true, |
| 68 | .output = { |
Lucas De Marchi | 807c601 | 2013-11-18 04:32:45 -0200 | [diff] [blame] | 69 | .out = TESTSUITE_ROOTFS "test-util/alias-correct.txt", |
Lucas De Marchi | c5d8198 | 2012-02-07 10:46:46 -0200 | [diff] [blame] | 70 | }); |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 71 | |
Lucas De Marchi | 1dda626 | 2013-11-18 05:13:59 -0200 | [diff] [blame] | 72 | static int test_getline_wrapped(const struct test *t) |
| 73 | { |
| 74 | FILE *fp = fopen("/getline_wrapped-input.txt", "re"); |
| 75 | |
| 76 | if (!fp) |
| 77 | return EXIT_FAILURE; |
| 78 | |
| 79 | while (!feof(fp) && !ferror(fp)) { |
| 80 | unsigned int num = 0; |
| 81 | char *s = getline_wrapped(fp, &num); |
| 82 | if (!s) |
| 83 | break; |
| 84 | puts(s); |
| 85 | free(s); |
| 86 | printf("%u\n", num); |
| 87 | } |
| 88 | |
| 89 | fclose(fp); |
| 90 | return EXIT_SUCCESS; |
| 91 | } |
| 92 | static DEFINE_TEST(test_getline_wrapped, |
| 93 | .description = "check if getline_wrapped() does the right thing", |
| 94 | .config = { |
| 95 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-util/", |
| 96 | }, |
| 97 | .need_spawn = true, |
| 98 | .output = { |
| 99 | .out = TESTSUITE_ROOTFS "test-util/getline_wrapped-correct.txt", |
| 100 | }); |
| 101 | |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 102 | static const struct test *tests[] = { |
| 103 | &salias_1, |
Lucas De Marchi | 1dda626 | 2013-11-18 05:13:59 -0200 | [diff] [blame] | 104 | &stest_getline_wrapped, |
Pedro Pedruzzi | 760b896 | 2012-01-28 03:22:47 -0200 | [diff] [blame] | 105 | NULL, |
| 106 | }; |
| 107 | |
Lucas De Marchi | e9fa9de | 2012-02-07 10:09:20 -0200 | [diff] [blame] | 108 | TESTSUITE_MAIN(tests); |