| 1 | // ------------------------------------------------------------------------------ |
| 2 | // format_test_enum.cpp : test format use with enums |
| 3 | // ------------------------------------------------------------------------------ |
| 4 | |
| 5 | // Copyright Steven Watanabe 2009. |
| 6 | // |
| 7 | // Distributed under the Boost Software License, Version 1.0. (See |
| 8 | // accompanying file LICENSE_1_0.txt or copy at |
| 9 | // http://www.boost.org/LICENSE_1_0.txt) |
| 10 | |
| 11 | // See http://www.boost.org/libs/format for library home page |
| 12 | |
| 13 | // ------------------------------------------------------------------------------ |
| 14 | |
| 15 | #include "boost/format.hpp" |
| 16 | |
| 17 | #define BOOST_INCLUDE_MAIN |
| 18 | #include <boost/test/test_tools.hpp> |
| 19 | |
| 20 | enum enum_plain { PLAIN }; |
| 21 | enum { ANONYMOUS }; |
| 22 | enum enum_overloaded { OVERLOADED }; |
| 23 | typedef enum { OVERLOADED_TYPEDEF } enum_overloaded_typedef; |
| 24 | |
| 25 | std::ostream& operator<<(std::ostream& os, enum_overloaded) { |
| 26 | os << "overloaded"; |
| 27 | return(os); |
| 28 | } |
| 29 | |
| 30 | std::ostream& operator<<(std::ostream& os, enum_overloaded_typedef) { |
| 31 | os << "overloaded"; |
| 32 | return(os); |
| 33 | } |
| 34 | |
| 35 | int test_main(int, char*[]) { |
| 36 | // in this case, we should implicitly convert to int |
| 37 | BOOST_CHECK_EQUAL((boost::format("%d") % PLAIN).str(), "0"); |
| 38 | BOOST_CHECK_EQUAL((boost::format("%d") % ANONYMOUS).str(), "0"); |
| 39 | |
| 40 | // but here we need to use the overloaded operator |
| 41 | BOOST_CHECK_EQUAL((boost::format("%s") % OVERLOADED).str(), "overloaded"); |
| 42 | BOOST_CHECK_EQUAL((boost::format("%s") % OVERLOADED_TYPEDEF).str(), "overloaded"); |
| 43 | |
| 44 | return 0; |
| 45 | } |