YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
testControlGain.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 "../UltraPythonCameraHelper.h"
20#include "CApiMock.h"
21#include "../Statistics.h"
22#include "gmock/gmock.h"
23#include "gtest/gtest.h"
24
25#include <chrono>
26#include <linux/v4l2-controls.h>
27#include <thread>
28
29using namespace std::chrono_literals;
30using namespace testing;
31
32TEST(UltraPython, setGainAbsolute_value1_ok) {
33 // given
35 UltraPythonCameraHelper helper(interface);
36
37 struct v4l2_control control1;
38 control1.id = V4L2_CID_GAIN;
39 control1.value = 1;
40 struct v4l2_control control2;
41 control2.id = 0x009e0903;
42 control2.value = 1;
43 EXPECT_CALL(*interface, ioctl_query_c(_, _, _))
44 .WillOnce(Return(1))
45 .WillOnce(Return(1))
46 .WillOnce(Return(1))
47 .WillOnce(Return(1));
48 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(2);
49 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control2)).Times(2);
50
51 // when
52 helper.setControl(V4L2_CID_GAIN, 1, true);
53
54 delete interface;
55}
56
57TEST(UltraPython, setGainAbsolute_value2_ok) {
58 // given
60 UltraPythonCameraHelper helper(interface);
61
62 struct v4l2_control control1;
63 control1.id = V4L2_CID_GAIN;
64 control1.value = 1;
65 struct v4l2_control control2;
66 control2.id = 0x009e0903;
67 control2.value = 2;
68 EXPECT_CALL(*interface, ioctl_query_c(_, _, _))
69 .WillOnce(Return(1))
70 .WillOnce(Return(1))
71 .WillOnce(Return(1))
72 .WillOnce(Return(1));
73 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(2);
74 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control2)).Times(2);
75
76 // when
77 bool res = helper.setControl(V4L2_CID_GAIN, 2, true);
78
79 // then
80 EXPECT_TRUE(res);
81
82 delete interface;
83}
84
85TEST(UltraPython, setGainAbsolute_value11_ok) {
86 // given
88 UltraPythonCameraHelper helper(interface);
89
90 struct v4l2_control control1;
91 control1.id = V4L2_CID_GAIN;
92 control1.value = 2;
93 struct v4l2_control control2;
94 control2.id = 0x009e0903;
95 control2.value = 7;
96 EXPECT_CALL(*interface, ioctl_query_c(_, _, _))
97 .WillOnce(Return(1))
98 .WillOnce(Return(1))
99 .WillOnce(Return(1))
100 .WillOnce(Return(1));
101 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(2);
102 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control2)).Times(2);
103
104 // when
105 bool res = helper.setControl(V4L2_CID_GAIN, 11, true);
106
107 // then
108 EXPECT_TRUE(res);
109
110 delete interface;
111}
112
113TEST(UltraPython, setGainAbsolute_value12_fail) {
114 // given
115 InterfaceFoCApiMock *interface = new InterfaceFoCApiMock();
116 UltraPythonCameraHelper helper(interface);
117
118 EXPECT_CALL(*interface, ioctl_query_c(_, _, _)).Times(0);
119 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, _)).Times(0);
120
121 // when
122 bool res = helper.setControl(V4L2_CID_GAIN, 12, true);
123
124 // then
125 EXPECT_FALSE(res);
126
127 delete interface;
128}
129
130TEST(UltraPython, setGain_value05_ok) {
131 // given
132 InterfaceFoCApiMock *interface = new InterfaceFoCApiMock();
133 UltraPythonCameraHelper helper(interface);
134
135 struct v4l2_control control1;
136 control1.id = V4L2_CID_GAIN;
137 control1.value = 2;
138 struct v4l2_control control2;
139 control2.id = 0x009e0903;
140 control2.value = 2;
141 EXPECT_CALL(*interface, ioctl_query_c(_, _, _))
142 .WillOnce(Return(1))
143 .WillOnce(Return(1))
144 .WillOnce(Return(1))
145 .WillOnce(Return(1));
146 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(2);
147 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control2)).Times(2);
148
149 // when
150 bool res = helper.setControl(V4L2_CID_GAIN, 0.5, false);
151
152 // then
153 EXPECT_TRUE(res);
154
155 delete interface;
156}
157
158TEST(UltraPython, setGain_value07_ok) {
159 // given
160 InterfaceFoCApiMock *interface = new InterfaceFoCApiMock();
161 UltraPythonCameraHelper helper(interface);
162
163 struct v4l2_control control1;
164 control1.id = V4L2_CID_GAIN;
165 control1.value = 2;
166 struct v4l2_control control2;
167 control2.id = 0x009e0903;
168 control2.value = 4;
169 EXPECT_CALL(*interface, ioctl_query_c(_, _, _))
170 .WillOnce(Return(1))
171 .WillOnce(Return(1))
172 .WillOnce(Return(1))
173 .WillOnce(Return(1));
174 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(2);
175 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control2)).Times(2);
176
177 // when
178 bool res = helper.setControl(V4L2_CID_GAIN, 0.7, false);
179
180 // then
181 EXPECT_TRUE(res);
182
183 delete interface;
184}
185
186TEST(UltraPython, setGain_value15_fail) {
187 // given
188 InterfaceFoCApiMock *interface = new InterfaceFoCApiMock();
189 UltraPythonCameraHelper helper(interface);
190
191 EXPECT_CALL(*interface, ioctl_query_c(_, _, _)).Times(0);
192 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, _)).Times(0);
193
194 // when
195 bool res = helper.setControl(V4L2_CID_GAIN, 1.5, false);
196
197 // then
198 EXPECT_FALSE(res);
199
200 delete interface;
201}
202
203TEST(UltraPython, setGain_valuenegative_fail) {
204 // given
205 InterfaceFoCApiMock *interface = new InterfaceFoCApiMock();
206 UltraPythonCameraHelper helper(interface);
207
208 EXPECT_CALL(*interface, ioctl_query_c(_, _, _)).Times(0);
209 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, _)).Times(0);
210
211 // when
212 bool res = helper.setControl(V4L2_CID_GAIN, -11, false);
213
214 // then
215 EXPECT_FALSE(res);
216
217 delete interface;
218}
TEST(UltraPython, setGainAbsolute_value1_ok)