From 6857f23e6f87e10480dfe0400195fee68a8d1702 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Tue, 20 May 2014 21:22:40 +0400 Subject: [PATCH] Use minimal subset of Boost.Test and do not depend on ability of Boost.Test to work with rtti off --- test/Jamfile.v2 | 25 +++++------ test/testing_crossmodule.cpp | 15 +++++-- test/testing_crossmodule_anonymous.cpp | 13 ++++-- test/type_index_test.cpp | 58 +++++++++++++++++++------- 4 files changed, 77 insertions(+), 34 deletions(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 277944e..819bc65 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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/static ; - # Variable that contains all the stuff required for linking together on and off compat = BOOST_TYPE_INDEX_FORCE_NO_RTTI_COMPATIBILITY ; @@ -39,23 +36,23 @@ lib test_lib_rtti_compat : test_lib_rtti_compat-obj : shared $(nortti) $(c test-suite type_index : - [ run type_index_test.cpp $(tlib) ] - [ run type_index_test.cpp $(tlib) : : : off : type_index_test_no_rtti ] - [ run ctti_print_name.cpp : : : always_show_run_output ] - [ run testing_crossmodule.cpp test_lib_rtti $(tlib) ] - [ run testing_crossmodule.cpp test_lib_nortti $(tlib) : : : 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) : : : off : testing_crossmodule_anonymous_no_rtti ] + [ run type_index_test.cpp ] + [ run type_index_test.cpp : : : off : type_index_test_no_rtti ] + [ run ctti_print_name.cpp : : : always_show_run_output ] + [ run testing_crossmodule.cpp test_lib_rtti ] + [ run testing_crossmodule.cpp test_lib_nortti : : : off : testing_crossmodule_no_rtti ] + [ run testing_crossmodule_anonymous.cpp test_lib_anonymous_rtti ] + [ run testing_crossmodule_anonymous.cpp test_lib_anonymous_nortti : : : 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. diff --git a/test/testing_crossmodule.cpp b/test/testing_crossmodule.cpp index 3204bd4..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 +#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 d9e2b0e..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 +#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 60e7f73..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 +#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; +} +