// License: Modified MIT (NON-AI) // See the LICENSE file in the root directory for license information. // Copyright 2025 Timothy Prepscius #include "RTTI.hpp" #include #include #include #include namespace tjp::core::rtti { namespace { struct A { ENABLE_RTTI_BASE; } ; struct B : A { ENABLE_RTTI(A); } ; struct C_different_base { ENABLE_RTTI_BASE; } ; //struct D_no_inherit_shouldn_t_compile { // ENABLE_RTTI(A); //} ; struct E : A { ENABLE_RTTI(A); } ; struct B_A : B { ENABLE_RTTI(B); } ; struct X0 {}; struct X1 {}; SCENARIO("core::rtti") { GIVEN("some structures") { A a_; B b_; C_different_base c_; // D_no_inherit d_; B_A b_a_; auto *a = &a_; unused(a); auto *b = &b_; unused(a); auto *c = &c_; unused(c); // auto *d = &d_; auto *b_a = &b_a_; static_assert(has_rtti_method::value == false); static_assert(has_rtti_method::value == true); sLogTest("testing", logVar(type_id().v) << logVar(type_id().v) << logVar(type_id().v) // << logVar(type_id().v) << logVar(type_id().v) << logVar(type_id().v) ); sLogTest("testing", logVar(has_rtti_method::value) << logVar(has_rtti_method::value) << logVar(has_rtti_method::value) << logVar(has_rtti_method::value) // << logVar(has_rtti_method::value) << logVar(has_rtti_method::value) << logVar(has_rtti_method::value) ); { auto cast_a = dynamic_cast_ptr(b); auto cast_b = dynamic_cast_ptr(cast_a); REQUIRE(cast_b == b); } { auto cast_a = dynamic_cast_ptr(b); auto cast_e = dynamic_cast_ptr(cast_a); REQUIRE(cast_e == nullptr); } { auto cast_a = dynamic_cast_ptr(b_a); auto cast_b = dynamic_cast_ptr(cast_a); REQUIRE(cast_b == b_a); auto cast_b_a = dynamic_cast_ptr(cast_a); REQUIRE(cast_b_a == b_a); auto cast_b_a_2 = dynamic_cast_ptr(cast_b); REQUIRE(cast_b_a_2 == b_a); } } GIVEN("some datatypes") { int i_; char c_; float f_; X0 x0_; X1 x1_; auto *i = &i_; auto *c = &c_; unused(c); auto *f = &f_; auto *x0 = &x0_; auto *x1 = &x1_; unused(x1); { auto x = dynamic_cast_ptr(i); REQUIRE(x == nullptr); auto y = dynamic_cast_ptr(i); REQUIRE(y == i); } { auto x = dynamic_cast_ptr(f); REQUIRE(x == nullptr); auto y = dynamic_cast_ptr(f); REQUIRE(y == f); } { auto x = dynamic_cast_ptr(x0); REQUIRE(x == nullptr); auto y = dynamic_cast_ptr(x0); REQUIRE(y == x0); } } } } // namespace } // namespace