From patchwork Fri Sep 20 13:28:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 21293 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 8E5E1C32D5 for ; Fri, 20 Sep 2024 13:28:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 19E2063502; Fri, 20 Sep 2024 15:28:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="t+7dpps9"; dkim-atps=neutral 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 0CEF4634F8 for ; Fri, 20 Sep 2024 15:28:45 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:8ade:938d:48b1:cede]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2CCD2564; Fri, 20 Sep 2024 15:27:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1726838841; bh=m2RgS724KWx8eCi9Q/T7eoD8iBBuW1+7oBXMi0+RQfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t+7dpps9WFLFPezIP6JBf+hrMbXSIsn7YwHB2ay19sc/WFGvK9MQ72/PbK0qsb/7v xt5zNY52S6W552B4o1cqpTxIrICRlQF7aOa068v8S96T3g1s/46jpxV1D1UXLCSyWc XcuVXi0G4oXxiOYwiqE786bM4zagUjz4pelhVRaA= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v3 2/3] libcanera: yaml-parser: Add failing test for unexpected behavior Date: Fri, 20 Sep 2024 15:28:09 +0200 Message-ID: <20240920132823.88433-3-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920132823.88433-1-stefan.klug@ideasonboard.com> References: <20240920132823.88433-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When accessing a nonexistent key on a dict the YamlObject returns an empty element. This element can happily be cast to a string. This is unexpected. For example the following statement: yamlDict["nonexistent"].get("default") is expected to return "default" but actually returns "". Add a (failing) testcase for that behavior. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- Changes in v3: - Added separate patch for the failing test --- test/yaml-parser.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 347999831d61..4cc77e26ae39 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -536,6 +536,12 @@ protected: return TestFail; } + /* Test access to nonexistent member. */ + if (dictObj["nonexistent"].get("default") != "default") { + cerr << "Accessing nonexistent dict entry fails to return default" << std::endl; + return TestFail; + } + /* Make sure utils::map_keys() works on the adapter. */ (void)utils::map_keys(dictObj.asDict());