blob: dd8d159319c64912f37df715df481cdeccb6ecbe [file] [log] [blame]
Jason Rhinelander52f4be82016-09-03 14:54:22 -04001#pragma once
Wenzel Jakob8f4eb002015-10-15 18:13:33 +02002#include <pybind11/pybind11.h>
Wenzel Jakob38bd7112015-07-05 20:05:44 +02003
Wenzel Jakob8f4eb002015-10-15 18:13:33 +02004namespace py = pybind11;
Dean Moldovanc743e1b2016-08-29 03:05:42 +02005using namespace pybind11::literals;
Jason Rhinelander52f4be82016-09-03 14:54:22 -04006
7class test_initializer {
Dean Moldovan83e328f2017-06-09 00:44:49 +02008 using Initializer = void (*)(py::module &);
9
Jason Rhinelander52f4be82016-09-03 14:54:22 -040010public:
Dean Moldovan83e328f2017-06-09 00:44:49 +020011 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
22struct UnregisteredType { };
23
24/// A user-defined type which is exported and can be used by any test
25class UserType {
26public:
27 UserType() = default;
28 UserType(int i) : i(i) { }
29
30 int value() const { return i; }
31
32private:
33 int i = -1;
34};
35
36/// Like UserType, but increments `value` on copy for quick reference vs. copy tests
37class IncType : public UserType {
38public:
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 Rhinelander52f4be82016-09-03 14:54:22 -040045};