diff options
author | Joe Hershberger <joe.hershberger@ni.com> | 2015-05-20 14:27:37 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2015-05-21 09:16:18 -0400 |
commit | b04d3553ee389ea8abf13e52930ddde5943ed8a4 (patch) | |
tree | 142fe042db2a3df81c68bbbd8588d26def79c270 /test/env | |
parent | 421f86f3293c63fa2669972fb7bdc5ae78729e50 (diff) | |
download | u-boot-b04d3553ee389ea8abf13e52930ddde5943ed8a4.tar.gz u-boot-b04d3553ee389ea8abf13e52930ddde5943ed8a4.tar.bz2 u-boot-b04d3553ee389ea8abf13e52930ddde5943ed8a4.zip |
test: env: Add test for verifying env attrs
Add a test of the env_attr_lookup() function.
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/env')
-rw-r--r-- | test/env/Makefile | 1 | ||||
-rw-r--r-- | test/env/attr.c | 62 |
2 files changed, 63 insertions, 0 deletions
diff --git a/test/env/Makefile b/test/env/Makefile index 59b38e99ae..5168bcb328 100644 --- a/test/env/Makefile +++ b/test/env/Makefile @@ -5,3 +5,4 @@ # obj-y += cmd_ut_env.o +obj-y += attr.o diff --git a/test/env/attr.c b/test/env/attr.c new file mode 100644 index 0000000000..d9be825ecd --- /dev/null +++ b/test/env/attr.c @@ -0,0 +1,62 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include <common.h> +#include <command.h> +#include <env_attr.h> +#include <test/env.h> +#include <test/ut.h> + +static int env_test_attrs_lookup(struct unit_test_state *uts) +{ + char attrs[32]; + + ut_assertok(env_attr_lookup("foo:bar", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(",foo:bar", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(",foo:bar,", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(" foo:bar", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup("foo : bar", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(" foo: bar ", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup("foo:bar ", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(",foo:bar,goo:baz", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_asserteq(-ENOENT, env_attr_lookup(",,", "foo", attrs)); + + ut_asserteq(-ENOENT, env_attr_lookup("goo:baz", "foo", attrs)); + + ut_assertok(env_attr_lookup("foo:bar,foo:bat,foo:baz", "foo", attrs)); + ut_asserteq_str("baz", attrs); + + ut_assertok(env_attr_lookup( + " foo : bar , foo : bat , foot : baz ", "foo", attrs)); + ut_asserteq_str("bat", attrs); + + ut_assertok(env_attr_lookup( + " foo : bar , foo : bat , ufoo : baz ", "foo", attrs)); + ut_asserteq_str("bat", attrs); + + ut_asserteq(-EINVAL, env_attr_lookup(NULL, "foo", attrs)); + ut_asserteq(-EINVAL, env_attr_lookup("foo:bar", "foo", NULL)); + + return 0; +} +ENV_TEST(env_test_attrs_lookup, 0); |