Allow runtime type info even when RTTI is off. Improve tests and examples

This commit is contained in:
Antony Polukhin committed 2014-02-19 13:03:12 +04:00
1 parent c99b7b26da
commit ea2e5beabb
8 files changed
+120 -98

No files matched your search

+6 -7
View File
@@ -6,7 +6,7 @@
import testing ;
import feature ;
import os ;
# Variable that contains all the stuff required for linking against -lboost_unit_test
tlib = /boost/test//boost_unit_test_framework/<link>static ;
@@ -45,17 +45,16 @@ test-suite type_index
#[ link-fail testing_crossmodule.cpp $(tlib) test_lib_nortti : : link_fail_rtti_nortti ]
[ run testing_crossmodule.cpp $(tlib) test_lib_rtti_compat : : : $(nortti) $(compat) : testing_crossmodule_nortti_rtti_compat ]
[ run testing_crossmodule.cpp $(tlib) test_lib_nortti_compat : : : $(compat) : testing_crossmodule_rtti_nortti_compat ]
# Examples that must work even with RTTI disabled
[ run ../examples/registry.cpp : : : <rtti>off : registry_no_rtti ]
[ run ../examples/exact_types_match.cpp : : : <rtti>off : exact_types_match_no_rtti ]
[ run ../examples/demangled_names.cpp : : : <rtti>off : demangled_names_no_rtti ]
[ compile-fail ../examples/inheritance.cpp : <rtti>off : failing_inheritance_example ]
;
# Assuring that examples compile and run. Adding sources from `examples` directory to the `type_index` test suite.
for local p in [ glob ../examples/*.cpp ]
{
# RTTI on
type_index += [ run $(p) ] ;
# RTTI off
local target_name = $(p[1]:B)_no_rtti ;
type_index += [ run $(p) : : : <rtti>off : $(target_name) ] ;
}
+24 -4
View File
@@ -245,11 +245,19 @@ BOOST_AUTO_TEST_CASE(type_index_user_defined_class_test)
}
#ifndef BOOST_NO_RTTI
struct A {
public:
BOOST_TYPE_INDEX_REGISTER_CLASS
virtual ~A(){}
};
class A { public: virtual ~A(){} };
class B: public A{};
class C: public B {};
struct B: public A {
BOOST_TYPE_INDEX_REGISTER_CLASS
};
struct C: public B {
BOOST_TYPE_INDEX_REGISTER_CLASS
};
BOOST_AUTO_TEST_CASE(comparators_type_id_runtime)
{
@@ -259,6 +267,8 @@ BOOST_AUTO_TEST_CASE(comparators_type_id_runtime)
A& rc1 = c1;
A* pb1 = &b1;
A& rb1 = b1;
#ifndef BOOST_NO_RTTI
BOOST_CHECK(typeid(rc1) == typeid(*pc1));
BOOST_CHECK(typeid(rb1) == typeid(*pb1));
@@ -267,12 +277,19 @@ BOOST_AUTO_TEST_CASE(comparators_type_id_runtime)
BOOST_CHECK(typeid(&rc1) == typeid(pb1));
BOOST_CHECK(typeid(&rb1) == typeid(pc1));
#else
BOOST_CHECK(boost::typeind::type_index(pc1->type_id_ref()).raw_name());
#endif
BOOST_CHECK_EQUAL(boost::typeind::type_id_runtime(rc1), boost::typeind::type_id_runtime(*pc1));
BOOST_CHECK_EQUAL(boost::typeind::type_id<C>(), boost::typeind::type_id_runtime(*pc1));
BOOST_CHECK_EQUAL(boost::typeind::type_id_runtime(rb1), boost::typeind::type_id_runtime(*pb1));
BOOST_CHECK_EQUAL(boost::typeind::type_id<B>(), boost::typeind::type_id_runtime(*pb1));
BOOST_CHECK_NE(boost::typeind::type_id_runtime(rc1), boost::typeind::type_id_runtime(*pb1));
BOOST_CHECK_NE(boost::typeind::type_id_runtime(rb1), boost::typeind::type_id_runtime(*pc1));
#ifndef BOOST_NO_RTTI
BOOST_CHECK_EQUAL(boost::typeind::type_id_runtime(&rc1), boost::typeind::type_id_runtime(pb1));
BOOST_CHECK_EQUAL(boost::typeind::type_id_runtime(&rb1), boost::typeind::type_id_runtime(pc1));
@@ -283,9 +300,12 @@ BOOST_AUTO_TEST_CASE(comparators_type_id_runtime)
BOOST_CHECK(boost::typeind::type_id_runtime(rb1) != typeid(*pc1));
BOOST_CHECK(boost::typeind::type_id_runtime(&rc1) == typeid(pb1));
BOOST_CHECK(boost::typeind::type_id_runtime(&rb1) == typeid(pc1));
#endif
}
#ifndef BOOST_NO_RTTI
BOOST_AUTO_TEST_CASE(comparators_type_id_vs_type_info)
{
using namespace boost::typeind;