[{"id":31290,"web_url":"https://patchwork.libcamera.org/comment/31290/","msgid":"<172692267364.2374548.9394847656288806073@ping.linuxembedded.co.uk>","date":"2024-09-21T12:44:33","subject":"Re: [PATCH v3 1/3] libcamera: yaml-parser: Add additional tests","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2024-09-20 14:28:08)\n> Add additional tests in preparation for upcoming modifications on the\n> yaml parser. These tests handle the case where the yaml file contains\n> empty items in dictionaries or lists. E.g.:\n> \n> dict:\n>   key_with_value: value\n>   key_without_value:\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> \n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n> \n> In the end it turned out that the changes on the YamlParser were never\n> wrong, so these tests are somewhat superfluous. We could still merge\n> them to test specifically for that case or drop the patch.\n> \n> Changes in v3:\n> - Added seperate patch for the working tests\n> ---\n>  test/yaml-parser.cpp | 28 +++++++++++++++++++++++++---\n>  1 file changed, 25 insertions(+), 3 deletions(-)\n> \n> diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp\n> index 81c829834667..347999831d61 100644\n> --- a/test/yaml-parser.cpp\n> +++ b/test/yaml-parser.cpp\n> @@ -34,10 +34,12 @@ static const string testYaml =\n>         \"list:\\n\"\n>         \"  - James\\n\"\n>         \"  - Mary\\n\"\n> +       \"  - \\n\"\n>         \"dictionary:\\n\"\n>         \"  a: 1\\n\"\n>         \"  c: 3\\n\"\n>         \"  b: 2\\n\"\n> +       \"  empty:\\n\"\n>         \"level1:\\n\"\n>         \"  level2:\\n\"\n>         \"    - [1, 2]\\n\"\n> @@ -430,9 +432,10 @@ protected:\n>                 if (testObjectType(listObj, \"list\", Type::List) != TestPass)\n>                         return TestFail;\n>  \n> -               static constexpr std::array<const char *, 2> listValues{\n> +               static constexpr std::array<const char *, 3> listValues{\n>                         \"James\",\n>                         \"Mary\",\n> +                       \"\",\n>                 };\n>  \n>                 if (listObj.size() != listValues.size()) {\n> @@ -465,16 +468,23 @@ protected:\n>                         i++;\n>                 }\n>  \n> +               /* Ensure that empty objects get parsed as empty strings. */\n> +               if (!listObj[2].isValue()) {\n> +                       cerr << \"Empty object is not a value\" << std::endl;\n> +                       return TestFail;\n> +               }\n> +\n>                 /* Test dictionary object */\n>                 auto &dictObj = (*root)[\"dictionary\"];\n>  \n>                 if (testObjectType(dictObj, \"dictionary\", Type::Dictionary) != TestPass)\n>                         return TestFail;\n>  \n> -               static constexpr std::array<std::pair<const char *, int>, 3> dictValues{ {\n> +               static constexpr std::array<std::pair<const char *, int>, 4> dictValues{ {\n>                         { \"a\", 1 },\n>                         { \"c\", 3 },\n>                         { \"b\", 2 },\n> +                       { \"empty\", -100 },\n>                 } };\n>  \n>                 size_t dictSize = dictValues.size();\n> @@ -505,7 +515,7 @@ protected:\n>                                 return TestFail;\n>                         }\n>  \n> -                       if (elem.get<int32_t>(0) != item.second) {\n> +                       if (elem.get<int32_t>(-100) != item.second) {\n>                                 std::cerr << \"Dictionary element \" << i << \" has wrong value\"\n>                                           << std::endl;\n>                                 return TestFail;\n> @@ -514,6 +524,18 @@ protected:\n>                         i++;\n>                 }\n>  \n> +               /* Ensure that empty objects get parsed as empty strings. */\n> +               if (!dictObj[\"empty\"].isValue()) {\n> +                       cerr << \"Empty object is not of type value\" << std::endl;\n> +                       return TestFail;\n> +               }\n> +\n> +               /* Ensure that keys without values are added to a dict. */\n> +               if (!dictObj.contains(\"empty\")) {\n> +                       cerr << \"Empty element is missing in dict\" << std::endl;\n> +                       return TestFail;\n> +               }\n> +\n>                 /* Make sure utils::map_keys() works on the adapter. */\n>                 (void)utils::map_keys(dictObj.asDict());\n>  \n> -- \n> 2.43.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id F1B86C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 21 Sep 2024 12:44:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A303F634F9;\n\tSat, 21 Sep 2024 14:44:38 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AD805618E4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 21 Sep 2024 14:44:36 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2A3EC890;\n\tSat, 21 Sep 2024 14:43:12 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"BqJdUR1u\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1726922592;\n\tbh=PGiNHXsgPYDEwCn0WiJ3BpHM3NQ8Ejs3PHg9tX7Agsc=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=BqJdUR1ux1d/ALJKlAIT2VB3HCx6G1HE+11BUX0c9JYLx/kUPqDY2CgEm+cZPGzIk\n\tQvyNEnqwOoDvvV8FYRz1nkyziG/tjyJNdZCoGMLUuUUihFife0XthsD003TvfWJNz4\n\ty1aB+bTgVjKRtQ6qtILEknZ3sBS6it4z6hB9DrNA=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240920132823.88433-2-stefan.klug@ideasonboard.com>","References":"<20240920132823.88433-1-stefan.klug@ideasonboard.com>\n\t<20240920132823.88433-2-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v3 1/3] libcamera: yaml-parser: Add additional tests","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Sat, 21 Sep 2024 13:44:33 +0100","Message-ID":"<172692267364.2374548.9394847656288806073@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31301,"web_url":"https://patchwork.libcamera.org/comment/31301/","msgid":"<ZvE50xgLU2QGgaK9@pyrite.rasen.tech>","date":"2024-09-23T09:50:11","subject":"Re: [PATCH v3 1/3] libcamera: yaml-parser: Add additional tests","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Fri, Sep 20, 2024 at 03:28:08PM +0200, Stefan Klug wrote:\n> Add additional tests in preparation for upcoming modifications on the\n> yaml parser. These tests handle the case where the yaml file contains\n> empty items in dictionaries or lists. E.g.:\n> \n> dict:\n>   key_with_value: value\n>   key_without_value:\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> \n> ---\n> \n> In the end it turned out that the changes on the YamlParser were never\n> wrong, so these tests are somewhat superfluous. We could still merge\n> them to test specifically for that case or drop the patch.\n\nI think it's worth keeping the test to confirm correctness and ensure\nthat these aren't broken.\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> \n> Changes in v3:\n> - Added seperate patch for the working tests\n> ---\n>  test/yaml-parser.cpp | 28 +++++++++++++++++++++++++---\n>  1 file changed, 25 insertions(+), 3 deletions(-)\n> \n> diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp\n> index 81c829834667..347999831d61 100644\n> --- a/test/yaml-parser.cpp\n> +++ b/test/yaml-parser.cpp\n> @@ -34,10 +34,12 @@ static const string testYaml =\n>  \t\"list:\\n\"\n>  \t\"  - James\\n\"\n>  \t\"  - Mary\\n\"\n> +\t\"  - \\n\"\n>  \t\"dictionary:\\n\"\n>  \t\"  a: 1\\n\"\n>  \t\"  c: 3\\n\"\n>  \t\"  b: 2\\n\"\n> +\t\"  empty:\\n\"\n>  \t\"level1:\\n\"\n>  \t\"  level2:\\n\"\n>  \t\"    - [1, 2]\\n\"\n> @@ -430,9 +432,10 @@ protected:\n>  \t\tif (testObjectType(listObj, \"list\", Type::List) != TestPass)\n>  \t\t\treturn TestFail;\n>  \n> -\t\tstatic constexpr std::array<const char *, 2> listValues{\n> +\t\tstatic constexpr std::array<const char *, 3> listValues{\n>  \t\t\t\"James\",\n>  \t\t\t\"Mary\",\n> +\t\t\t\"\",\n>  \t\t};\n>  \n>  \t\tif (listObj.size() != listValues.size()) {\n> @@ -465,16 +468,23 @@ protected:\n>  \t\t\ti++;\n>  \t\t}\n>  \n> +\t\t/* Ensure that empty objects get parsed as empty strings. */\n> +\t\tif (!listObj[2].isValue()) {\n> +\t\t\tcerr << \"Empty object is not a value\" << std::endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n>  \t\t/* Test dictionary object */\n>  \t\tauto &dictObj = (*root)[\"dictionary\"];\n>  \n>  \t\tif (testObjectType(dictObj, \"dictionary\", Type::Dictionary) != TestPass)\n>  \t\t\treturn TestFail;\n>  \n> -\t\tstatic constexpr std::array<std::pair<const char *, int>, 3> dictValues{ {\n> +\t\tstatic constexpr std::array<std::pair<const char *, int>, 4> dictValues{ {\n>  \t\t\t{ \"a\", 1 },\n>  \t\t\t{ \"c\", 3 },\n>  \t\t\t{ \"b\", 2 },\n> +\t\t\t{ \"empty\", -100 },\n>  \t\t} };\n>  \n>  \t\tsize_t dictSize = dictValues.size();\n> @@ -505,7 +515,7 @@ protected:\n>  \t\t\t\treturn TestFail;\n>  \t\t\t}\n>  \n> -\t\t\tif (elem.get<int32_t>(0) != item.second) {\n> +\t\t\tif (elem.get<int32_t>(-100) != item.second) {\n>  \t\t\t\tstd::cerr << \"Dictionary element \" << i << \" has wrong value\"\n>  \t\t\t\t\t  << std::endl;\n>  \t\t\t\treturn TestFail;\n> @@ -514,6 +524,18 @@ protected:\n>  \t\t\ti++;\n>  \t\t}\n>  \n> +\t\t/* Ensure that empty objects get parsed as empty strings. */\n> +\t\tif (!dictObj[\"empty\"].isValue()) {\n> +\t\t\tcerr << \"Empty object is not of type value\" << std::endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Ensure that keys without values are added to a dict. */\n> +\t\tif (!dictObj.contains(\"empty\")) {\n> +\t\t\tcerr << \"Empty element is missing in dict\" << std::endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n>  \t\t/* Make sure utils::map_keys() works on the adapter. */\n>  \t\t(void)utils::map_keys(dictObj.asDict());\n>  \n> -- \n> 2.43.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 6A0DDC3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Sep 2024 09:50:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 534BF6350D;\n\tMon, 23 Sep 2024 11:50:22 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1266C6037E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Sep 2024 11:50:20 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:2fac:fd68:a1d3:63f3])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E158C670;\n\tMon, 23 Sep 2024 11:48:52 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"LpjldVKy\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727084934;\n\tbh=L0gUNLGdr+1elt8UOAM5Gtg18ELfG0LP7R23bu42CA0=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=LpjldVKyHg2o1InEOwaWw+S5JvDhsOtYmvxeqPaBI2LNga94DR8Dou+TDLZoD/s50\n\tv0xVwg3TF+HSiVv1e7tQHG9xhqzqGWxK5uoFQBjZqujA/wIX6XeQT5yISJiRF1Yuwo\n\tEO59mutIgRE+Z2cgqn637aCXsLCL+cEcS4BXTgNM=","Date":"Mon, 23 Sep 2024 18:50:11 +0900","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v3 1/3] libcamera: yaml-parser: Add additional tests","Message-ID":"<ZvE50xgLU2QGgaK9@pyrite.rasen.tech>","References":"<20240920132823.88433-1-stefan.klug@ideasonboard.com>\n\t<20240920132823.88433-2-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20240920132823.88433-2-stefan.klug@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]