blob: 50f297257d29b4e5c2675bd8a70b00329158dfaf [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// (C) Copyright Gennadiy Rozental 2004-2008.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5
6// See http://www.boost.org/libs/test for the library home page.
7//
8// File : $RCSfile$
9//
10// Version : $Revision: 57992 $
11//
12// Description : common code used by any agent serving as XML printer
13// ***************************************************************************
14
Jeff Thompson3d613fd2013-10-15 15:39:04 -070015#ifndef NDNBOOST_TEST_XML_PRINTER_HPP_071894GER
16#define NDNBOOST_TEST_XML_PRINTER_HPP_071894GER
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070017
18// Boost.Test
19#include <ndnboost/test/utils/basic_cstring/basic_cstring.hpp>
20#include <ndnboost/test/utils/fixed_mapping.hpp>
21#include <ndnboost/test/utils/custom_manip.hpp>
22#include <ndnboost/test/utils/foreach.hpp>
23#include <ndnboost/test/utils/basic_cstring/io.hpp>
24
25// Boost
26#include <ndnboost/config.hpp>
27
28// STL
29#include <iostream>
30
31#include <ndnboost/test/detail/suppress_warnings.hpp>
32
33//____________________________________________________________________________//
34
35namespace ndnboost {
36
37namespace unit_test {
38
39// ************************************************************************** //
40// ************** xml print helpers ************** //
41// ************************************************************************** //
42
43inline void
44print_escaped( std::ostream& where_to, const_string value )
45{
46 static fixed_mapping<char,char const*> char_type(
47 '<' , "lt",
48 '>' , "gt",
49 '&' , "amp",
50 '\'', "apos" ,
51 '"' , "quot",
52
53 0
54 );
55
Jeff Thompson3d613fd2013-10-15 15:39:04 -070056 NDNBOOST_TEST_FOREACH( char, c, value ) {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070057 char const* ref = char_type[c];
58
59 if( ref )
60 where_to << '&' << ref << ';';
61 else
62 where_to << c;
63 }
64}
65
66//____________________________________________________________________________//
67
68inline void
69print_escaped( std::ostream& where_to, std::string const& value )
70{
71 print_escaped( where_to, const_string( value ) );
72}
73
74//____________________________________________________________________________//
75
76template<typename T>
77inline void
78print_escaped( std::ostream& where_to, T const& value )
79{
80 where_to << value;
81}
82
83//____________________________________________________________________________//
84
85typedef custom_manip<struct attr_value_t> attr_value;
86
87template<typename T>
88inline std::ostream&
89operator<<( custom_printer<attr_value> const& p, T const& value )
90{
91 *p << "=\"";
92 print_escaped( *p, value );
93 *p << '"';
94
95 return *p;
96}
97
98//____________________________________________________________________________//
99
100typedef custom_manip<struct cdata_t> cdata;
101
102inline std::ostream&
103operator<<( custom_printer<cdata> const& p, const_string value )
104{
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700105 return *p << NDNBOOST_TEST_L( "<![CDATA[" ) << value << NDNBOOST_TEST_L( "]]>" );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700106}
107
108//____________________________________________________________________________//
109
110} // namespace unit_test
111
112} // namespace ndnboost
113
114//____________________________________________________________________________//
115
116#include <ndnboost/test/detail/enable_warnings.hpp>
117
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700118#endif // NDNBOOST_TEST_XML_PRINTER_HPP_071894GER