xo-reflect: utest for function reflection
This commit is contained in:
parent
ef191b136e
commit
fb8f4fdec2
3 changed files with 47 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
||||
|
|
|
|||
40
utest/FunctionTdx.test.cpp
Normal file
40
utest/FunctionTdx.test.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* @file FunctionTdx.test.cpp */
|
||||
|
||||
#include "xo/reflect/Reflect.hpp"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
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<std::vector<double>>();
|
||||
|
||||
REQUIRE(Reflect::is_reflected<FunctionType>() == 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<double (*)(double)>() == &fn);
|
||||
REQUIRE(tp.n_child() == 0); /*not a composite*/
|
||||
// REQUIRE(tp.child_td(0) == ...
|
||||
REQUIRE(tp.td()->fn_retval() == Reflect::require<double>());
|
||||
REQUIRE(tp.n_fn_arg() == 1);
|
||||
REQUIRE(tp.td()->fn_arg(0) == Reflect::require<double>());
|
||||
} /*TEST_CASE(function-reflect1)*/
|
||||
} /*namespace ut*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end FunctionTdx.test.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue