From patchwork Sat Jun 4 18:59:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16163 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 21A47C3278 for ; Sat, 4 Jun 2022 19:00:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8AE206563D; Sat, 4 Jun 2022 21:00:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1654369212; bh=SUZ5vJfie+i32xSq7wD2gVnyYdGkZTsdqJhOzBSQbHQ=; 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=G2CFfuUnYM/DyDPSU/RIXTUIf+cfOOdsVJuZxs3VzO9OuZ9HEWV9i6Zk0yLZ0zQaX d+PSAM/J5YfRc3yAJrZn2m7oBzsmayqKvdvwGXAvRP4Zir/X7uom3Qz9u38cBODsoI 0tL1WT7PkX5yonazMElXcVvWcLr0emmg3LgC6qNznVGpCaU2+aiGCwSr19iU8g0amF wljQfdB5Qu3kAGChlaaA1eLjPnUn/twVeQ3pYXE+UqFDrY+naSpf0GCdmZ0ozn+36k rEFhFrcNwVqgcU3i5bb2VJMouyzQ4MYhfJvAlP1juU61yhzJdLYiOb9pspqXnPH8K1 26a/9vnKNpqxg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AABFD6563D for ; Sat, 4 Jun 2022 21:00:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="K8kuYlwZ"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (85-76-79-203-nat.elisa-mobile.fi [85.76.79.203]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 41FF86D4; Sat, 4 Jun 2022 21:00:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1654369210; bh=SUZ5vJfie+i32xSq7wD2gVnyYdGkZTsdqJhOzBSQbHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K8kuYlwZ00g7uhuK3xC8+fSFvMs5eHXULdND3npPAHtiLg/uGc9WUuVeDS8y5evYj pKs3xgo2V12cDBiIzEMgwfu9agkAHZJPYhhUJHG8K170ulIDc1JjxKyX2912R+tden 8bmI7UPsn+8J94NGVC5Vo1M+wvUdEx5S6m5PcdQU= To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Jun 2022 21:59:33 +0300 Message-Id: <20220604185939.29163-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220604185939.29163-1-laurent.pinchart@ideasonboard.com> References: <20220604185939.29163-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 08/14] 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 582c9caed836..6dfec49d6be0 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 @@ -373,15 +374,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 */ @@ -422,18 +447,50 @@ protected: return TestFail; } - if (dictObj.size() != 3) { - cerr << "Dictionary object parse with wrong size" << std::endl; + static constexpr std::array, 3> dictValues{ { + { "a", 1 }, + { "c", 3 }, + { "b", 2 }, + } }; + + 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(); - if (memeberNames.size() != 3) { - cerr << "Dictionary object fail to extra member names" << std::endl; - return TestFail; - } - if (memeberNames[0] != "a" || memeberNames[1] != "c" || memeberNames[2] != "b") { @@ -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"];