Test: Use unique mocked utils for each test
The mocked utils object was shared between the tests because it's a
static object. This causes problems on expecting the number of
called the mocked functions.
Add a freeUtils() in mocked_utils.hpp, and call it in test fixture's
destructor, so that each test case will use a different mocked object.
Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I2622c678012d30b2bd75dc37a2bc3a663f40d86c
diff --git a/test/mocked_utils.hpp b/test/mocked_utils.hpp
index 85f5ffc..8c58a8e 100644
--- a/test/mocked_utils.hpp
+++ b/test/mocked_utils.hpp
@@ -33,10 +33,19 @@
const char* propertyName));
};
+static std::unique_ptr<MockedUtils> utils;
inline const UtilsInterface& getUtils()
{
- static MockedUtils utils;
- return utils;
+ if (!utils)
+ {
+ utils = std::make_unique<MockedUtils>();
+ }
+ return *utils;
+}
+
+inline void freeUtils()
+{
+ utils.reset();
}
} // namespace utils
diff --git a/test/test_activation.cpp b/test/test_activation.cpp
index f89475a..a402758 100644
--- a/test/test_activation.cpp
+++ b/test/test_activation.cpp
@@ -33,6 +33,7 @@
}
~TestActivation()
{
+ utils::freeUtils();
}
void onUpdateDone()
diff --git a/test/test_item_updater.cpp b/test/test_item_updater.cpp
index fb6ea93..ed55906 100644
--- a/test/test_item_updater.cpp
+++ b/test/test_item_updater.cpp
@@ -32,6 +32,7 @@
~TestItemUpdater()
{
+ utils::freeUtils();
}
const auto& GetActivations()