From fb8f4fdec29cc102767cc77905a6162cb1730505 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 14 Jun 2024 10:56:50 -0400 Subject: [PATCH] xo-reflect: utest for function reflection --- CMakeLists.txt | 10 +--------- utest/CMakeLists.txt | 7 ++++++- utest/FunctionTdx.test.cpp | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 utest/FunctionTdx.test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 050bc94..c2e8b74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,15 +7,7 @@ project(reflect VERSION 0.1) include(GNUInstallDirs) include(cmake/xo-bootstrap-macros.cmake) -xo_cxx_toplevel_options2() - -# ---------------------------------------------------------------- -# cmake -DCMAKE_BUILD_TYPE=coverage -xo_toplevel_coverage_config2() - -# ---------------------------------------------------------------- -# cmake -DCMAKE_BUILD_TYPE=debug -xo_toplevel_debug_config2() +xo_cxx_toplevel_options3() # ---------------------------------------------------------------- # c++ settings diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index aef60b2..edc997e 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -1,7 +1,12 @@ # build unittest reflect/utest set(SELF_EXECUTABLE_NAME utest.reflect) -set(SELF_SOURCE_FILES reflect_utest_main.cpp StructReflector.test.cpp VectorTdx.test.cpp StructTdx.test.cpp) +set(SELF_SOURCE_FILES + reflect_utest_main.cpp + StructReflector.test.cpp + VectorTdx.test.cpp + StructTdx.test.cpp + FunctionTdx.test.cpp) xo_add_utest_executable(${SELF_EXECUTABLE_NAME} ${SELF_SOURCE_FILES}) diff --git a/utest/FunctionTdx.test.cpp b/utest/FunctionTdx.test.cpp new file mode 100644 index 0000000..278a253 --- /dev/null +++ b/utest/FunctionTdx.test.cpp @@ -0,0 +1,40 @@ +/* @file FunctionTdx.test.cpp */ + +#include "xo/reflect/Reflect.hpp" +#include + +namespace xo { + using xo::reflect::Reflect; + using xo::reflect::TaggedPtr; + using xo::reflect::TypeDescr; + using xo::reflect::Metatype; + + namespace ut { + TEST_CASE("function-reflect1", "[reflect]") { + using FunctionType = double (*)(double); + + FunctionType fn = ::sqrt; + + TaggedPtr tp = Reflect::make_tp(&fn); + //TypeDescr td = Reflect::require>(); + + REQUIRE(Reflect::is_reflected() == true); + + REQUIRE(tp.td()->complete_flag()); + REQUIRE(tp.address() == &fn); + REQUIRE(tp.is_function()); + REQUIRE(tp.is_pointer() == false); + REQUIRE(tp.is_vector() == false); + REQUIRE(tp.is_struct() == false); + REQUIRE(tp.td()->metatype() == Metatype::mt_function); + REQUIRE(tp.recover_native() == &fn); + REQUIRE(tp.n_child() == 0); /*not a composite*/ + // REQUIRE(tp.child_td(0) == ... + REQUIRE(tp.td()->fn_retval() == Reflect::require()); + REQUIRE(tp.n_fn_arg() == 1); + REQUIRE(tp.td()->fn_arg(0) == Reflect::require()); + } /*TEST_CASE(function-reflect1)*/ + } /*namespace ut*/ +} /*namespace xo*/ + +/* end FunctionTdx.test.cpp */