testing_crossmodule.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // Copyright 2012-2019 Antony Polukhin.
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/type_index.hpp>
  8. #include "test_lib.hpp"
  9. #include <boost/core/lightweight_test.hpp>
  10. namespace user_defined_namespace {
  11. class user_defined{};
  12. }
  13. void comparing_types_between_modules()
  14. {
  15. boost::typeindex::type_index t_const_int = boost::typeindex::type_id_with_cvr<const int>();
  16. boost::typeindex::type_index t_int = boost::typeindex::type_id<int>();
  17. BOOST_TEST_EQ(t_int, test_lib::get_integer());
  18. BOOST_TEST_EQ(t_const_int, test_lib::get_const_integer());
  19. BOOST_TEST_NE(t_const_int, test_lib::get_integer());
  20. BOOST_TEST_NE(t_int, test_lib::get_const_integer());
  21. boost::typeindex::type_index t_const_userdef
  22. = boost::typeindex::type_id_with_cvr<const user_defined_namespace::user_defined>();
  23. boost::typeindex::type_index t_userdef
  24. = boost::typeindex::type_id<user_defined_namespace::user_defined>();
  25. BOOST_TEST_EQ(t_userdef, test_lib::get_user_defined_class());
  26. BOOST_TEST_EQ(t_const_userdef, test_lib::get_const_user_defined_class());
  27. BOOST_TEST_NE(t_const_userdef, test_lib::get_user_defined_class());
  28. BOOST_TEST_NE(t_userdef, test_lib::get_const_user_defined_class());
  29. BOOST_TEST_NE(t_userdef, test_lib::get_integer());
  30. BOOST_TEST_NE(t_const_userdef, test_lib::get_integer());
  31. BOOST_TEST_NE(t_int, test_lib::get_user_defined_class());
  32. BOOST_TEST_NE(t_const_int, test_lib::get_const_user_defined_class());
  33. // MSVC supports detect_missmatch pragma, but /GR- silently switch disable the link time check.
  34. // /GR- undefies the _CPPRTTI macro. Using it to detect working detect_missmatch pragma.
  35. #if !defined(BOOST_HAS_PRAGMA_DETECT_MISMATCH) || !defined(_CPPRTTI)
  36. test_lib::accept_typeindex(t_int);
  37. #endif
  38. }
  39. int main() {
  40. comparing_types_between_modules();
  41. return boost::report_errors();
  42. }