From patchwork Tue Feb 22 16:02:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 545044 Delivered-To: patch@linaro.org Received: by 2002:adf:a34a:0:0:0:0:0 with SMTP id d10csp367719wrb; Tue, 22 Feb 2022 08:01:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPeq0/Sv6B7JOikYEZddl+aqlZ8siv8myhyYXJnogqlO0laE4gZsjqyXNMItWbav08Bm35 X-Received: by 2002:a17:907:1245:b0:6cc:e663:7baa with SMTP id wc5-20020a170907124500b006cce6637baamr19306396ejb.447.1645545718391; Tue, 22 Feb 2022 08:01:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645545718; cv=none; d=google.com; s=arc-20160816; b=exSSXFBbGtOdPjPD2EV1kRDdNRiSNhJUV0gtHlmltO1LWr2RVftqgOuLK/4KYhMvJI kfeL0mjXh3+fgC3aHMJFha6QWV+iU4aEIqIT/3Nrd5WaJ/mGVac5L8FFL18OPnb1tjF0 fVS2wGZ9B+Ie3dbdpISl+ycXlsb57d6DwbeQoDqTEUrZ9m4ArzO2j1GhJ2Zg+1yjcUaq 5qTr3VupmoDz8VhVSAx5KxzSV9HbiM101NFk5mj3/Stpld0x46W1+ZUpoZg10RVAlZgX JA5VoBmQ6cHbllP4Sx843PXoonNa0P3W6xmmj2TRoPLZVVsAMXVuLgR0ukqdrKgmDjCE pEeQ== 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=uYXVrODQP3bDcX4pouiURu+RXuRdZIkQkC5Q4uWbocI=; b=yeHcNJj1Olw2v2q+/7Psmd7wGSEJa/lf/HBI4/crZdDddTQduMxeDrznXoyHRdcY2P RtflOlok8jCCVAoBG8cXF3352Fl5owziC5Hf5/G96lfmC13pTV885GyuSRn2gH0h1Ryd r2bn7xatvqc7/xE43qBa/jN9ohAOy19LNPXqEYPt1l8daP8pkp43vo3FbdYdojCvCBAQ hPu4i0Uijy3+nYTwNE9zhF4RsBDABhMkVU68etYuKaE56lolKM4mFS4m+GLtQXZX2yDf G2zz9I80Bn43NZKodtzdPm5rPHbgUI+upo15REMjd+A7o3j1RFn+0sHI9Oa701S+AeE2 CMqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GSehKTHv; 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 hq2si12415965ejc.865.2022.02.22.08.01.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 08:01:58 -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=GSehKTHv; 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 0FE7B83CA3; Tue, 22 Feb 2022 17:01:41 +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="GSehKTHv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8984483CA4; Tue, 22 Feb 2022 17:01:28 +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-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (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 1498E83CA3 for ; Tue, 22 Feb 2022 17:01:23 +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-pl1-x62a.google.com with SMTP id x11so15990268pll.10 for ; Tue, 22 Feb 2022 08:01:22 -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=uYXVrODQP3bDcX4pouiURu+RXuRdZIkQkC5Q4uWbocI=; b=GSehKTHvGmYraWWyEJ19qDrUbZtptgUo48I+P+6Vb5/wj4ESB1u3dhSijgBEIVLIb8 H8nPVshsCVulYflCdPzCsh+mfndohWeybiqbh1kJVaRc1unrSVIzxdfc32bTEIdg67bu WtjN1UpB0DuRoDL/c/kBYSZeSJYy660mMTCqz105ESL91DyappqSTx2NUoKbDPxYM5e5 isBITg8sDpdOaCnqSWm6tGcRFgW5ex0GTKgbLKgMuCJEponxR4SdmZt1UXR3yARHBxdm V8ZfxixV+wBCiNghFxn00foB8lEX2sB7WNd1faHPLh4ji3DZY7VmBFp7D1tgviZQyy9J 1Rxg== 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=uYXVrODQP3bDcX4pouiURu+RXuRdZIkQkC5Q4uWbocI=; b=x8cqm3dot9JV5S9hY4kLo5B9U10gvo74lktmmhMKo7dG/EKmAqVAxiP2Dv5Zb7apcI c2unnlwNI9N22KsEaNhuxS82bkXCN0bYHrad6z/Smdo5XpmK9tlI2sh3VS9ZTN+GBVc5 lgcMQJsn4hl4rguWvWGmIKSS/pOq2t5nulSy8tZ5ErpEpWt8wzmkdoG4mvknt2yv56OI nXwftmT0Aan41nLyiampB74EaN841b8igQ+LVhdHNenwVHiMeqbgvfIege+VQU6v6awS 7yIloi+ATENA5tURrIkZ/HcXm13puRDlnJclzBHRBFvLp7XrJCDqQYCpwqBdREOmLDye hvkQ== X-Gm-Message-State: AOAM532xrIHHFRrGVVlHobghv9B2AqEvTMH0O3lEALXH/CbSGvIsTzLL OUky3SnPRQjfonTjGc3F9u/lEaEg32SF3g== X-Received: by 2002:a17:90a:8689:b0:1b9:b23f:6c29 with SMTP id p9-20020a17090a868900b001b9b23f6c29mr4839248pjn.25.1645545681364; Tue, 22 Feb 2022 08:01:21 -0800 (PST) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id h6sm3017683pjs.30.2022.02.22.08.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 08:01:20 -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: [RFC PATCH v2 3/4] test: unit test for u16_strlcat() Date: Wed, 23 Feb 2022 01:02:34 +0900 Message-Id: <20220222160235.24748-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220222160235.24748-1-masahisa.kojima@linaro.org> References: <20220222160235.24748-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 --- 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);