diff options
Diffstat (limited to 'test/controls')
-rw-r--r-- | test/controls/control_info.cpp | 45 | ||||
-rw-r--r-- | test/controls/control_info_map.cpp | 13 | ||||
-rw-r--r-- | test/controls/control_list.cpp | 137 | ||||
-rw-r--r-- | test/controls/control_value.cpp | 82 | ||||
-rw-r--r-- | test/controls/meson.build | 18 |
5 files changed, 258 insertions, 37 deletions
diff --git a/test/controls/control_info.cpp b/test/controls/control_info.cpp index 1e05e131..e1bb43f0 100644 --- a/test/controls/control_info.cpp +++ b/test/controls/control_info.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2019, Google Inc. * - * control_info.cpp - ControlInfo tests + * ControlInfo tests */ #include <iostream> @@ -26,24 +26,59 @@ protected: */ ControlInfo brightness; - if (brightness.min().get<int32_t>() != 0 || - brightness.max().get<int32_t>() != 0) { + if (brightness.min().type() != ControlType::ControlTypeNone || + brightness.max().type() != ControlType::ControlTypeNone || + brightness.def().type() != ControlType::ControlTypeNone) { cout << "Invalid control range for Brightness" << endl; return TestFail; } /* * Test information retrieval from a control with a minimum and - * a maximum value. + * a maximum value, and an implicit default value. */ ControlInfo contrast(10, 200); if (contrast.min().get<int32_t>() != 10 || - contrast.max().get<int32_t>() != 200) { + contrast.max().get<int32_t>() != 200 || + !contrast.def().isNone()) { cout << "Invalid control range for Contrast" << endl; return TestFail; } + /* + * Test information retrieval from a control with boolean + * values. + */ + ControlInfo aeEnable({ false, true }, false); + + if (aeEnable.min().get<bool>() != false || + aeEnable.def().get<bool>() != false || + aeEnable.max().get<bool>() != true) { + cout << "Invalid control range for AeEnable" << endl; + return TestFail; + } + + if (aeEnable.values()[0].get<bool>() != false || + aeEnable.values()[1].get<bool>() != true) { + cout << "Invalid control values for AeEnable" << endl; + return TestFail; + } + + ControlInfo awbEnable(true); + + if (awbEnable.min().get<bool>() != true || + awbEnable.def().get<bool>() != true || + awbEnable.max().get<bool>() != true) { + cout << "Invalid control range for AwbEnable" << endl; + return TestFail; + } + + if (awbEnable.values()[0].get<bool>() != true) { + cout << "Invalid control values for AwbEnable" << endl; + return TestFail; + } + return TestPass; } }; diff --git a/test/controls/control_info_map.cpp b/test/controls/control_info_map.cpp index eeb702db..b0be14b5 100644 --- a/test/controls/control_info_map.cpp +++ b/test/controls/control_info_map.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2019, Google Inc. * - * control_info.cpp - ControlInfoMap tests + * ControlInfoMap tests */ #include <iostream> @@ -12,7 +12,7 @@ #include <libcamera/control_ids.h> #include <libcamera/controls.h> -#include "camera_controls.h" +#include "libcamera/internal/camera_controls.h" #include "camera_test.h" #include "test.h" @@ -24,7 +24,7 @@ class ControlInfoMapTest : public CameraTest, public Test { public: ControlInfoMapTest() - : CameraTest("VIMC Sensor B") + : CameraTest("platform/vimc.0 Sensor B") { } @@ -75,6 +75,13 @@ protected: return TestFail; } + /* Test looking up a control on a default-constructed infoMap */ + const ControlInfoMap emptyInfoMap; + if (emptyInfoMap.find(12345) != emptyInfoMap.end()) { + cerr << "find() on empty ControlInfoMap failed" << endl; + return TestFail; + } + return TestPass; } }; diff --git a/test/controls/control_list.cpp b/test/controls/control_list.cpp index 5374c6f9..e27325c3 100644 --- a/test/controls/control_list.cpp +++ b/test/controls/control_list.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2019, Google Inc. * - * control_list.cpp - ControlList tests + * ControlList tests */ #include <iostream> @@ -12,7 +12,7 @@ #include <libcamera/control_ids.h> #include <libcamera/controls.h> -#include "camera_controls.h" +#include "libcamera/internal/camera_controls.h" #include "camera_test.h" #include "test.h" @@ -24,7 +24,7 @@ class ControlListTest : public CameraTest, public Test { public: ControlListTest() - : CameraTest("VIMC Sensor B") + : CameraTest("platform/vimc.0 Sensor B") { } @@ -50,7 +50,7 @@ protected: return TestFail; } - if (list.contains(controls::Brightness)) { + if (list.get(controls::Brightness)) { cout << "List should not contain Brightness control" << endl; return TestFail; } @@ -68,7 +68,7 @@ protected: * Set a control, and verify that the list now contains it, and * nothing else. */ - list.set(controls::Brightness, 255); + list.set(controls::Brightness, -0.5f); if (list.empty()) { cout << "List should not be empty" << endl; @@ -80,7 +80,7 @@ protected: return TestFail; } - if (!list.contains(controls::Brightness)) { + if (!list.get(controls::Brightness)) { cout << "List should contain Brightness control" << endl; return TestFail; } @@ -94,28 +94,29 @@ protected: return TestFail; } - if (list.get(controls::Brightness) != 255) { + if (list.get(controls::Brightness) != -0.5f) { cout << "Incorrest Brightness control value" << endl; return TestFail; } - if (list.contains(controls::Contrast)) { + if (list.get(controls::Contrast)) { cout << "List should not contain Contract control" << endl; return TestFail; } /* Update the first control and set a second one. */ - list.set(controls::Brightness, 64); - list.set(controls::Contrast, 128); + list.set(controls::Brightness, 0.0f); + list.set(controls::Contrast, 1.5f); - if (!list.contains(controls::Contrast) || - !list.contains(controls::Contrast)) { - cout << "List should contain Contrast control" << endl; + if (!list.get(controls::Brightness) || + !list.get(controls::Contrast)) { + cout << "List should contain Brightness and Contrast controls" + << endl; return TestFail; } - if (list.get(controls::Brightness) != 64 || - list.get(controls::Contrast) != 128) { + if (list.get(controls::Brightness) != 0.0f || + list.get(controls::Contrast) != 1.5f) { cout << "Failed to retrieve control value" << endl; return TestFail; } @@ -124,11 +125,11 @@ protected: * Update both controls and verify that the container doesn't * grow. */ - list.set(controls::Brightness, 10); - list.set(controls::Contrast, 20); + list.set(controls::Brightness, 0.5f); + list.set(controls::Contrast, 1.1f); - if (list.get(controls::Brightness) != 10 || - list.get(controls::Contrast) != 20) { + if (list.get(controls::Brightness) != 0.5f || + list.get(controls::Contrast) != 1.1f) { cout << "Failed to update control value" << endl; return TestFail; } @@ -144,11 +145,107 @@ protected: */ list.set(controls::AwbEnable, true); - if (list.contains(controls::AwbEnable)) { + if (list.get(controls::AwbEnable)) { cout << "List shouldn't contain AwbEnable control" << endl; return TestFail; } + /* + * Create a new list with a new control and merge it with the + * existing one, verifying that the existing controls + * values don't get overwritten. + */ + ControlList mergeList(controls::controls, &validator); + mergeList.set(controls::Brightness, 0.7f); + mergeList.set(controls::Saturation, 0.4f); + + mergeList.merge(list); + if (mergeList.size() != 3) { + cout << "Merged list should contain three elements" << endl; + return TestFail; + } + + if (list.size() != 2) { + cout << "The list to merge should contain two elements" + << endl; + return TestFail; + } + + if (!mergeList.get(controls::Brightness) || + !mergeList.get(controls::Contrast) || + !mergeList.get(controls::Saturation)) { + cout << "Merged list does not contain all controls" << endl; + return TestFail; + } + + if (mergeList.get(controls::Brightness) != 0.7f) { + cout << "Brightness control value changed after merging lists" + << endl; + return TestFail; + } + + if (mergeList.get(controls::Contrast) != 1.1f) { + cout << "Contrast control value changed after merging lists" + << endl; + return TestFail; + } + + if (mergeList.get(controls::Saturation) != 0.4f) { + cout << "Saturation control value changed after merging lists" + << endl; + return TestFail; + } + + /* + * Create two lists with overlapping controls. Merge them with + * overwriteExisting = true, verifying that the existing control + * values *get* overwritten. + */ + mergeList.clear(); + mergeList.set(controls::Brightness, 0.7f); + mergeList.set(controls::Saturation, 0.4f); + + list.clear(); + list.set(controls::Brightness, 0.5f); + list.set(controls::Contrast, 1.1f); + + mergeList.merge(list, ControlList::MergePolicy::OverwriteExisting); + if (mergeList.size() != 3) { + cout << "Merged list should contain three elements" << endl; + return TestFail; + } + + if (list.size() != 2) { + cout << "The list to merge should contain two elements" + << endl; + return TestFail; + } + + if (!mergeList.get(controls::Brightness) || + !mergeList.get(controls::Contrast) || + !mergeList.get(controls::Saturation)) { + cout << "Merged list does not contain all controls" << endl; + return TestFail; + } + + if (mergeList.get(controls::Brightness) != 0.5f) { + cout << "Brightness control value did not change after merging lists" + << endl; + return TestFail; + } + + if (mergeList.get(controls::Contrast) != 1.1f) { + cout << "Contrast control value changed after merging lists" + << endl; + return TestFail; + } + + if (mergeList.get(controls::Saturation) != 0.4f) { + cout << "Saturation control value changed after merging lists" + << endl; + return TestFail; + } + return TestPass; } }; diff --git a/test/controls/control_value.cpp b/test/controls/control_value.cpp index ad8e05d0..5084fd0c 100644 --- a/test/controls/control_value.cpp +++ b/test/controls/control_value.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2019, Google Inc. * - * control_value.cpp - ControlValue tests + * ControlValue tests */ #include <algorithm> @@ -110,6 +110,86 @@ protected: } /* + * Unsigned Integer16 type. + */ + value.set(static_cast<uint16_t>(42)); + if (value.isNone() || value.isArray() || + value.type() != ControlTypeUnsigned16) { + cerr << "Control type mismatch after setting to uint16_t" << endl; + return TestFail; + } + + if (value.get<uint16_t>() != 42) { + cerr << "Control value mismatch after setting to uint16_t" << endl; + return TestFail; + } + + if (value.toString() != "42") { + cerr << "Control string mismatch after setting to uint16_t" << endl; + return TestFail; + } + + std::array<uint16_t, 4> uint16s{ 3, 14, 15, 9 }; + value.set(Span<uint16_t>(uint16s)); + if (value.isNone() || !value.isArray() || + value.type() != ControlTypeUnsigned16) { + cerr << "Control type mismatch after setting to uint16_t array" << endl; + return TestFail; + } + + Span<const uint16_t> uint16sResult = value.get<Span<const uint16_t>>(); + if (uint16s.size() != uint16sResult.size() || + !std::equal(uint16s.begin(), uint16s.end(), uint16sResult.begin())) { + cerr << "Control value mismatch after setting to uint16_t array" << endl; + return TestFail; + } + + if (value.toString() != "[ 3, 14, 15, 9 ]") { + cerr << "Control string mismatch after setting to uint16_t array" << endl; + return TestFail; + } + + /* + * Unsigned Integer32 type. + */ + value.set(static_cast<uint32_t>(42)); + if (value.isNone() || value.isArray() || + value.type() != ControlTypeUnsigned32) { + cerr << "Control type mismatch after setting to uint32_t" << endl; + return TestFail; + } + + if (value.get<uint32_t>() != 42) { + cerr << "Control value mismatch after setting to uint32_t" << endl; + return TestFail; + } + + if (value.toString() != "42") { + cerr << "Control string mismatch after setting to uint32_t" << endl; + return TestFail; + } + + std::array<uint32_t, 4> uint32s{ 3, 14, 15, 9 }; + value.set(Span<uint32_t>(uint32s)); + if (value.isNone() || !value.isArray() || + value.type() != ControlTypeUnsigned32) { + cerr << "Control type mismatch after setting to uint32_t array" << endl; + return TestFail; + } + + Span<const uint32_t> uint32sResult = value.get<Span<const uint32_t>>(); + if (uint32s.size() != uint32sResult.size() || + !std::equal(uint32s.begin(), uint32s.end(), uint32sResult.begin())) { + cerr << "Control value mismatch after setting to uint32_t array" << endl; + return TestFail; + } + + if (value.toString() != "[ 3, 14, 15, 9 ]") { + cerr << "Control string mismatch after setting to uint32_t array" << endl; + return TestFail; + } + + /* * Integer32 type. */ value.set(0x42000000); diff --git a/test/controls/meson.build b/test/controls/meson.build index 7fff2413..763f8905 100644 --- a/test/controls/meson.build +++ b/test/controls/meson.build @@ -1,14 +1,16 @@ +# SPDX-License-Identifier: CC0-1.0 + control_tests = [ - [ 'control_info', 'control_info.cpp' ], - [ 'control_info_map', 'control_info_map.cpp' ], - [ 'control_list', 'control_list.cpp' ], - [ 'control_value', 'control_value.cpp' ], + {'name': 'control_info', 'sources': ['control_info.cpp']}, + {'name': 'control_info_map', 'sources': ['control_info_map.cpp']}, + {'name': 'control_list', 'sources': ['control_list.cpp']}, + {'name': 'control_value', 'sources': ['control_value.cpp']}, ] -foreach t : control_tests - exe = executable(t[0], t[1], - dependencies : libcamera_dep, +foreach test : control_tests + exe = executable(test['name'], test['sources'], + dependencies : libcamera_public, link_with : test_libraries, include_directories : test_includes_internal) - test(t[0], exe, suite : 'controls', is_parallel : false) + test(test['name'], exe, suite : 'controls', is_parallel : false) endforeach |