to_string_stub_test.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include <boost/exception/to_string_stub.hpp>
  5. #include <boost/detail/lightweight_test.hpp>
  6. #include <iostream>
  7. namespace
  8. n1
  9. {
  10. class
  11. c1
  12. {
  13. };
  14. std::string
  15. to_string( c1 const & )
  16. {
  17. return "c1";
  18. }
  19. }
  20. namespace
  21. n2
  22. {
  23. class
  24. c2
  25. {
  26. };
  27. std::ostream &
  28. operator<<( std::ostream & s, c2 const & )
  29. {
  30. s << "c2";
  31. return s;
  32. }
  33. }
  34. namespace
  35. n3
  36. {
  37. class
  38. c3
  39. {
  40. };
  41. std::ostream &
  42. operator<<( std::ostream & s, c3 const & )
  43. {
  44. s << "bad";
  45. return s;
  46. }
  47. std::string
  48. to_string( c3 const & )
  49. {
  50. return "c3";
  51. }
  52. }
  53. namespace
  54. boost
  55. {
  56. class
  57. to_string_tester
  58. {
  59. };
  60. }
  61. template <class T>
  62. struct
  63. my_stub
  64. {
  65. std::string
  66. operator()( T const & )
  67. {
  68. return "stub";
  69. }
  70. };
  71. int
  72. main()
  73. {
  74. using namespace boost;
  75. BOOST_TEST( to_string(42)=="42" );
  76. BOOST_TEST( to_string(n1::c1())=="c1" );
  77. BOOST_TEST( to_string(n2::c2())=="c2" );
  78. BOOST_TEST( to_string(n3::c3())=="c3" );
  79. BOOST_TEST( to_string_stub(42)=="42" );
  80. BOOST_TEST( to_string_stub(n1::c1())=="c1" );
  81. BOOST_TEST( to_string_stub(n2::c2())=="c2" );
  82. BOOST_TEST( to_string_stub(n3::c3())=="c3" );
  83. BOOST_TEST( to_string_stub(to_string_tester(),my_stub<to_string_tester>())=="stub" );
  84. BOOST_TEST( !to_string_stub(to_string_tester()).empty() );
  85. return boost::report_errors();
  86. }