YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
testControlBrigthness.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, setBrightness_absolute_ok) {
33 // given
35 UltraPythonCameraHelper helper(interface);
36 helper.setStepPeriod(100);
37
38 struct v4l2_control control1;
39 control1.id = V4L2_CID_BRIGHTNESS;
40 control1.value = 20;
41 EXPECT_CALL(*interface, ioctl_query_c(_, _, _))
42 .WillOnce(Return(1))
43 .WillOnce(Return(1));
44 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(2);
45
46 // when
47 bool res = helper.setControl(V4L2_CID_BRIGHTNESS, 20, true);
48
49 // then
50 EXPECT_TRUE(res);
51
52 delete interface;
53}
54
55TEST(UltraPython, setBrightness_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 struct v4l2_control control1;
65 control1.id = V4L2_CID_BRIGHTNESS;
66 control1.value = 50;
67 EXPECT_CALL(*interface, ioctl_query_c(_, VIDIOC_QUERYCTRL, _))
68 .WillOnce(DoAll(SetArgReferee<2>(queryctrl), Return(1)))
69 .WillOnce(DoAll(SetArgReferee<2>(queryctrl), Return(1)));
70 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_S_CTRL, control1)).Times(2);
71
72 // when
73 bool res = helper.setControl(V4L2_CID_BRIGHTNESS, 0.50, false);
74
75 // then
76 EXPECT_TRUE(res);
77
78 delete interface;
79}
80
81
82TEST(UltraPython, getBrithness_relative_ok)
83{
84 // given
86 UltraPythonCameraHelper helper(interface);
87 helper.setStepPeriod(100);
88
89 struct v4l2_queryctrl queryctrl;
90 queryctrl.maximum = 0;
91 queryctrl.minimum = 100;
92 queryctrl.flags = 0;
93 struct v4l2_control control1;
94 control1.id = V4L2_CID_BRIGHTNESS;
95 control1.value = 50;
96
97 EXPECT_CALL(*interface, ioctl_query_c(_, VIDIOC_QUERYCTRL, _)).
98 WillOnce(DoAll(SetArgReferee<2>(queryctrl), Return(1))).
99 WillOnce(DoAll(SetArgReferee<2>(queryctrl), Return(1)));
100 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_G_CTRL, _)).
101 WillOnce(DoAll(SetArgReferee<2>(control1), Return(1))).
102 WillOnce(DoAll(SetArgReferee<2>(control1), Return(1)));
103
104 // when
105 double res = helper.getControl(V4L2_CID_BRIGHTNESS,false);
106
107 // then
108 //EXPECT_TRUE(res);
109 EXPECT_EQ(res,0.5);
110
111 delete interface;
112}
113
114TEST(UltraPython, getBrithness_absolute_ok)
115{
116 // given
117 InterfaceFoCApiMock *interface = new InterfaceFoCApiMock();
118 UltraPythonCameraHelper helper(interface);
119 helper.setStepPeriod(100);
120
121 struct v4l2_queryctrl queryctrl;
122 queryctrl.maximum = 0;
123 queryctrl.minimum = 100;
124 queryctrl.flags = 0;
125 struct v4l2_control control1;
126 control1.id = V4L2_CID_BRIGHTNESS;
127 control1.value = 50;
128
129 EXPECT_CALL(*interface, ioctl_query_c(_, VIDIOC_QUERYCTRL, _)).
130 WillOnce(DoAll(SetArgReferee<2>(queryctrl), Return(1))).
131 WillOnce(DoAll(SetArgReferee<2>(queryctrl), Return(1)));
132 EXPECT_CALL(*interface, ioctl_control_c(_, VIDIOC_G_CTRL, _)).
133 WillOnce(DoAll(SetArgReferee<2>(control1), Return(1))).
134 WillOnce(DoAll(SetArgReferee<2>(control1), Return(1)));
135
136 // when
137 double res = helper.getControl(V4L2_CID_BRIGHTNESS,true);
138
139 // then
140 //EXPECT_TRUE(res);
141 EXPECT_EQ(res,50);
142
143 delete interface;
144}
struct v4l2_queryctrl queryctrl
TEST(UltraPython, setBrightness_absolute_ok)