forked from boostorg/type_index
Gix a Boost.test another chance, more macro definitions in build scripts
This commit is contained in:
@ -13,9 +13,9 @@ compat = <define>BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY ;
|
||||
|
||||
# Making own `nortti` that is link compatible.
|
||||
# We explicitly define BOOST_NO_RTTI because it sometimes can not be detected by build system.
|
||||
nortti = <toolset>gcc:"<cxxflags>-fno-rtti -DBOOST_NO_RTTI" <toolset>clang:"<cxxflags>-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID" <toolset>intel:"<cxxflags>-fno-rtti -DBOOST_NO_RTTI" <toolset>msvc:<cxxflags>/GR- ;
|
||||
nortti = <toolset>gcc:"<cxxflags>-fno-rtti -DBOOST_NO_RTTI" <toolset>clang:"<cxxflags>-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID" <toolset>intel:"<cxxflags>-fno-rtti -DBOOST_NO_RTTI" <toolset>darwin:"<cxxflags>-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID" <toolset>msvc:<cxxflags>/GR- ;
|
||||
|
||||
norttidefines = <toolset>gcc:"<cxxflags>-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" <toolset>clang:"<cxxflags>-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" <toolset>intel:"<cxxflags>-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" <toolset>msvc:<cxxflags>-DBOOST_NO_RTTI ;
|
||||
norttidefines = <toolset>gcc:"<cxxflags>-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" <toolset>clang:"<cxxflags>-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" <toolset>intel:"<cxxflags>-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" <toolset>darwin:"<cxxflags>-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" <toolset>msvc:<cxxflags>-DBOOST_NO_RTTI ;
|
||||
|
||||
|
||||
# Making libraries that CANNOT work between rtti-on/rtti-off modules
|
||||
|
105
test/test.hpp
105
test/test.hpp
@ -1,105 +0,0 @@
|
||||
//
|
||||
// Copyright Antony Polukhin, 2014.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// Unfortunately Boost.Test does not satisfies the requirements of Boost.TypeIndex library:
|
||||
// * Boost.Test fails to work with RTTI off
|
||||
// * release version of Boost.Test is not updated for a long time, so new fixes do not make their way to release
|
||||
|
||||
#ifndef BOOST_TEST_LIGHTWEIGHT_EMULATION
|
||||
#define BOOST_TEST_LIGHTWEIGHT_EMULATION
|
||||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <iostream>
|
||||
|
||||
namespace boost { namespace test_x2 {
|
||||
|
||||
|
||||
class tester {
|
||||
typedef void (*test_function_t)();
|
||||
typedef std::pair<const char*, test_function_t> pair_t;
|
||||
|
||||
private:
|
||||
std::vector<pair_t> tests_;
|
||||
int error_count_;
|
||||
|
||||
public:
|
||||
tester() : error_count_(0) {}
|
||||
|
||||
void on_fail() {
|
||||
++ error_count_;
|
||||
}
|
||||
|
||||
void add_test(const char* name, test_function_t func) {
|
||||
tests_.push_back(pair_t(name, func));
|
||||
}
|
||||
|
||||
int run() {
|
||||
std::cout << "Running " << tests_.size() << " tests\n";
|
||||
|
||||
for (std::size_t i = 0; i < tests_.size(); ++i) {
|
||||
std::cout << "Running '" << tests_[i].first << "' test case\n";
|
||||
(*tests_[i].second)(); // calling function
|
||||
}
|
||||
|
||||
return error_count_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
extern tester g_tester;
|
||||
|
||||
}} // namespace boost::test_x2
|
||||
|
||||
#define BOOST_AUTO_TEST_CASE(name) \
|
||||
void name (); \
|
||||
struct name ## _starter { name ## _starter () { \
|
||||
boost::test_x2::g_tester.add_test(#name, & name); \
|
||||
}} name ## _starter_variable; \
|
||||
void name () \
|
||||
/**/
|
||||
|
||||
|
||||
#define BOOST_CHECK(pred) \
|
||||
do{ \
|
||||
if(!(pred)){ \
|
||||
std::cout << __FILE__ << ":" << __LINE__ << ": Error in " << BOOST_STRINGIZE(pred) << std::endl; \
|
||||
boost::test_x2::g_tester.on_fail(); \
|
||||
} \
|
||||
}while(0)
|
||||
|
||||
#define BOOST_CHECK_TRIPLE_IMPL(x, oper, y) \
|
||||
do{ \
|
||||
if(!(x oper y)){ \
|
||||
std::cout << __FILE__ << ":" << __LINE__ << ": Error in " \
|
||||
<< BOOST_STRINGIZE(x) << BOOST_STRINGIZE(oper) << BOOST_STRINGIZE(y) \
|
||||
<< " where lhs = " << x << " and rhs = " << y << std::endl; \
|
||||
boost::test_x2::g_tester.on_fail(); \
|
||||
} \
|
||||
}while(0)
|
||||
|
||||
#define BOOST_CHECK_EQUAL(x, y) BOOST_CHECK_TRIPLE_IMPL(x, ==, y)
|
||||
#define BOOST_CHECK_NE(x, y) BOOST_CHECK_TRIPLE_IMPL(x, !=, y)
|
||||
#define BOOST_CHECK_LE(x, y) BOOST_CHECK_TRIPLE_IMPL(x, <=, y)
|
||||
#define BOOST_CHECK_GE(x, y) BOOST_CHECK_TRIPLE_IMPL(x, >=, y)
|
||||
|
||||
#endif // BOOST_TEST_LIGHTWEIGHT_EMULATION
|
||||
|
||||
|
||||
#ifdef BOOST_TEST_MODULE
|
||||
|
||||
namespace boost { namespace test_x2 {
|
||||
tester g_tester;
|
||||
}} // namespace boost::test_x2
|
||||
|
||||
int main() {
|
||||
return boost::test_x2::g_tester.run();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -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 "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;
|
||||
}
|
||||
|
||||
|
@ -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 "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;
|
||||
}
|
||||
|
||||
|
@ -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 "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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user