lexical_cast_abstract_test.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Unit test for boost::lexical_cast.
  2. //
  3. // See http://www.boost.org for most recent version, including documentation.
  4. //
  5. // Copyright Sergey Shandar 2005, Alexander Nasonov, 2007.
  6. //
  7. // Distributed under the Boost
  8. // Software License, Version 1.0. (See accompanying file
  9. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
  10. //
  11. // Test abstract class. Bug 1358600:
  12. // http://sf.net/tracker/?func=detail&aid=1358600&group_id=7586&atid=107586
  13. #include <boost/config.hpp>
  14. #if defined(__INTEL_COMPILER)
  15. #pragma warning(disable: 193 383 488 981 1418 1419)
  16. #elif defined(BOOST_MSVC)
  17. #pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
  18. #endif
  19. #include <boost/lexical_cast.hpp>
  20. #include <boost/test/unit_test.hpp>
  21. using namespace boost;
  22. void test_abstract();
  23. unit_test::test_suite *init_unit_test_suite(int, char *[])
  24. {
  25. unit_test::test_suite *suite =
  26. BOOST_TEST_SUITE("lexical_cast unit test");
  27. suite->add(BOOST_TEST_CASE(&test_abstract));
  28. return suite;
  29. }
  30. class A
  31. {
  32. public:
  33. virtual void out(std::ostream &) const = 0;
  34. virtual ~A() {}
  35. };
  36. class B: public A
  37. {
  38. public:
  39. virtual void out(std::ostream &O) const { O << "B"; }
  40. };
  41. std::ostream &operator<<(std::ostream &O, const A &a)
  42. {
  43. a.out(O);
  44. return O;
  45. }
  46. void test_abstract()
  47. {
  48. const A &a = B();
  49. BOOST_CHECK(boost::lexical_cast<std::string>(a) == "B");
  50. }