new file mode 100644
@@ -0,0 +1,102 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * control_info.cpp - ControlInfoMap tests
+ */
+
+#include <iostream>
+
+#include <libcamera/camera.h>
+#include <libcamera/camera_manager.h>
+#include <libcamera/control_ids.h>
+#include <libcamera/controls.h>
+
+#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> camera_;
+};
+
+TEST_REGISTER(ControlInfoMapTest)
@@ -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' ],
Add a test to exercise the ControlInfoMap API. This currently tests at(), count(), find() and end(). Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- test/controls/control_info.cpp | 102 +++++++++++++++++++++++++++++++++ test/controls/meson.build | 1 + 2 files changed, 103 insertions(+) create mode 100644 test/controls/control_info.cpp