From patchwork Thu Mar 24 13:54:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 553914 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp4438267mag; Thu, 24 Mar 2022 06:55:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgxXspgjoEPtph82cunVyVF3DMaeFtzJOifzxeZU7ZIWa38uf382VTSlL/hEYFvhUy/Obm X-Received: by 2002:a17:906:e28a:b0:6d6:e2e9:d39d with SMTP id gg10-20020a170906e28a00b006d6e2e9d39dmr5923029ejb.2.1648130126879; Thu, 24 Mar 2022 06:55:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648130126; cv=none; d=google.com; s=arc-20160816; b=J5tpdFrngUxCRs6zz0ogkWEBw+v7XCE3ZWpZ2c90pT6jnLMFeB+mjoTAuEUoQPjx5Z DoiGX1IghynOjrkSfuwJtg0nwwbyzZcP4wxP0zpRUGbKTM10+E89uzf2JxLNCWH95MbE rtlhssuyU/x275ykBlxoyrAdrjUPOeguvwd97wE1jIQAY+4dflSUTrdoyARXpgBzAx9i H+MAc0vetCmAFquBNe53RlRFcbbisKSg9VUiIF/sG3C/sUDInijIP/6GwSoB6lH+eSi8 PprWa1Skqe0c9xZLM2tG0cpf5vFRJqL111C0xEbW3xszu5dC1fCtf4tNL4yQAKGbkwP7 g34A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=WbGWy1ftbC23huCet0201xoU+6I2uYKaBD5Szx9Q3Sg=; b=FjtZeIC4hFZQyQLKZQ7nRGMiXfODT6ue6gT9VxUEQeL3oLi0yHytqvPrvmuJOyQvwd a7cX7sdQc2ISPscOQZpIZJ2zFjBE6RWRsFcdyBLQe7e2iGbc1WxHXc8J5esUBkblLPAD Fb9EgJw5o4hn/9ydjDs1tw2sh+Gh8Dpkop+x3arwn6lFRy3kEWGhS4RyZh7gWJSm9SuI EmzJZyniCXEMt/7HnpHNEJMzXwrj9BYAf/WU1RhoRlvh41sTSDPPsWCmE9ZKglLkVeTb 86tTemb5KtStDqlBW0sJ7om4kMzfcWLqZX4WU+CTsNasYbepJ/nPoQGQihNb/OxnQq4V suZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YKM3V9mW; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id m21-20020a50d7d5000000b00418c2b5bdedsi24845754edj.207.2022.03.24.06.55.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 06:55:26 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YKM3V9mW; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 668FB840B8; Thu, 24 Mar 2022 14:54:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="YKM3V9mW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 66940840AB; Thu, 24 Mar 2022 14:54:50 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 529D0840AB for ; Thu, 24 Mar 2022 14:54:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pj1-x102a.google.com with SMTP id gp15-20020a17090adf0f00b001c7cd11b0b3so685857pjb.3 for ; Thu, 24 Mar 2022 06:54:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WbGWy1ftbC23huCet0201xoU+6I2uYKaBD5Szx9Q3Sg=; b=YKM3V9mWyPK6+qSAtuwLgvTsBe0ax0CRlm4eBezkEXWtfPNgIs6D1Zytr8DKWSBDyI Pd8gZlgbdT5VdKFdRjz0tAm/Zq/kpVtWmsRYghRC1PO2qTcxCpvQPx2TapwcQUx6UjhD eejNJlOE3VjnIHH+nvQ/ho1fbPm9/lBoB+AYktqQB3l1Vy0fkUjHFssw58seMrS1XrdQ prkxFyOQwW1dIopGb5E12co1Zu1kOYmj/6VeH9Z4eIIzyOaq8Erd28h/4PTP8E1qz05e 7eYjFQX+SumVbBGaMjvkez+7XQjumEbK+549CCITICAl1PzRLrPO+FeZBXj9IEHx2DyA H6mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WbGWy1ftbC23huCet0201xoU+6I2uYKaBD5Szx9Q3Sg=; b=5yvZgfcf7TtSMxweWgZWJPDs0/hM31BEbGtlGUytRxjmx1yOQZbW739X86AfbSmKLp OANNaYycEXwe/YJ4ScSCbiceG0IYD1h5PNVx+vbSp4C6QYlnsPR3P77FavECI2dVnOFr IKDuG87Y1Rc/pL+OJks7mxL1fhEK6fX+cn51jQMSYthIJ+WqhsalrDnRO/GUP+Zfsai3 TsZDEaVf+62Y11fzLng+SaBVBRS9l770DVUUs9CeZkGrcmt5w2amOcPIZNd8hdyTIcl6 bKlwQQZjY+0z7kr2qH/bOHxWKsPF3ycWnA/JaKNsUIjbqurV870SAnG014jamG/Z4HZQ kv+g== X-Gm-Message-State: AOAM532UaZzfjf7Ztv43xrfvIqDbQqOQKh47oDklY7YhhyNq89jR+SgI f9jdFbF8FcexK1OxxgTs8fUlp4Ro+4wG9Q== X-Received: by 2002:a17:902:f54c:b0:154:6794:ab18 with SMTP id h12-20020a170902f54c00b001546794ab18mr6172710plf.118.1648130085624; Thu, 24 Mar 2022 06:54:45 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id p15-20020a056a000a0f00b004f7c63cba5asm3974609pfh.21.2022.03.24.06.54.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Mar 2022 06:54:45 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Francois Ozog , Mark Kettenis , Masahisa Kojima Subject: [PATCH v4 03/11] test: unit test for u16_strlcat() Date: Thu, 24 Mar 2022 22:54:35 +0900 Message-Id: <20220324135443.1571-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220324135443.1571-1-masahisa.kojima@linaro.org> References: <20220324135443.1571-1-masahisa.kojima@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Provide a unit test for function u16_strlcat(). Signed-off-by: Masahisa Kojima Reviewed-by: Simon Glass --- No change since v2 Newly created in v2 test/unicode_ut.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/unicode_ut.c b/test/unicode_ut.c index f2f63d5367..f79b0439bc 100644 --- a/test/unicode_ut.c +++ b/test/unicode_ut.c @@ -758,6 +758,51 @@ static int unicode_test_efi_create_indexed_name(struct unit_test_state *uts) UNICODE_TEST(unicode_test_efi_create_indexed_name); #endif +static int unicode_test_u16_strlcat(struct unit_test_state *uts) +{ + u16 buf[11]; + u16 dest[] = u"U-Boot"; + u16 src[] = u"test"; + u16 expected[] = u"U-Boottest"; + u16 null_src = u'\0'; + size_t ret; + + memcpy(buf, dest, sizeof(dest)); + ret = u16_strlcat(buf, src, sizeof(buf)); + ut_asserteq(20, ret); + ut_assert(!unicode_test_u16_strcmp(buf, expected, 11)); + + /* dest is empty string */ + memset(buf, 0, sizeof(buf)); + ret = u16_strlcat(buf, src, sizeof(buf)); + ut_asserteq(8, ret); + ut_assert(!unicode_test_u16_strcmp(buf, src, 11)); + + /* src is empty string */ + memset(buf, 0, sizeof(buf)); + memcpy(buf, dest, sizeof(dest)); + ret = u16_strlcat(buf, &null_src, sizeof(buf)); + ut_asserteq(12, ret); + ut_assert(!unicode_test_u16_strcmp(buf, dest, 11)); + + /* size is smaller than dest size */ + memset(buf, 0, sizeof(buf)); + memcpy(buf, dest, sizeof(dest)); + ret = u16_strlcat(buf, src, 6); + ut_asserteq(14, ret); + ut_assert(!unicode_test_u16_strcmp(buf, dest, 11)); + + /* size is insufficient to append src string */ + memset(buf, 0, sizeof(buf)); + memcpy(buf, dest, sizeof(dest)); + ret = u16_strlcat(buf, src, 20); + ut_asserteq(20, ret); + ut_assert(!unicode_test_u16_strcmp(buf, u"U-Boottes", 11)); + + return 0; +} +UNICODE_TEST(unicode_test_u16_strlcat); + int do_ut_unicode(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(unicode_test);