Started the work on new interface

This commit is contained in:
Antony Polukhin committed 2014-02-06 16:00:27 +04:00
1 parent 5f97225a18
commit 3daeab38fa
9 files changed
+698 -603

No files matched your search

+31 -31
View File
@@ -18,45 +18,45 @@ 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
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 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) ;
## 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 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_nortti $(tlib) : : : <rtti>off : testing_crossmodule_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_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 ]
# 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 ]
# # 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 ]
# [ 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 ]
{
type_index += [ run $(p) ] ;
}
#for local p in [ glob ../examples/*.cpp ]
#{
# type_index += [ run $(p) ] ;
#}
+1 -1
View File
@@ -8,7 +8,7 @@
#define BOOST_TEST_MODULE template_index_test_module
#include <boost/test/unit_test.hpp>
#include <boost/type_index/template_index.hpp>
#include <boost/type_index.hpp>
namespace my_namespace1 {
class my_class{};
-191
View File
@@ -5,195 +5,4 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/functional/hash.hpp>
#include <boost/lexical_cast.hpp>
BOOST_AUTO_TEST_CASE(names_matches_template_id)
{
using namespace boost;
BOOST_CHECK_EQUAL(template_id<int>().name_demangled(), "int");
BOOST_CHECK_EQUAL(template_id<double>().name_demangled(), "double");
BOOST_CHECK_EQUAL(template_id<int>().name(), template_id<int>().name());
BOOST_CHECK_NE(template_id<int>().name(), template_id<double>().name());
BOOST_CHECK_NE(template_id<double>().name(), template_id<int>().name());
BOOST_CHECK_EQUAL(template_id<double>().name(), template_id<double>().name());
}
BOOST_AUTO_TEST_CASE(comparators_template_id)
{
using namespace boost;
template_index t_int = template_id<int>();
template_index t_double = template_id<double>();
BOOST_CHECK_EQUAL(t_int, t_int);
BOOST_CHECK_LE(t_int, t_int);
BOOST_CHECK_GE(t_int, t_int);
BOOST_CHECK_NE(t_int, t_double);
BOOST_CHECK_LE(t_double, t_double);
BOOST_CHECK_GE(t_double, t_double);
BOOST_CHECK_NE(t_double, t_int);
BOOST_CHECK(t_double < t_int || t_int < t_double);
BOOST_CHECK(t_double > t_int || t_int > t_double);
}
BOOST_AUTO_TEST_CASE(hash_code_template_id)
{
using namespace boost;
std::size_t t_int1 = template_id<int>().hash_code();
std::size_t t_double1 = template_id<double>().hash_code();
std::size_t t_int2 = template_id<int>().hash_code();
std::size_t t_double2 = template_id<double>().hash_code();
BOOST_CHECK_EQUAL(t_int1, t_int2);
BOOST_CHECK_NE(t_int1, t_double2);
BOOST_CHECK_LE(t_double1, t_double2);
}
template <class T1, class T2>
static void test_with_modofiers() {
using namespace boost;
template_index t1 = template_id_with_cvr<T1>();
template_index t2 = template_id_with_cvr<T2>();
BOOST_CHECK_NE(t2, t1);
BOOST_CHECK(t1 < t2 || t2 < t1);
BOOST_CHECK(t1 > t2 || t2 > t1);
BOOST_CHECK_EQUAL(t1, template_id_with_cvr<T1>());
BOOST_CHECK_EQUAL(t2, template_id_with_cvr<T2>());
BOOST_CHECK_EQUAL(t1.hash_code(), template_id_with_cvr<T1>().hash_code());
BOOST_CHECK_EQUAL(t2.hash_code(), template_id_with_cvr<T2>().hash_code());
BOOST_CHECK_NE(t1.hash_code(), template_id_with_cvr<T2>().hash_code());
BOOST_CHECK_NE(t2.hash_code(), template_id_with_cvr<T1>().hash_code());
}
BOOST_AUTO_TEST_CASE(template_id_storing_modifiers)
{
test_with_modofiers<int, const int>();
test_with_modofiers<int, const int&>();
test_with_modofiers<int, int&>();
test_with_modofiers<int, volatile int>();
test_with_modofiers<int, volatile int&>();
test_with_modofiers<int, const volatile int>();
test_with_modofiers<int, const volatile int&>();
test_with_modofiers<const int, int>();
test_with_modofiers<const int, const int&>();
test_with_modofiers<const int, int&>();
test_with_modofiers<const int, volatile int>();
test_with_modofiers<const int, volatile int&>();
test_with_modofiers<const int, const volatile int>();
test_with_modofiers<const int, const volatile int&>();
test_with_modofiers<const int&, int>();
test_with_modofiers<const int&, const int>();
test_with_modofiers<const int&, int&>();
test_with_modofiers<const int&, volatile int>();
test_with_modofiers<const int&, volatile int&>();
test_with_modofiers<const int&, const volatile int>();
test_with_modofiers<const int&, const volatile int&>();
test_with_modofiers<int&, const int>();
test_with_modofiers<int&, const int&>();
test_with_modofiers<int&, int>();
test_with_modofiers<int&, volatile int>();
test_with_modofiers<int&, volatile int&>();
test_with_modofiers<int&, const volatile int>();
test_with_modofiers<int&, const volatile int&>();
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
test_with_modofiers<int&&, const int>();
test_with_modofiers<int&&, const int&>();
test_with_modofiers<int&&, const int&&>();
test_with_modofiers<int&&, int>();
test_with_modofiers<int&&, volatile int>();
test_with_modofiers<int&&, volatile int&>();
test_with_modofiers<int&&, volatile int&&>();
test_with_modofiers<int&&, const volatile int>();
test_with_modofiers<int&&, const volatile int&>();
test_with_modofiers<int&&, const volatile int&&>();
#endif
}
template <class T>
static void test_storing_nonstoring_modifiers_templ() {
using namespace boost;
template_index t1 = template_id_with_cvr<T>();
template_index t2 = template_id<T>();
BOOST_CHECK_EQUAL(t2, t1);
BOOST_CHECK_EQUAL(t1, t2);
BOOST_CHECK(t1 <= t2);
BOOST_CHECK(t1 >= t2);
BOOST_CHECK(t2 <= t1);
BOOST_CHECK(t2 >= t1);
BOOST_CHECK_EQUAL(t2.name_demangled(), t1.name_demangled());
}
BOOST_AUTO_TEST_CASE(template_id_storing_modifiers_vs_nonstoring)
{
test_storing_nonstoring_modifiers_templ<int>();
test_storing_nonstoring_modifiers_templ<my_namespace1::my_class>();
test_storing_nonstoring_modifiers_templ<my_namespace2::my_class>();
boost::template_index t1 = boost::template_id_with_cvr<const int>();
boost::template_index t2 = boost::template_id<int>();
BOOST_CHECK_NE(t2, t1);
BOOST_CHECK(t1.name_demangled() == "const int" || t1.name_demangled() == "int const");
}
BOOST_AUTO_TEST_CASE(template_index_stream_operator_via_lexical_cast_testing)
{
using namespace boost;
std::string s_int2 = lexical_cast<std::string>(template_id<int>());
BOOST_CHECK_EQUAL(s_int2, "int");
std::string s_double2 = lexical_cast<std::string>(template_id<double>());
BOOST_CHECK_EQUAL(s_double2, "double");
}
BOOST_AUTO_TEST_CASE(template_index_stripping_cvr_test)
{
using namespace boost;
BOOST_CHECK_EQUAL(template_id<int>(), template_id<const int>());
BOOST_CHECK_EQUAL(template_id<int>(), template_id<const volatile int>());
BOOST_CHECK_EQUAL(template_id<int>(), template_id<const volatile int&>());
BOOST_CHECK_EQUAL(template_id<int>(), template_id<int&>());
BOOST_CHECK_EQUAL(template_id<int>(), template_id<volatile int>());
BOOST_CHECK_EQUAL(template_id<int>(), template_id<volatile int&>());
BOOST_CHECK_EQUAL(template_id<double>(), template_id<const double>());
BOOST_CHECK_EQUAL(template_id<double>(), template_id<const volatile double>());
BOOST_CHECK_EQUAL(template_id<double>(), template_id<const volatile double&>());
BOOST_CHECK_EQUAL(template_id<double>(), template_id<double&>());
BOOST_CHECK_EQUAL(template_id<double>(), template_id<volatile double>());
BOOST_CHECK_EQUAL(template_id<double>(), template_id<volatile double&>());
}
BOOST_AUTO_TEST_CASE(template_index_user_defined_class_test)
{
using namespace boost;
BOOST_CHECK_EQUAL(template_id<my_namespace1::my_class>(), template_id<my_namespace1::my_class>());
BOOST_CHECK_EQUAL(template_id<my_namespace2::my_class>(), template_id<my_namespace2::my_class>());
BOOST_CHECK_NE(template_id<my_namespace1::my_class>(), template_id<my_namespace2::my_class>());
BOOST_CHECK_NE(
template_id<my_namespace1::my_class>().name_demangled().find("my_namespace1::my_class"),
std::string::npos);
}
+194 -2
View File
@@ -8,7 +8,10 @@
#define BOOST_TEST_MODULE type_index_test_module
#include <boost/test/unit_test.hpp>
#include <boost/type_index/type_index.hpp>
#include <boost/type_index.hpp>
#include <boost/functional/hash.hpp>
#include <boost/lexical_cast.hpp>
namespace my_namespace1 {
class my_class{};
@@ -19,4 +22,193 @@ namespace my_namespace2 {
class my_class{};
}
#include "type_index_tests.ipp"
BOOST_AUTO_TEST_CASE(names_matches_type_id)
{
using namespace boost::typeind;
BOOST_CHECK_EQUAL(type_id<int>().pretty_name(), "int");
BOOST_CHECK_EQUAL(type_id<double>().pretty_name(), "double");
BOOST_CHECK_EQUAL(type_id<int>().name(), type_id<int>().name());
BOOST_CHECK_NE(type_id<int>().name(), type_id<double>().name());
BOOST_CHECK_NE(type_id<double>().name(), type_id<int>().name());
BOOST_CHECK_EQUAL(type_id<double>().name(), type_id<double>().name());
}
BOOST_AUTO_TEST_CASE(comparators_type_id)
{
using namespace boost::typeind;
type_index t_int = type_id<int>();
type_index t_double = type_id<double>();
BOOST_CHECK_EQUAL(t_int, t_int);
BOOST_CHECK_LE(t_int, t_int);
BOOST_CHECK_GE(t_int, t_int);
BOOST_CHECK_NE(t_int, t_double);
BOOST_CHECK_LE(t_double, t_double);
BOOST_CHECK_GE(t_double, t_double);
BOOST_CHECK_NE(t_double, t_int);
BOOST_CHECK(t_double < t_int || t_int < t_double);
BOOST_CHECK(t_double > t_int || t_int > t_double);
}
BOOST_AUTO_TEST_CASE(hash_code_type_id)
{
using namespace boost::typeind;
std::size_t t_int1 = type_id<int>().hash_code();
std::size_t t_double1 = type_id<double>().hash_code();
std::size_t t_int2 = type_id<int>().hash_code();
std::size_t t_double2 = type_id<double>().hash_code();
BOOST_CHECK_EQUAL(t_int1, t_int2);
BOOST_CHECK_NE(t_int1, t_double2);
BOOST_CHECK_LE(t_double1, t_double2);
}
template <class T1, class T2>
static void test_with_modofiers() {
using namespace boost::typeind;
type_index t1 = type_id_with_cvr<T1>();
type_index t2 = type_id_with_cvr<T2>();
BOOST_CHECK_NE(t2, t1);
BOOST_CHECK(t1 < t2 || t2 < t1);
BOOST_CHECK(t1 > t2 || t2 > t1);
BOOST_CHECK_EQUAL(t1, type_id_with_cvr<T1>());
BOOST_CHECK_EQUAL(t2, type_id_with_cvr<T2>());
BOOST_CHECK_EQUAL(t1.hash_code(), type_id_with_cvr<T1>().hash_code());
BOOST_CHECK_EQUAL(t2.hash_code(), type_id_with_cvr<T2>().hash_code());
BOOST_CHECK_NE(t1.hash_code(), type_id_with_cvr<T2>().hash_code());
BOOST_CHECK_NE(t2.hash_code(), type_id_with_cvr<T1>().hash_code());
}
BOOST_AUTO_TEST_CASE(type_id_storing_modifiers)
{
test_with_modofiers<int, const int>();
test_with_modofiers<int, const int&>();
test_with_modofiers<int, int&>();
test_with_modofiers<int, volatile int>();
test_with_modofiers<int, volatile int&>();
test_with_modofiers<int, const volatile int>();
test_with_modofiers<int, const volatile int&>();
test_with_modofiers<const int, int>();
test_with_modofiers<const int, const int&>();
test_with_modofiers<const int, int&>();
test_with_modofiers<const int, volatile int>();
test_with_modofiers<const int, volatile int&>();
test_with_modofiers<const int, const volatile int>();
test_with_modofiers<const int, const volatile int&>();
test_with_modofiers<const int&, int>();
test_with_modofiers<const int&, const int>();
test_with_modofiers<const int&, int&>();
test_with_modofiers<const int&, volatile int>();
test_with_modofiers<const int&, volatile int&>();
test_with_modofiers<const int&, const volatile int>();
test_with_modofiers<const int&, const volatile int&>();
test_with_modofiers<int&, const int>();
test_with_modofiers<int&, const int&>();
test_with_modofiers<int&, int>();
test_with_modofiers<int&, volatile int>();
test_with_modofiers<int&, volatile int&>();
test_with_modofiers<int&, const volatile int>();
test_with_modofiers<int&, const volatile int&>();
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
test_with_modofiers<int&&, const int>();
test_with_modofiers<int&&, const int&>();
test_with_modofiers<int&&, const int&&>();
test_with_modofiers<int&&, int>();
test_with_modofiers<int&&, volatile int>();
test_with_modofiers<int&&, volatile int&>();
test_with_modofiers<int&&, volatile int&&>();
test_with_modofiers<int&&, const volatile int>();
test_with_modofiers<int&&, const volatile int&>();
test_with_modofiers<int&&, const volatile int&&>();
#endif
}
template <class T>
static void test_storing_nonstoring_modifiers_templ() {
using namespace boost::typeind;
type_index t1 = type_id_with_cvr<T>();
type_index t2 = type_id<T>();
BOOST_CHECK_EQUAL(t2, t1);
BOOST_CHECK_EQUAL(t1, t2);
BOOST_CHECK(t1 <= t2);
BOOST_CHECK(t1 >= t2);
BOOST_CHECK(t2 <= t1);
BOOST_CHECK(t2 >= t1);
BOOST_CHECK_EQUAL(t2.pretty_name(), t1.pretty_name());
}
BOOST_AUTO_TEST_CASE(type_id_storing_modifiers_vs_nonstoring)
{
test_storing_nonstoring_modifiers_templ<int>();
test_storing_nonstoring_modifiers_templ<my_namespace1::my_class>();
test_storing_nonstoring_modifiers_templ<my_namespace2::my_class>();
boost::typeind::type_index t1 = boost::typeind::type_id_with_cvr<const int>();
boost::typeind::type_index t2 = boost::typeind::type_id<int>();
BOOST_CHECK_NE(t2, t1);
BOOST_CHECK(t1.pretty_name() == "const int" || t1.pretty_name() == "int const");
}
BOOST_AUTO_TEST_CASE(type_index_stream_operator_via_lexical_cast_testing)
{
using namespace boost::typeind;
std::string s_int2 = boost::lexical_cast<std::string>(type_id<int>());
BOOST_CHECK_EQUAL(s_int2, "int");
std::string s_double2 = boost::lexical_cast<std::string>(type_id<double>());
BOOST_CHECK_EQUAL(s_double2, "double");
}
BOOST_AUTO_TEST_CASE(type_index_stripping_cvr_test)
{
using namespace boost::typeind;
BOOST_CHECK_EQUAL(type_id<int>(), type_id<const int>());
BOOST_CHECK_EQUAL(type_id<int>(), type_id<const volatile int>());
BOOST_CHECK_EQUAL(type_id<int>(), type_id<const volatile int&>());
BOOST_CHECK_EQUAL(type_id<int>(), type_id<int&>());
BOOST_CHECK_EQUAL(type_id<int>(), type_id<volatile int>());
BOOST_CHECK_EQUAL(type_id<int>(), type_id<volatile int&>());
BOOST_CHECK_EQUAL(type_id<double>(), type_id<const double>());
BOOST_CHECK_EQUAL(type_id<double>(), type_id<const volatile double>());
BOOST_CHECK_EQUAL(type_id<double>(), type_id<const volatile double&>());
BOOST_CHECK_EQUAL(type_id<double>(), type_id<double&>());
BOOST_CHECK_EQUAL(type_id<double>(), type_id<volatile double>());
BOOST_CHECK_EQUAL(type_id<double>(), type_id<volatile double&>());
}
BOOST_AUTO_TEST_CASE(type_index_user_defined_class_test)
{
using namespace boost::typeind;
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>());
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);
}