From: Masahisa Kojima <masahisa.kojima@linaro.org>
To: u-boot@lists.denx.de
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Simon Glass <sjg@chromium.org>,
Takahiro Akashi <takahiro.akashi@linaro.org>,
Francois Ozog <francois.ozog@linaro.org>,
Mark Kettenis <mark.kettenis@xs4all.nl>,
Masahisa Kojima <masahisa.kojima@linaro.org>
Subject: [PATCH v4 03/11] test: unit test for u16_strlcat()
Date: Thu, 24 Mar 2022 22:54:35 +0900 [thread overview]
Message-ID: <20220324135443.1571-4-masahisa.kojima@linaro.org> (raw)
In-Reply-To: <20220324135443.1571-1-masahisa.kojima@linaro.org>
Provide a unit test for function u16_strlcat().
Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
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);
--
2.17.1
next prev parent reply other threads:[~2022-03-24 13:55 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-24 13:54 [PATCH v4 00/11] enable menu-driven boot device selection Masahisa Kojima
2022-03-24 13:54 ` [PATCH v4 01/11] bootmenu: fix menu API error handling Masahisa Kojima
2022-03-30 8:55 ` Ilias Apalodimas
2022-03-24 13:54 ` [PATCH v4 02/11] lib/charset: add u16_strlcat() function Masahisa Kojima
2022-04-02 7:14 ` Heinrich Schuchardt
2022-04-04 14:50 ` Masahisa Kojima
2022-04-16 7:32 ` Heinrich Schuchardt
2022-04-18 7:47 ` Masahisa Kojima
2022-04-28 7:45 ` Masahisa Kojima
2022-03-24 13:54 ` Masahisa Kojima [this message]
2022-04-02 7:47 ` [PATCH v4 03/11] test: unit test for u16_strlcat() Heinrich Schuchardt
2022-04-04 14:54 ` Masahisa Kojima
2022-03-24 13:54 ` [PATCH v4 04/11] menu: always show the menu regardless of the number of entry Masahisa Kojima
2022-04-02 7:56 ` Heinrich Schuchardt
2022-03-24 13:54 ` [PATCH v4 05/11] efi_loader: export efi_locate_device_handle() Masahisa Kojima
2022-04-01 5:43 ` Ilias Apalodimas
2022-03-24 13:54 ` [PATCH v4 06/11] efi_loader: bootmgr: add booting from removable media Masahisa Kojima
2022-03-30 19:13 ` Ilias Apalodimas
2022-03-31 0:51 ` Masahisa Kojima
2022-03-31 6:25 ` Ilias Apalodimas
2022-04-02 6:12 ` Heinrich Schuchardt
2022-04-04 6:48 ` Masahisa Kojima
2022-04-04 21:54 ` Heinrich Schuchardt
2022-03-24 13:54 ` [PATCH v4 07/11] bootmenu: add UEFI and disto_boot entries Masahisa Kojima
2022-04-01 6:08 ` Ilias Apalodimas
2022-04-02 6:33 ` Heinrich Schuchardt
2022-04-04 8:10 ` Masahisa Kojima
2022-03-24 13:54 ` [PATCH v4 08/11] bootmenu: factor out the user input handling Masahisa Kojima
2022-03-24 13:54 ` [PATCH v4 09/11] efi_loader: add menu-driven UEFI Boot Variable maintenance Masahisa Kojima
2022-03-31 8:31 ` Ilias Apalodimas
2022-04-14 9:25 ` Masahisa Kojima
2022-03-24 13:54 ` [PATCH v4 10/11] bootmenu: add removable media entries Masahisa Kojima
2022-03-31 8:48 ` Ilias Apalodimas
2022-03-31 10:18 ` Masahisa Kojima
2022-04-04 22:00 ` Heinrich Schuchardt
2022-03-24 13:54 ` [PATCH v4 11/11] doc:bootmenu: add UEFI boot variable and distro boot support Masahisa Kojima
2022-04-02 5:51 ` Heinrich Schuchardt
2022-03-25 1:20 ` [PATCH v4 00/11] enable menu-driven boot device selection Takahiro Akashi
2022-03-25 6:57 ` Masahisa Kojima
2022-04-02 5:48 ` Heinrich Schuchardt
2022-04-04 6:10 ` Masahisa Kojima
2022-04-16 6:46 ` Heinrich Schuchardt
2022-04-28 7:35 ` Masahisa Kojima
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220324135443.1571-4-masahisa.kojima@linaro.org \
--to=masahisa.kojima@linaro.org \
--cc=francois.ozog@linaro.org \
--cc=ilias.apalodimas@linaro.org \
--cc=mark.kettenis@xs4all.nl \
--cc=sjg@chromium.org \
--cc=takahiro.akashi@linaro.org \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).