[PATCH] test: controls: control_info: Add test for enum controls

Paul Elder paul.elder at ideasonboard.com
Tue Sep 10 15:31:30 CEST 2024


Add a test for enum controls to test that the ranges and values are set
properly.

Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
---
 test/controls/control_info.cpp | 39 ++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/test/controls/control_info.cpp b/test/controls/control_info.cpp
index e1bb43f0e..460aaa345 100644
--- a/test/controls/control_info.cpp
+++ b/test/controls/control_info.cpp
@@ -6,6 +6,7 @@
  */
 
 #include <iostream>
+#include <vector>
 
 #include <libcamera/control_ids.h>
 #include <libcamera/controls.h>
@@ -79,6 +80,44 @@ protected:
 			return TestFail;
 		}
 
+		/*
+		 * Test information retrieval from an enum control.
+		 */
+		ControlInfo awbMode(static_cast<int32_t>(controls::AwbTungsten),
+				    static_cast<int32_t>(controls::AwbDaylight));
+		if (awbMode.min().get<int32_t>() != controls::AwbTungsten ||
+		    awbMode.max().get<int32_t>() != controls::AwbDaylight) {
+			cout << "Invalid control range for AwbMode" << endl;
+			return TestFail;
+		}
+
+		std::vector<ControlValue> modes = {
+			static_cast<int32_t>(controls::AwbTungsten),
+			static_cast<int32_t>(controls::AwbFluorescent),
+			static_cast<int32_t>(controls::AwbDaylight),
+		};
+		ControlInfo awbModes(Span<const ControlValue>{ modes });
+
+		if (awbModes.min() != modes.front() ||
+		    awbModes.def() != modes.front() ||
+		    awbModes.max() != modes.back()) {
+			cout << "Invalid control range for AwbModes" << endl;
+			return TestFail;
+		}
+
+		if (awbModes.values().size() != modes.size()) {
+			cout << "Invalid size for AwbModes" << endl;
+			return TestFail;
+		}
+
+		unsigned int i = 0;
+		for (const auto &value : awbModes.values()) {
+			if (value != modes.at(i++)) {
+				cout << "Invalid control values for AwbModes" << endl;
+				return TestFail;
+			}
+		}
+
 		return TestPass;
 	}
 };
-- 
2.39.2



More information about the libcamera-devel mailing list