|
Packit |
534379 |
#pragma once
|
|
Packit |
534379 |
#include <pybind11/pybind11.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#if defined(_MSC_VER) && _MSC_VER < 1910
|
|
Packit |
534379 |
// We get some really long type names here which causes MSVC 2015 to emit warnings
|
|
Packit |
534379 |
# pragma warning(disable: 4503) // warning C4503: decorated name length exceeded, name was truncated
|
|
Packit |
534379 |
#endif
|
|
Packit |
534379 |
|
|
Packit |
534379 |
namespace py = pybind11;
|
|
Packit |
534379 |
using namespace pybind11::literals;
|
|
Packit |
534379 |
|
|
Packit |
534379 |
class test_initializer {
|
|
Packit |
534379 |
using Initializer = void (*)(py::module &);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
public:
|
|
Packit |
534379 |
test_initializer(Initializer init);
|
|
Packit |
534379 |
test_initializer(const char *submodule_name, Initializer init);
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#define TEST_SUBMODULE(name, variable) \
|
|
Packit |
534379 |
void test_submodule_##name(py::module &); \
|
|
Packit |
534379 |
test_initializer name(#name, test_submodule_##name); \
|
|
Packit |
534379 |
void test_submodule_##name(py::module &variable)
|
|
Packit |
534379 |
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/// Dummy type which is not exported anywhere -- something to trigger a conversion error
|
|
Packit |
534379 |
struct UnregisteredType { };
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/// A user-defined type which is exported and can be used by any test
|
|
Packit |
534379 |
class UserType {
|
|
Packit |
534379 |
public:
|
|
Packit |
534379 |
UserType() = default;
|
|
Packit |
534379 |
UserType(int i) : i(i) { }
|
|
Packit |
534379 |
|
|
Packit |
534379 |
int value() const { return i; }
|
|
Packit |
534379 |
void set(int set) { i = set; }
|
|
Packit |
534379 |
|
|
Packit |
534379 |
private:
|
|
Packit |
534379 |
int i = -1;
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/// Like UserType, but increments `value` on copy for quick reference vs. copy tests
|
|
Packit |
534379 |
class IncType : public UserType {
|
|
Packit |
534379 |
public:
|
|
Packit |
534379 |
using UserType::UserType;
|
|
Packit |
534379 |
IncType() = default;
|
|
Packit |
534379 |
IncType(const IncType &other) : IncType(other.value() + 1) { }
|
|
Packit |
534379 |
IncType(IncType &&) = delete;
|
|
Packit |
534379 |
IncType &operator=(const IncType &) = delete;
|
|
Packit |
534379 |
IncType &operator=(IncType &&) = delete;
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/// Custom cast-only type that casts to a string "rvalue" or "lvalue" depending on the cast context.
|
|
Packit |
534379 |
/// Used to test recursive casters (e.g. std::tuple, stl containers).
|
|
Packit |
534379 |
struct RValueCaster {};
|
|
Packit |
534379 |
NAMESPACE_BEGIN(pybind11)
|
|
Packit |
534379 |
NAMESPACE_BEGIN(detail)
|
|
Packit |
534379 |
template<> class type_caster<RValueCaster> {
|
|
Packit |
534379 |
public:
|
|
Packit |
534379 |
PYBIND11_TYPE_CASTER(RValueCaster, _("RValueCaster"));
|
|
Packit |
534379 |
static handle cast(RValueCaster &&, return_value_policy, handle) { return py::str("rvalue").release(); }
|
|
Packit |
534379 |
static handle cast(const RValueCaster &, return_value_policy, handle) { return py::str("lvalue").release(); }
|
|
Packit |
534379 |
};
|
|
Packit |
534379 |
NAMESPACE_END(detail)
|
|
Packit |
534379 |
NAMESPACE_END(pybind11)
|