YARP
Yet Another Robot Platform
Loading...
Searching...
No Matches
testControlExposition.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
30
using namespace
std::chrono_literals;
31
using namespace
testing;
32
33
TEST
(UltraPython, setExposition_absolute_ok)
34
{
35
// given
36
InterfaceFoCApiMock
*
interface
= new
InterfaceFoCApiMock
();
37
UltraPythonCameraHelper
helper(interface);
38
helper.setStepPeriod(100);
39
40
struct
v4l2_control control1;
41
control1.id =
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
;
42
control1.value = 20;
43
EXPECT_CALL(*interface, ioctl_query_c(_, _, _)).WillOnce(Return(1));
44
EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(1);
45
46
// when
47
bool
res = helper.setControl(
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
, 20,
true
);
48
49
// then
50
EXPECT_TRUE(res);
51
52
delete
interface;
53
}
54
TEST
(UltraPython, setExposition_absolute_honoryes_ok)
55
{
56
// given
57
InterfaceFoCApiMock
*
interface
= new
InterfaceFoCApiMock
();
58
UltraPythonCameraHelper
helper(interface);
59
helper.setStepPeriod(90);
60
helper.setHonorFps(
true
);
61
62
struct
v4l2_control control1;
63
control1.id =
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
;
64
control1.value = 20;
65
EXPECT_CALL(*interface, ioctl_query_c(_, _, _)).WillOnce(Return(1));
66
EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(1);
67
68
// when
69
bool
res = helper.setControl(
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
, 20,
true
);
70
71
// then
72
EXPECT_TRUE(res);
73
74
delete
interface;
75
}
76
77
TEST
(UltraPython, setExposition_absolute_honoryes_ko)
78
{
79
// given
80
InterfaceFoCApiMock
*
interface
= new
InterfaceFoCApiMock
();
81
UltraPythonCameraHelper
helper(interface);
82
helper.setStepPeriod(20);
83
helper.setHonorFps(
true
);
84
85
struct
v4l2_control control1;
86
control1.id =
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
;
87
control1.value = 20;
88
EXPECT_CALL(*interface, ioctl_query_c(_, _, _)).WillOnce(Return(1));
89
EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(0);
90
91
// when
92
bool
res = helper.setControl(
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
, 20,
true
);
93
94
// then
95
EXPECT_FALSE(res);
96
97
delete
interface;
98
}
99
100
TEST
(UltraPython, setExposition_absolute_honorno_ok)
101
{
102
// given
103
InterfaceFoCApiMock
*
interface
= new
InterfaceFoCApiMock
();
104
UltraPythonCameraHelper
helper(interface);
105
helper.setStepPeriod(20);
106
helper.setHonorFps(
false
);
107
108
struct
v4l2_control control1;
109
control1.id =
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
;
110
control1.value = 20;
111
EXPECT_CALL(*interface, ioctl_query_c(_, _, _)).WillOnce(Return(1));
112
EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(1);
113
114
// when
115
bool
res = helper.setControl(
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
, 20,
true
);
116
117
// then
118
EXPECT_TRUE(res);
119
120
delete
interface;
121
}
122
123
TEST
(UltraPython, setExposition_absolute_negative)
124
{
125
// given
126
InterfaceFoCApiMock
*
interface
= new
InterfaceFoCApiMock
();
127
UltraPythonCameraHelper
helper(interface);
128
helper.setStepPeriod(100);
129
130
struct
v4l2_control control1;
131
control1.id =
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
;
132
control1.value = -20;
133
EXPECT_CALL(*interface, ioctl_query_c(_, _, _)).Times(0);
134
EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(0);
135
136
// when
137
bool
res = helper.setControl(
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
, -20,
true
);
138
139
// then
140
EXPECT_FALSE(res);
141
142
delete
interface;
143
}
144
145
TEST
(UltraPython, setExposition_normalized_ok)
146
{
147
// given
148
InterfaceFoCApiMock
*
interface
= new
InterfaceFoCApiMock
();
149
UltraPythonCameraHelper
helper(interface);
150
helper.setStepPeriod(100);
151
152
struct
v4l2_control control1;
153
control1.id =
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
;
154
control1.value = 57;
155
EXPECT_CALL(*interface, ioctl_query_c(_, _, _)).WillOnce(Return(1));
156
EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(1);
157
158
// when
159
bool
res = helper.setControl(
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
, 0.5,
false
);
160
161
// then
162
EXPECT_TRUE(res);
163
164
delete
interface;
165
}
166
167
TEST
(UltraPython, setExposition_normalized_honoryes_ok)
168
{
169
// given
170
InterfaceFoCApiMock
*
interface
= new
InterfaceFoCApiMock
();
171
UltraPythonCameraHelper
helper(interface);
172
helper.setStepPeriod(90);
173
helper.setHonorFps(
true
);
174
175
struct
v4l2_control control1;
176
control1.id =
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
;
177
control1.value = 57;
178
EXPECT_CALL(*interface, ioctl_query_c(_, _, _)).WillOnce(Return(1));
179
EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(1);
180
181
// when
182
bool
res = helper.setControl(
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
, 0.5,
false
);
183
184
// then
185
EXPECT_TRUE(res);
186
187
delete
interface;
188
}
189
190
TEST
(UltraPython, setExposition_normalized_honoryes_k0)
191
{
192
// given
193
InterfaceFoCApiMock
*
interface
= new
InterfaceFoCApiMock
();
194
UltraPythonCameraHelper
helper(interface);
195
helper.setStepPeriod(30);
196
helper.setHonorFps(
true
);
197
198
struct
v4l2_control control1;
199
control1.id =
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
;
200
control1.value = 57;
201
EXPECT_CALL(*interface, ioctl_query_c(_, _, _)).WillOnce(Return(1));
202
EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(0);
203
204
// when
205
bool
res = helper.setControl(
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
, 0.5,
false
);
206
207
// then
208
EXPECT_FALSE(res);
209
210
delete
interface;
211
}
212
213
TEST
(UltraPython, setExposition_normalized_negative)
214
{
215
// given
216
InterfaceFoCApiMock
*
interface
= new
InterfaceFoCApiMock
();
217
UltraPythonCameraHelper
helper(interface);
218
helper.setStepPeriod(100);
219
220
struct
v4l2_control control1;
221
control1.id =
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
;
222
control1.value = -57;
223
EXPECT_CALL(*interface, ioctl_query_c(_, _, _)).Times(0);
224
EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(0);
225
226
// when
227
bool
res = helper.setControl(
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
, -0.5,
false
);
228
229
// then
230
EXPECT_FALSE(res);
231
232
delete
interface;
233
}
CApiMock.h
InterfaceFoCApiMock
Definition
CApiMock.h:35
UltraPythonCameraHelper
Definition
UltraPythonCameraHelper.h:55
UltraPythonCameraHelper::V4L2_EXPOSURE_ULTRA_PYTHON
static constexpr unsigned int V4L2_EXPOSURE_ULTRA_PYTHON
Definition
UltraPythonCameraHelper.h:61
TEST
TEST(UltraPython, setExposition_absolute_ok)
Definition
testControlExposition.cpp:33
YARP
3.11.100+20250603.4+gitaa77f8b5c
opt-modules
yarp-device-ultrapython
src
devices
ultrapython
unittest
testControlExposition.cpp
Generated on Wed Jun 4 2025 02:39:55 for YARP by
1.9.8