Skip to content
Snippets Groups Projects
Unverified Commit bfb0c322 authored by Joris Vaillant's avatar Joris Vaillant
Browse files

unittest: Refactor test to test on std::variant and boost::variant

parent 30e4a49d
Loading
......@@ -45,24 +45,28 @@ add_lib_unit_test(std_vector)
add_lib_unit_test(std_array)
add_lib_unit_test(std_pair)
add_lib_unit_test(user_struct)
add_lib_unit_test(boost_variant)
function(config_bind_optional tagname opttype)
set(MODNAME bind_optional_${tagname})
set(OPTIONAL ${opttype})
configure_file(bind_optional.cpp.in ${MODNAME}.cpp)
function(config_test test tagname opttype)
set(MODNAME ${test}_${tagname})
set(TEST_TYPE ${opttype})
configure_file(${test}.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/${MODNAME}.cpp)
set(py_file test_optional_${tagname}.py)
configure_file(python/test_optional.py.in
set(py_file test_${test}_${tagname}.py)
configure_file(python/test_${test}.py.in
${CMAKE_CURRENT_BINARY_DIR}/python/${py_file})
add_lib_unit_test(${MODNAME})
add_python_unit_test("py-optional-${tagname}" "unittest/python/${py_file}"
add_python_unit_test("py-${test}-${tagname}" "unittest/python/${py_file}"
"unittest")
endfunction()
config_bind_optional(boost "boost::optional")
config_test(variant boost "boost::variant")
if(CMAKE_CXX_STANDARD GREATER 14 AND CMAKE_CXX_STANDARD LESS 98)
config_bind_optional(std "std::optional")
config_test(variant std "std::variant")
endif()
config_test(bind_optional boost "boost::optional")
if(CMAKE_CXX_STANDARD GREATER 14 AND CMAKE_CXX_STANDARD LESS 98)
config_test(bind_optional std "std::optional")
endif()
add_lib_unit_test(bind_virtual_factory)
......@@ -133,10 +137,6 @@ add_python_unit_test("py-user-struct" "unittest/python/test_user_struct.py"
"python;unittest")
set_tests_properties("py-user-struct" PROPERTIES DEPENDS ${PYWRAP})
add_python_unit_test("py-boost-variant" "unittest/python/test_boost_variant.py"
"python;unittest")
set_tests_properties("py-boost-variant" PROPERTIES DEPENDS ${PYWRAP})
add_python_unit_test("py-bind-virtual" "unittest/python/test_bind_virtual.py"
"python;unittest")
set_tests_properties("py-bind-virtual" PROPERTIES DEPENDS ${PYWRAP})
......@@ -8,7 +8,8 @@
#include <optional>
#endif
#cmakedefine OPTIONAL @OPTIONAL@
#cmakedefine TEST_TYPE @TEST_TYPE@
#define OPTIONAL TEST_TYPE
typedef eigenpy::detail::nullopt_helper<OPTIONAL> none_helper;
static auto OPT_NONE = none_helper::value();
......@@ -74,6 +75,7 @@ BOOST_PYTHON_MODULE(@MODNAME@) {
bp::make_setter(&mystruct::msg));
bp::def("none_if_zero", none_if_zero, bp::args("i"));
bp::def("create_if_true", create_if_true, (bp::arg("flag"), bp::arg("b") = OPT_NONE));
bp::def("create_if_true", create_if_true,
(bp::arg("flag"), bp::arg("b") = OPT_NONE));
bp::def("random_mat_if_true", random_mat_if_true, bp::args("flag"));
}
from boost_variant import V1, V2, VariantHolder, make_variant
import importlib
variant_module = importlib.import_module("@MODNAME@")
V1 = variant_module.V1
V2 = variant_module.V2
VariantHolder = variant_module.VariantHolder
make_variant = variant_module.make_variant
variant = make_variant()
assert isinstance(variant, V1)
......
......@@ -4,6 +4,9 @@
#include <eigenpy/eigenpy.hpp>
#include <eigenpy/variant.hpp>
#cmakedefine TEST_TYPE @TEST_TYPE@
#define VARIANT TEST_TYPE
namespace bp = boost::python;
struct V1 {
......@@ -12,7 +15,7 @@ struct V1 {
struct V2 {
char v;
};
typedef boost::variant<V1, V2> MyVariant;
typedef VARIANT<V1, V2> MyVariant;
MyVariant make_variant() { return V1(); }
......@@ -20,7 +23,7 @@ struct VariantHolder {
MyVariant variant;
};
BOOST_PYTHON_MODULE(boost_variant) {
BOOST_PYTHON_MODULE(@MODNAME@) {
using namespace eigenpy;
enableEigenPy();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment