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