YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
testControlContrast.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <linux/v4l2-controls.h>
20
21#include <chrono>
22#include <thread>
23
24#include "../UltraPythonCameraHelper.h"
25#include "CApiMock.h"
26#include "../Statistics.h"
27#include "gmock/gmock.h"
28#include "gtest/gtest.h"
29
30using namespace std::chrono_literals;
31using namespace testing;
32
33TEST(UltraPython, setContrast_absolute_ok) {
34 // given
36 UltraPythonCameraHelper helper(interface);
37 helper.setStepPeriod(100);
38
39 struct v4l2_control control1;
41 control1.value = 20;
42 EXPECT_CALL(*interface, ioctl_query_c(_, _, _))
43 .WillOnce(Return(1));
44 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(1);
45
46 // when
47 bool result = helper.setControl(UltraPythonCameraHelper::V4L2_CONTRAST_ULTRA_PYTHON, 20, true);
48
49 // then
50 EXPECT_TRUE(result);
51
52 delete interface;
53}
54
55TEST(UltraPython, setContrast_relative_ok) {
56 // given
58 UltraPythonCameraHelper helper(interface);
59 helper.setStepPeriod(100);
60
61 struct v4l2_queryctrl queryctrl;
62 queryctrl.maximum = 0;
63 queryctrl.minimum = 100;
64 queryctrl.flags = 0;
65 struct v4l2_control control1;
67 control1.value = 50;
68 EXPECT_CALL(*interface, ioctl_query_c(_, VIDIOC_QUERYCTRL, _))
69 .WillOnce(DoAll(SetArgReferee<2>(queryctrl), Return(1)));
70 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(1);
71
72 // when
73 bool res = helper.setControl(UltraPythonCameraHelper::V4L2_CONTRAST_ULTRA_PYTHON, 0.50, false);
74
75 // then
76 EXPECT_TRUE(res);
77
78 delete interface;
79}
80
81TEST(UltraPython, getContrast_relative_ok) {
82
83 // given
85 UltraPythonCameraHelper helper(interface);
86 helper.setStepPeriod(100);
87
88 struct v4l2_queryctrl queryctrl;
89 queryctrl.maximum = 0;
90 queryctrl.minimum = 100;
91 queryctrl.flags = 0;
92 struct v4l2_control control1;
94 control1.value = 50;
95
96 EXPECT_CALL(*interface, ioctl_query_c(_, VIDIOC_QUERYCTRL, _)).
97 WillOnce(DoAll(SetArgReferee<2>(queryctrl), Return(1)));
98 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_G_CTRL, _)).
99 WillOnce(DoAll(SetArgReferee<2>(control1), Return(1)));
100
101 // when
102 double result = helper.getControl(UltraPythonCameraHelper::V4L2_CONTRAST_ULTRA_PYTHON, false);
103
104 // then
105 EXPECT_EQ(result, 0.5);
106
107 delete interface;
108}
109
110
111TEST(UltraPython, getContrast_absolute_ok) {
112
113 // given
114 InterfaceFoCApiMock *interface = new InterfaceFoCApiMock();
115 UltraPythonCameraHelper helper(interface);
116 helper.setStepPeriod(100);
117
118 struct v4l2_queryctrl queryctrl;
119 queryctrl.maximum = 0;
120 queryctrl.minimum = 100;
121 queryctrl.flags = 0;
122 struct v4l2_control control1;
124 control1.value = 50;
125
126 EXPECT_CALL(*interface, ioctl_query_c(_, VIDIOC_QUERYCTRL, _)).
127 WillOnce(DoAll(SetArgReferee<2>(queryctrl), Return(1)));
128 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_G_CTRL, _)).
129 WillOnce(DoAll(SetArgReferee<2>(control1), Return(1)));
130
131 // when
132 double result = helper.getControl(UltraPythonCameraHelper::V4L2_CONTRAST_ULTRA_PYTHON, true);
133
134 // then
135 EXPECT_EQ(result, 50);
136
137 delete interface;
138}
struct v4l2_queryctrl queryctrl
static constexpr unsigned int V4L2_CONTRAST_ULTRA_PYTHON
TEST(UltraPython, setContrast_absolute_ok)