libcamera/test/controls/control_list.cpp
Laurent Pinchart 626172a16b libcamera: Drop file name from header comment blocks
Source files in libcamera start by a comment block header, which
includes the file name and a one-line description of the file contents.
While the latter is useful to get a quick overview of the file contents
at a glance, the former is mostly a source of inconvenience. The name in
the comments can easily get out of sync with the file name when files
are renamed, and copy & paste during development have often lead to
incorrect names being used to start with.

Readers of the source code are expected to know which file they're
looking it. Drop the file name from the header comment block.

The change was generated with the following script:

----------------------------------------

dirs="include/libcamera src test utils"

declare -rA patterns=(
	['c']=' \* '
	['cpp']=' \* '
	['h']=' \* '
	['py']='# '
	['sh']='# '
)

for ext in ${!patterns[@]} ; do
	files=$(for dir in $dirs ; do find $dir -name "*.${ext}" ; done)
	pattern=${patterns[${ext}]}

	for file in $files ; do
		name=$(basename ${file})
		sed -i "s/^\(${pattern}\)${name} - /\1/" "$file"
	done
done
----------------------------------------

This misses several files that are out of sync with the comment block
header. Those will be addressed separately and manually.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
2024-05-08 22:39:50 +03:00

253 lines
6 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* ControlList tests
*/
#include <iostream>
#include <libcamera/camera.h>
#include <libcamera/camera_manager.h>
#include <libcamera/control_ids.h>
#include <libcamera/controls.h>
#include "libcamera/internal/camera_controls.h"
#include "camera_test.h"
#include "test.h"
using namespace std;
using namespace libcamera;
class ControlListTest : public CameraTest, public Test
{
public:
ControlListTest()
: CameraTest("platform/vimc.0 Sensor B")
{
}
protected:
int init() override
{
return status_;
}
int run() override
{
CameraControlValidator validator(camera_.get());
ControlList list(controls::controls, &validator);
/* 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.get(controls::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.set(controls::Brightness, -0.5f);
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.get(controls::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.get(controls::Brightness) != -0.5f) {
cout << "Incorrest Brightness control value" << endl;
return TestFail;
}
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, 0.0f);
list.set(controls::Contrast, 1.5f);
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) != 0.0f ||
list.get(controls::Contrast) != 1.5f) {
cout << "Failed to retrieve control value" << endl;
return TestFail;
}
/*
* Update both controls and verify that the container doesn't
* grow.
*/
list.set(controls::Brightness, 0.5f);
list.set(controls::Contrast, 1.1f);
if (list.get(controls::Brightness) != 0.5f ||
list.get(controls::Contrast) != 1.1f) {
cout << "Failed to update control value" << endl;
return TestFail;
}
if (list.size() != 2) {
cout << "List should contain two elements" << endl;
return TestFail;
}
/*
* Attempt to set an invalid control and verify that the
* operation failed.
*/
list.set(controls::AwbEnable, true);
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;
}
};
TEST_REGISTER(ControlListTest)