blob: 45b8c753a40424b1a4488376aaee80fb1d6912b4 [file] [log] [blame]
Joe Hershbergerb04d3552015-05-20 14:27:37 -05001/*
2 * (C) Copyright 2015
3 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
4 *
5 * SPDX-License-Identifier: GPL-2.0
6 */
7
8#include <common.h>
9#include <command.h>
10#include <env_attr.h>
11#include <test/env.h>
12#include <test/ut.h>
13
14static int env_test_attrs_lookup(struct unit_test_state *uts)
15{
16 char attrs[32];
17
18 ut_assertok(env_attr_lookup("foo:bar", "foo", attrs));
19 ut_asserteq_str("bar", attrs);
20
21 ut_assertok(env_attr_lookup(",foo:bar", "foo", attrs));
22 ut_asserteq_str("bar", attrs);
23
24 ut_assertok(env_attr_lookup(",foo:bar,", "foo", attrs));
25 ut_asserteq_str("bar", attrs);
26
27 ut_assertok(env_attr_lookup(" foo:bar", "foo", attrs));
28 ut_asserteq_str("bar", attrs);
29
30 ut_assertok(env_attr_lookup("foo : bar", "foo", attrs));
31 ut_asserteq_str("bar", attrs);
32
33 ut_assertok(env_attr_lookup(" foo: bar ", "foo", attrs));
34 ut_asserteq_str("bar", attrs);
35
36 ut_assertok(env_attr_lookup("foo:bar ", "foo", attrs));
37 ut_asserteq_str("bar", attrs);
38
39 ut_assertok(env_attr_lookup(",foo:bar,goo:baz", "foo", attrs));
40 ut_asserteq_str("bar", attrs);
41
42 ut_asserteq(-ENOENT, env_attr_lookup(",,", "foo", attrs));
43
44 ut_asserteq(-ENOENT, env_attr_lookup("goo:baz", "foo", attrs));
45
46 ut_assertok(env_attr_lookup("foo:bar,foo:bat,foo:baz", "foo", attrs));
47 ut_asserteq_str("baz", attrs);
48
49 ut_assertok(env_attr_lookup(
50 " foo : bar , foo : bat , foot : baz ", "foo", attrs));
51 ut_asserteq_str("bat", attrs);
52
53 ut_assertok(env_attr_lookup(
54 " foo : bar , foo : bat , ufoo : baz ", "foo", attrs));
55 ut_asserteq_str("bat", attrs);
56
57 ut_asserteq(-EINVAL, env_attr_lookup(NULL, "foo", attrs));
58 ut_asserteq(-EINVAL, env_attr_lookup("foo:bar", "foo", NULL));
59
60 return 0;
61}
62ENV_TEST(env_test_attrs_lookup, 0);
Joe Hershbergerf68c2b22015-05-20 14:27:38 -050063
64#ifdef CONFIG_REGEX
65static int env_test_attrs_lookup_regex(struct unit_test_state *uts)
66{
67 char attrs[32];
68
69 ut_assertok(env_attr_lookup("foo1?:bar", "foo", attrs));
70 ut_asserteq_str("bar", attrs);
71
72 ut_assertok(env_attr_lookup("foo1?:bar", "foo1", attrs));
73 ut_asserteq_str("bar", attrs);
74
75 ut_assertok(env_attr_lookup(".foo:bar", ".foo", attrs));
76 ut_asserteq_str("bar", attrs);
77
78 ut_assertok(env_attr_lookup(".foo:bar", "ufoo", attrs));
79 ut_asserteq_str("bar", attrs);
80
81 ut_assertok(env_attr_lookup("\\.foo:bar", ".foo", attrs));
82 ut_asserteq_str("bar", attrs);
83
84 ut_asserteq(-ENOENT, env_attr_lookup("\\.foo:bar", "ufoo", attrs));
85
86 return 0;
87}
88ENV_TEST(env_test_attrs_lookup_regex, 0);
89#endif