test_macros.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2006-2013
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/intrusive for documentation.
  10. //
  11. /////////////////////////////////////////////////////////////////////////////
  12. #ifndef BOOST_INTRUSIVE_TEST_TEST_MACROS_HPP
  13. #define BOOST_INTRUSIVE_TEST_TEST_MACROS_HPP
  14. #include <boost/intrusive/intrusive_fwd.hpp>
  15. #include <algorithm> //std::unique
  16. namespace boost{
  17. namespace intrusive{
  18. namespace test{
  19. template <class T>
  20. struct is_multikey_true
  21. {
  22. typedef char yes_type;
  23. template<bool IsMultikey>
  24. struct two { yes_type _[1+IsMultikey]; };
  25. template <class U> static yes_type test(...);
  26. template <class U> static two<U::is_multikey>test(int);
  27. static const bool value = sizeof(test<T>(0)) != sizeof(yes_type);
  28. };
  29. } //namespace test{
  30. template<class It1, class It2>
  31. bool test_equal(It1 f1, It1 l1, It2 f2)
  32. {
  33. while(f1 != l1){
  34. if(*f1 != *f2){
  35. return false;
  36. }
  37. ++f1;
  38. ++f2;
  39. }
  40. return true;
  41. }
  42. #define TEST_INTRUSIVE_SEQUENCE( INTVALUES, ITERATOR )\
  43. { \
  44. BOOST_TEST (boost::intrusive::test_equal(&INTVALUES[0], &INTVALUES[0] + sizeof(INTVALUES)/sizeof(INTVALUES[0]), ITERATOR) ); \
  45. }
  46. #define TEST_INTRUSIVE_SEQUENCE_EXPECTED( EXPECTEDVECTOR, ITERATOR )\
  47. { \
  48. BOOST_TEST (boost::intrusive::test_equal(EXPECTEDVECTOR.begin(), EXPECTEDVECTOR.end(), ITERATOR) ); \
  49. }
  50. namespace test{
  51. template<class Container, class Vector>
  52. void test_intrusive_maybe_unique(const Container &c, Vector &v)
  53. {
  54. if(!is_multikey_true<Container>::value)
  55. v.erase(std::unique(v.begin(), v.end()), v.end());
  56. BOOST_TEST (boost::intrusive::test_equal(v.begin(), v.end(), c.begin()) );
  57. }
  58. } //namespace test{
  59. #define TEST_INTRUSIVE_SEQUENCE_MAYBEUNIQUE(INTVALUES, CONTAINER)\
  60. {\
  61. boost::container::vector<int>v(&INTVALUES[0], &INTVALUES[0] + sizeof(INTVALUES)/sizeof(INTVALUES[0]));\
  62. boost::intrusive::test::test_intrusive_maybe_unique(CONTAINER, v);\
  63. }\
  64. //
  65. } //namespace boost{
  66. } //namespace intrusive{
  67. #endif