From patchwork Thu Jun 16 14:23:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16239 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 CDFF3C3275 for ; Thu, 16 Jun 2022 14:24:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C7A146563B; Thu, 16 Jun 2022 16:24:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655389463; bh=l/IgiffefRYZLY6fMuKPGTjR9AJ3eP6LacrA1gQk1Yc=; 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=STPtpu15iIqr/6mauXJv07yc7bc/Qsd+a4ZN11hrjNAS/U73D+8PcN8f8KgopLqOV bpzUUSl5jRTie7Gw7e27n+AJh2UaHbjdc4kQXNS796i8CTcpo7PThixznkqcE8+V3E TH/LE5zVIBO2qc04xMFosv5JNlfwX4BNu96Me/RUz7QTMHYNvMY/OzAnAtG6z1pD0g EzWOX9i+EJeCTV+51OyGX00+20abd/kJk1ZQR1psx1HFOrvK+1H6aHfQFjLN1V3M6g 379evsWpEZdEpaTOAvv6rRw6HqKjALpZF0fb5wU6YwUr0+p9sw0oYsrvRYGJRQQOZq YJDsCDuEG3wnw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4240165635 for ; Thu, 16 Jun 2022 16:24:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HTZBke8b"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A61B3415; Thu, 16 Jun 2022 16:24:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655389460; bh=l/IgiffefRYZLY6fMuKPGTjR9AJ3eP6LacrA1gQk1Yc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HTZBke8bnEAqdckiXUJ6jgl1tR62Gpu3tVAzra9SW4sfcs4HhJZU4tIFvja6Q3yZO IILDG6MVTuG57AenIYNWsGWi1QR2WQwbmEV/aq/99kr9G8ohpnwmR2xCLZpuzMLAMt gTeljWlETZFmsrjh5zC2cHJNTH9KtqxLNGS3gAz0= To: libcamera-devel@lists.libcamera.org Date: Thu, 16 Jun 2022 17:23:59 +0300 Message-Id: <20220616142403.20723-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> References: <20220616142403.20723-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/7] 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 Reviewed-by: Jacopo Mondi Reviewed-by: Han-Lin Chen --- test/yaml-parser.cpp | 99 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 19 deletions(-) diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 5ff4c3236dbf..ab6e9a01c0fe 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -5,11 +5,14 @@ * yaml-parser.cpp - YAML parser operations tests */ +#include #include +#include #include #include #include +#include #include "libcamera/internal/yaml_parser.h" @@ -373,15 +376,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,19 +449,60 @@ protected: return TestFail; } - if (dictObj.size() != 3) { - cerr << "Dictionary object parse with wrong size" << std::endl; + std::map dictValues{ { + { "a", 1 }, + { "b", 2 }, + { "c", 3 }, + } }; + + size_t dictSize = dictValues.size(); + + if (dictObj.size() != dictSize) { + cerr << "Dictionary object has wrong size" << std::endl; return TestFail; } + i = 0; + for (const auto &[key, elem] : dictObj.asDict()) { + if (i >= dictSize) { + std::cerr << "Too many elements in dictionary during iteration" + << std::endl; + return TestFail; + } + + const auto item = dictValues.find(key); + if (item == dictValues.end()) { + 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) != item->second) { + std::cerr << "Dictionary element " << i << " has wrong value" + << std::endl; + return TestFail; + } + + /* + * Erase the item to make sure that each iteration + * produces a different value. + */ + dictValues.erase(item); + i++; + } + + /* Make sure utils::map_keys() works on the adapter. */ + (void)utils::map_keys(dictObj.asDict()); + 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") { @@ -442,13 +510,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"];