From patchwork Fri Oct 25 21:32:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2223 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 8878761375 for ; Fri, 25 Oct 2019 23:33:07 +0200 (CEST) Received: from pendragon.ideasonboard.com (143.121.2.93.rev.sfr.net [93.2.121.143]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0AF7C813 for ; Fri, 25 Oct 2019 23:33:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1572039187; bh=aJCNH2u5jO0bFjeNJYWHSM24201u2AkbphOSMmt40Ss=; h=From:To:Subject:Date:From; b=O/+hajqgJ7CDRExF2bZjzZnt9/AoyyJS+uREEh+BG9YwbzAWV8j18EeYgqvING4j6 vbv3d5/iq1MtXFFbEgr19msd9GS5HV2mrjtwTVScLKCnHsdagzMJZ681Y1FYnRqrA2 F5tEOfyTxKVGUxn2KXhoJrjVt/Gbsrc20lxAFVLk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 26 Oct 2019 00:32:54 +0300 Message-Id: <20191025213255.2751-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] test: controls: Add ControlInfoMap test X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Oct 2019 21:33:07 -0000 Add a test to exercise the ControlInfoMap API. This currently tests at(), count(), find() and end(). Signed-off-by: Laurent Pinchart --- test/controls/control_info.cpp | 102 +++++++++++++++++++++++++++++++++ test/controls/meson.build | 1 + 2 files changed, 103 insertions(+) create mode 100644 test/controls/control_info.cpp diff --git a/test/controls/control_info.cpp b/test/controls/control_info.cpp new file mode 100644 index 000000000000..f5ba1caec7bf --- /dev/null +++ b/test/controls/control_info.cpp @@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * control_info.cpp - ControlInfoMap tests + */ + +#include + +#include +#include +#include +#include + +#include "camera_controls.h" +#include "test.h" + +using namespace std; +using namespace libcamera; + +class ControlInfoMapTest : public Test +{ +protected: + int init() + { + cm_ = new CameraManager(); + + if (cm_->start()) { + cout << "Failed to start camera manager" << endl; + return TestFail; + } + + camera_ = cm_->get("VIMC Sensor B"); + if (!camera_) { + cout << "Can not find VIMC camera" << endl; + return TestSkip; + } + + return TestPass; + } + + int run() + { + const ControlInfoMap &info = camera_->controls(); + + /* Test looking up a valid control by ControlId. */ + if (info.count(&controls::Brightness) != 1) { + cout << "count() on valid control failed" << endl; + return TestFail; + } + + if (info.find(&controls::Brightness) == info.end()) { + cout << "find() on valid control failed" << endl; + return TestFail; + } + + info.at(&controls::Brightness); + + /* Test looking up a valid control by numerical ID. */ + if (info.count(controls::Brightness.id()) != 1) { + cout << "count() on valid ID failed" << endl; + return TestFail; + } + + if (info.find(controls::Brightness.id()) == info.end()) { + cout << "find() on valid ID failed" << endl; + return TestFail; + } + + info.at(controls::Brightness.id()); + + /* Test looking up an invalid control by numerical ID. */ + if (info.count(12345) != 0) { + cout << "count() on invalid ID failed" << endl; + return TestFail; + } + + if (info.find(12345) != info.end()) { + cout << "find() on invalid ID failed" << endl; + return TestFail; + } + + return TestPass; + } + + void cleanup() + { + if (camera_) { + camera_->release(); + camera_.reset(); + } + + cm_->stop(); + delete cm_; + } + +private: + CameraManager *cm_; + std::shared_ptr camera_; +}; + +TEST_REGISTER(ControlInfoMapTest) diff --git a/test/controls/meson.build b/test/controls/meson.build index 9f0f005a2759..f0850df28c8a 100644 --- a/test/controls/meson.build +++ b/test/controls/meson.build @@ -1,4 +1,5 @@ control_tests = [ + [ 'control_info', 'control_info.cpp' ], [ 'control_list', 'control_list.cpp' ], [ 'control_range', 'control_range.cpp' ], [ 'control_value', 'control_value.cpp' ],