From e042cb448ced740381a5a4698f4dddc40c022999 Mon Sep 17 00:00:00 2001 From: Longquan Chen Date: Sun, 4 Jun 2017 10:45:11 -0400 Subject: [PATCH] EHN: Test improved for time stamp message --- Testing/CMakeLists.txt | 2 +- Testing/igtlTimeStampTest1.cxx | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 748b503a..b1e3c8ab 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -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}) diff --git a/Testing/igtlTimeStampTest1.cxx b/Testing/igtlTimeStampTest1.cxx index d509a7a2..cca4c4bc 100644 --- a/Testing/igtlTimeStampTest1.cxx +++ b/Testing/igtlTimeStampTest1.cxx @@ -12,14 +12,12 @@ =========================================================================*/ #include - -#define EXIT_SUCCESS 0 -#define EXIT_FAILURE 1 +#include "igtlOSUtil.h" +#include "igtlTestConfig.h" #include -int main(int, char * [] ) -{ +TEST(TimeStampTest, SetTime){ // Simply testing Setter/Getter igtl::TimeStamp::Pointer ts = igtl::TimeStamp::New(); ts->GetTime(); @@ -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(); +}