test_xml_parser_common.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #include "test_utils.hpp"
  13. #include <boost/property_tree/xml_parser.hpp>
  14. #include "xml_parser_test_data.hpp"
  15. struct ReadFuncWS
  16. {
  17. template<class Ptree>
  18. void operator()(const std::string &filename, Ptree &pt) const
  19. {
  20. boost::property_tree::read_xml(filename, pt,
  21. boost::property_tree::xml_parser::no_concat_text);
  22. }
  23. };
  24. struct WriteFuncWS
  25. {
  26. template<class Ptree>
  27. void operator()(const std::string &filename, const Ptree &pt) const
  28. {
  29. boost::property_tree::write_xml(filename, pt);
  30. }
  31. };
  32. struct ReadFuncNS
  33. {
  34. template<class Ptree>
  35. void operator()(const std::string &filename, Ptree &pt) const
  36. {
  37. boost::property_tree::read_xml(filename, pt,
  38. boost::property_tree::xml_parser::trim_whitespace);
  39. }
  40. };
  41. struct WriteFuncNS
  42. {
  43. template<class Ptree>
  44. void operator()(const std::string &filename, const Ptree &pt) const
  45. {
  46. boost::property_tree::write_xml(filename, pt, std::locale(),
  47. boost::property_tree::xml_writer_make_settings<typename Ptree::key_type>(' ', 4));
  48. }
  49. };
  50. template <typename Ch> int umlautsize();
  51. template <> inline int umlautsize<char>() { return 2; }
  52. template <> inline int umlautsize<wchar_t>() { return 1; }
  53. template<class Ptree>
  54. void test_xml_parser()
  55. {
  56. using namespace boost::property_tree;
  57. typedef typename Ptree::data_type::value_type char_type;
  58. generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
  59. (
  60. ReadFuncWS(), WriteFuncWS(), ok_data_1, NULL,
  61. "testok1.xml", NULL, "testok1out.xml", 2, 0, 5
  62. );
  63. generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
  64. (
  65. ReadFuncWS(), WriteFuncWS(), ok_data_2, NULL,
  66. "testok2a.xml", NULL, "testok2aout.xml", 15, 23, 89
  67. );
  68. generic_parser_test_ok<Ptree, ReadFuncNS, WriteFuncNS>
  69. (
  70. ReadFuncNS(), WriteFuncNS(), ok_data_2, NULL,
  71. "testok2b.xml", NULL, "testok2bout.xml", 6, 15, 8
  72. );
  73. generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
  74. (
  75. ReadFuncWS(), WriteFuncWS(), ok_data_3, NULL,
  76. "testok3a.xml", NULL, "testok3aout.xml", 1662, 35377, 11706
  77. );
  78. generic_parser_test_ok<Ptree, ReadFuncNS, WriteFuncNS>
  79. (
  80. ReadFuncNS(), WriteFuncNS(), ok_data_3, NULL,
  81. "testok3b.xml", NULL, "testok3bout.xml", 787, 31376, 3831
  82. );
  83. generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
  84. (
  85. ReadFuncWS(), WriteFuncWS(), ok_data_4, NULL,
  86. "testok4.xml", NULL, "testok4out.xml", 11, 7, 74
  87. );
  88. generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
  89. (
  90. ReadFuncWS(), WriteFuncWS(), ok_data_5, NULL,
  91. "testok5.xml", NULL, "testok5out.xml",
  92. 3, umlautsize<char_type>(), 12
  93. );
  94. generic_parser_test_error<Ptree, ReadFuncWS, WriteFuncWS, xml_parser_error>
  95. (
  96. ReadFuncWS(), WriteFuncWS(), error_data_1, NULL,
  97. "testerr1.xml", NULL, "testerr1out.xml", 1
  98. );
  99. generic_parser_test_error<Ptree, ReadFuncWS, WriteFuncWS, xml_parser_error>
  100. (
  101. ReadFuncWS(), WriteFuncWS(), error_data_2, NULL,
  102. "testerr2.xml", NULL, "testerr2out.xml", 2
  103. );
  104. generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
  105. (
  106. ReadFuncWS(), WriteFuncWS(), bug_data_pr2855, NULL,
  107. "testpr2855.xml", NULL, "testpr2855out.xml", 3, 7, 14
  108. );
  109. generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
  110. (
  111. ReadFuncWS(), WriteFuncWS(), bug_data_pr1678, NULL,
  112. "testpr1678.xml", NULL, "testpr1678out.xml", 2, 0, 4
  113. );
  114. generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
  115. (
  116. ReadFuncWS(), WriteFuncWS(), bug_data_pr5203, NULL,
  117. "testpr5203.xml", NULL, "testpr5203out.xml",
  118. 3, 4 * umlautsize<char_type>(), 13
  119. );
  120. generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
  121. (
  122. ReadFuncWS(), WriteFuncWS(), bug_data_pr4840, NULL,
  123. "testpr4840.xml", NULL, "testpr4840out.xml",
  124. 4, 13, 15
  125. );
  126. }
  127. #endif