Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2573092rdg; Mon, 14 Aug 2023 06:58:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcPdywhUeCPzDQwzh/QdaIfXRphpTXAzcWDFpAdhTwAy8A0Ajmruj7hrtm5Zk8X0cOEFj8 X-Received: by 2002:a05:6a20:1392:b0:12f:a373:ba8d with SMTP id hn18-20020a056a20139200b0012fa373ba8dmr11139905pzc.24.1692021497172; Mon, 14 Aug 2023 06:58:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692021497; cv=none; d=google.com; s=arc-20160816; b=UPy4krXe5zgflu9qP1ONBi0yJwn+bo1F5uU4R+CMPl2FBJkB0ReH1ay9l/7MPZHh3d AKXYDQyf8Nc1O+O4Qz0FQtP5OxMcv0JkUXjt6Qu6e+nqywWeMA/oigGTpQYDD/YitPyD VnnFsdQouTR7nub8aHQdeOHPTmbKeIu528iDneHrCUHnBUXGDjf59L3ydcKqQQF6Tdhw u3n8RnHJEYvTvHUtN6cil4YHIFVnClu2h4dGIcKMuM+SnhnaDqwL7imXz2bruQeu1gNM vQhSC8fqBq9Db6IbLugdPUVywYqepEel2mTlkE+K8Z1QmZWNtyXFcQe/uTj8xZvBmnBw oDng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Y+sd3a/o1GUUs4yo0lq87GbdUfS162oRTEWPoq4kVAc=; fh=bGF4ESczbIrmrNxFOdEMfzJNgTVkRsqDRt+LRN0CeSg=; b=VGPobrpZA0vXA+WLjU1ZQWKBEsQtwZNrDhhYiCLV/KHzCyoY2HkxLyPvqTYXD02/6v CbDSGXKYJxlrST5gdtJ1oZAYuNeSxk8ww3oHByXpB3wkNoUmp/zNvQvGHlP1wd+IVvWF LE3T9KmGcScTttozr+qF6cDED7s6xTDWOhotSuLbBjbSGs1MmGgxkNva0PpoP4dqicOw jZD+1rgFWhGIhPPHAjh77Q6imLf8MykWlXzCH8JrPTKZYe0m/GcVwb5TAA8S7RIUdRs9 ENUT+G4Xmty+6uUFi1xQznoDvqcU0ZtXSHAUjFgU+EOSSGHeklvhha+H66jQ3+ft4z/W b3uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=ZVtEI+5e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u10-20020a6540ca000000b0054405623a4asi7961405pgp.615.2023.08.14.06.58.04; Mon, 14 Aug 2023 06:58:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=ZVtEI+5e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230345AbjHNNXv (ORCPT + 99 others); Mon, 14 Aug 2023 09:23:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230396AbjHNNX2 (ORCPT ); Mon, 14 Aug 2023 09:23:28 -0400 Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AFE210CE; Mon, 14 Aug 2023 06:23:27 -0700 (PDT) Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 37EBX0QX010808; Mon, 14 Aug 2023 08:23:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= PODMain02222019; bh=Y+sd3a/o1GUUs4yo0lq87GbdUfS162oRTEWPoq4kVAc=; b= ZVtEI+5eCgVZlzSbl5qarpI5rhxxPbLJ0trhaZ2kDUK1ZYBCOu9EHStPMPbNmAaj ETReIuRpaqUkNYWVzkTTHkD3AETAmGNncYmPqj6NifJij+9Bzyb/YavL/1cANvRb yZHCiUs5iNvVKBjDMLFUO+N8yqLFbp6phjZYlSMmvFh3S84nKrrSLKRJdPJyg0k6 3WNztbafRj/9EDDdPIjJMX82T3l5plinL0nShGX6Pjh17rtasnmLDoyDgjEmTL67 Hp2ZHYRdoSCz5GCv8vYIhSzLCTEYxpKgv9L3t/GKQiZfisG4Bvq6XP36Hi1cUD3M LoGhQoKIj2RWzo/wsqDxSQ== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3se6uhhvdp-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 14 Aug 2023 08:23:13 -0500 (CDT) Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Mon, 14 Aug 2023 14:23:13 +0100 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.30 via Frontend Transport; Mon, 14 Aug 2023 14:23:13 +0100 Received: from EDIN4L06LR3.ad.cirrus.com (EDIN4L06LR3.ad.cirrus.com [198.61.65.68]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id DE07C15B4; Mon, 14 Aug 2023 13:23:12 +0000 (UTC) From: Richard Fitzgerald To: , , CC: , , , , Richard Fitzgerald Subject: [PATCH v4 03/10] kunit: string-stream: Add cases for adding empty strings to a string_stream Date: Mon, 14 Aug 2023 14:23:02 +0100 Message-ID: <20230814132309.32641-4-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230814132309.32641-1-rf@opensource.cirrus.com> References: <20230814132309.32641-1-rf@opensource.cirrus.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: Cfk9gbhP_noQrxClgFSo0sxdLnZ6YV0t X-Proofpoint-ORIG-GUID: Cfk9gbhP_noQrxClgFSo0sxdLnZ6YV0t X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adds string_stream_append_empty_string_test() to test that adding an empty string to a string_stream doesn't create a new empty fragment. Signed-off-by: Richard Fitzgerald --- lib/kunit/string-stream-test.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/kunit/string-stream-test.c b/lib/kunit/string-stream-test.c index 1d46d5f06d2a..efe13e3322b5 100644 --- a/lib/kunit/string-stream-test.c +++ b/lib/kunit/string-stream-test.c @@ -206,11 +206,32 @@ static void string_stream_append_test(struct kunit *test) KUNIT_EXPECT_STREQ(test, string_stream_get_string(stream_1), stream_2_content); } +/* Adding an empty string should not create a fragment. */ +static void string_stream_append_empty_string_test(struct kunit *test) +{ + struct string_stream *stream; + + stream = alloc_string_stream(test, GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, stream); + + /* Formatted empty string */ + string_stream_add(stream, "%s", ""); + KUNIT_EXPECT_TRUE(test, string_stream_is_empty(stream)); + KUNIT_EXPECT_TRUE(test, list_empty(&stream->fragments)); + + /* Adding an empty string to a non-empty stream */ + string_stream_add(stream, "Add this line"); + string_stream_add(stream, "%s", ""); + KUNIT_EXPECT_EQ(test, list_count_nodes(&stream->fragments), 1); + KUNIT_EXPECT_STREQ(test, string_stream_get_string(stream), "Add this line"); +} + static struct kunit_case string_stream_test_cases[] = { KUNIT_CASE(string_stream_init_test), KUNIT_CASE(string_stream_line_add_test), KUNIT_CASE(string_stream_variable_length_line_test), KUNIT_CASE(string_stream_append_test), + KUNIT_CASE(string_stream_append_empty_string_test), {} }; -- 2.30.2