aboutsummaryrefslogtreecommitdiffstats
path: root/storageframework/src/tests/clock
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-02-18 14:18:25 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-02-18 14:18:25 +0000
commit7cdf46e48695488110b05027e1d76963d4c4db6f (patch)
tree6b6d896c78471aa6b4a511a1568a5de772292b5c /storageframework/src/tests/clock
parenta0d5c322fa46e5e3ddc57eb2bfab09b792bd604c (diff)
Add gtest runner in storageframework and migrate timetest from CppUnit to gtest.
Diffstat (limited to 'storageframework/src/tests/clock')
-rw-r--r--storageframework/src/tests/clock/CMakeLists.txt1
-rw-r--r--storageframework/src/tests/clock/timetest.cpp72
2 files changed, 26 insertions, 47 deletions
diff --git a/storageframework/src/tests/clock/CMakeLists.txt b/storageframework/src/tests/clock/CMakeLists.txt
index 66b175d81ad..f887de61239 100644
--- a/storageframework/src/tests/clock/CMakeLists.txt
+++ b/storageframework/src/tests/clock/CMakeLists.txt
@@ -4,4 +4,5 @@ vespa_add_library(storageframework_testclock
timetest.cpp
DEPENDS
storageframework
+ gtest
)
diff --git a/storageframework/src/tests/clock/timetest.cpp b/storageframework/src/tests/clock/timetest.cpp
index d1fd3b7b1bb..1bbd075ffb2 100644
--- a/storageframework/src/tests/clock/timetest.cpp
+++ b/storageframework/src/tests/clock/timetest.cpp
@@ -2,80 +2,58 @@
#include <vespa/storageframework/generic/clock/time.h>
#include <vespa/storageframework/defaultimplementation/clock/fakeclock.h>
-#include <vespa/vdstestlib/cppunit/macros.h>
+#include <gtest/gtest.h>
-namespace storage {
-namespace framework {
-namespace defaultimplementation {
+namespace storage::framework::defaultimplementation {
-struct TimeTest : public CppUnit::TestFixture
-{
- void testBasics();
- void testCreatedFromClock();
- void canAssignMicrosecondResolutionTimeToFakeClock();
-
- CPPUNIT_TEST_SUITE(TimeTest);
- CPPUNIT_TEST(testBasics); // Fails sometimes, test needs rewrite.
- CPPUNIT_TEST(testCreatedFromClock);
- CPPUNIT_TEST(canAssignMicrosecondResolutionTimeToFakeClock);
- CPPUNIT_TEST_SUITE_END();
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(TimeTest);
-
-void
-TimeTest::testBasics()
+TEST(TimeTest, testBasics)
{
SecondTime timeSec(1);
MilliSecTime timeMillis = timeSec.getMillis();
- CPPUNIT_ASSERT_EQUAL(uint64_t(1000), timeMillis.getTime());
- CPPUNIT_ASSERT_EQUAL(timeSec, timeMillis.getSeconds());
+ EXPECT_EQ(uint64_t(1000), timeMillis.getTime());
+ EXPECT_EQ(timeSec, timeMillis.getSeconds());
MicroSecTime timeMicros = timeSec.getMicros();
- CPPUNIT_ASSERT_EQUAL(timeSec.getMicros(), timeMillis.getMicros());
- CPPUNIT_ASSERT_EQUAL(timeMillis, timeMicros.getMillis());
- CPPUNIT_ASSERT_EQUAL(timeSec, timeMicros.getSeconds());
+ EXPECT_EQ(timeSec.getMicros(), timeMillis.getMicros());
+ EXPECT_EQ(timeMillis, timeMicros.getMillis());
+ EXPECT_EQ(timeSec, timeMicros.getSeconds());
MicroSecTime timeMicros2 = timeMicros;
- CPPUNIT_ASSERT(timeMicros2 == timeMicros);
+ EXPECT_EQ(timeMicros2, timeMicros);
timeMicros2 += MicroSecTime(25000);
- CPPUNIT_ASSERT(timeMicros2 > timeMicros);
- CPPUNIT_ASSERT(timeMicros < timeMicros2);
+ EXPECT_GT(timeMicros2, timeMicros);
+ EXPECT_LT(timeMicros, timeMicros2);
timeMicros2 -= MicroSecTime(30000);
- CPPUNIT_ASSERT(timeMicros2 < timeMicros);
- CPPUNIT_ASSERT(timeMicros > timeMicros2);
+ EXPECT_LT(timeMicros2, timeMicros);
+ EXPECT_GT(timeMicros, timeMicros2);
timeMicros2 += MicroSecTime(55000);
MilliSecTime timeMillis2 = timeMicros2.getMillis();
- CPPUNIT_ASSERT(timeMillis2 > timeMillis);
- CPPUNIT_ASSERT_EQUAL(uint64_t(1050), timeMillis2.getTime());
- CPPUNIT_ASSERT_EQUAL(timeSec, timeMillis2.getSeconds());
+ EXPECT_GT(timeMillis2, timeMillis);
+ EXPECT_EQ(uint64_t(1050), timeMillis2.getTime());
+ EXPECT_EQ(timeSec, timeMillis2.getSeconds());
}
-void
-TimeTest::testCreatedFromClock()
+TEST(TimeTest, testCreatedFromClock)
{
defaultimplementation::FakeClock clock;
clock.setAbsoluteTimeInSeconds(600);
- CPPUNIT_ASSERT_EQUAL(SecondTime(600), SecondTime(clock));
- CPPUNIT_ASSERT_EQUAL(MilliSecTime(600 * 1000), MilliSecTime(clock));
- CPPUNIT_ASSERT_EQUAL(MicroSecTime(600 * 1000 * 1000), MicroSecTime(clock));
+ EXPECT_EQ(SecondTime(600), SecondTime(clock));
+ EXPECT_EQ(MilliSecTime(600 * 1000), MilliSecTime(clock));
+ EXPECT_EQ(MicroSecTime(600 * 1000 * 1000), MicroSecTime(clock));
}
-void
-TimeTest::canAssignMicrosecondResolutionTimeToFakeClock()
+TEST(TimeTest, canAssignMicrosecondResolutionTimeToFakeClock)
{
defaultimplementation::FakeClock clock;
clock.setAbsoluteTimeInMicroSeconds(1234567); // 1.234567 seconds
// All non-microsec time points must necessarily be truncated.
- CPPUNIT_ASSERT_EQUAL(SecondTime(1), SecondTime(clock));
- CPPUNIT_ASSERT_EQUAL(MilliSecTime(1234), MilliSecTime(clock));
- CPPUNIT_ASSERT_EQUAL(MicroSecTime(1234567), MicroSecTime(clock));
+ EXPECT_EQ(SecondTime(1), SecondTime(clock));
+ EXPECT_EQ(MilliSecTime(1234), MilliSecTime(clock));
+ EXPECT_EQ(MicroSecTime(1234567), MicroSecTime(clock));
}
-} // defaultimplementation
-} // framework
-} // storage
+}