[{"id":1972,"web_url":"https://patchwork.libcamera.org/comment/1972/","msgid":"<20190622224344.GK8156@pendragon.ideasonboard.com>","date":"2019-06-22T22:43:44","subject":"Re: [libcamera-devel] [RFC PATCH v2 2/9] libcamera: test: Add Value\n\ttests","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Fri, Jun 21, 2019 at 05:13:54PM +0100, Kieran Bingham wrote:\n> Add initial basic testing for the new Value APIs.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  test/meson.build |  1 +\n>  test/value.cpp   | 82 ++++++++++++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 83 insertions(+)\n>  create mode 100644 test/value.cpp\n> \n> diff --git a/test/meson.build b/test/meson.build\n> index c36ac2479636..eff541ddc0a6 100644\n> --- a/test/meson.build\n> +++ b/test/meson.build\n> @@ -15,6 +15,7 @@ public_tests = [\n>      ['list-cameras',                    'list-cameras.cpp'],\n>      ['signal',                          'signal.cpp'],\n>      ['timer',                           'timer.cpp'],\n> +    ['value',                           'value.cpp'],\n>  ]\n>  \n>  internal_tests = [\n> diff --git a/test/value.cpp b/test/value.cpp\n> new file mode 100644\n> index 000000000000..fea8cd2396cd\n> --- /dev/null\n> +++ b/test/value.cpp\n> @@ -0,0 +1,82 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * value.cpp - Value tests\n> + */\n> +\n> +#include <iostream>\n> +\n> +#include <libcamera/value.h>\n> +\n> +#include \"test.h\"\n> +\n> +using namespace std;\n> +using namespace libcamera;\n> +\n> +class Values : public Test\n> +{\n> +protected:\n> +\tint run()\n> +\t{\n> +\t\tValue integer(1234);\n> +\t\tValue boolean(true);\n> +\t\tValue string(\"test-string\");\n> +\n> +\t\t/* Just a string conversion output test... no validation */\n> +\t\tcout << \"Int: \" << integer.toString()\n> +\t\t     << \" Bool: \" << boolean.toString()\n> +\t\t     << \" String: \" << string.toString()\n> +\t\t     << endl;\n> +\n> +\t\t/* Just a string conversion output test. Using overloaded << */\n> +\t\tcout << \"Int: \" << integer\n> +\t\t     << \" Bool: \" << boolean\n> +\t\t     << \" String: \" << string\n> +\t\t     << endl;\n\nI think you should validate them both instead of printing them. You can\noutput to a stringstream and compare the result with an expected value.\n\n> +\n> +\t\tif (integer.getInt() != 1234) {\n> +\t\t\tcerr << \"Failed to get Integer\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (boolean.getBool() != true) {\n> +\t\t\tcerr << \"Failed to get Boolean\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (string.getString() != \"test-string\") {\n> +\t\t\tcerr << \"Failed to get string\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Test an uninitialised value, and updating it. */\n> +\n> +\t\tValue value;\n> +\t\tif (!value.isNull()) {\n> +\t\t\tcerr << \"Empty value is non-null\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tvalue.set(true);\n> +\t\tif (value.isNull()) {\n> +\t\t\tcerr << \"Failed to set an empty object\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (value.getBool() != true) {\n> +\t\t\tcerr << \"Failed to get Booleans\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tvalue.set(10);\n> +\t\tif (value.getInt() != 10) {\n> +\t\t\tcerr << \"Failed to get Integer\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +};\n> +\n> +TEST_REGISTER(Values)","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B36E6002B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 23 Jun 2019 00:44:03 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 93DFB67;\n\tSun, 23 Jun 2019 00:44:02 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1561243442;\n\tbh=MnbEuKn/H7HyiMCndJ0tU3y/FZJgsiKiNR6Oa6a4D0o=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=DqlP9DdbKd11K4uxiSaCgZZTGZwKpkiWYEpm+dV6Vuvskq6RvYKUHXVVAybD2TJt2\n\tD8hWE5KZAm4FJdqIySBYmT2a+Q0r06ke2kyEsFz5GOIdn2IJiQeIdWhaOId0enyZF8\n\ty47jAUVv/FptsF/QAnwQ69ifxEApBT9xRk4SW1Qw=","Date":"Sun, 23 Jun 2019 01:43:44 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20190622224344.GK8156@pendragon.ideasonboard.com>","References":"<20190621161401.28337-1-kieran.bingham@ideasonboard.com>\n\t<20190621161401.28337-3-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190621161401.28337-3-kieran.bingham@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [RFC PATCH v2 2/9] libcamera: test: Add Value\n\ttests","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Sat, 22 Jun 2019 22:44:03 -0000"}}]