From patchwork Wed Apr 29 05:51:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 465896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id E6B0014032D for ; Wed, 29 Apr 2015 15:54:54 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 13CBF4BA8B; Wed, 29 Apr 2015 07:54:17 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9TCLQAWvdzel; Wed, 29 Apr 2015 07:54:16 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E6DE04BAAB; Wed, 29 Apr 2015 07:53:40 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E26284BA7A for ; Wed, 29 Apr 2015 07:53:22 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KXTlwTZG2qj3 for ; Wed, 29 Apr 2015 07:53:22 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from ni.com (skprod3.natinst.com [130.164.80.24]) by theia.denx.de (Postfix) with ESMTPS id 293AE4BA71 for ; Wed, 29 Apr 2015 07:53:18 +0200 (CEST) Received: from us-aus-mgwout1.amer.corp.natinst.com (nb-snip2-1338.natinst.com [130.164.19.135]) by us-aus-skprod3.natinst.com (8.15.0.59/8.15.0.59) with ESMTP id t3T5rFRn004353; Wed, 29 Apr 2015 00:53:15 -0500 Received: from linux-xvxi.natinst.com ([130.164.14.198]) by us-aus-mgwout1.amer.corp.natinst.com (Lotus Domino Release 8.5.3FP6) with ESMTP id 2015042900531615-380901 ; Wed, 29 Apr 2015 00:53:16 -0500 From: Joe Hershberger To: u-boot@lists.denx.de Date: Wed, 29 Apr 2015 00:51:03 -0500 Message-Id: <1430286666-392-17-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <1430286666-392-1-git-send-email-joe.hershberger@ni.com> References: <1429653771-11676-1-git-send-email-joe.hershberger@ni.com> <1430286666-392-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on US-AUS-MGWOut1/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 04/29/2015 12:53:16 AM, Serialize by Router on US-AUS-MGWOut1/AUS/H/NIC(Release 8.5.3FP6|November 21, 2013) at 04/29/2015 12:53:16 AM, Serialize complete at 04/29/2015 12:53:16 AM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2015-04-29_01:, , signatures=0 Cc: Tom Rini , Joe Hershberger Subject: [U-Boot] [PATCH v2 16/19] test: env: Add test for verifying env attrs X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add a test of the env_attr_lookup() function. Signed-off-by: Joe Hershberger Reviewed-by: Simon Glass --- 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 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 +#include +#include +#include +#include + +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);