diff options
author | Geir Storli <geirst@verizonmedia.com> | 2019-05-07 14:28:37 +0000 |
---|---|---|
committer | Geir Storli <geirst@verizonmedia.com> | 2019-05-07 14:28:37 +0000 |
commit | c35c529c5500abaaa182701e5beeb0e171bcdfec (patch) | |
tree | 4794cdd94ed7e9a7297984ba975e3b9b729fb628 /metrics | |
parent | 231477602105f19e232fdb7fce3f7d0912028b64 (diff) |
Rewrite tests to use gtest.
Diffstat (limited to 'metrics')
-rw-r--r-- | metrics/src/tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | metrics/src/tests/loadmetrictest.cpp | 53 | ||||
-rw-r--r-- | metrics/src/tests/summetrictest.cpp | 65 |
3 files changed, 45 insertions, 77 deletions
diff --git a/metrics/src/tests/CMakeLists.txt b/metrics/src/tests/CMakeLists.txt index 2c69b83d4b7..11d59e63c30 100644 --- a/metrics/src/tests/CMakeLists.txt +++ b/metrics/src/tests/CMakeLists.txt @@ -5,6 +5,8 @@ vespa_add_executable(metrics_gtest_runner_app TEST SOURCES countmetrictest.cpp + loadmetrictest.cpp + summetrictest.cpp gtest_runner.cpp DEPENDS metrics @@ -23,9 +25,7 @@ vespa_add_executable(metrics_testrunner_app TEST testrunner.cpp valuemetrictest.cpp metricsettest.cpp - summetrictest.cpp metricmanagertest.cpp - loadmetrictest.cpp snapshottest.cpp stresstest.cpp metrictest.cpp diff --git a/metrics/src/tests/loadmetrictest.cpp b/metrics/src/tests/loadmetrictest.cpp index 5cbec2c4fae..b89628f4476 100644 --- a/metrics/src/tests/loadmetrictest.cpp +++ b/metrics/src/tests/loadmetrictest.cpp @@ -3,7 +3,7 @@ #include <vespa/metrics/valuemetric.h> #include <vespa/metrics/loadmetric.hpp> #include <vespa/metrics/summetric.hpp> -#include <vespa/vdstestlib/cppunit/macros.h> +#include <vespa/vespalib/gtest/gtest.h> namespace metrics { @@ -20,30 +20,11 @@ struct LoadTypeSetImpl : public LoadTypeSet { const LoadType& lt(LoadTypeSet::operator[](i)); if (lt.getName() == name) return lt; } - CPPUNIT_FAIL("No load type with name " + name); - return operator[](0); // Should never get here + abort(); } }; -struct LoadMetricTest : public CppUnit::TestFixture { - void testNormalUsage(); - void testClone(Metric::CopyType); - void testInactiveCopy() { testClone(Metric::INACTIVE); } - void testActiveCopy() { testClone(Metric::CLONE); } - void testAdding(); - - CPPUNIT_TEST_SUITE(LoadMetricTest); - CPPUNIT_TEST(testNormalUsage); - CPPUNIT_TEST(testActiveCopy); - CPPUNIT_TEST(testInactiveCopy); - CPPUNIT_TEST(testAdding); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(LoadMetricTest); - -void -LoadMetricTest::testNormalUsage() +TEST(LoadMetricTest, test_normal_usage) { LoadTypeSetImpl loadTypes; loadTypes.add(32, "foo").add(1000, "bar"); @@ -76,7 +57,7 @@ namespace { } void -LoadMetricTest::testClone(Metric::CopyType copyType) +test_clone(Metric::CopyType copyType) { LoadTypeSetImpl loadTypes; loadTypes.add(32, "foo").add(1000, "bar"); @@ -87,7 +68,7 @@ LoadMetricTest::testClone(Metric::CopyType copyType) std::vector<Metric::UP> ownerList; MetricSet::UP copy(dynamic_cast<MetricSet*>(top.clone(ownerList, copyType, 0, true))); - CPPUNIT_ASSERT(copy.get()); + ASSERT_TRUE(copy.get()); std::string expected = "top:\n" @@ -101,12 +82,21 @@ LoadMetricTest::testClone(Metric::CopyType copyType) " bar:\n" " tack average=0 last=0 count=0 total=0"; - CPPUNIT_ASSERT_EQUAL(expected, std::string(top.toString(true))); - CPPUNIT_ASSERT_EQUAL(expected, std::string(copy->toString(true))); + EXPECT_EQ(expected, std::string(top.toString(true))); + EXPECT_EQ(expected, std::string(copy->toString(true))); } -void -LoadMetricTest::testAdding() +TEST(LoadMetricTest, test_inactive_copy) +{ + test_clone(Metric::INACTIVE); +} + +TEST(LoadMetricTest, test_active_copy) +{ + test_clone(Metric::CLONE); +} + +TEST(LoadMetricTest, test_adding) { LoadTypeSetImpl loadTypes; loadTypes.add(32, "foo").add(1000, "bar"); @@ -118,7 +108,7 @@ LoadMetricTest::testAdding() std::vector<Metric::UP> ownerList; MetricSet::UP copy(dynamic_cast<MetricSet*>( top.clone(ownerList, Metric::INACTIVE, 0, false))); - CPPUNIT_ASSERT(copy.get()); + ASSERT_TRUE(copy.get()); top.reset(); @@ -132,8 +122,7 @@ LoadMetricTest::testAdding() " foo:\n" " tack average=5 last=5 min=5 max=5 count=1 total=5"; - CPPUNIT_ASSERT_EQUAL(expected, std::string(copy->toString(true))); - + EXPECT_EQ(expected, std::string(copy->toString(true))); } -} // documentapi +} diff --git a/metrics/src/tests/summetrictest.cpp b/metrics/src/tests/summetrictest.cpp index 32c5ee2c309..e3d58659daf 100644 --- a/metrics/src/tests/summetrictest.cpp +++ b/metrics/src/tests/summetrictest.cpp @@ -1,29 +1,10 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/metrics/metrics.h> -#include <vespa/vdstestlib/cppunit/macros.h> +#include <vespa/vespalib/gtest/gtest.h> namespace metrics { -struct SumMetricTest : public CppUnit::TestFixture { - void testLongCountMetric(); - void testAverageMetric(); - void testMetricSet(); - void testRemove(); - void testStartValue(); - - CPPUNIT_TEST_SUITE(SumMetricTest); - CPPUNIT_TEST(testLongCountMetric); - CPPUNIT_TEST(testAverageMetric); - CPPUNIT_TEST(testMetricSet); - CPPUNIT_TEST(testRemove); - CPPUNIT_TEST(testStartValue); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(SumMetricTest); - -void -SumMetricTest::testLongCountMetric() +TEST(SumMetricTest, test_long_count_metric) { MetricSet parent("parent", {}, ""); SumMetric<LongCountMetric> sum("foo", {}, "foodesc", &parent); @@ -40,12 +21,12 @@ SumMetricTest::testLongCountMetric() // Verify XML output. Should be in register order. std::string expected("foo count=10"); - CPPUNIT_ASSERT_EQUAL(expected, sum.toString()); - CPPUNIT_ASSERT_EQUAL(int64_t(10), sum.getLongValue("value")); + EXPECT_EQ(expected, sum.toString()); + EXPECT_EQ(int64_t(10), sum.getLongValue("value")); } -void -SumMetricTest::testAverageMetric() { +TEST(SumMetricTest, test_average_metric) +{ MetricSet parent("parent", {}, ""); SumMetric<LongAverageMetric> sum("foo", {}, "foodesc", &parent); @@ -61,14 +42,14 @@ SumMetricTest::testAverageMetric() { // Verify XML output. Should be in register order. std::string expected("foo average=5 last=7 min=3 max=7 count=2 total=10"); - CPPUNIT_ASSERT_EQUAL(expected, sum.toString()); - CPPUNIT_ASSERT_EQUAL(int64_t(5), sum.getLongValue("value")); - CPPUNIT_ASSERT_EQUAL(int64_t(3), sum.getLongValue("min")); - CPPUNIT_ASSERT_EQUAL(int64_t(7), sum.getLongValue("max")); + EXPECT_EQ(expected, sum.toString()); + EXPECT_EQ(int64_t(5), sum.getLongValue("value")); + EXPECT_EQ(int64_t(3), sum.getLongValue("min")); + EXPECT_EQ(int64_t(7), sum.getLongValue("max")); } -void -SumMetricTest::testMetricSet() { +TEST(SumMetricTest, test_metric_set) +{ MetricSet parent("parent", {}, ""); SumMetric<MetricSet> sum("foo", {}, "bar", &parent); @@ -82,23 +63,22 @@ SumMetricTest::testMetricSet() { sum.addMetricToSum(set1); sum.addMetricToSum(set2); - // Give them some values + // Give them some values v1.addValue(3); v2.addValue(7); v3.inc(2); v4.inc(); - // Verify XML output. Should be in register order. + // Verify XML output. Should be in register order. std::string expected("'\n" "foo:\n" " c average=3 last=3 min=3 max=3 count=1 total=3\n" " e count=2'" ); - CPPUNIT_ASSERT_EQUAL(expected, "'\n" + sum.toString() + "'"); + EXPECT_EQ(expected, "'\n" + sum.toString() + "'"); } -void -SumMetricTest::testRemove() +TEST(SumMetricTest, test_remove) { MetricSet parent("parent", {}, ""); SumMetric<LongCountMetric> sum("foo", {}, "foodesc", &parent); @@ -116,13 +96,12 @@ SumMetricTest::testRemove() v2.inc(7); v3.inc(10); - CPPUNIT_ASSERT_EQUAL(int64_t(20), sum.getLongValue("value")); + EXPECT_EQ(int64_t(20), sum.getLongValue("value")); sum.removeMetricFromSum(v2); - CPPUNIT_ASSERT_EQUAL(int64_t(13), sum.getLongValue("value")); + EXPECT_EQ(int64_t(13), sum.getLongValue("value")); } -void -SumMetricTest::testStartValue() +TEST(SumMetricTest, test_start_value) { MetricSnapshot snapshot("active"); SumMetric<LongValueMetric> sum("foo", {}, "foodesc", @@ -132,7 +111,7 @@ SumMetricTest::testStartValue() sum.setStartValue(start); // without children - CPPUNIT_ASSERT_EQUAL(int64_t(50), sum.getLongValue("value")); + EXPECT_EQ(int64_t(50), sum.getLongValue("value")); MetricSnapshot copy("copy"); copy.recreateSnapshot(snapshot.getMetrics(), true); @@ -143,7 +122,7 @@ SumMetricTest::testStartValue() value.set(10); // with children - CPPUNIT_ASSERT_EQUAL(int64_t(60), sum.getLongValue("value")); + EXPECT_EQ(int64_t(60), sum.getLongValue("value")); } -} // metrics +} |