Use minimal subset of Boost.Test and do not depend on ability of Boost.Test to work with rtti off

This commit is contained in:
Antony Polukhin
2014-05-20 21:22:40 +04:00
parent ce103443fd
commit 6857f23e6f
4 changed files with 77 additions and 34 deletions

View File

@ -8,9 +8,6 @@ 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 ;
# Variable that contains all the stuff required for linking together <rtti>on and <rtti>off
compat = <define>BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY ;
@ -39,23 +36,23 @@ lib test_lib_rtti_compat : test_lib_rtti_compat-obj : <link>shared $(nortti) $(c
test-suite type_index
:
[ run type_index_test.cpp $(tlib) ]
[ run type_index_test.cpp $(tlib) : : : <rtti>off : type_index_test_no_rtti ]
[ run ctti_print_name.cpp : : : <test-info>always_show_run_output ]
[ run testing_crossmodule.cpp test_lib_rtti $(tlib) ]
[ run testing_crossmodule.cpp test_lib_nortti $(tlib) : : : <rtti>off : testing_crossmodule_no_rtti ]
[ run testing_crossmodule_anonymous.cpp test_lib_anonymous_rtti $(tlib) ]
[ run testing_crossmodule_anonymous.cpp test_lib_anonymous_nortti $(tlib) : : : <rtti>off : testing_crossmodule_anonymous_no_rtti ]
[ run type_index_test.cpp ]
[ run type_index_test.cpp : : : <rtti>off : type_index_test_no_rtti ]
[ run ctti_print_name.cpp : : : <test-info>always_show_run_output ]
[ run testing_crossmodule.cpp test_lib_rtti ]
[ run testing_crossmodule.cpp test_lib_nortti : : : <rtti>off : testing_crossmodule_no_rtti ]
[ run testing_crossmodule_anonymous.cpp test_lib_anonymous_rtti ]
[ run testing_crossmodule_anonymous.cpp test_lib_anonymous_nortti : : : <rtti>off : testing_crossmodule_anonymous_no_rtti ]
[ compile-fail type_index_test_ctti_copy_fail.cpp ]
[ compile-fail type_index_test_ctti_construct_fail.cpp ]
[ compile type_index_test_ctti_alignment.cpp ]
# Mixing RTTI on and off
[ link-fail testing_crossmodule.cpp $(tlib) test_lib_rtti : $(nortti) : link_fail_nortti_rtti ]
[ link-fail testing_crossmodule.cpp 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 ]
#[ link-fail testing_crossmodule.cpp test_lib_nortti : : link_fail_rtti_nortti ]
[ run testing_crossmodule.cpp test_lib_rtti_compat : : : $(nortti) $(compat) : testing_crossmodule_nortti_rtti_compat ]
[ run testing_crossmodule.cpp test_lib_nortti_compat : : : $(compat) : testing_crossmodule_rtti_nortti_compat ]
;
# Assuring that examples compile and run. Adding sources from `examples` directory to the `type_index` test suite.

View File

@ -5,17 +5,19 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_TEST_MODULE testing_crossmodule_module
#include <boost/test/unit_test.hpp>
#include <boost/test/minimal.hpp>
#include <boost/type_index.hpp>
#include "test_lib.hpp"
#define BOOST_CHECK_EQUAL(x, y) BOOST_CHECK(x == y)
#define BOOST_CHECK_NE(x, y) BOOST_CHECK(x != y)
namespace user_defined_namespace {
class user_defined{};
}
BOOST_AUTO_TEST_CASE(comparing_types_between_modules)
void comparing_types_between_modules()
{
boost::typeindex::type_index t_const_int = boost::typeindex::type_id_with_cvr<const int>();
boost::typeindex::type_index t_int = boost::typeindex::type_id<int>();
@ -45,3 +47,10 @@ BOOST_AUTO_TEST_CASE(comparing_types_between_modules)
test_lib::accept_typeindex(t_int);
}
int test_main(int , char* []) {
comparing_types_between_modules();
return 0;
}

View File

@ -5,17 +5,18 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_TEST_MODULE testing_crossmodule_anon_module
#include <boost/test/unit_test.hpp>
#include "boost/test/minimal.hpp"
#include <boost/type_index.hpp>
#include "test_lib_anonymous.hpp"
#define BOOST_CHECK_NE(x, y) BOOST_CHECK(x != y)
namespace {
class user_defined{};
}
BOOST_AUTO_TEST_CASE(comparing_anonymous_types_between_modules)
void comparing_anonymous_types_between_modules()
{
boost::typeindex::type_index t_const_userdef = boost::typeindex::type_id_with_cvr<const user_defined>();
boost::typeindex::type_index t_userdef = boost::typeindex::type_id<user_defined>();
@ -26,3 +27,9 @@ BOOST_AUTO_TEST_CASE(comparing_anonymous_types_between_modules)
BOOST_CHECK_NE(t_userdef, test_lib::get_const_anonymous_user_defined_class());
}
int test_main(int , char* []) {
comparing_anonymous_types_between_modules();
return 0;
}

View File

@ -5,14 +5,19 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_TEST_MODULE type_index_test_module
#include <boost/test/unit_test.hpp>
#include <boost/test/minimal.hpp>
#include <boost/type_index.hpp>
#include <boost/functional/hash.hpp>
#include <boost/lexical_cast.hpp>
#define BOOST_CHECK_EQUAL(x, y) BOOST_CHECK(x == y)
#define BOOST_CHECK_NE(x, y) BOOST_CHECK(x != y)
#define BOOST_CHECK_LE(x, y) BOOST_CHECK(x <= y)
#define BOOST_CHECK_GE(x, y) BOOST_CHECK(x >= y)
namespace my_namespace1 {
class my_class{};
}
@ -23,7 +28,7 @@ namespace my_namespace2 {
}
BOOST_AUTO_TEST_CASE(names_matches_type_id)
void names_matches_type_id()
{
using namespace boost::typeindex;
BOOST_CHECK_EQUAL(type_id<int>().pretty_name(), "int");
@ -35,7 +40,7 @@ BOOST_AUTO_TEST_CASE(names_matches_type_id)
BOOST_CHECK_EQUAL(type_id<double>().name(), type_id<double>().name());
}
BOOST_AUTO_TEST_CASE(default_construction)
void default_construction()
{
using namespace boost::typeindex;
type_index ti1, ti2;
@ -47,7 +52,7 @@ BOOST_AUTO_TEST_CASE(default_construction)
}
BOOST_AUTO_TEST_CASE(copy_construction)
void copy_construction()
{
using namespace boost::typeindex;
type_index ti1, ti2 = type_id<int>();
@ -59,7 +64,7 @@ BOOST_AUTO_TEST_CASE(copy_construction)
BOOST_CHECK_EQUAL(ti3, ti1);
}
BOOST_AUTO_TEST_CASE(comparators_type_id)
void comparators_type_id()
{
using namespace boost::typeindex;
type_index t_int = type_id<int>();
@ -78,7 +83,7 @@ BOOST_AUTO_TEST_CASE(comparators_type_id)
BOOST_CHECK(t_double > t_int || t_int > t_double);
}
BOOST_AUTO_TEST_CASE(hash_code_type_id)
void hash_code_type_id()
{
using namespace boost::typeindex;
std::size_t t_int1 = type_id<int>().hash_code();
@ -92,6 +97,8 @@ BOOST_AUTO_TEST_CASE(hash_code_type_id)
BOOST_CHECK_LE(t_double1, t_double2);
}
template <class T1, class T2>
static void test_with_modofiers() {
using namespace boost::typeindex;
@ -132,7 +139,7 @@ static void test_with_modofiers() {
BOOST_CHECK_NE(t2.hash_code(), type_id_with_cvr<T1>().hash_code());
}
BOOST_AUTO_TEST_CASE(type_id_storing_modifiers)
void type_id_storing_modifiers()
{
test_with_modofiers<int, const int>();
test_with_modofiers<int, const int&>();
@ -197,7 +204,7 @@ static void test_storing_nonstoring_modifiers_templ() {
BOOST_CHECK_EQUAL(t2.pretty_name(), t1.pretty_name());
}
BOOST_AUTO_TEST_CASE(type_id_storing_modifiers_vs_nonstoring)
void type_id_storing_modifiers_vs_nonstoring()
{
test_storing_nonstoring_modifiers_templ<int>();
test_storing_nonstoring_modifiers_templ<my_namespace1::my_class>();
@ -209,7 +216,7 @@ BOOST_AUTO_TEST_CASE(type_id_storing_modifiers_vs_nonstoring)
BOOST_CHECK(t1.pretty_name() == "const int" || t1.pretty_name() == "int const");
}
BOOST_AUTO_TEST_CASE(type_index_stream_operator_via_lexical_cast_testing)
void type_index_stream_operator_via_lexical_cast_testing()
{
using namespace boost::typeindex;
@ -220,7 +227,7 @@ BOOST_AUTO_TEST_CASE(type_index_stream_operator_via_lexical_cast_testing)
BOOST_CHECK_EQUAL(s_double2, "double");
}
BOOST_AUTO_TEST_CASE(type_index_stripping_cvr_test)
void type_index_stripping_cvr_test()
{
using namespace boost::typeindex;
@ -243,7 +250,7 @@ BOOST_AUTO_TEST_CASE(type_index_stripping_cvr_test)
}
BOOST_AUTO_TEST_CASE(type_index_user_defined_class_test)
void type_index_user_defined_class_test()
{
using namespace boost::typeindex;
@ -264,6 +271,9 @@ BOOST_AUTO_TEST_CASE(type_index_user_defined_class_test)
}
struct A {
public:
BOOST_TYPE_INDEX_REGISTER_CLASS
@ -278,7 +288,7 @@ struct C: public B {
BOOST_TYPE_INDEX_REGISTER_CLASS
};
BOOST_AUTO_TEST_CASE(comparators_type_id_runtime)
void comparators_type_id_runtime()
{
C c1;
B b1;
@ -325,7 +335,7 @@ BOOST_AUTO_TEST_CASE(comparators_type_id_runtime)
#ifndef BOOST_NO_RTTI
BOOST_AUTO_TEST_CASE(comparators_type_id_vs_type_info)
void comparators_type_id_vs_type_info()
{
using namespace boost::typeindex;
type_index t_int = type_id<int>();
@ -375,3 +385,23 @@ BOOST_AUTO_TEST_CASE(comparators_type_id_vs_type_info)
#endif // BOOST_NO_RTTI
int test_main(int , char* []) {
names_matches_type_id();
default_construction();
copy_construction();
comparators_type_id();
hash_code_type_id();
type_id_storing_modifiers();
type_id_storing_modifiers_vs_nonstoring();
type_index_stream_operator_via_lexical_cast_testing();
type_index_stripping_cvr_test();
type_index_user_defined_class_test();
comparators_type_id_runtime();
#ifndef BOOST_NO_RTTI
comparators_type_id_vs_type_info();
#endif
return 0;
}