From patchwork Mon Apr 15 16:56:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 988 Return-Path: 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 EB32860DCC for ; Mon, 15 Apr 2019 18:57:16 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 81180B81 for ; Mon, 15 Apr 2019 18:57:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1555347436; bh=3xVTvaBVOA4Plyd3pIxARfd1JmMrOkx92cNZikTLFUg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FCDa2Lz0/QsSqTfwHd1OsFxlHaKCWIhVV7go/Prhl+0LSWNVNVviVDDiazaK0olYc 4N2T/HI/tEQM0v4UkRbs3a/cm0RLZeYydNIKI/2zHyXrGRfBPApDQLs/+cf6OIU5JC 9lcwYcnvp1p6mNOc3ZWDGJ0K8Fxn7cFClrjZU4/o= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 15 Apr 2019 19:56:56 +0300 Message-Id: <20190415165700.22970-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415165700.22970-1-laurent.pinchart@ideasonboard.com> References: <20190415165700.22970-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 07/11] test: geometry: Add tests for Size class comparison operators X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Apr 2019 16:57:17 -0000 Add a test that exercises all the comparison operators for the Size class. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- test/geometry.cpp | 125 ++++++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 1 + 2 files changed, 126 insertions(+) create mode 100644 test/geometry.cpp diff --git a/test/geometry.cpp b/test/geometry.cpp new file mode 100644 index 000000000000..7ba3f72ed71d --- /dev/null +++ b/test/geometry.cpp @@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * geometry.cpp - Geometry classes tests + */ + +#include + +#include + +#include "test.h" + +using namespace std; +using namespace libcamera; + +class GeometryTest : public Test +{ +protected: + int init() + { + return 0; + } + + bool compare(const Size &lhs, const Size &rhs, + bool (*op)(const Size &lhs, const Size &rhs), + const char *opName, bool expect) + { + bool result = op(lhs, rhs); + + if (result != expect) { + cout << "Size(" << lhs.width << ", " << lhs.height << ") " + << opName << " " + << "Size(" << rhs.width << ", " << rhs.height << ") " + << "test failed" << std::endl; + return false; + } + + return true; + } + + int run() + { + /* Test Size equality and inequality. */ + if (!compare(Size(100, 100), Size(100, 100), &operator==, "==", true)) + return TestFail; + if (!compare(Size(100, 100), Size(100, 100), &operator!=, "!=", false)) + return TestFail; + + if (!compare(Size(100, 100), Size(200, 100), &operator==, "==", false)) + return TestFail; + if (!compare(Size(100, 100), Size(200, 100), &operator!=, "!=", true)) + return TestFail; + + if (!compare(Size(100, 100), Size(100, 200), &operator==, "==", false)) + return TestFail; + if (!compare(Size(100, 100), Size(100, 200), &operator!=, "!=", true)) + return TestFail; + + /* Test Size ordering based on combined with and height. */ + if (!compare(Size(100, 100), Size(200, 200), &operator<, "<", true)) + return TestFail; + if (!compare(Size(100, 100), Size(200, 200), &operator<=, "<=", true)) + return TestFail; + if (!compare(Size(100, 100), Size(200, 200), &operator>, ">", false)) + return TestFail; + if (!compare(Size(100, 100), Size(200, 200), &operator>=, ">=", false)) + return TestFail; + + if (!compare(Size(200, 200), Size(100, 100), &operator<, "<", false)) + return TestFail; + if (!compare(Size(200, 200), Size(100, 100), &operator<=, "<=", false)) + return TestFail; + if (!compare(Size(200, 200), Size(100, 100), &operator>, ">", true)) + return TestFail; + if (!compare(Size(200, 200), Size(100, 100), &operator>=, ">=", true)) + return TestFail; + + /* Test Size ordering based on area (with overlapping sizes). */ + if (!compare(Size(200, 100), Size(100, 400), &operator<, "<", true)) + return TestFail; + if (!compare(Size(200, 100), Size(100, 400), &operator<=, "<=", true)) + return TestFail; + if (!compare(Size(200, 100), Size(100, 400), &operator>, ">", false)) + return TestFail; + if (!compare(Size(200, 100), Size(100, 400), &operator>=, ">=", false)) + return TestFail; + + if (!compare(Size(100, 400), Size(200, 100), &operator<, "<", false)) + return TestFail; + if (!compare(Size(100, 400), Size(200, 100), &operator<=, "<=", false)) + return TestFail; + if (!compare(Size(100, 400), Size(200, 100), &operator>, ">", true)) + return TestFail; + if (!compare(Size(100, 400), Size(200, 100), &operator>=, ">=", true)) + return TestFail; + + /* Test Size ordering based on width (with identical areas). */ + if (!compare(Size(100, 200), Size(200, 100), &operator<, "<", true)) + return TestFail; + if (!compare(Size(100, 200), Size(200, 100), &operator<=, "<=", true)) + return TestFail; + if (!compare(Size(100, 200), Size(200, 100), &operator>, ">", false)) + return TestFail; + if (!compare(Size(100, 200), Size(200, 100), &operator>=, ">=", false)) + return TestFail; + + if (!compare(Size(200, 100), Size(100, 200), &operator<, "<", false)) + return TestFail; + if (!compare(Size(200, 100), Size(100, 200), &operator<=, "<=", false)) + return TestFail; + if (!compare(Size(200, 100), Size(100, 200), &operator>, ">", true)) + return TestFail; + if (!compare(Size(200, 100), Size(100, 200), &operator>=, ">=", true)) + return TestFail; + + return TestPass; + } + + void cleanup() + { + } +}; + +TEST_REGISTER(GeometryTest) diff --git a/test/meson.build b/test/meson.build index 71a96921697c..d501f2beaf96 100644 --- a/test/meson.build +++ b/test/meson.build @@ -9,6 +9,7 @@ subdir('v4l2_subdevice') public_tests = [ ['event', 'event.cpp'], ['event-dispatcher', 'event-dispatcher.cpp'], + ['geometry', 'geometry.cpp'], ['list-cameras', 'list-cameras.cpp'], ['signal', 'signal.cpp'], ['timer', 'timer.cpp'],