From 4f51c2df452ceb48d2d91869f98772915ccce5e8 Mon Sep 17 00:00:00 2001 From: Vladimir Romanov Date: Sun, 8 Dec 2024 17:15:41 +0100 Subject: [PATCH] Improve coverage --- src/HistoryCounters.cpp | 5 +---- tests/TestHistoryCounters.cpp | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/HistoryCounters.cpp b/src/HistoryCounters.cpp index bc8037c..12e19c3 100644 --- a/src/HistoryCounters.cpp +++ b/src/HistoryCounters.cpp @@ -18,10 +18,7 @@ bool HistoryCountersClear() { if (counters_suffix) { STRNCAT(name, counters_suffix); } - if (!remove_test_file(name)) { - return false; - } - return true; + return remove_test_file(name); } HistoryCounterData *HistoryCounters::GetCounterPtr(const char *name) { diff --git a/tests/TestHistoryCounters.cpp b/tests/TestHistoryCounters.cpp index 6e05d9e..6d7428c 100644 --- a/tests/TestHistoryCounters.cpp +++ b/tests/TestHistoryCounters.cpp @@ -19,8 +19,22 @@ TEST_F(TestHistoryCounters, Open) { TEST_F(TestHistoryCounters, GetIndex) { EXPECT_TRUE(HistoryCountersClear()); - EXPECT_EQ(0, GetHistoryCounters().GetCounterIndex(TEST_COUNTER ".c1")); - EXPECT_EQ(1, GetHistoryCounters().GetCounterIndex(TEST_COUNTER ".c2")); + for (int i = 0; i < COUNTER_MAX_AMOUNT_HISTORY; i++) { + char cn[100]; + snprintf(cn, sizeof(cn), TEST_COUNTER ".%05d", i); + EXPECT_EQ(i, GetHistoryCounters().GetCounterIndex(cn)); + } + EXPECT_EQ(DICTIONARY_INVALID_INDEX, GetHistoryCounters().GetCounterIndex("xxx")); +} + +TEST_F(TestHistoryCounters, GetCounterPtr) { + EXPECT_TRUE(HistoryCountersClear()); + for (int i = 0; i < COUNTER_MAX_AMOUNT_HISTORY; i++) { + char cn[100]; + snprintf(cn, sizeof(cn), TEST_COUNTER ".%05d", i); + EXPECT_NE(nullptr, GetHistoryCounters().GetCounterPtr(cn)); + } + EXPECT_EQ(nullptr, GetHistoryCounters().GetCounterPtr("xxx")); } static void FillTestData(ClockOverride& co, HistoryCounter& c1, HistoryCounter& c2, HistoryCounter& c3) {