μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
test_const_name.cpp
Go to the documentation of this file.
1// Copyright (c) 2021 The Pybind Development Team.
2// All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "pybind11_tests.h"
6
7#if defined(_MSC_VER) && _MSC_VER < 1910
8
9// MSVC 2015 fails in bizarre ways.
10# define PYBIND11_SKIP_TEST_CONST_NAME
11
12#else // Only test with MSVC 2017 or newer.
13
14// IUT = Implementation Under Test
15# define CONST_NAME_TESTS(TEST_FUNC, IUT) \
16 std::string TEST_FUNC(int selector) { \
17 switch (selector) { \
18 case 0: \
19 return IUT("").text; \
20 case 1: \
21 return IUT("A").text; \
22 case 2: \
23 return IUT("Bd").text; \
24 case 3: \
25 return IUT("Cef").text; \
26 case 4: \
27 return IUT<int>().text; /*NOLINT(bugprone-macro-parentheses)*/ \
28 case 5: \
29 return IUT<std::string>().text; /*NOLINT(bugprone-macro-parentheses)*/ \
30 case 6: \
31 return IUT<true>("T1", "T2").text; /*NOLINT(bugprone-macro-parentheses)*/ \
32 case 7: \
33 return IUT<false>("U1", "U2").text; /*NOLINT(bugprone-macro-parentheses)*/ \
34 case 8: \
35 /*NOLINTNEXTLINE(bugprone-macro-parentheses)*/ \
36 return IUT<true>(IUT("D1"), IUT("D2")).text; \
37 case 9: \
38 /*NOLINTNEXTLINE(bugprone-macro-parentheses)*/ \
39 return IUT<false>(IUT("E1"), IUT("E2")).text; \
40 case 10: \
41 return IUT("KeepAtEnd").text; \
42 default: \
43 break; \
44 } \
45 throw std::runtime_error("Invalid selector value."); \
46 }
47
48CONST_NAME_TESTS(const_name_tests, py::detail::const_name)
49
50# ifdef PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY
51CONST_NAME_TESTS(underscore_tests, py::detail::_)
52# endif
53
54#endif // MSVC >= 2017
55
56TEST_SUBMODULE(const_name, m) {
57#ifdef PYBIND11_SKIP_TEST_CONST_NAME
58 m.attr("const_name_tests") = "PYBIND11_SKIP_TEST_CONST_NAME";
59#else
60 m.def("const_name_tests", const_name_tests);
61#endif
62
63#ifdef PYBIND11_SKIP_TEST_CONST_NAME
64 m.attr("underscore_tests") = "PYBIND11_SKIP_TEST_CONST_NAME";
65#elif defined(PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY)
66 m.def("underscore_tests", underscore_tests);
67#else
68 m.attr("underscore_tests") = "PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY not defined.";
69#endif
70}
#define TEST_SUBMODULE(name, variable)
#define CONST_NAME_TESTS(TEST_FUNC, IUT)