From patchwork Mon Feb 26 14:11:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 775868 Delivered-To: patch@linaro.org Received: by 2002:a5d:6103:0:b0:33d:da16:65b6 with SMTP id v3csp348703wrt; Mon, 26 Feb 2024 06:12:37 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVIvk+Nj7CuVcfDcdixXgaOzYI3FWT/mBg2kNZyJ64dykvPRkUuE1LRbQX3QPdxrOKnn8zQHdg4mtYBhgS8OuQz X-Google-Smtp-Source: AGHT+IGBXurQu40d1XZ7Lvze0bwIv2itCcNHGiSPPvShudk0DSf5rkOwKdC6PKeYuj5nxsu1usCU X-Received: by 2002:ac8:5a41:0:b0:42e:8d1e:1cf6 with SMTP id o1-20020ac85a41000000b0042e8d1e1cf6mr1393722qta.10.1708956756776; Mon, 26 Feb 2024 06:12:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708956756; cv=none; d=google.com; s=arc-20160816; b=WuhWN3c8hVBLfcmZulbDElyy8CeMZk9lnofJvuqOUrsAp5pRbmiRZiJ06DXtvXwHBH 75l0Krj+yRcFPfRet2jbAE0KCAjl8XyllBEHr548JlVQC8JwMn5p2qM09v2HiJXgOc+c SaF9SJkFyni4L2NVaxrYRzEKg1xGnJRhoIBoUlok38+Krgy4zenzbuUYNBOEdSFacqmu KYS6qAmWgfX/KhfOAEdKgm+yTBLozUF+apT2VutJyBAPZ4dHrCrH7LCtPdbW0dXioHss USYF4gFw5talqN3DtbOjrxTkLm3ofJvUcLuaNRKhrSVv3FrM8qcPm+OxIKI5lg2XrZuc IDAg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WqJvgmD2xSxG0JQjLIcAdWT5nW/VU/NqNnXte/SlaSQ=; fh=rrdawBiabB2BvF5LirDty9GjZtgb7ZSnQZHFBgn7Db0=; b=eFqv3Wu2i5hKejqN+XBnmx3GyFOpLNN8DxYx0WPQrV/LkEVwluPLjkxaZ5Nu2Ol6GR Ia/aeqe9vbzO6XptfrZq4wccR/V3BYGNeHIqs6142s2hBgSopG1pnbTCWT5qiDj031BR JpODScRm05kTzbu3rHLQ9HIacWxhZrJVSfE4QdB1m0hOESJYtm+PQqgh7dCmB+LODSv+ uEdb0z7U/ZNwexWrWekT7SncXsIOdSVrxPFyBmFhScDZIivxIObpOgnsH6bGyiafkPRb DHlr9yHIa7sAj2Ec6FtvYWCgkK9RweLpVE3p+C1wPu5AxMNNMx1a4hyyalAyiB5w+YqL T/Iw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fDCz4KaV; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id wg23-20020a05620a569700b007872024671csi5082611qkn.732.2024.02.26.06.12.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 06:12:36 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fDCz4KaV; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rebhk-0003Cu-Ha; Mon, 26 Feb 2024 09:11:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rebhj-0003Ca-9V for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:39 -0500 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rebhh-00026Z-IO for qemu-devel@nongnu.org; Mon, 26 Feb 2024 09:11:39 -0500 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-51197ca63f5so4704273e87.1 for ; Mon, 26 Feb 2024 06:11:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708956696; x=1709561496; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WqJvgmD2xSxG0JQjLIcAdWT5nW/VU/NqNnXte/SlaSQ=; b=fDCz4KaVpB+M2bdcQdv/WbPRVXaODcE/twaxehBDIPvMpuobHDplE7ofy9iwdwQb4g 2Jere7GIvGEtBH+JZas/e1G8U6reHsQY8V48QTm6zOpHmONj1AqtllxL/WixjMQo0D7H UY98DUE/hFxN2x6bMqTH/y32p9m7LFHOvBrr6vQ/lmkof4ndRPEkrFyyxc7pwVKQHAB+ fgisbkZ/lIRJI1XAvYhJnFB6eEAVEiZgszvsZ81p3F6QxEPGU0/Of1wMZPeyGBR4oh7O WhXha1CVHPuVYnimM4olkmRdP0fXn2fCWHNzw5YDZrZc2BC0sFwNcvesJq/GQBNqatXX DOMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708956696; x=1709561496; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WqJvgmD2xSxG0JQjLIcAdWT5nW/VU/NqNnXte/SlaSQ=; b=NCVT9q+2/plKAkG8LEnyULGMkNcqFHXrseumUwspyi3xy9Gdrch17rjieT7Cl9hH/r obt0JxZpcV+KXafW7EkX/a36JHLvKXATe8WQODbOWEcT5tmvKObJ+OUFEZ4EH8mQ7LZY fsJMmjiU0tgoX0aKBrzLq5lWcyyjcMW5xaurP9zMwc+vVyxUDv0dbya+NYcbbiFTsbFi iKyLH/iaxuKvokX/pe1SJcLZpRf6hoKB3F77u+C0Qzu/NI2lsQJosZ7C0WUjR88t+XaD 5P7QIkeRFQ3FAnCGlxN0/JbvmwNrPtxECXTUf0reiJqnET/VkrM1ZaDJgOeh+nCoRzCM Qr8A== X-Forwarded-Encrypted: i=1; AJvYcCUxVX0BJQ+9GMYYIF0yDT8b50n96uy3YPQOe8DaVOZqLWqI0PFF5rHsx8Cn+Imkai/J1lfphla2Kivx/BGo/CfhoTtW5kU= X-Gm-Message-State: AOJu0YyG/A3ZZF4xvrAq35QifDjfIhHTnNbaGF4OPRnALfWgaX+DYWe0 NuYU8WU8/MH1uuGrlWXjQiNwYufs4cVbiwV6SAybuY+tGO+2IhQzEPht0tTE1yg= X-Received: by 2002:ac2:4344:0:b0:512:bebf:1a with SMTP id o4-20020ac24344000000b00512bebf001amr4798235lfl.57.1708956695939; Mon, 26 Feb 2024 06:11:35 -0800 (PST) Received: from m1x-phil.lan ([176.187.223.153]) by smtp.gmail.com with ESMTPSA id vo9-20020a170907a80900b00a4136d18988sm2452797ejc.36.2024.02.26.06.11.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 26 Feb 2024 06:11:35 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Markus Armbruster , qemu-devel@nongnu.org, Steve Sistare Cc: "Dr. David Alan Gilbert" , Jason Wang , Michael Roth , Peter Xu , Fabiano Rosas , =?utf-8?q?Ma?= =?utf-8?q?rc-Andr=C3=A9_Lureau?= Subject: [PATCH v6 4/5] util: strList unit tests Date: Mon, 26 Feb 2024 15:11:06 +0100 Message-ID: <20240226141108.73664-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240226141108.73664-1-philmd@linaro.org> References: <20240226141108.73664-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12f; envelope-from=philmd@linaro.org; helo=mail-lf1-x12f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Steve Sistare Signed-off-by: Steve Sistare Reviewed-by: Marc-André Lureau Message-ID: <1708638470-114846-5-git-send-email-steven.sistare@oracle.com> --- tests/unit/test-strList.c | 80 +++++++++++++++++++++++++++++++++++++++ tests/unit/meson.build | 1 + 2 files changed, 81 insertions(+) create mode 100644 tests/unit/test-strList.c diff --git a/tests/unit/test-strList.c b/tests/unit/test-strList.c new file mode 100644 index 0000000000..40af6b2ad1 --- /dev/null +++ b/tests/unit/test-strList.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 - 2024 Oracle and/or its affiliates. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/strList.h" + +static strList *make_list(int length) +{ + strList *head = 0, *list, **prev = &head; + + while (length--) { + list = *prev = g_new0(strList, 1); + list->value = g_strdup("aaa"); + prev = &list->next; + } + return head; +} + +static void test_length(void) +{ + strList *list; + int i; + + for (i = 0; i < 5; i++) { + list = make_list(i); + g_assert_cmpint(i, ==, QAPI_LIST_LENGTH(list)); + qapi_free_strList(list); + } +} + +struct { + const char *string; + const char *delim; + const char *argv[5]; +} list_data[] = { + { NULL, ",", { NULL } }, + { "", ",", { NULL } }, + { "a", ",", { "a", NULL } }, + { "a,b", ",", { "a", "b", NULL } }, + { "a,b,c", ",", { "a", "b", "c", NULL } }, + { "first last", " ", { "first", "last", NULL } }, + { "a:", ":", { "a", "", NULL } }, + { "a::b", ":", { "a", "", "b", NULL } }, + { ":", ":", { "", "", NULL } }, + { ":a", ":", { "", "a", NULL } }, + { "::a", ":", { "", "", "a", NULL } }, +}; + +static void test_strv(void) +{ + int i, j; + const char **expect; + strList *list; + char **argv; + + for (i = 0; i < ARRAY_SIZE(list_data); i++) { + expect = list_data[i].argv; + list = str_split(list_data[i].string, list_data[i].delim); + argv = strv_from_strList(list); + qapi_free_strList(list); + for (j = 0; expect[j] && argv[j]; j++) { + g_assert_cmpstr(expect[j], ==, argv[j]); + } + g_assert_null(expect[j]); + g_assert_null(argv[j]); + g_strfreev(argv); + } +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_add_func("/test-string/length", test_length); + g_test_add_func("/test-string/strv", test_strv); + return g_test_run(); +} diff --git a/tests/unit/meson.build b/tests/unit/meson.build index cae925c132..9984860f0f 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -35,6 +35,7 @@ tests = { 'test-rcu-simpleq': [], 'test-rcu-tailq': [], 'test-rcu-slist': [], + 'test-strList': [], 'test-qdist': [], 'test-qht': [], 'test-qtree': [],