24 #include <robottestingframework/TestAssert.h>
25 #include <robottestingframework/dll/Plugin.h>
26 #include <yarp/os/Network.h>
27 #include <yarp/os/Time.h>
28 #include <yarp/os/Property.h>
30 #include "CameraTest.h"
32 using namespace robottestingframework;
33 using namespace yarp::os;
34 using namespace yarp::sig;
42 ROBOTTESTINGFRAMEWORK_PREPARE_PLUGIN(
CameraTest)
44 CameraTest::CameraTest() : yarp::robottestingframework::TestCase(
"CameraTest") {
47 CameraTest::~CameraTest() { }
49 bool CameraTest::setup(yarp::os::Property& property) {
51 if(property.check(
"name"))
52 setName(property.find(
"name").asString());
55 ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(property.check(
"portname"),
56 "The portname must be given as the test paramter!");
57 cameraPortName =
property.find(
"portname").asString();
58 measure_time =
property.check(
"measure_time") ?
property.find(
"measure_time").asInt32() : TIMES;
59 expected_frequency =
property.check(
"expected_frequency") ?
property.find(
"expected_frequency").asInt32() : FREQUENCY;
60 tolerance =
property.check(
"tolerance") ?
property.find(
"tolerance").asInt32() : TOLERANCE;
63 ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(port.open(
"/CameraTest/image:i"),
64 "opening port, is YARP network available?");
66 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format(
"Listening to camera for %d seconds",
70 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format(
"connecting from %s to %s",
71 port.getName().c_str(), cameraPortName.c_str()));
72 ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(Network::connect(cameraPortName, port.getName()),
73 "could not connect to remote port, camera unavailable");
77 void CameraTest::tearDown() {
78 Network::disconnect(cameraPortName, port.getName());
82 void CameraTest::run() {
83 ROBOTTESTINGFRAMEWORK_TEST_REPORT(
"Reading images...");
84 double timeStart=yarp::os::Time::now();
85 double timeNow=timeStart;
88 while(timeNow<timeStart+measure_time) {
89 Image *image=port.read(
false);
92 yarp::os::Time::delay(0.01);
93 timeNow=yarp::os::Time::now();
96 int expectedFrames = measure_time*expected_frequency;
97 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format(
"Received %d frames, expecting %d",
100 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(abs(frames-expectedFrames)<tolerance,
101 "checking number of received frames");
Check if a camera is publishing images at desired framerate.