Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55952 - branches/sredl_2009_05_proptree_update/libs/property_tree/test
From: sebastian.redl_at_[hidden]
Date: 2009-09-01 06:30:21


Author: cornedbee
Date: 2009-09-01 06:30:20 EDT (Tue, 01 Sep 2009)
New Revision: 55952
URL: http://svn.boost.org/trac/boost/changeset/55952

Log:
Add UTF-8 test case and get it to run.
Text files modified:
   branches/sredl_2009_05_proptree_update/libs/property_tree/test/test_utils.hpp | 15 +++++----------
   branches/sredl_2009_05_proptree_update/libs/property_tree/test/test_xml_parser_common.hpp | 11 +++++++++++
   branches/sredl_2009_05_proptree_update/libs/property_tree/test/test_xml_parser_rapidxml.cpp | 10 ++++++++++
   branches/sredl_2009_05_proptree_update/libs/property_tree/test/xml_parser_test_data.hpp | 9 +++++++++
   4 files changed, 35 insertions(+), 10 deletions(-)

Modified: branches/sredl_2009_05_proptree_update/libs/property_tree/test/test_utils.hpp
==============================================================================
--- branches/sredl_2009_05_proptree_update/libs/property_tree/test/test_utils.hpp (original)
+++ branches/sredl_2009_05_proptree_update/libs/property_tree/test/test_utils.hpp 2009-09-01 06:30:20 EDT (Tue, 01 Sep 2009)
@@ -52,7 +52,6 @@
     return size;
 }
 
-template<class Ch>
 class test_file
 {
 public:
@@ -61,12 +60,8 @@
         if (test_data && filename)
         {
             name = filename;
- std::basic_ofstream<Ch> stream(name.c_str());
- while (*test_data)
- {
- stream << Ch(*test_data);
- ++test_data;
- }
+ std::ofstream stream(name.c_str());
+ stream.write(test_data, strlen(test_data));
             BOOST_CHECK(stream.good());
         }
     }
@@ -109,9 +104,9 @@
     typedef typename Ptree::key_type::value_type Ch;
 
     // Create test files
- test_file<Ch> file_1(test_data_1, filename_1);
- test_file<Ch> file_2(test_data_2, filename_2);
- test_file<Ch> file_out("", filename_out);
+ test_file file_1(test_data_1, filename_1);
+ test_file file_2(test_data_2, filename_2);
+ test_file file_out("", filename_out);
 
     rf(filename_1, pt); // Read file
     wf(filename_out, pt); // Write file

Modified: branches/sredl_2009_05_proptree_update/libs/property_tree/test/test_xml_parser_common.hpp
==============================================================================
--- branches/sredl_2009_05_proptree_update/libs/property_tree/test/test_xml_parser_common.hpp (original)
+++ branches/sredl_2009_05_proptree_update/libs/property_tree/test/test_xml_parser_common.hpp 2009-09-01 06:30:20 EDT (Tue, 01 Sep 2009)
@@ -32,6 +32,10 @@
     }
 };
 
+template <typename Ch> int umlautsize();
+template <> inline int umlautsize<char>() { return 2; }
+template <> inline int umlautsize<wchar_t>() { return 1; }
+
 template<class Ptree>
 void test_xml_parser()
 {
@@ -62,6 +66,13 @@
         "testok4.xml", NULL, "testok4out.xml", 5, 2, 20
     );
 
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_5, NULL,
+ "testok5.xml", NULL, "testok5out.xml",
+ 2, umlautsize<typename Ptree::data_type::value_type>(), 3
+ );
+
     generic_parser_test_error<Ptree, ReadFunc, WriteFunc, xml_parser_error>
     (
         ReadFunc(), WriteFunc(), error_data_1, NULL,

Modified: branches/sredl_2009_05_proptree_update/libs/property_tree/test/test_xml_parser_rapidxml.cpp
==============================================================================
--- branches/sredl_2009_05_proptree_update/libs/property_tree/test/test_xml_parser_rapidxml.cpp (original)
+++ branches/sredl_2009_05_proptree_update/libs/property_tree/test/test_xml_parser_rapidxml.cpp 2009-09-01 06:30:20 EDT (Tue, 01 Sep 2009)
@@ -9,13 +9,23 @@
 // ----------------------------------------------------------------------------
 
 #include "test_xml_parser_common.hpp"
+#include <locale>
+#define BOOST_UTF8_BEGIN_NAMESPACE namespace boost { namespace property_tree {
+#define BOOST_UTF8_END_NAMESPACE }}
+#define BOOST_UTF8_DECL
+#include <boost/detail/utf8_codecvt_facet.hpp>
+#include "../../detail/utf8_codecvt_facet.cpp"
 
 int test_main(int argc, char *argv[])
 {
     using namespace boost::property_tree;
+ using std::locale;
     test_xml_parser<ptree>();
     test_xml_parser<iptree>();
 #ifndef BOOST_NO_CWCHAR
+ // We need a UTF-8-aware global locale now.
+ locale loc(locale(), new utf8_codecvt_facet);
+ locale::global(loc);
     test_xml_parser<wptree>();
     test_xml_parser<wiptree>();
 #endif

Modified: branches/sredl_2009_05_proptree_update/libs/property_tree/test/xml_parser_test_data.hpp
==============================================================================
--- branches/sredl_2009_05_proptree_update/libs/property_tree/test/xml_parser_test_data.hpp (original)
+++ branches/sredl_2009_05_proptree_update/libs/property_tree/test/xml_parser_test_data.hpp 2009-09-01 06:30:20 EDT (Tue, 01 Sep 2009)
@@ -731,6 +731,15 @@
     "</channel>\n"
     "</rss>\n";
 
+// Correct, with UTF-8 data
+const char ok_data_5[] = {
+ '<', '?', 'x', 'm', 'l', ' ', 'v', 'e', 'r', 's', 'i', 'o', 'n', '=', '"',
+ '1', '.', '0', '"', ' ', 'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g', '=', '"',
+ 'u', 't', 'f', '-', '8', '"', '?', '>', '\n', /*39 chars*/
+ '<', 'd', 'o', 'c', '>', 0xC3, 0xA4, '<', '/', 'd', 'o', 'c', '>',
+ 0
+};
+
 // Erroneous
 const char *error_data_1 =
     "a"; // bogus character


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk