From patchwork Fri Feb 25 01:32:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 545899 Delivered-To: patch@linaro.org Received: by 2002:ac0:d8d1:0:0:0:0:0 with SMTP id b17csp733247imj; Thu, 24 Feb 2022 17:32:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJx6afusHuP5hERXtJ+DOeuFDtFj7edw6FdR68PLoouowHjHBsnqCTshlPUGZUPhwvTmfTfz X-Received: by 2002:a05:6402:4389:b0:410:9a9d:ab53 with SMTP id o9-20020a056402438900b004109a9dab53mr4961836edc.16.1645752744257; Thu, 24 Feb 2022 17:32:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645752744; cv=none; d=google.com; s=arc-20160816; b=0LA3fxHIbhUil4Tx4SsPevPT52zL29fdkvnHjKSGSq5q6bvm0XrzJrXi+jxH9EIosa 2mT8t5ElRgWCzFYPsi7zLXKIiC0NmyiGHYsIg+VK0q09TKl/lWiWd9quzfMfVNIhUy46 z+BYj0iJxGmOrjH6OTinV1SOyuR5A7CaW1YV/Fyx2IC/hloHv/I4UtfBmYQpW7r01CU/ YZaDdcZpFz2zbtpKBP3YXyoOfHBxrVK/h8gevsVYENUt/R667hm1A6WRaXOPGwjjllmZ Djp2ARDMjan6+wyzp34fY5qz11Rs8jYav7qgVb4As00aVvgO4AT0+1Miy5u5cgF+EE+w sA6g== 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=G9XKS0BmLPXzRkmpjrYpnCQ6Ib2/X9G2MUaC9o17spQ=; b=aSMJvom1cx/g75NOA/FNsdGPTq82BFJvhPCyXB0g6S6sVvaN/g+MoygBgYv+f/Om3Q Z2xxMdqUOkZ1YSjlZUr/wvZhDiNRsG+YD/HqqpLHyY9fy7/MM/ey6oBbS71bf8lEYP+K 3/Fduj18WR4QZiCZJkp0bd70KT94HDEpc3qYHs6MsoW9niXIy0E7edxinubJyFGXANr4 CmXVdyfk6LttJ70Z1etv4ErbmWeK0H6JYonk2ZXvk/qRXi7wDTdpWyF0KZtkqKucKyhT ta5O97zIn3pWPAJYUUoNDMeQ2vnZunEup2gjRJe66wi6gba/GtlKcy7SBulf9PRf16yZ P9Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HOBmctbs; 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 p20-20020a170906615400b006cfbb200709si550559ejl.900.2022.02.24.17.32.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 17:32:24 -0800 (PST) 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=HOBmctbs; 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 4AFCA83C58; Fri, 25 Feb 2022 02:32:11 +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="HOBmctbs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 301A883CBC; Fri, 25 Feb 2022 02:31:52 +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-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) (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 9055683C69 for ; Fri, 25 Feb 2022 02:31:46 +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-x1034.google.com with SMTP id iq13-20020a17090afb4d00b001bc4437df2cso3513273pjb.2 for ; Thu, 24 Feb 2022 17:31:46 -0800 (PST) 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=G9XKS0BmLPXzRkmpjrYpnCQ6Ib2/X9G2MUaC9o17spQ=; b=HOBmctbsHXBADg6YTWxILS03odLXRBPd4kmsj6MTMCk4Ab7oPpOIe4j2y/G458WKuk whMctRKQveE8e8K3WeUh1sVR0h/HyguODaXnSuhhCcO69SiXXiAuuip83V89Ws3ReRvT 69J8xEX2VkUeWX2j3N4iQvvIJPhPc6f2RktaKOyJwhBXDgL5xFJyeCVeualfl4/NQ2eo ZVHnKp5xxc+vd4u9VXFZwty20LvUoQYMgJ4asMjApBf9t8L1sBOrg0TE38pRR+2DFoCh 74GKjGTIiALNzNwi/WImuNZwSsW/jkAdEM5hnskWbH3n4mqgq1Xn16Xbvpu2BAXUrmq7 UffA== 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=G9XKS0BmLPXzRkmpjrYpnCQ6Ib2/X9G2MUaC9o17spQ=; b=5mXsOMGtEGlZSf1oEetBWkqaIS19xhOs4yBbgiyiD/nVVSnDtRxBG/su+A8WpmoT56 Hbj2jYW3Xvju9+A6eRQOTGiUfXZKrFEGyRhWJosGizAP/g1FD3K1vzl4aqhTDs5egUsp yPfApgQ1irCku6lCz4Ng7JMlXghq1qtxxLDftAxv4LINAteEqGzpjZU3foSdpJLr8vaE 3e4TCHpGqTiwvw4b8ew4Is57HyLela0Lrzy1EnCOszJ799jPRpaHrqWvBmocxm118N/U NL19nfuNeFFmQc6jZaS0MF1jqF/DOGycwCnpmJO2KO2x9cpr9GBl4ZipIeQjTJLLNDxZ JSVg== X-Gm-Message-State: AOAM531MRWoB/JC8Q36ZYo3Nn4vGq5zCaPAVv0JsHIb6S1IjNfB2RST1 84ZrEZ/HC7qpQKNiCt7FqicV21UOL0aS5g== X-Received: by 2002:a17:902:f602:b0:14f:53a8:64f7 with SMTP id n2-20020a170902f60200b0014f53a864f7mr5094535plg.151.1645752704937; Thu, 24 Feb 2022 17:31:44 -0800 (PST) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id n18-20020a056a00213200b004e17d967d13sm703888pfj.124.2022.02.24.17.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 17:31:44 -0800 (PST) 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: [RESEND RFC PATCH v2 3/4] test: unit test for u16_strlcat() Date: Fri, 25 Feb 2022 10:32:56 +0900 Message-Id: <20220225013257.15674-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220225013257.15674-1-masahisa.kojima@linaro.org> References: <20220225013257.15674-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 --- 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);