Restore some of the tests and fix a bunch of bugs

This commit is contained in:
Antony Polukhin
2014-02-06 17:52:18 +04:00
parent 50d496288f
commit c43f8c1cfa
7 changed files with 205 additions and 130 deletions

View File

@ -96,6 +96,70 @@ inline bool operator != (const type_index_base<TypeInfo>& lhs, const type_index_
return !(lhs == rhs);
}
// ######################### COMPARISONS with TypeInfo ############################ //
template <class TypeInfo>
inline bool operator == (const TypeInfo& lhs, const type_index_base<TypeInfo>& rhs) BOOST_NOEXCEPT {
return type_index_base<TypeInfo>(lhs) == rhs;
}
template <class TypeInfo>
inline bool operator < (const TypeInfo& lhs, const type_index_base<TypeInfo>& rhs) BOOST_NOEXCEPT {
return type_index_base<TypeInfo>(lhs) < rhs;
}
template <class TypeInfo>
inline bool operator > (const TypeInfo& lhs, const type_index_base<TypeInfo>& rhs) BOOST_NOEXCEPT {
return rhs < type_index_base<TypeInfo>(lhs);
}
template <class TypeInfo>
inline bool operator <= (const TypeInfo& lhs, const type_index_base<TypeInfo>& rhs) BOOST_NOEXCEPT {
return !(type_index_base<TypeInfo>(lhs) > rhs);
}
template <class TypeInfo>
inline bool operator >= (const TypeInfo& lhs, const type_index_base<TypeInfo>& rhs) BOOST_NOEXCEPT {
return !(type_index_base<TypeInfo>(lhs) < rhs);
}
template <class TypeInfo>
inline bool operator != (const TypeInfo& lhs, const type_index_base<TypeInfo>& rhs) BOOST_NOEXCEPT {
return !(type_index_base<TypeInfo>(lhs) == rhs);
}
template <class TypeInfo>
inline bool operator == (const type_index_base<TypeInfo>& lhs, const TypeInfo& rhs) BOOST_NOEXCEPT {
return lhs == type_index_base<TypeInfo>(rhs);
}
template <class TypeInfo>
inline bool operator < (const type_index_base<TypeInfo>& lhs, const TypeInfo& rhs) BOOST_NOEXCEPT {
return lhs < type_index_base<TypeInfo>(rhs);
}
template <class TypeInfo>
inline bool operator > (const type_index_base<TypeInfo>& lhs, const TypeInfo& rhs) BOOST_NOEXCEPT {
return type_index_base<TypeInfo>(rhs) < lhs;
}
template <class TypeInfo>
inline bool operator <= (const type_index_base<TypeInfo>& lhs, const TypeInfo& rhs) BOOST_NOEXCEPT {
return !(lhs > type_index_base<TypeInfo>(rhs));
}
template <class TypeInfo>
inline bool operator >= (const type_index_base<TypeInfo>& lhs, const TypeInfo& rhs) BOOST_NOEXCEPT {
return !(lhs < type_index_base<TypeInfo>(rhs));
}
template <class TypeInfo>
inline bool operator != (const type_index_base<TypeInfo>& lhs, const TypeInfo& rhs) BOOST_NOEXCEPT {
return !(lhs == type_index_base<TypeInfo>(rhs));
}
// ######################### COMPARISONS with TypeInfo END ############################ //
#ifndef BOOST_NO_IOSTREAM
#ifdef BOOST_NO_TEMPLATED_IOSTREAMS

View File

@ -18,36 +18,34 @@ compat = <define>BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY ;
nortti = <toolset>gcc:<cxxflags>-fno-rtti <toolset>clang:<cxxflags>-fno-rtti <toolset>msvc:<cxxflags>/GR- ;
## Making libraries that CANNOT work between rtti-on/rtti-off modules
# Making libraries that CANNOT work between rtti-on/rtti-off modules
#obj test_lib_nortti-obj : test_lib.cpp : <link>shared <rtti>off ;
#obj test_lib_rtti-obj : test_lib.cpp : <link>shared ;
#lib test_lib_rtti : test_lib_rtti-obj : <link>shared ;
#lib test_lib_nortti : test_lib_nortti-obj : <link>shared <rtti>off ;
## Making libraries that can work between rtti-on/rtti-off modules
#obj test_lib_nortti_compat-obj : test_lib.cpp : <link>shared $(nortti) $(compat) ;
#obj test_lib_rtti_compat-obj : test_lib.cpp : <link>shared $(nortti) $(compat) ;
#lib test_lib_nortti_compat : test_lib_nortti_compat-obj : <link>shared $(nortti) $(compat) ;
#lib test_lib_rtti_compat : test_lib_rtti_compat-obj : <link>shared $(nortti) $(compat) ;
obj test_lib_rtti-obj : test_lib.cpp : <link>shared ;
lib test_lib_rtti : test_lib_rtti-obj : <link>shared ;
# Making libraries that can work between rtti-on/rtti-off modules
obj test_lib_nortti_compat-obj : test_lib.cpp : <link>shared $(nortti) $(compat) ;
obj test_lib_rtti_compat-obj : test_lib.cpp : <link>shared $(nortti) $(compat) ;
lib test_lib_nortti_compat : test_lib_nortti_compat-obj : <link>shared $(nortti) $(compat) ;
lib test_lib_rtti_compat : test_lib_rtti_compat-obj : <link>shared $(nortti) $(compat) ;
test-suite type_index
:
[ run type_index_test.cpp $(tlib) ]
[ run type_index_test.cpp $(tlib) : : : <rtti>off : type_index_test_no_rtti ]
# [ run template_index_test.cpp $(tlib) ]
# [ run testing_both.cpp $(tlib) ]
# [ run testing_both_no_rtti.cpp $(tlib) : : : <rtti>off ]
# [ run testing_crossmodule.cpp test_lib_rtti $(tlib) ]
[ run testing_crossmodule.cpp test_lib_rtti $(tlib) ]
# [ run testing_crossmodule.cpp test_lib_nortti $(tlib) : : : <rtti>off : testing_crossmodule_no_rtti ]
# # Mixing RTTI on and off
# [ link-fail testing_crossmodule.cpp $(tlib) test_lib_rtti : $(nortti) : link_fail_nortti_rtti ]
# # MSVC sometimes overrides the /GR-, that's why the following tests is disabled
# #[ 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 ]
#
# Mixing RTTI on and off
[ link-fail testing_crossmodule.cpp $(tlib) test_lib_rtti : $(nortti) : link_fail_nortti_rtti ]
# MSVC sometimes overrides the /GR-, that's why the following tests is disabled
#[ 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 ]

View File

@ -1,31 +1,33 @@
#define TEST_LIB_SOURCE
#include "test_lib.hpp"
#include <boost/functional/hash.hpp>
namespace user_defined_namespace {
class user_defined{};
}
namespace test_lib {
boost::type_index get_integer() {
return boost::type_id<int>();
boost::typeind::type_index get_integer() {
return boost::typeind::type_id<int>();
}
boost::type_index get_user_defined_class() {
return boost::type_id<user_defined_namespace::user_defined>();
boost::typeind::type_index get_user_defined_class() {
return boost::typeind::type_id<user_defined_namespace::user_defined>();
}
boost::type_index get_const_integer() {
return boost::type_id_with_cvr<const int>();
boost::typeind::type_index get_const_integer() {
return boost::typeind::type_id_with_cvr<const int>();
}
boost::type_index get_const_user_defined_class() {
return boost::type_id_with_cvr<const user_defined_namespace::user_defined>();
boost::typeind::type_index get_const_user_defined_class() {
return boost::typeind::type_id_with_cvr<const user_defined_namespace::user_defined>();
}
// Just do nothing
void accept_typeindex(const boost::type_index&) {}
void accept_typeindex(const boost::typeind::type_index&) {}
}

View File

@ -25,14 +25,14 @@
namespace test_lib {
TEST_LIB_DECL boost::type_index get_integer();
TEST_LIB_DECL boost::type_index get_user_defined_class();
TEST_LIB_DECL boost::typeind::type_index get_integer();
TEST_LIB_DECL boost::typeind::type_index get_user_defined_class();
TEST_LIB_DECL boost::type_index get_const_integer();
TEST_LIB_DECL boost::type_index get_const_user_defined_class();
TEST_LIB_DECL boost::typeind::type_index get_const_integer();
TEST_LIB_DECL boost::typeind::type_index get_const_user_defined_class();
// This is required for checking RTTI on/off linkage
TEST_LIB_DECL void accept_typeindex(const boost::type_index&);
TEST_LIB_DECL void accept_typeindex(const boost::typeind::type_index&);
}

View File

@ -8,7 +8,7 @@
#define BOOST_TEST_MODULE testing_crossmodule_module
#include <boost/test/unit_test.hpp>
#include <boost/type_index/type_index.hpp>
#include <boost/type_index.hpp>
#include "test_lib.hpp"
namespace user_defined_namespace {
@ -17,8 +17,8 @@ namespace user_defined_namespace {
BOOST_AUTO_TEST_CASE(comparing_types_between_modules)
{
boost::type_index t_const_int = boost::type_id_with_cvr<const int>();
boost::type_index t_int = boost::type_id<int>();
boost::typeind::type_index t_const_int = boost::typeind::type_id_with_cvr<const int>();
boost::typeind::type_index t_int = boost::typeind::type_id<int>();
BOOST_CHECK_EQUAL(t_int, test_lib::get_integer());
BOOST_CHECK_EQUAL(t_const_int, test_lib::get_const_integer());
@ -26,8 +26,10 @@ BOOST_AUTO_TEST_CASE(comparing_types_between_modules)
BOOST_CHECK_NE(t_int, test_lib::get_const_integer());
boost::type_index t_const_userdef = boost::type_id_with_cvr<const user_defined_namespace::user_defined>();
boost::type_index t_userdef = boost::type_id<user_defined_namespace::user_defined>();
boost::typeind::type_index t_const_userdef
= boost::typeind::type_id_with_cvr<const user_defined_namespace::user_defined>();
boost::typeind::type_index t_userdef
= boost::typeind::type_id<user_defined_namespace::user_defined>();
BOOST_CHECK_EQUAL(t_userdef, test_lib::get_user_defined_class());
BOOST_CHECK_EQUAL(t_const_userdef, test_lib::get_const_user_defined_class());

View File

@ -207,8 +207,108 @@ BOOST_AUTO_TEST_CASE(type_index_user_defined_class_test)
BOOST_CHECK_EQUAL(type_id<my_namespace1::my_class>(), type_id<my_namespace1::my_class>());
BOOST_CHECK_EQUAL(type_id<my_namespace2::my_class>(), type_id<my_namespace2::my_class>());
#ifndef BOOST_NO_RTTI
BOOST_CHECK(type_id<my_namespace1::my_class>() == typeid(my_namespace1::my_class));
BOOST_CHECK(type_id<my_namespace2::my_class>() == typeid(my_namespace2::my_class));
BOOST_CHECK(typeid(my_namespace1::my_class) == type_id<my_namespace1::my_class>());
BOOST_CHECK(typeid(my_namespace2::my_class) == type_id<my_namespace2::my_class>());
#endif
BOOST_CHECK_NE(type_id<my_namespace1::my_class>(), type_id<my_namespace2::my_class>());
BOOST_CHECK_NE(
type_id<my_namespace1::my_class>().pretty_name().find("my_namespace1::my_class"),
std::string::npos);
}
#ifndef BOOST_NO_RTTI
class A { public: virtual ~A(){} };
class B: public A{};
class C: public B {};
BOOST_AUTO_TEST_CASE(comparators_type_id_runtime)
{
C c1;
B b1;
A* pc1 = &c1;
A& rc1 = c1;
A* pb1 = &b1;
A& rb1 = b1;
BOOST_CHECK(typeid(rc1) == typeid(*pc1));
BOOST_CHECK(typeid(rb1) == typeid(*pb1));
BOOST_CHECK(typeid(rc1) != typeid(*pb1));
BOOST_CHECK(typeid(rb1) != typeid(*pc1));
BOOST_CHECK(typeid(&rc1) == typeid(pb1));
BOOST_CHECK(typeid(&rb1) == typeid(pc1));
BOOST_CHECK_EQUAL(boost::typeind::type_id_runtime(rc1), boost::typeind::type_id_runtime(*pc1));
BOOST_CHECK_EQUAL(boost::typeind::type_id_runtime(rb1), 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));
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));
BOOST_CHECK(boost::typeind::type_id_runtime(rc1) == typeid(*pc1));
BOOST_CHECK(boost::typeind::type_id_runtime(rb1) == typeid(*pb1));
BOOST_CHECK(boost::typeind::type_id_runtime(rc1) != typeid(*pb1));
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));
}
BOOST_AUTO_TEST_CASE(comparators_type_id_vs_type_info)
{
using namespace boost::typeind;
type_index t_int = type_id<int>();
BOOST_CHECK(t_int == typeid(int));
BOOST_CHECK(typeid(int) == t_int);
BOOST_CHECK(t_int <= typeid(int));
BOOST_CHECK(typeid(int) <= t_int);
BOOST_CHECK(t_int >= typeid(int));
BOOST_CHECK(typeid(int) >= t_int);
type_index t_double = type_id<double>();
BOOST_CHECK(t_double == typeid(double));
BOOST_CHECK(typeid(double) == t_double);
BOOST_CHECK(t_double <= typeid(double));
BOOST_CHECK(typeid(double) <= t_double);
BOOST_CHECK(t_double >= typeid(double));
BOOST_CHECK(typeid(double) >= t_double);
if (t_double < t_int) {
BOOST_CHECK(t_double < typeid(int));
BOOST_CHECK(typeid(double) < t_int);
BOOST_CHECK(typeid(int) > t_double);
BOOST_CHECK(t_int > typeid(double));
BOOST_CHECK(t_double <= typeid(int));
BOOST_CHECK(typeid(double) <= t_int);
BOOST_CHECK(typeid(int) >= t_double);
BOOST_CHECK(t_int >= typeid(double));
} else {
BOOST_CHECK(t_double > typeid(int));
BOOST_CHECK(typeid(double) > t_int);
BOOST_CHECK(typeid(int) < t_double);
BOOST_CHECK(t_int < typeid(double));
BOOST_CHECK(t_double >= typeid(int));
BOOST_CHECK(typeid(double) >= t_int);
BOOST_CHECK(typeid(int) <= t_double);
BOOST_CHECK(t_int <= typeid(double));
}
}
#endif // BOOST_NO_RTTI

View File

@ -55,52 +55,7 @@ BOOST_AUTO_TEST_CASE(hash_code_type_id)
#ifndef BOOST_NO_RTTI
BOOST_AUTO_TEST_CASE(comparators_type_id_vs_type_info)
{
using namespace boost;
type_index t_int = type_id<int>();
BOOST_CHECK(t_int == typeid(int));
BOOST_CHECK(typeid(int) == t_int);
BOOST_CHECK(t_int <= typeid(int));
BOOST_CHECK(typeid(int) <= t_int);
BOOST_CHECK(t_int >= typeid(int));
BOOST_CHECK(typeid(int) >= t_int);
type_index t_double = type_id<double>();
BOOST_CHECK(t_double == typeid(double));
BOOST_CHECK(typeid(double) == t_double);
BOOST_CHECK(t_double <= typeid(double));
BOOST_CHECK(typeid(double) <= t_double);
BOOST_CHECK(t_double >= typeid(double));
BOOST_CHECK(typeid(double) >= t_double);
if (t_double < t_int) {
BOOST_CHECK(t_double < typeid(int));
BOOST_CHECK(typeid(double) < t_int);
BOOST_CHECK(typeid(int) > t_double);
BOOST_CHECK(t_int > typeid(double));
BOOST_CHECK(t_double <= typeid(int));
BOOST_CHECK(typeid(double) <= t_int);
BOOST_CHECK(typeid(int) >= t_double);
BOOST_CHECK(t_int >= typeid(double));
} else {
BOOST_CHECK(t_double > typeid(int));
BOOST_CHECK(typeid(double) > t_int);
BOOST_CHECK(typeid(int) < t_double);
BOOST_CHECK(t_int < typeid(double));
BOOST_CHECK(t_double >= typeid(int));
BOOST_CHECK(typeid(double) >= t_int);
BOOST_CHECK(typeid(int) <= t_double);
BOOST_CHECK(t_int <= typeid(double));
}
}
#endif // BOOST_NO_RTTI
@ -243,12 +198,6 @@ BOOST_AUTO_TEST_CASE(type_index_user_defined_class_test)
BOOST_CHECK_EQUAL(type_id<my_namespace1::my_class>(), type_id<my_namespace1::my_class>());
BOOST_CHECK_EQUAL(type_id<my_namespace2::my_class>(), type_id<my_namespace2::my_class>());
#ifndef BOOST_NO_RTTI
BOOST_CHECK(type_id<my_namespace1::my_class>() == typeid(my_namespace1::my_class));
BOOST_CHECK(type_id<my_namespace2::my_class>() == typeid(my_namespace2::my_class));
BOOST_CHECK(typeid(my_namespace1::my_class) == type_id<my_namespace1::my_class>());
BOOST_CHECK(typeid(my_namespace2::my_class) == type_id<my_namespace2::my_class>());
#endif
BOOST_CHECK_NE(type_id<my_namespace1::my_class>(), type_id<my_namespace2::my_class>());
BOOST_CHECK_NE(
@ -257,46 +206,6 @@ BOOST_AUTO_TEST_CASE(type_index_user_defined_class_test)
}
#ifndef BOOST_NO_RTTI
class A { public: virtual ~A(){} };
class B: public A{};
class C: public B {};
BOOST_AUTO_TEST_CASE(comparators_type_id_rtti_only)
{
C c1;
B b1;
A* pc1 = &c1;
A& rc1 = c1;
A* pb1 = &b1;
A& rb1 = b1;
BOOST_CHECK(typeid(rc1) == typeid(*pc1));
BOOST_CHECK(typeid(rb1) == typeid(*pb1));
BOOST_CHECK(typeid(rc1) != typeid(*pb1));
BOOST_CHECK(typeid(rb1) != typeid(*pc1));
BOOST_CHECK(typeid(&rc1) == typeid(pb1));
BOOST_CHECK(typeid(&rb1) == typeid(pc1));
BOOST_CHECK_EQUAL(boost::type_id_rtti_only(rc1), boost::type_id_rtti_only(*pc1));
BOOST_CHECK_EQUAL(boost::type_id_rtti_only(rb1), boost::type_id_rtti_only(*pb1));
BOOST_CHECK_NE(boost::type_id_rtti_only(rc1), boost::type_id_rtti_only(*pb1));
BOOST_CHECK_NE(boost::type_id_rtti_only(rb1), boost::type_id_rtti_only(*pc1));
BOOST_CHECK_EQUAL(boost::type_id_rtti_only(&rc1), boost::type_id_rtti_only(pb1));
BOOST_CHECK_EQUAL(boost::type_id_rtti_only(&rb1), boost::type_id_rtti_only(pc1));
BOOST_CHECK(boost::type_id_rtti_only(rc1) == typeid(*pc1));
BOOST_CHECK(boost::type_id_rtti_only(rb1) == typeid(*pb1));
BOOST_CHECK(boost::type_id_rtti_only(rc1) != typeid(*pb1));
BOOST_CHECK(boost::type_id_rtti_only(rb1) != typeid(*pc1));
BOOST_CHECK(boost::type_id_rtti_only(&rc1) == typeid(pb1));
BOOST_CHECK(boost::type_id_rtti_only(&rb1) == typeid(pc1));
}
#endif // BOOST_NO_RTTI