October 2013
Intermediate to advanced
368 pages
9h 20m
English
We move on to designing the ThreadPool class. Before we introduce threads, we test-drive some building blocks for handling requests.
| c9/5/ThreadPoolTest.cpp | |
| | #include "CppUTest/TestHarness.h" |
| | #include "ThreadPool.h" |
| | |
| | using namespace std; |
| | |
| | TEST_GROUP(AThreadPool) { |
| | ThreadPool pool; |
| | }; |
| | |
| | TEST(AThreadPool, HasNoWorkOnCreation) { |
| | CHECK_FALSE(pool.hasWork()); |
| | } |
| | |
| | TEST(AThreadPool, HasWorkAfterAdd) { |
| | pool.add(Work{}); |
| | CHECK_TRUE(pool.hasWork()); |
| | } |
| | |
| | TEST(AThreadPool, AnswersWorkAddedOnPull) { |
| | pool.add(Work{1}); |
| | auto work = pool.pullWork(); |
| | |
| | LONGS_EQUAL(1, work.id()); |
| | } |
| | |
| | TEST(AThreadPool, PullsElementsInFIFOOrder) { |
| | pool.add(Work{1}); |
| | pool.add(Work{2}); |
| | auto work = pool.pullWork(); ... |