[{"id":13497,"web_url":"https://patchwork.libcamera.org/comment/13497/","msgid":"<20201026232810.GK3756@pendragon.ideasonboard.com>","date":"2020-10-26T23:28:10","subject":"Re: [libcamera-devel] [PATCH v6 6/6] test: geometry: Add unit tests\n\tfor new geometry helper functions","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi David,\n\nThank you for the patch.\n\nOn Mon, Oct 26, 2020 at 05:19:08PM +0000, David Plowman wrote:\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> ---\n>  test/geometry.cpp | 258 +++++++++++++++++++++++++++++++++++++++++++++-\n>  1 file changed, 254 insertions(+), 4 deletions(-)\n> \n> diff --git a/test/geometry.cpp b/test/geometry.cpp\n> index 08e268c9..175221f9 100644\n> --- a/test/geometry.cpp\n> +++ b/test/geometry.cpp\n> @@ -17,16 +17,17 @@ using namespace libcamera;\n>  class GeometryTest : public Test\n>  {\n>  protected:\n> -\tbool compare(const Size &lhs, const Size &rhs,\n> -\t\t     bool (*op)(const Size &lhs, const Size &rhs),\n> +\ttemplate<typename T = Size>\n\nI think you can drop = Size, the type will be deduced.\n\n> +\tbool compare(const T &lhs, const T &rhs,\n> +\t\t     bool (*op)(const T &lhs, const T &rhs),\n>  \t\t     const char *opName, bool expect)\n>  \t{\n>  \t\tbool result = op(lhs, rhs);\n>  \n>  \t\tif (result != expect) {\n> -\t\t\tcout << \"Size(\" << lhs.width << \", \" << lhs.height << \") \"\n> +\t\t\tcout << lhs.toString()\n>  \t\t\t     << opName << \" \"\n> -\t\t\t     << \"Size(\" << rhs.width << \", \" << rhs.height << \") \"\n> +\t\t\t     << rhs.toString()\n>  \t\t\t     << \"test failed\" << std::endl;\n>  \t\t\treturn false;\n>  \t\t}\n> @@ -36,6 +37,63 @@ protected:\n>  \n>  \tint run()\n>  \t{\n> +\t\t/*\n> +\t\t * Point tests\n> +\t\t */\n> +\n> +\t\t/* Equality */\n> +\t\tif (!compare(Point(50, 100), Point(50, 100), &operator==, \"==\", true))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tif (!compare(Point(-50, 100), Point(-50, 100), &operator==, \"==\", true))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tif (!compare(Point(50, -100), Point(50, -100), &operator==, \"==\", true))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tif (!compare(Point(-50, -100), Point(-50, -100), &operator==, \"==\", true))\n> +\t\t\treturn TestFail;\n> +\n> +\t\t/* Inequality */\n> +\t\tif (!compare(Point(50, 100), Point(50, 100), &operator!=, \"!=\", false))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tif (!compare(Point(-50, 100), Point(-50, 100), &operator!=, \"!=\", false))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tif (!compare(Point(50, -100), Point(50, -100), &operator!=, \"!=\", false))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tif (!compare(Point(-50, -100), Point(-50, -100), &operator!=, \"!=\", false))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tif (!compare(Point(-50, 100), Point(50, 100), &operator!=, \"!=\", true))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tif (!compare(Point(50, -100), Point(50, 100), &operator!=, \"!=\", true))\n> +\t\t\treturn TestFail;\n> +\n> +\t\tif (!compare(Point(-50, -100), Point(50, 100), &operator!=, \"!=\", true))\n> +\t\t\treturn TestFail;\n> +\n> +\t\t/* Negation */\n> +\t\tif (Point(50, 100) != -Point(-50, -100) ||\n> +\t\t    Point(50, 100) == -Point(50, -100) ||\n> +\t\t    Point(50, 100) == -Point(-50, 100)) {\n> +\t\t\tcout << \"Point negation test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Default constructor */\n> +\t\tif (Point() != Point(0, 0)) {\n> +\t\t\tcout << \"Default constructor test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/*\n> +\t\t * Size tests\n> +\t\t */\n> +\n>  \t\tif (!Size().isNull() || !Size(0, 0).isNull()) {\n>  \t\t\tcout << \"Null size incorrectly reported as not null\" << endl;\n>  \t\t\treturn TestFail;\n> @@ -109,6 +167,76 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>  \n> +\t\t/* Aspect ratio tests */\n> +\t\tif (Size(0, 0).boundedToAspectRatio(Size(4, 3)) != Size(0, 0) ||\n> +\t\t    Size(1920, 1440).boundedToAspectRatio(Size(16, 9)) != Size(1920, 1080) ||\n> +\t\t    Size(1920, 1440).boundedToAspectRatio(Size(65536, 36864)) != Size(1920, 1080) ||\n> +\t\t    Size(1440, 1920).boundedToAspectRatio(Size(9, 16)) != Size(1080, 1920) ||\n> +\t\t    Size(1920, 1080).boundedToAspectRatio(Size(4, 3)) != Size(1440, 1080) ||\n> +\t\t    Size(1920, 1080).boundedToAspectRatio(Size(65536, 49152)) != Size(1440, 1080) ||\n> +\t\t    Size(1024, 1024).boundedToAspectRatio(Size(1, 1)) != Size(1024, 1024) ||\n> +\t\t    Size(1920, 1080).boundedToAspectRatio(Size(16, 9)) != Size(1920, 1080) ||\n> +\t\t    Size(200, 100).boundedToAspectRatio(Size(16, 9)) != Size(177, 100) ||\n> +\t\t    Size(300, 200).boundedToAspectRatio(Size(16, 9)) != Size(300, 168)) {\n> +\t\t\tcout << \"Size::boundedToAspectRatio test failed\" << endl;\n\ns/Size::boundedToAspectRatio/Size::boundedToAspectRatio()/\n\nSame below.\n\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (Size(0, 0).expandedToAspectRatio(Size(4, 3)) != Size(0, 0) ||\n> +\t\t    Size(1920, 1440).expandedToAspectRatio(Size(16, 9)) != Size(2560, 1440) ||\n> +\t\t    Size(1920, 1440).expandedToAspectRatio(Size(65536, 36864)) != Size(2560, 1440) ||\n> +\t\t    Size(1440, 1920).expandedToAspectRatio(Size(9, 16)) != Size(1440, 2560) ||\n> +\t\t    Size(1920, 1080).expandedToAspectRatio(Size(4, 3)) != Size(1920, 1440) ||\n> +\n\nThis blank line car be dropped.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nI'll address these small issues when applying.\n\n> +\t\t    Size(1920, 1080).expandedToAspectRatio(Size(65536, 49152)) != Size(1920, 1440) ||\n> +\t\t    Size(1024, 1024).expandedToAspectRatio(Size(1, 1)) != Size(1024, 1024) ||\n> +\t\t    Size(1920, 1080).expandedToAspectRatio(Size(16, 9)) != Size(1920, 1080) ||\n> +\t\t    Size(200, 100).expandedToAspectRatio(Size(16, 9)) != Size(200, 112) ||\n> +\t\t    Size(300, 200).expandedToAspectRatio(Size(16, 9)) != Size(355, 200)) {\n> +\t\t\tcout << \"Size::expandedToAspectRatio test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Size::centeredTo tests */\n> +\t\tif (Size(0, 0).centeredTo(Point(50, 100)) != Rectangle(50, 100, 0, 0) ||\n> +\t\t    Size(0, 0).centeredTo(Point(-50, -100)) != Rectangle(-50, -100, 0, 0) ||\n> +\t\t    Size(100, 200).centeredTo(Point(50, 100)) != Rectangle(0, 0, 100, 200) ||\n> +\t\t    Size(100, 200).centeredTo(Point(-50, -100)) != Rectangle(-100, -200, 100, 200) ||\n> +\t\t    Size(101, 201).centeredTo(Point(-50, -100)) != Rectangle(-100, -200, 101, 201) ||\n> +\t\t    Size(101, 201).centeredTo(Point(-51, -101)) != Rectangle(-101, -201, 101, 201)) {\n> +\t\t\tcout << \"Size::centeredTo test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Scale a size by a float */\n> +\t\tif (Size(1000, 2000) * 2.0 != Size(2000, 4000) ||\n> +\t\t    Size(300, 100) * 0.5 != Size(150, 50) ||\n> +\t\t    Size(1, 2) * 1.6 != Size(1, 3)) {\n> +\t\t\tcout << \"Size::operator* failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (Size(1000, 2000) / 2.0 != Size(500, 1000) ||\n> +\t\t    Size(300, 100) / 0.5 != Size(600, 200) ||\n> +\t\t    Size(1000, 2000) / 3.0 != Size(333, 666)) {\n> +\t\t\tcout << \"Size::operator* failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\ts = Size(300, 100);\n> +\t\ts *= 0.3333;\n> +\t\tif (s != Size(99, 33)) {\n> +\t\t\tcout << \"Size::operator* test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\ts = Size(300, 100);\n> +\t\ts /= 3;\n> +\t\tif (s != Size(100, 33)) {\n> +\t\t\tcout << \"Size::operator* test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n>  \t\t/* Test Size equality and inequality. */\n>  \t\tif (!compare(Size(100, 100), Size(100, 100), &operator==, \"==\", true))\n>  \t\t\treturn TestFail;\n> @@ -182,6 +310,10 @@ protected:\n>  \t\tif (!compare(Size(200, 100), Size(100, 200), &operator>=, \">=\", true))\n>  \t\t\treturn TestFail;\n>  \n> +\t\t/*\n> +\t\t * Rectangle tests\n> +\t\t */\n> +\n>  \t\t/* Test Rectangle::isNull(). */\n>  \t\tif (!Rectangle(0, 0, 0, 0).isNull() ||\n>  \t\t    !Rectangle(1, 1, 0, 0).isNull()) {\n> @@ -196,6 +328,124 @@ protected:\n>  \t\t\treturn TestFail;\n>  \t\t}\n>  \n> +\t\t/* Rectangle::size, Rectangle::topLeft and Rectangle::center tests */\n> +\t\tif (Rectangle(-1, -2, 3, 4).size() != Size(3, 4) ||\n> +\t\t    Rectangle(0, 0, 100000, 200000).size() != Size(100000, 200000)) {\n> +\t\t\tcout << \"Rectangle::size test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (Rectangle(1, 2, 3, 4).topLeft() != Point(1, 2) ||\n> +\t\t    Rectangle(-1, -2, 3, 4).topLeft() != Point(-1, -2)) {\n> +\t\t\tcout << \"Rectangle::topLeft test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (Rectangle(0, 0, 300, 400).center() != Point(150, 200) ||\n> +\t\t    Rectangle(-1000, -2000, 300, 400).center() != Point(-850, -1800) ||\n> +\t\t    Rectangle(10, 20, 301, 401).center() != Point(160, 220) ||\n> +\t\t    Rectangle(11, 21, 301, 401).center() != Point(161, 221) ||\n> +\t\t    Rectangle(-1011, -2021, 301, 401).center() != Point(-861, -1821)) {\n> +\t\t\tcout << \"Rectangle::center test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Rectangle::boundedTo (intersection function) */\n> +\t\tif (Rectangle(0, 0, 1000, 2000).boundedTo(Rectangle(0, 0, 1000, 2000)) !=\n> +\t\t\t    Rectangle(0, 0, 1000, 2000) ||\n> +\t\t    Rectangle(-500, -1000, 1000, 2000).boundedTo(Rectangle(0, 0, 1000, 2000)) !=\n> +\t\t\t    Rectangle(0, 0, 500, 1000) ||\n> +\t\t    Rectangle(500, 1000, 1000, 2000).boundedTo(Rectangle(0, 0, 1000, 2000)) !=\n> +\t\t\t    Rectangle(500, 1000, 500, 1000) ||\n> +\t\t    Rectangle(300, 400, 50, 100).boundedTo(Rectangle(0, 0, 1000, 2000)) !=\n> +\t\t\t    Rectangle(300, 400, 50, 100) ||\n> +\t\t    Rectangle(0, 0, 1000, 2000).boundedTo(Rectangle(300, 400, 50, 100)) !=\n> +\t\t\t    Rectangle(300, 400, 50, 100) ||\n> +\t\t    Rectangle(0, 0, 100, 100).boundedTo(Rectangle(50, 100, 100, 100)) !=\n> +\t\t\t    Rectangle(50, 100, 50, 0) ||\n> +\t\t    Rectangle(0, 0, 100, 100).boundedTo(Rectangle(100, 50, 100, 100)) !=\n> +\t\t\t    Rectangle(100, 50, 0, 50) ||\n> +\t\t    Rectangle(-10, -20, 10, 20).boundedTo(Rectangle(10, 20, 100, 100)) !=\n> +\t\t\t    Rectangle(10, 20, 0, 0)) {\n> +\t\t\tcout << \"Rectangle::boundedTo test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Rectangle::enclosedIn tests */\n> +\t\tif (Rectangle(10, 20, 300, 400).enclosedIn(Rectangle(-10, -20, 1300, 1400)) !=\n> +\t\t\t    Rectangle(10, 20, 300, 400) ||\n> +\t\t    Rectangle(-100, -200, 3000, 4000).enclosedIn(Rectangle(-10, -20, 1300, 1400)) !=\n> +\t\t\t    Rectangle(-10, -20, 1300, 1400) ||\n> +\t\t    Rectangle(-100, -200, 300, 400).enclosedIn(Rectangle(-10, -20, 1300, 1400)) !=\n> +\t\t\t    Rectangle(-10, -20, 300, 400) ||\n> +\t\t    Rectangle(5100, 6200, 300, 400).enclosedIn(Rectangle(-10, -20, 1300, 1400)) !=\n> +\t\t\t    Rectangle(990, 980, 300, 400) ||\n> +\t\t    Rectangle(100, -300, 150, 200).enclosedIn(Rectangle(50, 0, 200, 300)) !=\n> +\t\t\t    Rectangle(100, 0, 150, 200) ||\n> +\t\t    Rectangle(100, -300, 150, 1200).enclosedIn(Rectangle(50, 0, 200, 300)) !=\n> +\t\t\t    Rectangle(100, 0, 150, 300) ||\n> +\t\t    Rectangle(-300, 100, 200, 150).enclosedIn(Rectangle(0, 50, 300, 200)) !=\n> +\t\t\t    Rectangle(0, 100, 200, 150) ||\n> +\t\t    Rectangle(-300, 100, 1200, 150).enclosedIn(Rectangle(0, 50, 300, 200)) !=\n> +\t\t\t    Rectangle(0, 100, 300, 150)) {\n> +\t\t\tcout << \"Rectangle::enclosedIn test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Rectange::scaledBy tests */\n> +\t\tif (Rectangle(10, 20, 300, 400).scaledBy(Size(0, 0), Size(1, 1)) !=\n> +\t\t\t    Rectangle(0, 0, 0, 0) ||\n> +\t\t    Rectangle(10, -20, 300, 400).scaledBy(Size(32768, 65536), Size(32768, 32768)) !=\n> +\t\t\t    Rectangle(10, -40, 300, 800) ||\n> +\t\t    Rectangle(-30000, 10000, 20000, 20000).scaledBy(Size(7, 7), Size(7, 7)) !=\n> +\t\t\t    Rectangle(-30000, 10000, 20000, 20000) ||\n> +\t\t    Rectangle(-20, -30, 320, 240).scaledBy(Size(1280, 960), Size(640, 480)) !=\n> +\t\t\t    Rectangle(-40, -60, 640, 480) ||\n> +\t\t    Rectangle(1, 1, 2026, 1510).scaledBy(Size(4056, 3024), Size(2028, 1512)) !=\n> +\t\t\t    Rectangle(2, 2, 4052, 3020)) {\n> +\t\t\tcout << \"Rectangle::scaledBy test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Rectangle::translatedBy tests */\n> +\t\tif (Rectangle(10, -20, 300, 400).translatedBy(Point(-30, 40)) !=\n> +\t\t\t    Rectangle(-20, 20, 300, 400) ||\n> +\t\t    Rectangle(-10, 20, 400, 300).translatedBy(Point(50, -60)) !=\n> +\t\t\t    Rectangle(40, -40, 400, 300)) {\n> +\t\t\tcout << \"Rectangle::translatedBy test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Rectangle::scaleBy tests */\n> +\t\tRectangle r(-20, -30, 320, 240);\n> +\t\tr.scaleBy(Size(1280, 960), Size(640, 480));\n> +\t\tif (r != Rectangle(-40, -60, 640, 480)) {\n> +\t\t\tcout << \"Rectangle::scaleBy test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tr = Rectangle(1, 1, 2026, 1510);\n> +\t\tr.scaleBy(Size(4056, 3024), Size(2028, 1512));\n> +\t\tif (r != Rectangle(2, 2, 4052, 3020)) {\n> +\t\t\tcout << \"Rectangle::scaleBy test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/* Rectangle::translateBy tests */\n> +\t\tr = Rectangle(10, -20, 300, 400);\n> +\t\tr.translateBy(Point(-30, 40));\n> +\t\tif (r != Rectangle(-20, 20, 300, 400)) {\n> +\t\t\tcout << \"Rectangle::translateBy test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tr = Rectangle(-10, 20, 400, 300);\n> +\t\tr.translateBy(Point(50, -60));\n> +\t\tif (r != Rectangle(40, -40, 400, 300)) {\n> +\t\t\tcout << \"Rectangle::translateBy test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n>  \t\treturn TestPass;\n>  \t}\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 7BE25BDB1E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 26 Oct 2020 23:29:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CE34F62064;\n\tTue, 27 Oct 2020 00:28:59 +0100 (CET)","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 BA02062061\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Oct 2020 00:28:57 +0100 (CET)","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 3BB3081;\n\tTue, 27 Oct 2020 00:28:57 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"iu7r3KFZ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1603754937;\n\tbh=yFBgZKDTWklrk6Xg72FGO6dSQuWrs/2LBAuJfLc+NkE=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=iu7r3KFZs73O9zpC/SbftQnDszc7oI8E0k1Lsy/0r7OIK5fVC1uPSOb4e+jMAIhXS\n\tnrTymNwMm7goORTsMYQsVhfMqr7GU700qDA+ZrgQ3JTI31HDcj5TM6YoflMZtGJqov\n\tJOqYof+moUIiZUXbKiDyI5YKRK0DzN90E8QcLXyc=","Date":"Tue, 27 Oct 2020 01:28:10 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"David Plowman <david.plowman@raspberrypi.com>","Message-ID":"<20201026232810.GK3756@pendragon.ideasonboard.com>","References":"<20201026171908.21463-1-david.plowman@raspberrypi.com>\n\t<20201026171908.21463-7-david.plowman@raspberrypi.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201026171908.21463-7-david.plowman@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v6 6/6] test: geometry: Add unit tests\n\tfor new geometry helper functions","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]