Skip to content

Commit

Permalink
EHN: Test improved for time stamp message
Browse files Browse the repository at this point in the history
  • Loading branch information
leochan2009 committed Jun 5, 2017
1 parent d45c558 commit e042cb4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ TARGET_LINK_LIBRARIES(igtlMultiThreaderTest1 OpenIGTLink)
TARGET_LINK_LIBRARIES(igtlMultiThreaderTest2 OpenIGTLink)
TARGET_LINK_LIBRARIES(igtlMultiThreaderTest3 OpenIGTLink)
TARGET_LINK_LIBRARIES(igtlMessageFactoryTest OpenIGTLink)
TARGET_LINK_LIBRARIES(igtlTimeStampTest1 OpenIGTLink)
TARGET_LINK_LIBRARIES(igtlTimeStampTest1 ${GTEST_LINK})
TARGET_LINK_LIBRARIES(igtlMessageBaseTest ${GTEST_LINK})
TARGET_LINK_LIBRARIES(igtlConditionVariableTest ${GTEST_LINK})

Expand Down
33 changes: 25 additions & 8 deletions Testing/igtlTimeStampTest1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
=========================================================================*/

#include <igtlTimeStamp.h>

#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#include "igtlOSUtil.h"
#include "igtlTestConfig.h"

#include <iostream>

int main(int, char * [] )
{
TEST(TimeStampTest, SetTime){
// Simply testing Setter/Getter
igtl::TimeStamp::Pointer ts = igtl::TimeStamp::New();
ts->GetTime();
Expand All @@ -29,15 +27,34 @@ int main(int, char * [] )
ts->SetTimeInNanoseconds(totalNanosSinceEpochBefore);

igtlUint64 totalNanosSinceEpochAfter = ts->GetTimeStampInNanoseconds();
EXPECT_EQ(totalNanosSinceEpochAfter, totalNanosSinceEpochBefore);
if (totalNanosSinceEpochAfter != totalNanosSinceEpochBefore)
{
std::cerr << "Expected totalNanosSinceEpochBefore=" << totalNanosSinceEpochBefore << " to equal totalNanosSinceEpochAfter=" << totalNanosSinceEpochAfter << std::endl;
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}
TEST(TimeStampTest, GetTimeInterval)
{
for (int i = 0; i < 10; i++)
{
igtl::TimeStamp::Pointer ts_pre = igtl::TimeStamp::New();
ts_pre->GetTime();
igtlUint64 nanoTimePre = ts_pre->GetTimeStampInNanoseconds();
igtl::Sleep(20);
igtl::TimeStamp::Pointer ts_post = igtl::TimeStamp::New();
ts_post->GetTime();
igtlUint64 nanoTimePost = ts_post->GetTimeStampInNanoseconds();
std::cerr << "Time Pre: " << nanoTimePre << "Time Post: " << nanoTimePost << std::endl;
EXPECT_NE(nanoTimePost, nanoTimePre);
}
}


int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}



Expand Down

0 comments on commit e042cb4

Please sign in to comment.