Save properties to persistent storage when host is on
1. When host is on, set properties as requested properties instead
of notify listeners;
2. When host becomes off, and requested properties are not empty, notify
the listners and reset the requested properties.
Add unit tests.
Change-Id: I9359c801c698df0c6e5eab43e12427bb5a6da611
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/test/TestHostEpoch.cpp b/test/TestHostEpoch.cpp
index ec8ecf1..0ff8a11 100644
--- a/test/TestHostEpoch.cpp
+++ b/test/TestHostEpoch.cpp
@@ -2,6 +2,7 @@
#include <gtest/gtest.h>
#include "host_epoch.hpp"
+#include "utils.hpp"
#include "config.h"
#include "types.hpp"
@@ -45,16 +46,6 @@
{
return hostEpoch.timeOwner;
}
- template <typename T>
- T readData(const char* fileName)
- {
- return HostEpoch::readData<T>(fileName);
- }
- template <typename T>
- void writeData(const char* fileName, T&& data)
- {
- HostEpoch::writeData<T>(fileName, std::forward<T>(data));
- }
microseconds getOffset()
{
return hostEpoch.offset;
@@ -75,7 +66,7 @@
{
// When file does not exist, the default offset shall be 0
microseconds offset(0);
- auto value = readData<decltype(offset)::rep>(FILE_NOT_EXIST);
+ auto value = utils::readData<decltype(offset)::rep>(FILE_NOT_EXIST);
EXPECT_EQ(0, value);
}
@@ -83,12 +74,13 @@
{
// Write offset to file
microseconds offsetToWrite(1234567);
- writeData<decltype(offsetToWrite)::rep>(FILE_OFFSET, offsetToWrite.count());
+ utils::writeData<decltype(offsetToWrite)::rep>(
+ FILE_OFFSET, offsetToWrite.count());
// Read it back
microseconds offsetToRead;
offsetToRead = microseconds(
- readData<decltype(offsetToRead)::rep>(FILE_OFFSET));
+ utils::readData<decltype(offsetToRead)::rep>(FILE_OFFSET));
EXPECT_EQ(offsetToWrite, offsetToRead);
}