icub-test
All Data Structures Modules Pages
ExampleFixture.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 <cstdio>
22 #include <ctime>
23 #include <robottestingframework/dll/Plugin.h>
24 #include "ExampleFixture.h"
25 #include <yarp/os/Property.h>
26 #include <yarp/os/Random.h>
27 
28 using namespace std;
29 using namespace robottestingframework;
30 using namespace yarp::os;
31 
32 ROBOTTESTINGFRAMEWORK_PREPARE_FIXTURE_PLUGIN(ExampleFixture)
33 
34 bool ExampleFixture::setup(int argc, char** argv) {
35  printf("ExampleFixture: setupping fixture...\n");
36  // do the setup here
37  Property prop;
38  prop.fromCommand(argc, argv, false);
39  if(!prop.check("probability")) {
40  printf("ExampleFixture: missing 'probability' param.\n");
41  return false;
42  }
43  probability = prop.find("probability").asFloat64();
44  Random::seed(time(NULL));
45  return true;
46 }
47 
48 bool ExampleFixture::check() {
49  // return a random boolean
50  return ((double)Random::uniform(0, 100) <= 100.0*probability);
51 }
52 
53 void ExampleFixture::tearDown() {
54  printf("ExampleFixture: tearing down the fixture...\n");
55 }