Index: test/SchedulerTest.cpp |
=================================================================== |
--- a/test/SchedulerTest.cpp |
+++ b/test/SchedulerTest.cpp |
@@ -60,17 +60,44 @@ |
EXPECT_EQ(1, counter); |
} |
+struct RudimentaryTask |
+ : public TaskFunctionInterface |
+{ |
+ std::function<void()> f; |
+ RudimentaryTask(std::function<void()> f) |
+ : f(f) |
+ {} |
+ virtual void operator()() override |
+ { |
+ f(); |
+ } |
+ virtual void Interrupt() override |
+ {} |
+}; |
+ |
+std::shared_ptr<RudimentaryTask> MakeRudimentaryTask(std::function<void()> f) |
+{ |
+ return std::make_shared<RudimentaryTask>(f); |
+} |
+ |
+struct NullUserData {}; |
+ |
TEST(Scheduler, Instance) |
{ |
- SchedulerT<SingleUseWorker> s; |
+ SchedulerT<SingleUseWorker, NullUserData> s; |
} |
+std::shared_ptr<NullUserData> MakeNullUserData() |
+{ |
+ return std::shared_ptr<NullUserData>(); |
+} |
+ |
TEST(Scheduler, RunOnce) |
{ |
int counter = 0; |
- SchedulerT<SingleUseWorker> s; |
+ SchedulerT<SingleUseWorker, NullUserData> s; |
EXPECT_EQ(0, counter); |
- s.Run([&]() {++counter; }); |
+ s.Run(MakeRudimentaryTask([&]() {++counter; }), MakeNullUserData()); |
s.JoinAll(); |
EXPECT_EQ(1, counter); |
} |
@@ -78,10 +105,10 @@ |
TEST(Scheduler, RunTwice) |
{ |
int counter = 0; |
- SchedulerT<SingleUseWorker> s; |
- s.Run([&]() {++counter; }); |
+ SchedulerT<SingleUseWorker, NullUserData> s; |
+ s.Run(MakeRudimentaryTask([&]() {++counter; }), MakeNullUserData()); |
s.JoinAll(); |
- s.Run([&]() {++counter; }); |
+ s.Run(MakeRudimentaryTask([&]() {++counter; }), MakeNullUserData()); |
s.JoinAll(); |
EXPECT_EQ(2, counter); |
} |
@@ -90,7 +117,7 @@ |
{ |
std::mutex m; |
int counter = 0; |
- SchedulerT<SingleUseWorker> s; |
+ SchedulerT<SingleUseWorker, NullUserData> s; |
auto f = [&]() { |
std::unique_lock<std::mutex> ul(m); |
++counter; |
@@ -99,7 +126,7 @@ |
for (int j = 0; j < n; ++j) |
{ |
auto g = f; |
- s.Run(g); |
+ s.Run(MakeRudimentaryTask(g), MakeNullUserData()); |
} |
ASSERT_NO_THROW(s.JoinAll()); |
EXPECT_EQ(n, counter); |