From patchwork Tue May 24 22:58:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16032 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 14737BD161 for ; Tue, 24 May 2022 22:58:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AAE3665672; Wed, 25 May 2022 00:58:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653433113; bh=yuzPcW09xN5jnjxLp9B1c60Gpp/d/NIaVzr7xlwAIT8=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=UYhFUdKiQGGXeEeO7xXKBeuyldzDPCpMrCYccGH0ArCPwV7SXtAVK/1ppsu1O2QcR B4fjjKsvRAYqG59UiWOT/9d+2a56VFAU21g5NMN0J4SXrzQa+N0ouPvpiS96wtdV9q //vi5AGi7pZ5CB+0jnshCnMZkVicpCBMhNP7K6QS9luKIpNVzPBEMSCglfjXMgK4ym 2tWfzmY3jqOHVYQ75zm7j5x3zVa346F+xu3mNCWmC9xlqcwVz3J/Q2y4zobpBGjqjt N2yGGAgearMx86VdvfhMtvVQRrtZGgrd9ipQWLKUVUnZLuHM7xUYQFfXgKfyuoXnyh OJbHr+BUyDFyQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 27C9B65663 for ; Wed, 25 May 2022 00:58:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jSk9RUyF"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (ip-109-40-241-133.web.vodafone.de [109.40.241.133]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 865DB1224; Wed, 25 May 2022 00:58:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653433107; bh=yuzPcW09xN5jnjxLp9B1c60Gpp/d/NIaVzr7xlwAIT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jSk9RUyFQNjozcwhesKnzxVaETbxx5h6iNdlcSw3cpVQDdTwD1kNS0LSHxSlh93gv 4x99X2f5kw6YcnYOeN+ogihohA0Km/O/OF1sm+JR2Ti5396Avwv6t3p+0geskbPF6L oVtcSqj54YiicMOCWY4g/NyvkRg+LKkdY/wHFMOc= To: libcamera-devel@lists.libcamera.org Date: Wed, 25 May 2022 01:58:10 +0300 Message-Id: <20220524225816.6830-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> References: <20220524225816.6830-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 06/12] test: yaml_parser: Extend tests to cover the iterator API X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Test iteration over lists and dictionaries to test the YamlObject iterator API. Signed-off-by: Laurent Pinchart --- test/yaml-parser.cpp | 88 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 19 deletions(-) diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 944b564bbe22..7ad9936bb82b 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -5,6 +5,7 @@ * yaml-parser.cpp - YAML parser operations tests */ +#include #include #include #include @@ -372,15 +373,39 @@ protected: return TestFail; } - if (listObj.size() > 2) { + static constexpr std::array listValues{ + "James", + "Mary", + }; + + if (listObj.size() != listValues.size()) { cerr << "List object parse with wrong size" << std::endl; return TestFail; } - if (listObj[0].get("") != "James" || - listObj[1].get("") != "Mary") { - cerr << "List object parse as wrong value" << std::endl; - return TestFail; + unsigned int i = 0; + for (auto &elem : listObj.asList()) { + if (i >= listValues.size()) { + std::cerr << "Too many elements in list during iteration" + << std::endl; + return TestFail; + } + + std::string value = listValues[i]; + + if (&elem != &listObj[i]) { + std::cerr << "List element " << i << " has wrong address" + << std::endl; + return TestFail; + } + + if (elem.get("") != value) { + std::cerr << "List element " << i << " has wrong value" + << std::endl; + return TestFail; + } + + i++; } /* Test dictionary object */ @@ -421,19 +446,51 @@ protected: return TestFail; } - if (dictObj.size() != 3) { - cerr << "Dictionary object parse with wrong size" << std::endl; + static constexpr std::array, 3> dictValues{ { + { "a", 1 }, + { "b", 2 }, + { "c", 3 }, + } }; + + if (dictObj.size() != dictValues.size()) { + cerr << "Dictionary object has wrong size" << std::endl; return TestFail; } + i = 0; + for (const auto &[key, elem] : dictObj.asDict()) { + if (i >= dictValues.size()) { + std::cerr << "Too many elements in dictionary during iteration" + << std::endl; + return TestFail; + } + + const std::pair &value = dictValues[i]; + + if (key != value.first) { + std::cerr << "Dictionary key " << i << " has wrong value" + << std::endl; + return TestFail; + } + + if (&elem != &dictObj[key]) { + std::cerr << "Dictionary element " << i << " has wrong address" + << std::endl; + return TestFail; + } + + if (elem.get(0) != value.second) { + std::cerr << "Dictionary element " << i << " has wrong value" + << std::endl; + return TestFail; + } + + i++; + } + auto memeberNames = dictObj.memberNames(); sort(memeberNames.begin(), memeberNames.end()); - if (memeberNames.size() != 3) { - cerr << "Dictionary object fail to extra member names" << std::endl; - return TestFail; - } - if (memeberNames[0] != "a" || memeberNames[1] != "b" || memeberNames[2] != "c") { @@ -441,13 +498,6 @@ protected: return TestFail; } - if (dictObj["a"].get(0) != 1 || - dictObj["b"].get(0) != 2 || - dictObj["c"].get(0) != 3) { - cerr << "Dictionary object fail to parse member value" << std::endl; - return TestFail; - } - /* Test leveled objects */ auto &level1Obj = (*root)["level1"];