Still Simply Test-Driving
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(); ... |
Get Modern C++ Programming with Test-Driven Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.