70#define WB_FNAME "guWhiteboard_SimpleWhiteboardTest"
107 self.stringValue = [[NSString alloc] initWithUTF8String: str.c_str()];
108 self.callbackCount++;
109 dispatch_semaphore_signal(
self.semaphore);
116#pragma clang diagnostic push
117#pragma clang diagnostic ignored "-Wdeprecated-declarations"
118#pragma clang diagnostic ignored "-Wdirect-ivar-access"
132 self.callbackCount = 0;
133 self.semaphore = dispatch_semaphore_create(0);
162 self.semaphore = NULL;
174 string testString(
"Testing the Whiteboard");
175 Say_t wbSpeech(testString);
176 string result = wbSpeech();
178 XCTAssertTrue(result == testString,
@"Expected result to be '%s', but got '%s'", testString.c_str(), result.c_str());
187 int oldNumber = playerNumber();
189 playerNumber = newNumber;
190 int result = playerNumber;
192 XCTAssertEqual(result, newNumber,
@"Expected player '%d', but got '%d'", newNumber, result);
194 playerNumber.
set(oldNumber);
195 result = playerNumber.
get();
197 XCTAssertEqual(result, oldNumber,
@"Expected old player '%d', but got '%d'", oldNumber, result);
210 fsmStatus.
set(newStatus);
212 XCTAssertFalse(result.
get(0),
@"Expecting 0 to be unset");
213 XCTAssertTrue(result.
get(1),
@"Expecting 1 to be set");
214 XCTAssertFalse(result.
get(2),
@"Expecting 2 to be unset");
215 XCTAssertTrue(result.
get(3),
@"Expecting 3 to be set");
216 XCTAssertTrue(result.
get(4),
@"Expecting 4 to be set");
217 fsmStatus.
set(oldStatus);
218 result = fsmStatus.
get();
219 XCTAssertTrue(result == oldStatus,
@"Expecting old status to be restored");
226 XCTAssertEqualWithAccuracy(DEG2RAD(10), testA.HeadYaw (), 0.01,
@"Head Yaw match");
227 XCTAssertEqualWithAccuracy(DEG2RAD(20), testA.HeadPitch(), 0.01,
@"Head Pitch match");
237 XCTAssertFalse(testA.isVisible(),
@"Expected not visible");
241 XCTAssertTrue(testB.isVisible(),
@"Expected visible");
242 XCTAssertEqual(10, testB.distance(),
@"Distance match");
243 XCTAssertEqual(100, testB.frameCounter(),
@"frameCounter match");
245 string s = testB.description();
248 XCTAssertTrue(testC.isVisible(),
@"Expected visible");
249 XCTAssertEqual(testC.distance(), testB.distance(),
@"Distance match");
250 XCTAssertEqual(testC.frameCounter(), testB.frameCounter(),
@"frameCounter match");
261 XCTAssertFalse(testA.isVisible(),
@"Expected not visible");
265 XCTAssertTrue(testB.isVisible(),
@"Expected visible");
266 XCTAssertEqual(10, testB.distance(),
@"distance match");
267 XCTAssertEqual(20, testB.x(),
@"'x' match");
268 XCTAssertEqual(30, testB.y(),
@"'y' match");
269 XCTAssertEqual(40, testB.yaw(),
@"yaw match");
270 XCTAssertEqual(100, testB.frameCounter(),
@"frameCounter match");
272 string s = testB.description();
275 XCTAssertTrue(testC.isVisible(),
@"Expected visible");
276 XCTAssertEqual(testC.distance(), testB.distance(),
@"distance match");
277 XCTAssertEqual(testC.x(), testB.x(),
@"'x' match");
278 XCTAssertEqual(testC.y(), testB.y(),
@"'y' match");
279 XCTAssertEqual(testC.yaw(), testB.yaw(),
@"yaw match");
280 XCTAssertEqual(testC.frameCounter(), testB.frameCounter(),
@"frameCounter match");
292 XCTAssertTrue(testA.isVisible(),
@"Expected visible");
293 XCTAssertTrue(testB.isVisible(),
@"Expected visible");
294 XCTAssertEqual(testA.distance(), testB.distance(),
@"distance match");
295 XCTAssertEqual(testA.frameCounter(), testB.frameCounter(),
@"frameCounter match");
299 testArray.set_object(testC,
FSRight);
303 XCTAssertTrue(testC.isVisible(),
@"Expected visible");
304 XCTAssertTrue(testD.isVisible(),
@"Expected visible");
305 XCTAssertEqual(testC.distance(), testD.distance(),
@"distance match");
306 XCTAssertEqual(testC.frameCounter(), testD.frameCounter(),
@"frameCounter match");
312 XCTAssertTrue(testE.isVisible(),
@"Expected visible");
313 XCTAssertTrue(testF.isVisible(),
@"Expected visible");
314 XCTAssertEqual(testE.distance(), testB.distance(),
@"distance match");
315 XCTAssertEqual(testE.frameCounter(), testB.frameCounter(),
@"frameCounter match");
316 XCTAssertEqual(testF.distance(), testC.distance(),
@"distance match");
317 XCTAssertEqual(testF.frameCounter(), testC.frameCounter(),
@"frameCounter match");
319 string s =testArrayB.description();
322 XCTAssertTrue(testArrayC.get_object(
FSLeft).isVisible(),
@"Expected visible");
323 XCTAssertTrue(testArrayC.get_object(
FSRight).isVisible(),
@"Expected visible");
324 XCTAssertEqual(testArrayC.get_object(
FSLeft).distance(), testB.distance(),
@"distance match");
325 XCTAssertEqual(testArrayC.get_object(
FSLeft).frameCounter(), testB.frameCounter(),
@"frameCounter match");
326 XCTAssertEqual(testArrayC.get_object(
FSRight).distance(), testC.distance(),
@"distance match");
327 XCTAssertEqual(testArrayC.get_object(
FSRight).frameCounter(), testC.frameCounter(),
@"frameCounter match");
340 XCTAssertTrue(testP.isVisible(),
@"Expected visible");
341 XCTAssertTrue(testB.
isVisible(),
@"Expected visible");
342 XCTAssertEqual(testP.distance(), testB.
distance(),
@"distance match");
343 XCTAssertEqual(testP.x(), testB.
x(),
@"'x' match");
344 XCTAssertEqual(testP.y(), testB.
y(),
@"'y' match");
345 XCTAssertEqual(testP.yaw(), testB.
yaw(),
@"yaw match");
346 XCTAssertEqual(testP.frameCounter(), testB.
frameCounter(),
@"frameCounter match");
354 XCTAssertTrue(testL.isVisible(),
@"Expected visible");
355 XCTAssertTrue(testL1.
isVisible(),
@"Expected visible");
356 XCTAssertEqual(testL1.
distance(), testL.distance(),
@"distance match");
357 XCTAssertEqual(testL1.
x(), testL.x(),
@"'x' match");
358 XCTAssertEqual(testL1.
y(), testL.y(),
@"'y' match");
359 XCTAssertEqual(testL1.
yaw(), testL.yaw(),
@"yaw match");
360 XCTAssertEqual(testL1.
frameCounter(), testL.frameCounter(),
@"frameCounter match");
373 XCTAssertTrue(testPostLeft.
isVisible(),
@"Expected visible");
374 XCTAssertEqual(testPostLeft.
distance(), testL.distance(),
@"distance match");
375 XCTAssertEqual(testPostLeft.
x(), testL.x(),
@"'x' match");
376 XCTAssertEqual(testPostLeft.
y(), testL.y(),
@"'y' match");
377 XCTAssertEqual(testPostLeft.
yaw(), testL.yaw(),
@"yaw match");
378 XCTAssertEqual(testPostLeft.
frameCounter(), testL.frameCounter(),
@"frameCounter match");
379 XCTAssertTrue(testPostRight.
isVisible(),
@"Expected visible");
380 XCTAssertEqual(testPostRight.
distance(), testR.distance(),
@"distance match");
381 XCTAssertEqual(testPostRight.
x(), testR.x(),
@"'x' match");
382 XCTAssertEqual(testPostRight.
y(), testR.y(),
@"'y' match");
383 XCTAssertEqual(testPostRight.
yaw(), testR.yaw(),
@"yaw match");
384 XCTAssertEqual(testPostRight.
frameCounter(), testR.frameCounter(),
@"frameCounter match");
386 XCTAssertTrue(testCrossbar.
isVisible(),
@"Expected visible");
387 XCTAssertEqual(testCrossbar.
distance(), testC.distance(),
@"distance match");
388 XCTAssertEqual(testCrossbar.
x(), testC.x(),
@"'x' match");
389 XCTAssertEqual(testCrossbar.
y(), testC.y(),
@"'y' match");
390 XCTAssertEqual(testCrossbar.
yaw(), testC.yaw(),
@"yaw match");
391 XCTAssertEqual(testCrossbar.
frameCounter(), testC.frameCounter(),
@"frameCounter match");
393 string s =testArrayB.description();
396 XCTAssertTrue(testArrayC.objects(
FVOGoalPostLeftTop).isVisible(),
@"Expected visible");
398 XCTAssertEqual(testArrayC.objects(
FVOGoalPostLeftTop).distance(), testL.distance(),
@"distance match");
399 XCTAssertEqual(testArrayC.objects(
FVOGoalPostLeftTop).frameCounter(), testL.frameCounter(),
@"frameCounter match");
400 XCTAssertEqual(testArrayC.objects(
FVOGoalPostRightTop).distance(), testR.distance(),
@"distance match");
401 XCTAssertEqual(testArrayC.objects(
FVOGoalPostRightTop).frameCounter(), testR.frameCounter(),
@"frameCounter match");
411 bool ballInTopIsVisible=testBall.topVisible();
412 bool ballInBottomIsVisible=testBall.bottomVisible();
413 int x = testBall.topX();
414 int y = testBall.topY();
415 int radious = testBall.topRadius();
417 XCTAssertEqual(radious, 103,
@"radious incorrect");
419 aBallHandler.
set(testBall);
423 ballInTopIsVisible=ballSighting.topVisible();
424 ballInBottomIsVisible=ballSighting.bottomVisible();
425 int myTopRadius=0;
int centerTopX=0;
int centerTopY=0;
426 int myBottomRadius=0;
int centerBottomX=0;
int centerBottomY=0;
428 XCTAssertTrue(ballInTopIsVisible,
@"Expected top ball");
429 if ( ballInTopIsVisible )
431 DBG( std::cout <<
" Top ball radious ("<< theBalls[
Top]->GetRadius() <<
")" << std::endl; )
433 centerTopX = ballSighting.
topX();
434 centerTopY = ballSighting.
topY();
437 XCTAssertFalse(ballInBottomIsVisible,
@"Expected no bottom ball");
439 if ( ballInBottomIsVisible )
441 DBG( std::cout <<
" Bottom ball radious ("<< theBalls[
Bottom]->GetRadius() <<
")" << std::endl; )
443 centerBottomX = ballSighting.
bottomX();
444 centerBottomY = ballSighting.
bottomY();
447 XCTAssertEqual(x, centerTopX,
@"'x' match");
448 XCTAssertEqual(y, centerTopY,
@"'y' match");
449 XCTAssertEqual(radious, myTopRadius,
@"radiousr match");
450 XCTAssertEqual(ballSighting.frameNumber(), testBall.frameNumber(),
@"frameCounter match");
461 string testString(
"Testing Whiteboard subscription");
463 XCTAssertEqual(dispatch_semaphore_wait(
semaphore, DISPATCH_TIME_FOREVER), 0L,
@"Expected callback within a second");
465 XCTAssertTrue(testString ==
self.
stringValue.UTF8String,
@"Expected '%s' from callback, but got '%@'", testString.c_str(),
self.stringValue);
467 testString = [[[NSDate date] description] UTF8String];
469 XCTAssertEqual(dispatch_semaphore_wait(
semaphore, DISPATCH_TIME_FOREVER), 0L,
@"Expected second callback within a second");
471 XCTAssertTrue(testString ==
self.
stringValue.UTF8String,
@"Expected '%s' from callback, but got '%@'", testString.c_str(),
self.stringValue);
474static WBTypes nasty_wb_without_string_conversion[] = {
kwb_reserved_SubscribeToAllTypes_v,
kGCGameState_v,
kSensorsFootSensors_v,
kSENSORSLedsSensors_v,
kSENSORSLegJointTemps_v,
kSENSORSTorsoJointTemps_v,
kSoloTypeExample_v,
kUDPRN_v,
kTeleoperationControlStatus_v,
kTotoDoingMotion_v,
kCount_v,
480 string testString(
"000");
485 bool needStringConversion =
true;
486 for (
size_t i = 0; i <
sizeof(nasty_wb_without_string_conversion)/
sizeof(nasty_wb_without_string_conversion[0]); i++)
488 if (wbtype == nasty_wb_without_string_conversion[i])
490 needStringConversion =
false;
494 XCTAssertTrue(!needStringConversion || result,
@"Could not post wb message %d (%s):", wbtype,
WBTypes_stringValues[wbtype]);
505#ifndef GSW_IOS_DEVICE
507 XCTAssert(wbenv,
@"Whiteboard environment variable '%s' not set",
GSW_DEFAULT_ENV);
508 XCTAssertTrue(strcmp(wbenv,
WB_FNAME) == 0,
@"Whiteboard environment '%s' instead of '%s'", wbenv,
WB_FNAME);
509 const char *fname =
"/tmp/" WB_FNAME;
511 XCTAssertTrue(stat(fname, &buf) != -1,
@"Could not open whiteboard '%s': %s", fname, strerror(errno));
516#pragma clang diagnostic pop
#define WB_TYPE_BIND(t, f)
~WBSubscriber()
Test Destructor.
void sub(WBTypes, gu_simple_message *m)
Trigger subscription test.
WBSubscriber(SimpleWhiteboardTest *t)
Test Constructor.
void set(const object_type &msg)
designated setter for posting whiteboard messages
object_type get()
designated getter for getting a whiteboard message
object_type get_from(gu_simple_message *msg)
access method to get data from an existing, low-level message
WB Ptr Class: FSM_Status_t.
Class for controlling and getting the status of FSMs.
void clr(int fsm)
machine control/status clearer
void set(int fsm)
machine control/status setter
bool get(int fsm) const
machine status setter
Provides a C++ wrapper around wb_filtered_arrayonedimobjects.
void set_objects(const FilteredVisionObject *t_newValue)
const FilteredVisionObject * objects() const
Class for for the array of sonar messages, LEFT and RIGHT.
A class to contain objects that have been filtered through localisation.
Class for for one filtered sonar message.
WB Ptr Class: PlayerNumber_t.
Provides a C++ wrapper around wb_sensors_torsojointsensors.
WB Ptr Class: VisionBall_t.
Whiteboard Class used by vision to report detect ball Reports balls detected in top or bottom camera,...
int16_t bottomY() const
Center Y Position of the bottom ball.
int16_t topRadius() const
Radius of the top ball.
int16_t topY() const
Center Y Position of the top ball.
int16_t bottomRadius() const
Radius of the bottom ball.
int16_t topX() const
Center X Position of the top ball.
int16_t bottomX() const
Center X Position of the bottom ball.
This class provides a subscription implementation for the 'simple' whiteboard, aka the 'typed' whiteb...
void subscribe(WBFunctorBase *func)
Allows you to subscribe to a specific whiteboard type and get callbacks when that type is updated.
void unsubscribe(guWhiteboard ::wb_types t)
Stop getting callbacks for a particular whiteboard type.
const char ** WBTypes_stringValues
allow whiteboard to use old functions for whiteboard initialisation and choose which messages and con...
#define GSW_NUM_TYPES_DEFINED
allow whiteboard to use old functions for whiteboard initialisation and choose which messages and con...
#define GSW_DEFAULT_ENV
environment variable containing the default whiteboard file name
#define kFilteredGoalSighting_v
#define kSoloTypeExample_v
#define kFilteredBallSighting_v
#define kSENSORSLedsSensors_v
#define kTotoDoingMotion_v
#define kSENSORSLegJointTemps_v
#define kOculusPrime_Command_v
#define kTeleoperationControlStatus_v
#define kSensorsFootSensors_v
#define kSENSORSTorsoJointTemps_v
wb_types
All the message 'types' for the class based whiteboard.
#define kwb_reserved_SubscribeToAllTypes_v
NSString * stringValue
not sure, some string for test
void setUp()
Setup objects for testing.
void tearDown()
Destroy testing objects.
void testSerializationFilteredArrayOneDimObjects()
void testSerializationSENSORSTorsoJointSensors()
dispatch_semaphore_t semaphore
not sure, some sem used in testing
void testStringPostings()
void testSerializationFilteredSonarObject()
void testVisionBallPutGet()
void testStringPutGet()
String Test function for 'simple' whiteboard setter and getter.
int callbackCount
counter used for testing callbacks
void testEnvWhiteboardName()
void testSerializationFilteredArrayOneDimSonar()
void testIntGetPutGetPut()
Int Test function for 'simple' whiteboard setter and getter.
void testSerializationFilteredOneDimObject()
bool postmsg(wb_types message_index, std::string message_content, gu_simple_whiteboard_descriptor *wbd)
WHITEBOARD_POSTER_STRING_CONVERSION.
Simple sonar information for the whiteboard.
union type that is used to store data in shared memory
@ FVOGoalPostLeftTop
Filtered information for a post we know is Left.
@ FVOGoalCrossBarTop
Filtered information for the cross BAR.
@ FVOGoalPostTop
Filtered information for a post we cannot tell is Left or right.
@ FVOGoalPostRightTop
Filtered information for a post we know is right.
@ Bottom
Bottom Camera on the nao.
@ Top
Top Camera on the nao.