-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
99 lines (81 loc) · 3.41 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright (C) 2020 iCub Tech Facility - Istituto Italiano di Tecnologia
* Author: Ugo Pattacini <[email protected]>
* CopyPolicy: Released under the terms of the GNU GPL v3.0.
*/
#include <string>
#include <robottestingframework/dll/Plugin.h>
#include <robottestingframework/TestAssert.h>
#include <yarp/robottestingframework/TestCase.h>
#include <yarp/os/all.h>
using namespace std;
using namespace robottestingframework;
using namespace yarp::os;
/**********************************************************************/
class TestAssignmentWebContestSandbox : public yarp::robottestingframework::TestCase
{
RpcClient servicePort;
RpcClient worldPort;
public:
/******************************************************************/
TestAssignmentWebContestSandbox() :
yarp::robottestingframework::TestCase("TestAssignmentWebContestSandbox") {}
/******************************************************************/
virtual ~TestAssignmentWebContestSandbox() {}
/******************************************************************/
bool setup(Property& property) override
{
float rpcTmo=(float)property.check("rpc-timeout",Value(240.0)).asFloat64();
worldPort.open("/"+getName()+"/world:rpc");
worldPort.asPort().setTimeout(rpcTmo);
if (!Network::connect(worldPort.getName(), "/world/rpc")) {
ROBOTTESTINGFRAMEWORK_ASSERT_FAIL("Unable to connect to /world/rpc");
}
servicePort.open("/"+getName()+"/service:rpc");
ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Set rpc timeout = %g [s]",rpcTmo));
servicePort.asPort().setTimeout(rpcTmo);
if (!Network::connect(servicePort.getName(), "/service")) {
ROBOTTESTINGFRAMEWORK_ASSERT_FAIL("Unable to connect to /service");
}
return true;
}
/******************************************************************/
void tearDown() override
{
worldPort.close();
servicePort.close();
}
/******************************************************************/
void run() override
{
unsigned int score{0};
for (int attempt = 1; attempt <= 3; attempt++) {
ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Starting attempt #%d...", attempt));
int response_correct, response_actual;
{
Bottle cmd, rep;
cmd.addVocab32("shuffle");
worldPort.write(cmd, rep);
response_correct = rep.get(1).asInt32();
Time::delay(5.);
}
{
Bottle cmd, rep;
cmd.addVocab32("go");
if (servicePort.write(cmd, rep)) {
response_actual = rep.get(0).asInt32();
} else {
ROBOTTESTINGFRAMEWORK_ASSERT_FAIL("Unable to talk to /service");
}
}
if (response_actual == response_correct) {
ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Attempt #%d result: got it!", attempt));
score += 1;
} else {
ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Attempt #%d result: damn'!", attempt));
}
}
ROBOTTESTINGFRAMEWORK_TEST_CHECK(score > 1, Asserter::format("Total score = %d", score));
}
};
ROBOTTESTINGFRAMEWORK_PREPARE_PLUGIN(TestAssignmentWebContestSandbox)