[{"id":23463,"web_url":"https://patchwork.libcamera.org/comment/23463/","msgid":"<20220617151525.2q5yhnfwqagn4lih@uno.localdomain>","date":"2022-06-17T15:15:25","subject":"Re: [libcamera-devel] [PATCH 3/7] test: yaml_parser: Extend tests\n\tto cover the iterator API","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent\n\nOn Thu, Jun 16, 2022 at 05:23:59PM +0300, Laurent Pinchart via libcamera-devel wrote:\n> Test iteration over lists and dictionaries to test the YamlObject\n> iterator API.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  test/yaml-parser.cpp | 99 +++++++++++++++++++++++++++++++++++---------\n>  1 file changed, 80 insertions(+), 19 deletions(-)\n>\n> diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp\n> index 5ff4c3236dbf..ab6e9a01c0fe 100644\n> --- a/test/yaml-parser.cpp\n> +++ b/test/yaml-parser.cpp\n> @@ -5,11 +5,14 @@\n>   * yaml-parser.cpp - YAML parser operations tests\n>   */\n>\n> +#include <array>\n>  #include <iostream>\n> +#include <map>\n>  #include <string>\n>  #include <unistd.h>\n>\n>  #include <libcamera/base/file.h>\n> +#include <libcamera/base/utils.h>\n>\n>  #include \"libcamera/internal/yaml_parser.h\"\n>\n> @@ -373,15 +376,39 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> -\t\tif (listObj.size() > 2) {\n> +\t\tstatic constexpr std::array<const char *, 2> listValues{\n> +\t\t\t\"James\",\n> +\t\t\t\"Mary\",\n> +\t\t};\n> +\n> +\t\tif (listObj.size() != listValues.size()) {\n>  \t\t\tcerr << \"List object parse with wrong size\" << std::endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> -\t\tif (listObj[0].get<string>(\"\") != \"James\" ||\n> -\t\t    listObj[1].get<string>(\"\") != \"Mary\") {\n> -\t\t\tcerr << \"List object parse as wrong value\" << std::endl;\n> -\t\t\treturn TestFail;\n> +\t\tunsigned int i = 0;\n> +\t\tfor (auto &elem : listObj.asList()) {\n> +\t\t\tif (i >= listValues.size()) {\n> +\t\t\t\tstd::cerr << \"Too many elements in list during iteration\"\n> +\t\t\t\t\t  << std::endl;\n> +\t\t\t\treturn TestFail;\n> +\t\t\t}\n> +\n> +\t\t\tstd::string value = listValues[i];\n> +\n> +\t\t\tif (&elem != &listObj[i]) {\n> +\t\t\t\tstd::cerr << \"List element \" << i << \" has wrong address\"\n> +\t\t\t\t\t  << std::endl;\n> +\t\t\t\treturn TestFail;\n> +\t\t\t}\n> +\n> +\t\t\tif (elem.get<std::string>(\"\") != value) {\n> +\t\t\t\tstd::cerr << \"List element \" << i << \" has wrong value\"\n> +\t\t\t\t\t  << std::endl;\n> +\t\t\t\treturn TestFail;\n> +\t\t\t}\n> +\n> +\t\t\ti++;\n>  \t\t}\n>\n>  \t\t/* Test dictionary object */\n> @@ -422,19 +449,60 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> -\t\tif (dictObj.size() != 3) {\n> -\t\t\tcerr << \"Dictionary object parse with wrong size\" << std::endl;\n> +\t\tstd::map<std::string, int> dictValues{ {\n> +\t\t\t{ \"a\", 1 },\n> +\t\t\t{ \"b\", 2 },\n> +\t\t\t{ \"c\", 3 },\n> +\t\t} };\n> +\n> +\t\tsize_t dictSize = dictValues.size();\n> +\n> +\t\tif (dictObj.size() != dictSize) {\n> +\t\t\tcerr << \"Dictionary object has wrong size\" << std::endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> +\t\ti = 0;\n> +\t\tfor (const auto &[key, elem] : dictObj.asDict()) {\n> +\t\t\tif (i >= dictSize) {\n> +\t\t\t\tstd::cerr << \"Too many elements in dictionary during iteration\"\n> +\t\t\t\t\t  << std::endl;\n> +\t\t\t\treturn TestFail;\n> +\t\t\t}\n> +\n> +\t\t\tconst auto item = dictValues.find(key);\n> +\t\t\tif (item == dictValues.end()) {\n> +\t\t\t\tstd::cerr << \"Dictionary key \" << i << \" has wrong value\"\n> +\t\t\t\t\t  << std::endl;\n> +\t\t\t\treturn TestFail;\n> +\t\t\t}\n> +\n> +\t\t\tif (&elem != &dictObj[key]) {\n> +\t\t\t\tstd::cerr << \"Dictionary element \" << i << \" has wrong address\"\n> +\t\t\t\t\t  << std::endl;\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\t\tstd::cerr << \"Dictionary element \" << i << \" has wrong value\"\n> +\t\t\t\t\t  << std::endl;\n> +\t\t\t\treturn TestFail;\n> +\t\t\t}\n> +\n> +\t\t\t/*\n> +\t\t\t * Erase the item to make sure that each iteration\n> +\t\t\t * produces a different value.\n> +\t\t\t */\n> +\t\t\tdictValues.erase(item);\n\nCan the iteration return the same element twice ?\n\nWith this clarified\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n\n> +\t\t\ti++;\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>  \t\tauto memeberNames = dictObj.memberNames();\n>  \t\tsort(memeberNames.begin(), memeberNames.end());\n>\n> -\t\tif (memeberNames.size() != 3) {\n> -\t\t\tcerr << \"Dictionary object fail to extra member names\" << std::endl;\n> -\t\t\treturn TestFail;\n> -\t\t}\n> -\n>  \t\tif (memeberNames[0] != \"a\" ||\n>  \t\t    memeberNames[1] != \"b\" ||\n>  \t\t    memeberNames[2] != \"c\") {\n> @@ -442,13 +510,6 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> -\t\tif (dictObj[\"a\"].get<int32_t>(0) != 1 ||\n> -\t\t    dictObj[\"b\"].get<int32_t>(0) != 2 ||\n> -\t\t    dictObj[\"c\"].get<int32_t>(0) != 3) {\n> -\t\t\tcerr << \"Dictionary object fail to parse member value\" << std::endl;\n> -\t\t\treturn TestFail;\n> -\t\t}\n> -\n>  \t\t/* Test leveled objects */\n>  \t\tauto &level1Obj = (*root)[\"level1\"];\n>\n> --\n> Regards,\n>\n> Laurent Pinchart\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 5F79BBD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 17 Jun 2022 15:15:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 92E8565637;\n\tFri, 17 Jun 2022 17:15:28 +0200 (CEST)","from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2EDD565632\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jun 2022 17:15:27 +0200 (CEST)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id A33E410000A;\n\tFri, 17 Jun 2022 15:15:26 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655478928;\n\tbh=2ipXluK8Oj8R7Nrs/3d183oGSnZazJJD9iCJuF4o72c=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=QkRDnaKWOcOJHmTsW1RQxHU+kBkE1whb7aUNsbZc0qswVzY2mSzOJi8DwHZPv3CIv\n\tU+Ps3O3d8V1OaoQorrKePQZRJcqKI4J42kD7330N+/ON6Ki05q7KohkOL1hacxt2g0\n\tVZNWW83fBfZiMf+Sd2o7NhKM7PjJvA/R/soWdho1GYHytYz1T2ZvSCxWHavmvV8oDQ\n\t3pfZheDExp2n9a457wYP9PLEC6igBf+dHL1Px0kxHzOCZYLaY/19Ys4S3XnauLEHlI\n\tAOInLdbtU1giBjkOtELTa/ciQ+IxUuirPsrrOt53WlhTAD+VfKbd5T1/ZZvOGM8/0Z\n\t4+yUMO0UZkNfA==","Date":"Fri, 17 Jun 2022 17:15:25 +0200","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20220617151525.2q5yhnfwqagn4lih@uno.localdomain>","References":"<20220616142403.20723-1-laurent.pinchart@ideasonboard.com>\n\t<20220616142403.20723-4-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220616142403.20723-4-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 3/7] test: yaml_parser: Extend tests\n\tto cover the iterator API","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>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":23464,"web_url":"https://patchwork.libcamera.org/comment/23464/","msgid":"<Yqyj28B7nnQgycsU@pendragon.ideasonboard.com>","date":"2022-06-17T15:55:07","subject":"Re: [libcamera-devel] [PATCH 3/7] test: yaml_parser: Extend tests\n\tto cover the iterator API","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Fri, Jun 17, 2022 at 05:15:25PM +0200, Jacopo Mondi wrote:\n> On Thu, Jun 16, 2022 at 05:23:59PM +0300, Laurent Pinchart via libcamera-devel wrote:\n> > Test iteration over lists and dictionaries to test the YamlObject\n> > iterator API.\n> >\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  test/yaml-parser.cpp | 99 +++++++++++++++++++++++++++++++++++---------\n> >  1 file changed, 80 insertions(+), 19 deletions(-)\n> >\n> > diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp\n> > index 5ff4c3236dbf..ab6e9a01c0fe 100644\n> > --- a/test/yaml-parser.cpp\n> > +++ b/test/yaml-parser.cpp\n> > @@ -5,11 +5,14 @@\n> >   * yaml-parser.cpp - YAML parser operations tests\n> >   */\n> >\n> > +#include <array>\n> >  #include <iostream>\n> > +#include <map>\n> >  #include <string>\n> >  #include <unistd.h>\n> >\n> >  #include <libcamera/base/file.h>\n> > +#include <libcamera/base/utils.h>\n> >\n> >  #include \"libcamera/internal/yaml_parser.h\"\n> >\n> > @@ -373,15 +376,39 @@ protected:\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > -\t\tif (listObj.size() > 2) {\n> > +\t\tstatic constexpr std::array<const char *, 2> listValues{\n> > +\t\t\t\"James\",\n> > +\t\t\t\"Mary\",\n> > +\t\t};\n> > +\n> > +\t\tif (listObj.size() != listValues.size()) {\n> >  \t\t\tcerr << \"List object parse with wrong size\" << std::endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > -\t\tif (listObj[0].get<string>(\"\") != \"James\" ||\n> > -\t\t    listObj[1].get<string>(\"\") != \"Mary\") {\n> > -\t\t\tcerr << \"List object parse as wrong value\" << std::endl;\n> > -\t\t\treturn TestFail;\n> > +\t\tunsigned int i = 0;\n> > +\t\tfor (auto &elem : listObj.asList()) {\n> > +\t\t\tif (i >= listValues.size()) {\n> > +\t\t\t\tstd::cerr << \"Too many elements in list during iteration\"\n> > +\t\t\t\t\t  << std::endl;\n> > +\t\t\t\treturn TestFail;\n> > +\t\t\t}\n> > +\n> > +\t\t\tstd::string value = listValues[i];\n> > +\n> > +\t\t\tif (&elem != &listObj[i]) {\n> > +\t\t\t\tstd::cerr << \"List element \" << i << \" has wrong address\"\n> > +\t\t\t\t\t  << std::endl;\n> > +\t\t\t\treturn TestFail;\n> > +\t\t\t}\n> > +\n> > +\t\t\tif (elem.get<std::string>(\"\") != value) {\n> > +\t\t\t\tstd::cerr << \"List element \" << i << \" has wrong value\"\n> > +\t\t\t\t\t  << std::endl;\n> > +\t\t\t\treturn TestFail;\n> > +\t\t\t}\n> > +\n> > +\t\t\ti++;\n> >  \t\t}\n> >\n> >  \t\t/* Test dictionary object */\n> > @@ -422,19 +449,60 @@ protected:\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > -\t\tif (dictObj.size() != 3) {\n> > -\t\t\tcerr << \"Dictionary object parse with wrong size\" << std::endl;\n> > +\t\tstd::map<std::string, int> dictValues{ {\n> > +\t\t\t{ \"a\", 1 },\n> > +\t\t\t{ \"b\", 2 },\n> > +\t\t\t{ \"c\", 3 },\n> > +\t\t} };\n> > +\n> > +\t\tsize_t dictSize = dictValues.size();\n> > +\n> > +\t\tif (dictObj.size() != dictSize) {\n> > +\t\t\tcerr << \"Dictionary object has wrong size\" << std::endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > +\t\ti = 0;\n> > +\t\tfor (const auto &[key, elem] : dictObj.asDict()) {\n> > +\t\t\tif (i >= dictSize) {\n> > +\t\t\t\tstd::cerr << \"Too many elements in dictionary during iteration\"\n> > +\t\t\t\t\t  << std::endl;\n> > +\t\t\t\treturn TestFail;\n> > +\t\t\t}\n> > +\n> > +\t\t\tconst auto item = dictValues.find(key);\n> > +\t\t\tif (item == dictValues.end()) {\n> > +\t\t\t\tstd::cerr << \"Dictionary key \" << i << \" has wrong value\"\n> > +\t\t\t\t\t  << std::endl;\n> > +\t\t\t\treturn TestFail;\n> > +\t\t\t}\n> > +\n> > +\t\t\tif (&elem != &dictObj[key]) {\n> > +\t\t\t\tstd::cerr << \"Dictionary element \" << i << \" has wrong address\"\n> > +\t\t\t\t\t  << std::endl;\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\t\tstd::cerr << \"Dictionary element \" << i << \" has wrong value\"\n> > +\t\t\t\t\t  << std::endl;\n> > +\t\t\t\treturn TestFail;\n> > +\t\t\t}\n> > +\n> > +\t\t\t/*\n> > +\t\t\t * Erase the item to make sure that each iteration\n> > +\t\t\t * produces a different value.\n> > +\t\t\t */\n> > +\t\t\tdictValues.erase(item);\n> \n> Can the iteration return the same element twice ?\n\nIt's not supposed to. That's why this is trying to catch, without the\nerase, if the iterator returned the same element three times, the test\nwould pass.\n\n> With this clarified\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> \n> > +\t\t\ti++;\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> >  \t\tauto memeberNames = dictObj.memberNames();\n> >  \t\tsort(memeberNames.begin(), memeberNames.end());\n> >\n> > -\t\tif (memeberNames.size() != 3) {\n> > -\t\t\tcerr << \"Dictionary object fail to extra member names\" << std::endl;\n> > -\t\t\treturn TestFail;\n> > -\t\t}\n> > -\n> >  \t\tif (memeberNames[0] != \"a\" ||\n> >  \t\t    memeberNames[1] != \"b\" ||\n> >  \t\t    memeberNames[2] != \"c\") {\n> > @@ -442,13 +510,6 @@ protected:\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > -\t\tif (dictObj[\"a\"].get<int32_t>(0) != 1 ||\n> > -\t\t    dictObj[\"b\"].get<int32_t>(0) != 2 ||\n> > -\t\t    dictObj[\"c\"].get<int32_t>(0) != 3) {\n> > -\t\t\tcerr << \"Dictionary object fail to parse member value\" << std::endl;\n> > -\t\t\treturn TestFail;\n> > -\t\t}\n> > -\n> >  \t\t/* Test leveled objects */\n> >  \t\tauto &level1Obj = (*root)[\"level1\"];\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 42EDEBD161\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 17 Jun 2022 15:55:21 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 61C6B65635;\n\tFri, 17 Jun 2022 17:55:20 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E457865632\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jun 2022 17:55:18 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 70766982;\n\tFri, 17 Jun 2022 17:55:18 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655481320;\n\tbh=cjxInGjWlXP1dfkLDSN90bhMtsCPa5ER9qUGOP0rgH4=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=zhZOz0LqYGPZ+VdZWALH+Z4HS0SuvKjpZhn2vW6iThtMHkNYHY8X2KsUqPVaLrbY0\n\tWni17ZmrIMgEQmYaE/ecsAmO+xITbTQ29JFLgXGyImUbyGSGDQHCIRtNsxAw0bOfUT\n\ts5mDtyx4HwWc6wp89Neb8XsXokiGC16656a+8KeA5Wnn6QBlSd/MTt/pKoksGOCtnk\n\tqtwUUwnBQEEa4uR+utIr7GI2vygCAgGWRRzwYv7N4VLuIZ1bx/YSvcgNLcqeNhYutJ\n\tFuSxdyPm/QkXZ2AzPVcTNSX9QEsB/SkxBlKlHd0KqhU6zSPPa77X7Emh2X2FK8JZdF\n\tpIqwTli0WiJ9A==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1655481318;\n\tbh=cjxInGjWlXP1dfkLDSN90bhMtsCPa5ER9qUGOP0rgH4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=MaN1ppG709sm1r2s/t2HKEORO4c+L13G/hXU6MjTYLSXBVNTJYU2HmIyrOvn1mSYB\n\tsQn2y/DMY0Jgi+poKcpNUh/eZqf0mFTxjmaQtUnbe2Hwf4vmnb2riM4kI6JhRApxAr\n\tjV2U1GrhTGy5J3f3aISbGN79wRUOrz8P2nngSta0="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"MaN1ppG7\"; dkim-atps=neutral","Date":"Fri, 17 Jun 2022 18:55:07 +0300","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<Yqyj28B7nnQgycsU@pendragon.ideasonboard.com>","References":"<20220616142403.20723-1-laurent.pinchart@ideasonboard.com>\n\t<20220616142403.20723-4-laurent.pinchart@ideasonboard.com>\n\t<20220617151525.2q5yhnfwqagn4lih@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220617151525.2q5yhnfwqagn4lih@uno.localdomain>","Subject":"Re: [libcamera-devel] [PATCH 3/7] test: yaml_parser: Extend tests\n\tto cover the iterator API","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":23486,"web_url":"https://patchwork.libcamera.org/comment/23486/","msgid":"<CAJAuwMkMQdie2j7pyM6SqFnf50sVPSrVwjjW1x62QnbNd-PSAg@mail.gmail.com>","date":"2022-06-20T12:06:56","subject":"Re: [libcamera-devel] [PATCH 3/7] test: yaml_parser: Extend tests\n\tto cover the iterator API","submitter":{"id":98,"url":"https://patchwork.libcamera.org/api/people/98/","name":"Hanlin Chen","email":"hanlinchen@chromium.org"},"content":"Hi Laurent,\n\nReviewed-by: Han-Lin Chen <hanlinchen@chromium.org>\nThanks.\n\nOn Fri, Jun 17, 2022 at 11:55 PM Laurent Pinchart via libcamera-devel\n<libcamera-devel@lists.libcamera.org> wrote:\n>\n> Hi Jacopo,\n>\n> On Fri, Jun 17, 2022 at 05:15:25PM +0200, Jacopo Mondi wrote:\n> > On Thu, Jun 16, 2022 at 05:23:59PM +0300, Laurent Pinchart via libcamera-devel wrote:\n> > > Test iteration over lists and dictionaries to test the YamlObject\n> > > iterator API.\n> > >\n> > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > > ---\n> > >  test/yaml-parser.cpp | 99 +++++++++++++++++++++++++++++++++++---------\n> > >  1 file changed, 80 insertions(+), 19 deletions(-)\n> > >\n> > > diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp\n> > > index 5ff4c3236dbf..ab6e9a01c0fe 100644\n> > > --- a/test/yaml-parser.cpp\n> > > +++ b/test/yaml-parser.cpp\n> > > @@ -5,11 +5,14 @@\n> > >   * yaml-parser.cpp - YAML parser operations tests\n> > >   */\n> > >\n> > > +#include <array>\n> > >  #include <iostream>\n> > > +#include <map>\n> > >  #include <string>\n> > >  #include <unistd.h>\n> > >\n> > >  #include <libcamera/base/file.h>\n> > > +#include <libcamera/base/utils.h>\n> > >\n> > >  #include \"libcamera/internal/yaml_parser.h\"\n> > >\n> > > @@ -373,15 +376,39 @@ protected:\n> > >                     return TestFail;\n> > >             }\n> > >\n> > > -           if (listObj.size() > 2) {\n> > > +           static constexpr std::array<const char *, 2> listValues{\n> > > +                   \"James\",\n> > > +                   \"Mary\",\n> > > +           };\n> > > +\n> > > +           if (listObj.size() != listValues.size()) {\n> > >                     cerr << \"List object parse with wrong size\" << std::endl;\n> > >                     return TestFail;\n> > >             }\n> > >\n> > > -           if (listObj[0].get<string>(\"\") != \"James\" ||\n> > > -               listObj[1].get<string>(\"\") != \"Mary\") {\n> > > -                   cerr << \"List object parse as wrong value\" << std::endl;\n> > > -                   return TestFail;\n> > > +           unsigned int i = 0;\n> > > +           for (auto &elem : listObj.asList()) {\n> > > +                   if (i >= listValues.size()) {\n> > > +                           std::cerr << \"Too many elements in list during iteration\"\n> > > +                                     << std::endl;\n> > > +                           return TestFail;\n> > > +                   }\n> > > +\n> > > +                   std::string value = listValues[i];\n> > > +\n> > > +                   if (&elem != &listObj[i]) {\n> > > +                           std::cerr << \"List element \" << i << \" has wrong address\"\n> > > +                                     << std::endl;\n> > > +                           return TestFail;\n> > > +                   }\n> > > +\n> > > +                   if (elem.get<std::string>(\"\") != value) {\n> > > +                           std::cerr << \"List element \" << i << \" has wrong value\"\n> > > +                                     << std::endl;\n> > > +                           return TestFail;\n> > > +                   }\n> > > +\n> > > +                   i++;\n> > >             }\n> > >\n> > >             /* Test dictionary object */\n> > > @@ -422,19 +449,60 @@ protected:\n> > >                     return TestFail;\n> > >             }\n> > >\n> > > -           if (dictObj.size() != 3) {\n> > > -                   cerr << \"Dictionary object parse with wrong size\" << std::endl;\n> > > +           std::map<std::string, int> dictValues{ {\n> > > +                   { \"a\", 1 },\n> > > +                   { \"b\", 2 },\n> > > +                   { \"c\", 3 },\n> > > +           } };\n> > > +\n> > > +           size_t dictSize = dictValues.size();\n> > > +\n> > > +           if (dictObj.size() != dictSize) {\n> > > +                   cerr << \"Dictionary object has wrong size\" << std::endl;\n> > >                     return TestFail;\n> > >             }\n> > >\n> > > +           i = 0;\n> > > +           for (const auto &[key, elem] : dictObj.asDict()) {\n> > > +                   if (i >= dictSize) {\n> > > +                           std::cerr << \"Too many elements in dictionary during iteration\"\n> > > +                                     << std::endl;\n> > > +                           return TestFail;\n> > > +                   }\n> > > +\n> > > +                   const auto item = dictValues.find(key);\n> > > +                   if (item == dictValues.end()) {\n> > > +                           std::cerr << \"Dictionary key \" << i << \" has wrong value\"\n> > > +                                     << std::endl;\n> > > +                           return TestFail;\n> > > +                   }\n> > > +\n> > > +                   if (&elem != &dictObj[key]) {\n> > > +                           std::cerr << \"Dictionary element \" << i << \" has wrong address\"\n> > > +                                     << std::endl;\n> > > +                           return TestFail;\n> > > +                   }\n> > > +\n> > > +                   if (elem.get<int32_t>(0) != item->second) {\n> > > +                           std::cerr << \"Dictionary element \" << i << \" has wrong value\"\n> > > +                                     << std::endl;\n> > > +                           return TestFail;\n> > > +                   }\n> > > +\n> > > +                   /*\n> > > +                    * Erase the item to make sure that each iteration\n> > > +                    * produces a different value.\n> > > +                    */\n> > > +                   dictValues.erase(item);\n> >\n> > Can the iteration return the same element twice ?\n>\n> It's not supposed to. That's why this is trying to catch, without the\n> erase, if the iterator returned the same element three times, the test\n> would pass.\n>\n> > With this clarified\n> > Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> >\n> > > +                   i++;\n> > > +           }\n> > > +\n> > > +           /* Make sure utils::map_keys() works on the adapter. */\n> > > +           (void)utils::map_keys(dictObj.asDict());\n> > > +\n> > >             auto memeberNames = dictObj.memberNames();\n> > >             sort(memeberNames.begin(), memeberNames.end());\n> > >\n> > > -           if (memeberNames.size() != 3) {\n> > > -                   cerr << \"Dictionary object fail to extra member names\" << std::endl;\n> > > -                   return TestFail;\n> > > -           }\n> > > -\n> > >             if (memeberNames[0] != \"a\" ||\n> > >                 memeberNames[1] != \"b\" ||\n> > >                 memeberNames[2] != \"c\") {\n> > > @@ -442,13 +510,6 @@ protected:\n> > >                     return TestFail;\n> > >             }\n> > >\n> > > -           if (dictObj[\"a\"].get<int32_t>(0) != 1 ||\n> > > -               dictObj[\"b\"].get<int32_t>(0) != 2 ||\n> > > -               dictObj[\"c\"].get<int32_t>(0) != 3) {\n> > > -                   cerr << \"Dictionary object fail to parse member value\" << std::endl;\n> > > -                   return TestFail;\n> > > -           }\n> > > -\n> > >             /* Test leveled objects */\n> > >             auto &level1Obj = (*root)[\"level1\"];\n> > >\n>\n> --\n> Regards,\n>\n> Laurent Pinchart","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 EAE41BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Jun 2022 12:07:10 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5DA8C65637;\n\tMon, 20 Jun 2022 14:07:10 +0200 (CEST)","from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com\n\t[IPv6:2607:f8b0:4864:20::32a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A832D65632\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Jun 2022 14:07:08 +0200 (CEST)","by mail-ot1-x32a.google.com with SMTP id\n\ta8-20020a05683012c800b0060c027c8afdso8176147otq.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Jun 2022 05:07:08 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655726830;\n\tbh=qNxau8WJ2ycRPjn/j02XNfbStgrPlvJcgFCHuC0HBKY=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=1+U/2tMVVdca/evQNmYzTTT85i3J4ccVy5llicKWe+2spnt6lDEFtCIO+WLe+oH8u\n\t1h5fNGaZZBIykeI/fAuR4602yDLz1u1srxC6/IhmSyugmIh26ZtV59ktaRSlUOjZ/f\n\t9N74fDodK4cK43PcIDmQG5NzacGAwXX0JPuwqGF2IokX9HMTqE3uULeQYH2Daig78F\n\taaiatWV/cPvX3f2QEKayQ6kOLi65rRfaqVyjPjq8Ml/M6agGAfmhvTFrROc91tMyWT\n\t8HO0ZFgGjHJc3xk+G83ryD2gcHH2+UhTlHuFDlfoqhj9eiMVPf+uNLU1I2LM/DMQOr\n\tl1cUcv8fBiFAw==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=GDkzk6cFH51ZXPl2FTKtOEft7+FprI4yt+GJ3o1fZtw=;\n\tb=L8joHxej9GXAptakhiXOY84btDLg9hc+qVII4VH+lXzatSCvnn7eWL55RvX3T07woC\n\tZF+1QM3HRQA6OfYL29gOONPdG8nt8GS8CZR0+t+SipOV8FcRaTd43gMxG6YPdY6Ptrb4\n\tnwIpcymucptqry46oFyDCYwNX02VVkkkhTvVc="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"L8joHxej\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=GDkzk6cFH51ZXPl2FTKtOEft7+FprI4yt+GJ3o1fZtw=;\n\tb=QU1w6CBYd6SLWk0lhYRGsKsDNVfba68zObqlZe5nH107WXdfuq9wsolhJrH0hpiVjE\n\tP+2FR+CpDtfZ6+7eaQKdJlpSPYiGx4wl3iCYZtHTo2JL4DRNt0AuNxaAB/zeHd+yxsg7\n\tAygSxKhV2s7PuyUX2K5uQX1tG8gadHftsngVcS2VCjLuKX1Qp521u/fcL9bvT+jr9D+P\n\tZa5w5FUQUhQhR9Vkd0r7kRuehP/t8MetFZtcQGyuNPjGn3CLi1VihbuR/TDA4kYrtnS1\n\tb48fkBThrpLDuqgC0jt462QResa8t/I2r2oeNmydICqDJ6NGIiXo0lpDvCsbTnZZGEKJ\n\tnUWw==","X-Gm-Message-State":"AJIora+X8gmVnu3G9sPJ2a8/8eY9DJBqm+nbpeZLmRBtpGpg7XE26hWP\n\t+Lc8KWKJZxY3mRsH6HHtMXMvw5Uy0tltBbFv1uQnPkM7a0VgqQ==","X-Google-Smtp-Source":"AGRyM1uhHgY8DuDPWvDtgweBTpYIo1ardbYJBMU72MSuJKcwLO2q7kR5/JMZQdH0kDVBoUGRdkkhFo/uAE7K+f3IkSs=","X-Received":"by 2002:a9d:5a9b:0:b0:60b:faf0:a1aa with SMTP id\n\tw27-20020a9d5a9b000000b0060bfaf0a1aamr8869556oth.176.1655726827478;\n\tMon, 20 Jun 2022 05:07:07 -0700 (PDT)","MIME-Version":"1.0","References":"<20220616142403.20723-1-laurent.pinchart@ideasonboard.com>\n\t<20220616142403.20723-4-laurent.pinchart@ideasonboard.com>\n\t<20220617151525.2q5yhnfwqagn4lih@uno.localdomain>\n\t<Yqyj28B7nnQgycsU@pendragon.ideasonboard.com>","In-Reply-To":"<Yqyj28B7nnQgycsU@pendragon.ideasonboard.com>","Date":"Mon, 20 Jun 2022 20:06:56 +0800","Message-ID":"<CAJAuwMkMQdie2j7pyM6SqFnf50sVPSrVwjjW1x62QnbNd-PSAg@mail.gmail.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH 3/7] test: yaml_parser: Extend tests\n\tto cover the iterator API","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>","From":"Hanlin Chen via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Hanlin Chen <hanlinchen@chromium.org>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]