pybind11_tests.h 1.22 KB
Newer Older
1
#pragma once
2
#include <pybind11/pybind11.h>
Wenzel Jakob's avatar
Wenzel Jakob committed
3

4
namespace py = pybind11;
5
using namespace pybind11::literals;
6
7

class test_initializer {
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
    using Initializer = void (*)(py::module &);

public:
    test_initializer(Initializer init);
    test_initializer(const char *submodule_name, Initializer init);
};

#define TEST_SUBMODULE(name, variable)                   \
    void test_submodule_##name(py::module &);            \
    test_initializer name(#name, test_submodule_##name); \
    void test_submodule_##name(py::module &variable)


/// Dummy type which is not exported anywhere -- something to trigger a conversion error
struct UnregisteredType { };

/// A user-defined type which is exported and can be used by any test
class UserType {
public:
    UserType() = default;
    UserType(int i) : i(i) { }

    int value() const { return i; }

private:
    int i = -1;
};

/// Like UserType, but increments `value` on copy for quick reference vs. copy tests
class IncType : public UserType {
38
public:
39
40
41
42
43
44
    using UserType::UserType;
    IncType() = default;
    IncType(const IncType &other) : IncType(other.value() + 1) { }
    IncType(IncType &&) = delete;
    IncType &operator=(const IncType &) = delete;
    IncType &operator=(IncType &&) = delete;
45
};