Kata Step One
Our first test verifies that when a BoundedQueue is created, it tells the Producer it can start enqueuing items.
BoundedQueueTest.cpp
TEST(BoundedQueueTest, CreateResumesProducer) {
MockQueueControl producer;
EXPECT_CALL(producer, Resume());
BoundedQueue<int> q(producer);
}Now when we "make" we get compiler errors. Let's see... The first compiler error is 'class MockQueueControl' has no member named 'gmock_Resume'
That seems reasonable. We want our QueueControl interface to have a method called Resume(). We don't need it to take any parameters or return any value.
Let's add the void Resume() method to our mock, and to our interface.
BoundedQueueTest.cpp
class MockQueueControl : public QueueControl {
public:
MOCK_METHOD0(Resume, void());
};QueueControl.h
class QueueControl {
public:
...
virtual void Resume() = 0;
};We should be down to one compiler error when we "make". no matching function for call to 'BoundedQueue<int>::BoundedQueue(MockQueueControl&)'
Looks like we need to add a constructor for BoundedQueue:
BoundedQueue.h
template <typename T>
class BoundedQueue {
public:
BoundedQueue(QueueControl& producer) {}So now we should be able to compile.
And voila! The test now fails.
Congratulations, you have a failing test, you can now write some code!
You may want to take a minute to see if you can make the test pass on your own. Or read on:
OK, what's the simplest thing we can do to make the test pass?
Just call Resume() when the BoundedQueue gets constructed.
BoundedQueue.h
template <typename T>
class BoundedQueue {
public:
BoundedQueue(QueueControl& producer) {
producer.Resume();
}
};Woo-hoo! Green bar!
Go on to BoundedQueueKataStepTwo.... or go back
