From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BCDAAC433F5 for ; Fri, 25 Feb 2022 01:32:24 +0000 (UTC) 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) 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-Google-Smtp-Source: ABdhPJxsSMsciAU/si6LrL9EjQNU9naVmGZQnClWMaKkN85s1AZ66TQZ1FeSl+qACqVT9+BsLdtq2Q== 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 --- 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); -- 2.17.1