57 mitk::NavigationDataPlayer::Pointer player = mitk::NavigationDataPlayer::New();
60 mitk::NavigationDataReaderXML::Pointer navigationDataReader = mitk::NavigationDataReaderXML::New();
61 std::string file = mitk::StandardFileLocations::GetInstance()->FindFile(
"NavigationDataTestData.xml",
"Modules/IGT/Testing/Data");
64 mitk::NavigationDataSet::Pointer navigationDataSet = navigationDataReader->Read(file);
65 player->SetNavigationDataSet( navigationDataSet );
66 MITK_TEST_CONDITION_REQUIRED( navigationDataSet == player->GetNavigationDataSet() ,
67 "Testing SetNavigationDataSet and GetNavigationDataSet." );
69 player->StartPlaying();
71 player->StopPlaying();
73 mitk::NavigationData::Pointer nd = player->GetOutput();
79 MITK_TEST_CONDITION_REQUIRED( nd->GetPosition() == pnt,
"Testing position of replayed NavigaionData" );
81 player = mitk::NavigationDataPlayer::New();
82 player->SetNavigationDataSet( navigationDataReader->Read(file) );
84 std::vector<double> times, refTimes;
91 std::vector<mitk::Point3D> points, refPoints;
93 refPoints[0][0] = 1; refPoints[0][1] = 0; refPoints[0][2] = 3;
94 refPoints[1][0] = 2; refPoints[1][1] = 1; refPoints[1][2] = 4;
95 refPoints[2][0] = 3; refPoints[2][1] = 2; refPoints[2][2] = 5;
96 refPoints[3][0] = 4; refPoints[3][1] = 3; refPoints[3][2] = 6;
97 refPoints[4][0] = 5; refPoints[4][1] = 4; refPoints[4][2] = 7;
102 itk::Object::Pointer obj = itk::Object::New();
104 mitk::Point3D oldPos;
110 player->StartPlaying();
111 while( times.size()<5 )
114 pnt = player->GetOutput()->GetPosition();
117 times.push_back( timer->GetElapsed(obj) );
118 points.push_back(oldPos);
122 player->StopPlaying();
126 for (
int i=0;i<5;i++ )
128 if ((times[i]>refTimes[i]-150 && times[i]<refTimes[i]+150)) {MITK_TEST_OUTPUT(<<
"ref: " << refTimes[i] <<
" / time elapsed: " << times[i]);}
129 MITK_TEST_CONDITION_REQUIRED( (times[i]>refTimes[i]-150 && times[i]<refTimes[i]+150),
"checking for more or less correct time-line" );
130 MITK_TEST_CONDITION_REQUIRED(points[i] == refPoints[i],
"checking if the point coordinates are correct")
137 std::string tmp =
"";
140 mitk::NavigationDataPlayer::Pointer player = mitk::NavigationDataPlayer::New();
143 mitk::NavigationDataReaderXML::Pointer navigationDataReader = mitk::NavigationDataReaderXML::New();
144 std::string file = mitk::StandardFileLocations::GetInstance()->FindFile(
"NavigationDataTestData.xml",
"Modules/IGT/Testing/Data");
147 player->SetNavigationDataSet( navigationDataReader->Read(file) );
149 player->StartPlaying();
152 mitk::NavigationData::Pointer nd = player->GetOutput();
158 MITK_TEST_CONDITION_REQUIRED( nd->GetPosition() == pnt,
"Testing position of replayed NavigaionData" );
160 MITK_TEST_OUTPUT(<<
"Test double call of Pause() method!");
164 MITK_TEST_OUTPUT(<<
"Test double call of Resume() method!");
169 player->StopPlaying();
171 player = mitk::NavigationDataPlayer::New();
172 player->SetNavigationDataSet( navigationDataReader->Read(file) );
174 std::vector<double> times, refTimes;
180 refTimes[4] = 385.39;
181 std::vector<mitk::Point3D> points, refPoints;
183 refPoints[0][0] = 1; refPoints[0][1] = 0; refPoints[0][2] = 3;
184 refPoints[1][0] = 2; refPoints[1][1] = 1; refPoints[1][2] = 4;
185 refPoints[2][0] = 3; refPoints[2][1] = 2; refPoints[2][2] = 5;
186 refPoints[3][0] = 4; refPoints[3][1] = 3; refPoints[3][2] = 6;
187 refPoints[4][0] = 5; refPoints[4][1] = 4; refPoints[4][2] = 7;
192 itk::Object::Pointer obj = itk::Object::New();
194 mitk::Point3D oldPos;
200 player->StartPlaying();
202 MITK_TEST_CONDITION_REQUIRED(!player->IsAtEnd(),
"Testing method IsAtEnd() #0");
204 while( times.size()<3 )
207 pnt = player->GetOutput()->GetPosition();
210 times.push_back( timer->GetElapsed(obj) );
211 points.push_back(oldPos);
215 MITK_TEST_OUTPUT(<<
"Test pause method!");
218 MITK_TEST_CONDITION_REQUIRED(!player->IsAtEnd(),
"Testing method IsAtEnd() #1");
220 MITK_TEST_OUTPUT(<<
"Test resume method!");
222 while( times.size()<5 )
225 pnt = player->GetOutput()->GetPosition();
228 times.push_back( timer->GetElapsed(obj) );
229 points.push_back(oldPos);
235 player->StopPlaying();
239 for (
int i=0;i<5;i++ )
241 if ((times[i]>refTimes[i]-150 && times[i]<refTimes[i]+150)) {MITK_TEST_OUTPUT(<<
"ref: " << refTimes[i] <<
" / time elapsed: " << times[i]);}
242 MITK_TEST_CONDITION_REQUIRED( (times[i]>refTimes[i]-150 && times[i]<refTimes[i]+150),
"checking for more or less correct time-line" );
243 MITK_TEST_CONDITION_REQUIRED(points[i] == refPoints[i],
"checking if the point coordinates are correct")
246 MITK_TEST_CONDITION_REQUIRED(player->IsAtEnd(),
"Testing method IsAtEnd() #2");
251 MITK_TEST_OUTPUT(<<
"#### Testing invalid input data: errors are expected. ####");
254 mitk::NavigationDataPlayer::Pointer player;
258 player = mitk::NavigationDataPlayer::New();
259 bool InvalidStreamException0 =
false;
262 player->StartPlaying();
266 InvalidStreamException0=
true;
268 player->StopPlaying();
269 MITK_TEST_OUTPUT(<<
"#0: Tested stream not set. Application should not crash.");
272 MITK_TEST_CONDITION_REQUIRED(InvalidStreamException0,
"Testing Invalid Stream method if exception (stream not set) was thrown.");
275 player = mitk::NavigationDataPlayer::New();
276 bool InvalidStreamException1 =
false;
281 player->StartPlaying();
285 InvalidStreamException1=
true;
287 player->StopPlaying();
288 MITK_TEST_OUTPUT(<<
"#1: Tested non-existing file. Application should not crash.");
291 MITK_TEST_CONDITION_REQUIRED(InvalidStreamException1,
"Testing Invalid Stream method if exception (non-existing file) was thrown.");
294 player = mitk::NavigationDataPlayer::New();
295 bool InvalidStreamException2 =
false;
296 file = mitk::StandardFileLocations::GetInstance()->FindFile(
"SROMFile.rom",
"Modules/IGT/Testing/Data");
300 player->StartPlaying();
304 InvalidStreamException2=
true;
306 player->StopPlaying();
307 MITK_TEST_OUTPUT(<<
"#2: Tested wrong file format. Application should not crash.");
310 MITK_TEST_CONDITION_REQUIRED(InvalidStreamException2,
"Testing Invalid Stream method if exception (wrong file format) was thrown.");
313 player = mitk::NavigationDataPlayer::New();
314 file = mitk::StandardFileLocations::GetInstance()->FindFile(
"InvalidVersionNavigationDataTestData.xml",
"Modules/IGT/Testing/Data");
316 bool InvalidStreamException3 =
false;
319 player->StartPlaying();
323 InvalidStreamException3 =
true;
325 player->StopPlaying();
326 MITK_TEST_OUTPUT(<<
"#3: Tested wrong file version. Application should not crash.");
328 MITK_TEST_CONDITION_REQUIRED(InvalidStreamException3,
"Testing Invalid Stream method if exception (wrong file version) was thrown.");
331 mitk::NavigationDataSet::Pointer navigationDataSet;
332 mitk::NavigationDataReaderXML::Pointer navigationDataReader = mitk::NavigationDataReaderXML::New();
334 navigationDataSet = navigationDataReader->Read(
"cs:\fsd/$%§²³ffdsd"));
336 player = mitk::NavigationDataPlayer::New();
337 player->SetNavigationDataSet( navigationDataSet );
339 bool InvalidStreamException4=
false;
342 player->StartPlaying();
346 InvalidStreamException4=
true;
347 MITK_TEST_OUTPUT(<<
"#4: Tested wrong file. Application should not crash.");
350 MITK_TEST_CONDITION_REQUIRED(InvalidStreamException4,
"Testing Invalid Stream method if exception (wrong file) was thrown.");
353 player = mitk::NavigationDataPlayer::New();
354 bool InvalidStreamException5=
false;
357 player->StartPlaying();
361 InvalidStreamException5=
true;
363 player->StopPlaying();
364 MITK_TEST_OUTPUT(<<
"#5: Tested null stream. Application should not crash.");
367 MITK_TEST_CONDITION_REQUIRED(InvalidStreamException5,
"Testing Invalid Stream method if exception (null stream) was thrown.");
370 player = mitk::NavigationDataPlayer::New();
371 bool InvalidStreamException6=
false;
372 std::ifstream* myEmptyStream;
375 myEmptyStream =
new std::ifstream(
"");
376 mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New();
377 reader->Read( myEmptyStream );
381 InvalidStreamException6=
true;
382 MITK_TEST_OUTPUT(<<
"#6: Tested empty stream. Application should not crash.");
384 MITK_TEST_CONDITION_REQUIRED(InvalidStreamException6,
"Testing Invalid Stream method if exception (empty stream) was thrown.");
390 player = mitk::NavigationDataPlayer::New();
391 file = mitk::StandardFileLocations::GetInstance()->FindFile(
"SROMFile.rom",
"Modules/IGT/Testing/Data");
393 bool InvalidStreamException7=
false;
394 std::ifstream* myWrongStream;
395 myWrongStream =
new std::ifstream(file.c_str());
398 mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New();
399 reader->Read( myWrongStream );
403 InvalidStreamException7=
true;
404 MITK_TEST_OUTPUT(<<
"#7: Tested wrong stream. Application should not crash.");
407 MITK_TEST_CONDITION_REQUIRED(InvalidStreamException7,
"Testing Invalid Stream method if exception (wrong stream) was thrown.");
412 player = mitk::NavigationDataPlayer::New();
413 file = mitk::StandardFileLocations::GetInstance()->FindFile(
"InvalidDataNavigationDataTestData.xml",
"Modules/IGT/Testing/Data");
414 bool InvalidStreamException8=
false;
417 mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New();
418 reader->Read( myWrongStream );
419 player->SetNavigationDataSet( reader->Read( file ) );
420 player->StartPlaying();
424 InvalidStreamException8=
true;
425 MITK_TEST_OUTPUT(<<
"#8: Tested invalid file version. Application should not crash.");
427 MITK_TEST_CONDITION_REQUIRED(InvalidStreamException8,
"Testing Invalid Stream method if exception (Invalid) was thrown.");
430 delete myEmptyStream;
431 delete myWrongStream;
461 MITK_INFO <<
"In the following, exceptions are tested. Errors will occur and are expected.";
465 mitk::NavigationDataPlayer::Pointer myTestPlayer1 = mitk::NavigationDataPlayer::New();
466 bool exceptionThrown1 =
false;
469 myTestPlayer1->StartPlaying();
474 exceptionThrown1 =
true;
475 myTestPlayer1->StopPlaying();
476 MITK_TEST_OUTPUT(<<
"#10: Tested exception for the case when stream=nullptr in StartPlaying. Application should not crash.");
479 MITK_TEST_CONDITION_REQUIRED(exceptionThrown1,
"Testing StartPlaying method if exception (stream=nullptr) was thrown.");
482 mitk::NavigationDataPlayer::Pointer myTestPlayer2 = mitk::NavigationDataPlayer::New();
486 bool exceptionThrown2 =
false;
488 myTestPlayer2->StartPlaying();
492 exceptionThrown2 =
true;
493 myTestPlayer2->StopPlaying();
494 MITK_TEST_OUTPUT(<<
"#11: Tested exception for the case when file does not exist in StartPlaying. Application should not crash.");
496 MITK_TEST_CONDITION_REQUIRED(exceptionThrown2,
"Testing StartPlaying method if exception is thrown when file does not exist.");
500 mitk::NavigationDataPlayer::Pointer myTestPlayer3 = mitk::NavigationDataPlayer::New();
501 std::string file3 = mitk::StandardFileLocations::GetInstance()->FindFile(
"SROMFile.rom",
"Modules/IGT/Testing/Data");
503 bool exceptionThrown3 =
false;
510 MITK_TEST_OUTPUT(<<
"#12: Tested exception for the case when file format is wrong. Application should not crash.");
511 exceptionThrown3 =
true;
513 MITK_TEST_CONDITION_REQUIRED(exceptionThrown3,
"Testing StartPlaying method if exception (file format is wrong) was thrown.");
516 mitk::NavigationDataPlayer::Pointer myTestPlayer4 = mitk::NavigationDataPlayer::New();
517 std::string file4 = mitk::StandardFileLocations::GetInstance()->FindFile(
"InvalidVersionNavigationDataTestData.xml",
"Modules/IGT/Testing/Data");
518 bool exceptionThrown4 =
false;
521 mitk::NavigationDataSet::Pointer navigationDataSet
523 myTestPlayer4->SetNavigationDataSet( navigationDataSet );
527 exceptionThrown4 =
true;
528 MITK_TEST_OUTPUT(<<
"#13: Tested exception for the case when file version is wrong in StartPlaying. Application should not crash.");
530 MITK_TEST_CONDITION_REQUIRED(exceptionThrown4,
"Testing StartPlaying method if exception (file version is wrong) was thrown.");
533 mitk::NavigationDataPlayer::Pointer myTestPlayer5 = mitk::NavigationDataPlayer::New();
534 bool exceptionThrown5 =
false;
538 mitk::NavigationDataSet::Pointer navigationDataSet
540 myTestPlayer4->SetNavigationDataSet( navigationDataSet );
544 exceptionThrown5 =
true;
545 MITK_TEST_OUTPUT(<<
"#14: Tested exception for the case when non-existing file name in StartPlaying. Application should not crash.");
547 MITK_TEST_CONDITION_REQUIRED(exceptionThrown5,
"Testing StartPlaying method if exception (non-existing file name) was thrown.");