MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkTimeStampTest.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
13#include "mitkIGTTimeStamp.h"
14#include "mitkRealTimeClock.h"
15
16#include "mitkTestingMacros.h"
17#include "itkObject.h"
18
19//#include <time.h>
20
21#ifndef WIN32
22#include <unistd.h>
23#endif
24
25
26
30int mitkTimeStampTest(int /* argc */, char* /*argv*/[])
31{
32 MITK_TEST_BEGIN("IGTTimeStamp")
33
34 //create testing objects
35 itk::Object::Pointer tester = itk::Object::New();
36 itk::Object::Pointer tester2 = itk::Object::New();
37
38 //try methods without calling CreateInstance() before (error test cases)
39 MITK_TEST_OUTPUT(<<"Testing behavior of methodes if they are called at the wrong moment (error should occure).");
42
43 //create instance of singleton time stamp class
44 MITK_TEST_CONDITION_REQUIRED(mitk::IGTTimeStamp::CreateInstance() != (nullptr), "Testing GetInstance() of Singleton" );
45
46 double timestampX = mitk::IGTTimeStamp::GetInstance()->GetElapsed();
47 MITK_TEST_CONDITION_REQUIRED(timestampX==-1,"..Testing method GetCurrentTimeStamp().");
48 double offsetX = mitk::IGTTimeStamp::GetInstance()->GetOffset(tester2);
49 MITK_TEST_CONDITION_REQUIRED(offsetX==-1.0,"..Testing method GetOffset().");
50
51 //start-tracking sets the reference-time, timestamps are relative to this time
53 MITK_INFO << "first device has started tracking\n";
54
55 //sleeps for 20 ms
56 #if defined (WIN32) || defined (_WIN32)
57 Sleep(20);
58 #else
59 usleep(20000);
60 #endif
61
62 MITK_INFO << "supposed to have waited 20ms \n";
63
64 double time_elapsed, relative_time_elapsed;
65
66 //gets time elapsed since start
68
69 MITK_INFO << "have actually waited : " << time_elapsed << "ms \n";
70
71 //elapsed time is not allowed to be too far from 20 ms (+-10ms)-> debugging "destroys" the correct value of course
72 MITK_TEST_CONDITION_REQUIRED((time_elapsed-20) > -10 , "Testing if elapsed time is correct (-10)");
73 //MITK_TEST_CONDITION_REQUIRED((time_elapsed-20) < 10 , "Testing if elapsed time is correct (+10)");
74
75 //second "device" starts tracking
77 MITK_INFO << "second device has started\n";
78 //first device stops
80 MITK_INFO << "first device has stopped tracking\n";
81
83 relative_time_elapsed = mitk::IGTTimeStamp::GetInstance()->GetElapsed(tester2);
84
85 MITK_INFO << "time elapsed supposed to be greater than 20 ms\n";
86 MITK_INFO << time_elapsed << " actually elapsed\n";
87
88 MITK_INFO << "relative time elapsed supposed to be smaller than absolute time elapsed : \n";
89 MITK_INFO << relative_time_elapsed << " actually elapsed\n";
90
91 //relative timespan must be smaller than absolute timespan
92 MITK_TEST_CONDITION_REQUIRED( time_elapsed > relative_time_elapsed , " testing if relative timespan is shorter than absolute timespan");
93
94 //timestamp still has to be valid (tester2 still tracking), and has to be larger than 20ms
95 //MITK_TEST_CONDITION_REQUIRED( time_elapsed > 15 , "testing if second device is still keeping the TimeStamp \"alive\"");
96
98 MITK_INFO << " second device has stopped tracking\n";
100
101 //when all devices have stopped, -1 has to be returned
102 MITK_TEST_CONDITION_REQUIRED( time_elapsed == -1 , "testing if -1 is returned after all devices have stopped");
103
104 //test set realtime clock
105 mitk::RealTimeClock::Pointer myRealTimeClock = mitk::RealTimeClock::New();
107
108 // always end with this!
109 MITK_TEST_END();
110
111}
112
113
static IGTTimeStamp * CreateInstance()
creates a new instance of mitkTimeStamp
static IGTTimeStamp * GetInstance()
returns a pointer to the current instance of mitkTimeStamp
void Start(itk::Object::Pointer device)
starts the time-acquisition
void Stop(itk::Object::Pointer device)
stops the time-acqusition
double GetElapsed()
returns the time elapsed since calling Start() for the first time in milliseconds
void SetRealTimeClock(mitk::RealTimeClock::Pointer Clock)
setter for the internally used RealTimeClock()
double GetOffset(itk::Object::Pointer Device)
returns the offset of this device's starting-time to the reference-time in ms
static Pointer New(void)
instanciates a new, operating-system dependant, instance of mitk::RealTimeClock.
int mitkTimeStampTest(int, char *[])