Jason Rhinelander | 52f4be8 | 2016-09-03 14:54:22 -0400 | [diff] [blame] | 1 | #pragma once |
Wenzel Jakob | 8f4eb00 | 2015-10-15 18:13:33 +0200 | [diff] [blame] | 2 | #include <pybind11/pybind11.h> |
Wenzel Jakob | 38bd711 | 2015-07-05 20:05:44 +0200 | [diff] [blame] | 3 | |
Wenzel Jakob | 8f4eb00 | 2015-10-15 18:13:33 +0200 | [diff] [blame] | 4 | namespace py = pybind11; |
Dean Moldovan | c743e1b | 2016-08-29 03:05:42 +0200 | [diff] [blame] | 5 | using namespace pybind11::literals; |
Jason Rhinelander | 52f4be8 | 2016-09-03 14:54:22 -0400 | [diff] [blame] | 6 | |
| 7 | class test_initializer { |
Dean Moldovan | 83e328f | 2017-06-09 00:44:49 +0200 | [diff] [blame] | 8 | using Initializer = void (*)(py::module &); |
| 9 | |
Jason Rhinelander | 52f4be8 | 2016-09-03 14:54:22 -0400 | [diff] [blame] | 10 | public: |
Dean Moldovan | 83e328f | 2017-06-09 00:44:49 +0200 | [diff] [blame] | 11 | test_initializer(Initializer init); |
| 12 | test_initializer(const char *submodule_name, Initializer init); |
| 13 | }; |
| 14 | |
| 15 | #define TEST_SUBMODULE(name, variable) \ |
| 16 | void test_submodule_##name(py::module &); \ |
| 17 | test_initializer name(#name, test_submodule_##name); \ |
| 18 | void test_submodule_##name(py::module &variable) |
| 19 | |
| 20 | |
| 21 | /// Dummy type which is not exported anywhere -- something to trigger a conversion error |
| 22 | struct UnregisteredType { }; |
| 23 | |
| 24 | /// A user-defined type which is exported and can be used by any test |
| 25 | class UserType { |
| 26 | public: |
| 27 | UserType() = default; |
| 28 | UserType(int i) : i(i) { } |
| 29 | |
| 30 | int value() const { return i; } |
| 31 | |
| 32 | private: |
| 33 | int i = -1; |
| 34 | }; |
| 35 | |
| 36 | /// Like UserType, but increments `value` on copy for quick reference vs. copy tests |
| 37 | class IncType : public UserType { |
| 38 | public: |
| 39 | using UserType::UserType; |
| 40 | IncType() = default; |
| 41 | IncType(const IncType &other) : IncType(other.value() + 1) { } |
| 42 | IncType(IncType &&) = delete; |
| 43 | IncType &operator=(const IncType &) = delete; |
| 44 | IncType &operator=(IncType &&) = delete; |
Jason Rhinelander | 52f4be8 | 2016-09-03 14:54:22 -0400 | [diff] [blame] | 45 | }; |