From 5f5d6bf45fdea9661cb6fd8400ac1bf44fc34f92 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Fri, 18 Oct 2013 13:59:09 +0400 Subject: [PATCH] Added cross module tests --- libs/type_index/test/Jamfile.v2 | 24 ++++++----- libs/type_index/test/test_lib.cpp | 27 ++++++++++++ libs/type_index/test/test_lib.hpp | 37 +++++++++++++++++ libs/type_index/test/testing_crossmodule.cpp | 43 ++++++++++++++++++++ 4 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 libs/type_index/test/test_lib.cpp create mode 100644 libs/type_index/test/test_lib.hpp create mode 100644 libs/type_index/test/testing_crossmodule.cpp diff --git a/libs/type_index/test/Jamfile.v2 b/libs/type_index/test/Jamfile.v2 index 3a5dec8..22f7686 100644 --- a/libs/type_index/test/Jamfile.v2 +++ b/libs/type_index/test/Jamfile.v2 @@ -7,20 +7,22 @@ import testing ; import feature ; -project - : requirements - /boost/test//boost_unit_test_framework - static - ; +tlib = /boost/test//boost_unit_test_framework/static ; + +lib test_lib_rtti : test_lib.cpp : shared ; +lib test_lib_nortti : test_lib.cpp : shared off ; test-suite type_index : - [ run type_index_test.cpp ] - [ run template_index_test.cpp ] - [ run testing_both.cpp ] - [ run testing_both_no_rtti.cpp : : : off ] - [ run testing_minimal.cpp ] - [ run testing_minimal_no_rtti.cpp : : : off ] + [ run type_index_test.cpp $(tlib) ] + [ run template_index_test.cpp $(tlib) ] + [ run testing_both.cpp $(tlib) ] + [ run testing_both_no_rtti.cpp $(tlib) : : : off ] + [ run testing_minimal.cpp $(tlib) ] + [ run testing_minimal_no_rtti.cpp $(tlib) : : : off ] + [ run testing_crossmodule.cpp test_lib_rtti $(tlib) ] + [ run testing_crossmodule.cpp test_lib_nortti $(tlib) : : : off : testing_crossmodule_no_rtti ] + # Examples that must work even with RTTI disabled [ run ../examples/registry.cpp : : : off : registry_no_rtti ] [ run ../examples/exact_types_match.cpp : : : off : exact_types_match_no_rtti ] diff --git a/libs/type_index/test/test_lib.cpp b/libs/type_index/test/test_lib.cpp new file mode 100644 index 0000000..d012dac --- /dev/null +++ b/libs/type_index/test/test_lib.cpp @@ -0,0 +1,27 @@ +#define TEST_LIB_SOURCE +#include "test_lib.hpp" + +namespace user_defined_namespace { + class user_defined{}; +} + +namespace test_lib { + +boost::type_index get_integer() { + return boost::type_id(); +} + +boost::type_index get_user_defined_class() { + return boost::type_id(); +} + +boost::type_index get_const_integer() { + return boost::type_id_with_cvr(); +} + +boost::type_index get_const_user_defined_class() { + return boost::type_id_with_cvr(); +} + +} + diff --git a/libs/type_index/test/test_lib.hpp b/libs/type_index/test/test_lib.hpp new file mode 100644 index 0000000..0bafed4 --- /dev/null +++ b/libs/type_index/test/test_lib.hpp @@ -0,0 +1,37 @@ +// +// Copyright (c) Antony Polukhin, 2012-2013. +// +// +// 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) +// + +#ifndef BOOST_TYPE_INDEX_TESTS_TEST_LIB_HPP +#define BOOST_TYPE_INDEX_TESTS_TEST_LIB_HPP + +// MS compatible compilers support #pragma once +#if defined(_MSC_VER) +# pragma once +#endif + +#include + +// This is ALWAYS a dynamic library +#if defined(TEST_LIB_SOURCE) +# define TEST_LIB_DECL BOOST_SYMBOL_EXPORT +# else +# define TEST_LIB_DECL BOOST_SYMBOL_IMPORT +# endif + +namespace test_lib { + +TEST_LIB_DECL boost::type_index get_integer(); +TEST_LIB_DECL boost::type_index get_user_defined_class(); + +TEST_LIB_DECL boost::type_index get_const_integer(); +TEST_LIB_DECL boost::type_index get_const_user_defined_class(); + +} + +#endif // BOOST_TYPE_INDEX_TESTS_LIB1_HPP + diff --git a/libs/type_index/test/testing_crossmodule.cpp b/libs/type_index/test/testing_crossmodule.cpp new file mode 100644 index 0000000..16d863c --- /dev/null +++ b/libs/type_index/test/testing_crossmodule.cpp @@ -0,0 +1,43 @@ +// +// Copyright Antony Polukhin, 2012-2013. +// +// 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) + +#define BOOST_TEST_MODULE testing_crossmodule_module +#include + +#include +#include "test_lib.hpp" + +namespace user_defined_namespace { + class user_defined{}; +} + +BOOST_AUTO_TEST_CASE(comparing_types_between_modules) +{ + boost::type_index t_const_int = boost::type_id_with_cvr(); + boost::type_index t_int = boost::type_id(); + + BOOST_CHECK_EQUAL(t_int, test_lib::get_integer()); + BOOST_CHECK_EQUAL(t_const_int, test_lib::get_const_integer()); + BOOST_CHECK_NE(t_const_int, test_lib::get_integer()); + BOOST_CHECK_NE(t_int, test_lib::get_const_integer()); + + + boost::type_index t_const_userdef = boost::type_id_with_cvr(); + boost::type_index t_userdef = boost::type_id(); + + BOOST_CHECK_EQUAL(t_userdef, test_lib::get_user_defined_class()); + BOOST_CHECK_EQUAL(t_const_userdef, test_lib::get_const_user_defined_class()); + BOOST_CHECK_NE(t_const_userdef, test_lib::get_user_defined_class()); + BOOST_CHECK_NE(t_userdef, test_lib::get_const_user_defined_class()); + + + BOOST_CHECK_NE(t_userdef, test_lib::get_integer()); + BOOST_CHECK_NE(t_const_userdef, test_lib::get_integer()); + BOOST_CHECK_NE(t_int, test_lib::get_user_defined_class()); + BOOST_CHECK_NE(t_const_int, test_lib::get_const_user_defined_class()); +} +