Message ID | 1430286666-392-17-git-send-email-joe.hershberger@ni.com |
---|---|
State | Superseded |
Headers | show |
Hi Joe, On 28 April 2015 at 23:51, Joe Hershberger <joe.hershberger@ni.com> wrote: > Add a test of the env_attr_lookup() function. > > Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> > --- > > Changes in v2: > -New for version 2 > > test/env/Makefile | 1 + > test/env/attr.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 63 insertions(+) > create mode 100644 test/env/attr.c Reviewed-by: Simon Glass <sjg@chromium.org> I don't know how much it matters, but I was trying to make test commands start with 'ut_' (unit test) so they would all appear in the same place when you type 'help'. Regards, Simon
Hi Simon, On Thu, Apr 30, 2015 at 10:46 PM, Simon Glass <sjg@chromium.org> wrote: > Hi Joe, > > On 28 April 2015 at 23:51, Joe Hershberger <joe.hershberger@ni.com> wrote: >> Add a test of the env_attr_lookup() function. >> >> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> >> --- >> >> Changes in v2: >> -New for version 2 >> >> test/env/Makefile | 1 + >> test/env/attr.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 63 insertions(+) >> create mode 100644 test/env/attr.c > > Reviewed-by: Simon Glass <sjg@chromium.org> > > I don't know how much it matters, but I was trying to make test > commands start with 'ut_' (unit test) so they would all appear in the > same place when you type 'help'. I took it one step further by creating a ut command that can have sub-commands that are test suites. This also should help address Tom's concerns about ease of running. Cheers, -Joe
diff --git a/test/env/Makefile b/test/env/Makefile index c35b18e..c8d345b 100644 --- a/test/env/Makefile +++ b/test/env/Makefile @@ -5,3 +5,4 @@ # obj-y += cmd_env_test.o +obj-y += attr.o diff --git a/test/env/attr.c b/test/env/attr.c new file mode 100644 index 0000000..87ebdac --- /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 <env_test.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);
Add a test of the env_attr_lookup() function. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> --- Changes in v2: -New for version 2 test/env/Makefile | 1 + test/env/attr.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/env/attr.c