1// ----------------------------------------------------------------------------
2// Copyright (C) 2002-2006 Marcin Kalicinski
3//
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7//
8// For more information, see www.boost.org
9// ----------------------------------------------------------------------------
10#ifndef TEST_XML_PARSER_COMMON_HPP_INCLUDED
11#define TEST_XML_PARSER_COMMON_HPP_INCLUDED
12
13#include "test_utils.hpp"
14#include <boost/property_tree/xml_parser.hpp>
15#include "xml_parser_test_data.hpp"
16
17struct ReadFuncWS
18{
19 template<class Ptree>
20 void operator()(const std::string &filename, Ptree &pt) const
21 {
22 boost::property_tree::read_xml(filename, pt,
23 boost::property_tree::xml_parser::no_concat_text);
24 }
25};
26
27struct WriteFuncWS
28{
29 template<class Ptree>
30 void operator()(const std::string &filename, const Ptree &pt) const
31 {
32 boost::property_tree::write_xml(filename, pt);
33 }
34};
35
36struct ReadFuncNS
37{
38 template<class Ptree>
39 void operator()(const std::string &filename, Ptree &pt) const
40 {
41 boost::property_tree::read_xml(filename, pt,
42 boost::property_tree::xml_parser::trim_whitespace);
43 }
44};
45
46struct WriteFuncNS
47{
48 template<class Ptree>
49 void operator()(const std::string &filename, const Ptree &pt) const
50 {
51 boost::property_tree::write_xml(filename, pt, std::locale(),
52 boost::property_tree::xml_writer_make_settings<typename Ptree::key_type>(' ', 4));
53 }
54};
55
56template <typename Ch> int umlautsize();
57template <> inline int umlautsize<char>() { return 2; }
58template <> inline int umlautsize<wchar_t>() { return 1; }
59
60template<class Ptree>
61void test_xml_parser()
62{
63
64 using namespace boost::property_tree;
65 typedef typename Ptree::data_type::value_type char_type;
66
67 generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
68 (
69 ReadFuncWS(), WriteFuncWS(), ok_data_1, NULL,
70 "testok1.xml", NULL, "testok1out.xml", 2, 0, 5
71 );
72
73 generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
74 (
75 ReadFuncWS(), WriteFuncWS(), ok_data_2, NULL,
76 "testok2a.xml", NULL, "testok2aout.xml", 15, 23, 89
77 );
78
79 generic_parser_test_ok<Ptree, ReadFuncNS, WriteFuncNS>
80 (
81 ReadFuncNS(), WriteFuncNS(), ok_data_2, NULL,
82 "testok2b.xml", NULL, "testok2bout.xml", 6, 15, 8
83 );
84
85 generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
86 (
87 ReadFuncWS(), WriteFuncWS(), ok_data_3, NULL,
88 "testok3a.xml", NULL, "testok3aout.xml", 1662, 35377, 11706
89 );
90
91 generic_parser_test_ok<Ptree, ReadFuncNS, WriteFuncNS>
92 (
93 ReadFuncNS(), WriteFuncNS(), ok_data_3, NULL,
94 "testok3b.xml", NULL, "testok3bout.xml", 787, 31376, 3831
95 );
96
97 generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
98 (
99 ReadFuncWS(), WriteFuncWS(), ok_data_4, NULL,
100 "testok4.xml", NULL, "testok4out.xml", 11, 7, 74
101 );
102
103 generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
104 (
105 ReadFuncWS(), WriteFuncWS(), ok_data_5, NULL,
106 "testok5.xml", NULL, "testok5out.xml",
107 3, umlautsize<char_type>(), 12
108 );
109
110 generic_parser_test_error<Ptree, ReadFuncWS, WriteFuncWS, xml_parser_error>
111 (
112 ReadFuncWS(), WriteFuncWS(), error_data_1, NULL,
113 "testerr1.xml", NULL, "testerr1out.xml", 1
114 );
115
116 generic_parser_test_error<Ptree, ReadFuncWS, WriteFuncWS, xml_parser_error>
117 (
118 ReadFuncWS(), WriteFuncWS(), error_data_2, NULL,
119 "testerr2.xml", NULL, "testerr2out.xml", 2
120 );
121
122 generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
123 (
124 ReadFuncWS(), WriteFuncWS(), bug_data_pr2855, NULL,
125 "testpr2855.xml", NULL, "testpr2855out.xml", 3, 7, 14
126 );
127
128 generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
129 (
130 ReadFuncWS(), WriteFuncWS(), bug_data_pr1678, NULL,
131 "testpr1678.xml", NULL, "testpr1678out.xml", 2, 0, 4
132 );
133
134 generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
135 (
136 ReadFuncWS(), WriteFuncWS(), bug_data_pr5203, NULL,
137 "testpr5203.xml", NULL, "testpr5203out.xml",
138 3, 4 * umlautsize<char_type>(), 13
139 );
140
141 generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
142 (
143 ReadFuncWS(), WriteFuncWS(), bug_data_pr4840, NULL,
144 "testpr4840.xml", NULL, "testpr4840out.xml",
145 4, 13, 15
146 );
147
148}
149
150#endif
151

source code of boost/libs/property_tree/test/test_xml_parser_common.hpp