Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 1 | #ifndef _AOS_EVENTS_EVENT_LOOP_PARAM_TEST_H_ |
| 2 | #define _AOS_EVENTS_EVENT_LOOP_PARAM_TEST_H_ |
| 3 | |
Neil Balch | 229001a | 2018-01-07 18:22:52 -0800 | [diff] [blame] | 4 | #include <vector> |
| 5 | |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 6 | #include "aos/events/event-loop.h" |
| 7 | #include "gtest/gtest.h" |
| 8 | |
| 9 | namespace aos { |
| 10 | namespace testing { |
| 11 | |
| 12 | class EventLoopTestFactory { |
| 13 | public: |
| 14 | virtual ~EventLoopTestFactory() {} |
| 15 | |
Austin Schuh | 44019f9 | 2019-05-19 19:58:27 -0700 | [diff] [blame] | 16 | // Makes a connected event loop. |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 17 | virtual std::unique_ptr<EventLoop> Make() = 0; |
Austin Schuh | 44019f9 | 2019-05-19 19:58:27 -0700 | [diff] [blame] | 18 | // Makes a primary event loop. This is the one the tests will try to use for |
| 19 | // anything blocking. |
| 20 | virtual std::unique_ptr<EventLoop> MakePrimary() = 0; |
| 21 | |
| 22 | // Runs the loops until they quit. |
| 23 | virtual void Run() = 0; |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 24 | }; |
| 25 | |
Austin Schuh | 6b6dfa5 | 2019-06-12 20:16:20 -0700 | [diff] [blame] | 26 | class AbstractEventLoopTestBase |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 27 | : public ::testing::TestWithParam<std::function<EventLoopTestFactory *()>> { |
| 28 | public: |
Austin Schuh | 6b6dfa5 | 2019-06-12 20:16:20 -0700 | [diff] [blame] | 29 | AbstractEventLoopTestBase() { factory_.reset(GetParam()()); } |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 30 | |
Austin Schuh | 44019f9 | 2019-05-19 19:58:27 -0700 | [diff] [blame] | 31 | ::std::unique_ptr<EventLoop> Make() { return factory_->Make(); } |
| 32 | ::std::unique_ptr<EventLoop> MakePrimary() { return factory_->MakePrimary(); } |
| 33 | |
| 34 | void Run() { return factory_->Run(); } |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 35 | // You can implement all the usual fixture class members here. |
| 36 | // To access the test parameter, call GetParam() from class |
| 37 | // TestWithParam<T>. |
| 38 | private: |
Austin Schuh | 44019f9 | 2019-05-19 19:58:27 -0700 | [diff] [blame] | 39 | ::std::unique_ptr<EventLoopTestFactory> factory_; |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 40 | }; |
| 41 | |
Austin Schuh | 6b6dfa5 | 2019-06-12 20:16:20 -0700 | [diff] [blame] | 42 | typedef AbstractEventLoopTestBase AbstractEventLoopDeathTest; |
| 43 | typedef AbstractEventLoopTestBase AbstractEventLoopTest; |
| 44 | |
Parker Schuh | e4a70d6 | 2017-12-27 20:10:20 -0800 | [diff] [blame] | 45 | } // namespace testing |
| 46 | } // namespace aos |
| 47 | |
| 48 | #endif // _AOS_EVENTS_EVENT_LOOP_PARAM_TEST_H_ |