diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 9c96485..dc2b86f 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -13,9 +13,9 @@ compat = 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 = gcc:"-fno-rtti -DBOOST_NO_RTTI" clang:"-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID" intel:"-fno-rtti -DBOOST_NO_RTTI" msvc:/GR- ; +nortti = gcc:"-fno-rtti -DBOOST_NO_RTTI" clang:"-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID" intel:"-fno-rtti -DBOOST_NO_RTTI" darwin:"-fno-rtti -DBOOST_NO_RTTI -DBOOST_NO_TYPEID" msvc:/GR- ; -norttidefines = gcc:"-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" clang:"-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" intel:"-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" msvc:-DBOOST_NO_RTTI ; +norttidefines = gcc:"-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" clang:"-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" intel:"-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" darwin:"-DBOOST_NO_RTTI -DBOOST_NO_TYPEID" msvc:-DBOOST_NO_RTTI ; # Making libraries that CANNOT work between rtti-on/rtti-off modules diff --git a/test/test.hpp b/test/test.hpp deleted file mode 100644 index f0fbb79..0000000 --- a/test/test.hpp +++ /dev/null @@ -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 -#include -#include - -namespace boost { namespace test_x2 { - - -class tester { - typedef void (*test_function_t)(); - typedef std::pair pair_t; - -private: - std::vector 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 - - diff --git a/test/testing_crossmodule.cpp b/test/testing_crossmodule.cpp index 8a96f2c..859d678 100644 --- a/test/testing_crossmodule.cpp +++ b/test/testing_crossmodule.cpp @@ -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 #include #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(); boost::typeindex::type_index t_int = boost::typeindex::type_id(); @@ -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; +} + diff --git a/test/testing_crossmodule_anonymous.cpp b/test/testing_crossmodule_anonymous.cpp index deee42c..825af61 100644 --- a/test/testing_crossmodule_anonymous.cpp +++ b/test/testing_crossmodule_anonymous.cpp @@ -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 #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(); boost::typeindex::type_index t_userdef = boost::typeindex::type_id(); @@ -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; +} + diff --git a/test/type_index_test.cpp b/test/type_index_test.cpp index ab20c22..8f2771a 100644 --- a/test/type_index_test.cpp +++ b/test/type_index_test.cpp @@ -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 #include #include #include +#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().pretty_name(), "int"); @@ -35,7 +40,7 @@ BOOST_AUTO_TEST_CASE(names_matches_type_id) BOOST_CHECK_EQUAL(type_id().name(), type_id().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(); @@ -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(); @@ -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().hash_code(); @@ -92,6 +97,8 @@ BOOST_AUTO_TEST_CASE(hash_code_type_id) BOOST_CHECK_LE(t_double1, t_double2); } + + template 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().hash_code()); } -BOOST_AUTO_TEST_CASE(type_id_storing_modifiers) +void type_id_storing_modifiers() { test_with_modofiers(); test_with_modofiers(); @@ -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(); test_storing_nonstoring_modifiers_templ(); @@ -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(); @@ -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; +} +