2021-10-17 20:12:33 +00:00
|
|
|
#include <components/misc/progressreporter.hpp>
|
|
|
|
|
|
|
|
#include <gmock/gmock.h>
|
2022-09-22 18:26:05 +00:00
|
|
|
#include <gtest/gtest.h>
|
2021-10-17 20:12:33 +00:00
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using namespace testing;
|
|
|
|
using namespace Misc;
|
|
|
|
|
|
|
|
struct ReportMock
|
|
|
|
{
|
|
|
|
MOCK_METHOD(void, call, (std::size_t, std::size_t), ());
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Report
|
|
|
|
{
|
|
|
|
StrictMock<ReportMock>* mImpl;
|
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
void operator()(std::size_t provided, std::size_t expected) { mImpl->call(provided, expected); }
|
2021-10-17 20:12:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST(MiscProgressReporterTest, shouldCallReportWhenPassedInterval)
|
|
|
|
{
|
|
|
|
StrictMock<ReportMock> report;
|
|
|
|
EXPECT_CALL(report, call(13, 42)).WillOnce(Return());
|
2022-09-22 18:26:05 +00:00
|
|
|
ProgressReporter reporter(std::chrono::steady_clock::duration(0), Report{ &report });
|
2021-10-17 20:12:33 +00:00
|
|
|
reporter(13, 42);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MiscProgressReporterTest, shouldNotCallReportWhenIntervalIsNotPassed)
|
|
|
|
{
|
|
|
|
StrictMock<ReportMock> report;
|
|
|
|
EXPECT_CALL(report, call(13, 42)).Times(0);
|
2022-09-22 18:26:05 +00:00
|
|
|
ProgressReporter reporter(std::chrono::seconds(1000), Report{ &report });
|
2021-10-17 20:12:33 +00:00
|
|
|
reporter(13, 42);
|
|
|
|
}
|
|
|
|
}
|