summaryrefslogtreecommitdiff
path: root/src/apps/lc-compliance/tests/controls_test.cpp
blob: e9bdf6fdb7e3561abd9844c830178af57151ce29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2023, Ideas On Board Oy
 *
 * controls_test.cpp - Test controls and properties
 */

#include <array>
#include <iostream>

#include <libcamera/control_ids.h>
#include <libcamera/controls.h>
#include <libcamera/property_ids.h>

#include <gtest/gtest.h>

#include "environment.h"

using namespace libcamera;

std::array<const ControlIdMap *, 2> controlMaps = {
	&controls::controls,
	&properties::properties,
};

class ControlTest : public testing::TestWithParam<const ControlIdMap *>
{
public:
	static std::string nameParameters(const testing::TestParamInfo<ControlTest::ParamType> &info);

protected:
	void SetUp() override;
	void TearDown() override;

	std::shared_ptr<Camera> camera_;
};

void ControlTest::SetUp()
{
	Environment *env = Environment::get();

	camera_ = env->cm()->get(env->cameraId());

	ASSERT_EQ(camera_->acquire(), 0);
}

void ControlTest::TearDown()
{
	if (!camera_)
		return;

	camera_->release();
	camera_.reset();
}

std::string ControlTest::nameParameters(const testing::TestParamInfo<ControlTest::ParamType> &info)
{
	const ControlIdMap *idMap = info.param;
	if (idMap == &controls::controls)
		return "controls";
	else if (idMap == &properties::properties)
		return "properties";

	return "vendor";
}

/* Test that mandatory controls and properties are supported by a camera. */
TEST_P(ControlTest, RequiredControls)
{
	auto controlMap = GetParam();

	for (const auto &[id, ctrl] : *controlMap) {
		if (!ctrl->required())
			continue;

		if (controlMap == &controls::controls) {
			const auto it = camera_->controls().find(ctrl);

			if (it == camera_->controls().end())
				FAIL() << "Mandatory control \"" << ctrl->name()
				       << "\" not supported" << std::endl;
		} else if (controlMap == &properties::properties) {
			bool found = camera_->properties().contains(id);

			if (!found)
				FAIL() << "Mandatory property \"" << ctrl->name()
				       << "\" not supported" << std::endl;
		}
	}
}

/*
 * Use a Value-Parametrized Test case so that vendors can easily test vendor
 * control lists by expading 'controlMaps'.
 */
INSTANTIATE_TEST_SUITE_P(ControlsTest, ControlTest,
			 testing::ValuesIn(controlMaps),
			 ControlTest::nameParameters);