• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
14 #include <boost/config.hpp>
15 
16 #if defined(__INTEL_COMPILER)
17 #pragma warning(disable: 193 383 488 981 1418 1419)
18 #elif defined(BOOST_MSVC)
19 #pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
20 #endif
21 
22 #include <boost/lexical_cast.hpp>
23 #include <boost/test/unit_test.hpp>
24 
25 using namespace boost;
26 
27 void test_abstract();
28 
init_unit_test_suite(int,char * [])29 unit_test::test_suite *init_unit_test_suite(int, char *[])
30 {
31     unit_test::test_suite *suite =
32         BOOST_TEST_SUITE("lexical_cast unit test");
33     suite->add(BOOST_TEST_CASE(&test_abstract));
34 
35     return suite;
36 }
37 
38 class A
39 {
40 public:
41     virtual void out(std::ostream &) const = 0;
~A()42     virtual ~A() {}
43 };
44 
45 class B: public A
46 {
47 public:
out(std::ostream & O) const48     virtual void out(std::ostream &O) const { O << "B"; }
49 };
50 
operator <<(std::ostream & O,const A & a)51 std::ostream &operator<<(std::ostream &O, const A &a)
52 {
53     a.out(O);
54     return O;
55 }
56 
test_abstract()57 void test_abstract()
58 {
59     const A &a = B();
60     BOOST_CHECK(boost::lexical_cast<std::string>(a) == "B");
61 }
62 
63