You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

2 months ago
  1. #pragma once
  2. #include <pybind11/pybind11.h>
  3. namespace py = pybind11;
  4. using namespace pybind11::literals;
  5. class test_initializer {
  6. using Initializer = void (*)(py::module &);
  7. public:
  8. test_initializer(Initializer init);
  9. test_initializer(const char *submodule_name, Initializer init);
  10. };
  11. #define TEST_SUBMODULE(name, variable) \
  12. void test_submodule_##name(py::module &); \
  13. test_initializer name(#name, test_submodule_##name); \
  14. void test_submodule_##name(py::module &variable)
  15. /// Dummy type which is not exported anywhere -- something to trigger a conversion error
  16. struct UnregisteredType { };
  17. /// A user-defined type which is exported and can be used by any test
  18. class UserType {
  19. public:
  20. UserType() = default;
  21. UserType(int i) : i(i) { }
  22. int value() const { return i; }
  23. private:
  24. int i = -1;
  25. };
  26. /// Like UserType, but increments `value` on copy for quick reference vs. copy tests
  27. class IncType : public UserType {
  28. public:
  29. using UserType::UserType;
  30. IncType() = default;
  31. IncType(const IncType &other) : IncType(other.value() + 1) { }
  32. IncType(IncType &&) = delete;
  33. IncType &operator=(const IncType &) = delete;
  34. IncType &operator=(IncType &&) = delete;
  35. };