iodrivers_base
FixtureGTest.hpp
Go to the documentation of this file.
1 #ifndef IODRIVERS_BASE_GTEST_HPP
2 #define IODRIVERS_BASE_GTEST_HPP
3 
4 #include <gtest/gtest.h>
5 #include <iodrivers_base/Fixture.hpp>
6 
7 #define IODRIVERS_BASE_MOCK() iodrivers_base::Fixture<fixture_driver_t>::GTestMockContext __context(this);
8 
9 namespace iodrivers_base {
10  template<typename Driver>
12  {
13  public:
15  GTestMockContext(Fixture* fixture): fixture(fixture)
16  {
17  fixture->setMockMode(true);
18  }
27  void tearDown()
28  {
29  try
30  {
31  fixture->validateExpectationsAreEmpty();
32  }
34  {
35  ADD_FAILURE() << "IODRIVERS_BASE_MOCK Error: Test reached its end without satisfying all expecations.";
36  }
37  }
38 
40  {
41  fixture->setMockMode(false);
42  fixture->clearExpectations();
43  tearDown();
44  }
45 
46  };
47 }
48 
49 #endif
Fixture * fixture
Definition: FixtureGTest.hpp:14
GTestMockContext(Fixture *fixture)
Definition: FixtureGTest.hpp:15
Definition: Driver.hpp:69
void setMockMode(bool mode)
Definition: Fixture.hpp:182
~GTestMockContext()
Definition: FixtureGTest.hpp:39
Definition: Fixture.hpp:76
void tearDown()
Definition: FixtureGTest.hpp:27
Definition: FixtureGTest.hpp:11
Definition: Exceptions.hpp:44