YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
testUltraPytonRunning.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, step_base_ok) {
33 // given
35 UltraPythonCameraHelper helper(interface);
36
37 struct v4l2_buffer buf;
38 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
39 buf.memory = V4L2_MEMORY_MMAP;
40 buf.index = 1;
41 buf.flags = 0;
42 buf.sequence = 0;
43 buf.bytesused = 10000;
44 EXPECT_CALL(*interface, select_c(_, _, nullptr, nullptr, _))
45 .WillOnce(Return(1));
46 EXPECT_CALL(*interface, xioctl_v4l2(_, VIDIOC_DQBUF, _))
47 .WillOnce(DoAll(SetArgPointee<2>(buf), Return(1)));
48 EXPECT_CALL(*interface, xioctl(_, VIDIOC_QBUF, _)).WillOnce(Return(1));
49
50 // when
51 unsigned char *yarpbuffer=new unsigned char[10000000];
52 helper.mapBufferFill(yarpbuffer,1);
53 bool out = helper.step(yarpbuffer);
54
55 // then
56 EXPECT_TRUE(out);
57
58 delete interface;
59}
60
61TEST(UltraPython, step_base_error1) {
62 // given
64 UltraPythonCameraHelper helper(interface);
65
66 struct v4l2_buffer buf;
67 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
68 buf.memory = V4L2_MEMORY_MMAP;
69 buf.index = 1;
70 buf.flags = V4L2_BUF_FLAG_ERROR;
71 buf.sequence = 0;
72 buf.bytesused = 10000;
73 EXPECT_CALL(*interface, select_c(_, _, nullptr, nullptr, _))
74 .WillOnce(Return(1));
75 EXPECT_CALL(*interface, xioctl_v4l2(_, VIDIOC_DQBUF, _))
76 .WillOnce(DoAll(SetArgPointee<2>(buf), Return(1)));
77 EXPECT_CALL(*interface, xioctl(_, VIDIOC_QBUF, _)).Times(0);
78
79 // when
80 unsigned char yarpbuffer[1000000];
81 helper.mapBufferFill(yarpbuffer,1);
82 bool out = helper.step(yarpbuffer);
83
84 // then
85 EXPECT_FALSE(out);
86
87 delete interface;
88}
89
90TEST(UltraPython, step_base_timeout_ko) {
91 // given
93 UltraPythonCameraHelper helper(interface);
94
95 EXPECT_CALL(*interface, select_c(_, _, nullptr, nullptr, _))
96 .WillOnce(Return(0));
97
98 // when
99 unsigned char yarpbuffer[1000000];
100 helper.mapBufferFill(yarpbuffer,1);
101 bool out = helper.step(yarpbuffer);
102
103 // then
104 EXPECT_FALSE(out);
105
106 delete interface;
107}
108
109TEST(UltraPython, step_base_error_ko) {
110 // given
111 InterfaceFoCApiMock *interface = new InterfaceFoCApiMock();
112 UltraPythonCameraHelper helper(interface);
113
114 EXPECT_CALL(*interface, select_c(_, _, nullptr, nullptr, _))
115 .WillOnce(Return(-1));
116
117 // when
118 unsigned char yarpbuffer[1000000];
119 helper.mapBufferFill(yarpbuffer,1);
120 bool out = helper.step(yarpbuffer);
121
122 // then
123 EXPECT_FALSE(out);
124
125 delete interface;
126}
TEST(UltraPython, step_base_ok)