blob: 30032b7cfcb8e28476bfcd44c795ac810589c6b9 [file] [log] [blame]
Pedro Pedruzzi760b8962012-01-28 03:22:47 -02001/*
Lucas De Marchie6b0e492013-01-16 11:27:21 -02002 * Copyright (C) 2012-2013 ProFUSION embedded systems
Pedro Pedruzzi760b8962012-01-28 03:22:47 -02003 * Copyright (C) 2012 Pedro Pedruzzi
4 *
Lucas De Marchie1b1ab22012-07-10 09:42:24 -03005 * 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 Pedruzzi760b8962012-01-28 03:22:47 -02009 *
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 Marchie1b1ab22012-07-10 09:42:24 -030012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020014 *
Lucas De Marchie1b1ab22012-07-10 09:42:24 -030015 * 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 Pedruzzi760b8962012-01-28 03:22:47 -020018 */
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020023
Lucas De Marchi96573a02014-10-03 00:01:35 -030024#include <shared/util.h>
25
Lucas De Marchic2e42862014-10-03 01:41:42 -030026#include <libkmod.h>
27#include <libkmod-util.h>
28
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020029#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
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020049 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}
Lucas De Marchic5d81982012-02-07 10:46:46 -020063static DEFINE_TEST(alias_1,
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020064 .description = "check if alias_normalize does the right thing",
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020065 .config = {
Lucas De Marchi807c6012013-11-18 04:32:45 -020066 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-util/",
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020067 },
68 .need_spawn = true,
69 .output = {
Lucas De Marchi807c6012013-11-18 04:32:45 -020070 .out = TESTSUITE_ROOTFS "test-util/alias-correct.txt",
Lucas De Marchic5d81982012-02-07 10:46:46 -020071 });
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020072
Lucas De Marchiaafd3832014-10-03 03:25:06 -030073static int test_freadline_wrapped(const struct test *t)
Lucas De Marchi1dda6262013-11-18 05:13:59 -020074{
Lucas De Marchiaafd3832014-10-03 03:25:06 -030075 FILE *fp = fopen("/freadline_wrapped-input.txt", "re");
Lucas De Marchi1dda6262013-11-18 05:13:59 -020076
77 if (!fp)
78 return EXIT_FAILURE;
79
80 while (!feof(fp) && !ferror(fp)) {
81 unsigned int num = 0;
Lucas De Marchiaafd3832014-10-03 03:25:06 -030082 char *s = freadline_wrapped(fp, &num);
Lucas De Marchi1dda6262013-11-18 05:13:59 -020083 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}
Lucas De Marchiaafd3832014-10-03 03:25:06 -030093static DEFINE_TEST(test_freadline_wrapped,
94 .description = "check if freadline_wrapped() does the right thing",
Lucas De Marchi1dda6262013-11-18 05:13:59 -020095 .config = {
96 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-util/",
97 },
98 .need_spawn = true,
99 .output = {
Lucas De Marchiaafd3832014-10-03 03:25:06 -0300100 .out = TESTSUITE_ROOTFS "test-util/freadline_wrapped-correct.txt",
Lucas De Marchi1dda6262013-11-18 05:13:59 -0200101 });
102
Pedro Pedruzzi760b8962012-01-28 03:22:47 -0200103static const struct test *tests[] = {
104 &salias_1,
Lucas De Marchiaafd3832014-10-03 03:25:06 -0300105 &stest_freadline_wrapped,
Pedro Pedruzzi760b8962012-01-28 03:22:47 -0200106 NULL,
107};
108
Lucas De Marchie9fa9de2012-02-07 10:09:20 -0200109TESTSUITE_MAIN(tests);