summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2019-06-21 16:29:11 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-07-02 16:59:53 +0300
commit6481c71a618a7b6940cbe4269a33c24f33ddf6be (patch)
treee110abd97a5ab47f25d4bede7bb99ea0058aa765 /test
parent41c184afc3e9079d532e9fcd6a858e7961dbcf65 (diff)
libcamera: test: Add ControlList tests
Add tests of the ControlList infrastructure and public API. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'test')
-rw-r--r--test/controls/control_list.cpp213
-rw-r--r--test/controls/meson.build1
2 files changed, 214 insertions, 0 deletions
diff --git a/test/controls/control_list.cpp b/test/controls/control_list.cpp
new file mode 100644
index 00000000..c834edc3
--- /dev/null
+++ b/test/controls/control_list.cpp
@@ -0,0 +1,213 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * control_list.cpp - ControlList tests
+ */
+
+#include <iostream>
+
+#include <libcamera/camera.h>
+#include <libcamera/camera_manager.h>
+#include <libcamera/controls.h>
+
+#include "test.h"
+
+using namespace std;
+using namespace libcamera;
+
+class ControlListTest : public Test
+{
+protected:
+ int init()
+ {
+ cm_ = CameraManager::instance();
+
+ 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()
+ {
+ ControlList list(camera_.get());
+
+ /* Test that the list is initially empty. */
+ if (!list.empty()) {
+ cout << "List should to be empty" << endl;
+ return TestFail;
+ }
+
+ if (list.size() != 0) {
+ cout << "List should contain zero items" << endl;
+ return TestFail;
+ }
+
+ if (list.contains(Brightness)) {
+ cout << "List should not contain Brightness control" << endl;
+ return TestFail;
+ }
+
+ unsigned int count = 0;
+ for (auto iter = list.begin(); iter != list.end(); ++iter)
+ count++;
+
+ if (count != 0) {
+ cout << "List iteration should not produce any item" << endl;
+ return TestFail;
+ }
+
+ /*
+ * Set a control, and verify that the list now contains it, and
+ * nothing else.
+ */
+ list[Brightness] = 255;
+
+ if (list.empty()) {
+ cout << "List should not be empty" << endl;
+ return TestFail;
+ }
+
+ if (list.size() != 1) {
+ cout << "List should contain one item" << endl;
+ return TestFail;
+ }
+
+ if (!list.contains(Brightness)) {
+ cout << "List should contain Brightness control" << endl;
+ return TestFail;
+ }
+
+ count = 0;
+ for (auto iter = list.begin(); iter != list.end(); ++iter)
+ count++;
+
+ if (count != 1) {
+ cout << "List iteration should produce one item" << endl;
+ return TestFail;
+ }
+
+ if (list[Brightness].getInt() != 255) {
+ cout << "Incorrest Brightness control value" << endl;
+ return TestFail;
+ }
+
+ if (list.contains(Contrast)) {
+ cout << "List should not contain Contract control" << endl;
+ return TestFail;
+ }
+
+ /*
+ * Set a second control through ControlInfo and retrieve it
+ * through both controlId and ControlInfo.
+ */
+ const ControlInfoMap &controls = camera_->controls();
+ const ControlInfo *brightness = &controls.find(Brightness)->second;
+ const ControlInfo *contrast = &controls.find(Contrast)->second;
+
+ list[brightness] = 64;
+ list[contrast] = 128;
+
+ if (!list.contains(Contrast) || !list.contains(contrast)) {
+ cout << "List should contain Contrast control" << endl;
+ return TestFail;
+ }
+
+ /*
+ * Test control value retrieval and update through ControlInfo.
+ */
+ if (list[brightness].getInt() != 64 ||
+ list[contrast].getInt() != 128) {
+ cout << "Failed to retrieve control value" << endl;
+ return TestFail;
+ }
+
+ list[brightness] = 10;
+ list[contrast] = 20;
+
+ if (list[brightness].getInt() != 10 ||
+ list[contrast].getInt() != 20) {
+ cout << "Failed to update control value" << endl;
+ return TestFail;
+ }
+
+ /*
+ * Assert that the container has not grown with the control
+ * updated.
+ */
+ if (list.size() != 2) {
+ cout << "List should contain two elements" << endl;
+ return TestFail;
+ }
+
+ /*
+ * Test list merging. Create a new list, add two controls with
+ * one overlapping the existing list, merge the lists and clear
+ * the old list. Verify that the new list is empty and that the
+ * new list contains the expected items and values.
+ */
+ ControlList newList(camera_.get());
+
+ newList[Brightness] = 128;
+ newList[Saturation] = 255;
+ newList.update(list);
+
+ list.clear();
+
+ if (list.size() != 0) {
+ cout << "Old List should contain zero items" << endl;
+ return TestFail;
+ }
+
+ if (!list.empty()) {
+ cout << "Old List should be empty" << endl;
+ return TestFail;
+ }
+
+ if (newList.size() != 3) {
+ cout << "New list has incorrect size" << endl;
+ return TestFail;
+ }
+
+ if (!newList.contains(Brightness) ||
+ !newList.contains(Contrast) ||
+ !newList.contains(Saturation)) {
+ cout << "New list contains incorrect items" << endl;
+ return TestFail;
+ }
+
+ if (newList[Brightness].getInt() != 10 ||
+ newList[Contrast].getInt() != 20 ||
+ newList[Saturation].getInt() != 255) {
+ cout << "New list contains incorrect values" << endl;
+ return TestFail;
+ }
+
+ return TestPass;
+ }
+
+ void cleanup()
+ {
+ if (camera_) {
+ camera_->release();
+ camera_.reset();
+ }
+
+ cm_->stop();
+ }
+
+private:
+ CameraManager *cm_;
+ std::shared_ptr<Camera> camera_;
+};
+
+TEST_REGISTER(ControlListTest)
diff --git a/test/controls/meson.build b/test/controls/meson.build
index f8cda287..f4fc7b94 100644
--- a/test/controls/meson.build
+++ b/test/controls/meson.build
@@ -1,5 +1,6 @@
control_tests = [
[ 'control_info', 'control_info.cpp' ],
+ [ 'control_list', 'control_list.cpp' ],
[ 'control_value', 'control_value.cpp' ],
]