owner_less_test.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // owner_less_test.cpp
  3. //
  4. // A regression test for owner_less
  5. //
  6. // Copyright (c) 2008 Frank Mori Hess
  7. //
  8. // Distributed under the Boost Software License, Version 1.0.
  9. //
  10. // See accompanying file LICENSE_1_0.txt or copy at
  11. // http://www.boost.org/LICENSE_1_0.txt)
  12. //
  13. #include <boost/detail/lightweight_test.hpp>
  14. #include <boost/smart_ptr/owner_less.hpp>
  15. #include <boost/shared_ptr.hpp>
  16. #include <boost/weak_ptr.hpp>
  17. int main()
  18. {
  19. boost::owner_less<boost::shared_ptr<int> > comp;
  20. {
  21. boost::shared_ptr<int> x;
  22. boost::shared_ptr<int> y;
  23. boost::weak_ptr<int> w;
  24. BOOST_TEST(!(comp(x, w) || comp(w, x)));
  25. }
  26. {
  27. boost::shared_ptr<int> z((int*)0);
  28. boost::weak_ptr<int> w;
  29. BOOST_TEST(comp(z, w) || comp(w, z));
  30. {
  31. boost::shared_ptr<int> zz(z);
  32. w = boost::weak_ptr<int>(zz);
  33. BOOST_TEST(!(comp(z, zz) || comp(z, zz)));
  34. BOOST_TEST(!(comp(z, w) || comp(z, w)));
  35. }
  36. BOOST_TEST(!(comp(z, w) || comp(w, z)));
  37. }
  38. {
  39. boost::shared_ptr<int> x;
  40. boost::shared_ptr<int> z((int*)0);
  41. BOOST_TEST(comp(x, z) || comp(z, x));
  42. }
  43. {
  44. boost::shared_ptr<int> a((int*)0);
  45. boost::shared_ptr<int> b((int*)0);
  46. BOOST_TEST(comp(a, b) || comp(b, a));
  47. boost::weak_ptr<int> w(a);
  48. BOOST_TEST(!(comp(a, w) || comp(w, a)));
  49. BOOST_TEST(comp(b, w) || comp(w, b));
  50. }
  51. boost::owner_less<boost::weak_ptr<int> > weak_comp;
  52. {
  53. boost::shared_ptr<int> a((int*)0);
  54. boost::weak_ptr<int> wa(a);
  55. boost::shared_ptr<int> b((int*)0);
  56. boost::weak_ptr<int> wb(b);
  57. BOOST_TEST(!(weak_comp(a, wa) || weak_comp(wa, a)));
  58. BOOST_TEST(!(weak_comp(b, wb) || weak_comp(wb, b)));
  59. BOOST_TEST(weak_comp(wa, wb) || weak_comp(wb, wa));
  60. BOOST_TEST(weak_comp(wa, b) || weak_comp(b, wa));
  61. }
  62. return boost::report_errors();
  63. }