blob: 5fa8c44e5692ae1c9e073b296a2e5038e465570e [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
Lucas De Marchidea2dfe2014-12-25 23:32:03 -020016 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020017 */
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020022
Lucas De Marchi96573a02014-10-03 00:01:35 -030023#include <shared/util.h>
24
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020025#include "testsuite.h"
26
27static int alias_1(const struct test *t)
28{
29 static const char *input[] = {
30 "test1234",
31 "test[abcfoobar]2211",
32 "bar[aaa][bbbb]sss",
33 "kmod[p.b]lib",
34 "[az]1234[AZ]",
35 NULL,
36 };
37
38 char buf[PATH_MAX];
39 size_t len;
40 const char **alias;
41
42 for (alias = input; *alias != NULL; alias++) {
43 int ret;
44
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020045 ret = alias_normalize(*alias, buf, &len);
46 printf("input %s\n", *alias);
47 printf("return %d\n", ret);
48
49 if (ret == 0) {
50 printf("len %zu\n", len);
51 printf("output %s\n", buf);
52 }
53
54 printf("\n");
55 }
56
57 return EXIT_SUCCESS;
58}
Lucas De Marchif1155c12014-10-09 13:00:30 -030059DEFINE_TEST(alias_1,
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020060 .description = "check if alias_normalize does the right thing",
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020061 .config = {
Lucas De Marchi807c6012013-11-18 04:32:45 -020062 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-util/",
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020063 },
64 .need_spawn = true,
65 .output = {
Lucas De Marchi807c6012013-11-18 04:32:45 -020066 .out = TESTSUITE_ROOTFS "test-util/alias-correct.txt",
Lucas De Marchic5d81982012-02-07 10:46:46 -020067 });
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020068
Lucas De Marchiaafd3832014-10-03 03:25:06 -030069static int test_freadline_wrapped(const struct test *t)
Lucas De Marchi1dda6262013-11-18 05:13:59 -020070{
Lucas De Marchiaafd3832014-10-03 03:25:06 -030071 FILE *fp = fopen("/freadline_wrapped-input.txt", "re");
Lucas De Marchi1dda6262013-11-18 05:13:59 -020072
73 if (!fp)
74 return EXIT_FAILURE;
75
76 while (!feof(fp) && !ferror(fp)) {
77 unsigned int num = 0;
Lucas De Marchiaafd3832014-10-03 03:25:06 -030078 char *s = freadline_wrapped(fp, &num);
Lucas De Marchi1dda6262013-11-18 05:13:59 -020079 if (!s)
80 break;
81 puts(s);
82 free(s);
83 printf("%u\n", num);
84 }
85
86 fclose(fp);
87 return EXIT_SUCCESS;
88}
Lucas De Marchif1155c12014-10-09 13:00:30 -030089DEFINE_TEST(test_freadline_wrapped,
Lucas De Marchiaafd3832014-10-03 03:25:06 -030090 .description = "check if freadline_wrapped() does the right thing",
Lucas De Marchi1dda6262013-11-18 05:13:59 -020091 .config = {
92 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-util/",
93 },
94 .need_spawn = true,
95 .output = {
Lucas De Marchiaafd3832014-10-03 03:25:06 -030096 .out = TESTSUITE_ROOTFS "test-util/freadline_wrapped-correct.txt",
Lucas De Marchi1dda6262013-11-18 05:13:59 -020097 });
98
Lucas De Marchi43289822014-10-09 14:29:04 -030099TESTSUITE_MAIN();