icub-test
SkinWrapperTest.cpp
1 /*
2  * iCub Robot Unit Tests (Robot Testing Framework)
3  *
4  * Copyright (C) 2015-2019 Istituto Italiano di Tecnologia (IIT)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <string>
22 #include <robottestingframework/dll/Plugin.h>
23 #include <robottestingframework/TestAssert.h>
24 
25 #include "SkinWrapperTest.h"
26 
27 using namespace std;
28 using namespace robottestingframework;
29 using namespace yarp::os;
30 using namespace yarp::dev;
31 
32 // prepare the plugin
33 ROBOTTESTINGFRAMEWORK_PREPARE_PLUGIN(SkinWrapperTest)
34 
35 
36 /***********************************************************************************/
37 SkinWrapperTest::SkinWrapperTest() :
38  yarp::robottestingframework::TestCase("SkinWrapperTest")
39 {
40 }
41 
42 
43 /***********************************************************************************/
44 SkinWrapperTest::~SkinWrapperTest()
45 {
46 }
47 
48 
49 /***********************************************************************************/
50 bool SkinWrapperTest::setup(Property &property)
51 {
52  //test #1
53  Property p;
54  p.put("device","skinWrapper");
55  p.put("robotName","fakeiCub");
56  p.put("name","/testSkinWrapper");
57  p.put("period",20);
58  p.put("total_taxels",10);
59  p.put("subdevice","fakeAnalogSensor");
60  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Opening the skinWrapper with one port");
61  ROBOTTESTINGFRAMEWORK_TEST_CHECK(dd1.open(p),"Unable to open the device!");
62  //test #2
63  BufferedPort<Bottle> port,portrpc;
64  portrpc.open("/fakeiCub2/skin/rpc:i");
65  port.open("/fakeiCub2/skin");
66  p.unput("robotName");
67  p.put("robotName","fakeiCub2");
68  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Opening the skinWrapper with one port (address conflict case)");
69  ROBOTTESTINGFRAMEWORK_TEST_CHECK(!dd2.open(p),"Unable to open the device as expected");
70  portrpc.close();
71  port.close();
72  //test #3
73  Property p2;
74  p2.put("device","skinWrapper");
75  p2.put("robotName","fakeiCub3");
76  p2.put("name","/testSkinWrapperMultip");
77  p2.put("period",20);
78  p2.put("total_taxels",3);
79  p2.put("subdevice","fakeAnalogSensor");
80  p2.fromString("(ports (left_hand left_forearm left_arm)) (left_hand 0 0 0 0) (left_forearm 0 0 0 0) (left_arm 0 0 0 0)", false);
81  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Opening the skinWrapper with multiple ports");
82  ROBOTTESTINGFRAMEWORK_TEST_CHECK(dd3.open(p2),"Unable to open the device!");
83  //test #4
84  port.open("/fakeiCub4/skin/left_hand");
85  portrpc.open("/fakeiCub4/skin/left_forearm/rpc:i");
86  p2.unput("robotName");
87  p2.put("robotName","fakeiCub4");
88  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Opening the skinWrapper with multiple ports (address conflict case)");
89  ROBOTTESTINGFRAMEWORK_TEST_CHECK(!dd4.open(p2),"Unable to open the device as expected");
90 
91  port.close();
92  portrpc.close();
93  return true;
94 }
95 
96 
97 /***********************************************************************************/
98 void SkinWrapperTest::tearDown()
99 {
100  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Closing the skinWrapper");
101  ROBOTTESTINGFRAMEWORK_ASSERT_FAIL_IF_FALSE(dd1.close() && dd2.close() && dd3.close() && dd4.close(),"Unable to close the device!");
102 }
103 
104 
105 /***********************************************************************************/
106 void SkinWrapperTest::run()
107 {
108  bool result;
109  result = Network::exists("/fakeiCub/skin/rpc:i");
110  result &= Network::exists("/fakeiCub/skin");
111  result &= Network::exists("/fakeiCub3/skin/left_hand");
112  result &= Network::exists("/fakeiCub3/skin/left_hand/rpc:i");
113  result &= Network::exists("/fakeiCub3/skin/left_forearm");
114  result &= Network::exists("/fakeiCub3/skin/left_forearm/rpc:i");
115  result &= Network::exists("/fakeiCub3/skin/left_arm");
116  result &= Network::exists("/fakeiCub3/skin/left_arm/rpc:i");
117  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Checking if all ports has been opened successfully");
118  ROBOTTESTINGFRAMEWORK_TEST_CHECK(result,"ports opened succefully");
119  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Checking the validity of devices");
120  ROBOTTESTINGFRAMEWORK_TEST_CHECK(dd1.isValid() && !dd2.isValid() && dd3.isValid() && !dd4.isValid(),"dd1 and dd3 valid, dd2 and dd4 not valid as expected");
121 
122 
123 }
124 
This test verifies the functionalities of skinWrapper after the removal of analogServer from icub-mai...