summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/property_tree
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/property_tree
parentInitial commit. (diff)
downloadceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz
ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/property_tree')
-rw-r--r--src/boost/libs/property_tree/breaking_changes.txt51
-rw-r--r--src/boost/libs/property_tree/examples/Jamfile.v212
-rw-r--r--src/boost/libs/property_tree/examples/custom_data_type.cpp88
-rw-r--r--src/boost/libs/property_tree/examples/debug_settings.cpp95
-rw-r--r--src/boost/libs/property_tree/examples/debug_settings.xml15
-rw-r--r--src/boost/libs/property_tree/examples/empty_ptree_trick.cpp71
-rw-r--r--src/boost/libs/property_tree/examples/info_grammar_spirit.cpp152
-rw-r--r--src/boost/libs/property_tree/examples/settings_fully-existent.info6
-rw-r--r--src/boost/libs/property_tree/examples/settings_non-existent.info6
-rw-r--r--src/boost/libs/property_tree/examples/settings_partially-existent.info6
-rw-r--r--src/boost/libs/property_tree/examples/speed_test.cpp130
-rw-r--r--src/boost/libs/property_tree/index.html14
-rw-r--r--src/boost/libs/property_tree/meta/libraries.json16
-rw-r--r--src/boost/libs/property_tree/test/Jamfile.v227
-rw-r--r--src/boost/libs/property_tree/test/prefixing_callbacks.hpp79
-rw-r--r--src/boost/libs/property_tree/test/sandbox.cpp22
-rw-r--r--src/boost/libs/property_tree/test/test_info_parser.cpp249
-rw-r--r--src/boost/libs/property_tree/test/test_ini_parser.cpp226
-rw-r--r--src/boost/libs/property_tree/test/test_json_parser.cpp443
-rw-r--r--src/boost/libs/property_tree/test/test_json_parser2.cpp935
-rw-r--r--src/boost/libs/property_tree/test/test_multi_module1.cpp21
-rw-r--r--src/boost/libs/property_tree/test/test_multi_module2.cpp18
-rw-r--r--src/boost/libs/property_tree/test/test_property_tree.cpp203
-rw-r--r--src/boost/libs/property_tree/test/test_property_tree.hpp1355
-rw-r--r--src/boost/libs/property_tree/test/test_utils.hpp252
-rw-r--r--src/boost/libs/property_tree/test/test_xml_parser_common.hpp150
-rw-r--r--src/boost/libs/property_tree/test/test_xml_parser_rapidxml.cpp34
-rw-r--r--src/boost/libs/property_tree/test/xml_parser_test_data.hpp777
28 files changed, 5453 insertions, 0 deletions
diff --git a/src/boost/libs/property_tree/breaking_changes.txt b/src/boost/libs/property_tree/breaking_changes.txt
new file mode 100644
index 000000000..f9044e483
--- /dev/null
+++ b/src/boost/libs/property_tree/breaking_changes.txt
@@ -0,0 +1,51 @@
+Copyright (C) 2009 Sebastian Redl
+Distributed under the Boost Software License, Version 1.0.
+See http://www.boost.org/LICENSE_1_0.txt
+
+
+List all breaking changes done to the interface during the update here.
+
+- Template parameters
+Template parameters have been thoroughly changed.
+Impact: If you were using a custom instantiation of basic_ptree, you have to
+ change your code.
+Rationale: The old order made no sense. It ordered the key comparison predicate
+ before the key, although it could easily be defaulted based on it,
+ and the path before the data type, when the path is something you
+ will very rarely want to change (and it could default, too).
+
+- put*
+The put and put_child functions of basic_ptree had add and add_child split from
+them, by separating along the lines of the do_not_replace parameter.
+Impact: If you were using the third parameter of these functions, you have to
+ change your code.
+Rationale: I'm not fond of using boolean parameters to change function behavior.
+ They're hard to remember and hard to read in code. When projects
+ adopt the convention of passing /*boolean=*/true,
+ /*parameters=*/false, /*like=*/false this, something's wrong.
+ It's even more wrong when the parameter has a negative name, as
+ do_not_replace had.
+
+- Custom paths
+Custom paths have been thoroughly changed.
+Impact: If you were using custom paths, you have to change your code. If you
+ referred to the basic_path template by name, you have to change your
+ code.
+Rationale: The old interface required a huge amount of repeated code for
+ custom paths. The new interface is a lot easier to implement.
+
+- Translators
+Translators have been thoroughly changed.
+Impact: If you were using translators at all, you probably have to change your
+ code.
+Rationale: The new interface makes it easier to pass custom translators to
+ specific get/put operations. It also keeps the translator out of
+ the tree's type.
+
+- find
+find() returns an assoc_iterator.
+Impact: If you use find, you may have to change your code. Most importantly,
+ you need to compare against not_found() instead of end().
+Rationale: equal_range() also returns assoc_iterators. equal_range() cannot
+ return normal iterators, since the conversion would not preserve
+ the equal range or even the range property.
diff --git a/src/boost/libs/property_tree/examples/Jamfile.v2 b/src/boost/libs/property_tree/examples/Jamfile.v2
new file mode 100644
index 000000000..07c382aed
--- /dev/null
+++ b/src/boost/libs/property_tree/examples/Jamfile.v2
@@ -0,0 +1,12 @@
+# Boost PropertyTree Library Example Jamfile
+# Copyright (c) 2013 Sebastian Redl
+# Distributed under the Boost Software License, Version 1.0.
+# See http://www.boost.org/LICENSE_1_0.txt
+
+project
+ : requirements
+ <include>../../../
+ :
+ ;
+
+exe debug_settings : debug_settings.cpp ;
diff --git a/src/boost/libs/property_tree/examples/custom_data_type.cpp b/src/boost/libs/property_tree/examples/custom_data_type.cpp
new file mode 100644
index 000000000..dbc905fe0
--- /dev/null
+++ b/src/boost/libs/property_tree/examples/custom_data_type.cpp
@@ -0,0 +1,88 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+
+// This example shows what need to be done to customize data_type of ptree.
+//
+// It creates my_ptree type, which is a basic_ptree having boost::any as its data
+// container (instead of std::string that standard ptree has).
+
+#include <boost/property_tree/ptree.hpp>
+#include <boost/any.hpp>
+#include <list>
+#include <string>
+#include <iostream>
+
+// Custom translator that works with boost::any instead of std::string
+template <class Ext, class Int = boost::any>
+struct variant_translator
+{
+ typedef Ext external_type;
+ typedef Int internal_type;
+
+ external_type
+ get_value(const internal_type &value) const
+ {
+ return boost::any_cast<external_type>(value);
+ }
+ internal_type
+ put_value(const external_type &value) const
+ {
+ return value;
+ }
+};
+
+int main()
+{
+
+ using namespace boost::property_tree;
+
+ // Property_tree with boost::any as data type
+ // Key type: std::string
+ // Data type: boost::any
+ // Key comparison: default (std::less<std::string>)
+ typedef basic_ptree<std::string, boost::any> my_ptree;
+ my_ptree pt;
+
+ // Put/get int value
+ typedef variant_translator<int> int_tran;
+ pt.put("int value", 3, int_tran());
+ int int_value = pt.get<int>("int value", int_tran());
+ std::cout << "Int value: " << int_value << "\n";
+
+ // Put/get string value
+ typedef variant_translator<std::string> string_tran;
+ pt.put<std::string>("string value", "foo bar", string_tran());
+ std::string string_value = pt.get<std::string>(
+ "string value"
+ , string_tran()
+ );
+ std::cout << "String value: " << string_value << "\n";
+
+ // Put/get list<int> value
+ typedef std::list<int> intlist;
+ typedef variant_translator<intlist> intlist_tran;
+ int list_data[] = { 1, 2, 3, 4, 5 };
+ pt.put<intlist>(
+ "list value"
+ , intlist(
+ list_data
+ , list_data + sizeof(list_data) / sizeof(*list_data)
+ )
+ , intlist_tran()
+ );
+ intlist list_value = pt.get<intlist>(
+ "list value"
+ , intlist_tran()
+ );
+ std::cout << "List value: ";
+ for (intlist::iterator it = list_value.begin(); it != list_value.end(); ++it)
+ std::cout << *it << ' ';
+ std::cout << '\n';
+}
diff --git a/src/boost/libs/property_tree/examples/debug_settings.cpp b/src/boost/libs/property_tree/examples/debug_settings.cpp
new file mode 100644
index 000000000..5e214290b
--- /dev/null
+++ b/src/boost/libs/property_tree/examples/debug_settings.cpp
@@ -0,0 +1,95 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+
+//[debug_settings_includes
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/xml_parser.hpp>
+#include <boost/foreach.hpp>
+#include <string>
+#include <set>
+#include <exception>
+#include <iostream>
+namespace pt = boost::property_tree;
+//]
+//[debug_settings_data
+struct debug_settings
+{
+ std::string m_file; // log filename
+ int m_level; // debug level
+ std::set<std::string> m_modules; // modules where logging is enabled
+ void load(const std::string &filename);
+ void save(const std::string &filename);
+};
+//]
+//[debug_settings_load
+void debug_settings::load(const std::string &filename)
+{
+ // Create empty property tree object
+ pt::ptree tree;
+
+ // Parse the XML into the property tree.
+ pt::read_xml(filename, tree);
+
+ // Use the throwing version of get to find the debug filename.
+ // If the path cannot be resolved, an exception is thrown.
+ m_file = tree.get<std::string>("debug.filename");
+
+ // Use the default-value version of get to find the debug level.
+ // Note that the default value is used to deduce the target type.
+ m_level = tree.get("debug.level", 0);
+
+ // Use get_child to find the node containing the modules, and iterate over
+ // its children. If the path cannot be resolved, get_child throws.
+ // A C++11 for-range loop would also work.
+ BOOST_FOREACH(pt::ptree::value_type &v, tree.get_child("debug.modules")) {
+ // The data function is used to access the data stored in a node.
+ m_modules.insert(v.second.data());
+ }
+
+}
+//]
+//[debug_settings_save
+void debug_settings::save(const std::string &filename)
+{
+ // Create an empty property tree object.
+ pt::ptree tree;
+
+ // Put the simple values into the tree. The integer is automatically
+ // converted to a string. Note that the "debug" node is automatically
+ // created if it doesn't exist.
+ tree.put("debug.filename", m_file);
+ tree.put("debug.level", m_level);
+
+ // Add all the modules. Unlike put, which overwrites existing nodes, add
+ // adds a new node at the lowest level, so the "modules" node will have
+ // multiple "module" children.
+ BOOST_FOREACH(const std::string &name, m_modules)
+ tree.add("debug.modules.module", name);
+
+ // Write property tree to XML file
+ pt::write_xml(filename, tree);
+}
+//]
+
+int main()
+{
+ try
+ {
+ debug_settings ds;
+ ds.load("debug_settings.xml");
+ ds.save("debug_settings_out.xml");
+ std::cout << "Success\n";
+ }
+ catch (std::exception &e)
+ {
+ std::cout << "Error: " << e.what() << "\n";
+ }
+ return 0;
+}
diff --git a/src/boost/libs/property_tree/examples/debug_settings.xml b/src/boost/libs/property_tree/examples/debug_settings.xml
new file mode 100644
index 000000000..2ac170ec0
--- /dev/null
+++ b/src/boost/libs/property_tree/examples/debug_settings.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Copyright (C) 2006 Marcin Kalicinski
+Distributed under the Boost Software License, Version 1.0.
+See http://www.boost.org/LICENSE_1_0.txt
+-->
+<debug>
+ <filename>debug.log</filename>
+ <modules>
+ <module>Finance</module>
+ <module>Admin</module>
+ <module>HR</module>
+ </modules>
+ <level>2</level>
+</debug>
diff --git a/src/boost/libs/property_tree/examples/empty_ptree_trick.cpp b/src/boost/libs/property_tree/examples/empty_ptree_trick.cpp
new file mode 100644
index 000000000..37285b24a
--- /dev/null
+++ b/src/boost/libs/property_tree/examples/empty_ptree_trick.cpp
@@ -0,0 +1,71 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/info_parser.hpp>
+#include <iostream>
+#include <iomanip>
+#include <string>
+
+using namespace boost::property_tree;
+
+// Process settings using empty ptree trick. Note that it is considerably simpler
+// than version which does not use the "trick"
+void process_settings(const std::string &filename)
+{
+ ptree pt;
+ read_info(filename, pt);
+ const ptree &settings = pt.get_child("settings", empty_ptree<ptree>());
+ std::cout << "\n Processing " << filename << std::endl;
+ std::cout << " Setting 1 is " << settings.get("setting1", 0) << std::endl;
+ std::cout << " Setting 2 is " << settings.get("setting2", 0.0) << std::endl;
+ std::cout << " Setting 3 is " << settings.get("setting3", "default") << std::endl;
+}
+
+// Process settings not using empty ptree trick. This one must duplicate much of the code.
+void process_settings_without_trick(const std::string &filename)
+{
+ ptree pt;
+ read_info(filename, pt);
+ if (boost::optional<ptree &> settings = pt.get_child_optional("settings"))
+ {
+ std::cout << "\n Processing " << filename << std::endl;
+ std::cout << " Setting 1 is " << settings.get().get("setting1", 0) << std::endl;
+ std::cout << " Setting 2 is " << settings.get().get("setting2", 0.0) << std::endl;
+ std::cout << " Setting 3 is " << settings.get().get("setting3", "default") << std::endl;
+ }
+ else
+ {
+ std::cout << "\n Processing " << filename << std::endl;
+ std::cout << " Setting 1 is " << 0 << std::endl;
+ std::cout << " Setting 2 is " << 0.0 << std::endl;
+ std::cout << " Setting 3 is " << "default" << std::endl;
+ }
+}
+
+int main()
+{
+ try
+ {
+ std::cout << "Processing settings with empty-ptree-trick:\n";
+ process_settings("settings_fully-existent.info");
+ process_settings("settings_partially-existent.info");
+ process_settings("settings_non-existent.info");
+ std::cout << "\nProcessing settings without empty-ptree-trick:\n";
+ process_settings_without_trick("settings_fully-existent.info");
+ process_settings_without_trick("settings_partially-existent.info");
+ process_settings_without_trick("settings_non-existent.info");
+ }
+ catch (std::exception &e)
+ {
+ std::cout << "Error: " << e.what() << "\n";
+ }
+ return 0;
+}
diff --git a/src/boost/libs/property_tree/examples/info_grammar_spirit.cpp b/src/boost/libs/property_tree/examples/info_grammar_spirit.cpp
new file mode 100644
index 000000000..07025341b
--- /dev/null
+++ b/src/boost/libs/property_tree/examples/info_grammar_spirit.cpp
@@ -0,0 +1,152 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+
+/* This is grammar of INFO file format written in form of boost::spirit rules.
+ For simplicity, it does not parse #include directive. Note that INFO parser
+ included in property_tree library does not use Spirit.
+*/
+
+//#define BOOST_SPIRIT_DEBUG // uncomment to enable debug output
+#include <boost/spirit.hpp>
+
+struct info_grammar: public boost::spirit::grammar<info_grammar>
+{
+
+ template<class Scanner>
+ struct definition
+ {
+
+ boost::spirit::rule<typename boost::spirit::lexeme_scanner<Scanner>::type> chr, qchr, escape_seq;
+ boost::spirit::rule<Scanner> string, qstring, cstring, key, value, entry, info;
+
+ definition(const info_grammar &self)
+ {
+
+ using namespace boost::spirit;
+
+ escape_seq = chset_p("0abfnrtv\"\'\\");
+ chr = (anychar_p - space_p - '\\' - '{' - '}' - '#' - '"') | ('\\' >> escape_seq);
+ qchr = (anychar_p - '"' - '\n' - '\\') | ('\\' >> escape_seq);
+ string = lexeme_d[+chr];
+ qstring = lexeme_d['"' >> *qchr >> '"'];
+ cstring = lexeme_d['"' >> *qchr >> '"' >> '\\'];
+ key = string | qstring;
+ value = string | qstring | (+cstring >> qstring) | eps_p;
+ entry = key >> value >> !('{' >> *entry >> '}');
+ info = *entry >> end_p;
+
+ // Debug nodes
+ BOOST_SPIRIT_DEBUG_NODE(escape_seq);
+ BOOST_SPIRIT_DEBUG_NODE(chr);
+ BOOST_SPIRIT_DEBUG_NODE(qchr);
+ BOOST_SPIRIT_DEBUG_NODE(string);
+ BOOST_SPIRIT_DEBUG_NODE(qstring);
+ BOOST_SPIRIT_DEBUG_NODE(key);
+ BOOST_SPIRIT_DEBUG_NODE(value);
+ BOOST_SPIRIT_DEBUG_NODE(entry);
+ BOOST_SPIRIT_DEBUG_NODE(info);
+
+ }
+
+ const boost::spirit::rule<Scanner> &start() const
+ {
+ return info;
+ }
+
+ };
+};
+
+void info_parse(const char *s)
+{
+
+ using namespace boost::spirit;
+
+ // Parse and display result
+ info_grammar g;
+ parse_info<const char *> pi = parse(s, g, space_p | comment_p(";"));
+ std::cout << "Parse result: " << (pi.hit ? "Success" : "Failure") << "\n";
+
+}
+
+int main()
+{
+
+ // Sample data 1
+ const char *data1 =
+ "\n"
+ "key1 data1\n"
+ "{\n"
+ "\tkey data\n"
+ "}\n"
+ "key2 \"data2 \" {\n"
+ "\tkey data\n"
+ "}\n"
+ "key3 \"data\"\n"
+ "\t \"3\" {\n"
+ "\tkey data\n"
+ "}\n"
+ "\n"
+ "\"key4\" data4\n"
+ "{\n"
+ "\tkey data\n"
+ "}\n"
+ "\"key.5\" \"data.5\" { \n"
+ "\tkey data \n"
+ "}\n"
+ "\"key6\" \"data\"\n"
+ "\t \"6\" {\n"
+ "\tkey data\n"
+ "}\n"
+ " \n"
+ "key1 data1\n"
+ "{\n"
+ "\tkey data\n"
+ "}\n"
+ "key2 \"data2 \" {\n"
+ "\tkey data\n"
+ "}\n"
+ "key3 \"data\"\n"
+ "\t \"3\" {\n"
+ "\tkey data\n"
+ "}\n"
+ "\n"
+ "\"key4\" data4\n"
+ "{\n"
+ "\tkey data\n"
+ "}\n"
+ "\"key.5\" \"data.5\" {\n"
+ "\tkey data\n"
+ "}\n"
+ "\"key6\" \"data\"\n"
+ "\t \"6\" {\n"
+ "\tkey data\n"
+ "}\n"
+ "\\\\key\\t7 data7\\n\\\"data7\\\"\n"
+ "{\n"
+ "\tkey data\n"
+ "}\n"
+ "\"\\\\key\\t8\" \"data8\\n\\\"data8\\\"\"\n"
+ "{\n"
+ "\tkey data\n"
+ "}\n"
+ "\n";
+
+ // Sample data 2
+ const char *data2 =
+ "key1\n"
+ "key2\n"
+ "key3\n"
+ "key4\n";
+
+ // Parse sample data
+ info_parse(data1);
+ info_parse(data2);
+
+}
diff --git a/src/boost/libs/property_tree/examples/settings_fully-existent.info b/src/boost/libs/property_tree/examples/settings_fully-existent.info
new file mode 100644
index 000000000..bec7a64b3
--- /dev/null
+++ b/src/boost/libs/property_tree/examples/settings_fully-existent.info
@@ -0,0 +1,6 @@
+settings
+{
+ setting1 15
+ setting2 9.876
+ setting3 Alice in Wonderland
+}
diff --git a/src/boost/libs/property_tree/examples/settings_non-existent.info b/src/boost/libs/property_tree/examples/settings_non-existent.info
new file mode 100644
index 000000000..4f76b2a45
--- /dev/null
+++ b/src/boost/libs/property_tree/examples/settings_non-existent.info
@@ -0,0 +1,6 @@
+;settings // non-existent
+;{
+; setting1 15
+; setting2 9.876
+; setting3 Alice in Wonderland
+;}
diff --git a/src/boost/libs/property_tree/examples/settings_partially-existent.info b/src/boost/libs/property_tree/examples/settings_partially-existent.info
new file mode 100644
index 000000000..ed5e8c225
--- /dev/null
+++ b/src/boost/libs/property_tree/examples/settings_partially-existent.info
@@ -0,0 +1,6 @@
+settings
+{
+ setting1 15
+ ;setting2 9.876 // non-existent
+ ;setting3 Alice in Wonderland // non-existent
+}
diff --git a/src/boost/libs/property_tree/examples/speed_test.cpp b/src/boost/libs/property_tree/examples/speed_test.cpp
new file mode 100644
index 000000000..4d5efd8c3
--- /dev/null
+++ b/src/boost/libs/property_tree/examples/speed_test.cpp
@@ -0,0 +1,130 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+
+#define _HAS_ITERATOR_DEBUGGING 0
+
+#include <boost/property_tree/ptree.hpp>
+#include <boost/format.hpp>
+#include <boost/shared_array.hpp>
+#include <iostream>
+#include <ctime>
+#include <algorithm>
+
+using namespace std;
+using namespace boost;
+using namespace boost::property_tree;
+
+string dummy;
+vector<string> keys;
+vector<string> shuffled_keys;
+
+void prepare_keys(int size)
+{
+ // Prepare keys
+ keys.clear();
+ for (int i = 0; i < size; ++i)
+ keys.push_back((format("%d") % i).str());
+ shuffled_keys = keys;
+ srand(0);
+ random_shuffle(shuffled_keys.begin(), shuffled_keys.end());
+}
+
+void clock_push_back(int size)
+{
+ prepare_keys(size);
+ int max_repeats = 1000000 / size;
+ shared_array<ptree> pt_array(new ptree[max_repeats]);
+
+ int n = 0;
+ clock_t t1 = clock(), t2;
+ do
+ {
+ if (n >= max_repeats)
+ break;
+ ptree &pt = pt_array[n];
+ for (int i = 0; i < size; ++i)
+ pt.push_back(ptree::value_type(shuffled_keys[i], ptree()));
+ t2 = clock();
+ ++n;
+ } while (t2 - t1 < CLOCKS_PER_SEC);
+
+ cout << " push_back (" << size << "): " << double(t2 - t1) / CLOCKS_PER_SEC / n * 1000 << " ms\n";
+
+}
+
+void clock_find(int size)
+{
+ prepare_keys(size);
+
+ ptree pt;
+ for (int i = 0; i < size; ++i)
+ pt.push_back(ptree::value_type(keys[i], ptree("data")));
+
+ int n = 0;
+ clock_t t1 = clock(), t2;
+ do
+ {
+ for (int i = 0; i < size; ++i)
+ pt.find(shuffled_keys[i]);
+ t2 = clock();
+ ++n;
+ } while (t2 - t1 < CLOCKS_PER_SEC);
+
+ cout << " find (" << size << "): " << double(t2 - t1) / CLOCKS_PER_SEC / n * 1000 << " ms\n";
+
+}
+
+void clock_erase(int size)
+{
+ prepare_keys(size);
+
+ int max_repeats = 100000 / size;
+ shared_array<ptree> pt_array(new ptree[max_repeats]);
+
+ ptree pt;
+ for (int n = 0; n < max_repeats; ++n)
+ for (int i = 0; i < size; ++i)
+ pt_array[n].push_back(ptree::value_type(keys[i], ptree("data")));
+
+ int n = 0;
+ clock_t t1 = clock(), t2;
+ do
+ {
+ if (n >= max_repeats)
+ break;
+ ptree &pt = pt_array[n];
+ for (int i = 0; i < size; ++i)
+ pt.erase(shuffled_keys[i]);
+ t2 = clock();
+ ++n;
+ } while (t2 - t1 < CLOCKS_PER_SEC);
+
+ cout << " erase (" << size << "): " << double(t2 - t1) / CLOCKS_PER_SEC / n * 1000 << " ms\n";
+}
+
+int main()
+{
+
+ // push_back
+ clock_push_back(10);
+ clock_push_back(100);
+ clock_push_back(1000);
+
+ // erase
+ clock_erase(10);
+ clock_erase(100);
+ clock_erase(1000);
+
+ // find
+ clock_find(10);
+ clock_find(100);
+ clock_find(1000);
+
+}
diff --git a/src/boost/libs/property_tree/index.html b/src/boost/libs/property_tree/index.html
new file mode 100644
index 000000000..5d800309c
--- /dev/null
+++ b/src/boost/libs/property_tree/index.html
@@ -0,0 +1,14 @@
+<html>
+<head>
+<meta http-equiv="refresh" content="0; URL=../../doc/html/property_tree.html">
+</head>
+<body>
+Automatic redirection failed, please go to the
+<a href="../../doc/html/property_tree.html">Boost.PropertyTree documentation</a>.
+<p>Copyright&nbsp;Sebastian Redl 2009</p>
+<p>Distributed under the Boost Software License, Version 1.0. (See accompanying file
+<a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at
+<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>).
+</p>
+</body>
+</html>
diff --git a/src/boost/libs/property_tree/meta/libraries.json b/src/boost/libs/property_tree/meta/libraries.json
new file mode 100644
index 000000000..025c04397
--- /dev/null
+++ b/src/boost/libs/property_tree/meta/libraries.json
@@ -0,0 +1,16 @@
+{
+ "key": "property_tree",
+ "name": "Property Tree",
+ "authors": [
+ "Marcin Kalicinski",
+ "Sebastian Redl"
+ ],
+ "description": "A tree data structure especially suited to storing configuration data.",
+ "category": [
+ "Containers",
+ "Data"
+ ],
+ "maintainers": [
+ "Sebastian Redl <sebastian.redl -at- getdesigned.at>"
+ ]
+}
diff --git a/src/boost/libs/property_tree/test/Jamfile.v2 b/src/boost/libs/property_tree/test/Jamfile.v2
new file mode 100644
index 000000000..af25731d7
--- /dev/null
+++ b/src/boost/libs/property_tree/test/Jamfile.v2
@@ -0,0 +1,27 @@
+# Boost.PropertyTree
+#
+# Copyright (c) 2009 Sebastian Redl
+#
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+# bring in rules for testing
+import testing ;
+
+project
+ : requirements
+ <link>static
+ <toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS=1
+ ;
+
+test-suite "property_tree"
+ : [ run test_property_tree.cpp /boost/serialization//boost_serialization ]
+ [ run test_info_parser.cpp ]
+ [ run test_json_parser.cpp ]
+ [ run test_json_parser2.cpp /boost/test//boost_unit_test_framework ]
+ [ run test_ini_parser.cpp ]
+ [ run test_xml_parser_rapidxml.cpp ]
+
+ [ run test_multi_module1.cpp test_multi_module2.cpp ]
+;
diff --git a/src/boost/libs/property_tree/test/prefixing_callbacks.hpp b/src/boost/libs/property_tree/test/prefixing_callbacks.hpp
new file mode 100644
index 000000000..d993fb592
--- /dev/null
+++ b/src/boost/libs/property_tree/test/prefixing_callbacks.hpp
@@ -0,0 +1,79 @@
+#ifndef JSON_PARSER_PREFIXING_CALLBACKS_HPP
+#define JSON_PARSER_PREFIXING_CALLBACKS_HPP
+
+#include <boost/property_tree/json_parser/detail/standard_callbacks.hpp>
+
+namespace constants
+{
+ template <typename Ch> const Ch* null_prefix();
+ template <> inline const char* null_prefix() { return "_:"; }
+ template <> inline const wchar_t* null_prefix() { return L"_:"; }
+
+ template <typename Ch> const Ch* boolean_prefix();
+ template <> inline const char* boolean_prefix() { return "b:"; }
+ template <> inline const wchar_t* boolean_prefix() { return L"b:"; }
+
+ template <typename Ch> const Ch* number_prefix();
+ template <> inline const char* number_prefix() { return "n:"; }
+ template <> inline const wchar_t* number_prefix() { return L"n:"; }
+
+ template <typename Ch> const Ch* string_prefix();
+ template <> inline const char* string_prefix() { return "s:"; }
+ template <> inline const wchar_t* string_prefix() { return L"s:"; }
+
+ template <typename Ch> const Ch* array_prefix();
+ template <> inline const char* array_prefix() { return "a:"; }
+ template <> inline const wchar_t* array_prefix() { return L"a:"; }
+
+ template <typename Ch> const Ch* object_prefix();
+ template <> inline const char* object_prefix() { return "o:"; }
+ template <> inline const wchar_t* object_prefix() { return L"o:"; }
+}
+
+template <typename Ptree>
+struct prefixing_callbacks
+ : boost::property_tree::json_parser::detail::standard_callbacks<Ptree> {
+ typedef boost::property_tree::json_parser::detail::standard_callbacks<Ptree>
+ base;
+ typedef typename base::string string;
+ typedef typename base::char_type char_type;
+
+ void on_null() {
+ base::on_null();
+ this->current_value().insert(0, constants::null_prefix<char_type>());
+ }
+
+ void on_boolean(bool b) {
+ base::on_boolean(b);
+ this->current_value().insert(0, constants::boolean_prefix<char_type>());
+ }
+
+ template <typename Range>
+ void on_number(Range code_units) {
+ base::on_number(code_units);
+ this->current_value().insert(0, constants::number_prefix<char_type>());
+ }
+ void on_begin_number() {
+ base::on_begin_number();
+ this->current_value() = constants::number_prefix<char_type>();
+ }
+
+ void on_begin_string() {
+ base::on_begin_string();
+ if (!this->is_key()) {
+ this->current_value() = constants::string_prefix<char_type>();
+ }
+ }
+
+ void on_begin_array() {
+ base::on_begin_array();
+ this->current_value() = constants::array_prefix<char_type>();
+ }
+
+ void on_begin_object() {
+ base::on_begin_object();
+ this->current_value() = constants::object_prefix<char_type>();
+ }
+};
+
+#endif
diff --git a/src/boost/libs/property_tree/test/sandbox.cpp b/src/boost/libs/property_tree/test/sandbox.cpp
new file mode 100644
index 000000000..9eb5908de
--- /dev/null
+++ b/src/boost/libs/property_tree/test/sandbox.cpp
@@ -0,0 +1,22 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2009 Sebastian Redl
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+
+#define _CRT_SECURE_NO_DEPRECATE
+#include <boost/property_tree/xml_parser.hpp>
+#include <boost/property_tree/info_parser.hpp>
+#include <iostream>
+
+int main()
+{
+ using namespace boost::property_tree;
+ ptree pt;
+ read_xml("simple_all.xml", pt);
+ write_info(std::cout, pt);
+}
diff --git a/src/boost/libs/property_tree/test/test_info_parser.cpp b/src/boost/libs/property_tree/test/test_info_parser.cpp
new file mode 100644
index 000000000..798f09e44
--- /dev/null
+++ b/src/boost/libs/property_tree/test/test_info_parser.cpp
@@ -0,0 +1,249 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+
+#include "test_utils.hpp"
+#include <boost/property_tree/info_parser.hpp>
+
+///////////////////////////////////////////////////////////////////////////////
+// Test data
+
+const char *ok_data_1 =
+ ";Test file for info_parser\n"
+ "\n"
+ "key1 data1\n"
+ "{\n"
+ "\tkey data\n"
+ "}\n"
+ "#include \"testok1_inc.info\"\n"
+ "key2 \"data2 \" {\n"
+ "\tkey data\n"
+ "}\n"
+ "#\tinclude \"testok1_inc.info\"\n"
+ "key3 \"data\"\n"
+ "\t \"3\" {\n"
+ "\tkey data\n"
+ "}\n"
+ "\t#include \"testok1_inc.info\"\n"
+ "\n"
+ "\"key4\" data4\n"
+ "{\n"
+ "\tkey data\n"
+ "}\n"
+ "#include \"testok1_inc.info\"\n"
+ "\"key.5\" \"data.5\" { \n"
+ "\tkey data \n"
+ "}\n"
+ "#\tinclude \"testok1_inc.info\"\n"
+ "\"key6\" \"data\"\n"
+ "\t \"6\" {\n"
+ "\tkey data\n"
+ "}\n"
+ "\t#include \"testok1_inc.info\"\n"
+ " \n"
+ "key1 data1; comment\n"
+ "{; comment\n"
+ "\tkey data; comment\n"
+ "}; comment\n"
+ "#include \"testok1_inc.info\"\n"
+ "key2 \"data2 \" {; comment\n"
+ "\tkey data; comment\n"
+ "}; comment\n"
+ "#\tinclude \"testok1_inc.info\"\n"
+ "key3 \"data\"; comment\n"
+ "\t \"3\" {; comment\n"
+ "\tkey data; comment\n"
+ "}; comment\n"
+ "\t#include \"testok1_inc.info\"\n"
+ "\n"
+ "\"key4\" data4; comment\n"
+ "{; comment\n"
+ "\tkey data; comment\n"
+ "}; comment\n"
+ "#include \"testok1_inc.info\"\n"
+ "\"key.5\" \"data.5\" {; comment\n"
+ "\tkey data; comment\n"
+ "}; comment\n"
+ "#\tinclude \"testok1_inc.info\"\n"
+ "\"key6\" \"data\"; comment\n"
+ "\t \"6\" {; comment\n"
+ "\tkey data; comment\n"
+ "}; comment\n"
+ "\t#include \"testok1_inc.info\"\n"
+ "\\\\key\\t7 data7\\n\\\"data7\\\"\n"
+ "{\n"
+ "\tkey data\n"
+ "}\n"
+ "\"\\\\key\\t8\" \"data8\\n\\\"data8\\\"\"\n"
+ "{\n"
+ "\tkey data\n"
+ "}\n"
+ "\n";
+
+const char *ok_data_1_inc =
+ ";Test file for info_parser\n"
+ "\n"
+ "inc_key inc_data ;;; comment\\";
+
+const char *ok_data_2 =
+ "";
+
+const char *ok_data_3 =
+ "key1 \"\"\n"
+ "key2 \"\"\n"
+ "key3 \"\"\n"
+ "key4 \"\"\n";
+
+const char *ok_data_4 =
+ "key1 data key2 data";
+
+const char *ok_data_5 =
+ "key { key \"\" key \"\" }\n";
+
+const char *ok_data_6 =
+ "\"key with spaces\" \"data with spaces\"\n"
+ "\"key with spaces\" \"multiline data\"\\\n"
+ "\"cont\"\\\n"
+ "\"cont\"";
+
+const char *error_data_1 =
+ ";Test file for info_parser\n"
+ "#include \"bogus_file\"\n"; // Nonexistent include file
+
+const char *error_data_2 =
+ ";Test file for info_parser\n"
+ "key \"data with bad escape: \\q\"\n"; // Bad escape
+
+const char *error_data_3 =
+ ";Test file for info_parser\n"
+ "{\n"; // Opening brace without key
+
+const char *error_data_4 =
+ ";Test file for info_parser\n"
+ "}\n"; // Closing brace without opening brace
+
+const char *error_data_5 =
+ ";Test file for info_parser\n"
+ "key data\n"
+ "{\n"
+ ""; // No closing brace
+
+struct ReadFunc
+{
+ template<class Ptree>
+ void operator()(const std::string &filename, Ptree &pt) const
+ {
+ boost::property_tree::read_info(filename, pt);
+ }
+};
+
+struct WriteFunc
+{
+ template<class Ptree>
+ void operator()(const std::string &filename, const Ptree &pt) const
+ {
+ boost::property_tree::write_info(filename, pt);
+ }
+};
+
+template<class Ptree>
+void test_info_parser()
+{
+
+ using namespace boost::property_tree;
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_1, ok_data_1_inc,
+ "testok1.info", "testok1_inc.info", "testok1out.info", 45, 240, 192
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_2, NULL,
+ "testok2.info", NULL, "testok2out.info", 1, 0, 0
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_3, NULL,
+ "testok3.info", NULL, "testok3out.info", 5, 0, 16
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_4, NULL,
+ "testok4.info", NULL, "testok4out.info", 3, 8, 8
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_5, NULL,
+ "testok5.info", NULL, "testok5out.info", 4, 0, 9
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_6, NULL,
+ "testok6.info", NULL, "testok6out.info", 3, 38, 30
+ );
+
+ generic_parser_test_error<Ptree, ReadFunc, WriteFunc, info_parser_error>
+ (
+ ReadFunc(), WriteFunc(), error_data_1, NULL,
+ "testerr1.info", NULL, "testerr1out.info", 2
+ );
+
+ generic_parser_test_error<Ptree, ReadFunc, WriteFunc, info_parser_error>
+ (
+ ReadFunc(), WriteFunc(), error_data_2, NULL,
+ "testerr2.info", NULL, "testerr2out.info", 2
+ );
+
+ generic_parser_test_error<Ptree, ReadFunc, WriteFunc, info_parser_error>
+ (
+ ReadFunc(), WriteFunc(), error_data_3, NULL,
+ "testerr3.info", NULL, "testerr3out.info", 2
+ );
+
+ generic_parser_test_error<Ptree, ReadFunc, WriteFunc, info_parser_error>
+ (
+ ReadFunc(), WriteFunc(), error_data_4, NULL,
+ "testerr4.info", NULL, "testerr4out.info", 2
+ );
+
+ generic_parser_test_error<Ptree, ReadFunc, WriteFunc, info_parser_error>
+ (
+ ReadFunc(), WriteFunc(), error_data_5, NULL,
+ "testerr5.info", NULL, "testerr5out.info", 4
+ );
+
+ // Test read with default ptree
+ {
+ Ptree pt, default_pt;
+ pt.put_value(1);
+ default_pt.put_value(2);
+ BOOST_CHECK(pt != default_pt);
+ read_info("nonexisting file.nonexisting file", pt, default_pt);
+ BOOST_CHECK(pt == default_pt);
+ }
+
+}
+
+int test_main(int argc, char *argv[])
+{
+ using namespace boost::property_tree;
+ test_info_parser<ptree>();
+ test_info_parser<iptree>();
+#ifndef BOOST_NO_CWCHAR
+ test_info_parser<wptree>();
+ test_info_parser<wiptree>();
+#endif
+ return 0;
+}
diff --git a/src/boost/libs/property_tree/test/test_ini_parser.cpp b/src/boost/libs/property_tree/test/test_ini_parser.cpp
new file mode 100644
index 000000000..2edb48cd4
--- /dev/null
+++ b/src/boost/libs/property_tree/test/test_ini_parser.cpp
@@ -0,0 +1,226 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+
+#include "test_utils.hpp"
+#include <boost/property_tree/ini_parser.hpp>
+#include <sstream>
+
+using namespace boost::property_tree;
+
+///////////////////////////////////////////////////////////////////////////////
+// Test data
+
+// Correct data
+const char *ok_data_1 =
+ "\n"
+ "; Comment\n"
+ "[Section1]\n"
+ "\t \t; Comment\n"
+ " Key1=Data1\n"
+ " \n"
+ " Key2 = Data2\n"
+ "Key 3 = Data 3 \n"
+ "Key4=Data4\n"
+ "[Section2] ;Comment\n"
+ "\t \tKey1=Data4\n";
+
+// Correct data
+const char *ok_data_2 =
+ "[Section1]\n"
+ "Key1=Data1"; // No eol
+
+// Correct data
+const char *ok_data_3 =
+ "";
+
+// Correct data
+const char *ok_data_4 =
+ ";Comment";
+
+// Correct data
+const char *ok_data_5 =
+ "Key1=Data1\n" // No section
+ "Key2=Data2\n";
+
+// Treat # as comment.
+const char *ok_data_6 =
+ "# Comment\n"
+ "[Section1]\n"
+ "Key1=Data1\n";
+
+// Erroneous data
+const char *error_data_1 =
+ "[Section1]\n"
+ "Key1\n" // No equals sign
+ "Key2=Data2";
+
+// Erroneous data
+const char *error_data_2 =
+ "[Section1]\n"
+ "Key1=Data1\n"
+ "=Data2\n"; // No key
+
+struct ReadFunc
+{
+ template<class Ptree>
+ void operator()(const std::string &filename, Ptree &pt) const
+ {
+ read_ini(filename, pt);
+ }
+};
+
+struct WriteFunc
+{
+ template<class Ptree>
+ void operator()(const std::string &filename, const Ptree &pt) const
+ {
+ write_ini(filename, pt);
+ }
+};
+
+void test_erroneous_write(const boost::property_tree::ptree &pt)
+{
+ std::stringstream stream;
+ try
+ {
+ write_ini(stream, pt);
+ BOOST_ERROR("No required exception thrown");
+ }
+ catch (ini_parser_error &e)
+ {
+ (void)e;
+ }
+ catch (...)
+ {
+ BOOST_ERROR("Wrong exception type thrown");
+ }
+}
+
+template<class Ptree>
+void test_ini_parser()
+{
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_1, NULL,
+ "testok1.ini", NULL, "testok1out.ini", 8, 26, 37
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_2, NULL,
+ "testok2.ini", NULL, "testok2out.ini", 3, 5, 12
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_3, NULL,
+ "testok3.ini", NULL, "testok3out.ini", 1, 0, 0
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_4, NULL,
+ "testok4.ini", NULL, "testok4out.ini", 1, 0, 0
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_5, NULL,
+ "testok5.ini", NULL, "testok5out.ini", 3, 10, 8
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(), ok_data_6, NULL,
+ "testok6.ini", NULL, "testok6out.ini", 3, 5, 12
+ );
+
+ generic_parser_test_error<Ptree, ReadFunc, WriteFunc, ini_parser_error>
+ (
+ ReadFunc(), WriteFunc(), error_data_1, NULL,
+ "testerr1.ini", NULL, "testerr1out.ini", 2
+ );
+
+ generic_parser_test_error<Ptree, ReadFunc, WriteFunc, ini_parser_error>
+ (
+ ReadFunc(), WriteFunc(), error_data_2, NULL,
+ "testerr2.ini", NULL, "testerr2out.ini", 3
+ );
+}
+
+void test_unmappable_trees()
+{
+ // Test too deep ptrees
+ {
+ ptree pt;
+ pt.put_child("section.key.bogus", ptree());
+ test_erroneous_write(pt);
+ }
+
+ // Test duplicate sections
+ {
+ ptree pt;
+ pt.push_back(std::make_pair("section", ptree()));
+ pt.push_back(std::make_pair("section", ptree()));
+ test_erroneous_write(pt);
+ }
+
+ // Test duplicate keys
+ {
+ ptree pt;
+ ptree &child = pt.put_child("section", ptree());
+ child.push_back(std::make_pair("key", ptree()));
+ child.push_back(std::make_pair("key", ptree()));
+ test_erroneous_write(pt);
+ }
+
+ // Test mixed data and children.
+ {
+ ptree pt;
+ ptree &child = pt.put_child("section", ptree("value"));
+ child.push_back(std::make_pair("key", ptree()));
+ child.push_back(std::make_pair("key", ptree()));
+ test_erroneous_write(pt);
+ }
+}
+
+void test_other_trees()
+{
+ // Top-level keys must be written before any section.
+ {
+ ptree pt;
+ pt.put("section.innerkey", "v1");
+ pt.put("nosection", "v2");
+ std::stringstream s;
+ write_ini(s, pt);
+ s.clear();
+ s.seekg(0, std::ios_base::beg);
+ ptree result;
+ read_ini(s, result);
+ BOOST_CHECK(result.get("section.innerkey", "bad") == "v1");
+ BOOST_CHECK(result.get("nosection", "bad") == "v2");
+ }
+}
+
+int test_main(int argc, char *argv[])
+{
+ test_ini_parser<ptree>();
+ test_ini_parser<iptree>();
+#ifndef BOOST_NO_CWCHAR
+ test_ini_parser<wptree>();
+ test_ini_parser<wiptree>();
+#endif
+
+ test_unmappable_trees();
+ test_other_trees();
+
+ return 0;
+
+}
diff --git a/src/boost/libs/property_tree/test/test_json_parser.cpp b/src/boost/libs/property_tree/test/test_json_parser.cpp
new file mode 100644
index 000000000..3c14d9b33
--- /dev/null
+++ b/src/boost/libs/property_tree/test/test_json_parser.cpp
@@ -0,0 +1,443 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+
+#include "test_utils.hpp"
+#include <boost/property_tree/json_parser.hpp>
+
+///////////////////////////////////////////////////////////////////////////////
+// Test data
+
+const char *ok_data_1 =
+ "{}";
+
+const char *ok_data_2 =
+ " \t {\n"
+ " \t \"name 0\" : \"value\", \t \n"
+ " \t \"name 1\" : \"\", \n"
+ " \t \"name 2\" : true, \n"
+ " \t \"name 3\" : false, \n"
+ " \t \"name 4\" : null, \n"
+ " \t \"name 5\" : 0, \n"
+ " \t \"name 6\" : -5, \n"
+ " \t \"name 7\" : 1.1, \n"
+ " \t \"name 8\" : -956.45e+4, \n"
+ " \t \"name 8\" : 5956.45E-11, \n"
+ " \t \"name 9\" : [1,2,3,4], \n"
+ " \t \"name 10\" : {\"a\":\"b\"} \n"
+ " \t } \n";
+
+const char *ok_data_3 =
+ "{\"a\":{\"b\":\"c\"}}";
+
+const char *ok_data_4 =
+ "{\"a\":[{\"b\":\"c\"},{\"d\":\"e\"},1,2,3,4],\"f\":null}";
+
+const char *ok_data_6 =
+ "{\"menu\": {\n"
+ " \"header\": \"SVG Viewer\",\n"
+ " \"items\": [\n"
+ " {\"id\": \"Open\"},\n"
+ " {\"id\": \"OpenNew\", \"label\": \"Open New\"},\n"
+ " null,\n"
+ " {\"id\": \"ZoomIn\", \"label\": \"Zoom In\"},\n"
+ " {\"id\": \"ZoomOut\", \"label\": \"Zoom Out\"},\n"
+ " {\"id\": \"OriginalView\", \"label\": \"Original View\"},\n"
+ " null,\n"
+ " {\"id\": \"Quality\"},\n"
+ " {\"id\": \"Pause\"},\n"
+ " {\"id\": \"Mute\"},\n"
+ " null,\n"
+ " {\"id\": \"Find\", \"label\": \"Find...\"},\n"
+ " {\"id\": \"FindAgain\", \"label\": \"Find Again\"},\n"
+ " {\"id\": \"Copy\"},\n"
+ " {\"id\": \"CopyAgain\", \"label\": \"Copy Again\"},\n"
+ " {\"id\": \"CopySVG\", \"label\": \"Copy SVG\"},\n"
+ " {\"id\": \"ViewSVG\", \"label\": \"View SVG\"},\n"
+ " {\"id\": \"ViewSource\", \"label\": \"View Source\"},\n"
+ " {\"id\": \"SaveAs\", \"label\": \"Save As\"},\n"
+ " null,\n"
+ " {\"id\": \"Help\"},\n"
+ " {\"id\": \"About\", \"label\": \"About Adobe CVG Viewer...\"}\n"
+ " ]\n"
+ "}}\n";
+
+const char *ok_data_7 =
+ "{\"web-app\": {\n"
+ " \"servlet\": [ \n"
+ " {\n"
+ " \"servlet-name\": \"cofaxCDS\",\n"
+ " \"servlet-class\": \"org.cofax.cds.CDSServlet\",\n"
+ " \"init-param\": {\n"
+ " \"configGlossary:installationAt\": \"Philadelphia, PA\",\n"
+ " \"configGlossary:adminEmail\": \"ksm@pobox.com\",\n"
+ " \"configGlossary:poweredBy\": \"Cofax\",\n"
+ " \"configGlossary:poweredByIcon\": \"/images/cofax.gif\",\n"
+ " \"configGlossary:staticPath\": \"/content/static\",\n"
+ " \"templateProcessorClass\": \"org.cofax.WysiwygTemplate\",\n"
+ " \"templateLoaderClass\": \"org.cofax.FilesTemplateLoader\",\n"
+ " \"templatePath\": \"templates\",\n"
+ " \"templateOverridePath\": \"\",\n"
+ " \"defaultListTemplate\": \"listTemplate.htm\",\n"
+ " \"defaultFileTemplate\": \"articleTemplate.htm\",\n"
+ " \"useJSP\": false,\n"
+ " \"jspListTemplate\": \"listTemplate.jsp\",\n"
+ " \"jspFileTemplate\": \"articleTemplate.jsp\",\n"
+ " \"cachePackageTagsTrack\": 200,\n"
+ " \"cachePackageTagsStore\": 200,\n"
+ " \"cachePackageTagsRefresh\": 60,\n"
+ " \"cacheTemplatesTrack\": 100,\n"
+ " \"cacheTemplatesStore\": 50,\n"
+ " \"cacheTemplatesRefresh\": 15,\n"
+ " \"cachePagesTrack\": 200,\n"
+ " \"cachePagesStore\": 100,\n"
+ " \"cachePagesRefresh\": 10,\n"
+ " \"cachePagesDirtyRead\": 10,\n"
+ " \"searchEngineListTemplate\": \"forSearchEnginesList.htm\",\n"
+ " \"searchEngineFileTemplate\": \"forSearchEngines.htm\",\n"
+ " \"searchEngineRobotsDb\": \"WEB-INF/robots.db\",\n"
+ " \"useDataStore\": true,\n"
+ " \"dataStoreClass\": \"org.cofax.SqlDataStore\",\n"
+ " \"redirectionClass\": \"org.cofax.SqlRedirection\",\n"
+ " \"dataStoreName\": \"cofax\",\n"
+ " \"dataStoreDriver\": \"com.microsoft.jdbc.sqlserver.SQLServerDriver\",\n"
+ " \"dataStoreUrl\": \"jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon\",\n"
+ " \"dataStoreUser\": \"sa\",\n"
+ " \"dataStorePassword\": \"dataStoreTestQuery\",\n"
+ " \"dataStoreTestQuery\": \"SET NOCOUNT ON;select test='test';\",\n"
+ " \"dataStoreLogFile\": \"/usr/local/tomcat/logs/datastore.log\",\n"
+ " \"dataStoreInitConns\": 10,\n"
+ " \"dataStoreMaxConns\": 100,\n"
+ " \"dataStoreConnUsageLimit\": 100,\n"
+ " \"dataStoreLogLevel\": \"debug\",\n"
+ " \"maxUrlLength\": 500}},\n"
+ " {\n"
+ " \"servlet-name\": \"cofaxEmail\",\n"
+ "\n \"servlet-class\": \"org.cofax.cds.EmailServlet\",\n"
+ " \"init-param\": {\n"
+ " \"mailHost\": \"mail1\",\n"
+ " \"mailHostOverride\": \"mail2\"}},\n"
+ " {\n"
+ " \"servlet-name\": \"cofaxAdmin\",\n"
+ " \"servlet-class\": \"org.cofax.cds.AdminServlet\"},\n"
+ " \n"
+ " {\n"
+ " \"servlet-name\": \"fileServlet\",\n"
+ " \"servlet-class\": \"org.cofax.cds.FileServlet\"},\n"
+ " {\n"
+ " \"servlet-name\": \"cofaxTools\",\n"
+ " \"servlet-class\": \"org.cofax.cms.CofaxToolsServlet\",\n"
+ " \"init-param\": {\n"
+ " \"templatePath\": \"toolstemplates/\",\n"
+ " \"log\": 1,\n"
+ " \"logLocation\": \"/usr/local/tomcat/logs/CofaxTools.log\",\n"
+ " \"logMaxSize\": \"\",\n"
+ " \"dataLog\": 1,\n"
+ " \"dataLogLocation\": \"/usr/local/tomcat/logs/dataLog.log\",\n"
+ " \"dataLogMaxSize\": \"\",\n"
+ " \"removePageCache\": \"/content/admin/remove?cache=pages&id=\",\n"
+ " \"removeTemplateCache\": \"/content/admin/remove?cache=templates&id=\",\n"
+ " \"fileTransferFolder\": \"/usr/local/tomcat/webapps/content/fileTransferFolder\",\n"
+ " \"lookInContext\": 1,\n"
+ " \"adminGroupID\": 4,\n"
+ " \"betaServer\": true}}],\n"
+ " \"servlet-mapping\": {\n"
+ " \"cofaxCDS\": \"/\",\n"
+ " \"cofaxEmail\": \"/cofaxutil/aemail/*\",\n"
+ " \"cofaxAdmin\": \"/admin/*\",\n"
+ " \"fileServlet\": \"/static/*\",\n"
+ " \"cofaxTools\": \"/tools/*\"},\n"
+ " \n"
+ " \"taglib\": {\n"
+ " \"taglib-uri\": \"cofax.tld\",\n"
+ " \"taglib-location\": \"/WEB-INF/tlds/cofax.tld\"}}}\n";
+
+const char *ok_data_8 =
+ "{\"widget\": {\n"
+ " \"debug\": \"on\",\n"
+ " \"window\": {\n"
+ " \"title\": \"Sample Konfabulator Widget\", \"name\": \"main_window\", \"width\": 500, \"height\": 500\n"
+ " }, \"image\": { \n"
+ " \"src\": \"Images/Sun.png\",\n"
+ " \"name\": \"sun1\", \"hOffset\": 250, \"vOffset\": 250, \"alignment\": \"center\"\n"
+ " }, \"text\": {\n"
+ " \"data\": \"Click Here\",\n"
+ " \"size\": 36,\n"
+ " \"style\": \"bold\", \"name\": \"text1\", \"hOffset\": 250, \"vOffset\": 100, \"alignment\": \"center\",\n"
+ " \"onMouseUp\": \"sun1.opacity = (sun1.opacity / 100) * 90;\"\n"
+ " }\n"
+ "}} \n";
+
+const char *ok_data_9 =
+ "{\"menu\": {\n"
+ " \"id\": \"file\",\n"
+ " \"value\": \"File:\",\n"
+ " \"popup\": {\n"
+ " \"menuitem\": [\n"
+ " {\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"},\n"
+ " {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"},\n"
+ "\n {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}\n"
+ " ]\n"
+ " }\n"
+ "}}\n";
+
+const char *ok_data_10 =
+ "{\n"
+ " \"glossary\": {\n"
+ " \"title\": \"example glossary\",\n"
+ " \"GlossDiv\": {\n"
+ " \"title\": \"S\",\n"
+ " \"GlossList\": [{\n"
+ " \"ID\": \"SGML\",\n"
+ " \"SortAs\": \"SGML\",\n"
+ " \"GlossTerm\": \"Standard Generalized Markup Language\",\n"
+ " \"Acronym\": \"SGML\",\n"
+ " \"Abbrev\": \"ISO 8879:1986\",\n"
+ " \"GlossDef\": \n"
+ "\"A meta-markup language, used to create markup languages such as DocBook.\",\n"
+ " \"GlossSeeAlso\": [\"GML\", \"XML\", \"markup\"]\n"
+ " }]\n"
+ " }\n"
+ " }\n"
+ "}\n";
+
+const char *ok_data_11 =
+ "{\n"
+ " \"data\" : [\n"
+ " {\n"
+ " \"First Name\" : \"Bob\",\n"
+ " \"Last Name\" : \"Smith\",\n"
+ " \"Email\" : \"bsmith@someurl.com\",\n"
+ " \"Phone\" : \"(555) 555-1212\"\n"
+ " },\n"
+ " {\n"
+ " \"First Name\" : \"Jan\",\n"
+ " \"Last Name\" : \"Smith\",\n"
+ " \"Email\" : \"jsmith@someurl.com\",\n"
+ " \"Phone\" : \"(555) 555-3434\"\n"
+ " },\n"
+ " {\n"
+ " \"First Name\" : \"Sue\",\n"
+ " \"Last Name\" : \"Smith\",\n"
+ " \"Email\" : \"ssmith@someurl.com\",\n"
+ " \"Phone\" : \"(555) 555-5656\"\n"
+ " }\n"
+ " ]\n"
+ "}\n";
+
+const char *ok_data_12 =
+ "{\" \\\" \\\\ \\b \\f \\n \\r \\t \" : \"\"}";
+
+const char *error_data_1 =
+ ""; // No root object
+
+const char *error_data_2 =
+ "{\n\"a\":1\n"; // Unclosed object brace
+
+const char *error_data_3 =
+ "{\n\"a\":\n[1,2,3,4\n}"; // Unclosed array brace
+
+const char *error_data_4 =
+ "{\n\"a\"\n}"; // No object
+
+const char *bug_data_pr4387 =
+ "[1, 2, 3]"; // Root array
+
+const char *bug_data_pr7180_1 =
+ "{\n"
+ " \"a\": [\n"
+ " \"1\",\n"
+ " \"2\"\n"
+ " ]\n"
+ "}\n";
+const char *bug_data_pr7180_2 =
+ "{\"a\":[\"1\",\"2\"]}\n";
+
+struct ReadFunc
+{
+ template<class Ptree>
+ void operator()(const std::string &filename, Ptree &pt) const
+ {
+ boost::property_tree::read_json(filename, pt);
+ }
+ template <class Ptree>
+ void operator()(
+ std::basic_istream<typename Ptree::key_type::value_type>& is,
+ Ptree& pt) const
+ {
+ boost::property_tree::read_json(is, pt);
+ }
+};
+
+struct WriteFunc
+{
+ WriteFunc(bool pretty = false) : pretty(pretty) {}
+
+ template<class Ptree>
+ void operator()(const std::string &filename, const Ptree &pt) const
+ {
+ boost::property_tree::write_json(filename, pt, std::locale(), pretty);
+ }
+
+ template<class Ptree>
+ void operator()(
+ std::basic_ostream<typename Ptree::key_type::value_type>& os,
+ Ptree& pt) const
+ {
+ boost::property_tree::write_json(os, pt, pretty);
+ }
+
+ bool pretty;
+};
+
+template<class Ptree>
+void test_json_parser()
+{
+
+ using namespace boost::property_tree;
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(false), ok_data_1, NULL,
+ "testok1.json", NULL, "testok1out.json", 1, 0, 0
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(false), ok_data_2, NULL,
+ "testok2.json", NULL, "testok2out.json", 18, 50, 74
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(false), ok_data_3, NULL,
+ "testok3.json", NULL, "testok3out.json", 3, 1, 2
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(false), ok_data_4, NULL,
+ "testok4.json", NULL, "testok4out.json", 11, 10, 4
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(false), ok_data_6, NULL,
+ "testok6.json", NULL, "testok6out.json", 56, 265, 111
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(false), ok_data_7, NULL,
+ "testok7.json", NULL, "testok7out.json", 87, 1046, 1216
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(false), ok_data_8, NULL,
+ "testok8.json", NULL, "testok8out.json", 23, 149, 125
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(false), ok_data_9, NULL,
+ "testok9.json", NULL, "testok9out.json", 15, 54, 60
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(false), ok_data_10, NULL,
+ "testok10.json", NULL, "testok10out.json", 17, 162, 85
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(false), ok_data_11, NULL,
+ "testok11.json", NULL, "testok11out.json", 17, 120, 91
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(false), ok_data_12, NULL,
+ "testok12.json", NULL, "testok12out.json", 2, 0, 17
+ );
+
+ generic_parser_test_error<ptree, ReadFunc, WriteFunc, json_parser_error>
+ (
+ ReadFunc(), WriteFunc(false), error_data_1, NULL,
+ "testerr1.json", NULL, "testerr1out.json", 1
+ );
+
+ generic_parser_test_error<ptree, ReadFunc, WriteFunc, json_parser_error>
+ (
+ ReadFunc(), WriteFunc(false), error_data_2, NULL,
+ "testerr2.json", NULL, "testerr2out.json", 3
+ );
+
+ generic_parser_test_error<ptree, ReadFunc, WriteFunc, json_parser_error>
+ (
+ ReadFunc(), WriteFunc(false), error_data_3, NULL,
+ "testerr3.json", NULL, "testerr3out.json", 4
+ );
+
+ generic_parser_test_error<ptree, ReadFunc, WriteFunc, json_parser_error>
+ (
+ ReadFunc(), WriteFunc(false), error_data_4, NULL,
+ "testerr4.json", NULL, "testerr4out.json", 3
+ );
+
+ generic_parser_test_ok<Ptree, ReadFunc, WriteFunc>
+ (
+ ReadFunc(), WriteFunc(false), bug_data_pr4387, NULL,
+ "testpr4387.json", NULL, "testpr4387out.json", 4, 3, 0
+ );
+
+ check_exact_roundtrip<Ptree>(ReadFunc(), WriteFunc(true),
+ bug_data_pr7180_1);
+ check_exact_roundtrip<Ptree>(ReadFunc(), WriteFunc(false),
+ bug_data_pr7180_2);
+
+}
+
+void test_escaping_utf8()
+{
+ // This is cyrillic text encoded as UTF-8
+ std::string str = "\xD0\x9C\xD0\xB0\xD0\xBC\xD0\xB0 "
+ "\xD0\xBC\xD1\x8B\xD0\xBB\xD0\xB0 \xD1\x80\xD0\xB0\xD0\xBC\xD1\x83";
+ // Should NOT escape UTF-8
+ BOOST_CHECK(boost::property_tree::json_parser::create_escapes(str) == str);
+}
+
+void test_escaping_wide()
+{
+ // Should NOT escape characters within ASCII range.
+ std::wstring str1 = L"I am wstring with ASCII";
+ BOOST_CHECK(boost::property_tree::json_parser::create_escapes(str1) == str1);
+ // Should escape characters outside ASCII range - this is NOT utf-8
+ // This is cyrillic text
+ std::wstring str2 = L"\u041C\u0430\u043C\u0430 "
+ L"\u043C\u044B\u043B\u0430 \u0440\u0430\u043C\u0443";
+ BOOST_CHECK(boost::property_tree::json_parser::create_escapes(str2) ==
+ L"\\u041C\\u0430\\u043C\\u0430 "
+ L"\\u043C\\u044B\\u043B\\u0430 \\u0440\\u0430\\u043C\\u0443");
+}
+
+int test_main(int argc, char *argv[])
+{
+ using namespace boost::property_tree;
+ test_json_parser<ptree>();
+ test_json_parser<iptree>();
+ test_escaping_utf8();
+#ifndef BOOST_NO_CWCHAR
+ test_json_parser<wptree>();
+ test_json_parser<wiptree>();
+ test_escaping_wide();
+#endif
+ return 0;
+}
diff --git a/src/boost/libs/property_tree/test/test_json_parser2.cpp b/src/boost/libs/property_tree/test/test_json_parser2.cpp
new file mode 100644
index 000000000..248ba4692
--- /dev/null
+++ b/src/boost/libs/property_tree/test/test_json_parser2.cpp
@@ -0,0 +1,935 @@
+#include <boost/property_tree/json_parser/detail/parser.hpp>
+#include <boost/property_tree/json_parser/detail/narrow_encoding.hpp>
+#include <boost/property_tree/json_parser/detail/wide_encoding.hpp>
+#include <boost/property_tree/json_parser/detail/standard_callbacks.hpp>
+#include "prefixing_callbacks.hpp"
+
+#define BOOST_TEST_NO_MAIN
+#include <boost/test/unit_test.hpp>
+#include <boost/test/parameterized_test.hpp>
+
+#include <boost/property_tree/ptree.hpp>
+#include <boost/range/iterator_range.hpp>
+
+#include <cassert>
+#include <sstream>
+#include <vector>
+
+using namespace boost::property_tree;
+
+template <typename Ch> struct encoding;
+template <> struct encoding<char>
+ : json_parser::detail::utf8_utf8_encoding
+{};
+template <> struct encoding<wchar_t>
+ : json_parser::detail::wide_wide_encoding
+{};
+
+template <typename Callbacks, typename Ch>
+struct test_parser
+{
+ Callbacks callbacks;
+ ::encoding<Ch> encoding;
+ typedef std::basic_string<Ch> string;
+ typedef basic_ptree<string, string> tree;
+ json_parser::detail::parser<Callbacks, ::encoding<Ch>,
+ typename string::const_iterator,
+ typename string::const_iterator>
+ parser;
+
+ test_parser() : parser(callbacks, encoding) {}
+
+ bool parse_null(const string& input, string& output) {
+ parser.set_input("", input);
+ bool result = parser.parse_null();
+ if (result) {
+ parser.finish();
+ output = callbacks.output().data();
+ }
+ return result;
+ }
+
+ bool parse_boolean(const string& input, string& output) {
+ parser.set_input("", input);
+ bool result = parser.parse_boolean();
+ if (result) {
+ parser.finish();
+ output = callbacks.output().data();
+ }
+ return result;
+ }
+
+ bool parse_number(const string& input, string& output) {
+ parser.set_input("", input);
+ bool result = parser.parse_number();
+ if (result) {
+ parser.finish();
+ output = callbacks.output().data();
+ }
+ return result;
+ }
+
+ bool parse_string(const string& input, string& output) {
+ parser.set_input("", input);
+ bool result = parser.parse_string();
+ if (result) {
+ parser.finish();
+ output = callbacks.output().data();
+ }
+ return result;
+ }
+
+ bool parse_array(const string& input, tree& output) {
+ parser.set_input("", input);
+ bool result = parser.parse_array();
+ if (result) {
+ parser.finish();
+ output = callbacks.output();
+ }
+ return result;
+ }
+
+ bool parse_object(const string& input, tree& output) {
+ parser.set_input("", input);
+ bool result = parser.parse_object();
+ if (result) {
+ parser.finish();
+ output = callbacks.output();
+ }
+ return result;
+ }
+
+ void parse_value(const string& input, tree& output) {
+ parser.set_input("", input);
+ parser.parse_value();
+ parser.finish();
+ output = callbacks.output();
+ }
+};
+
+template <typename Ch>
+struct standard_parser
+ : test_parser<
+ json_parser::detail::standard_callbacks<
+ basic_ptree<std::basic_string<Ch>, std::basic_string<Ch> > >,
+ Ch>
+{};
+
+template <typename Ch>
+struct prefixing_parser
+ : test_parser<
+ prefixing_callbacks<
+ basic_ptree<std::basic_string<Ch>, std::basic_string<Ch> > >,
+ Ch>
+{};
+
+#define BOM_N "\xef\xbb\xbf"
+#define BOM_W L"\xfeff"
+
+namespace boost { namespace test_tools { namespace tt_detail {
+ template<>
+ struct print_log_value<std::wstring> {
+ void operator()(std::ostream& os, const std::wstring& s) {
+ print_log_value<const wchar_t*>()(os, s.c_str());
+ }
+ };
+}}}
+BOOST_TEST_DONT_PRINT_LOG_VALUE(ptree::iterator)
+BOOST_TEST_DONT_PRINT_LOG_VALUE(ptree::const_iterator)
+BOOST_TEST_DONT_PRINT_LOG_VALUE(wptree::iterator)
+BOOST_TEST_DONT_PRINT_LOG_VALUE(wptree::const_iterator)
+
+BOOST_AUTO_TEST_CASE(null_parse_result_is_input) {
+ std::string parsed;
+ standard_parser<char> p;
+ BOOST_REQUIRE(p.parse_null("null", parsed));
+ BOOST_CHECK_EQUAL("null", parsed);
+}
+
+BOOST_AUTO_TEST_CASE(uses_traits_from_null)
+{
+ std::string parsed;
+ prefixing_parser<char> p;
+ BOOST_REQUIRE(p.parse_null("null", parsed));
+ BOOST_CHECK_EQUAL("_:null", parsed);
+}
+
+BOOST_AUTO_TEST_CASE(null_parse_skips_bom) {
+ std::string parsed;
+ standard_parser<char> p;
+ BOOST_REQUIRE(p.parse_null(BOM_N "null", parsed));
+ BOOST_CHECK_EQUAL("null", parsed);
+}
+
+BOOST_AUTO_TEST_CASE(null_parse_result_is_input_w) {
+ std::wstring parsed;
+ standard_parser<wchar_t> p;
+ BOOST_REQUIRE(p.parse_null(L"null", parsed));
+ BOOST_CHECK_EQUAL(L"null", parsed);
+}
+
+BOOST_AUTO_TEST_CASE(uses_traits_from_null_w)
+{
+ std::wstring parsed;
+ prefixing_parser<wchar_t> p;
+ BOOST_REQUIRE(p.parse_null(L"null", parsed));
+ BOOST_CHECK_EQUAL(L"_:null", parsed);
+}
+
+BOOST_AUTO_TEST_CASE(null_parse_skips_bom_w) {
+ std::wstring parsed;
+ standard_parser<wchar_t> p;
+ BOOST_REQUIRE(p.parse_null(BOM_W L"null", parsed));
+ BOOST_CHECK_EQUAL(L"null", parsed);
+}
+
+void boolean_parse_result_is_input_n(const char* param) {
+ std::string parsed;
+ standard_parser<char> p;
+ BOOST_REQUIRE(p.parse_boolean(param, parsed));
+ BOOST_CHECK_EQUAL(param, parsed);
+}
+
+const char* const booleans_n[] = { "true", "false" };
+
+BOOST_AUTO_TEST_CASE(uses_traits_from_boolean_n)
+{
+ std::string parsed;
+ prefixing_parser<char> p;
+ BOOST_REQUIRE(p.parse_boolean("true", parsed));
+ BOOST_CHECK_EQUAL("b:true", parsed);
+}
+
+void boolean_parse_result_is_input_w(const wchar_t* param) {
+ std::wstring parsed;
+ standard_parser<wchar_t> p;
+ BOOST_REQUIRE(p.parse_boolean(param, parsed));
+ BOOST_CHECK_EQUAL(param, parsed);
+}
+
+const wchar_t* const booleans_w[] = { L"true", L"false" };
+
+BOOST_AUTO_TEST_CASE(uses_traits_from_boolean_w)
+{
+ std::wstring parsed;
+ prefixing_parser<wchar_t> p;
+ BOOST_REQUIRE(p.parse_boolean(L"true", parsed));
+ BOOST_CHECK_EQUAL(L"b:true", parsed);
+}
+
+void number_parse_result_is_input_n(const char* param) {
+ std::string parsed;
+ standard_parser<char> p;
+ BOOST_REQUIRE(p.parse_number(param, parsed));
+ BOOST_CHECK_EQUAL(param, parsed);
+}
+
+const char* const numbers_n[] = {
+ "0",
+ "-0",
+ "1824",
+ "-0.1",
+ "123.142",
+ "1e+0",
+ "1E-0",
+ "1.1e134"
+};
+
+BOOST_AUTO_TEST_CASE(uses_traits_from_number_n)
+{
+ std::string parsed;
+ prefixing_parser<char> p;
+ BOOST_REQUIRE(p.parse_number("12345", parsed));
+ BOOST_CHECK_EQUAL("n:12345", parsed);
+}
+
+void number_parse_result_is_input_w(const wchar_t* param) {
+ std::wstring parsed;
+ standard_parser<wchar_t> p;
+ BOOST_REQUIRE(p.parse_number(param, parsed));
+ BOOST_CHECK_EQUAL(param, parsed);
+}
+
+const wchar_t* const numbers_w[] = {
+ L"0",
+ L"-0",
+ L"1824",
+ L"-0.1",
+ L"123.142",
+ L"1e+0",
+ L"1E-0",
+ L"1.1e134"
+};
+
+BOOST_AUTO_TEST_CASE(uses_traits_from_number_w)
+{
+ std::wstring parsed;
+ prefixing_parser<wchar_t> p;
+ BOOST_REQUIRE(p.parse_number(L"12345", parsed));
+ BOOST_CHECK_EQUAL(L"n:12345", parsed);
+}
+
+struct string_input_n {
+ const char* encoded;
+ const char* expected;
+};
+
+void string_parsed_correctly_n(string_input_n param) {
+ std::string parsed;
+ standard_parser<char> p;
+ BOOST_REQUIRE(p.parse_string(param.encoded, parsed));
+ BOOST_CHECK_EQUAL(param.expected, parsed);
+}
+
+const string_input_n strings_n[] = {
+ {"\"\"", ""},
+ {"\"abc\"", "abc"},
+ {"\"a\\nb\"", "a\nb"},
+ {"\"\\\"\"", "\""},
+ {"\"\\\\\"", "\\"},
+ {"\"\\/\"", "/"},
+ {"\"\\b\"", "\b"},
+ {"\"\\f\"", "\f"},
+ {"\"\\r\"", "\r"},
+ {"\"\\t\"", "\t"},
+ {"\"\\u0001\\u00f2\\u28Ec\"", "\x01" "\xC3\xB2" "\xE2\xA3\xAC"},
+ {"\"\\ud801\\udc37\"", "\xf0\x90\x90\xb7"}, // U+10437
+ {"\xef\xbb\xbf\"\"", ""} // BOM
+};
+
+BOOST_AUTO_TEST_CASE(uses_string_callbacks)
+{
+ std::string parsed;
+ prefixing_parser<char> p;
+ BOOST_REQUIRE(p.parse_string("\"a\"", parsed));
+ BOOST_CHECK_EQUAL("s:a", parsed);
+}
+
+struct string_input_w {
+ const wchar_t* encoded;
+ const wchar_t* expected;
+};
+
+void string_parsed_correctly_w(string_input_w param) {
+ std::wstring parsed;
+ standard_parser<wchar_t> p;
+ BOOST_REQUIRE(p.parse_string(param.encoded, parsed));
+ BOOST_CHECK_EQUAL(param.expected, parsed);
+}
+
+const string_input_w strings_w[] = {
+ {L"\"\"", L""},
+ {L"\"abc\"", L"abc"},
+ {L"\"a\\nb\"", L"a\nb"},
+ {L"\"\\\"\"", L"\""},
+ {L"\"\\\\\"", L"\\"},
+ {L"\"\\/\"", L"/"},
+ {L"\"\\b\"", L"\b"},
+ {L"\"\\f\"", L"\f"},
+ {L"\"\\r\"", L"\r"},
+ {L"\"\\t\"", L"\t"},
+ {L"\"\\u0001\\u00f2\\u28Ec\"", L"\x0001" L"\x00F2" L"\x28EC"},
+ {L"\xfeff\"\"", L""} // BOM
+};
+
+BOOST_AUTO_TEST_CASE(empty_array) {
+ ptree tree;
+ standard_parser<char> p;
+ const char* input = " [ ]";
+ BOOST_REQUIRE(p.parse_array(input, tree));
+ BOOST_CHECK_EQUAL("", tree.data());
+ BOOST_CHECK_EQUAL(0u, tree.size());
+}
+
+BOOST_AUTO_TEST_CASE(array_gets_tagged) {
+ wptree tree;
+ prefixing_parser<wchar_t> p;
+ const wchar_t* input = L" [ ]";
+ BOOST_REQUIRE(p.parse_array(input, tree));
+ BOOST_CHECK_EQUAL(L"a:", tree.data());
+ BOOST_CHECK_EQUAL(0u, tree.size());
+}
+
+BOOST_AUTO_TEST_CASE(array_with_values) {
+ wptree tree;
+ standard_parser<wchar_t> p;
+ const wchar_t* input = L"[\n"
+L" 123, \"abc\" ,true ,\n"
+L" null\n"
+L" ]";
+ BOOST_REQUIRE(p.parse_array(input, tree));
+ BOOST_REQUIRE_EQUAL(4u, tree.size());
+ wptree::iterator it = tree.begin();
+ BOOST_CHECK_EQUAL(L"", it->first);
+ BOOST_CHECK_EQUAL(L"123", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL(L"", it->first);
+ BOOST_CHECK_EQUAL(L"abc", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL(L"", it->first);
+ BOOST_CHECK_EQUAL(L"true", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL(L"", it->first);
+ BOOST_CHECK_EQUAL(L"null", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL(tree.end(), it);
+}
+
+BOOST_AUTO_TEST_CASE(array_values_get_tagged) {
+ ptree tree;
+ prefixing_parser<char> p;
+ const char* input = "[\n"
+" 123, \"abc\" ,true ,\n"
+" null\n"
+" ]";
+ BOOST_REQUIRE(p.parse_array(input, tree));
+ BOOST_REQUIRE_EQUAL(4u, tree.size());
+ BOOST_CHECK_EQUAL("a:", tree.data());
+ ptree::iterator it = tree.begin();
+ BOOST_CHECK_EQUAL("", it->first);
+ BOOST_CHECK_EQUAL("n:123", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("", it->first);
+ BOOST_CHECK_EQUAL("s:abc", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("", it->first);
+ BOOST_CHECK_EQUAL("b:true", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("", it->first);
+ BOOST_CHECK_EQUAL("_:null", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL(tree.end(), it);
+}
+
+BOOST_AUTO_TEST_CASE(nested_array) {
+ ptree tree;
+ standard_parser<char> p;
+ const char* input = "[[1,2],3,[4,5]]";
+ BOOST_REQUIRE(p.parse_array(input, tree));
+ BOOST_REQUIRE_EQUAL(3u, tree.size());
+ ptree::iterator it = tree.begin();
+ BOOST_CHECK_EQUAL("", it->first);
+ {
+ ptree& sub = it->second;
+ BOOST_CHECK_EQUAL("", sub.data());
+ BOOST_REQUIRE_EQUAL(2u, sub.size());
+ ptree::iterator iit = sub.begin();
+ BOOST_CHECK_EQUAL("", iit->first);
+ BOOST_CHECK_EQUAL("1", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL("", iit->first);
+ BOOST_CHECK_EQUAL("2", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL(sub.end(), iit);
+ }
+ ++it;
+ BOOST_CHECK_EQUAL("", it->first);
+ BOOST_CHECK_EQUAL("3", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("", it->first);
+ {
+ ptree& sub = it->second;
+ BOOST_CHECK_EQUAL("", sub.data());
+ BOOST_REQUIRE_EQUAL(2u, sub.size());
+ ptree::iterator iit = sub.begin();
+ BOOST_CHECK_EQUAL("", iit->first);
+ BOOST_CHECK_EQUAL("4", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL("", iit->first);
+ BOOST_CHECK_EQUAL("5", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL(sub.end(), iit);
+ }
+ ++it;
+ BOOST_CHECK_EQUAL(tree.end(), it);
+}
+
+BOOST_AUTO_TEST_CASE(empty_object) {
+ ptree tree;
+ standard_parser<char> p;
+ const char* input = " { }";
+ BOOST_REQUIRE(p.parse_object(input, tree));
+ BOOST_CHECK_EQUAL("", tree.data());
+ BOOST_CHECK_EQUAL(0u, tree.size());
+}
+
+BOOST_AUTO_TEST_CASE(object_gets_tagged) {
+ wptree tree;
+ prefixing_parser<wchar_t> p;
+ const wchar_t* input = L" { }";
+ BOOST_REQUIRE(p.parse_object(input, tree));
+ BOOST_CHECK_EQUAL(L"o:", tree.data());
+ BOOST_CHECK_EQUAL(0u, tree.size());
+}
+
+BOOST_AUTO_TEST_CASE(object_with_values) {
+ wptree tree;
+ standard_parser<wchar_t> p;
+ const wchar_t* input = L"{\n"
+L" \"1\":123, \"2\"\n"
+L" :\"abc\" ,\"3\": true ,\n"
+L" \"4\" : null\n"
+L" }";
+ BOOST_REQUIRE(p.parse_object(input, tree));
+ BOOST_REQUIRE_EQUAL(4u, tree.size());
+ wptree::iterator it = tree.begin();
+ BOOST_CHECK_EQUAL(L"1", it->first);
+ BOOST_CHECK_EQUAL(L"123", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL(L"2", it->first);
+ BOOST_CHECK_EQUAL(L"abc", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL(L"3", it->first);
+ BOOST_CHECK_EQUAL(L"true", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL(L"4", it->first);
+ BOOST_CHECK_EQUAL(L"null", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL(tree.end(), it);
+}
+
+BOOST_AUTO_TEST_CASE(object_values_get_tagged) {
+ ptree tree;
+ prefixing_parser<char> p;
+ const char* input = "{\n"
+ "\"1\": 123, \"2\": \"abc\" ,\"3\": true ,\n"
+ "\"4\": null\n"
+ "}";
+ BOOST_REQUIRE(p.parse_object(input, tree));
+ BOOST_REQUIRE_EQUAL(4u, tree.size());
+ BOOST_CHECK_EQUAL("o:", tree.data());
+ ptree::iterator it = tree.begin();
+ BOOST_CHECK_EQUAL("1", it->first);
+ BOOST_CHECK_EQUAL("n:123", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("2", it->first);
+ BOOST_CHECK_EQUAL("s:abc", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("3", it->first);
+ BOOST_CHECK_EQUAL("b:true", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("4", it->first);
+ BOOST_CHECK_EQUAL("_:null", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL(tree.end(), it);
+}
+
+BOOST_AUTO_TEST_CASE(nested_object) {
+ ptree tree;
+ standard_parser<char> p;
+ const char* input = "{\"a\":{\"b\":1,\"c\":2},\"d\":3,\"e\":{\"f\":4,\"g\":5}}";
+ BOOST_REQUIRE(p.parse_object(input, tree));
+ BOOST_REQUIRE_EQUAL(3u, tree.size());
+ ptree::iterator it = tree.begin();
+ BOOST_CHECK_EQUAL("a", it->first);
+ {
+ ptree& sub = it->second;
+ BOOST_CHECK_EQUAL("", sub.data());
+ BOOST_REQUIRE_EQUAL(2u, sub.size());
+ ptree::iterator iit = sub.begin();
+ BOOST_CHECK_EQUAL("b", iit->first);
+ BOOST_CHECK_EQUAL("1", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL("c", iit->first);
+ BOOST_CHECK_EQUAL("2", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL(sub.end(), iit);
+ }
+ ++it;
+ BOOST_CHECK_EQUAL("d", it->first);
+ BOOST_CHECK_EQUAL("3", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("e", it->first);
+ {
+ ptree& sub = it->second;
+ BOOST_CHECK_EQUAL("", sub.data());
+ BOOST_REQUIRE_EQUAL(2u, sub.size());
+ ptree::iterator iit = sub.begin();
+ BOOST_CHECK_EQUAL("f", iit->first);
+ BOOST_CHECK_EQUAL("4", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL("g", iit->first);
+ BOOST_CHECK_EQUAL("5", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL(sub.end(), iit);
+ }
+ ++it;
+ BOOST_CHECK_EQUAL(tree.end(), it);
+}
+
+BOOST_AUTO_TEST_CASE(array_in_object) {
+ ptree tree;
+ standard_parser<char> p;
+ const char* input = "{\"a\":[1,2],\"b\":3,\"c\":[4,5]}";
+ BOOST_REQUIRE(p.parse_object(input, tree));
+ BOOST_REQUIRE_EQUAL(3u, tree.size());
+ ptree::iterator it = tree.begin();
+ BOOST_CHECK_EQUAL("a", it->first);
+ {
+ ptree& sub = it->second;
+ BOOST_CHECK_EQUAL("", sub.data());
+ BOOST_REQUIRE_EQUAL(2u, sub.size());
+ ptree::iterator iit = sub.begin();
+ BOOST_CHECK_EQUAL("", iit->first);
+ BOOST_CHECK_EQUAL("1", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL("", iit->first);
+ BOOST_CHECK_EQUAL("2", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL(sub.end(), iit);
+ }
+ ++it;
+ BOOST_CHECK_EQUAL("b", it->first);
+ BOOST_CHECK_EQUAL("3", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("c", it->first);
+ {
+ ptree& sub = it->second;
+ BOOST_CHECK_EQUAL("", sub.data());
+ BOOST_REQUIRE_EQUAL(2u, sub.size());
+ ptree::iterator iit = sub.begin();
+ BOOST_CHECK_EQUAL("", iit->first);
+ BOOST_CHECK_EQUAL("4", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL("", iit->first);
+ BOOST_CHECK_EQUAL("5", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL(sub.end(), iit);
+ }
+ ++it;
+ BOOST_CHECK_EQUAL(tree.end(), it);
+}
+
+BOOST_AUTO_TEST_CASE(object_in_array) {
+ ptree tree;
+ standard_parser<char> p;
+ const char* input = "[{\"a\":1,\"b\":2},3,{\"c\":4,\"d\":5}]";
+ BOOST_REQUIRE(p.parse_array(input, tree));
+ BOOST_REQUIRE_EQUAL(3u, tree.size());
+ ptree::iterator it = tree.begin();
+ BOOST_CHECK_EQUAL("", it->first);
+ {
+ ptree& sub = it->second;
+ BOOST_CHECK_EQUAL("", sub.data());
+ BOOST_REQUIRE_EQUAL(2u, sub.size());
+ ptree::iterator iit = sub.begin();
+ BOOST_CHECK_EQUAL("a", iit->first);
+ BOOST_CHECK_EQUAL("1", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL("b", iit->first);
+ BOOST_CHECK_EQUAL("2", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL(sub.end(), iit);
+ }
+ ++it;
+ BOOST_CHECK_EQUAL("", it->first);
+ BOOST_CHECK_EQUAL("3", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("", it->first);
+ {
+ ptree& sub = it->second;
+ BOOST_CHECK_EQUAL("", sub.data());
+ BOOST_REQUIRE_EQUAL(2u, sub.size());
+ ptree::iterator iit = sub.begin();
+ BOOST_CHECK_EQUAL("c", iit->first);
+ BOOST_CHECK_EQUAL("4", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL("d", iit->first);
+ BOOST_CHECK_EQUAL("5", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL(sub.end(), iit);
+ }
+ ++it;
+ BOOST_CHECK_EQUAL(tree.end(), it);
+}
+
+BOOST_AUTO_TEST_CASE(parser_works_with_input_iterators) {
+ const char* input = " {\n"
+" \"1\":123, \"2\"\n"
+" :\"abc\" ,\"3\": true ,\n"
+" \"4\" : null, \"5\" : [ 1, 23\n"
+" , 456 ]\n"
+" }";
+
+ std::istringstream is(input);
+ typedef std::istreambuf_iterator<char> iterator;
+ json_parser::detail::standard_callbacks<ptree> callbacks;
+ json_parser::detail::utf8_utf8_encoding encoding;
+ json_parser::detail::parser<json_parser::detail::standard_callbacks<ptree>,
+ json_parser::detail::utf8_utf8_encoding,
+ iterator, iterator>
+ p(callbacks, encoding);
+
+ p.set_input("", boost::make_iterator_range(iterator(is), iterator()));
+ p.parse_value();
+
+ const ptree& tree = callbacks.output();
+ BOOST_REQUIRE_EQUAL(5u, tree.size());
+ ptree::const_iterator it = tree.begin();
+ BOOST_CHECK_EQUAL("1", it->first);
+ BOOST_CHECK_EQUAL("123", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("2", it->first);
+ BOOST_CHECK_EQUAL("abc", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("3", it->first);
+ BOOST_CHECK_EQUAL("true", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("4", it->first);
+ BOOST_CHECK_EQUAL("null", it->second.data());
+ ++it;
+ BOOST_CHECK_EQUAL("5", it->first);
+ {
+ const ptree& sub = it->second;
+ BOOST_CHECK_EQUAL("", sub.data());
+ BOOST_REQUIRE_EQUAL(3u, sub.size());
+ ptree::const_iterator iit = sub.begin();
+ BOOST_CHECK_EQUAL("", iit->first);
+ BOOST_CHECK_EQUAL("1", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL("", iit->first);
+ BOOST_CHECK_EQUAL("23", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL("", iit->first);
+ BOOST_CHECK_EQUAL("456", iit->second.data());
+ ++iit;
+ BOOST_CHECK_EQUAL(sub.end(), iit);
+ }
+ ++it;
+ BOOST_CHECK_EQUAL(tree.end(), it);
+}
+
+struct bad_parse_n {
+ const char* json;
+ const char* message_substring;
+};
+
+void parse_error_thrown_with_message_n(bad_parse_n param) {
+ try {
+ standard_parser<char> p;
+ ptree dummy;
+ p.parse_value(param.json, dummy);
+ BOOST_FAIL("expected exception");
+ } catch (json_parser::json_parser_error& e) {
+ std::string message = e.message();
+ BOOST_CHECK_MESSAGE(message.find(param.message_substring) !=
+ std::string::npos,
+ "bad error message on input '" << param.json
+ << "', need: '" << param.message_substring
+ << "' but found '" << message << "'");
+ }
+}
+
+const bad_parse_n errors_n[] = {
+ {"", "expected value"},
+ {"(", "expected value"},
+
+ {"n", "expected 'null'"},
+ {"nu", "expected 'null'"},
+ {"nul", "expected 'null'"},
+ {"n ", "expected 'null'"},
+ {"nu ", "expected 'null'"},
+ {"nul ", "expected 'null'"},
+ {"nx", "expected 'null'"},
+ {"nux", "expected 'null'"},
+ {"nulx", "expected 'null'"},
+
+ {"t", "expected 'true'"},
+ {"tr", "expected 'true'"},
+ {"tu", "expected 'true'"},
+ {"t ", "expected 'true'"},
+ {"tr ", "expected 'true'"},
+ {"tru ", "expected 'true'"},
+ {"tx", "expected 'true'"},
+ {"trx", "expected 'true'"},
+ {"trux", "expected 'true'"},
+
+ {"f", "expected 'false'"},
+ {"fa", "expected 'false'"},
+ {"fal", "expected 'false'"},
+ {"fals", "expected 'false'"},
+ {"f ", "expected 'false'"},
+ {"fa ", "expected 'false'"},
+ {"fal ", "expected 'false'"},
+ {"fals ", "expected 'false'"},
+ {"fx", "expected 'false'"},
+ {"fax", "expected 'false'"},
+ {"falx", "expected 'false'"},
+ {"falsx", "expected 'false'"},
+
+ {"-", "expected digits"},
+ {"01", "garbage after data"},
+ {"0.", "need at least one digit after '.'"},
+ {"0e", "need at least one digit in exponent"},
+ {"0e-", "need at least one digit in exponent"},
+
+ {"\"", "unterminated string"},
+ {"\"asd", "unterminated string"},
+ {"\"\n\"", "invalid code sequence"}, // control character
+ {"\"\xff\"", "invalid code sequence"}, // bad lead byte
+ {"\"\x80\"", "invalid code sequence"}, // stray trail byte
+ {"\"\xc0", "invalid code sequence"}, // eos after lead byte
+ {"\"\xc0\"", "invalid code sequence"}, // bad trail byte
+ {"\"\xc0m\"", "invalid code sequence"}, // also bad trail byte
+ {"\"\\", "invalid escape sequence"},
+ {"\"\\p\"", "invalid escape sequence"},
+ {"\"\\u", "invalid escape sequence"},
+ {"\"\\u\"", "invalid escape sequence"},
+ {"\"\\ug\"", "invalid escape sequence"},
+ {"\"\\u1\"", "invalid escape sequence"},
+ {"\"\\u1g\"", "invalid escape sequence"},
+ {"\"\\u11\"", "invalid escape sequence"},
+ {"\"\\u11g\"", "invalid escape sequence"},
+ {"\"\\u111\"", "invalid escape sequence"},
+ {"\"\\u111g\"", "invalid escape sequence"},
+ {"\"\\ude00\"", "stray low surrogate"},
+ {"\"\\ud900", "stray high surrogate"},
+ {"\"\\ud900foo\"", "stray high surrogate"},
+ {"\"\\ud900\\", "expected codepoint reference"},
+ {"\"\\ud900\\n\"", "expected codepoint reference"},
+ {"\"\\ud900\\u1000\"", "expected low surrogate"},
+
+ {"[", "expected value"},
+ {"[1", "expected ']' or ','"},
+ {"[1,", "expected value"},
+ {"[1,]", "expected value"},
+ {"[1}", "expected ']' or ','"},
+
+ {"{", "expected key string"},
+ {"{1:2}", "expected key string"},
+ {"{\"\"", "expected ':'"},
+ {"{\"\"}", "expected ':'"},
+ {"{\"\":", "expected value"},
+ {"{\"\":}", "expected value"},
+ {"{\"\":0", "expected '}' or ','"},
+ {"{\"\":0]", "expected '}' or ','"},
+ {"{\"\":0,", "expected key string"},
+ {"{\"\":0,}", "expected key string"},
+};
+
+struct bad_parse_w {
+ const wchar_t* json;
+ const char* message_substring;
+};
+
+void parse_error_thrown_with_message_w(bad_parse_w param) {
+ try {
+ standard_parser<wchar_t> p;
+ wptree dummy;
+ p.parse_value(param.json, dummy);
+ BOOST_FAIL("expected exception");
+ } catch (json_parser::json_parser_error& e) {
+ std::string message = e.message();
+ BOOST_CHECK_MESSAGE(message.find(param.message_substring) !=
+ std::string::npos,
+ "bad error message on input '" << param.json
+ << "', need: '" << param.message_substring
+ << "' but found '" << message << "'");
+ }
+}
+
+const bad_parse_w errors_w[] = {
+ {L"", "expected value"},
+ {L"(", "expected value"},
+
+ {L"n", "expected 'null'"},
+ {L"nu", "expected 'null'"},
+ {L"nul", "expected 'null'"},
+ {L"n ", "expected 'null'"},
+ {L"nu ", "expected 'null'"},
+ {L"nul ", "expected 'null'"},
+ {L"nx", "expected 'null'"},
+ {L"nux", "expected 'null'"},
+ {L"nulx", "expected 'null'"},
+
+ {L"t", "expected 'true'"},
+ {L"tr", "expected 'true'"},
+ {L"tu", "expected 'true'"},
+ {L"t ", "expected 'true'"},
+ {L"tr ", "expected 'true'"},
+ {L"tru ", "expected 'true'"},
+ {L"tx", "expected 'true'"},
+ {L"trx", "expected 'true'"},
+ {L"trux", "expected 'true'"},
+
+ {L"f", "expected 'false'"},
+ {L"fa", "expected 'false'"},
+ {L"fal", "expected 'false'"},
+ {L"fals", "expected 'false'"},
+ {L"f ", "expected 'false'"},
+ {L"fa ", "expected 'false'"},
+ {L"fal ", "expected 'false'"},
+ {L"fals ", "expected 'false'"},
+ {L"fx", "expected 'false'"},
+ {L"fax", "expected 'false'"},
+ {L"falx", "expected 'false'"},
+ {L"falsx", "expected 'false'"},
+
+ {L"-", "expected digits"},
+ {L"01", "garbage after data"},
+ {L"0.", "need at least one digit after '.'"},
+ {L"0e", "need at least one digit in exponent"},
+ {L"0e-", "need at least one digit in exponent"},
+
+ {L"\"", "unterminated string"},
+ {L"\"asd", "unterminated string"},
+ {L"\"\n\"", "invalid code sequence"}, // control character
+ // Encoding not known, so no UTF-16 encoding error tests.
+ {L"\"\\", "invalid escape sequence"},
+ {L"\"\\p\"", "invalid escape sequence"},
+ {L"\"\\u", "invalid escape sequence"},
+ {L"\"\\u\"", "invalid escape sequence"},
+ {L"\"\\ug\"", "invalid escape sequence"},
+ {L"\"\\u1\"", "invalid escape sequence"},
+ {L"\"\\u1g\"", "invalid escape sequence"},
+ {L"\"\\u11\"", "invalid escape sequence"},
+ {L"\"\\u11g\"", "invalid escape sequence"},
+ {L"\"\\u111\"", "invalid escape sequence"},
+ {L"\"\\u111g\"", "invalid escape sequence"},
+ {L"\"\\ude00\"", "stray low surrogate"},
+ {L"\"\\ud900", "stray high surrogate"},
+ {L"\"\\ud900foo\"", "stray high surrogate"},
+ {L"\"\\ud900\\", "expected codepoint reference"},
+ {L"\"\\ud900\\n\"", "expected codepoint reference"},
+ {L"\"\\ud900\\u1000\"", "expected low surrogate"},
+
+ {L"[", "expected value"},
+ {L"[1", "expected ']' or ','"},
+ {L"[1,", "expected value"},
+ {L"[1,]", "expected value"},
+ {L"[1}", "expected ']' or ','"},
+
+ {L"{", "expected key string"},
+ {L"{1:2}", "expected key string"},
+ {L"{\"\"", "expected ':'"},
+ {L"{\"\"}", "expected ':'"},
+ {L"{\"\":", "expected value"},
+ {L"{\"\":}", "expected value"},
+ {L"{\"\":0", "expected '}' or ','"},
+ {L"{\"\":0]", "expected '}' or ','"},
+ {L"{\"\":0,", "expected key string"},
+ {L"{\"\":0,}", "expected key string"},
+};
+
+template <typename T, std::size_t N>
+std::size_t arraysize(T(&)[N]) { return N; }
+
+#define ARRAY_TEST_CASE(fn, a) \
+ BOOST_PARAM_TEST_CASE(fn, (a), (a) + arraysize((a)))
+
+using namespace boost::unit_test;
+
+test_suite* init_unit_test_suite(int, char*[])
+{
+ master_test_suite_t& ts = boost::unit_test::framework::master_test_suite();
+ ts.add(ARRAY_TEST_CASE(boolean_parse_result_is_input_n, booleans_n));
+ ts.add(ARRAY_TEST_CASE(boolean_parse_result_is_input_w, booleans_w));
+ ts.add(ARRAY_TEST_CASE(number_parse_result_is_input_n, numbers_n));
+ ts.add(ARRAY_TEST_CASE(number_parse_result_is_input_w, numbers_w));
+ ts.add(ARRAY_TEST_CASE(string_parsed_correctly_n, strings_n));
+ ts.add(ARRAY_TEST_CASE(string_parsed_correctly_w, strings_w));
+ ts.add(ARRAY_TEST_CASE(parse_error_thrown_with_message_n, errors_n));
+ ts.add(ARRAY_TEST_CASE(parse_error_thrown_with_message_w, errors_w));
+
+ return 0;
+}
diff --git a/src/boost/libs/property_tree/test/test_multi_module1.cpp b/src/boost/libs/property_tree/test/test_multi_module1.cpp
new file mode 100644
index 000000000..3bb3bb455
--- /dev/null
+++ b/src/boost/libs/property_tree/test/test_multi_module1.cpp
@@ -0,0 +1,21 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/info_parser.hpp>
+#include <boost/property_tree/ini_parser.hpp>
+#include <boost/property_tree/json_parser.hpp>
+#include <boost/property_tree/xml_parser.hpp>
+
+void f();
+
+int main()
+{
+ f();
+}
diff --git a/src/boost/libs/property_tree/test/test_multi_module2.cpp b/src/boost/libs/property_tree/test/test_multi_module2.cpp
new file mode 100644
index 000000000..6d35253f6
--- /dev/null
+++ b/src/boost/libs/property_tree/test/test_multi_module2.cpp
@@ -0,0 +1,18 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/info_parser.hpp>
+#include <boost/property_tree/ini_parser.hpp>
+#include <boost/property_tree/json_parser.hpp>
+#include <boost/property_tree/xml_parser.hpp>
+
+void f()
+{
+}
diff --git a/src/boost/libs/property_tree/test/test_property_tree.cpp b/src/boost/libs/property_tree/test/test_property_tree.cpp
new file mode 100644
index 000000000..55ff5a830
--- /dev/null
+++ b/src/boost/libs/property_tree/test/test_property_tree.cpp
@@ -0,0 +1,203 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+#include "test_utils.hpp"
+#include <boost/any.hpp>
+#include <boost/range.hpp>
+#include <list>
+#include <cmath>
+#include <iostream>
+
+// If using VC, disable some warnings that trip in boost::serialization bowels
+#ifdef BOOST_MSVC
+ #pragma warning(disable:4267) // Narrowing conversion
+ #pragma warning(disable:4996) // Deprecated functions
+#endif
+
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/binary_iarchive.hpp>
+#include <boost/archive/binary_oarchive.hpp>
+#include <boost/archive/xml_iarchive.hpp>
+#include <boost/archive/xml_oarchive.hpp>
+#include <boost/property_tree/ptree_serialization.hpp>
+
+// Predicate for sorting keys
+template<class Ptree>
+struct SortPred
+{
+ bool operator()(const typename Ptree::value_type &v1,
+ const typename Ptree::value_type &v2) const
+ {
+ return v1.first < v2.first;
+ }
+};
+
+// Predicate for sorting keys in reverse
+template<class Ptree>
+struct SortPredRev
+{
+ bool operator()(const typename Ptree::value_type &v1,
+ const typename Ptree::value_type &v2) const
+ {
+ return v1.first > v2.first;
+ }
+};
+
+// Custom translator that works with boost::any instead of std::string
+template <typename E>
+struct any_translator
+{
+ typedef boost::any internal_type;
+ typedef E external_type;
+
+ boost::optional<E> get_value(const internal_type &v) {
+ if(const E *p = boost::any_cast<E>(&v)) {
+ return *p;
+ }
+ return boost::optional<E>();
+ }
+ boost::optional<internal_type> put_value(const E &v) {
+ return boost::any(v);
+ }
+};
+
+namespace boost { namespace property_tree {
+ template <typename E>
+ struct translator_between<boost::any, E>
+ {
+ typedef any_translator<E> type;
+ };
+}}
+
+// Include char tests, case sensitive
+#define CHTYPE char
+#define T(s) s
+#define PTREE boost::property_tree::ptree
+#define NOCASE 0
+#define WIDECHAR 0
+# include "test_property_tree.hpp"
+#undef CHTYPE
+#undef T
+#undef PTREE
+#undef NOCASE
+#undef WIDECHAR
+
+// Include wchar_t tests, case sensitive
+#ifndef BOOST_NO_CWCHAR
+# define CHTYPE wchar_t
+# define T(s) L ## s
+# define PTREE boost::property_tree::wptree
+# define NOCASE 0
+# define WIDECHAR 1
+# include "test_property_tree.hpp"
+# undef CHTYPE
+# undef T
+# undef PTREE
+# undef NOCASE
+# undef WIDECHAR
+#endif
+
+// Include char tests, case insensitive
+#define CHTYPE char
+#define T(s) s
+#define PTREE boost::property_tree::iptree
+#define NOCASE 1
+# define WIDECHAR 0
+# include "test_property_tree.hpp"
+#undef CHTYPE
+#undef T
+#undef PTREE
+#undef NOCASE
+#undef WIDECHAR
+
+// Include wchar_t tests, case insensitive
+#ifndef BOOST_NO_CWCHAR
+# define CHTYPE wchar_t
+# define T(s) L ## s
+# define PTREE boost::property_tree::wiptree
+# define NOCASE 1
+# define WIDECHAR 1
+# include "test_property_tree.hpp"
+# undef CHTYPE
+# undef T
+# undef PTREE
+# undef NOCASE
+# undef WIDECHAR
+#endif
+
+template <typename Ptree>
+void run_tests(Ptree* pt)
+{
+ test_debug(pt);
+ test_constructor_destructor_assignment(pt);
+ test_insertion(pt);
+ test_erasing(pt);
+ test_clear(pt);
+ test_pushpop(pt);
+ test_container_iteration(pt);
+ test_swap(pt);
+ test_sort_reverse(pt);
+ test_case(pt);
+ test_comparison(pt);
+ test_front_back(pt);
+ test_get_put(pt);
+ test_get_child_put_child(pt);
+ test_equal_range(pt);
+ test_path_separator(pt);
+ test_path(pt);
+ test_precision(pt);
+ test_locale(pt);
+ test_custom_data_type(pt);
+ test_empty_size_max_size(pt);
+ test_ptree_bad_path(pt);
+ test_ptree_bad_data(pt);
+ test_serialization(pt);
+ test_bool(pt);
+ test_char(pt);
+ test_float(pt);
+ test_sort(pt);
+ test_leaks(pt); // must be a final test
+}
+
+int test_main(int, char *[])
+{
+
+ using namespace boost::property_tree;
+
+ // char tests, case sensitive
+ {
+ ptree *pt = 0;
+ run_tests(pt);
+ }
+
+ // wchar_t tests, case sensitive
+#ifndef BOOST_NO_CWCHAR
+ {
+ wptree *pt = 0;
+ run_tests(pt);
+ }
+#endif
+
+ // char tests, case insensitive
+ {
+ iptree *pt = 0;
+ run_tests(pt);
+ }
+
+ // wchar_t tests, case insensitive
+#ifndef BOOST_NO_CWCHAR
+ {
+ wiptree *pt = 0;
+ run_tests(pt);
+ }
+#endif
+
+ return 0;
+}
diff --git a/src/boost/libs/property_tree/test/test_property_tree.hpp b/src/boost/libs/property_tree/test/test_property_tree.hpp
new file mode 100644
index 000000000..4216945a1
--- /dev/null
+++ b/src/boost/libs/property_tree/test/test_property_tree.hpp
@@ -0,0 +1,1355 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+
+// Intentionally no include guards (to be included more than once)
+
+#if !defined(CHTYPE) || !defined(T) || !defined(PTREE) || !defined(NOCASE) || !defined(WIDECHAR)
+# error No character type specified
+#endif
+
+void test_debug(PTREE *)
+{
+#if 0
+ // Check count
+ BOOST_CHECK(PTREE::debug_get_instances_count() == 0);
+
+ {
+
+ // Create ptrees
+ PTREE pt1, pt2;
+ BOOST_CHECK(PTREE::debug_get_instances_count() == 2);
+
+ // Create PTREE
+ PTREE *pt3 = new PTREE;
+ BOOST_CHECK(PTREE::debug_get_instances_count() == 3);
+
+ // Insert
+ pt1.push_back(std::make_pair(T("key"), *pt3));
+ BOOST_CHECK(PTREE::debug_get_instances_count() == 4);
+
+ // Insert
+ pt2.push_back(std::make_pair(T("key"), *pt3));
+ BOOST_CHECK(PTREE::debug_get_instances_count() == 5);
+
+ // Clear
+ pt1.clear();
+ BOOST_CHECK(PTREE::debug_get_instances_count() == 4);
+
+ // Clear
+ pt2.clear();
+ BOOST_CHECK(PTREE::debug_get_instances_count() == 3);
+
+ // Delete
+ delete pt3;
+ BOOST_CHECK(PTREE::debug_get_instances_count() == 2);
+
+ }
+
+ // Check count
+ BOOST_CHECK(PTREE::debug_get_instances_count() == 0);
+#endif
+}
+
+void test_constructor_destructor_assignment(PTREE *)
+{
+
+ {
+
+ // Test constructor from string
+ PTREE pt1(T("data"));
+ BOOST_CHECK(pt1.data() == T("data"));
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 1);
+
+ // Do insertions
+ PTREE &tmp1 = pt1.put(T("key1"), T("data1"));
+ PTREE &tmp2 = pt1.put(T("key2"), T("data2"));
+ tmp1.put(T("key3"), T("data3"));
+ tmp2.put(T("key4"), T("data4"));
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 5);
+
+ // Make a copy using copy constructor
+ PTREE *pt2 = new PTREE(pt1);
+ BOOST_CHECK(*pt2 == pt1);
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 10);
+
+ // Make a copy using = operator
+ PTREE *pt3 = new PTREE;
+ *pt3 = *pt2;
+ BOOST_CHECK(*pt3 == *pt2);
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 15);
+
+ // Test self assignment
+ pt1 = pt1;
+ BOOST_CHECK(pt1 == *pt2);
+ BOOST_CHECK(pt1 == *pt3);
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 15);
+
+ // Destroy
+ delete pt2;
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 10);
+
+ // Destroy
+ delete pt3;
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 5);
+
+ }
+
+ // Check count
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 0);
+
+}
+
+void test_insertion(PTREE *)
+{
+
+ // Do insertions
+ PTREE pt;
+ PTREE tmp1(T("data1"));
+ PTREE tmp2(T("data2"));
+ PTREE tmp3(T("data3"));
+ PTREE tmp4(T("data4"));
+ PTREE::iterator it1 = pt.insert(pt.end(), std::make_pair(T("key1"), tmp1));
+ PTREE::iterator it2 = pt.insert(it1, std::make_pair(T("key2"), tmp2));
+ PTREE::iterator it3 = it1->second.push_back(std::make_pair(T("key3"), tmp3));
+ PTREE::iterator it4 = it1->second.push_front(std::make_pair(T("key4"), tmp4));
+ it2->second.insert(it2->second.end(), it1->second.begin(), it1->second.end());
+
+ // Check instance count
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 11);
+
+ // Check contents
+ BOOST_CHECK(pt.get(T("key1"), T("")) == T("data1"));
+ BOOST_CHECK(pt.get(T("key2"), T("")) == T("data2"));
+ BOOST_CHECK(pt.get(T("key1.key3"), T("")) == T("data3"));
+ BOOST_CHECK(pt.get(T("key1.key4"), T("")) == T("data4"));
+ BOOST_CHECK(pt.get(T("key2.key3"), T("")) == T("data3"));
+ BOOST_CHECK(pt.get(T("key2.key4"), T("")) == T("data4"));
+
+ // Check sequence
+ PTREE::iterator it = it2;
+ ++it; BOOST_CHECK(it == it1);
+ ++it; BOOST_CHECK(it == pt.end());
+ it = it4;
+ ++it; BOOST_CHECK(it == it3);
+ ++it; BOOST_CHECK(it == it1->second.end());
+
+}
+
+void test_erasing(PTREE *)
+{
+
+ // Do insertions
+ PTREE pt;
+ PTREE tmp1(T("data1"));
+ PTREE tmp2(T("data2"));
+ PTREE tmp3(T("data3"));
+ PTREE tmp4(T("data4"));
+ PTREE::iterator it1 = pt.insert(pt.end(), std::make_pair(T("key1"), tmp1));
+ PTREE::iterator it2 = pt.insert(it1, std::make_pair(T("key2"), tmp2));
+ it1->second.push_back(std::make_pair(T("key"), tmp3));
+ it1->second.push_front(std::make_pair(T("key"), tmp4));
+ it2->second.insert(it2->second.end(), it1->second.begin(), it1->second.end());
+
+ // Check instance count
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 11);
+
+ // Test range erase
+ PTREE::iterator it = it1->second.erase(it1->second.begin(), it1->second.end());
+ BOOST_CHECK(it == it1->second.end());
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 9);
+
+ // Test single erase
+ PTREE::size_type n = pt.erase(T("key1"));
+ BOOST_CHECK(n == 1);
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 8);
+
+ // Test multiple erase
+ n = it2->second.erase(T("key"));
+ BOOST_CHECK(n == 2);
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 6);
+
+ // Test one more erase
+ n = pt.erase(T("key2"));
+ BOOST_CHECK(n == 1);
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 5);
+
+}
+
+void test_clear(PTREE *)
+{
+
+ // Do insertions
+ PTREE pt(T("data"));
+ pt.push_back(std::make_pair(T("key"), PTREE(T("data"))));
+
+ // Check instance count
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 2);
+
+ // Test clear
+ pt.clear();
+ BOOST_CHECK(pt.empty());
+ BOOST_CHECK(pt.data().empty());
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 1);
+
+}
+
+void test_pushpop(PTREE *)
+{
+
+ // Do insertions
+ PTREE pt;
+ PTREE tmp1(T("data1"));
+ PTREE tmp2(T("data2"));
+ PTREE tmp3(T("data3"));
+ PTREE tmp4(T("data4"));
+ pt.push_back(std::make_pair(T("key3"), tmp3));
+ pt.push_front(std::make_pair(T("key2"), tmp2));
+ pt.push_back(std::make_pair(T("key4"), tmp4));
+ pt.push_front(std::make_pair(T("key1"), tmp1));
+
+ // Check instance count
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 9);
+
+ // Check sequence
+ PTREE::iterator it = pt.begin();
+ BOOST_CHECK(it->first == T("key1")); ++it;
+ BOOST_CHECK(it->first == T("key2")); ++it;
+ BOOST_CHECK(it->first == T("key3")); ++it;
+ BOOST_CHECK(it->first == T("key4")); ++it;
+ BOOST_CHECK(it == pt.end());
+
+ // Test pops
+ pt.pop_back();
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 8);
+ BOOST_CHECK(pt.front().second.data() == T("data1"));
+ BOOST_CHECK(pt.back().second.data() == T("data3"));
+ pt.pop_front();
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 7);
+ BOOST_CHECK(pt.front().second.data() == T("data2"));
+ BOOST_CHECK(pt.back().second.data() == T("data3"));
+ pt.pop_back();
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 6);
+ BOOST_CHECK(pt.front().second.data() == T("data2"));
+ BOOST_CHECK(pt.back().second.data() == T("data2"));
+ pt.pop_front();
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 5);
+ BOOST_CHECK(pt.empty());
+
+}
+
+void test_container_iteration(PTREE *)
+{
+
+ // Do insertions
+ PTREE pt;
+ pt.put(T("key3"), T(""));
+ pt.put(T("key1"), T(""));
+ pt.put(T("key4"), T(""));
+ pt.put(T("key2"), T(""));
+
+ // iterator
+ {
+ PTREE::iterator it = pt.begin();
+ BOOST_CHECK(it->first == T("key3")); ++it;
+ BOOST_CHECK(it->first == T("key1")); ++it;
+ BOOST_CHECK(it->first == T("key4")); ++it;
+ BOOST_CHECK(it->first == T("key2")); ++it;
+ BOOST_CHECK(it == pt.end());
+ }
+
+ // const_iterator
+ {
+ PTREE::const_iterator it = pt.begin();
+ BOOST_CHECK(it->first == T("key3")); ++it;
+ BOOST_CHECK(it->first == T("key1")); ++it;
+ BOOST_CHECK(it->first == T("key4")); ++it;
+ BOOST_CHECK(it->first == T("key2")); ++it;
+ BOOST_CHECK(it == pt.end());
+ }
+
+ // reverse_iterator
+ {
+ PTREE::reverse_iterator it = pt.rbegin();
+ BOOST_CHECK(it->first == T("key2")); ++it;
+ BOOST_CHECK(it->first == T("key4")); ++it;
+ BOOST_CHECK(it->first == T("key1")); ++it;
+ BOOST_CHECK(it->first == T("key3")); ++it;
+ BOOST_CHECK(it == pt.rend());
+ }
+
+ // const_reverse_iterator
+ {
+ PTREE::const_reverse_iterator it = pt.rbegin();
+ BOOST_CHECK(it->first == T("key2")); ++it;
+ BOOST_CHECK(it->first == T("key4")); ++it;
+ BOOST_CHECK(it->first == T("key1")); ++it;
+ BOOST_CHECK(it->first == T("key3")); ++it;
+ BOOST_CHECK(it == PTREE::const_reverse_iterator(pt.rend()));
+ }
+
+}
+
+void test_swap(PTREE *)
+{
+
+ PTREE pt1, pt2;
+
+ // Do insertions
+ pt1.put(T("key1"), T(""));
+ pt1.put(T("key2"), T(""));
+ pt1.put(T("key1.key3"), T(""));
+ pt1.put(T("key1.key4"), T(""));
+
+ // Check counts
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 6);
+ BOOST_CHECK(pt1.size() == 2);
+ BOOST_CHECK(pt1.get_child(T("key1")).size() == 2);
+ BOOST_CHECK(pt2.size() == 0);
+
+ // Swap using member function
+ pt1.swap(pt2);
+
+ // Check counts
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 6);
+ BOOST_CHECK(pt2.size() == 2);
+ BOOST_CHECK(pt2.get_child(T("key1")).size() == 2);
+ BOOST_CHECK(pt1.size() == 0);
+
+ // Swap using free function
+ swap(pt1, pt2);
+
+ // Check counts
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 6);
+ BOOST_CHECK(pt1.size() == 2);
+ BOOST_CHECK(pt1.get_child(T("key1")).size() == 2);
+ BOOST_CHECK(pt2.size() == 0);
+
+ // Swap using std algorithm
+ std::swap(pt1, pt2);
+
+ // Check counts
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 6);
+ BOOST_CHECK(pt2.size() == 2);
+ BOOST_CHECK(pt2.get_child(T("key1")).size() == 2);
+ BOOST_CHECK(pt1.size() == 0);
+
+}
+
+void test_sort_reverse(PTREE *)
+{
+
+ PTREE pt;
+
+ // Do insertions
+ pt.put(T("key2"), T("data2"));
+ pt.put(T("key1"), T("data1"));
+ pt.put(T("key4"), T("data4"));
+ pt.put(T("key3"), T("data3"));
+ pt.put(T("key3.key1"), T(""));
+ pt.put(T("key4.key2"), T(""));
+
+ // Reverse
+ pt.reverse();
+
+ // Check sequence
+ {
+ PTREE::iterator it = pt.begin();
+ BOOST_CHECK(it->first == T("key3")); ++it;
+ BOOST_CHECK(it->first == T("key4")); ++it;
+ BOOST_CHECK(it->first == T("key1")); ++it;
+ BOOST_CHECK(it->first == T("key2")); ++it;
+ BOOST_CHECK(it == pt.end());
+ }
+ // Check sequence using find to check if index is ok
+ {
+ PTREE::iterator it = pt.begin();
+ BOOST_CHECK(it == pt.to_iterator(pt.find(T("key3")))); ++it;
+ BOOST_CHECK(it == pt.to_iterator(pt.find(T("key4")))); ++it;
+ BOOST_CHECK(it == pt.to_iterator(pt.find(T("key1")))); ++it;
+ BOOST_CHECK(it == pt.to_iterator(pt.find(T("key2")))); ++it;
+ BOOST_CHECK(it == pt.end());
+ }
+
+ // Sort
+ pt.sort(SortPred<PTREE>());
+
+ // Check sequence
+ {
+ PTREE::iterator it = pt.begin();
+ BOOST_CHECK(it->first == T("key1")); ++it;
+ BOOST_CHECK(it->first == T("key2")); ++it;
+ BOOST_CHECK(it->first == T("key3")); ++it;
+ BOOST_CHECK(it->first == T("key4")); ++it;
+ BOOST_CHECK(it == pt.end());
+ }
+ // Check sequence (using find to check if index is ok)
+ {
+ PTREE::iterator it = pt.begin();
+ BOOST_CHECK(it == pt.to_iterator(pt.find(T("key1")))); ++it;
+ BOOST_CHECK(it == pt.to_iterator(pt.find(T("key2")))); ++it;
+ BOOST_CHECK(it == pt.to_iterator(pt.find(T("key3")))); ++it;
+ BOOST_CHECK(it == pt.to_iterator(pt.find(T("key4")))); ++it;
+ BOOST_CHECK(it == pt.end());
+ }
+
+ // Sort reverse
+ pt.sort(SortPredRev<PTREE>());
+
+ // Check sequence
+ {
+ PTREE::iterator it = pt.begin();
+ BOOST_CHECK(it->first == T("key4")); ++it;
+ BOOST_CHECK(it->first == T("key3")); ++it;
+ BOOST_CHECK(it->first == T("key2")); ++it;
+ BOOST_CHECK(it->first == T("key1")); ++it;
+ BOOST_CHECK(it == pt.end());
+ }
+ // Check sequence (using find to check if index is ok)
+ {
+ PTREE::iterator it = pt.begin();
+ BOOST_CHECK(it == pt.to_iterator(pt.find(T("key4")))); ++it;
+ BOOST_CHECK(it == pt.to_iterator(pt.find(T("key3")))); ++it;
+ BOOST_CHECK(it == pt.to_iterator(pt.find(T("key2")))); ++it;
+ BOOST_CHECK(it == pt.to_iterator(pt.find(T("key1")))); ++it;
+ BOOST_CHECK(it == pt.end());
+ }
+
+}
+
+void test_case(PTREE *)
+{
+
+ // Do insertions
+ PTREE pt;
+ pt.put(T("key1"), T("data1"));
+ pt.put(T("KEY2"), T("data2"));
+ pt.put(T("kEy1.keY3"), T("data3"));
+ pt.put(T("KEY1.key4"), T("data4"));
+
+ // Check findings depending on traits type
+#if (NOCASE == 0)
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 7);
+ BOOST_CHECK(pt.get(T("key1"), T("")) == T("data1"));
+ BOOST_CHECK(pt.get(T("key2"), T("")) == T(""));
+ BOOST_CHECK(pt.get(T("key1.key3"), T("")) == T(""));
+ BOOST_CHECK(pt.get(T("KEY1.key4"), T("")) == T("data4"));
+#else
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 5);
+ BOOST_CHECK(pt.get(T("key1"), T("1")) == pt.get(T("KEY1"), T("2")));
+ BOOST_CHECK(pt.get(T("key2"), T("1")) == pt.get(T("KEY2"), T("2")));
+ BOOST_CHECK(pt.get(T("key1.key3"), T("1")) == pt.get(T("KEY1.KEY3"), T("2")));
+ BOOST_CHECK(pt.get(T("key1.key4"), T("1")) == pt.get(T("KEY1.KEY4"), T("2")));
+#endif
+
+ // Do more insertions
+ pt.push_back(PTREE::value_type(T("key1"), PTREE()));
+ pt.push_back(PTREE::value_type(T("key1"), PTREE()));
+
+ // Test counts
+#if (NOCASE == 0)
+ BOOST_CHECK(pt.count(T("key1")) == 3);
+ BOOST_CHECK(pt.count(T("KEY1")) == 1);
+ BOOST_CHECK(pt.count(T("key2")) == 0);
+ BOOST_CHECK(pt.count(T("KEY2")) == 1);
+ BOOST_CHECK(pt.count(T("key3")) == 0);
+ BOOST_CHECK(pt.count(T("KEY3")) == 0);
+#else
+ BOOST_CHECK(pt.count(T("key1")) == 3);
+ BOOST_CHECK(pt.count(T("KEY1")) == 3);
+ BOOST_CHECK(pt.count(T("key2")) == 1);
+ BOOST_CHECK(pt.count(T("KEY2")) == 1);
+ BOOST_CHECK(pt.count(T("key3")) == 0);
+ BOOST_CHECK(pt.count(T("KEY3")) == 0);
+#endif
+
+}
+
+void test_comparison(PTREE *)
+{
+
+ // Prepare original
+ PTREE pt_orig(T("data"));
+ pt_orig.put(T("key1"), T("data1"));
+ pt_orig.put(T("key1.key3"), T("data2"));
+ pt_orig.put(T("key1.key4"), T("data3"));
+ pt_orig.put(T("key2"), T("data4"));
+
+ // Test originals
+ {
+ PTREE pt1(pt_orig);
+ PTREE pt2(pt_orig);
+ BOOST_CHECK(pt1 == pt2);
+ BOOST_CHECK(pt2 == pt1);
+ BOOST_CHECK(!(pt1 != pt2));
+ BOOST_CHECK(!(pt2 != pt1));
+ }
+
+ // Test originals with modified case
+#if (NOCASE != 0)
+ {
+ PTREE pt1(pt_orig);
+ PTREE pt2(pt_orig);
+ pt1.pop_back();
+ pt1.put(T("KEY2"), T("data4"));
+ BOOST_CHECK(pt1 == pt2);
+ BOOST_CHECK(pt2 == pt1);
+ BOOST_CHECK(!(pt1 != pt2));
+ BOOST_CHECK(!(pt2 != pt1));
+ }
+#endif
+
+ // Test modified copies (both modified the same way)
+ {
+ PTREE pt1(pt_orig);
+ PTREE pt2(pt_orig);
+ pt1.put(T("key1.key5"), T("."));
+ pt2.put(T("key1.key5"), T("."));
+ BOOST_CHECK(pt1 == pt2);
+ BOOST_CHECK(pt2 == pt1);
+ BOOST_CHECK(!(pt1 != pt2));
+ BOOST_CHECK(!(pt2 != pt1));
+ }
+
+ // Test modified copies (modified root data)
+ {
+ PTREE pt1(pt_orig);
+ PTREE pt2(pt_orig);
+ pt1.data() = T("a");
+ pt2.data() = T("b");
+ BOOST_CHECK(!(pt1 == pt2));
+ BOOST_CHECK(!(pt2 == pt1));
+ BOOST_CHECK(pt1 != pt2);
+ BOOST_CHECK(pt2 != pt1);
+ }
+
+ // Test modified copies (added subkeys with different data)
+ {
+ PTREE pt1(pt_orig);
+ PTREE pt2(pt_orig);
+ pt1.put(T("key1.key5"), T("a"));
+ pt2.put(T("key1.key5"), T("b"));
+ BOOST_CHECK(!(pt1 == pt2));
+ BOOST_CHECK(!(pt2 == pt1));
+ BOOST_CHECK(pt1 != pt2);
+ BOOST_CHECK(pt2 != pt1);
+ }
+
+ // Test modified copies (added subkeys with different keys)
+ {
+ PTREE pt1(pt_orig);
+ PTREE pt2(pt_orig);
+ pt1.put(T("key1.key5"), T(""));
+ pt2.put(T("key1.key6"), T(""));
+ BOOST_CHECK(!(pt1 == pt2));
+ BOOST_CHECK(!(pt2 == pt1));
+ BOOST_CHECK(pt1 != pt2);
+ BOOST_CHECK(pt2 != pt1);
+ }
+
+ // Test modified copies (added subkey to only one copy)
+ {
+ PTREE pt1(pt_orig);
+ PTREE pt2(pt_orig);
+ pt1.put(T("key1.key5"), T(""));
+ BOOST_CHECK(!(pt1 == pt2));
+ BOOST_CHECK(!(pt2 == pt1));
+ BOOST_CHECK(pt1 != pt2);
+ BOOST_CHECK(pt2 != pt1);
+ }
+
+}
+
+void test_front_back(PTREE *)
+{
+
+ // Do insertions
+ PTREE pt;
+ pt.put(T("key1"), T(""));
+ pt.put(T("key2"), T(""));
+
+ // Check front and back
+ BOOST_CHECK(pt.front().first == T("key1"));
+ BOOST_CHECK(pt.back().first == T("key2"));
+
+}
+
+void test_get_put(PTREE *)
+{
+
+ typedef std::basic_string<CHTYPE> str_t;
+
+ // Temporary storage
+ str_t tmp_string;
+ boost::optional<int> opt_int;
+ boost::optional<long> opt_long;
+ boost::optional<double> opt_double;
+ boost::optional<float> opt_float;
+ boost::optional<str_t> opt_string;
+ boost::optional<CHTYPE> opt_char;
+ boost::optional<bool> opt_bool;
+
+ // Do insertions via put
+ PTREE pt;
+ PTREE &pt1 = pt.put(T("k1"), 1);
+ PTREE &pt2 = pt.put(T("k2.k"), 2.5);
+ PTREE &pt3 = pt.put(T("k3.k.k"), T("ala ma kota"));
+ PTREE &pt4 = pt.put(T("k4.k.k.k"), CHTYPE('c'));
+ PTREE &pt5 = pt.put(T("k5.k.k.k.f"), false);
+ PTREE &pt6 = pt.put(T("k5.k.k.k.t"), true);
+
+ // Check instances count
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 17);
+
+ // Check if const char * version returns std::string
+ BOOST_CHECK(typeid(pt.get_value(T(""))) == typeid(str_t));
+
+ // Do extractions via get (throwing version)
+ BOOST_CHECK(pt.get<int>(T("k1")) == 1);
+ BOOST_CHECK(pt.get<long>(T("k1")) == 1);
+ BOOST_CHECK(pt.get<double>(T("k2.k")) == 2.5);
+ BOOST_CHECK(pt.get<float>(T("k2.k")) == 2.5f);
+ BOOST_CHECK(pt.get<str_t>(T("k3.k.k")) == str_t(T("ala ma kota")));
+ BOOST_CHECK(pt.get<CHTYPE>(T("k4.k.k.k")) == CHTYPE('c'));
+ BOOST_CHECK(pt.get<bool>(T("k5.k.k.k.f")) == false);
+ BOOST_CHECK(pt.get<bool>(T("k5.k.k.k.t")) == true);
+
+ // Do extractions via get (default value version)
+ BOOST_CHECK(pt.get(T("k1"), 0) == 1);
+ BOOST_CHECK(pt.get(T("k1"), 0L) == 1);
+ BOOST_CHECK(pt.get(T("k2.k"), 0.0) == 2.5);
+ BOOST_CHECK(pt.get(T("k2.k"), 0.0f) == 2.5f);
+ BOOST_CHECK(pt.get(T("k3.k.k"), str_t()) == str_t(T("ala ma kota")));
+ BOOST_CHECK(pt.get(T("k3.k.k"), T("")) == T("ala ma kota"));
+ BOOST_CHECK(pt.get(T("k4.k.k.k"), CHTYPE('\0')) == CHTYPE('c'));
+ BOOST_CHECK(pt.get(T("k5.k.k.k.f"), true) == false);
+ BOOST_CHECK(pt.get(T("k5.k.k.k.t"), false) == true);
+
+ // Do extractions via get (optional version)
+ opt_int = pt.get_optional<int>(T("k1"));
+ BOOST_CHECK(opt_int && *opt_int == 1);
+ opt_long = pt.get_optional<long>(T("k1"));
+ BOOST_CHECK(opt_long && *opt_long == 1);
+ opt_double = pt.get_optional<double>(T("k2.k"));
+ BOOST_CHECK(opt_double && *opt_double == 2.5);
+ opt_float = pt.get_optional<float>(T("k2.k"));
+ BOOST_CHECK(opt_float && *opt_float == 2.5f);
+ opt_string = pt.get_optional<str_t>(T("k3.k.k"));
+ BOOST_CHECK(opt_string && *opt_string == str_t(T("ala ma kota")));
+ opt_char = pt.get_optional<CHTYPE>(T("k4.k.k.k"));
+ BOOST_CHECK(opt_char && *opt_char == CHTYPE('c'));
+ opt_bool = pt.get_optional<bool>(T("k5.k.k.k.f"));
+ BOOST_CHECK(opt_bool && *opt_bool == false);
+ opt_bool = pt.get_optional<bool>(T("k5.k.k.k.t"));
+ BOOST_CHECK(opt_bool && *opt_bool == true);
+
+ // Do insertions via put_value
+ pt1.put_value(short(1));
+ pt2.put_value(2.5f);
+ pt3.put_value(str_t(T("ala ma kota")));
+ pt4.put_value(CHTYPE('c'));
+ pt5.put_value(false);
+ pt6.put_value(true);
+
+ // Do extractions via get_value (throwing version)
+ BOOST_CHECK(pt1.get_value<int>() == 1);
+ BOOST_CHECK(pt1.get_value<long>() == 1);
+ BOOST_CHECK(pt2.get_value<double>() == 2.5);
+ BOOST_CHECK(pt2.get_value<float>() == 2.5f);
+ BOOST_CHECK(pt3.get_value<str_t>() == str_t(T("ala ma kota")));
+ BOOST_CHECK(pt4.get_value<CHTYPE>() == CHTYPE('c'));
+ BOOST_CHECK(pt5.get_value<bool>() == false);
+ BOOST_CHECK(pt6.get_value<bool>() == true);
+
+ // Do extractions via get_value (default value version)
+ BOOST_CHECK(pt1.get_value(0) == 1);
+ BOOST_CHECK(pt1.get_value(0L) == 1);
+ BOOST_CHECK(pt2.get_value(0.0) == 2.5);
+ BOOST_CHECK(pt2.get_value(0.0f) == 2.5f);
+ BOOST_CHECK(pt3.get_value(str_t()) == str_t(T("ala ma kota")));
+ BOOST_CHECK(pt3.get_value(T("")) == T("ala ma kota"));
+ BOOST_CHECK(pt4.get_value(CHTYPE('\0')) == CHTYPE('c'));
+ BOOST_CHECK(pt5.get_value(true) == false);
+ BOOST_CHECK(pt6.get_value(false) == true);
+
+ // Do extractions via get_value (optional version)
+ opt_int = pt1.get_value_optional<int>();
+ BOOST_CHECK(opt_int && *opt_int == 1);
+ opt_long = pt1.get_value_optional<long>();
+ BOOST_CHECK(opt_long && *opt_long == 1);
+ opt_double = pt2.get_value_optional<double>();
+ BOOST_CHECK(opt_double && *opt_double == 2.5);
+ opt_float = pt2.get_value_optional<float>();
+ BOOST_CHECK(opt_float && *opt_float == 2.5f);
+ opt_string = pt3.get_value_optional<str_t>();
+ BOOST_CHECK(opt_string && *opt_string == str_t(T("ala ma kota")));
+ opt_char = pt4.get_value_optional<CHTYPE>();
+ BOOST_CHECK(opt_char && *opt_char == CHTYPE('c'));
+ opt_bool = pt5.get_value_optional<bool>();
+ BOOST_CHECK(opt_bool && *opt_bool == false);
+ opt_bool = pt6.get_value_optional<bool>();
+ BOOST_CHECK(opt_bool && *opt_bool == true);
+
+ // Do incorrect extractions (throwing version)
+ try
+ {
+ pt.get<int>(T("k2.k.bogus.path"));
+ BOOST_ERROR("No required exception thrown");
+ }
+ catch (boost::property_tree::ptree_bad_path &) { }
+ catch (...)
+ {
+ BOOST_ERROR("Wrong exception type thrown");
+ }
+ try
+ {
+ pt.get<int>(T("k2.k"));
+ BOOST_ERROR("No required exception thrown");
+ }
+ catch (boost::property_tree::ptree_bad_data &) { }
+ catch (...)
+ {
+ BOOST_ERROR("Wrong exception type thrown");
+ }
+
+ // Do incorrect extractions (default value version)
+ BOOST_CHECK(pt.get(T("k2.k"), -7) == -7);
+ BOOST_CHECK(pt.get(T("k3.k.k"), -7) == -7);
+ BOOST_CHECK(pt.get(T("k4.k.k.k"), -7) == -7);
+
+ // Do incorrect extractions (optional version)
+ BOOST_CHECK(!pt.get_optional<int>(T("k2.k")));
+ BOOST_CHECK(!pt.get_optional<int>(T("k3.k.k")));
+ BOOST_CHECK(!pt.get_optional<int>(T("k4.k.k.k")));
+
+ // Test multiple puts with the same key
+ {
+ PTREE pt;
+ pt.put(T("key"), 1);
+ BOOST_CHECK(pt.get<int>(T("key")) == 1);
+ BOOST_CHECK(pt.size() == 1);
+ pt.put(T("key"), 2);
+ BOOST_CHECK(pt.get<int>(T("key")) == 2);
+ BOOST_CHECK(pt.size() == 1);
+ pt.put(T("key.key.key"), 1);
+ PTREE &child = pt.get_child(T("key.key"));
+ BOOST_CHECK(pt.get<int>(T("key.key.key")) == 1);
+ BOOST_CHECK(child.size() == 1);
+ BOOST_CHECK(child.count(T("key")) == 1);
+ pt.put(T("key.key.key"), 2);
+ BOOST_CHECK(pt.get<int>(T("key.key.key")) == 2);
+ BOOST_CHECK(child.size() == 1);
+ BOOST_CHECK(child.count(T("key")) == 1);
+ }
+
+ // Test multiple puts with the same key
+ {
+ PTREE pt;
+ pt.put(T("key"), 1);
+ BOOST_CHECK(pt.get<int>(T("key")) == 1);
+ BOOST_CHECK(pt.size() == 1);
+ pt.put(T("key"), 2);
+ BOOST_CHECK(pt.get<int>(T("key")) == 2);
+ BOOST_CHECK(pt.size() == 1);
+ pt.put(T("key.key.key"), 1);
+ PTREE &child = pt.get_child(T("key.key"));
+ BOOST_CHECK(child.size() == 1);
+ BOOST_CHECK(child.count(T("key")) == 1);
+ pt.add(T("key.key.key"), 2);
+ BOOST_CHECK(child.size() == 2);
+ BOOST_CHECK(child.count(T("key")) == 2);
+ }
+
+ // Test that put does not destroy children
+ {
+ PTREE pt;
+ pt.put(T("key1"), 1);
+ pt.put(T("key1.key2"), 2);
+ BOOST_CHECK(pt.get<int>(T("key1"), 0) == 1);
+ BOOST_CHECK(pt.get<int>(T("key1.key2"), 0) == 2);
+ pt.put(T("key1"), 2);
+ BOOST_CHECK(pt.get<int>(T("key1"), 0) == 2);
+ BOOST_CHECK(pt.get<int>(T("key1.key2"), 0) == 2);
+ }
+
+ // Test that get of single character that is whitespace works
+ {
+ PTREE pt;
+ pt.put_value(T(' '));
+ CHTYPE ch = pt.get_value<CHTYPE>();
+ BOOST_CHECK(ch == T(' '));
+ }
+
+ // Test that get of non-char value with trailing and leading whitespace works
+ {
+ PTREE pt;
+ pt.put_value(T(" \t\n99 \t\n"));
+ BOOST_CHECK(pt.get_value<int>(0) == 99);
+ }
+
+}
+
+void test_get_child_put_child(PTREE *)
+{
+ PTREE pt(T("ala ma kota"));
+
+ // Do insertions via put_child
+ PTREE pt1, pt2, pt3;
+ pt1.put_child(T("k1"), PTREE());
+ pt1.put_child(T("k2.k"), PTREE());
+ pt2.put_child(T("k1"), pt);
+ pt2.put_child(T("k2.k"), pt);
+
+ // Const references to test const versions of methods
+ const PTREE &cpt1 = pt1, &cpt2 = pt2;
+
+ // Do correct extractions via get_child (throwing version)
+ BOOST_CHECK(pt1.get_child(T("k1")).empty());
+ BOOST_CHECK(pt1.get_child(T("k2.k")).empty());
+ BOOST_CHECK(pt2.get_child(T("k1")) == pt);
+ BOOST_CHECK(pt2.get_child(T("k2.k")) == pt);
+ BOOST_CHECK(cpt1.get_child(T("k1")).empty());
+ BOOST_CHECK(cpt1.get_child(T("k2.k")).empty());
+ BOOST_CHECK(cpt2.get_child(T("k1")) == pt);
+ BOOST_CHECK(cpt2.get_child(T("k2.k")) == pt);
+
+ // Do correct extractions via get_child (default value version)
+ BOOST_CHECK(pt1.get_child(T("k1"), PTREE(T("def"))) != PTREE(T("def")));
+ BOOST_CHECK(pt1.get_child(T("k2.k"), PTREE(T("def"))) != PTREE(T("def")));
+ BOOST_CHECK(pt2.get_child(T("k1"), PTREE(T("def"))) == pt);
+ BOOST_CHECK(pt2.get_child(T("k2.k"), PTREE(T("def"))) == pt);
+ BOOST_CHECK(cpt1.get_child(T("k1"), PTREE(T("def"))) != PTREE(T("def")));
+ BOOST_CHECK(cpt1.get_child(T("k2.k"), PTREE(T("def"))) != PTREE(T("def")));
+ BOOST_CHECK(cpt2.get_child(T("k1"), PTREE(T("def"))) == pt);
+ BOOST_CHECK(cpt2.get_child(T("k2.k"), PTREE(T("def"))) == pt);
+
+ // Do correct extractions via get_child (optional version)
+ boost::optional<PTREE &> opt;
+ boost::optional<const PTREE &> copt;
+ opt = pt1.get_child_optional(T("k1"));
+ BOOST_CHECK(opt);
+ opt = pt1.get_child_optional(T("k2.k"));
+ BOOST_CHECK(opt);
+ opt = pt2.get_child_optional(T("k1"));
+ BOOST_CHECK(opt && *opt == pt);
+ opt = pt2.get_child_optional(T("k2.k"));
+ BOOST_CHECK(opt && *opt == pt);
+ copt = cpt1.get_child_optional(T("k1"));
+ BOOST_CHECK(copt);
+ copt = cpt1.get_child_optional(T("k2.k"));
+ BOOST_CHECK(copt);
+ copt = cpt2.get_child_optional(T("k1"));
+ BOOST_CHECK(copt && *copt == pt);
+ copt = cpt2.get_child_optional(T("k2.k"));
+ BOOST_CHECK(copt && *copt == pt);
+
+ // Do incorrect extractions via get_child (throwing version)
+ try
+ {
+ pt.get_child(T("k2.k.bogus.path"));
+ BOOST_ERROR("No required exception thrown");
+ }
+ catch (boost::property_tree::ptree_bad_path &) { }
+ catch (...)
+ {
+ BOOST_ERROR("Wrong exception type thrown");
+ }
+
+ // Do incorrect extractions via get_child (default value version)
+ BOOST_CHECK(&pt.get_child(T("k2.k.bogus.path"), pt3) == &pt3);
+
+ // Do incorrect extractions via get_child (optional version)
+ BOOST_CHECK(!pt.get_child_optional(T("k2.k.bogus.path")));
+
+ // Test multiple puts with the same key
+ {
+ PTREE pt, tmp1(T("data1")), tmp2(T("data2"));
+ pt.put_child(T("key"), tmp1);
+ BOOST_CHECK(pt.get_child(T("key")) == tmp1);
+ BOOST_CHECK(pt.size() == 1);
+ pt.put_child(T("key"), tmp2);
+ BOOST_CHECK(pt.get_child(T("key")) == tmp2);
+ BOOST_CHECK(pt.size() == 1);
+ pt.put_child(T("key.key.key"), tmp1);
+ PTREE &child = pt.get_child(T("key.key"));
+ BOOST_CHECK(child.size() == 1);
+ pt.put_child(T("key.key.key"), tmp2);
+ BOOST_CHECK(child.size() == 1);
+ }
+
+ // Test multiple adds with the same key
+ {
+ PTREE pt, tmp1(T("data1")), tmp2(T("data2"));
+ pt.add_child(T("key"), tmp1);
+ BOOST_CHECK(pt.size() == 1);
+ pt.add_child(T("key"), tmp2);
+ BOOST_CHECK(pt.size() == 2);
+ BOOST_CHECK(pt.count(T("key")) == 2);
+ pt.add_child(T("key.key.key"), tmp1);
+ PTREE &child = pt.get_child(T("key.key"));
+ BOOST_CHECK(child.size() == 1);
+ BOOST_CHECK(child.count(T("key")) == 1);
+ pt.add_child(T("key.key.key"), tmp2);
+ BOOST_CHECK(child.size() == 2);
+ BOOST_CHECK(child.count(T("key")) == 2);
+ }
+
+ // Test assigning child to tree
+ {
+ PTREE pt;
+ pt.put(T("foo.bar"), T("baz"));
+ pt = pt.get_child(T("foo"));
+ BOOST_CHECK(pt.size() == 1);
+ BOOST_CHECK(pt.get< std::basic_string<CHTYPE> >(T("bar")) == T("baz"));
+ }
+
+}
+
+void test_equal_range(PTREE *)
+{
+ PTREE pt;
+ pt.add_child(T("k1"), PTREE());
+ pt.add_child(T("k2"), PTREE());
+ pt.add_child(T("k1"), PTREE());
+ pt.add_child(T("k3"), PTREE());
+ pt.add_child(T("k1"), PTREE());
+ pt.add_child(T("k2"), PTREE());
+
+ BOOST_CHECK(boost::distance(pt.equal_range(T("k1"))) == 3);
+ BOOST_CHECK(boost::distance(pt.equal_range(T("k2"))) == 2);
+ BOOST_CHECK(boost::distance(pt.equal_range(T("k3"))) == 1);
+}
+
+void test_path_separator(PTREE *)
+{
+
+ typedef PTREE::path_type path;
+
+ // Check instances count
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 0);
+
+ // Do insertions
+ PTREE pt;
+ pt.put(T("key1"), T("1"));
+ pt.put(T("key2.key"), T("2"));
+ pt.put(T("key3.key.key"), T("3"));
+ pt.put(path(T("key4"), CHTYPE('/')), T("4"));
+ pt.put(path(T("key5/key"), CHTYPE('/')), T("5"));
+ pt.put(path(T("key6/key/key"), CHTYPE('/')), T("6"));
+
+ // Check instances count
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 13);
+
+ // Do correct extractions
+ BOOST_CHECK(pt.get(T("key1"), 0) == 1);
+ BOOST_CHECK(pt.get(T("key2.key"), 0) == 2);
+ BOOST_CHECK(pt.get(T("key3.key.key"), 0) == 3);
+ BOOST_CHECK(pt.get(path(T("key4"), CHTYPE('/')), 0) == 4);
+ BOOST_CHECK(pt.get(path(T("key5/key"), CHTYPE('/')), 0) == 5);
+ BOOST_CHECK(pt.get(path(T("key6/key/key"), CHTYPE('/')), 0) == 6);
+
+ // Do incorrect extractions
+ BOOST_CHECK(pt.get(T("key2/key"), 0) == 0);
+ BOOST_CHECK(pt.get(T("key3/key/key"), 0) == 0);
+ BOOST_CHECK(pt.get(path(T("key5.key"), CHTYPE('/')), 0) == 0);
+ BOOST_CHECK(pt.get(path(T("key6.key.key"), CHTYPE('/')), 0) == 0);
+
+}
+
+void test_path(PTREE *)
+{
+
+ typedef PTREE::path_type path;
+
+ // Insert
+ PTREE pt;
+ pt.put(T("key1.key2.key3"), 1);
+
+ // Test operator /=
+ {
+ path p;
+ p /= T("key1"); p /= T("key2"); p /= T("key3");
+ BOOST_CHECK(pt.get<int>(p, 0) == 1);
+ }
+
+ // Test operator /=
+ {
+ path p(T("key1"));
+ p /= T("key2.key3");
+ BOOST_CHECK(pt.get<int>(p, 0) == 1);
+ }
+
+ // Test operator /=
+ {
+ path p;
+ path p1(T("key1.key2"));
+ path p2(T("key3"));
+ p /= p1;
+ p /= p2;
+ BOOST_CHECK(pt.get<int>(p, 0) == 1);
+ }
+
+ // Test operator /
+ {
+ path p = path(T("key1")) / T("key2.key3");
+ BOOST_CHECK(pt.get<int>(p, 0) == 1);
+ }
+
+ // Test operator /
+ {
+ path p = T("key1.key2") / path(T("key3"));
+ BOOST_CHECK(pt.get<int>(p, 0) == 1);
+ }
+
+}
+
+void test_precision(PTREE *)
+{
+
+ typedef double real;
+
+ // Quite precise PI value
+ real pi = real(3.1415926535897932384626433832795028841971);
+
+ // Put and get
+ PTREE pt;
+ pt.put_value(pi);
+ real pi2 = pt.get_value<real>();
+
+ // Test if precision is "good enough", i.e. if stream precision increase worked
+ using namespace std;
+ real error = abs(pi - pi2) *
+ pow(real(numeric_limits<real>::radix),
+ real(numeric_limits<real>::digits));
+ BOOST_CHECK(error < 100);
+
+}
+
+void test_locale(PTREE *)
+{
+ typedef boost::property_tree::translator_between<
+ std::basic_string<CHTYPE>, double>::type translator;
+ try
+ {
+
+ // Write strings in english and french locales
+ PTREE pt;
+#ifdef BOOST_WINDOWS
+ std::locale loc_english("english");
+ std::locale loc_french("french");
+#else
+ std::locale loc_english("en_GB");
+ std::locale loc_french("fr_FR");
+#endif
+ pt.put(T("english"), 1.234, translator(loc_english));
+ pt.put(T("french"), 1.234, translator(loc_french));
+
+ // Test contents
+ BOOST_CHECK(pt.get<PTREE::data_type>(T("english")) == T("1.234"));
+ BOOST_CHECK(pt.get<PTREE::data_type>(T("french")) == T("1,234"));
+
+ }
+ catch (boost::property_tree::ptree_error &)
+ {
+ throw;
+ }
+ catch (std::runtime_error &e)
+ {
+ std::cerr << "Required locale not supported by the platform. "
+ "Skipping locale tests (caught std::runtime_error with message " <<
+ e.what() << ").\n";
+ }
+
+}
+
+void test_custom_data_type(PTREE *)
+{
+
+ typedef std::basic_string<CHTYPE> Str;
+ typedef PTREE::key_compare Comp;
+
+ // Property_tree with boost::any as data type
+ typedef boost::property_tree::basic_ptree<Str, boost::any, Comp> my_ptree;
+ my_ptree pt;
+
+ // Put/get int value
+ pt.put(T("int value"), 3);
+ int int_value = pt.get<int>(T("int value"));
+ BOOST_CHECK(int_value == 3);
+
+ // Put/get string value
+ pt.put<std::basic_string<CHTYPE> >(T("string value"), T("foo bar"));
+ std::basic_string<CHTYPE> string_value = pt.get<std::basic_string<CHTYPE> >(T("string value"));
+ BOOST_CHECK(string_value == T("foo bar"));
+
+ // Put/get list<int> value
+ int list_data[] = { 1, 2, 3, 4, 5 };
+ pt.put<std::list<int> >(T("list value"), std::list<int>(list_data, list_data + sizeof(list_data) / sizeof(*list_data)));
+ std::list<int> list_value = pt.get<std::list<int> >(T("list value"));
+ BOOST_CHECK(list_value.size() == 5);
+ BOOST_CHECK(list_value.front() == 1);
+ BOOST_CHECK(list_value.back() == 5);
+
+}
+
+void test_empty_size_max_size(PTREE *)
+{
+
+ PTREE pt;
+ BOOST_CHECK(pt.max_size());
+ BOOST_CHECK(pt.empty());
+ BOOST_CHECK(pt.size() == 0);
+
+ pt.put(T("test1"), 1);
+ BOOST_CHECK(pt.max_size());
+ BOOST_CHECK(!pt.empty());
+ BOOST_CHECK(pt.size() == 1);
+
+ pt.put(T("test2"), 2);
+ BOOST_CHECK(pt.max_size());
+ BOOST_CHECK(!pt.empty());
+ BOOST_CHECK(pt.size() == 2);
+
+}
+
+void test_ptree_bad_path(PTREE *)
+{
+
+ PTREE pt;
+
+ try
+ {
+ pt.get<int>(T("non.existent.path"));
+ }
+ catch (boost::property_tree::ptree_bad_path &e)
+ {
+ PTREE::path_type path = e.path<PTREE::path_type>();
+ std::string what = e.what();
+ BOOST_CHECK(what.find("non.existent.path") != std::string::npos);
+ return;
+ }
+
+ BOOST_ERROR("No required exception thrown");
+
+}
+
+void test_ptree_bad_data(PTREE *)
+{
+
+ PTREE pt;
+ pt.put_value("non convertible to int");
+
+ try
+ {
+ pt.get_value<int>();
+ }
+ catch (boost::property_tree::ptree_bad_data &e)
+ {
+ PTREE::data_type data = e.data<PTREE::data_type>();
+ std::string what = e.what();
+ // FIXME: Bring back what translation or make it more clear that it
+ // doesn't work.
+ //BOOST_CHECK(what.find("non convertible to int") != std::string::npos);
+ return;
+ }
+
+ BOOST_ERROR("No required exception thrown");
+}
+
+void test_serialization(PTREE *)
+{
+
+ // Prepare test tree
+ PTREE pt;
+ pt.put_value(1);
+ pt.put(T("key1"), 3);
+ pt.put(T("key1.key11)"), 3.3);
+ pt.put(T("key1.key12"), T("foo"));
+ pt.put(T("key2"), true);
+ pt.put(T("key2.key21.key211.key2111.key21111"), T("super deep!"));
+ pt.put_child(T("empty"), PTREE());
+ pt.put(T("loooooong"), PTREE::data_type(10000, CHTYPE('a')));
+
+ // Endforce const for input
+ const PTREE &pt1 = pt;
+
+ // Test text archives
+ {
+ std::stringstream stream;
+ boost::archive::text_oarchive oa(stream);
+ oa & pt1;
+ boost::archive::text_iarchive ia(stream);
+ PTREE pt2;
+ ia & pt2;
+ BOOST_CHECK(pt1 == pt2);
+ }
+
+ // Test binary archives
+ {
+ std::stringstream stream;
+ boost::archive::binary_oarchive oa(stream);
+ oa & pt1;
+ boost::archive::binary_iarchive ia(stream);
+ PTREE pt2;
+ ia & pt2;
+ BOOST_CHECK(pt1 == pt2);
+ }
+
+ // Test XML archives
+ {
+ std::stringstream stream;
+ boost::archive::xml_oarchive oa(stream);
+ oa & boost::serialization::make_nvp("pt", pt1);
+ boost::archive::xml_iarchive ia(stream);
+ PTREE pt2;
+ ia & boost::serialization::make_nvp("pt", pt2);
+ BOOST_CHECK(pt1 == pt2);
+ }
+
+}
+
+void test_bool(PTREE *)
+{
+
+ // Prepare test tree
+ PTREE pt;
+ pt.put(T("bool.false.1"), false);
+ pt.put(T("bool.false.2"), T("0"));
+ pt.put(T("bool.true.1"), true);
+ pt.put(T("bool.true.2"), 1);
+ pt.put(T("bool.invalid.1"), T(""));
+ pt.put(T("bool.invalid.2"), T("tt"));
+ pt.put(T("bool.invalid.3"), T("ff"));
+ pt.put(T("bool.invalid.4"), T("2"));
+ pt.put(T("bool.invalid.5"), T("-1"));
+
+ // Test false
+ for (PTREE::iterator it = pt.get_child(T("bool.false")).begin(); it != pt.get_child(T("bool.false")).end(); ++it)
+ BOOST_CHECK(it->second.get_value<bool>() == false);
+
+ // Test true
+ for (PTREE::iterator it = pt.get_child(T("bool.true")).begin(); it != pt.get_child(T("bool.true")).end(); ++it)
+ BOOST_CHECK(it->second.get_value<bool>() == true);
+
+ // Test invalid
+ for (PTREE::iterator it = pt.get_child(T("bool.invalid")).begin(); it != pt.get_child(T("bool.invalid")).end(); ++it)
+ {
+ BOOST_CHECK(it->second.get_value<bool>(false) == false);
+ BOOST_CHECK(it->second.get_value<bool>(true) == true);
+ }
+
+}
+
+void test_char(PTREE *)
+{
+ typedef signed char schar;
+ typedef unsigned char uchar;
+
+ // Prepare test tree
+ PTREE pt;
+#if WIDECHAR == 0
+ pt.put(T("char"), char('A'));
+#endif
+ pt.put(T("signed char"), static_cast<schar>('A'));
+ pt.put(T("unsigned char"), static_cast<uchar>('A'));
+ pt.put(T("signed char min"), (std::numeric_limits<schar>::min)());
+ pt.put(T("signed char max"), (std::numeric_limits<schar>::max)());
+ pt.put(T("signed char underflow"),
+ static_cast<int>((std::numeric_limits<schar>::min)()) - 1);
+ pt.put(T("signed char overflow"),
+ static_cast<int>((std::numeric_limits<schar>::max)()) + 1);
+ pt.put(T("unsigned char min"), (std::numeric_limits<uchar>::min)());
+ pt.put(T("unsigned char max"), (std::numeric_limits<uchar>::max)());
+ pt.put(T("unsigned char overflow"),
+ static_cast<unsigned>((std::numeric_limits<uchar>::max)()) + 1);
+
+ // Verify normal conversions
+#if WIDECHAR == 0
+ BOOST_CHECK(pt.get<char>(T("char")) == 'A');
+#endif
+ BOOST_CHECK(pt.get<schar>(T("signed char")) == static_cast<schar>('A'));
+ BOOST_CHECK(pt.get<uchar>(T("unsigned char")) == static_cast<uchar>('A'));
+
+ // Verify that numbers are saved for signed and unsigned char
+ BOOST_CHECK(pt.get<int>(T("signed char")) == int('A'));
+ BOOST_CHECK(pt.get<int>(T("unsigned char")) == int('A'));
+
+ // Verify ranges
+ BOOST_CHECK(pt.get<schar>(T("signed char min")) ==
+ (std::numeric_limits<schar>::min)());
+ BOOST_CHECK(pt.get<schar>(T("signed char max")) ==
+ (std::numeric_limits<schar>::max)());
+ BOOST_CHECK(pt.get<uchar>(T("unsigned char min")) ==
+ (std::numeric_limits<uchar>::min)());
+ BOOST_CHECK(pt.get<uchar>(T("unsigned char max")) ==
+ (std::numeric_limits<uchar>::max)());
+
+ // Check that out-of-range throws.
+ try {
+ pt.get<schar>(T("signed char underflow"));
+ BOOST_ERROR("expected ptree_bad_data, but nothing was thrown");
+ } catch (boost::property_tree::ptree_bad_data&) {
+ } catch (...) {
+ BOOST_ERROR("expected ptree_bad_data, but something else was thrown");
+ }
+ try {
+ pt.get<schar>(T("signed char overflow"));
+ BOOST_ERROR("expected ptree_bad_data, but nothing was thrown");
+ } catch (boost::property_tree::ptree_bad_data&) {
+ } catch (...) {
+ BOOST_ERROR("expected ptree_bad_data, but something else was thrown");
+ }
+ try {
+ pt.get<uchar>(T("unsigned char overflow"));
+ BOOST_ERROR("expected ptree_bad_data, but nothing was thrown");
+ } catch (boost::property_tree::ptree_bad_data&) {
+ } catch (...) {
+ BOOST_ERROR("expected ptree_bad_data, but something else was thrown");
+ }
+}
+
+void test_float(PTREE*)
+{
+ const double difficult = -183.12345000098765e-10;
+ PTREE pt;
+ pt.put(T("num"), difficult);
+ double result = pt.get<double>(T("num"));
+
+ BOOST_CHECK(!(result < difficult || result > difficult));
+}
+
+void test_sort(PTREE *)
+{
+ PTREE pt;
+ pt.put(T("one"), T("v1"));
+ pt.put(T("two"), T("v2"));
+ pt.put(T("three"), T("v3"));
+ pt.put(T("four"), T("v4"));
+
+ pt.sort();
+
+ PTREE::iterator it = pt.begin();
+ BOOST_CHECK(std::distance(it, pt.end()) == 4);
+ BOOST_CHECK(it->first == T("four"));
+ BOOST_CHECK(it->second.data() == T("v4"));
+ ++it;
+ BOOST_CHECK(it->first == T("one"));
+ BOOST_CHECK(it->second.data() == T("v1"));
+ ++it;
+ BOOST_CHECK(it->first == T("three"));
+ BOOST_CHECK(it->second.data() == T("v3"));
+ ++it;
+ BOOST_CHECK(it->first == T("two"));
+ BOOST_CHECK(it->second.data() == T("v2"));
+}
+
+void test_leaks(PTREE *)
+{
+ //BOOST_CHECK(PTREE::debug_get_instances_count() == 0);
+}
diff --git a/src/boost/libs/property_tree/test/test_utils.hpp b/src/boost/libs/property_tree/test/test_utils.hpp
new file mode 100644
index 000000000..809f91f57
--- /dev/null
+++ b/src/boost/libs/property_tree/test/test_utils.hpp
@@ -0,0 +1,252 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2005 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+#ifndef BOOST_PROPERTY_TREE_TEST_UTILS_INCLUDED
+#define BOOST_PROPERTY_TREE_TEST_UTILS_INCLUDED
+
+#define BOOST_PROPERTY_TREE_DEBUG // Enable ptree debugging
+#include <boost/property_tree/ptree.hpp>
+
+// Do not deprecate insecure CRT calls on VC8
+#if (defined(BOOST_MSVC) && (BOOST_MSVC >= 1400) && !defined(_CRT_SECURE_NO_DEPRECATE))
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+#include <boost/test/minimal.hpp>
+#include <boost/property_tree/detail/ptree_utils.hpp>
+#include <fstream>
+#include <cstring>
+#include <sstream>
+
+template<class Ptree>
+typename Ptree::size_type total_size(const Ptree &pt)
+{
+ typename Ptree::size_type size = 1;
+ for (typename Ptree::const_iterator it = pt.begin(); it != pt.end(); ++it)
+ size += total_size(it->second);
+ return size;
+}
+
+template<class Ptree>
+typename Ptree::size_type total_keys_size(const Ptree &pt)
+{
+ typename Ptree::size_type size = 0;
+ for (typename Ptree::const_iterator it = pt.begin(); it != pt.end(); ++it)
+ {
+ size += it->first.size();
+ size += total_keys_size(it->second);
+ }
+ return size;
+}
+
+template<class Ptree>
+typename Ptree::size_type total_data_size(const Ptree &pt)
+{
+ typename Ptree::size_type size = pt.data().size();
+ for (typename Ptree::const_iterator it = pt.begin(); it != pt.end(); ++it)
+ size += total_data_size(it->second);
+ return size;
+}
+
+class test_file
+{
+public:
+ test_file(const char *test_data, const char *filename)
+ {
+ if (test_data && filename)
+ {
+ name = filename;
+ std::ofstream stream(name.c_str());
+ using namespace std;
+ stream.write(test_data, strlen(test_data));
+ BOOST_CHECK(stream.good());
+ }
+ }
+ ~test_file()
+ {
+ if (!name.empty())
+ remove(name.c_str());
+ }
+private:
+ std::string name;
+};
+
+template<class Ptree>
+Ptree get_test_ptree()
+{
+ using namespace boost::property_tree;
+ typedef typename Ptree::key_type Str;
+ Ptree pt;
+ pt.put_value(detail::widen<Str>("data0"));
+ pt.put(detail::widen<Str>("key1"), detail::widen<Str>("data1"));
+ pt.put(detail::widen<Str>("key1.key"), detail::widen<Str>("data2"));
+ pt.put(detail::widen<Str>("key2"), detail::widen<Str>("data3"));
+ pt.put(detail::widen<Str>("key2.key"), detail::widen<Str>("data4"));
+ return pt;
+}
+
+// Generic test for file parser
+template<class Ptree, class ReadFunc, class WriteFunc>
+void generic_parser_test(Ptree &pt,
+ ReadFunc rf,
+ WriteFunc wf,
+ const char *test_data_1,
+ const char *test_data_2,
+ const char *filename_1,
+ const char *filename_2,
+ const char *filename_out)
+{
+
+ using namespace boost::property_tree;
+
+ // Create test files
+ 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
+ Ptree pt2;
+ rf(filename_out, pt2); // Read file again
+
+ // Compare original with read
+ BOOST_CHECK(pt == pt2);
+
+}
+
+// Generic test for file parser with expected success
+template<class Ptree, class ReadFunc, class WriteFunc>
+void generic_parser_test_ok(ReadFunc rf,
+ WriteFunc wf,
+ const char *test_data_1,
+ const char *test_data_2,
+ const char *filename_1,
+ const char *filename_2,
+ const char *filename_out,
+ unsigned int total_size,
+ unsigned int total_data_size,
+ unsigned int total_keys_size)
+{
+
+ using namespace boost::property_tree;
+
+ std::cerr << "(progress) Starting generic parser test with test file \"" << filename_1 << "\"\n";
+
+ // Make sure no instances exist
+ //BOOST_CHECK(Ptree::debug_get_instances_count() == 0);
+
+ try
+ {
+
+ // Read file
+ Ptree pt;
+ generic_parser_test<Ptree, ReadFunc, WriteFunc>(pt, rf, wf,
+ test_data_1, test_data_2,
+ filename_1, filename_2, filename_out);
+
+ // Determine total sizes
+ typename Ptree::size_type actual_total_size = ::total_size(pt);
+ typename Ptree::size_type actual_data_size = ::total_data_size(pt);
+ typename Ptree::size_type actual_keys_size = ::total_keys_size(pt);
+ if (actual_total_size != total_size ||
+ actual_data_size != total_data_size ||
+ actual_keys_size != total_keys_size)
+ std::cerr << "Sizes: " << (unsigned)::total_size(pt) << ", " << (unsigned)::total_data_size(pt) << ", " << (unsigned)::total_keys_size(pt) << "\n";
+
+ // Check total sizes
+ BOOST_CHECK(actual_total_size == total_size);
+ BOOST_CHECK(actual_data_size == total_data_size);
+ BOOST_CHECK(actual_keys_size == total_keys_size);
+
+ }
+ catch (std::runtime_error &e)
+ {
+ BOOST_ERROR(e.what());
+ }
+
+ // Test for leaks
+ //BOOST_CHECK(Ptree::debug_get_instances_count() == 0);
+
+}
+
+// Generic test for file parser with expected error
+template<class Ptree, class ReadFunc, class WriteFunc, class Error>
+void generic_parser_test_error(ReadFunc rf,
+ WriteFunc wf,
+ const char *test_data_1,
+ const char *test_data_2,
+ const char *filename_1,
+ const char *filename_2,
+ const char *filename_out,
+ unsigned long expected_error_line)
+{
+
+ std::cerr << "(progress) Starting generic parser test with test file \"" << filename_1 << "\"\n";
+
+ // Make sure no instances exist
+ //BOOST_CHECK(Ptree::debug_get_instances_count() == 0);
+
+ {
+
+ // Create ptree as a copy of test ptree (to test if read failure does not damage ptree)
+ Ptree pt(get_test_ptree<Ptree>());
+ try
+ {
+ generic_parser_test<Ptree, ReadFunc, WriteFunc>(pt, rf, wf,
+ test_data_1, test_data_2,
+ filename_1, filename_2, filename_out);
+ BOOST_ERROR("No required exception thrown");
+ }
+ catch (Error &e)
+ {
+ BOOST_CHECK(e.line() == expected_error_line); // Test line number
+ BOOST_CHECK(pt == get_test_ptree<Ptree>()); // Test if error damaged contents
+ }
+ catch (...)
+ {
+ BOOST_ERROR("Invalid exception type thrown");
+ throw;
+ }
+
+ }
+
+ // Test for leaks
+ //BOOST_CHECK(Ptree::debug_get_instances_count() == 0);
+
+}
+
+template <typename Ch> std::basic_ostream<Ch>& errstream();
+template <> inline
+std::basic_ostream<char>& errstream() { return std::cerr; }
+#ifndef BOOST_NO_CWCHAR
+template <> inline
+std::basic_ostream<wchar_t>& errstream() { return std::wcerr; }
+#endif
+
+template <class Ptree, class ReadFunc, class WriteFunc>
+void check_exact_roundtrip(ReadFunc rf, WriteFunc wf, const char *test_data) {
+ std::cerr << "(progress) Starting exact roundtrip test with test data:\n"
+ << test_data << "\n-----\n";
+ using namespace boost::property_tree;
+ typedef typename Ptree::key_type::value_type Ch;
+ typedef typename Ptree::key_type Str;
+ Str native_test_data = detail::widen<Str>(test_data);
+
+ std::basic_istringstream<Ch> in_stream(native_test_data);
+ std::basic_ostringstream<Ch> out_stream;
+ Ptree tree;
+ rf(in_stream, tree);
+ wf(out_stream, tree);
+ std::cerr << "(progress) Roundtripped data:\n";
+ errstream<Ch>() << out_stream.str();
+ std::cerr << "\n-----\n";
+ BOOST_CHECK(native_test_data == out_stream.str());
+}
+
+#endif
diff --git a/src/boost/libs/property_tree/test/test_xml_parser_common.hpp b/src/boost/libs/property_tree/test/test_xml_parser_common.hpp
new file mode 100644
index 000000000..019773bb6
--- /dev/null
+++ b/src/boost/libs/property_tree/test/test_xml_parser_common.hpp
@@ -0,0 +1,150 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+#ifndef TEST_XML_PARSER_COMMON_HPP_INCLUDED
+#define TEST_XML_PARSER_COMMON_HPP_INCLUDED
+
+#include "test_utils.hpp"
+#include <boost/property_tree/xml_parser.hpp>
+#include "xml_parser_test_data.hpp"
+
+struct ReadFuncWS
+{
+ template<class Ptree>
+ void operator()(const std::string &filename, Ptree &pt) const
+ {
+ boost::property_tree::read_xml(filename, pt,
+ boost::property_tree::xml_parser::no_concat_text);
+ }
+};
+
+struct WriteFuncWS
+{
+ template<class Ptree>
+ void operator()(const std::string &filename, const Ptree &pt) const
+ {
+ boost::property_tree::write_xml(filename, pt);
+ }
+};
+
+struct ReadFuncNS
+{
+ template<class Ptree>
+ void operator()(const std::string &filename, Ptree &pt) const
+ {
+ boost::property_tree::read_xml(filename, pt,
+ boost::property_tree::xml_parser::trim_whitespace);
+ }
+};
+
+struct WriteFuncNS
+{
+ template<class Ptree>
+ void operator()(const std::string &filename, const Ptree &pt) const
+ {
+ boost::property_tree::write_xml(filename, pt, std::locale(),
+ boost::property_tree::xml_writer_make_settings<typename Ptree::key_type>(' ', 4));
+ }
+};
+
+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()
+{
+
+ using namespace boost::property_tree;
+ typedef typename Ptree::data_type::value_type char_type;
+
+ generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
+ (
+ ReadFuncWS(), WriteFuncWS(), ok_data_1, NULL,
+ "testok1.xml", NULL, "testok1out.xml", 2, 0, 5
+ );
+
+ generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
+ (
+ ReadFuncWS(), WriteFuncWS(), ok_data_2, NULL,
+ "testok2a.xml", NULL, "testok2aout.xml", 15, 23, 89
+ );
+
+ generic_parser_test_ok<Ptree, ReadFuncNS, WriteFuncNS>
+ (
+ ReadFuncNS(), WriteFuncNS(), ok_data_2, NULL,
+ "testok2b.xml", NULL, "testok2bout.xml", 6, 15, 8
+ );
+
+ generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
+ (
+ ReadFuncWS(), WriteFuncWS(), ok_data_3, NULL,
+ "testok3a.xml", NULL, "testok3aout.xml", 1662, 35377, 11706
+ );
+
+ generic_parser_test_ok<Ptree, ReadFuncNS, WriteFuncNS>
+ (
+ ReadFuncNS(), WriteFuncNS(), ok_data_3, NULL,
+ "testok3b.xml", NULL, "testok3bout.xml", 787, 31376, 3831
+ );
+
+ generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
+ (
+ ReadFuncWS(), WriteFuncWS(), ok_data_4, NULL,
+ "testok4.xml", NULL, "testok4out.xml", 11, 7, 74
+ );
+
+ generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
+ (
+ ReadFuncWS(), WriteFuncWS(), ok_data_5, NULL,
+ "testok5.xml", NULL, "testok5out.xml",
+ 3, umlautsize<char_type>(), 12
+ );
+
+ generic_parser_test_error<Ptree, ReadFuncWS, WriteFuncWS, xml_parser_error>
+ (
+ ReadFuncWS(), WriteFuncWS(), error_data_1, NULL,
+ "testerr1.xml", NULL, "testerr1out.xml", 1
+ );
+
+ generic_parser_test_error<Ptree, ReadFuncWS, WriteFuncWS, xml_parser_error>
+ (
+ ReadFuncWS(), WriteFuncWS(), error_data_2, NULL,
+ "testerr2.xml", NULL, "testerr2out.xml", 2
+ );
+
+ generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
+ (
+ ReadFuncWS(), WriteFuncWS(), bug_data_pr2855, NULL,
+ "testpr2855.xml", NULL, "testpr2855out.xml", 3, 7, 14
+ );
+
+ generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
+ (
+ ReadFuncWS(), WriteFuncWS(), bug_data_pr1678, NULL,
+ "testpr1678.xml", NULL, "testpr1678out.xml", 2, 0, 4
+ );
+
+ generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
+ (
+ ReadFuncWS(), WriteFuncWS(), bug_data_pr5203, NULL,
+ "testpr5203.xml", NULL, "testpr5203out.xml",
+ 3, 4 * umlautsize<char_type>(), 13
+ );
+
+ generic_parser_test_ok<Ptree, ReadFuncWS, WriteFuncWS>
+ (
+ ReadFuncWS(), WriteFuncWS(), bug_data_pr4840, NULL,
+ "testpr4840.xml", NULL, "testpr4840out.xml",
+ 4, 13, 15
+ );
+
+}
+
+#endif
diff --git a/src/boost/libs/property_tree/test/test_xml_parser_rapidxml.cpp b/src/boost/libs/property_tree/test/test_xml_parser_rapidxml.cpp
new file mode 100644
index 000000000..ed24e5fcb
--- /dev/null
+++ b/src/boost/libs/property_tree/test/test_xml_parser_rapidxml.cpp
@@ -0,0 +1,34 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+// Copyright (C) 2009-2010 Sebastian Redl
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+
+#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 <boost/detail/utf8_codecvt_facet.ipp>
+
+int test_main(int argc, char *argv[])
+{
+ using namespace boost::property_tree;
+ test_xml_parser<ptree>();
+ test_xml_parser<iptree>();
+#ifndef BOOST_NO_CWCHAR
+ using std::locale;
+ // 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
+ return 0;
+}
diff --git a/src/boost/libs/property_tree/test/xml_parser_test_data.hpp b/src/boost/libs/property_tree/test/xml_parser_test_data.hpp
new file mode 100644
index 000000000..d0b4c071c
--- /dev/null
+++ b/src/boost/libs/property_tree/test/xml_parser_test_data.hpp
@@ -0,0 +1,777 @@
+// ----------------------------------------------------------------------------
+// Copyright (C) 2002-2006 Marcin Kalicinski
+// Copyright (C) 2009 Sebastian Redl
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// For more information, see www.boost.org
+// ----------------------------------------------------------------------------
+
+#ifndef XML_PARSER_TEST_DATA_HPP_INCLUDED
+#define XML_PARSER_TEST_DATA_HPP_INCLUDED
+
+///////////////////////////////////////////////////////////////////////////////
+// Test data
+
+// Correct
+const char *ok_data_1 =
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<start/>";
+
+// Correct
+const char *ok_data_2 =
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<root>\n"
+ "<a>&lt;&gt;&amp;</a>\n"
+ "<b>1&lt;2&gt;3&amp;4</b>\n"
+ "<c> &lt; &gt; &amp; </c>\n"
+ "<d>&#32;</d>\n"
+ "</root>\n";
+
+// Correct
+const char *ok_data_3 =
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<!DOCTYPE spec PUBLIC \"-//W3C//DTD Specification::19990205//EN\" \"dtds/xmlspec.dtd\" [\n"
+ "<!ENTITY doc-type \"WD\">\n"
+ "<!ENTITY iso6.doc.date '29-May-1999'>\n"
+ "]>\n"
+ "<!--ArborText, Inc., 1988-1998, v.4002-->\n"
+ "<?Pub UDT _bookmark _target?>\n"
+ "<?Pub Inc?>\n"
+ "<?xml-stylesheet\n"
+ "href=\"file:///C|/Program%20Files/SoftQuad/XMetaL%201/display/xmlspec.css\"\n"
+ "type=\"text/css\"?>\n"
+ "<spec>\n"
+ "\n"
+ "<!-- Last edited: 27 May 1999 by bent -->\n"
+ "<header><?Pub Dtl?>\n"
+ "\t<title><![CDATA[XML Linking Language (XLink)]]></title>\n"
+ "\t<version>Version 1.0</version>\n"
+ "\t<w3c-designation>WD-xlink-19990527</w3c-designation>\n"
+ "\t<w3c-doctype>World Wide Web Consortium Working Draft</w3c-doctype>\n"
+ "\t<pubdate><day>29</day><month>May</month><year>1999</year></pubdate>\n"
+ "\t<notice>\n"
+ "\t<p>This draft is for public discussion.</p>\n"
+ "\t</notice>\n"
+ "\t<publoc><loc href=\"http://www.w3.org/XML/Group/1999/05/WD-xlink-current\">http://www.w3.org/XML/Group/1999/05/WD-xlink-current</loc></publoc>\n"
+ "\t<prevlocs>\n"
+ "\t<!--Check: was it actually August?-->\n"
+ "\t<loc href=\"http://www.w3.org/XML/Group/1999/05/WD-xlink-19990527\">http://www.w3.org/XML/Group/1999/05/WD-xlink-19990527</loc>\n"
+ "\t<loc href=\"http://www.w3.org/XML/Group/1999/05/WD-xlink-19990505\">http://www.w3.org/XML/Group/1999/05/WD-xlink-19990505</loc>\n"
+ "\t<loc href=\"http://www.w3.org/TR/1998/WD-xlink-19980303\">http://www.w3.org/TR/1998/WD-xlink-19980303</loc>\n"
+ "\t<loc href=\"http://www.w3.org/TR/WD-xml-link-970630\">http://www.w3.org/TR/WD-xml-link-970630</loc></prevlocs>\n"
+ "\n"
+ " <authlist>\n"
+ " <!--Updated author hrefs dorchard-->\n"
+ " <!-- Update Steve's email - bent --> \n"
+ " <author>\n"
+ " <name>Steve DeRose</name>\n"
+ " <affiliation>Inso Corp. and Brown University</affiliation>\n"
+ " <email href=\"mailto:Steven_DeRose@Brown.edu\">Steven_DeRose@Brown.edu</email>\n"
+ " </author>\n"
+ " <author>\n"
+ " <name>David Orchard</name>\n"
+ " <affiliation>IBM Corp.</affiliation>\n"
+ " <email href=\"mailto:dorchard@ca.ibm.com\">dorchard@ca.ibm.com</email>\n"
+ " </author>\n"
+ " <author>\n"
+ " <name>Ben Trafford</name>\n"
+ " <affiliation>Invited Expert</affiliation>\n"
+ " <email href=\"mailto:bent@exemplary.net\">bent@exemplary.net</email>\n"
+ " </author>\n"
+ " <!-- I suggest we move Eve and Tim down to the Acknowledgements section. We\n"
+ " also ought to add Gabe Beged-Dov there, as well. bent\n"
+ " how shall we cite Tim? sjd What about with an Acknowledgments section?\n"
+ " -elm <AUTHOR> <NAME>Tim Bray</NAME> <AFFILIATION>Textuality</AFFILIATION>\n"
+ " <EMAIL>tbray@textuality.com</EMAIL> </AUTHOR>-->\n"
+ " </authlist>\n"
+ "\n"
+ " <status>\n"
+ " <p>This is a W3C Working Draft for review by W3C members and other interested parties. It is a draft document and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use W3C Working Drafts as reference material or to cite them as other than \"work in progress\". A list of current W3C working drafts can be found at <loc href=\"http://www.w3.org/TR\">http://www.w3.org/TR</loc>.</p>\n"
+ " <p><emph>Note:</emph> Since working drafts are subject to frequent change, you are advised to reference the above URI, rather than the URIs for working drafts themselves. Some of the work remaining is described in <specref ref=\"unfinished\"/>. </p>\n"
+ " <p>This work is part of the W3C XML Activity (for current status, see <loc href=\"http://www.w3.org/MarkUp/SGML/Activity\">http://www.w3.org/XML/Activity </loc>). For information about the XPointer language which is expected to be used with XLink, see <loc href=\"http://www.w3.org/MarkUp/SGML/Activity\">http://www.w3.org/TR/WD-xptr</loc>.\n"
+ " </p>\n"
+ " <p>See <loc href=\"http://www.w3.org/TR/NOTE-xlink-principles\">http://www.w3.org/TR/NOTE-xlink-principles </loc> for additional background on the design principles informing XLink.</p>\n"
+ " <p>Also see <loc href=\"http://www.w3.org/TR/NOTE-xlink-req/\">http://www.w3.org/TR/NOTE-xlink-req/</loc> for the XLink requirements that this document attempts to satisfy.</p>\n"
+ " </status>\n"
+ "\n"
+ " <abstract>\n"
+ " <!-- edited the abstract for further clarity - bent -->\n"
+ " <p>This specification defines constructs that may be inserted into XML DTDs, schemas and document instances to describe links between objects. It uses XML syntax to create structures that can describe the simple unidirectional hyperlinks of today's HTML as well as more sophisticated links.</p>\n"
+ " </abstract>\n"
+ "\n"
+ " <pubstmt>\n"
+ " <p>Burlington, Seekonk, et al.: World-Wide Web Consortium, XML Working Group, 1998.</p>\n"
+ " </pubstmt>\n"
+ "\n"
+ " <sourcedesc>\n"
+ " <p>Created in electronic form.</p>\n"
+ " </sourcedesc>\n"
+ "\n"
+ " <langusage>\n"
+ " <language id=\"en\">English</language>\n"
+ " <language id=\"ebnf\">Extended Backus-Naur Form (formal grammar)</language>\n"
+ " </langusage>\n"
+ "\n"
+ " <revisiondesc>\n"
+ " <slist>\n"
+ " <sitem>1997-01-15 : Skeleton draft by TB</sitem>\n"
+ " <sitem>1997-01-24 : Fleshed out by sjd</sitem>\n"
+ " <sitem>1997-04-08 : Substantive draft</sitem>\n"
+ " <sitem>1997-06-30 : Public draft</sitem>\n"
+ " <sitem>1997-08-01 : Public draft</sitem>\n"
+ " <sitem>1997-08-05 : Prose/organization work by sjd</sitem>\n"
+ " <sitem>1997-10-14: Conformance and design principles; a bit of cleanup by elm</sitem>\n"
+ " <sitem>1997-11-07: Update for editorial issues per issues doc, by sjd.</sitem>\n"
+ " <sitem>1997-12-01: Update for editorial issues per issues doc in preparation for F2F meeting, by sjd.</sitem>\n"
+ " <sitem>1998-01-13: Editorial cleanup, addition of new design principles, by elm.</sitem>\n"
+ " <sitem>1998-02-27: Splitting out of XLink and XPointer, by elm.</sitem>\n"
+ " <sitem>1998-03-03: Moved most of the XPointer locator stuff here. elm</sitem>\n"
+ " <sitem>1999-04-24: Editorial rewrites to represent new ideas on XLink, especially the inclusion of arcs. bent</sitem>\n"
+ " <sitem>1999-05-05: Prose/organization work by dorchard. Moved much of the semantics section around, from: locators, link semantics, remote resource semantics, local resource semantics; to: resource semantics, locators, behavior semantics, link semantics, arc semantics</sitem>\n"
+ " <sitem>1999-05-12: Prose/organization work. Re-organized some of the sections, removed XML constructs from the document, added descriptive prose, edited document text for clarity. Rewrote the link recognition section. bent</sitem>\n"
+ " <sitem>1999-05-17: Further prose work. Added non-normative examples. Clarified arcs. bent</sitem>\n"
+ " <sitem>1999-05-23: Edited for grammar and clarity. bent</sitem>\n"
+ " <sitem>1999-05-27: Final once-over before sending to group. Fixed sjd's email address. bent</sitem>\n"
+ " </slist>\n"
+ " </revisiondesc>\n"
+ "</header>\n"
+ "\n"
+ "<body>\n"
+ " <div1><?Pub Dtl?>\n"
+ " <head>Introduction</head>\n"
+ " <p>This specification defines constructs that may be inserted into XML DTDs, schemas, and document instances to describe links between objects. A <termref def=\"dt-link\">link</termref>, as the term is used here, is an explicit relationship between two or more data objects or portions of data objects. This specification is concerned with the syntax used to assert link existence and describe link characteristics. Implicit (unasserted) relationships, for example that of one word to the next or that of a word in a text to its entry in an on-line dictionary are obviously important, but outside its scope.</p>\n"
+ " <p>Links are asserted by <xtermref href=\"WD-xml-lang.html#dt-element\">elements </xtermref> contained in <xtermref href=\"WD-xml-lang.html#dt-xml-doc\">XML document instances</xtermref>. The simplest case is very like an HTML <code>A</code> link, and has these characteristics:\n"
+ " <ulist>\n"
+ " <item><p>The link is expressed at one of its ends (similar to the <code>A</code> element in some document)</p></item>\n"
+ " <item><p>Users can only initiate travel from that end to the other</p></item>\n"
+ " <item><p>The link's effect on windows, frames, go-back lists, stylesheets in use, and so on is mainly determined by browsers, not by the link itself. For example, traveral of <code>A</code> links normally replaces the current view, perhaps with a user option to open a new window.</p></item>\n"
+ " <item><p>The link goes to only one destination (although a server may have great freedom in finding or dynamically creating that destination).</p></item>\n"
+ " </ulist>\n"
+ " </p>\n"
+ " <p>While this set of characteristics is already very powerful and obviously has proven itself highly useful and effective, each of these assumptions also limits the range of hypertext functionality. The linking model defined here provides ways to create links that go beyond each of these specific characteristics, thus providing features previously available mostly in dedicated hypermedia systems.\n"
+ " </p>\n"
+ "\n"
+ "<div2>\n"
+ " <head>Origin and Goals</head>\n"
+ " <p>Following is a summary of the design principles governing XLink:\n"
+ " <olist>\n"
+ " <item><p>XLink must be straightforwardly usable over the Internet. </p></item>\n"
+ " <item><p>XLink must be usable by a wide variety of link usage domains and classes of linking application software.</p></item>\n"
+ " <item><p>XLink must support HTML 4.0 linking constructs.</p></item>\n"
+ " <item><p>The XLink expression language must be XML.</p></item>\n"
+ " <item><p>The XLink design must be formal, concise, and illustrative.</p></item>\n"
+ " <item><p>XLinks must be human-readable and human-writable.</p></item>\n"
+ " <item><p>XLinks may reside within or outside the documents in which the\n"
+ " participating resources reside. </p></item>\n"
+ " <item><p>XLink must represent the abstract structure and significance of links.</p></item>\n"
+ " <item><p>XLink must be feasible to implement.</p></item>\n"
+ " <item><p>XLink must be informed by knowledge of established hypermedia systems and standards.</p></item>\n"
+ " </olist>\n"
+ " </p>\n"
+ "</div2>\n"
+ "<!--Changed the list of requirements to reflect current XLink requirements\n"
+ "document. bent-->\n"
+ "\n"
+ "<div2>\n"
+ " <head>Relationship to Existing Standards</head>\n"
+ " <p>Three standards have been especially influential:\n"
+ " <ulist>\n"
+ " <item><p><emph>HTML:</emph> Defines several SGML element types that represent links.</p></item>\n"
+ " <item><p><emph>HyTime:</emph> Defines inline and out-of-line link structures and some semantic features, including traversal control and presentation of objects. <!--Changed from \"placement of objects into a display or other space\" -elm-->\n"
+ " </p></item>\n"
+ " <item><p><emph>Text Encoding Initiative Guidelines (TEI P3):</emph> Provides structures for creating links, aggregate objects, and link collections out of them.</p></item>\n"
+ " </ulist>\n"
+ " </p>\n"
+ " <p>Many other linking systems have also informed this design, especially Dexter, FRESS, MicroCosm, and InterMedia.</p>\n"
+ "</div2>\n"
+ "\n"
+ "<div2>\n"
+ " <head>Terminology</head>\n"
+ " <p>The following basic terms apply in this document. <!--<IMG\n"
+ " SRC=\"local://./linkdiag.gif\">(figure to be inserted)-->\n"
+ " <glist>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-arc\" term=\"Arc\">arc</termdef></label>\n"
+ " <def><p>A symbolic representation of traversal behavior in links, especially the direction, context and timing of traversal.</p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-eltree\" term=\"Element Tree\">element tree</termdef></label>\n"
+ " <def><p>A representation of the relevant structure specified by the tags and attributes in an XML document, based on \"groves\" as defined in the ISO DSSSL standard. </p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-inline\" term=\"In-Line Link\">inline link</termdef></label>\n"
+ " <def><p>Abstractly, a <termref def=\"dt-link\">link</termref> which serves as one of its own <termref def=\"dt-resource\">resources</termref>. Concretely, a link where the content of the <termref def=\"dt-linkel\">linking element</termref> serves as a <termref def=\"dt-particip-resource\">participating resource</termref>.\n"
+ " HTML <code>A</code>, HyTime <code>clink</code>, and TEI <code>XREF</code>\n"
+ " are all inline links.</p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-link\" term=\"Link\">link</termdef></label>\n"
+ " <def><p>An explicit relationship between two or more data objects or portions of data objects.</p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-linkel\" term=\"Linking Element\">linking element </termdef></label>\n"
+ " <def><p>An <xtermref href=\"WD-xml-lang.html#dt-element\">element</xtermref> that asserts the existence and describes the characteristics of a <termref def=\"dt-link\"> link</termref>.</p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-local-resource\" term=\"Local Resource\">local resource</termdef></label>\n"
+ " <def><p>The content of an <termref def=\"dt-inline\">inline</termref>linking element. Note that the content of the linking element could be explicitly pointed to by means of a regular <termref def=\"dt-locator\">locator</termref> in the same linking element, in which case the resource is considered <termref def=\"dt-remote-resource\"> remote</termref>, not local.</p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-locator\" term=\"Locator\">locator</termdef> </label>\n"
+ " <def><p>Data, provided as part of a link, which identifies a\n"
+ " <termref def=\"dt-resource\">resource</termref>.</p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-multidir\" term=\"Multi-Directional Link\">multidirectional link</termdef></label>\n"
+ " <def><p>A <termref def=\"dt-link\">link</termref> whose <termref def=\"dt-traversal\"> traversal</termref> can be initiated from more than one of its <termref def=\"dt-particip-resource\"> participating resources</termref>. Note that being able to \"go back\" after following a one-directional link does not make the link multidirectional.</p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-outofline\" term=\"Out-of-line Link\">out-of-line link</termdef></label>\n"
+ " <def><p>A <termref def=\"dt-link\">link</termref> whose content does not serve as one of the link's <termref def=\"dt-particip-resource\">participating resources </termref>. Such links presuppose a notion like <termref def=\"dt-xlg\">extended link groups</termref>, which instruct application software where to look for links. Out-of-line links are generally required for supporting multidirectional <termref def=\"dt-traversal\">traversal</termref> and for allowing read-only resources to have outgoing links.</p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-parsedq\" term=\"Parsed\">parsed</termdef></label> <def><p>In the context of link behavior, a parsed link is any link whose content is transcluded into the document where the link originated. The use of the term \"parsed\" directly refers to the concept in XML of a\n"
+ " parsed entity.</p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-particip-resource\" term=\"Participating Resource\"> participating resource</termdef></label>\n"
+ " <def><p>A <termref def=\"dt-resource\">resource</termref> that belongs to a link. All resources are potential contributors to a link; participating resources are the actual contributors to a particular link.</p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-remote-resource\" term=\"Remote Resource\">remote resource</termdef></label>\n"
+ " <def><p>Any participating resource of a link that is pointed to with a locator. </p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-resource\" term=\"Resource\">resource</termdef></label>\n"
+ " <def><p>In the abstract sense, an addressable unit of information or service that is participating in a <termref def=\"dt-link\">link</termref>. Examples include files, images, documents, programs, and query results. Concretely, anything reachable by the use of a <termref def=\"dt-locator\">locator</termref> in some <termref def=\"dt-linkel\">linking element</termref>. Note that this term and its definition are taken from the basic specifications governing the World Wide Web. <!--Joel notes: need link here. bent asks: A link?-->\n"
+ " </p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-subresource\" term=\"sub-Resource\">sub-resource</termdef></label>\n"
+ " <def><p>A portion of a resource, pointed to as the precise destination of a link. As one example, a link might specify that an entire document be retrieved and displayed, but that some specific part(s) of it is the specific linked data, to be treated in an application-appropriate manner such as indication by highlighting, scrolling, etc.</p></def>\n"
+ " </gitem>\n"
+ " <gitem>\n"
+ " <label><termdef id=\"dt-traversal\" term=\"Traversal\">traversal</termdef></label>\n"
+ " <def><p>The action of using a <termref def=\"dt-link\">link</termref>; that is, of accessing a <termref def=\"dt-resource\">resource</termref>. Traversal may be initiated by a user action (for example, clicking on the displayed content of a <termref def=\"dt-linkel\">linking element</termref>) or occur under program control.</p></def>\n"
+ " </gitem>\n"
+ " </glist>\n"
+ " </p>\n"
+ "</div2>\n"
+ "\n"
+ "<div2>\n"
+ " <head>Notation</head>\n"
+ " <p>The formal grammar for <termref def=\"dt-locator\">locators</termref> is given using a simple Extended Backus-Naur Form (EBNF) location, as described in <xspecref href=\"http://www.w3.org/TR/REC-xml#sec-notation\">the XML specification</xspecref>.</p>\n"
+ " <!-- fixed link to XML spec - bent -->\n"
+ "</div2>\n"
+ "</div1>\n"
+ "\n"
+ "<div1 id=\"addressing\"><?Pub Dtl?>\n"
+ " <head>Locator Syntax</head>\n"
+ " <p>The locator for a <termref def=\"dt-resource\">resource</termref> is typically provided by means of a Uniform Resource Identifier, or URI. XPointers can be used in conjunction with the URI structure, as fragment identifiers, to specify a more precise sub-resource. </p>\n"
+ " <!-- Removed the discussion of queries from the previous paragraph, due to contention within the WG. bent -->\n"
+ " <p>A locator generally contains a URI, as described in IETF RFCs <bibref ref=\"rfc1738\"/> and <bibref ref=\"rfc1808\"/>. As these RFCs state, the URI may include a trailing <emph>query</emph> (marked by a leading \"<code>?</code>\"), and be followed by a \"<code>#</code>\" and a <emph>fragment identifier</emph>, with the query interpreted by the host providing the indicated resource, and the interpretation of the fragment identifier dependent on the data type of the indicated resource.</p>\n"
+ " <!--Is there some restriction on URNs having queries and/or fragment identifiers? Since these RFCs don't mention URIs explicitly, should the wording here lead from URLs to URIs more explicitly? -elm-->\n"
+ " <p>In order to locate XML documents and portions of documents, a locator value may contain either a <xtermref href=\"http://www.w3.org/Addressing/rfc1738.txt\"> URI</xtermref> or a fragment identifier, or both. Any fragment identifier for pointing into XML must be an <xtermref href=\"http://www.w3.org/TR/WD-xptr#dt-xpointer\"> XPointer</xtermref>.</p>\n"
+ " <p>Special syntax may be used to request the use of particular processing models in accessing the locator's resource. This is designed to reflect the realities of network operation, where it may or may not be desirable to exercise fine control over the distribution of work between local and remote processors. \n"
+ " <scrap id=\"locator\" lang=\"ebnf\">\n"
+ " <head>Locator</head>\n"
+ " <prod id=\"nt-locator\">\n"
+ " <lhs>Locator</lhs>\n"
+ " <rhs><nt def=\"nt-uri\">URI</nt></rhs>\n"
+ " <rhs>| <nt def=\"nt-connector\">Connector</nt> (<xnt href=\"http://www.w3.org/TR/WD-xptr\">XPointer</xnt> | <xnt href=\"WD-xml-lang.html#NT-Name\">Name</xnt>)</rhs>\n"
+ " <rhs>| <nt def=\"nt-uri\">URI</nt> <nt def=\"nt-connector\">Connector</nt> (<xnt href=\"http://www.w3.org/TR/WD-xptr\">XPointer</xnt> | <xnt href=\"WD-xml-lang.html#NT-Name\">Name</xnt>)</rhs>\n"
+ " </prod>\n"
+ " <prod id=\"nt-connector\">\n"
+ " <lhs>Connector</lhs><rhs>'#' | '|'</rhs>\n"
+ " </prod>\n"
+ " <prod id=\"nt-uri\">\n"
+ " <lhs>URI</lhs><rhs><xnt href=\"WD-xml-lang.html#NT-URLchar\">URIchar*</xnt></rhs>\n"
+ " </prod>\n"
+ " </scrap>\n"
+ " </p>\n"
+ " <p><termdef id=\"dt-designated\" term=\"Designated Resource\">In this discussion, the term <term>designated resource</term> refers to the resource which an entire locator serves to locate.</termdef> The following rules apply:\n"
+ " <ulist>\n"
+ " <item>\n"
+ " <p><termdef id=\"dt-containing-resource\" term=\"Containing Resource\"> The URI, if provided, locates a resource called the <term>containing resource</term>.</termdef></p>\n"
+ " </item>\n"
+ " <item>\n"
+ " <p>If the URI is not provided, the containing resource is considered to be the document in which the linking element is contained. \n"
+ " </p></item>\n"
+ " <item>\n"
+ " <p><termdef id=\"dt-sub-resource\" term=\"Sub-Resource\">If an XPointer is provided, the designated resource is a <term>sub-resource</term>\n"
+ " of the containing resource; otherwise the designated resource is the\n"
+ " containing resource.</termdef></p>\n"
+ " </item>\n"
+ " <!--Is this now incorrect, given the nature of the switch from here() to origin()? -elm \n"
+ " Oy, yes, i think so. it will require some fun wording, though, so i haven't fixed it yet here -sjd-->\n"
+ " <item>\n"
+ " <p>If the <nt def=\"nt-connector\">Connector</nt> is followed directly by a <xnt href=\"http://www.w3.org/TR/REC-xml#NT-Name\">Name</xnt>, the <xnt href=\"http://www.w3.org/TR/REC-xml#NT-Name\">Name</xnt> is shorthand for the XPointer\"<code>id(Name)</code>\"; that is, the sub-resource is the element in the containing resource that has an XML <xtermref href=\"http://www.w3.org/TR/REC-xml#sec-attrtypes\">ID attribute</xtermref> whose value <xtermref href=\"http://www.w3.org/TR/REC-xml#dt-match\">matches</xtermref> the <xnt href=\"http://www.w3.org/TR/REC-xml#NT-Name\">Name</xnt>. This shorthand is to encourage use of the robust <code>id</code> addressing mode.</p>\n"
+ " </item>\n"
+ " <!-- fixed links to the XML recommendation - bent -->\n"
+ " <item>\n"
+ " <p>If the connector is \"<code>#</code>\", this signals an intent that the containing resource is to be fetched as a whole from the host that provides it, and that the XPointer processing to extract the sub-resource\n"
+ " is to be performed on the client, that is to say on the same system where the linking element is recognized and processed.</p>\n"
+ " </item>\n"
+ " <item>\n"
+ " <p>If the connector is \"<code>|</code>\", no intent is signaled as to what processing model is to be used to go about accessing the designated resource.</p>\n"
+ " </item>\n"
+ " </ulist>\n"
+ " </p>\n"
+ " <p>Note that the definition of a URI includes an optional query component. </p>\n"
+ " <p>In the case where the URI contains a query (to be interpreted by the server), information providers and authors of server software are urged to use queries as follows: \n"
+ " <scrap id=\"querysyntax\" lang=\"ebnf\">\n"
+ " <head>Query</head>\n"
+ " <prod id=\"nt-query\">\n"
+ " <lhs>Query</lhs><rhs>'XML-XPTR=' (<xnt href=\"http://www.w3.org/TR/WD-xptr\"> XPointer</xnt> | <xnt href=\"http://www.w3.org/TR/REC-xml#NT-Name\">Name</xnt>)</rhs>\n"
+ " </prod>\n"
+ " </scrap>\n"
+ " </p>\n"
+ " <!-- fixed link to XML recommendation - bent -->\n"
+ "</div1>\n"
+ "\n"
+ "<div1><?Pub Dtl?>\n"
+ " <head>Link Recognition</head>\n"
+ " <p>The existence of a <termref def=\"dt-link\">link</termref> is asserted by a <termref def=\"dt-linkel\">linking element</termref>. Linking elements must be recognized reliably by application software in order to provide appropriate display and behavior. There are several ways link recognition could be accomplished: for example, reserving element type names, reserving attributes names, leaving the matter of recognition entirely up to stylesheets and application software, or using the XLink <xtermref href=\"http://www.w3.org/TR/REC-xml-names/\">namespace</xtermref> to specify element names and attribute names that would be recognized by namespace and XLink-aware processors. Using element and attribute names within the XLink namespace provides a balance between giving users control of their own markup language design and keeping the identification of linking elements simple and unambiguous.</p>\n"
+ " <p>The two approaches to identifying linking elements are relatively simple to implement. For example, here's how the HTML <code>A</code> element would be declared using attributes within the XLink namespace, and then how an element within the XLink namespace might do the same:\n"
+ " <eg>&lt;A xlink:type=\"simple\" xlink:href=\"http://www.w3.org/TR/wd-xlink/\"\n"
+ "xlink:title=\"The Xlink Working Draft\"&gt;The XLink Working Draft.&lt;/A&gt;</eg>\n"
+ " <eg>&lt;xlink:simple href=\"http://www.w3.org/TR/wd-xlink/\"\n"
+ "title=\"The XLink Working Draft\"&gt;The XLink Working Draft&lt;/xlink:simple&gt;</eg>\n"
+ " Any arbitrary element can be made into an XLink by using the <code>xlink:type</code> attribute. And, of course, the explicit XLink elements may be used, as well. This document will go on to describe the linking attributes that are associated with linking elements. It may be assumed by the reader that these attributes would require the <code>xlink</code> namespace prefix if they existed within an arbitrary element, or that they may be used directly if they exist within an explicit Xlink element.</p>\n"
+ " <!-- heavily modified this section to accomodate namespace-aware link recognition - bent -->\n"
+ "</div1>\n"
+ "\n"
+ "<!-- Rewrote this entire section. - bent -->\n"
+ "<div1>\n"
+ " <head>Linking Attributes</head>\n"
+ " <p>XLink has several attributes associated with the variety of links it may represent. These attributes define four main concepts: locators, arcs, behaviors, and semantics. <emph>Locators</emph> define where the actual resource is located. <emph>Arcs</emph> define the traversal of links. Where does the link come from? Where does it go to? All this information can be stored in the arc attributes. <emph>Behaviors</emph> define how the link is activated, and what the application should do with the resource being linked to. <emph>Semantics</emph> define useful information that the application may use, and enables the link for such specalized targets as constricted devices and accessibility software.</p>\n"
+ " \n"
+ " <div2 id=\"link-locators\">\n"
+ " <head>Locator Attributes</head>\n"
+ " <p>The only locator attribute at this time is <code>href</code>. This attribute must contain either a string in the form of a URI that defines the remote resource being linked to, a string containing a fragment identifier that links to a local resource, or a string containing a URI with a fragment identifier concacenated onto it.</p>\n"
+ " </div2>\n"
+ "\n"
+ " <div2 id=\"link-arcs\">\n"
+ " <head>Arc Attributes</head>\n"
+ " <p>Arcs contain two attributes, <code>from</code> and <code>to</code>. The <code>from</code> attribute may contain a string containing the content of a <code>role</code> attribute from the resource being linked from. The purpose of the <code>from</code> attribute is to define where this link is being actuated from.</p>\n"
+ " <p>The <code>to</code> attribute may contain a string containing the content of a <code>role</code> attribute from the resource being linked to. The purpose of the <code>to</code> attribute is to define where this link traverses to.</p>\n"
+ " <p>The application may use this information in a number of ways, especially in a complex hypertext system, but it is mainly useful in providing context for application behavior.</p>\n"
+ " <!-- I'm at a loss as to how to describe arcs more clearly than this. I don't want to devolve into discussions of directed graphs and n-ary links. -bent -->\n"
+ " </div2>\n"
+ "\n"
+ " <div2 id=\"link-behaviors\">\n"
+ " <head>Behavior Attributes</head>\n"
+ " <p>There are two attributes associated with behavior: <code>show</code> and <code>actuate</code>. The <code>show</code> attribute defines how the remote resource is to be revealed to the user. It has three options: <code>new</code>, <code>parsed</code>, and <code>replace</code>. The <code>new</code> option indicates that the remote resource should be shown in a new window (or other device context) without replacing the previous content. The <code>parsed</code> option, relating directly to the XML concept of a parsed entity, indicates that the content should be integrated into the document from which the link was actuated. The <code>replace</code> option is the one most commonly seen on the World Wide Web, where the document being linked from is entirely replaced by the object being linked to.</p>\n"
+ " <p>The <code>actuate</code> attribute defines how the link is initiated. It has two options: <code>user</code> and <code>auto</code>. The <code>user</code> option indicates that the link must be initiated by some sort of human-initiated selection, such as clicking on an HTML anchor. The <code>auto</code> option indicates that the link is automatically initiated when the application deems that the user has reached the link. It then follows the behavior set out in the <code>show</code> option.</p>\n"
+ " <!-- Something should be put here in terms of an example. Idea: \"A\" link versus automatically updating encyclopedia. -bent -->\n"
+ " </div2>\n"
+ "\n"
+ " <div2 id=\"link-semantics\">\n"
+ " <head>Semantic Attributes</head>\n"
+ " <p>There are two attributes associated with semantics, <code>role</code> and <code>title</code>. The <code>role</code> attribute is a generic string used to describe the function of the link's content. For example, a poem might have a link with a <code>role=\"stanza\"</code>. The <code>role</code> is also used as an identifier for the <code>from</code> and <code>to</code> attributes of arcs.</p>\n"
+ " <p>The <code>title</code> attribute is designed to provide human-readable text describing the link. It is very useful for those who have text-based applications, whether that be due to a constricted device that cannot display the link's content, or if it's being read by an application to a visually-impaired user, or if it's being used to create a table of links. The <code>title</code> attribute contains a simple, descriptive string.</p>\n"
+ " </div2>\n"
+ "</div1>\n"
+ "\n"
+ "<div1 id=\"linking-elements\">\n"
+ " <head>Linking Elements</head>\n"
+ " <p>There are several kinds of linking elements in XLink: <code>simple</code> links, <code>locators</code>, <code>arcs</code>, and <code>extended</code> links. These elements may be instantiated via element declarations from the XLink namespace, or they may be instantiated via attribute declarations from the XLink namespace. Both kinds of instantiation are described in the definition of each linking element.</p>\n"
+ " <p>The <code>simple</code> link is used to declare a link that approximates the functionality of the HTML <code>A</code> element. It has, however, a few added features to increase its value, including the potential declaration of semantics and behavior. The <code>locator</code> elements are used to define the resource being linked to. Some links may contain multiple locators, representing a choice of potential links to be traversed. The <code>arcs</code> are used to define the traversal semantics of the link. Finally, an <code>extended</code> linking element differs from a simple link in that it can connect any number of resources, not just one local resource (optionally) and one remote resource, and in that extended links are more often out-of-line than simple links.</p>\n"
+ "\n"
+ "<div2 id=\"simple-links\">\n"
+ " <head>Simple Links</head>\n"
+ " <p id=\"dt-simplelink\"><termdef id=\"dt-simpleline\" term=\"Simple Link\"><term>Simple links</term> can be used for purposes that approximate the functionality of a basic HTML <code>A</code> link, but they can also support a limited amount of additional functionality. Simple links have only one locator and thus, for convenience, combine the functions of a linking element and a locator into a single element.</termdef> As a result of this combination, the simple linking element offers both a locator attribute and all the behavior and semantic attributes.</p>\n"
+ " <p>The following are two examples of linking elements, each showing all the possible attributes that can be associated with a simple link. Here is the explicit XLink simple linking element.\n"
+ " <eg>&lt;!ELEMENT xlink:simple ANY&gt;\n"
+ "&lt;!ATTLIST xlink:slink\n"
+ " href CDATA #REQUIRED\n"
+ " role CDATA #IMPLIED\n"
+ " title CDATA #IMPLIED\n"
+ " show (new|parsed|replace) \"replace\"\n"
+ " actuate (user|auto) \"user\"\n"
+ "&gt;</eg>\n"
+ " And here is how to make an arbitrary element into a simple link.\n"
+ " <eg>&lt;!ELEMENT xlink:simple ANY&gt;\n"
+ "&lt;!ATTLIST foo\n"
+ " xlink:type (simple|extended|locator|arc) #FIXED \"simple\" \n"
+ " xlink:href CDATA #REQUIRED\n"
+ " xlink:role CDATA #IMPLIED\n"
+ " xlink:title CDATA #IMPLIED\n"
+ " xlink:show (new|parsed|replace) \"replace\"\n"
+ " xlink:actuate (user|auto) \"user\"\n"
+ "&gt;</eg>\n"
+ " Here is how the first example might look in a document:\n"
+ "<eg>&lt;xlink:simple href=\"http://www.w3.org/TR/wd-xlink\" role=\"working draft\" \n"
+ " title=\"The XLink Working Draft\" show=\"replace\" actuate=\"user\"&gt;\n"
+ "The XLink Working Draft.&lt;/xlink:simple&gt;</eg>\n"
+ "<eg>&lt;foo xlink:href=\"http://www.w3.org/TR/wd-xlink\" xlink:role=\"working draft\"\n"
+ " xlink:title=\"The XLink Working Draft\" xlink:show=\"new\" xlink:actuate=\"user\"&gt;\n"
+ "The XLink Working Draft.&lt;/foo&gt;</eg>\n"
+ " Alternately, a simple link could be as terse as this:\n"
+ "<eg>&lt;foo xlink:href=\"#stanza1\"&gt;The First Stanza.&lt;/foo&gt;</eg>\n"
+ " </p>\n"
+ " <p>\n"
+ " There are no constraints on the contents of a simple linking element. In\n"
+ " the sample declaration above, it is given a content model of <code>ANY</code>\n"
+ " to illustrate that any content model or declared content is acceptable. In\n"
+ " a valid document, every element that is significant to XLink must still conform\n"
+ " to the constraints expressed in its governing DTD.</p>\n"
+ " <p>Note that it is meaningful to have an out-of-line simple link, although\n"
+ " such links are uncommon. They are called \"one-ended\" and are typically used\n"
+ " to associate discrete semantic properties with locations. The properties might\n"
+ " be expressed by attributes on the link, the link's element type name, or in\n"
+ " some other way, and are not considered full-fledged resources of the link.\n"
+ " Most out-of-line links are extended links, as these have a far wider range\n"
+ " of uses.</p>\n"
+ "</div2>\n"
+ "\n"
+ "<div2 id=\"extended-link\">\n"
+ "<head>Extended Links</head>\n"
+ " <p><termdef id=\"dt-extendedlink\" term=\"Extended Link\">An <term>extended link</term> differs from a simple link in that it can connect any number of resources, not just one local resource (optionally) and one remote resource, and in that extended links are more often out-of-line than simple links.</termdef></p>\n"
+ " <p>These additional capabilities of extended links are required for: \n"
+ " <ulist>\n"
+ " <item>\n"
+ " <p>Enabling outgoing links in documents that cannot be modified to add an inline link</p>\n"
+ " </item>\n"
+ " <item>\n"
+ " <p>Creating links to and from resources in formats with no native support for embedded links (such as most multimedia formats)</p>\n"
+ " </item>\n"
+ " <item>\n"
+ " <p>Applying and filtering sets of relevant links on demand</p>\n"
+ " </item>\n"
+ " <item><p>Enabling other advanced hypermedia capabilities</p></item>\n"
+ " </ulist>\n"
+ " </p>\n"
+ " <p>Application software might be expected to provide traversal among all of a link's participating resources (subject to semantic constraints outside the scope of this specification) and to signal the fact that a given resource or sub-resource participates in one or more links when it is displayed (even though there is no markup at exactly that point to signal it).</p>\n"
+ " <p>A linking element for an extended link contains a series of <xtermref href=\"http://www.w3.org/TR/REC-xml/#dt-parentchild\">child elements</xtermref> that serve as locators and arcs. Because an extended link can have more than one remote resource, it separates out linking itself from the mechanisms used to locate each resource (whereas a simple link combines the two).</p>\n"
+ " <p>The <code>xlink:type</code> attribute value for an extended link must be <code> extended</code>, if the link is being instantiated on an arbitrary element. Note that extended links introduce variants of the <code>show</code> and <code>actuate</code> behavior attributes. These attributes, the <code>showdefault</code> and <code>actuatedefault</code> define the same behavior as their counterparts. However, in this case, they are considered to define the default behavior for all the linking elements that they contain.</p>\n"
+ " <p>However, when a linking element within an extended link has a <code>show</code> or <code>actuate</code> attribute of its own, that attribute overrides the defaults set on the extended linking element.</p>\n"
+ " <p>The extended linking element itself retains those attributes relevant to the link as a whole, and to its local resource if any. Following are two sample declaration for an extended link. The first is an example of the explicit XLink extended link:\n"
+ " \n"
+ "<eg>&lt;!ELEMENT xlink:extended ((xlink:arc | xlink:locator)*)>\n"
+ "&lt;!ATTLIST xlink:extended\n"
+ " role CDATA #IMPLIED\n"
+ " title CDATA #IMPLIED\n"
+ " showdefault (new|parsed|replace) #IMPLIED \n"
+ " actuatedefault (user|auto) #IMPLIED &gt;</eg>\n"
+ "\n"
+ " The second is an example of an arbitrary element being used an extended link:\n"
+ "\n"
+ "<eg>&lt;!ELEMENT foo ((xlink:arc | xlink:locator)*)>\n"
+ "&lt;!ATTLIST foo\n"
+ " xlink:type (simple|extended|locator|arc) #FIXED \"extended\"\n"
+ " xlink:role CDATA #IMPLIED\n"
+ " xlink:title CDATA #IMPLIED\n"
+ " xlink:showdefault (new|parsed|replace) #IMPLIED \n"
+ " xlink:actuatedefault (user|auto) #IMPLIED &gt;</eg>\n"
+ "\n"
+ " The following two examples demonstrate how each of the above might appear within a document instance. Note that the content of these examples would be other elements. For brevity's sake, they've been left blank. The first example shows how the link might appear, using an explicit XLink extended link:\n"
+ "\n"
+ "<eg>&lt;xlink:extended role=\"address book\" title=\"Ben's Address Book\" showdefault=\"replace\" actuatedefault=\"user\"&gt; ... &lt;/xlink:extended&gt;</eg>\n"
+ "\n"
+ " And the second shows how the link might appear, using an arbitrary element:\n"
+ "\n"
+ "<eg>&lt;foo xlink:type=\"extended\" xlink:role=\"address book\" xlink:title=\"Ben's Address Book\" xlink:showdefault=\"replace\" xlink:actuatedefault=\"user\"&gt; ... &lt;/foo&gt;</eg>\n"
+ " </p>\n"
+ "\n"
+ "</div2>\n"
+ "\n"
+ "<div2 id=\"xlink-arcs\">\n"
+ " <head>Arc Elements</head>\n"
+ " <p><termdef id=\"dt-arc\" term=\"Arc\">An <term>arc</term> is contained within an extended link for the purpose of defining traversal behavior.</termdef> More than one arc may be associated with a link. Otherwise, arc elements function exactly as the arc attributes might lead on to expect.</p>\n"
+ " <!-- More here? -bent -->\n"
+ "</div2>\n"
+ "\n"
+ "</div1>\n"
+ "<div1>\n"
+ "<head>Conformance</head>\n"
+ "<p>An element conforms to XLink if: <olist>\n"
+ "<item><p>The element has an <code>xml:link</code> attribute whose value is\n"
+ "one of the attribute values prescribed by this specification, and</p></item>\n"
+ "<item><p>the element and all of its attributes and content adhere to the\n"
+ "syntactic\n"
+ "requirements imposed by the chosen <code>xml:link</code> attribute value,\n"
+ "as prescribed in this specification.</p></item>\n"
+ "</olist></p>\n"
+ "<p>Note that conformance is assessed at the level of individual elements,\n"
+ "rather than whole XML documents, because XLink and non-XLink linking mechanisms\n"
+ "may be used side by side in any one document.</p>\n"
+ "<p>An application conforms to XLink if it interprets XLink-conforming elements\n"
+ "according to all required semantics prescribed by this specification and,\n"
+ "for any optional semantics it chooses to support, supports them in the way\n"
+ "prescribed. <!--If/when we split out the XLinkfunctionality\n"
+ "(e.g. inline links and out-of-line links), the\n"
+ "conformance language will have to address the different\n"
+ "levels of support. -elm--> </p>\n"
+ "</div1>\n"
+ "</body><back>\n"
+ "<div1 id=\"unfinished\">\n"
+ "<head>Unfinished Work</head>\n"
+ "<div2>\n"
+ "<head>Structured Titles</head>\n"
+ "<p>The simple title mechanism described in this draft is insufficient to cope\n"
+ "with internationalization or the use of multimedia in link titles. A future\n"
+ "version will provide a mechanism for the use of structured link titles.</p>\n"
+ "</div2>\n"
+ "</div1>\n"
+ "<div1>\n"
+ "<head>References</head>\n"
+ "<blist>\n"
+ "<bibl id=\"xptr\" key=\"XPTR\">Eve Maler and Steve DeRose, editors. <titleref>\n"
+ "XML Pointer Language (XPointer) V1.0</titleref>. ArborText, Inso, and Brown\n"
+ "University. Burlington, Seekonk, et al.: World Wide Web Consortium, 1998.\n"
+ "(See <loc href=\"http://www.w3.org/TR/WD-xptr\">http://www.w3.org/TR/WD-xptr\n"
+ " </loc>.)</bibl>\n"
+ "<bibl id=\"iso10744\" key=\"ISO/IEC 10744\">ISO (International Organization for\n"
+ "Standardization). <titleref>ISO/IEC 10744-1992 (E). Information technology\n"
+ "- Hypermedia/Time-based Structuring Language (HyTime).</titleref> [Geneva]:\n"
+ "International Organization for Standardization, 1992. <titleref>Extended\n"
+ "Facilities\n"
+ "Annex.</titleref> [Geneva]: International Organization for Standardization,\n"
+ "1996. (See <loc\n"
+ "href=\"http://www.ornl.gov/sgml/wg8/hytime/html/is10744r.html\">http://www.ornl.go\n"
+ "v/sgml/wg8/hytime/html/is10744r.html </loc> <!--p m-r says this link is\n"
+ "broken. elm --> ).</bibl>\n"
+ "<bibl id=\"rfc1738\" key=\"IETF RFC 1738\">IETF (Internet Engineering Task\n"
+ "Force). <titleref>\n"
+ "RFC 1738: Uniform Resource Locators</titleref>. 1991. (See <loc\n"
+ "href=\"http://www.w3.org/Addressing/rfc1738.txt\">\n"
+ "http://www.w3.org/Addressing/rfc1738.txt</loc>).</bibl>\n"
+ "<bibl id=\"rfc1808\" key=\"IETF RFC 1808\">IETF (Internet Engineering Task\n"
+ "Force). <titleref>\n"
+ "RFC 1808: Relative Uniform Resource Locators</titleref>. 1995. (See <loc\n"
+ "href=\"http://www.w3.org/Addressing/rfc1808.txt\">http://www.w3.org/Addressing/rfc\n"
+ "1808.txt </loc>).</bibl>\n"
+ "<bibl id=\"tei\" key=\"TEI\">C. M. Sperberg-McQueen and Lou Burnard, editors.\n"
+ "<titleref>\n"
+ "Guidelines for Electronic Text Encoding and Interchange</titleref>. Association\n"
+ "for Computers and the Humanities (ACH), Association for Computational\n"
+ "Linguistics\n"
+ "(ACL), and Association for Literary and Linguistic Computing (ALLC). Chicago,\n"
+ "Oxford: Text Encoding Initiative, 1994. <!-- add cite to DOM work --> </bibl>\n"
+ "<bibl id=\"chum\" key=\"CHUM\">]Steven J. DeRose and David G. Durand. 1995. \"The\n"
+ "TEI Hypertext Guidelines.\" In <titleref>Computing and the Humanities\n"
+ "</titleref>29(3).\n"
+ "Reprinted in <titleref>Text Encoding Initiative: Background and\n"
+ "Context</titleref>,\n"
+ "ed. Nancy Ide and Jean ronis <!-- fix this name -->, ISBN 0-7923-3704-2. </bibl>\n"
+ "</blist></div1>\n"
+ "</back></spec>\n"
+ "<?Pub *0000052575?>\n";
+
+// Correct
+const char *ok_data_4 =
+ "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
+ "<!DOCTYPE rss [\n"
+ "<!--\n"
+ "\n"
+ " Rich Site Summary (RSS) 0.91 official DTD, proposed.\n"
+ " \n"
+ " RSS is an XML vocabulary for describing\n"
+ " metadata about websites, and enabling the display of\n"
+ " \"channels\" on the \"My Netscape\" website.\n"
+ " \n"
+ " RSS Info can be found at http://my.netscape.com/publish/\n"
+ " XML Info can be found at http://www.w3.org/XML/ \n"
+ " \n"
+ " copyright Netscape Communications, 1999\n"
+ "\n"
+ " Dan Libby - danda@netscape.com\n"
+ " \n"
+ " Based on RSS DTD originally created by\n"
+ " Lars Marius Garshol - larsga@ifi.uio.no.\n"
+ " \n"
+ "-->\n"
+ "<!ELEMENT rss (channel)>\n"
+ "<!ATTLIST rss version CDATA #REQUIRED>\n"
+ "<!-- must be \"0.91\"> --><!ELEMENT channel (title | description | link \n"
+ "| language | item+ | rating? | image? | textinput? | copyright? | \n"
+ "pubDate? | lastBuildDate? | docs? | managingEditor? | webMaster? | \n"
+ "skipHours? | skipDays?)*>\n"
+ "<!ELEMENT title (#PCDATA)>\n"
+ "<!ELEMENT description (#PCDATA)>\n"
+ "<!ELEMENT link (#PCDATA)>\n"
+ "<!ELEMENT image (title | url | link | width? | height? | description?)*>\n"
+ "<!ELEMENT url (#PCDATA)>\n"
+ "<!ELEMENT item (title | link | description)*>\n"
+ "<!ELEMENT textinput (title | description | name | link)*>\n"
+ "<!ELEMENT name (#PCDATA)>\n"
+ "<!ELEMENT rating (#PCDATA)>\n"
+ "<!ELEMENT language (#PCDATA)>\n"
+ "<!ELEMENT width (#PCDATA)>\n"
+ "<!ELEMENT height (#PCDATA)>\n"
+ "<!ELEMENT copyright (#PCDATA)>\n"
+ "<!ELEMENT pubDate (#PCDATA)>\n"
+ "<!ELEMENT lastBuildDate (#PCDATA)>\n"
+ "<!ELEMENT docs (#PCDATA)>\n"
+ "<!ELEMENT managingEditor (#PCDATA)>\n"
+ "<!ELEMENT webMaster (#PCDATA)>\n"
+ "<!ELEMENT hour (#PCDATA)>\n"
+ "<!ELEMENT day (#PCDATA)>\n"
+ "<!ELEMENT skipHours (hour)+>\n"
+ "<!ELEMENT skipDays (day)+>\n"
+ "<!--\n"
+ " Copied from HTML 3.2 DTD, with modifications (removed CDATA)\n"
+ " http://www.w3.org/TR/REC-html32.html#dtd\n"
+ " =============== BEGIN ===================\n"
+ "-->\n"
+ "<!-- \n"
+ " Character Entities for ISO Latin-1\n"
+ " \n"
+ " (C) International Organization for Standardization 1986\n"
+ " Permission to copy in any form is granted for use with\n"
+ " conforming SGML systems and applications as defined in\n"
+ " ISO 8879, provided this notice is included in all copies.\n"
+ " This has been extended for use with HTML to cover the full\n"
+ " set of codes in the range 160-255 decimal.\n"
+ "-->\n"
+ "<!-- Character entity set. Typical invocation:\n"
+ " <!ENTITY % ISOlat1 PUBLIC\n"
+ " \"ISO 8879-1986//ENTITIES Added Latin 1//EN//HTML\">\n"
+ " %ISOlat1;\n"
+ "-->\n"
+ "<!ENTITY nbsp \"&#160;\"> <!-- no-break space -->\n"
+ "<!ENTITY iexcl \"&#161;\">\n"
+ "<!-- inverted exclamation mark --><!ENTITY cent \"&#162;\">\n"
+ "<!-- cent sign --><!ENTITY pound \"&#163;\">\n"
+ "<!-- pound sterling sign --><!ENTITY curren \"&#164;\">\n"
+ "<!-- general currency sign --><!ENTITY yen \"&#165;\">\n"
+ "<!-- yen sign --><!ENTITY brvbar \"&#166;\">\n"
+ "<!-- broken (vertical) bar --><!ENTITY sect \"&#167;\">\n"
+ "<!-- section sign --><!ENTITY uml \"&#168;\">\n"
+ "<!-- umlaut (dieresis) --><!ENTITY copy \"&#169;\">\n"
+ "<!-- copyright sign --><!ENTITY ordf \"&#170;\">\n"
+ "<!-- ordinal indicator, feminine --><!ENTITY laquo \"&#171;\">\n"
+ "<!-- angle quotation mark, left --><!ENTITY not \"&#172;\">\n"
+ "<!-- not sign --><!ENTITY shy \"&#173;\">\n"
+ "<!-- soft hyphen --><!ENTITY reg \"&#174;\">\n"
+ "<!-- registered sign --><!ENTITY macr \"&#175;\">\n"
+ "<!-- macron --><!ENTITY deg \"&#176;\">\n"
+ "<!-- degree sign --><!ENTITY plusmn \"&#177;\">\n"
+ "<!-- plus-or-minus sign --><!ENTITY sup2 \"&#178;\">\n"
+ "<!-- superscript two --><!ENTITY sup3 \"&#179;\">\n"
+ "<!-- superscript three --><!ENTITY acute \"&#180;\">\n"
+ "<!-- acute accent --><!ENTITY micro \"&#181;\">\n"
+ "<!-- micro sign --><!ENTITY para \"&#182;\">\n"
+ "<!-- pilcrow (paragraph sign) --><!ENTITY middot \"&#183;\">\n"
+ "<!-- middle dot --><!ENTITY cedil \"&#184;\">\n"
+ "<!-- cedilla --><!ENTITY sup1 \"&#185;\">\n"
+ "<!-- superscript one --><!ENTITY ordm \"&#186;\">\n"
+ "<!-- ordinal indicator, masculine --><!ENTITY raquo \"&#187;\">\n"
+ "<!-- angle quotation mark, right --><!ENTITY frac14 \"&#188;\">\n"
+ "<!-- fraction one-quarter --><!ENTITY frac12 \"&#189;\">\n"
+ "<!-- fraction one-half --><!ENTITY frac34 \"&#190;\">\n"
+ "<!-- fraction three-quarters --><!ENTITY iquest \"&#191;\">\n"
+ "<!-- inverted question mark --><!ENTITY Agrave \"&#192;\">\n"
+ "<!-- capital A, grave accent --><!ENTITY Aacute \"&#193;\">\n"
+ "<!-- capital A, acute accent --><!ENTITY Acirc \"&#194;\">\n"
+ "<!-- capital A, circumflex accent --><!ENTITY Atilde \"&#195;\">\n"
+ "<!-- capital A, tilde --><!ENTITY Auml \"&#196;\">\n"
+ "<!-- capital A, dieresis or umlaut mark --><!ENTITY Aring \"&#197;\">\n"
+ "<!-- capital A, ring --><!ENTITY AElig \"&#198;\">\n"
+ "<!-- capital AE diphthong (ligature) --><!ENTITY Ccedil \"&#199;\">\n"
+ "<!-- capital C, cedilla --><!ENTITY Egrave \"&#200;\">\n"
+ "<!-- capital E, grave accent --><!ENTITY Eacute \"&#201;\">\n"
+ "<!-- capital E, acute accent --><!ENTITY Ecirc \"&#202;\">\n"
+ "<!-- capital E, circumflex accent --><!ENTITY Euml \"&#203;\">\n"
+ "<!-- capital E, dieresis or umlaut mark --><!ENTITY Igrave \"&#204;\">\n"
+ "<!-- capital I, grave accent --><!ENTITY Iacute \"&#205;\">\n"
+ "<!-- capital I, acute accent --><!ENTITY Icirc \"&#206;\">\n"
+ "<!-- capital I, circumflex accent --><!ENTITY Iuml \"&#207;\">\n"
+ "<!-- capital I, dieresis or umlaut mark --><!ENTITY ETH \"&#208;\">\n"
+ "<!-- capital Eth, Icelandic --><!ENTITY Ntilde \"&#209;\">\n"
+ "<!-- capital N, tilde --><!ENTITY Ograve \"&#210;\">\n"
+ "<!-- capital O, grave accent --><!ENTITY Oacute \"&#211;\">\n"
+ "<!-- capital O, acute accent --><!ENTITY Ocirc \"&#212;\">\n"
+ "<!-- capital O, circumflex accent --><!ENTITY Otilde \"&#213;\">\n"
+ "<!-- capital O, tilde --><!ENTITY Ouml \"&#214;\">\n"
+ "<!-- capital O, dieresis or umlaut mark --><!ENTITY times \"&#215;\">\n"
+ "<!-- multiply sign --><!ENTITY Oslash \"&#216;\">\n"
+ "<!-- capital O, slash --><!ENTITY Ugrave \"&#217;\">\n"
+ "<!-- capital U, grave accent --><!ENTITY Uacute \"&#218;\">\n"
+ "<!-- capital U, acute accent --><!ENTITY Ucirc \"&#219;\">\n"
+ "<!-- capital U, circumflex accent --><!ENTITY Uuml \"&#220;\">\n"
+ "<!-- capital U, dieresis or umlaut mark --><!ENTITY Yacute \"&#221;\">\n"
+ "<!-- capital Y, acute accent --><!ENTITY THORN \"&#222;\">\n"
+ "<!-- capital THORN, Icelandic --><!ENTITY szlig \"&#223;\">\n"
+ "<!-- small sharp s, German (sz ligature) --><!ENTITY agrave \"&#224;\">\n"
+ "<!-- small a, grave accent --><!ENTITY aacute \"&#225;\">\n"
+ "<!-- small a, acute accent --><!ENTITY acirc \"&#226;\">\n"
+ "<!-- small a, circumflex accent --><!ENTITY atilde \"&#227;\">\n"
+ "<!-- small a, tilde --><!ENTITY auml \"&#228;\">\n"
+ "<!-- small a, dieresis or umlaut mark --><!ENTITY aring \"&#229;\">\n"
+ "<!-- small a, ring --><!ENTITY aelig \"&#230;\">\n"
+ "<!-- small ae diphthong (ligature) --><!ENTITY ccedil \"&#231;\">\n"
+ "<!-- small c, cedilla --><!ENTITY egrave \"&#232;\">\n"
+ "<!-- small e, grave accent --><!ENTITY eacute \"&#233;\">\n"
+ "<!-- small e, acute accent --><!ENTITY ecirc \"&#234;\">\n"
+ "<!-- small e, circumflex accent --><!ENTITY euml \"&#235;\">\n"
+ "<!-- small e, dieresis or umlaut mark --><!ENTITY igrave \"&#236;\">\n"
+ "<!-- small i, grave accent --><!ENTITY iacute \"&#237;\">\n"
+ "<!-- small i, acute accent --><!ENTITY icirc \"&#238;\">\n"
+ "<!-- small i, circumflex accent --><!ENTITY iuml \"&#239;\">\n"
+ "<!-- small i, dieresis or umlaut mark --><!ENTITY eth \"&#240;\">\n"
+ "<!-- small eth, Icelandic --><!ENTITY ntilde \"&#241;\">\n"
+ "<!-- small n, tilde --><!ENTITY ograve \"&#242;\">\n"
+ "<!-- small o, grave accent --><!ENTITY oacute \"&#243;\">\n"
+ "<!-- small o, acute accent --><!ENTITY ocirc \"&#244;\">\n"
+ "<!-- small o, circumflex accent --><!ENTITY otilde \"&#245;\">\n"
+ "<!-- small o, tilde --><!ENTITY ouml \"&#246;\">\n"
+ "<!-- small o, dieresis or umlaut mark --><!ENTITY divide \"&#247;\">\n"
+ "<!-- divide sign --><!ENTITY oslash \"&#248;\">\n"
+ "<!-- small o, slash --><!ENTITY ugrave \"&#249;\">\n"
+ "<!-- small u, grave accent --><!ENTITY uacute \"&#250;\">\n"
+ "<!-- small u, acute accent --><!ENTITY ucirc \"&#251;\">\n"
+ "<!-- small u, circumflex accent --><!ENTITY uuml \"&#252;\">\n"
+ "<!-- small u, dieresis or umlaut mark --><!ENTITY yacute \"&#253;\">\n"
+ "<!-- small y, acute accent --><!ENTITY thorn \"&#254;\">\n"
+ "<!-- small thorn, Icelandic --><!ENTITY yuml \"&#255;\">\n"
+ "<!-- small y, dieresis or umlaut mark --><!--\n"
+ " Copied from HTML 3.2 DTD, with modifications (removed CDATA)\n"
+ " http://www.w3.org/TR/REC-html32.html#dtd\n"
+ " ================= END ===================\n"
+ "-->\n"
+ "]>\n"
+ "<rss>\n"
+ "<channel>\n"
+ "<image/>\n"
+ "<title>PP</title>\n"
+ "</channel>\n"
+ "</rss>\n";
+
+// Correct, with UTF-8 data
+const char ok_data_5[] =
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" /*39 chars*/
+ "<doc>\xC3\xA4</doc>";
+
+// Erroneous
+const char *error_data_1 =
+ "a"; // bogus character
+
+// Erroneous
+const char *error_data_2 =
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<start>"; // XML tag not closed
+
+const char *bug_data_pr2855 =
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<start> notrim</start>";
+
+// byte order mark
+const char *bug_data_pr1678 =
+ "\xEF\xBB\xBF<?xml version=\"1.0\" encoding=\"utf-8\"?><root/>";
+
+// russian
+const char *bug_data_pr5203 =
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<name>\xD0\xAE\xD0\xBD\xD0\xB8\xD1\x82</name>";
+
+// Quoting attributes
+const char *bug_data_pr4840 =
+ "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<start a=\"hello &quot;world&quot;\"/>";
+
+#endif