]> git.ipfire.org Git - thirdparty/kmod.git/blame - testsuite/test-util.c
Rename getline_wrapped() to freadline_wrapped()
[thirdparty/kmod.git] / testsuite / test-util.c
CommitLineData
760b8968 1/*
e6b0e49b 2 * Copyright (C) 2012-2013 ProFUSION embedded systems
760b8968
PP
3 * Copyright (C) 2012 Pedro Pedruzzi
4 *
e1b1ab24
LDM
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.
760b8968
PP
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
e1b1ab24
LDM
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
760b8968 14 *
e1b1ab24
LDM
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
760b8968
PP
18 */
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
760b8968 23
96573a02
LDM
24#include <shared/util.h>
25
c2e4286b
LDM
26#include <libkmod.h>
27#include <libkmod-util.h>
28
760b8968
PP
29#include "testsuite.h"
30
31static int alias_1(const struct test *t)
32{
33 static const char *input[] = {
34 "test1234",
35 "test[abcfoobar]2211",
36 "bar[aaa][bbbb]sss",
37 "kmod[p.b]lib",
38 "[az]1234[AZ]",
39 NULL,
40 };
41
42 char buf[PATH_MAX];
43 size_t len;
44 const char **alias;
45
46 for (alias = input; *alias != NULL; alias++) {
47 int ret;
48
760b8968
PP
49 ret = alias_normalize(*alias, buf, &len);
50 printf("input %s\n", *alias);
51 printf("return %d\n", ret);
52
53 if (ret == 0) {
54 printf("len %zu\n", len);
55 printf("output %s\n", buf);
56 }
57
58 printf("\n");
59 }
60
61 return EXIT_SUCCESS;
62}
c5d81989 63static DEFINE_TEST(alias_1,
760b8968 64 .description = "check if alias_normalize does the right thing",
760b8968 65 .config = {
807c601d 66 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-util/",
760b8968
PP
67 },
68 .need_spawn = true,
69 .output = {
807c601d 70 .out = TESTSUITE_ROOTFS "test-util/alias-correct.txt",
c5d81989 71 });
760b8968 72
aafd3835 73static int test_freadline_wrapped(const struct test *t)
1dda626f 74{
aafd3835 75 FILE *fp = fopen("/freadline_wrapped-input.txt", "re");
1dda626f
LDM
76
77 if (!fp)
78 return EXIT_FAILURE;
79
80 while (!feof(fp) && !ferror(fp)) {
81 unsigned int num = 0;
aafd3835 82 char *s = freadline_wrapped(fp, &num);
1dda626f
LDM
83 if (!s)
84 break;
85 puts(s);
86 free(s);
87 printf("%u\n", num);
88 }
89
90 fclose(fp);
91 return EXIT_SUCCESS;
92}
aafd3835
LDM
93static DEFINE_TEST(test_freadline_wrapped,
94 .description = "check if freadline_wrapped() does the right thing",
1dda626f
LDM
95 .config = {
96 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-util/",
97 },
98 .need_spawn = true,
99 .output = {
aafd3835 100 .out = TESTSUITE_ROOTFS "test-util/freadline_wrapped-correct.txt",
1dda626f
LDM
101 });
102
760b8968
PP
103static const struct test *tests[] = {
104 &salias_1,
aafd3835 105 &stest_freadline_wrapped,
760b8968
PP
106 NULL,
107};
108
e9fa9de3 109TESTSUITE_MAIN(tests);