diff options
author | Geir Storli <geirst@verizonmedia.com> | 2019-02-18 14:18:25 +0000 |
---|---|---|
committer | Geir Storli <geirst@verizonmedia.com> | 2019-02-18 14:18:25 +0000 |
commit | 7cdf46e48695488110b05027e1d76963d4c4db6f (patch) | |
tree | 6b6d896c78471aa6b4a511a1568a5de772292b5c /storageframework/src | |
parent | a0d5c322fa46e5e3ddc57eb2bfab09b792bd604c (diff) |
Add gtest runner in storageframework and migrate timetest from CppUnit to gtest.
Diffstat (limited to 'storageframework/src')
-rw-r--r-- | storageframework/src/tests/.gitignore | 1 | ||||
-rw-r--r-- | storageframework/src/tests/CMakeLists.txt | 19 | ||||
-rw-r--r-- | storageframework/src/tests/clock/CMakeLists.txt | 1 | ||||
-rw-r--r-- | storageframework/src/tests/clock/timetest.cpp | 72 | ||||
-rw-r--r-- | storageframework/src/tests/gtest_runner.cpp | 14 |
5 files changed, 59 insertions, 48 deletions
diff --git a/storageframework/src/tests/.gitignore b/storageframework/src/tests/.gitignore index 9124b7b5751..94b0b80fe52 100644 --- a/storageframework/src/tests/.gitignore +++ b/storageframework/src/tests/.gitignore @@ -2,4 +2,5 @@ /Makefile /test.vlog /testrunner +storageframework_gtest_runner_app storageframework_testrunner_app diff --git a/storageframework/src/tests/CMakeLists.txt b/storageframework/src/tests/CMakeLists.txt index 0d604d64f74..0e562508d4c 100644 --- a/storageframework/src/tests/CMakeLists.txt +++ b/storageframework/src/tests/CMakeLists.txt @@ -1,9 +1,26 @@ # Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +# Runner for unit tests written in gtest. +# NOTE: All new test classes should be added here. +vespa_add_executable(storageframework_gtest_runner_app TEST + SOURCES + gtest_runner.cpp + DEPENDS + storageframework_testclock + gtest +) + +vespa_add_test( + NAME storageframework_gtest_runner_app + COMMAND storageframework_gtest_runner_app + DEPENDS storageframework_gtest_runner_app +) + +# Runner for unit tests written in CppUnit (DEPRECATED). vespa_add_executable(storageframework_testrunner_app TEST SOURCES testrunner.cpp DEPENDS - storageframework_testclock storageframework_teststatus storageframework_testthread ) 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 +} diff --git a/storageframework/src/tests/gtest_runner.cpp b/storageframework/src/tests/gtest_runner.cpp new file mode 100644 index 00000000000..ce0310d7fa1 --- /dev/null +++ b/storageframework/src/tests/gtest_runner.cpp @@ -0,0 +1,14 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <gtest/gtest.h> + +#include <vespa/log/log.h> +LOG_SETUP("storageframework_gtest_runner"); + +int +main(int argc, char* argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + |