xo-ratio: + xo_reflectutil feature + utest
This commit is contained in:
parent
ae69a418ff
commit
102fbf4a16
4 changed files with 60 additions and 0 deletions
|
|
@ -39,6 +39,7 @@ add_subdirectory(docs)
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
# dependencies
|
# dependencies
|
||||||
|
|
||||||
|
xo_headeronly_dependency(${SELF_LIB} xo_reflectutil)
|
||||||
xo_headeronly_dependency(${SELF_LIB} xo_flatstring)
|
xo_headeronly_dependency(${SELF_LIB} xo_flatstring)
|
||||||
#xo_headeronly_dependency(${SELF_LIB} randomgen)
|
#xo_headeronly_dependency(${SELF_LIB} randomgen)
|
||||||
# etc..
|
# etc..
|
||||||
|
|
|
||||||
25
include/xo/ratio/ratio_reflect.hpp
Normal file
25
include/xo/ratio/ratio_reflect.hpp
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/** @file ratio_reflect.hpp
|
||||||
|
*
|
||||||
|
* Author: Roland Conybeare
|
||||||
|
**/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "xo/reflectutil/reflect_struct_info.hpp"
|
||||||
|
#include "ratio.hpp"
|
||||||
|
//#include <cstdint>
|
||||||
|
|
||||||
|
namespace xo {
|
||||||
|
namespace reflect {
|
||||||
|
template <typename Int>
|
||||||
|
REFLECT_BASE_STRUCT_INFO_TBODY(xo::ratio::ratio<Int>, 2);
|
||||||
|
|
||||||
|
template <typename Int>
|
||||||
|
REFLECT_STRUCT_MEMBER_INFO_TBODY(xo::ratio::ratio<Int>, 0, num);
|
||||||
|
|
||||||
|
template <typename Int>
|
||||||
|
REFLECT_STRUCT_MEMBER_INFO_TBODY(xo::ratio::ratio<Int>, 1, den);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** end ratio_reflect.hpp **/
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
set(SELF_EXE utest.ratio)
|
set(SELF_EXE utest.ratio)
|
||||||
set(SELF_SRCS
|
set(SELF_SRCS
|
||||||
ratio_utest_main.cpp
|
ratio_utest_main.cpp
|
||||||
|
ratio_reflect.test.cpp
|
||||||
ratio.test.cpp)
|
ratio.test.cpp)
|
||||||
|
|
||||||
if (ENABLE_TESTING)
|
if (ENABLE_TESTING)
|
||||||
|
|
@ -14,6 +15,7 @@ if (ENABLE_TESTING)
|
||||||
# dependencies..
|
# dependencies..
|
||||||
|
|
||||||
xo_self_headeronly_dependency(${SELF_EXE} xo_ratio)
|
xo_self_headeronly_dependency(${SELF_EXE} xo_ratio)
|
||||||
|
xo_dependency(${SELF_EXE} reflect)
|
||||||
xo_dependency(${SELF_EXE} randomgen)
|
xo_dependency(${SELF_EXE} randomgen)
|
||||||
xo_dependency(${SELF_EXE} indentlog)
|
xo_dependency(${SELF_EXE} indentlog)
|
||||||
xo_external_target_dependency(${SELF_EXE} Catch2 Catch2::Catch2)
|
xo_external_target_dependency(${SELF_EXE} Catch2 Catch2::Catch2)
|
||||||
|
|
|
||||||
32
utest/ratio_reflect.test.cpp
Normal file
32
utest/ratio_reflect.test.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
/* @file ratio_reflect.test.cpp */
|
||||||
|
|
||||||
|
#include "xo/ratio/ratio_reflect.hpp"
|
||||||
|
#include "xo/reflect/reflect_struct.hpp"
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
|
namespace xo {
|
||||||
|
namespace ut {
|
||||||
|
TEST_CASE("ratio_reflect", "[ratio][reflect]") {
|
||||||
|
using xo::reflect::reflect_struct;
|
||||||
|
using xo::reflect::TypeDescrBase;
|
||||||
|
using xo::reflect::TypeDescr;
|
||||||
|
using xo::ratio::ratio;
|
||||||
|
|
||||||
|
/* verify ratio reflection */
|
||||||
|
|
||||||
|
TypeDescr td = reflect_struct<ratio<std::int64_t>>();
|
||||||
|
|
||||||
|
REQUIRE(td->is_struct());
|
||||||
|
REQUIRE(td->metatype() == xo::reflect::Metatype::mt_struct);
|
||||||
|
REQUIRE(td->n_child(nullptr) == 2);
|
||||||
|
REQUIRE(td->struct_member(0).member_name() == "num");
|
||||||
|
REQUIRE(td->struct_member(0).get_member_td()->short_name() == "long int");
|
||||||
|
REQUIRE(td->struct_member(1).member_name() == "den");
|
||||||
|
REQUIRE(td->struct_member(1).get_member_td()->short_name() == "long int");
|
||||||
|
|
||||||
|
TypeDescrBase::print_reflected_types(std::cerr);
|
||||||
|
}
|
||||||
|
} /*namespace ut*/
|
||||||
|
} /*namespace xo*/
|
||||||
|
|
||||||
|
/* end ratio_reflect.test.cpp */
|
||||||
Loading…
Add table
Add a link
Reference in a new issue