blob: 9ffcf56e30b674c2b725850cd75f96393f498cd0 [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
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020026#include "testsuite.h"
27
28static 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 Pedruzzi760b8962012-01-28 03:22:47 -020046 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 Marchif1155c12014-10-09 13:00:30 -030060DEFINE_TEST(alias_1,
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020061 .description = "check if alias_normalize does the right thing",
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020062 .config = {
Lucas De Marchi807c6012013-11-18 04:32:45 -020063 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-util/",
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020064 },
65 .need_spawn = true,
66 .output = {
Lucas De Marchi807c6012013-11-18 04:32:45 -020067 .out = TESTSUITE_ROOTFS "test-util/alias-correct.txt",
Lucas De Marchic5d81982012-02-07 10:46:46 -020068 });
Pedro Pedruzzi760b8962012-01-28 03:22:47 -020069
Lucas De Marchiaafd3832014-10-03 03:25:06 -030070static int test_freadline_wrapped(const struct test *t)
Lucas De Marchi1dda6262013-11-18 05:13:59 -020071{
Lucas De Marchiaafd3832014-10-03 03:25:06 -030072 FILE *fp = fopen("/freadline_wrapped-input.txt", "re");
Lucas De Marchi1dda6262013-11-18 05:13:59 -020073
74 if (!fp)
75 return EXIT_FAILURE;
76
77 while (!feof(fp) && !ferror(fp)) {
78 unsigned int num = 0;
Lucas De Marchiaafd3832014-10-03 03:25:06 -030079 char *s = freadline_wrapped(fp, &num);
Lucas De Marchi1dda6262013-11-18 05:13:59 -020080 if (!s)
81 break;
82 puts(s);
83 free(s);
84 printf("%u\n", num);
85 }
86
87 fclose(fp);
88 return EXIT_SUCCESS;
89}
Lucas De Marchif1155c12014-10-09 13:00:30 -030090DEFINE_TEST(test_freadline_wrapped,
Lucas De Marchiaafd3832014-10-03 03:25:06 -030091 .description = "check if freadline_wrapped() does the right thing",
Lucas De Marchi1dda6262013-11-18 05:13:59 -020092 .config = {
93 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-util/",
94 },
95 .need_spawn = true,
96 .output = {
Lucas De Marchiaafd3832014-10-03 03:25:06 -030097 .out = TESTSUITE_ROOTFS "test-util/freadline_wrapped-correct.txt",
Lucas De Marchi1dda6262013-11-18 05:13:59 -020098 });
99
Lucas De Marchi43289822014-10-09 14:29:04 -0300100TESTSUITE_MAIN();