blob: b5574ba50f55df6d812e9e755ae3717c31b24852 [file] [log] [blame]
Parker Schuhe4a70d62017-12-27 20:10:20 -08001#ifndef _AOS_EVENTS_EVENT_LOOP_PARAM_TEST_H_
2#define _AOS_EVENTS_EVENT_LOOP_PARAM_TEST_H_
3
Neil Balch229001a2018-01-07 18:22:52 -08004#include <vector>
5
Parker Schuhe4a70d62017-12-27 20:10:20 -08006#include "aos/events/event-loop.h"
7#include "gtest/gtest.h"
8
9namespace aos {
10namespace testing {
11
12class EventLoopTestFactory {
13 public:
14 virtual ~EventLoopTestFactory() {}
15
Austin Schuh44019f92019-05-19 19:58:27 -070016 // Makes a connected event loop.
Parker Schuhe4a70d62017-12-27 20:10:20 -080017 virtual std::unique_ptr<EventLoop> Make() = 0;
Austin Schuh44019f92019-05-19 19:58:27 -070018 // 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 Schuhe4a70d62017-12-27 20:10:20 -080024};
25
26class AbstractEventLoopTest
27 : public ::testing::TestWithParam<std::function<EventLoopTestFactory *()>> {
28 public:
29 AbstractEventLoopTest() { factory_.reset(GetParam()()); }
30
Austin Schuh44019f92019-05-19 19:58:27 -070031 ::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 Schuhe4a70d62017-12-27 20:10:20 -080035 // 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 Schuh44019f92019-05-19 19:58:27 -070039 ::std::unique_ptr<EventLoopTestFactory> factory_;
Parker Schuhe4a70d62017-12-27 20:10:20 -080040};
41
42} // namespace testing
43} // namespace aos
44
45#endif // _AOS_EVENTS_EVENT_LOOP_PARAM_TEST_H_