1
0
mirror of https://github.com/PerMalmberg/libcron.git synced 2025-12-20 11:02:48 -06:00

Added LocalClock.

This commit is contained in:
Per Malmberg
2018-03-11 23:38:12 +01:00
parent 582d0c4369
commit 9f7c5dc2fa
5 changed files with 44 additions and 26 deletions

View File

@@ -6,9 +6,9 @@
using namespace libcron;
using namespace std::chrono;
std::string create_schedule_expiring_in(hours h, minutes m, seconds s)
std::string create_schedule_expiring_in(std::shared_ptr<ICronClock> clock, hours h, minutes m, seconds s)
{
auto now = system_clock::now() + h + m + s;
auto now = clock->now() + h + m + s;
auto dt = CronSchedule::to_calendar_time(now);
std::string res{};
@@ -66,7 +66,7 @@ SCENARIO("Adding a task that expires in the future")
auto expired = false;
Cron c;
REQUIRE(c.add_schedule("A task", create_schedule_expiring_in(hours{0}, minutes{0}, seconds{3}),
REQUIRE(c.add_schedule("A task", create_schedule_expiring_in(c.get_clock(), hours{0}, minutes{0}, seconds{3}),
[&expired]()
{
expired = true;
@@ -107,14 +107,14 @@ SCENARIO("Task priority")
Cron c;
REQUIRE(c.add_schedule("Five", create_schedule_expiring_in(hours{0}, minutes{0}, seconds{5}),
REQUIRE(c.add_schedule("Five", create_schedule_expiring_in(c.get_clock(), hours{0}, minutes{0}, seconds{5}),
[&_5_second_expired]()
{
_5_second_expired++;
})
);
REQUIRE(c.add_schedule("Three", create_schedule_expiring_in(hours{0}, minutes{0}, seconds{3}),
REQUIRE(c.add_schedule("Three", create_schedule_expiring_in(c.get_clock(), hours{0}, minutes{0}, seconds{3}),
[&_3_second_expired]()
{
_3_second_expired++;