icub-test
FtSensorTest.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 <cstdlib>
22 #include <robottestingframework/dll/Plugin.h>
23 #include <robottestingframework/TestAssert.h>
24 
25 #include <yarp/os/Time.h>
26 
27 #include "FtSensorTest.h"
28 
29 using namespace std;
30 using namespace robottestingframework;
31 using namespace yarp::os;
32 using namespace yarp::sig;
33 
34 // prepare the plugin
35 ROBOTTESTINGFRAMEWORK_PREPARE_PLUGIN(FtSensorTest)
36 
37 FtSensorTest::FtSensorTest() : yarp::robottestingframework::TestCase("FtSensorTest") {
38 }
39 
40 FtSensorTest::~FtSensorTest() { }
41 
42 bool FtSensorTest::setup(yarp::os::Property &configuration) {
43  // initialization goes here ...
44  if(configuration.check("name"))
45  setName(configuration.find("name").asString());
46 
47  ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(configuration.check("portname"),
48  "Missing 'portname' parameter");
49  portname = configuration.find("portname").asString();
50 
51  ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(port.open("/iCubTest/FTsensor"),
52  "opening port, is YARP network working?");
53 
54  ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("connecting from %s to %s\n",
55  port.getName().c_str(), portname.c_str()));
56 
57  ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(Network::connect(portname, port.getName()),
58  Asserter::format("could not connect to remote port %s, FT sensor unavailable",
59  portname.c_str()));
60  return true;
61 }
62 
63 void FtSensorTest::tearDown() {
64  // finalization goes here ...
65  Network::disconnect(portname, port.getName());
66  port.close();
67 }
68 
69 void FtSensorTest::run() {
70  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Reading FT sensors...");
71  Vector *readSensor = port.read();
72  ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(readSensor, "could not read FT data from sensor");
73 
74  ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(readSensor->size() == 6, "sensor has 6 values");
75 }
76 
Check if a FT sensor port is correctly publishing a vector with 6 values.
Definition: FtSensorTest.h:41