YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
testUltraPythonGeneral.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 <chrono>
20#include <thread>
21
22#include "../InterfaceForCApi.h"
23#include "../Statistics.h"
24#include "../UltraPythonCameraHelper.h"
25#include "CApiMock.h"
26#include "gmock/gmock.h"
27#include "gtest/gtest.h"
28
29using namespace std::chrono_literals;
30using namespace testing;
31
32TEST(UltraPython, openAll_ok_002)
33{
34 // given
36 UltraPythonCameraHelper helper(interface);
37 EXPECT_CALL(*interface, open_c(_, O_RDWR)).Times(1);
38 EXPECT_CALL(*interface, open_c("video1", O_RDWR | O_NONBLOCK, 0)).Times(1);
39 EXPECT_CALL(*interface, open_c("video2", O_RDWR | O_NONBLOCK, 0)).Times(1);
40 EXPECT_CALL(*interface, open_c("video3", O_RDWR | O_NONBLOCK, 0)).Times(1);
41 EXPECT_CALL(*interface, open_c("video4", O_RDWR | O_NONBLOCK, 0)).Times(1);
42 EXPECT_CALL(*interface, open_c("video5", O_RDWR | O_NONBLOCK, 0)).Times(1);
43 EXPECT_CALL(*interface, open_c("video6", O_RDWR | O_NONBLOCK, 0)).Times(1);
44 EXPECT_CALL(*interface, open_c("video7", O_RDWR | O_NONBLOCK, 0)).Times(1);
45 EXPECT_CALL(*interface, open_c("video8", O_RDWR | O_NONBLOCK, 0)).Times(1);
46 EXPECT_CALL(*interface, open_c("video9", O_RDWR | O_NONBLOCK, 0)).Times(1);
47 EXPECT_CALL(*interface, udev_new_c()).WillOnce(Return(new udev()));
48 struct media_entity_desc info1;
49 strcpy(info1.name, "vcap_python output 0");
50 struct media_entity_desc info2;
51 strcpy(info2.name, "PYTHON1300");
52 struct media_entity_desc info3;
53 strcpy(info3.name, "v_tpg");
54 struct media_entity_desc info4;
55 strcpy(info4.name, "v_proc_ss");
56 struct media_entity_desc info5;
57 strcpy(info5.name, "Packet32");
58 struct media_entity_desc info6;
59 strcpy(info6.name, "imgfusion");
60 struct media_entity_desc info7;
61 strcpy(info7.name, "PYTHON1300_RXIF");
62 EXPECT_CALL(*interface, ioctl_media_c(_, _, _))
63 .WillOnce(DoAll(SetArgReferee<2>(info1), Return(1)))
64 .WillOnce(DoAll(SetArgReferee<2>(info2), Return(1)))
65 .WillOnce(DoAll(SetArgReferee<2>(info2), Return(1)))
66 .WillOnce(DoAll(SetArgReferee<2>(info3), Return(1)))
67 .WillOnce(DoAll(SetArgReferee<2>(info4), Return(1)))
68 .WillOnce(DoAll(SetArgReferee<2>(info5), Return(1)))
69 .WillOnce(DoAll(SetArgReferee<2>(info6), Return(1)))
70 .WillOnce(DoAll(SetArgReferee<2>(info7), Return(1)))
71 .WillOnce(DoAll(SetArgReferee<2>(info7), Return(1)))
72 .WillOnce(Return(-1));
73
74 EXPECT_CALL(*interface, xioctl(_, _, _)).WillRepeatedly(Return(1));
75 EXPECT_CALL(*interface, makedev_c(_, _))
76 .WillOnce(Return(1))
77 .WillOnce(Return(1))
78 .WillOnce(Return(1))
79 .WillOnce(Return(1))
80 .WillOnce(Return(1))
81 .WillOnce(Return(1))
82 .WillOnce(Return(1))
83 .WillOnce(Return(1))
84 .WillOnce(Return(1));
85 EXPECT_CALL(*interface, udev_device_new_from_devnum_c(_, _, _))
86 .WillOnce(Return(new udev_device()))
87 .WillOnce(Return(new udev_device()))
88 .WillOnce(Return(new udev_device()))
89 .WillOnce(Return(new udev_device()))
90 .WillOnce(Return(new udev_device()))
91 .WillOnce(Return(new udev_device()))
92 .WillOnce(Return(new udev_device()))
93 .WillOnce(Return(new udev_device()))
94 .WillOnce(Return(new udev_device()));
95 EXPECT_CALL(*interface, udev_device_get_devnode_c(_))
96 .WillOnce(Return("video1"))
97 .WillOnce(Return("video2"))
98 .WillOnce(Return("video3"))
99 .WillOnce(Return("video4"))
100 .WillOnce(Return("video5"))
101 .WillOnce(Return("video6"))
102 .WillOnce(Return("video7"))
103 .WillOnce(Return("video8"))
104 .WillOnce(Return("video9"));
105 EXPECT_CALL(*interface, udev_device_unref_c(_))
106 .WillOnce(Return(new udev_device()))
107 .WillOnce(Return(new udev_device()))
108 .WillOnce(Return(new udev_device()))
109 .WillOnce(Return(new udev_device()))
110 .WillOnce(Return(new udev_device()))
111 .WillOnce(Return(new udev_device()))
112 .WillOnce(Return(new udev_device()))
113 .WillOnce(Return(new udev_device()))
114 .WillOnce(Return(new udev_device()));
115 int tmp{1};
116 EXPECT_CALL(*interface, mmap_c(_, _, _, _, _, _)).WillRepeatedly(Return((void *)&tmp));
117
118 // when
119 bool out = helper.openAll();
120
121 // then
122 EXPECT_TRUE(out);
123
124 delete interface;
125}
126
127// Missing main device
128TEST(UltraPython, openAll_ko_000)
129{
130 // given
131 InterfaceFoCApiMock *interface = new InterfaceFoCApiMock();
132 UltraPythonCameraHelper helper(interface);
133 EXPECT_CALL(*interface, open_c(_, O_RDWR)).WillOnce(Return(-1));
134
135 // when
136 bool out = helper.openAll();
137
138 // then
139 EXPECT_FALSE(out);
140
141 delete interface;
142}
143
144// Missing sub device
145TEST(UltraPython, openAll_ko_001)
146{
147 // given
148 InterfaceFoCApiMock *interface = new InterfaceFoCApiMock();
149 UltraPythonCameraHelper helper(interface);
150 EXPECT_CALL(*interface, open_c(_, O_RDWR)).Times(1);
151 EXPECT_CALL(*interface, udev_new_c()).WillOnce(Return(new udev()));
152 EXPECT_CALL(*interface, open_c("video1", O_RDWR | O_NONBLOCK, 0)).Times(1);
153 EXPECT_CALL(*interface, open_c("video2", O_RDWR | O_NONBLOCK, 0)).Times(1);
154
155 struct media_entity_desc info1;
156 strcpy(info1.name, "vcap_python output 0");
157 struct media_entity_desc info2;
158 strcpy(info2.name, "PYTHON1300");
159 EXPECT_CALL(*interface, ioctl_media_c(_, _, _)).WillOnce(DoAll(SetArgReferee<2>(info1), Return(1))).WillOnce(DoAll(SetArgReferee<2>(info2), Return(1))).WillOnce(Return(-1));
160 EXPECT_CALL(*interface, xioctl(_, _, _)).WillRepeatedly(Return(1));
161 EXPECT_CALL(*interface, makedev_c(_, _)).WillOnce(Return(1)).WillOnce(Return(1));
162 EXPECT_CALL(*interface, udev_device_new_from_devnum_c(_, _, _)).WillOnce(Return(new udev_device())).WillOnce(Return(new udev_device()));
163 EXPECT_CALL(*interface, udev_device_get_devnode_c(_)).WillOnce(Return("video1")).WillOnce(Return("video2"));
164 EXPECT_CALL(*interface, udev_device_unref_c(_)).WillOnce(Return(new udev_device())).WillOnce(Return(new udev_device()));
165 int tmp{1};
166 EXPECT_CALL(*interface, mmap_c(_, _, _, _, _, _)).WillRepeatedly(Return((void *)&tmp));
167
168 // when
169 bool out = helper.openAll();
170
171 // then
172 EXPECT_FALSE(out);
173
174 delete interface;
175}
176
177TEST(UltraPython, log_ok_001)
178{
179 // given
180 InterfaceFoCApiMock *interface = new InterfaceFoCApiMock();
181 UltraPythonCameraHelper helper(interface);
182 {
183 helper.setInjectedLog([](const std::string &str, Severity severity) {
184 EXPECT_EQ("::~UltraPythonCameraHelper", str);
185 EXPECT_TRUE(severity == Severity::debug);
186 return str;
187 });
188
189 // when
190
191 delete interface;
192 }
193}
TEST(UltraPython, openAll_ok_002)