YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
testCli.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 "../../../cli/UltraPythonCli.h"
20#include "CliMock.h"
21
22#include "gmock/gmock.h"
23#include "gtest/gtest.h"
24
25using namespace testing;
26
27TEST(UltraPyCli, setFeature_ok) {
29 UltraPythonCli mockClient(grabberMock);
30
31 EXPECT_CALL(*grabberMock, setFeature(YARP_FEATURE_BRIGHTNESS_ABSOLUTE, 10))
32 .WillOnce(DoAll(Return<bool>(true)));
33
34 bool result = grabberMock->setFeature(YARP_FEATURE_BRIGHTNESS_ABSOLUTE, 10);
35
36 EXPECT_TRUE(result);
37
38 delete grabberMock;
39}
40
41TEST(UltraPyCli, getFeature_ok) {
43 UltraPythonCli mockClient(grabberMock);
44
45 double value = 10;
46
47 EXPECT_CALL(*grabberMock, getFeature(YARP_FEATURE_BRIGHTNESS_ABSOLUTE, &value))
48 .WillOnce(DoAll(SetArgPointee<1>(value), Return<bool>(true)));
49
50 bool result = grabberMock->getFeature(YARP_FEATURE_BRIGHTNESS_ABSOLUTE, &value);
51
52 EXPECT_EQ(value, 10);
53 EXPECT_TRUE(result);
54 delete grabberMock;
55}
56
57TEST(UltraPyCli, split_string_ok) {
58 // use ; as delimiter
59 std::string test1 = "a;b";
60 std::string test2 = "a;b;c";
61 std::string test3 = "a b";
62 std::string test4 = "a;b c";
63 std::string test5 = "a\nb;c";
64
66 UltraPythonCli mockClient(grabberMock);
67
68 std::vector<std::string> result1 = mockClient.splitString(test1, ";");
69 ASSERT_THAT(result1, ElementsAre("a", "b"));
70
71 std::vector<std::string> result2 = mockClient.splitString(test2, ";");
72 ASSERT_THAT(result2, ElementsAre("a", "b", "c"));
73
74 std::vector<std::string> result3 = mockClient.splitString(test3, ";");
75 ASSERT_THAT(result3, ElementsAre("a b"));
76
77 std::vector<std::string> result4 = mockClient.splitString(test4, ";");
78 ASSERT_THAT(result4, ElementsAre("a", "b c"));
79
80 std::vector<std::string> result5 = mockClient.splitString(test5, ";");
81 ASSERT_THAT(result5, ElementsAre("a\nb", "c"));
82}
Mocking class created to replace the grabber object.
Definition CliMock.h:28
bool getFeature(int feature, double *value1, double *value2) override
Get the current value for the requested feature.
Definition CliMock.h:38
bool setFeature(int feature, double value1, double value2) override
Set the requested feature to a value using 2 params (like white balance)
Definition CliMock.h:35
TEST(UltraPyCli, setFeature_ok)
Definition testCli.cpp:27