@@ -86,7 +86,15 @@ bool yarp::dev::RobotInterfaceTestMockDriver::open(yarp::os::Searchable& config)
86
86
globalState.mockDriverWasOpened = true ;
87
87
globalState.mockDriverParamStringValue = config.check (" theparam" , yarp::os::Value (" theparam_unset" ), " The string param" ).asString ();
88
88
globalState.mockDriverParamListValue = *config.check (" thelistparam" , emptyList.get (0 ), " The list param" ).asList ();
89
- globalState.mockDriverParamBlobValue = config.find (" theblobparam" ).asBlob (); // don't use the `check` signature as it creates a temporary
89
+
90
+ // don't use the `check` signature as it creates a temporary
91
+ if (const auto * ptr = config.find (" theblobparam" ).asBlob (); ptr != nullptr )
92
+ {
93
+ // the caller test suite outlives `config`, thus we passed a pointer to the data instead of the data itself,
94
+ // and we need to dereference it here
95
+ globalState.mockDriverParamBlobValue = *reinterpret_cast <char * const *>(ptr);
96
+ }
97
+
90
98
return true ;
91
99
}
92
100
@@ -415,7 +423,7 @@ TEST_CASE("robotinterface::XMLReaderTest", "[yarp::robotinterface]")
415
423
" </devices>\n "
416
424
" </robot>\n " ;
417
425
418
- int blobValue = 42 ;
426
+ auto * blobValue = &XMLString ;
419
427
420
428
yarp::robotinterface::XMLReader reader;
421
429
yarp::os::Property config;
@@ -440,7 +448,7 @@ TEST_CASE("robotinterface::XMLReaderTest", "[yarp::robotinterface]")
440
448
// Check that the device was opened and attach called
441
449
CHECK (globalState.mockDriverWasOpened );
442
450
CHECK (!globalState.mockDriverWasClosed );
443
- CHECK (* reinterpret_cast < const int *>( globalState.mockDriverParamBlobValue ) == blobValue);
451
+ CHECK (globalState.mockDriverParamBlobValue == blobValue);
444
452
445
453
// Stop the robot
446
454
ok = result.robot .enterPhase (yarp::robotinterface::ActionPhaseInterrupt1);
@@ -451,7 +459,7 @@ TEST_CASE("robotinterface::XMLReaderTest", "[yarp::robotinterface]")
451
459
// Check that the device was closed and detach called
452
460
CHECK (globalState.mockDriverWasOpened );
453
461
CHECK (globalState.mockDriverWasClosed );
454
- CHECK (* reinterpret_cast < const int *>( globalState.mockDriverParamBlobValue ) == blobValue);
462
+ CHECK (globalState.mockDriverParamBlobValue == blobValue);
455
463
}
456
464
457
465
SECTION (" Check valid robot file with portprefix passed via xml" )
0 commit comments