diff --git a/examples/custom_data_type.cpp b/examples/custom_data_type.cpp new file mode 100644 index 0000000..86097e9 --- /dev/null +++ b/examples/custom_data_type.cpp @@ -0,0 +1,80 @@ +// ---------------------------------------------------------------------------- +// 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 +#include +#include +#include +#include +#include +#include +#include +#include + +// Custom translator that works with boost::any instead of std::string +struct my_translator +{ + + // Custom extractor - converts data from boost::any to T + template + bool get_value(const Ptree &pt, T &value) const + { + value = boost::any_cast(pt.data()); + return true; // Success + } + + // Custom inserter - converts data from T to boost::any + template + bool put_value(Ptree &pt, const T &value) const + { + pt.data() = value; + return true; + } + +}; + +int main() +{ + + using namespace boost::property_tree; + + // Property_tree with boost::any as data type + // Key comparison: std::less + // Key type: std::string + // Path type: path + // Data type: boost::any + // Translator type: my_translator + typedef basic_ptree, std::string, path, boost::any, my_translator> my_ptree; + my_ptree pt; + + // Put/get int value + pt.put("int value", 3); + int int_value = pt.get("int value"); + std::cout << "Int value: " << int_value << "\n"; + + // Put/get string value + pt.put("string value", "foo bar"); + std::string string_value = pt.get("string value"); + std::cout << "String value: " << string_value << "\n"; + + // Put/get list value + int list_data[] = { 1, 2, 3, 4, 5 }; + pt.put >("list value", std::list(list_data, list_data + sizeof(list_data) / sizeof(*list_data))); + std::list list_value = pt.get >("list value"); + std::cout << "List value: "; + for (std::list::iterator it = list_value.begin(); it != list_value.end(); ++it) + std::cout << *it << ' '; + std::cout << '\n'; +} diff --git a/examples/debug_settings.cpp b/examples/debug_settings.cpp new file mode 100644 index 0000000..f7bcef7 --- /dev/null +++ b/examples/debug_settings.cpp @@ -0,0 +1,109 @@ +// ---------------------------------------------------------------------------- +// 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 +#include +//#include +#include +#include +#include +#include + +struct debug_settings +{ + std::string m_file; // log filename + int m_level; // debug level + std::set m_modules; // modules where logging is enabled + void load(const std::string &filename); + void save(const std::string &filename); +}; + +void debug_settings::load(const std::string &filename) +{ + + // Create empty property tree object + using boost::property_tree::ptree; + ptree pt; + + // Load XML file and put its contents in property tree. + // No namespace qualification is needed, because of Koenig + // lookup on the second argument. If reading fails, exception + // is thrown. + read_xml(filename, pt); + + // Get filename and store it in m_file variable. Note that + // we specify a path to the value using notation where keys + // are separated with dots (different separator may be used + // if keys themselves contain dots). If debug.filename key is + // not found, exception is thrown. + m_file = pt.get("debug.filename"); + + // Get debug level and store it in m_level variable. This is + // another version of get method: if debug.level key is not + // found, it will return default value (specified by second + // parameter) instead of throwing. Type of the value extracted + // is determined by type of second parameter, so we can simply + // write get(...) instead of get(...). + m_level = pt.get("debug.level", 0); + + // Iterate over debug.modules section and store all found + // modules in m_modules set. get_child() function returns a + // reference to child at specified path; if there is no such + // child, it throws. Property tree iterator can be used in + // the same way as standard container iterator. Category + // is bidirectional_iterator. + //BOOST_FOREACH(ptree::value_type &v, pt.get_child("debug.modules")) + // m_modules.insert(v.second.data()); + +} + +void debug_settings::save(const std::string &filename) +{ + + // Create empty property tree object + using boost::property_tree::ptree; + ptree pt; + + // Put log filename in property tree + pt.put("debug.filename", m_file); + + // Put debug level in property tree + pt.put("debug.level", m_level); + + // Iterate over modules in set and put them in property + // tree. Note that put function places new key at the + // end of list of keys. This is fine in most of the + // situations. If you want to place item at some other + // place (i.e. at front or somewhere in the middle), + // this can be achieved using combination of insert + // and put_value functions + //BOOST_FOREACH(const std::string &name, m_modules) + // pt.put("debug.modules.module", name, true); + + // Write property tree to XML file + write_xml(filename, pt); + +} + +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/examples/debug_settings.xml b/examples/debug_settings.xml new file mode 100644 index 0000000..9b8524a --- /dev/null +++ b/examples/debug_settings.xml @@ -0,0 +1,10 @@ + + + debug.log + + Finance + Admin + HR + + 2 + diff --git a/examples/empty_ptree_trick.cpp b/examples/empty_ptree_trick.cpp new file mode 100644 index 0000000..37285b2 --- /dev/null +++ b/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 +#include +#include +#include +#include + +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()); + 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 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/examples/info_grammar_spirit.cpp b/examples/info_grammar_spirit.cpp new file mode 100644 index 0000000..0702534 --- /dev/null +++ b/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 + +struct info_grammar: public boost::spirit::grammar +{ + + template + struct definition + { + + boost::spirit::rule::type> chr, qchr, escape_seq; + boost::spirit::rule 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 &start() const + { + return info; + } + + }; +}; + +void info_parse(const char *s) +{ + + using namespace boost::spirit; + + // Parse and display result + info_grammar g; + parse_info 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/examples/settings_fully-existent.info b/examples/settings_fully-existent.info new file mode 100644 index 0000000..bec7a64 --- /dev/null +++ b/examples/settings_fully-existent.info @@ -0,0 +1,6 @@ +settings +{ + setting1 15 + setting2 9.876 + setting3 Alice in Wonderland +} diff --git a/examples/settings_non-existent.info b/examples/settings_non-existent.info new file mode 100644 index 0000000..4f76b2a --- /dev/null +++ b/examples/settings_non-existent.info @@ -0,0 +1,6 @@ +;settings // non-existent +;{ +; setting1 15 +; setting2 9.876 +; setting3 Alice in Wonderland +;} diff --git a/examples/settings_partially-existent.info b/examples/settings_partially-existent.info new file mode 100644 index 0000000..ed5e8c2 --- /dev/null +++ b/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/examples/speed_test.cpp b/examples/speed_test.cpp new file mode 100644 index 0000000..176b79e --- /dev/null +++ b/examples/speed_test.cpp @@ -0,0 +1,134 @@ +// ---------------------------------------------------------------------------- +// 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 +#include +#include +#include +#include +#include + +using namespace std; +using namespace boost; +using namespace boost::property_tree; + +string dummy; +vector keys; +vector 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 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], empty_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 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/index.html b/index.html new file mode 100644 index 0000000..7974904 --- /dev/null +++ b/index.html @@ -0,0 +1,12 @@ + + + + +

+ Docs for Property Tree library not available yet.

+ + diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 new file mode 100644 index 0000000..2db2829 --- /dev/null +++ b/test/Jamfile.v2 @@ -0,0 +1,17 @@ +subproject libs/property_tree/test ; + +# bring in rules for testing +import testing ; + +# Make tests run by default. +DEPENDS all : property_tree ; + +{ + test-suite "property_tree" + : [ run test_property_tree.cpp ] + [ run test_info_parser.cpp ] + [ run test_json_parser.cpp ] + [ run test_ini_parser.cpp ] + [ run test_xml_parser_rapidxml.cpp ] + ; +} diff --git a/test/custom-build/Makefile b/test/custom-build/Makefile new file mode 100644 index 0000000..e2dd24c --- /dev/null +++ b/test/custom-build/Makefile @@ -0,0 +1,5 @@ +all: + +clean: + rm -f *_dbg.exe + rm -f *_rel.exe diff --git a/test/custom-build/Makefile-Common b/test/custom-build/Makefile-Common new file mode 100644 index 0000000..fcf9f36 --- /dev/null +++ b/test/custom-build/Makefile-Common @@ -0,0 +1,80 @@ +CCINCLUDE=-I../../../../../boost -I../../../.. + +all: test + +-include Makefile + +test: build + ./ptree_dbg.exe + ./ptree_rel.exe + ./cmdline_dbg.exe + ./cmdline_rel.exe + ./ini_dbg.exe + ./ini_rel.exe + ./info_dbg.exe + ./info_rel.exe + ./json_dbg.exe + ./json_rel.exe + ./xml_dbg.exe + ./xml_rel.exe + ./multi_module_dbg.exe + ./multi_module_rel.exe + ./example_custom_data_type_dbg.exe + ./example_custom_data_type_rel.exe + ./example_debug_settings_dbg.exe + ./example_debug_settings_rel.exe + ./example_empty_ptree_trick_dbg.exe + ./example_empty_ptree_trick_rel.exe + ./example_info_grammar_spirit_dbg.exe + ./example_info_grammar_spirit_rel.exe + +build: debug release + +debug: ptree_dbg.exe cmdline_dbg.exe ini_dbg.exe info_dbg.exe json_dbg.exe xml_dbg.exe multi_module_dbg.exe example_custom_data_type_dbg.exe example_debug_settings_dbg.exe example_empty_ptree_trick_dbg.exe example_info_grammar_spirit_dbg.exe + +release: ptree_rel.exe cmdline_rel.exe ini_rel.exe info_rel.exe json_rel.exe xml_rel.exe multi_module_rel.exe example_custom_data_type_rel.exe example_debug_settings_rel.exe example_empty_ptree_trick_rel.exe example_info_grammar_spirit_rel.exe + +ptree_dbg.exe: ../test_property_tree.cpp + $(CC) $(CFLAGSDBG) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +ptree_rel.exe: ../test_property_tree.cpp + $(CC) $(CFLAGSREL) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +cmdline_dbg.exe: ../test_cmdline_parser.cpp + $(CC) $(CFLAGSDBG) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +cmdline_rel.exe: ../test_cmdline_parser.cpp + $(CC) $(CFLAGSREL) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +ini_dbg.exe: ../test_ini_parser.cpp + $(CC) $(CFLAGSDBG) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +ini_rel.exe: ../test_ini_parser.cpp + $(CC) $(CFLAGSREL) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +info_dbg.exe: ../test_info_parser.cpp + $(CC) $(CFLAGSDBG) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +info_rel.exe: ../test_info_parser.cpp + $(CC) $(CFLAGSREL) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +json_dbg.exe: ../test_json_parser.cpp + $(CC) $(CFLAGSDBG) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +json_rel.exe: ../test_json_parser.cpp + $(CC) $(CFLAGSREL) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +xml_dbg.exe: ../test_xml_parser_spirit.cpp + $(CC) $(CFLAGSDBG) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +xml_rel.exe: ../test_xml_parser_spirit.cpp + $(CC) $(CFLAGSREL) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +multi_module_dbg.exe: ../test_multi_module1.cpp ../test_multi_module2.cpp + $(CC) $(CFLAGSDBG) $(CCINCLUDE) $(EXTINCLUDE) $? -o $@ $(EXTLIBS) +multi_module_rel.exe: ../test_multi_module1.cpp ../test_multi_module2.cpp + $(CC) $(CFLAGSREL) $(CCINCLUDE) $(EXTINCLUDE) $? -o $@ $(EXTLIBS) +example_custom_data_type_dbg.exe: ../../examples/custom_data_type.cpp + $(CC) $(CFLAGSDBG) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +example_custom_data_type_rel.exe: ../../examples/custom_data_type.cpp + $(CC) $(CFLAGSREL) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +example_debug_settings_dbg.exe: ../../examples/debug_settings.cpp + $(CC) $(CFLAGSDBG) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +example_debug_settings_rel.exe: ../../examples/debug_settings.cpp + $(CC) $(CFLAGSREL) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +example_empty_ptree_trick_dbg.exe: ../../examples/empty_ptree_trick.cpp + $(CC) $(CFLAGSDBG) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +example_empty_ptree_trick_rel.exe: ../../examples/empty_ptree_trick.cpp + $(CC) $(CFLAGSREL) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +example_info_grammar_spirit_dbg.exe: ../../examples/info_grammar_spirit.cpp + $(CC) $(CFLAGSDBG) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) +example_info_grammar_spirit_rel.exe: ../../examples/info_grammar_spirit.cpp + $(CC) $(CFLAGSREL) $(CCINCLUDE) $(EXTINCLUDE) $< -o $@ $(EXTLIBS) diff --git a/test/custom-build/debug_settings.xml b/test/custom-build/debug_settings.xml new file mode 100644 index 0000000..9b8524a --- /dev/null +++ b/test/custom-build/debug_settings.xml @@ -0,0 +1,10 @@ + + + debug.log + + Finance + Admin + HR + + 2 + diff --git a/test/custom-build/gcc.mak b/test/custom-build/gcc.mak new file mode 100644 index 0000000..bc2660b --- /dev/null +++ b/test/custom-build/gcc.mak @@ -0,0 +1,6 @@ +CC=g++ +CFLAGSREL=-Wall -pedantic -ftemplate-depth-255 -O3 +CFLAGSDBG=-Wall -pedantic -ftemplate-depth-255 -O0 +INCLUDE=-I../../../../../boost -I../../../.. + +-include Makefile-Common diff --git a/test/custom-build/icc.mak b/test/custom-build/icc.mak new file mode 100644 index 0000000..98d9d94 --- /dev/null +++ b/test/custom-build/icc.mak @@ -0,0 +1,6 @@ +CC=icc +CFLAGSREL=-O3 -static +CFLAGSDBG=-O0 -static +INCLUDE=-I../../../../../boost -I../../../.. + +-include Makefile-Common diff --git a/test/custom-build/sandbox.vcproj b/test/custom-build/sandbox.vcproj new file mode 100644 index 0000000..b7bbd5c --- /dev/null +++ b/test/custom-build/sandbox.vcproj @@ -0,0 +1,330 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/custom-build/settings_fully-existent.info b/test/custom-build/settings_fully-existent.info new file mode 100644 index 0000000..bec7a64 --- /dev/null +++ b/test/custom-build/settings_fully-existent.info @@ -0,0 +1,6 @@ +settings +{ + setting1 15 + setting2 9.876 + setting3 Alice in Wonderland +} diff --git a/test/custom-build/settings_non-existent.info b/test/custom-build/settings_non-existent.info new file mode 100644 index 0000000..4f76b2a --- /dev/null +++ b/test/custom-build/settings_non-existent.info @@ -0,0 +1,6 @@ +;settings // non-existent +;{ +; setting1 15 +; setting2 9.876 +; setting3 Alice in Wonderland +;} diff --git a/test/custom-build/settings_partially-existent.info b/test/custom-build/settings_partially-existent.info new file mode 100644 index 0000000..ed5e8c2 --- /dev/null +++ b/test/custom-build/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/test/custom-build/test_example_custom_data_type.vcproj b/test/custom-build/test_example_custom_data_type.vcproj new file mode 100644 index 0000000..e7f240c --- /dev/null +++ b/test/custom-build/test_example_custom_data_type.vcproj @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/custom-build/test_example_debug_settings.vcproj b/test/custom-build/test_example_debug_settings.vcproj new file mode 100644 index 0000000..b91c196 --- /dev/null +++ b/test/custom-build/test_example_debug_settings.vcproj @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/custom-build/test_example_empty_ptree_trick.vcproj b/test/custom-build/test_example_empty_ptree_trick.vcproj new file mode 100644 index 0000000..946c23e --- /dev/null +++ b/test/custom-build/test_example_empty_ptree_trick.vcproj @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/custom-build/test_info_grammar_spirit.vcproj b/test/custom-build/test_info_grammar_spirit.vcproj new file mode 100644 index 0000000..9f02d63 --- /dev/null +++ b/test/custom-build/test_info_grammar_spirit.vcproj @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/custom-build/test_info_parser.vcproj b/test/custom-build/test_info_parser.vcproj new file mode 100644 index 0000000..d490f80 --- /dev/null +++ b/test/custom-build/test_info_parser.vcproj @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/custom-build/test_ini_parser.vcproj b/test/custom-build/test_ini_parser.vcproj new file mode 100644 index 0000000..1129c52 --- /dev/null +++ b/test/custom-build/test_ini_parser.vcproj @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/custom-build/test_json_parser.vcproj b/test/custom-build/test_json_parser.vcproj new file mode 100644 index 0000000..6930190 --- /dev/null +++ b/test/custom-build/test_json_parser.vcproj @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/custom-build/test_multi_module.vcproj b/test/custom-build/test_multi_module.vcproj new file mode 100644 index 0000000..812bf50 --- /dev/null +++ b/test/custom-build/test_multi_module.vcproj @@ -0,0 +1,193 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/custom-build/test_property_tree.vcproj b/test/custom-build/test_property_tree.vcproj new file mode 100644 index 0000000..2ce8fd3 --- /dev/null +++ b/test/custom-build/test_property_tree.vcproj @@ -0,0 +1,194 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/custom-build/test_xml_parser.vcproj b/test/custom-build/test_xml_parser.vcproj new file mode 100644 index 0000000..bf0e110 --- /dev/null +++ b/test/custom-build/test_xml_parser.vcproj @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/custom-build/tests.sln b/test/custom-build/tests.sln new file mode 100644 index 0000000..6becf5b --- /dev/null +++ b/test/custom-build/tests.sln @@ -0,0 +1,80 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual C++ Express 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_property_tree", "test_property_tree.vcproj", "{DB0C18AA-BBA4-4DBF-A76E-92B642E45A74}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_ini_parser", "test_ini_parser.vcproj", "{20D5FE87-9284-4B1A-8505-7B913474C4AA}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_info_parser", "test_info_parser.vcproj", "{03A81E3E-895A-4E1D-A42C-EB155A2868E1}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_xml_parser", "test_xml_parser.vcproj", "{02D60AE7-3C50-45BB-AB12-ECCB22F1B9AF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sandbox", "sandbox.vcproj", "{85FA9AEF-966B-4D93-9431-F507754B0431}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_json_parser", "test_json_parser.vcproj", "{CDDC4697-F51B-4B9A-A029-C2EB5271848F}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_example_custom_data_type", "test_example_custom_data_type.vcproj", "{87516DC2-FDF4-4ECC-8713-D6D955100D86}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_example_debug_settings", "test_example_debug_settings.vcproj", "{16D41CBD-3C58-4631-B4D4-29A42E47D619}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_example_empty_ptree_trick", "test_example_empty_ptree_trick.vcproj", "{A242FE56-D039-4CEC-9FD3-AACABEA684C9}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_info_grammar_spirit", "test_info_grammar_spirit.vcproj", "{305891FE-2572-4F6A-A52B-3A1964A3CA76}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_multi_module", "test_multi_module.vcproj", "{4B88BAC5-5CA8-403A-83E7-0F758405AB2D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DB0C18AA-BBA4-4DBF-A76E-92B642E45A74}.Debug|Win32.ActiveCfg = Debug|Win32 + {DB0C18AA-BBA4-4DBF-A76E-92B642E45A74}.Debug|Win32.Build.0 = Debug|Win32 + {DB0C18AA-BBA4-4DBF-A76E-92B642E45A74}.Release|Win32.ActiveCfg = Release|Win32 + {DB0C18AA-BBA4-4DBF-A76E-92B642E45A74}.Release|Win32.Build.0 = Release|Win32 + {20D5FE87-9284-4B1A-8505-7B913474C4AA}.Debug|Win32.ActiveCfg = Debug|Win32 + {20D5FE87-9284-4B1A-8505-7B913474C4AA}.Debug|Win32.Build.0 = Debug|Win32 + {20D5FE87-9284-4B1A-8505-7B913474C4AA}.Release|Win32.ActiveCfg = Release|Win32 + {20D5FE87-9284-4B1A-8505-7B913474C4AA}.Release|Win32.Build.0 = Release|Win32 + {03A81E3E-895A-4E1D-A42C-EB155A2868E1}.Debug|Win32.ActiveCfg = Debug|Win32 + {03A81E3E-895A-4E1D-A42C-EB155A2868E1}.Debug|Win32.Build.0 = Debug|Win32 + {03A81E3E-895A-4E1D-A42C-EB155A2868E1}.Release|Win32.ActiveCfg = Release|Win32 + {03A81E3E-895A-4E1D-A42C-EB155A2868E1}.Release|Win32.Build.0 = Release|Win32 + {02D60AE7-3C50-45BB-AB12-ECCB22F1B9AF}.Debug|Win32.ActiveCfg = Debug|Win32 + {02D60AE7-3C50-45BB-AB12-ECCB22F1B9AF}.Debug|Win32.Build.0 = Debug|Win32 + {02D60AE7-3C50-45BB-AB12-ECCB22F1B9AF}.Release|Win32.ActiveCfg = Release|Win32 + {02D60AE7-3C50-45BB-AB12-ECCB22F1B9AF}.Release|Win32.Build.0 = Release|Win32 + {85FA9AEF-966B-4D93-9431-F507754B0431}.Debug|Win32.ActiveCfg = Debug|Win32 + {85FA9AEF-966B-4D93-9431-F507754B0431}.Debug|Win32.Build.0 = Debug|Win32 + {85FA9AEF-966B-4D93-9431-F507754B0431}.Release|Win32.ActiveCfg = Release|Win32 + {85FA9AEF-966B-4D93-9431-F507754B0431}.Release|Win32.Build.0 = Release|Win32 + {CDDC4697-F51B-4B9A-A029-C2EB5271848F}.Debug|Win32.ActiveCfg = Debug|Win32 + {CDDC4697-F51B-4B9A-A029-C2EB5271848F}.Debug|Win32.Build.0 = Debug|Win32 + {CDDC4697-F51B-4B9A-A029-C2EB5271848F}.Release|Win32.ActiveCfg = Release|Win32 + {CDDC4697-F51B-4B9A-A029-C2EB5271848F}.Release|Win32.Build.0 = Release|Win32 + {87516DC2-FDF4-4ECC-8713-D6D955100D86}.Debug|Win32.ActiveCfg = Debug|Win32 + {87516DC2-FDF4-4ECC-8713-D6D955100D86}.Debug|Win32.Build.0 = Debug|Win32 + {87516DC2-FDF4-4ECC-8713-D6D955100D86}.Release|Win32.ActiveCfg = Release|Win32 + {87516DC2-FDF4-4ECC-8713-D6D955100D86}.Release|Win32.Build.0 = Release|Win32 + {16D41CBD-3C58-4631-B4D4-29A42E47D619}.Debug|Win32.ActiveCfg = Debug|Win32 + {16D41CBD-3C58-4631-B4D4-29A42E47D619}.Debug|Win32.Build.0 = Debug|Win32 + {16D41CBD-3C58-4631-B4D4-29A42E47D619}.Release|Win32.ActiveCfg = Release|Win32 + {16D41CBD-3C58-4631-B4D4-29A42E47D619}.Release|Win32.Build.0 = Release|Win32 + {A242FE56-D039-4CEC-9FD3-AACABEA684C9}.Debug|Win32.ActiveCfg = Debug|Win32 + {A242FE56-D039-4CEC-9FD3-AACABEA684C9}.Debug|Win32.Build.0 = Debug|Win32 + {A242FE56-D039-4CEC-9FD3-AACABEA684C9}.Release|Win32.ActiveCfg = Release|Win32 + {A242FE56-D039-4CEC-9FD3-AACABEA684C9}.Release|Win32.Build.0 = Release|Win32 + {305891FE-2572-4F6A-A52B-3A1964A3CA76}.Debug|Win32.ActiveCfg = Debug|Win32 + {305891FE-2572-4F6A-A52B-3A1964A3CA76}.Debug|Win32.Build.0 = Debug|Win32 + {305891FE-2572-4F6A-A52B-3A1964A3CA76}.Release|Win32.ActiveCfg = Release|Win32 + {305891FE-2572-4F6A-A52B-3A1964A3CA76}.Release|Win32.Build.0 = Release|Win32 + {4B88BAC5-5CA8-403A-83E7-0F758405AB2D}.Debug|Win32.ActiveCfg = Debug|Win32 + {4B88BAC5-5CA8-403A-83E7-0F758405AB2D}.Debug|Win32.Build.0 = Debug|Win32 + {4B88BAC5-5CA8-403A-83E7-0F758405AB2D}.Release|Win32.ActiveCfg = Release|Win32 + {4B88BAC5-5CA8-403A-83E7-0F758405AB2D}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/test/custom-build/vc.mak b/test/custom-build/vc.mak new file mode 100644 index 0000000..2ff7349 --- /dev/null +++ b/test/custom-build/vc.mak @@ -0,0 +1,7 @@ +CC=cl +CFLAGSREL=-O2 -Ox -EHsc -DBOOST_DISABLE_WIN32 -nologo +CFLAGSDBG=-EHsc -DBOOST_DISABLE_WIN32 -nologo +EXTINCLUDE= +EXTLIBS= + +-include Makefile-Common diff --git a/test/sandbox.cpp b/test/sandbox.cpp new file mode 100644 index 0000000..2c1c97e --- /dev/null +++ b/test/sandbox.cpp @@ -0,0 +1,13 @@ +#define _CRT_SECURE_NO_DEPRECATE +//#define BOOST_PROPERTY_TREE_XML_PARSER_PUGXML +#include +#include +#include + +int main() +{ + using namespace boost::property_tree; + ptree pt; + read_xml("simple_all.xml", pt); + write_info(std::cout, pt); +} diff --git a/test/test_cmdline_parser.cpp b/test/test_cmdline_parser.cpp new file mode 100644 index 0000000..03b5d46 --- /dev/null +++ b/test/test_cmdline_parser.cpp @@ -0,0 +1,116 @@ +// ---------------------------------------------------------------------------- +// 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 +#include +#include +#include + +namespace +{ + + // Test arguments + char *argv[] = + { + "c:\\program.exe", + "-Isrc/include1", + " file2.cc ", + "/L src/lib1", + "-Lsrc/lib2", + "/ooutput", + "file1.cc", + "-g", + "-", + "/", + " /Isrc/include2 ", + " file3.cc ", + "-I src/include3 " + }; + + // Test arguments count + const int argc = sizeof(argv) / sizeof(*argv); + +} + +template +void test_cmdline_parser() +{ + + using namespace boost::property_tree; + typedef typename Ptree::key_type::value_type Ch; + typedef std::basic_string Str; + + // Prepare arguments of proper char type + std::vector p; + std::vector strings; + strings.reserve(argc); + for (int i = 0; i < argc; ++i) + { + strings.push_back(detail::widen(argv[i])); + p.push_back(const_cast(strings.back().c_str())); + } + + Ptree pt1; + read_cmdline(argc, &p.front(), detail::widen("-/"), pt1); + + // Check indices + BOOST_CHECK(pt1.template get_optional(detail::widen("L.0")).get() == detail::widen("src/lib1")); + BOOST_CHECK(pt1.template get_optional(detail::widen("L.1")).get() == detail::widen("src/lib2")); + BOOST_CHECK(!pt1.template get_optional(detail::widen("L.2"))); + BOOST_CHECK(pt1.template get_optional(detail::widen(".0")).get() == detail::widen("c:\\program.exe")); + BOOST_CHECK(pt1.template get_optional(detail::widen(".1")).get() == detail::widen("file2.cc")); + BOOST_CHECK(pt1.template get_optional(detail::widen(".2")).get() == detail::widen("file1.cc")); + BOOST_CHECK(pt1.template get_optional(detail::widen(".3")).get() == detail::widen("file3.cc")); + BOOST_CHECK(!pt1.template get_optional(detail::widen(".4"))); + + // Check total sizes + //std::cerr << total_size(pt1) << " " << total_data_size(pt1) << " " << total_keys_size(pt1) << "\n"; + BOOST_CHECK(total_size(pt1) == 21); + BOOST_CHECK(total_data_size(pt1) == 130); + BOOST_CHECK(total_keys_size(pt1) == 19); + + Ptree pt2; + read_cmdline(argc, &p.front(), detail::widen("-"), pt2); + + // Check indices + BOOST_CHECK(pt2.template get_optional(detail::widen("L.0")).get() == detail::widen("src/lib2")); + BOOST_CHECK(!pt2.template get_optional(detail::widen("L.1"))); + + // Check total sizes + //std::cerr << total_size(pt2) << " " << total_data_size(pt2) << " " << total_keys_size(pt2) << "\n"; + BOOST_CHECK(total_size(pt2) == 19); + BOOST_CHECK(total_data_size(pt2) == 135); + BOOST_CHECK(total_keys_size(pt2) == 17); + + Ptree pt3; + read_cmdline(argc, &p.front(), detail::widen("/"), pt3); + + // Check indices + BOOST_CHECK(pt3.template get_optional(detail::widen("L.0")).get() == detail::widen("src/lib1")); + BOOST_CHECK(!pt3.template get_optional(detail::widen("L.1"))); + + // Check total sizes + //std::cerr << total_size(pt3) << " " << total_data_size(pt3) << " " << total_keys_size(pt3) << "\n"; + BOOST_CHECK(total_size(pt3) == 19); + BOOST_CHECK(total_data_size(pt3) == 149); + BOOST_CHECK(total_keys_size(pt3) == 17); + +} + +int test_main(int argc, char *argv[]) +{ + using namespace boost::property_tree; + test_cmdline_parser(); +#ifndef BOOST_NO_CWCHAR + test_cmdline_parser(); +#endif + return 0; +} diff --git a/test/test_info_parser.cpp b/test/test_info_parser.cpp new file mode 100644 index 0000000..3c28a07 --- /dev/null +++ b/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 + +/////////////////////////////////////////////////////////////////////////////// +// 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 + void operator()(const std::string &filename, Ptree &pt) const + { + boost::property_tree::read_info(filename, pt); + } +}; + +struct WriteFunc +{ + template + void operator()(const std::string &filename, const Ptree &pt) const + { + boost::property_tree::write_info(filename, pt); + } +}; + +template +void test_info_parser() +{ + + using namespace boost::property_tree; + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_1, ok_data_1_inc, + "testok1.info", "testok1_inc.info", "testok1out.info", 45, 240, 192 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_2, NULL, + "testok2.info", NULL, "testok2out.info", 1, 0, 0 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_3, NULL, + "testok3.info", NULL, "testok3out.info", 5, 0, 16 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_4, NULL, + "testok4.info", NULL, "testok4out.info", 3, 8, 8 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_5, NULL, + "testok5.info", NULL, "testok5out.info", 4, 0, 9 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_6, NULL, + "testok6.info", NULL, "testok6out.info", 3, 38, 30 + ); + + generic_parser_test_error + ( + ReadFunc(), WriteFunc(), error_data_1, NULL, + "testerr1.info", NULL, "testerr1out.info", 2 + ); + + generic_parser_test_error + ( + ReadFunc(), WriteFunc(), error_data_2, NULL, + "testerr2.info", NULL, "testerr2out.info", 2 + ); + + generic_parser_test_error + ( + ReadFunc(), WriteFunc(), error_data_3, NULL, + "testerr3.info", NULL, "testerr3out.info", 2 + ); + + generic_parser_test_error + ( + ReadFunc(), WriteFunc(), error_data_4, NULL, + "testerr4.info", NULL, "testerr4out.info", 2 + ); + + generic_parser_test_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(); + test_info_parser(); +#ifndef BOOST_NO_CWCHAR + test_info_parser(); + test_info_parser(); +#endif + return 0; +} diff --git a/test/test_ini_parser.cpp b/test/test_ini_parser.cpp new file mode 100644 index 0000000..36c5ba2 --- /dev/null +++ b/test/test_ini_parser.cpp @@ -0,0 +1,198 @@ +// ---------------------------------------------------------------------------- +// 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 +#include + +/////////////////////////////////////////////////////////////////////////////// +// 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 \t; Comment\n" + " \t [ Section 3 ];Comment \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"; + +// Erroneous data +const char *error_data_1 = + "[Section1]\n" + "Key1\n" // No equals sign + "Key2=Data2"; + +// Erroneous data +const char *error_data_2 = + "Key1=Data1\n" // No section + "Key2=Data2\n"; + +// Erroneous data +const char *error_data_3 = + "[Section1]\n" + "Key1=Data1\n" + "=Data2\n"; // No key + +struct ReadFunc +{ + template + void operator()(const std::string &filename, Ptree &pt) const + { + boost::property_tree::read_ini(filename, pt); + } +}; + +struct WriteFunc +{ + template + void operator()(const std::string &filename, const Ptree &pt) const + { + boost::property_tree::write_ini(filename, pt); + } +}; + +void test_erroneous_write(const boost::property_tree::ptree &pt) +{ + using namespace boost::property_tree; + 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 +void test_ini_parser() +{ + + using namespace boost::property_tree; + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_1, NULL, + "testok1.ini", NULL, "testok1out.ini", 8, 21, 42 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_2, NULL, + "testok2.ini", NULL, "testok2out.ini", 3, 5, 12 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_3, NULL, + "testok3.ini", NULL, "testok3out.ini", 1, 0, 0 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_4, NULL, + "testok4.ini", NULL, "testok4out.ini", 1, 0, 0 + ); + + generic_parser_test_error + ( + ReadFunc(), WriteFunc(), error_data_1, NULL, + "testerr1.ini", NULL, "testerr1out.ini", 2 + ); + + generic_parser_test_error + ( + ReadFunc(), WriteFunc(), error_data_2, NULL, + "testerr2.ini", NULL, "testerr2out.ini", 1 + ); + + generic_parser_test_error + ( + ReadFunc(), WriteFunc(), error_data_3, NULL, + "testerr3.ini", NULL, "testerr3out.ini", 3 + ); + +} + +int test_main(int argc, char *argv[]) +{ + + using namespace boost::property_tree; + + test_ini_parser(); + test_ini_parser(); +#ifndef BOOST_NO_CWCHAR + test_ini_parser(); + test_ini_parser(); +#endif + + /////////////////////////////////////////////////////////////////////////// + // Too rich property tree tests + + // Test too deep ptrees + { + ptree pt; + pt.put_child("section.key.bogus", empty_ptree()); + test_erroneous_write(pt); + } + + // Test data in sections + { + ptree pt; + pt.put("section", 1); + 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", empty_ptree()); + child.push_back(std::make_pair("key", ptree())); + child.push_back(std::make_pair("key", ptree())); + test_erroneous_write(pt); + } + + return 0; + +} diff --git a/test/test_json_parser.cpp b/test/test_json_parser.cpp new file mode 100644 index 0000000..c41917d --- /dev/null +++ b/test/test_json_parser.cpp @@ -0,0 +1,384 @@ +// ---------------------------------------------------------------------------- +// 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 + +/////////////////////////////////////////////////////////////////////////////// +// Test data + +const char *ok_data_1 = + "{}"; + +const char *ok_data_2 = + " \t {\n" + " \t \"name 0\" : \"value\", \t // comment \n" + " \t \"name 1\" : \"\", // comment \n" + " \t \"name 2\" : true, // comment \n" + " \t \"name 3\" : false, // comment \n" + " \t \"name 4\" : null, // comment \n" + " \t \"name 5\" : 0, // comment \n" + " \t \"name 6\" : -5, // comment \n" + " \t \"name 7\" : 1.1, // comment \n" + " \t \"name 8\" : -956.45e+4, // comment \n" + " \t \"name 8\" : 5956.45E-11, // comment \n" + " \t \"name 9\" : [1,2,3,4], // comment \n" + " \t \"name 10\" : {\"a\":\"b\"} // comment \n" + " \t } // comment \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_5 = + "{/* \n\n//{}//{}{\n{//\n}//{}{\n */}"; + +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\": [ // Defines the CDSServlet\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 = + "{\" \\\" \\\\ \\0 \\b \\f \\n \\r \\t \" : \"multi\" \"-\" \"string\"}"; + +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 + +struct ReadFunc +{ + template + void operator()(const std::string &filename, Ptree &pt) const + { + boost::property_tree::read_json(filename, pt); + } +}; + +struct WriteFunc +{ + template + void operator()(const std::string &filename, const Ptree &pt) const + { + boost::property_tree::write_json(filename, pt); + } +}; + +template +void test_json_parser() +{ + + using namespace boost::property_tree; + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_1, NULL, + "testok1.json", NULL, "testok1out.json", 1, 0, 0 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_2, NULL, + "testok2.json", NULL, "testok2out.json", 18, 50, 74 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_3, NULL, + "testok3.json", NULL, "testok3out.json", 3, 1, 2 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_4, NULL, + "testok4.json", NULL, "testok4out.json", 11, 10, 4 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_5, NULL, + "testok5.json", NULL, "testok5out.json", 1, 0, 0 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_6, NULL, + "testok6.json", NULL, "testok6out.json", 56, 265, 111 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_7, NULL, + "testok7.json", NULL, "testok7out.json", 87, 1046, 1216 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_8, NULL, + "testok8.json", NULL, "testok8out.json", 23, 149, 125 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_9, NULL, + "testok9.json", NULL, "testok9out.json", 15, 54, 60 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_10, NULL, + "testok10.json", NULL, "testok10out.json", 17, 162, 85 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_11, NULL, + "testok11.json", NULL, "testok11out.json", 17, 120, 91 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_12, NULL, + "testok12.json", NULL, "testok12out.json", 2, 12, 19 + ); + + generic_parser_test_error + ( + ReadFunc(), WriteFunc(), error_data_1, NULL, + "testerr1.json", NULL, "testerr1out.json", 1 + ); + + generic_parser_test_error + ( + ReadFunc(), WriteFunc(), error_data_2, NULL, + "testerr2.json", NULL, "testerr2out.json", 3 + ); + + generic_parser_test_error + ( + ReadFunc(), WriteFunc(), error_data_3, NULL, + "testerr3.json", NULL, "testerr3out.json", 4 + ); + + generic_parser_test_error + ( + ReadFunc(), WriteFunc(), error_data_4, NULL, + "testerr4.json", NULL, "testerr4out.json", 3 + ); + +} + +int test_main(int argc, char *argv[]) +{ + using namespace boost::property_tree; + test_json_parser(); + test_json_parser(); +#ifndef BOOST_NO_CWCHAR + test_json_parser(); + test_json_parser(); +#endif + return 0; +} diff --git a/test/test_multi_module1.cpp b/test/test_multi_module1.cpp new file mode 100644 index 0000000..3bb3bb4 --- /dev/null +++ b/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 +#include +#include +#include +#include + +void f(); + +int main() +{ + f(); +} diff --git a/test/test_multi_module2.cpp b/test/test_multi_module2.cpp new file mode 100644 index 0000000..6d35253 --- /dev/null +++ b/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 +#include +#include +#include +#include + +void f() +{ +} diff --git a/test/test_property_tree.cpp b/test/test_property_tree.cpp new file mode 100644 index 0000000..a4c3176 --- /dev/null +++ b/test/test_property_tree.cpp @@ -0,0 +1,263 @@ +// ---------------------------------------------------------------------------- +// 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 +#include +#include + +// 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 +#include +#include +#include +#include +#include +#include + +// Predicate for sorting keys +template +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 +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 +struct MyTranslator +{ + + // Custom extractor - converts data from boost::any to T + template + bool get_value(const Ptree &pt, T &value) const + { + value = boost::any_cast(pt.data()); + return true; // Success + } + + // Custom inserter - converts data from T to boost::any + template + bool put_value(Ptree &pt, const T &value) const + { + pt.data() = value; + return true; + } + +}; + +// 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 + +int test_main(int, char *[]) +{ + + using namespace boost::property_tree; + + // char tests, case sensitive + { + ptree *pt = 0; + 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_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_leaks(pt); // must be a final test + } + + // wchar_t tests, case sensitive +#ifndef BOOST_NO_CWCHAR + { + wptree *pt = 0; + 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_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_leaks(pt); // must be a final test + } +#endif + + // char tests, case insensitive + { + iptree *pt = 0; + 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_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_leaks(pt); // must be a final test + } + + // wchar_t tests, case insensitive +#ifndef BOOST_NO_CWCHAR + { + wiptree *pt = 0; + 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_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_leaks(pt); // must be a final test + } +#endif + + return 0; +} diff --git a/test/test_property_tree.hpp b/test/test_property_tree.hpp new file mode 100644 index 0000000..0d53cca --- /dev/null +++ b/test/test_property_tree.hpp @@ -0,0 +1,1263 @@ +// ---------------------------------------------------------------------------- +// 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 *) +{ + + // 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); + +} + +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.find(T("key3"))); ++it; + BOOST_CHECK(it == pt.find(T("key4"))); ++it; + BOOST_CHECK(it == pt.find(T("key1"))); ++it; + BOOST_CHECK(it == pt.find(T("key2"))); ++it; + BOOST_CHECK(it == pt.end()); + } + + // Sort + pt.sort(SortPred()); + + // 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.find(T("key1"))); ++it; + BOOST_CHECK(it == pt.find(T("key2"))); ++it; + BOOST_CHECK(it == pt.find(T("key3"))); ++it; + BOOST_CHECK(it == pt.find(T("key4"))); ++it; + BOOST_CHECK(it == pt.end()); + } + + // Sort reverse + pt.sort(SortPredRev()); + + // 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.find(T("key4"))); ++it; + BOOST_CHECK(it == pt.find(T("key3"))); ++it; + BOOST_CHECK(it == pt.find(T("key2"))); ++it; + BOOST_CHECK(it == 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 str_t; + + // Temporary storage + str_t tmp_string; + boost::optional opt_int; + boost::optional opt_long; + boost::optional opt_double; + boost::optional opt_float; + boost::optional opt_string; + boost::optional opt_char; + boost::optional opt_bool; + + // Do insertions via put + PTREE pt; + PTREE &pt1 = pt.put(T("k1"), 1); // put as int + PTREE &pt2 = pt.put(T("k2.k"), 2.5); // put as double + PTREE &pt3 = pt.put(T("k3.k.k"), T("ala ma kota")); // put as string + PTREE &pt4 = pt.put(T("k4.k.k.k"), CHTYPE('c')); // put as character + PTREE &pt5 = pt.put(T("k5.k.k.k.f"), false); // put as bool + PTREE &pt6 = pt.put(T("k5.k.k.k.t"), true); // put as bool + + // 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(T("k1")) == 1); // get as int + BOOST_CHECK(pt.get(T("k1")) == 1); // get as long + BOOST_CHECK(pt.get(T("k2.k")) == 2.5); // get as double + BOOST_CHECK(pt.get(T("k2.k")) == 2.5f); // get as float + BOOST_CHECK(pt.get(T("k3.k.k")) == str_t(T("ala ma kota"))); // get as string + BOOST_CHECK(pt.get(T("k4.k.k.k")) == CHTYPE('c')); // get as char + BOOST_CHECK(pt.get(T("k5.k.k.k.f")) == false); // get as bool + BOOST_CHECK(pt.get(T("k5.k.k.k.t")) == true); // get as bool + + // Do extractions via get (default value version) + BOOST_CHECK(pt.get(T("k1"), 0) == 1); // get as int + BOOST_CHECK(pt.get(T("k1"), 0L) == 1); // get as long + BOOST_CHECK(pt.get(T("k2.k"), 0.0) == 2.5); // get as double + BOOST_CHECK(pt.get(T("k2.k"), 0.0f) == 2.5f); // get as float + BOOST_CHECK(pt.get(T("k3.k.k"), str_t()) == str_t(T("ala ma kota"))); // get as string + BOOST_CHECK(pt.get(T("k3.k.k"), T("")) == T("ala ma kota")); // get as const char * + BOOST_CHECK(pt.get(T("k4.k.k.k"), CHTYPE('\0')) == CHTYPE('c')); // get as char + BOOST_CHECK(pt.get(T("k5.k.k.k.f"), true) == false); // get as bool + BOOST_CHECK(pt.get(T("k5.k.k.k.t"), false) == true); // get as bool + + // Do extractions via get (optional version) + opt_int = pt.get_optional(T("k1")); // get as int + BOOST_CHECK(opt_int && *opt_int == 1); + opt_long = pt.get_optional(T("k1")); // get as long + BOOST_CHECK(opt_long && *opt_long == 1); + opt_double = pt.get_optional(T("k2.k")); // get as double + BOOST_CHECK(opt_double && *opt_double == 2.5); + opt_float = pt.get_optional(T("k2.k")); // get as float + BOOST_CHECK(opt_float && *opt_float == 2.5f); + opt_string = pt.get_optional(T("k3.k.k")); // get as string + BOOST_CHECK(opt_string && *opt_string == str_t(T("ala ma kota"))); + opt_char = pt.get_optional(T("k4.k.k.k")); // get as char + BOOST_CHECK(opt_char && *opt_char == CHTYPE('c')); + opt_bool = pt.get_optional(T("k5.k.k.k.f")); // get as bool + BOOST_CHECK(opt_bool && *opt_bool == false); + opt_bool = pt.get_optional(T("k5.k.k.k.t")); // get as bool + BOOST_CHECK(opt_bool && *opt_bool == true); + + // Do insertions via put_value + pt1.put_value(short(1)); // put as short + pt2.put_value(2.5f); // put as float + pt3.put_value(str_t(T("ala ma kota"))); // put as string + pt4.put_value(CHTYPE('c')); // put as character + pt5.put_value(false); // put as bool + pt6.put_value(true); // put as bool + + // Do extractions via get_value (throwing version) + BOOST_CHECK(pt1.get_value() == 1); // get as int + BOOST_CHECK(pt1.get_value() == 1); // get as long + BOOST_CHECK(pt2.get_value() == 2.5); // get as double + BOOST_CHECK(pt2.get_value() == 2.5f); // get as float + BOOST_CHECK(pt3.get_value() == str_t(T("ala ma kota"))); // get as string + BOOST_CHECK(pt4.get_value() == CHTYPE('c')); // get as char + BOOST_CHECK(pt5.get_value() == false); // get as bool + BOOST_CHECK(pt6.get_value() == true); // get as bool + + // Do extractions via get_value (default value version) + BOOST_CHECK(pt1.get_value(0) == 1); // get as int + BOOST_CHECK(pt1.get_value(0L) == 1); // get as long + BOOST_CHECK(pt2.get_value(0.0) == 2.5); // get as double + BOOST_CHECK(pt2.get_value(0.0f) == 2.5f); // get as float + BOOST_CHECK(pt3.get_value(str_t()) == str_t(T("ala ma kota"))); // get as string + BOOST_CHECK(pt3.get_value(T("")) == T("ala ma kota")); // get as const char * + BOOST_CHECK(pt4.get_value(CHTYPE('\0')) == CHTYPE('c')); // get as char + BOOST_CHECK(pt5.get_value(true) == false); // get as bool + BOOST_CHECK(pt6.get_value(false) == true); // get as bool + + // Do extractions via get_value (optional version) + opt_int = pt1.get_value_optional(); // get as int + BOOST_CHECK(opt_int && *opt_int == 1); + opt_long = pt1.get_value_optional(); // get as long + BOOST_CHECK(opt_long && *opt_long == 1); + opt_double = pt2.get_value_optional(); // get as double + BOOST_CHECK(opt_double && *opt_double == 2.5); + opt_float = pt2.get_value_optional(); // get as float + BOOST_CHECK(opt_float && *opt_float == 2.5f); + opt_string = pt3.get_value_optional(); // get as string + BOOST_CHECK(opt_string && *opt_string == str_t(T("ala ma kota"))); + opt_char = pt4.get_value_optional(); // get as char + BOOST_CHECK(opt_char && *opt_char == CHTYPE('c')); + opt_bool = pt5.get_value_optional(); // get as bool + BOOST_CHECK(opt_bool && *opt_bool == false); + opt_bool = pt6.get_value_optional(); // get as bool + BOOST_CHECK(opt_bool && *opt_bool == true); + + // Do incorrect extractions (throwing version) + try + { + pt.get(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(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(T("k2.k"))); + BOOST_CHECK(!pt.get_optional(T("k3.k.k"))); + BOOST_CHECK(!pt.get_optional(T("k4.k.k.k"))); + + // Test multiple puts with the same key + { + PTREE pt; + pt.put(T("key"), 1); + BOOST_CHECK(pt.get(T("key")) == 1); + BOOST_CHECK(pt.size() == 1); + pt.put(T("key"), 2); + BOOST_CHECK(pt.get(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(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(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(T("key")) == 1); + BOOST_CHECK(pt.size() == 1); + pt.put(T("key"), 2); + BOOST_CHECK(pt.get(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.put(T("key.key.key"), 2, true); + 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(T("key1"), 0) == 1); + BOOST_CHECK(pt.get(T("key1.key2"), 0) == 2); + pt.put(T("key1"), 2); + BOOST_CHECK(pt.get(T("key1"), 0) == 2); + BOOST_CHECK(pt.get(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(); + 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(0) == 99); + } + +} + +void test_get_child_put_child(PTREE *) +{ + + typedef std::basic_string str_t; + + PTREE pt(T("ala ma kota")); + + // Do insertions via put_child + PTREE pt1, pt2, pt3; + pt1.put_child(T("k1"), boost::property_tree::empty_ptree()); + pt1.put_child(T("k2.k"), boost::property_tree::empty_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"), boost::property_tree::empty_ptree()) != &boost::property_tree::empty_ptree()); + BOOST_CHECK(&pt1.get_child(T("k2.k"), boost::property_tree::empty_ptree()) != &boost::property_tree::empty_ptree()); + BOOST_CHECK(pt2.get_child(T("k1"), boost::property_tree::empty_ptree()) == pt); + BOOST_CHECK(pt2.get_child(T("k2.k"), boost::property_tree::empty_ptree()) == pt); + BOOST_CHECK(&cpt1.get_child(T("k1"), boost::property_tree::empty_ptree()) != &boost::property_tree::empty_ptree()); + BOOST_CHECK(&cpt1.get_child(T("k2.k"), boost::property_tree::empty_ptree()) != &boost::property_tree::empty_ptree()); + BOOST_CHECK(cpt2.get_child(T("k1"), boost::property_tree::empty_ptree()) == pt); + BOOST_CHECK(cpt2.get_child(T("k2.k"), boost::property_tree::empty_ptree()) == pt); + + // Do correct extractions via get_child (optional version) + boost::optional opt; + boost::optional 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 puts with the same key using do_not_replace + { + PTREE pt, tmp1(T("data1")), tmp2(T("data2")); + pt.put_child(T("key"), tmp1); + BOOST_CHECK(pt.size() == 1); + pt.put_child(T("key"), tmp2, true); + BOOST_CHECK(pt.size() == 2); + BOOST_CHECK(pt.count(T("key")) == 2); + pt.put_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.put_child(T("key.key.key"), tmp2, true); + BOOST_CHECK(child.size() == 2); + BOOST_CHECK(child.count(T("key")) == 2); + } + +} + +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(p, 0) == 1); + } + + // Test operator /= + { + path p(T("key1")); + p /= T("key2.key3"); + BOOST_CHECK(pt.get(p, 0) == 1); + } + + // Test operator /= + { + path p; + path p1(T("key1.key2")); + path p2(T("key3")); + p /= p1; + p /= p2; + BOOST_CHECK(pt.get(p, 0) == 1); + } + + // Test operator / + { + path p = path(T("key1")) / T("key2.key3"); + BOOST_CHECK(pt.get(p, 0) == 1); + } + + // Test operator / + { + path p = T("key1.key2") / path(T("key3")); + BOOST_CHECK(pt.get(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(); + + // 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::radix), + real(numeric_limits::digits)); + BOOST_CHECK(error < 100); + +} + +void test_locale(PTREE *) +{ + + 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, false, loc_english); + pt.put(T("french"), 1.234, false, loc_french); + + // Test contents + BOOST_CHECK(pt.get(T("english")) == T("1.234")); + BOOST_CHECK(pt.get(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 Str; + typedef PTREE::key_compare Comp; + typedef PTREE::path_type Path; + + // Property_tree with boost::any as data type + typedef boost::property_tree::basic_ptree my_ptree; + my_ptree pt; + + // Put/get int value + pt.put(T("int value"), 3); + int int_value = pt.get(T("int value")); + BOOST_CHECK(int_value == 3); + + // Put/get string value + pt.put >(T("string value"), T("foo bar")); + std::basic_string string_value = pt.get >(T("string value")); + BOOST_CHECK(string_value == T("foo bar")); + + // Put/get list value + int list_data[] = { 1, 2, 3, 4, 5 }; + pt.put >(T("list value"), std::list(list_data, list_data + sizeof(list_data) / sizeof(*list_data))); + std::list list_value = pt.get >(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(T("non.existent.path")); + } + catch (boost::property_tree::ptree_bad_path &e) + { + PTREE::path_type path = e.path(); + 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(); + } + catch (boost::property_tree::ptree_bad_data &e) + { + PTREE::data_type data = e.data(); + std::string what = e.what(); + 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"), boost::property_tree::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() == 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() == 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(false) == false); + BOOST_CHECK(it->second.get_value(true) == true); + } + +} + +void test_char(PTREE *) +{ + + // Prepare test tree + PTREE pt; +#if WIDECHAR == 0 + pt.put(T("char"), char('A')); +#endif + pt.put(T("signed char"), static_cast('A')); + pt.put(T("unsigned char"), static_cast('A')); + pt.put(T("signed char min"), (std::numeric_limits::min)()); + pt.put(T("signed char max"), (std::numeric_limits::max)()); + pt.put(T("unsigned char min"), (std::numeric_limits::min)()); + pt.put(T("unsigned char max"), (std::numeric_limits::max)()); + + // Verify normal conversions +#if WIDECHAR == 0 + BOOST_CHECK(pt.get(T("char")) == 'A'); +#endif + BOOST_CHECK(pt.get(T("signed char")) == static_cast('A')); + BOOST_CHECK(pt.get(T("unsigned char")) == static_cast('A')); + + // Verify that numbers are saved for signed and unsigned char + BOOST_CHECK(pt.get(T("signed char")) == int('A')); + BOOST_CHECK(pt.get(T("unsigned char")) == int('A')); + + // Verify ranges + BOOST_CHECK(pt.get(T("signed char min")) == (std::numeric_limits::min)()); + BOOST_CHECK(pt.get(T("signed char max")) == (std::numeric_limits::max)()); + BOOST_CHECK(pt.get(T("unsigned char min")) == (std::numeric_limits::min)()); + BOOST_CHECK(pt.get(T("unsigned char max")) == (std::numeric_limits::max)()); + +} + +void test_leaks(PTREE *) +{ + BOOST_CHECK(PTREE::debug_get_instances_count() == 0); +} diff --git a/test/test_registry_parser.cpp b/test/test_registry_parser.cpp new file mode 100644 index 0000000..2e7c348 --- /dev/null +++ b/test/test_registry_parser.cpp @@ -0,0 +1,110 @@ +// ---------------------------------------------------------------------------- +// 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" + +// Only test registry parser if we have windows platform +#ifdef BOOST_WINDOWS + +#include +#include + +/////////////////////////////////////////////////////////////////////////////// +// Test data + +const char *data_1 = + "root\n" + "{\n" + " subkey1 \"default value 1\"\n" + " subkey2 \"default value 2\"\n" + " \\\\values\n" + " {\n" + " REG_NONE \"\"\n" + " REG_BINARY \"de ad be ef\"\n" + " REG_DWORD 1234567890\n" + " REG_QWORD 12345678901234567890\n" + " REG_SZ \"some text\"\n" + " REG_EXPAND_SZ \"some other text\"\n" + " }\n" + " \\\\types\n" + " {\n" + " REG_NONE 0\n" + " REG_BINARY 3\n" + " REG_DWORD 4\n" + " REG_QWORD 11\n" + " REG_SZ 1\n" + " REG_EXPAND_SZ 2\n" + " }\n" + "}\n"; + +template +void test_registry_parser() +{ + + using namespace boost::property_tree; + typedef typename Ptree::key_type::value_type Ch; + typedef std::basic_string Str; + + // Delete test registry key + RegDeleteKeyA(HKEY_CURRENT_USER, "boost ptree test"); + + // Get test ptree + Ptree pt; + std::basic_stringstream stream(detail::widen(data_1)); + read_info(stream, pt); + + try + { + + // Write to registry, read back and compare contents + Ptree pt2; + write_registry(HKEY_CURRENT_USER, detail::widen("boost ptree test"), pt); + read_registry(HKEY_CURRENT_USER, detail::widen("boost ptree test"), pt2); + BOOST_CHECK(pt == pt2); + + // Test binary translation + Str s = pt2.template get(detail::widen("root.\\values.REG_BINARY")); + std::vector bin = registry_parser::translate(REG_BINARY, s); + BOOST_REQUIRE(bin.size() == 4); + BOOST_CHECK(*reinterpret_cast(&bin.front()) == 0xEFBEADDE); + Str s2 = registry_parser::translate(REG_BINARY, bin); + BOOST_CHECK(s == s2); + + } + catch (std::exception &e) + { + BOOST_ERROR(e.what()); + } + + // Delete test registry key + RegDeleteKeyA(HKEY_CURRENT_USER, "boost ptree test"); + +} + +int test_main(int argc, char *argv[]) +{ + using namespace boost::property_tree; + test_registry_parser(); + //test_registry_parser(); +#ifndef BOOST_NO_CWCHAR + //test_registry_parser(); + //test_registry_parser(); +#endif + return 0; +} + +#else + +int test_main(int argc, char *argv[]) +{ + return 0; +} + +#endif diff --git a/test/test_utils.hpp b/test/test_utils.hpp new file mode 100644 index 0000000..2db2267 --- /dev/null +++ b/test/test_utils.hpp @@ -0,0 +1,227 @@ +// ---------------------------------------------------------------------------- +// 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 + +// 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 +#include +#include + +template +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 +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 +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; +} + +template +class test_file +{ +public: + test_file(const char *test_data, const char *filename) + { + if (test_data && filename) + { + name = filename; + std::basic_ofstream stream(name.c_str()); + while (*test_data) + { + stream << Ch(*test_data); + ++test_data; + } + BOOST_CHECK(stream.good()); + } + } + ~test_file() + { + if (!name.empty()) + remove(name.c_str()); + } +private: + std::string name; +}; + +template +Ptree get_test_ptree() +{ + using namespace boost::property_tree; + typedef typename Ptree::key_type::value_type Ch; + Ptree pt; + pt.put_value(detail::widen("data0")); + pt.put(detail::widen("key1"), detail::widen("data1")); + pt.put(detail::widen("key1.key"), detail::widen("data2")); + pt.put(detail::widen("key2"), detail::widen("data3")); + pt.put(detail::widen("key2.key"), detail::widen("data4")); + return pt; +} + +// Generic test for file parser +template +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; + typedef typename Ptree::key_type::value_type Ch; + + // 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 +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(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 +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()); + try + { + generic_parser_test(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()); // Test if error damaged contents + } + catch (...) + { + BOOST_ERROR("Invalid exception type thrown"); + throw; + } + + } + + // Test for leaks + BOOST_CHECK(Ptree::debug_get_instances_count() == 0); + +} + +#endif diff --git a/test/test_xml_parser_common.hpp b/test/test_xml_parser_common.hpp new file mode 100644 index 0000000..9eeb04b --- /dev/null +++ b/test/test_xml_parser_common.hpp @@ -0,0 +1,79 @@ +// ---------------------------------------------------------------------------- +// 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 +#include "xml_parser_test_data.hpp" + +struct ReadFunc +{ + template + void operator()(const std::string &filename, Ptree &pt) const + { + boost::property_tree::read_xml(filename, pt); + } +}; + +struct WriteFunc +{ + template + void operator()(const std::string &filename, const Ptree &pt) const + { + boost::property_tree::write_xml(filename, pt); + } +}; + +template +void test_xml_parser() +{ + + using namespace boost::property_tree; + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_1, NULL, + "testok1.xml", NULL, "testok1out.xml", 2, 0, 5 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_2, NULL, + "testok2.xml", NULL, "testok2out.xml", 5, 15, 7 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_3, NULL, + "testok3.xml", NULL, "testok3out.xml", 787, 31346, 3831 + ); + + generic_parser_test_ok + ( + ReadFunc(), WriteFunc(), ok_data_4, NULL, + "testok4.xml", NULL, "testok4out.xml", 5, 2, 20 + ); + + generic_parser_test_error + ( + ReadFunc(), WriteFunc(), error_data_1, NULL, + "testerr1.xml", NULL, "testerr1out.xml", 1 + ); + + generic_parser_test_error + ( + ReadFunc(), WriteFunc(), error_data_2, NULL, + "testerr2.xml", NULL, "testerr2out.xml", 2 + ); + +} + +#endif diff --git a/test/test_xml_parser_pugxml.cpp b/test/test_xml_parser_pugxml.cpp new file mode 100644 index 0000000..b873c3c --- /dev/null +++ b/test/test_xml_parser_pugxml.cpp @@ -0,0 +1,25 @@ +// ---------------------------------------------------------------------------- +// 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 _CRT_SECURE_NO_DEPRECATE +#define BOOST_PROPERTY_TREE_XML_PARSER_PUGXML +#include "test_xml_parser_common.hpp" + +int test_main(int argc, char *argv[]) +{ + using namespace boost::property_tree; + test_xml_parser(); + //test_xml_parser(); +#ifndef BOOST_NO_CWCHAR + //test_xml_parser(); + //test_xml_parser(); +#endif + return 0; +} diff --git a/test/test_xml_parser_rapidxml.cpp b/test/test_xml_parser_rapidxml.cpp new file mode 100644 index 0000000..5abc18f --- /dev/null +++ b/test/test_xml_parser_rapidxml.cpp @@ -0,0 +1,23 @@ +// ---------------------------------------------------------------------------- +// 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_xml_parser_common.hpp" + +int test_main(int argc, char *argv[]) +{ + using namespace boost::property_tree; + test_xml_parser(); + test_xml_parser(); +#ifndef BOOST_NO_CWCHAR + test_xml_parser(); + test_xml_parser(); +#endif + return 0; +} diff --git a/test/test_xml_parser_spirit.cpp b/test/test_xml_parser_spirit.cpp new file mode 100644 index 0000000..75cc49a --- /dev/null +++ b/test/test_xml_parser_spirit.cpp @@ -0,0 +1,24 @@ +// ---------------------------------------------------------------------------- +// 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 BOOST_PROPERTY_TREE_XML_PARSER_SPIRIT +#include "test_xml_parser_common.hpp" + +int test_main(int argc, char *argv[]) +{ + using namespace boost::property_tree; + test_xml_parser(); + test_xml_parser(); +#ifndef BOOST_NO_CWCHAR + test_xml_parser(); + test_xml_parser(); +#endif + return 0; +} diff --git a/test/test_xml_parser_tinyxml.cpp b/test/test_xml_parser_tinyxml.cpp new file mode 100644 index 0000000..eb4be3c --- /dev/null +++ b/test/test_xml_parser_tinyxml.cpp @@ -0,0 +1,26 @@ +// ---------------------------------------------------------------------------- +// 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 +// ---------------------------------------------------------------------------- + +#ifdef _DEBUG + #pragma comment( lib, "tinyxmld_STL.lib" ) +#else + #pragma comment( lib, "tinyxml_STL.lib" ) +#endif + +#define BOOST_PROPERTY_TREE_XML_PARSER_TINYXML +#include "test_xml_parser_common.hpp" + +int test_main(int argc, char *argv[]) +{ + using namespace boost::property_tree; + test_xml_parser(); + test_xml_parser(); + return 0; +} diff --git a/test/xml_parser_test_data.hpp b/test/xml_parser_test_data.hpp new file mode 100644 index 0000000..557b052 --- /dev/null +++ b/test/xml_parser_test_data.hpp @@ -0,0 +1,743 @@ +#ifndef XML_PARSER_TEST_DATA_HPP_INCLUDED +#define XML_PARSER_TEST_DATA_HPP_INCLUDED + +/////////////////////////////////////////////////////////////////////////////// +// Test data + +// Correct +const char *ok_data_1 = + "\n" + ""; + +// Correct +const char *ok_data_2 = + "\n" + "\n" + "<>&\n" + "1<2>3&4\n" + " < > & \n" + "\n"; + +// Correct +const char *ok_data_3 = + "\n" + "\n" + "\n" + "]>\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "
\n" + " XML Linking Language (XLink)\n" + " Version 1.0\n" + " WD-xlink-19990527\n" + " World Wide Web Consortium Working Draft\n" + " 29May1999\n" + " \n" + "

This draft is for public discussion.

\n" + "
\n" + " http://www.w3.org/XML/Group/1999/05/WD-xlink-current\n" + " \n" + " \n" + " http://www.w3.org/XML/Group/1999/05/WD-xlink-19990527\n" + " http://www.w3.org/XML/Group/1999/05/WD-xlink-19990505\n" + " http://www.w3.org/TR/1998/WD-xlink-19980303\n" + " http://www.w3.org/TR/WD-xml-link-970630\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " Steve DeRose\n" + " Inso Corp. and Brown University\n" + " Steven_DeRose@Brown.edu\n" + " \n" + " \n" + " David Orchard\n" + " IBM Corp.\n" + " dorchard@ca.ibm.com\n" + " \n" + " \n" + " Ben Trafford\n" + " Invited Expert\n" + " bent@exemplary.net\n" + " \n" + " \n" + " \n" + "\n" + " \n" + "

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 http://www.w3.org/TR.

\n" + "

Note: 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 .

\n" + "

This work is part of the W3C XML Activity (for current status, see http://www.w3.org/XML/Activity ). For information about the XPointer language which is expected to be used with XLink, see http://www.w3.org/TR/WD-xptr.\n" + "

\n" + "

See http://www.w3.org/TR/NOTE-xlink-principles for additional background on the design principles informing XLink.

\n" + "

Also see http://www.w3.org/TR/NOTE-xlink-req/ for the XLink requirements that this document attempts to satisfy.

\n" + "
\n" + "\n" + " \n" + " \n" + "

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.

\n" + "
\n" + "\n" + " \n" + "

Burlington, Seekonk, et al.: World-Wide Web Consortium, XML Working Group, 1998.

\n" + "
\n" + "\n" + " \n" + "

Created in electronic form.

\n" + "
\n" + "\n" + " \n" + " English\n" + " Extended Backus-Naur Form (formal grammar)\n" + " \n" + "\n" + " \n" + " \n" + " 1997-01-15 : Skeleton draft by TB\n" + " 1997-01-24 : Fleshed out by sjd\n" + " 1997-04-08 : Substantive draft\n" + " 1997-06-30 : Public draft\n" + " 1997-08-01 : Public draft\n" + " 1997-08-05 : Prose/organization work by sjd\n" + " 1997-10-14: Conformance and design principles; a bit of cleanup by elm\n" + " 1997-11-07: Update for editorial issues per issues doc, by sjd.\n" + " 1997-12-01: Update for editorial issues per issues doc in preparation for F2F meeting, by sjd.\n" + " 1998-01-13: Editorial cleanup, addition of new design principles, by elm.\n" + " 1998-02-27: Splitting out of XLink and XPointer, by elm.\n" + " 1998-03-03: Moved most of the XPointer locator stuff here. elm\n" + " 1999-04-24: Editorial rewrites to represent new ideas on XLink, especially the inclusion of arcs. bent\n" + " 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\n" + " 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\n" + " 1999-05-17: Further prose work. Added non-normative examples. Clarified arcs. bent\n" + " 1999-05-23: Edited for grammar and clarity. bent\n" + " 1999-05-27: Final once-over before sending to group. Fixed sjd's email address. bent\n" + " \n" + " \n" + "
\n" + "\n" + "\n" + " \n" + " Introduction\n" + "

This specification defines constructs that may be inserted into XML DTDs, schemas, and document instances to describe links between objects. A link, 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.

\n" + "

Links are asserted by elements contained in XML document instances. The simplest case is very like an HTML A link, and has these characteristics:\n" + " \n" + "

The link is expressed at one of its ends (similar to the A element in some document)

\n" + "

Users can only initiate travel from that end to the other

\n" + "

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 A links normally replaces the current view, perhaps with a user option to open a new window.

\n" + "

The link goes to only one destination (although a server may have great freedom in finding or dynamically creating that destination).

\n" + " \n" + "

\n" + "

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" + "

\n" + "\n" + "\n" + " Origin and Goals\n" + "

Following is a summary of the design principles governing XLink:\n" + " \n" + "

XLink must be straightforwardly usable over the Internet.

\n" + "

XLink must be usable by a wide variety of link usage domains and classes of linking application software.

\n" + "

XLink must support HTML 4.0 linking constructs.

\n" + "

The XLink expression language must be XML.

\n" + "

The XLink design must be formal, concise, and illustrative.

\n" + "

XLinks must be human-readable and human-writable.

\n" + "

XLinks may reside within or outside the documents in which the\n" + " participating resources reside.

\n" + "

XLink must represent the abstract structure and significance of links.

\n" + "

XLink must be feasible to implement.

\n" + "

XLink must be informed by knowledge of established hypermedia systems and standards.

\n" + " \n" + "

\n" + "
\n" + "\n" + "\n" + "\n" + " Relationship to Existing Standards\n" + "

Three standards have been especially influential:\n" + " \n" + "

HTML: Defines several SGML element types that represent links.

\n" + "

HyTime: Defines inline and out-of-line link structures and some semantic features, including traversal control and presentation of objects. \n" + "

\n" + "

Text Encoding Initiative Guidelines (TEI P3): Provides structures for creating links, aggregate objects, and link collections out of them.

\n" + " \n" + "

\n" + "

Many other linking systems have also informed this design, especially Dexter, FRESS, MicroCosm, and InterMedia.

\n" + "
\n" + "\n" + "\n" + " Terminology\n" + "

The following basic terms apply in this document. \n" + " \n" + " \n" + " \n" + "

A symbolic representation of traversal behavior in links, especially the direction, context and timing of traversal.

\n" + " \n" + " \n" + " \n" + "

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.

\n" + "
\n" + " \n" + " \n" + "

Abstractly, a link which serves as one of its own resources. Concretely, a link where the content of the linking element serves as a participating resource.\n" + " HTML A, HyTime clink, and TEI XREF\n" + " are all inline links.

\n" + "
\n" + " \n" + " \n" + "

An explicit relationship between two or more data objects or portions of data objects.

\n" + "
\n" + " \n" + " \n" + "

An element that asserts the existence and describes the characteristics of a link.

\n" + "
\n" + " \n" + " \n" + "

The content of an inlinelinking element. Note that the content of the linking element could be explicitly pointed to by means of a regular locator in the same linking element, in which case the resource is considered remote, not local.

\n" + "
\n" + " \n" + " \n" + "

Data, provided as part of a link, which identifies a\n" + " resource.

\n" + "
\n" + " \n" + " \n" + "

A link whose traversal can be initiated from more than one of its participating resources. Note that being able to \"go back\" after following a one-directional link does not make the link multidirectional.

\n" + "
\n" + " \n" + " \n" + "

A link whose content does not serve as one of the link's participating resources . Such links presuppose a notion like extended link groups, which instruct application software where to look for links. Out-of-line links are generally required for supporting multidirectional traversal and for allowing read-only resources to have outgoing links.

\n" + "
\n" + " \n" + "

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.

\n" + "
\n" + " \n" + " \n" + "

A resource that belongs to a link. All resources are potential contributors to a link; participating resources are the actual contributors to a particular link.

\n" + "
\n" + " \n" + " \n" + "

Any participating resource of a link that is pointed to with a locator.

\n" + "
\n" + " \n" + " \n" + "

In the abstract sense, an addressable unit of information or service that is participating in a link. Examples include files, images, documents, programs, and query results. Concretely, anything reachable by the use of a locator in some linking element. Note that this term and its definition are taken from the basic specifications governing the World Wide Web. \n" + "

\n" + "
\n" + " \n" + " \n" + "

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.

\n" + "
\n" + " \n" + " \n" + "

The action of using a link; that is, of accessing a resource. Traversal may be initiated by a user action (for example, clicking on the displayed content of a linking element) or occur under program control.

\n" + "
\n" + " \n" + "

\n" + "
\n" + "\n" + "\n" + " Notation\n" + "

The formal grammar for locators is given using a simple Extended Backus-Naur Form (EBNF) location, as described in the XML specification.

\n" + " \n" + "
\n" + "
\n" + "\n" + "\n" + " Locator Syntax\n" + "

The locator for a resource 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.

\n" + " \n" + "

A locator generally contains a URI, as described in IETF RFCs and . As these RFCs state, the URI may include a trailing query (marked by a leading \"?\"), and be followed by a \"#\" and a fragment identifier, 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.

\n" + " \n" + "

In order to locate XML documents and portions of documents, a locator value may contain either a URI or a fragment identifier, or both. Any fragment identifier for pointing into XML must be an XPointer.

\n" + "

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" + " \n" + " Locator\n" + " \n" + " Locator\n" + " URI\n" + " | Connector (XPointer | Name)\n" + " | URI Connector (XPointer | Name)\n" + " \n" + " \n" + " Connector'#' | '|'\n" + " \n" + " \n" + " URIURIchar*\n" + " \n" + " \n" + "

\n" + "

In this discussion, the term designated resource refers to the resource which an entire locator serves to locate. The following rules apply:\n" + " \n" + " \n" + "

The URI, if provided, locates a resource called the containing resource.

\n" + " \n" + " \n" + "

If the URI is not provided, the containing resource is considered to be the document in which the linking element is contained. \n" + "

\n" + " \n" + "

If an XPointer is provided, the designated resource is a sub-resource\n" + " of the containing resource; otherwise the designated resource is the\n" + " containing resource.

\n" + "
\n" + " \n" + " \n" + "

If the Connector is followed directly by a Name, the Name is shorthand for the XPointer\"id(Name)\"; that is, the sub-resource is the element in the containing resource that has an XML ID attribute whose value matches the Name. This shorthand is to encourage use of the robust id addressing mode.

\n" + "
\n" + " \n" + " \n" + "

If the connector is \"#\", 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.

\n" + "
\n" + " \n" + "

If the connector is \"|\", no intent is signaled as to what processing model is to be used to go about accessing the designated resource.

\n" + "
\n" + " \n" + "

\n" + "

Note that the definition of a URI includes an optional query component.

\n" + "

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" + " \n" + " Query\n" + " \n" + " Query'XML-XPTR=' ( XPointer | Name)\n" + " \n" + " \n" + "

\n" + " \n" + "
\n" + "\n" + "\n" + " Link Recognition\n" + "

The existence of a link is asserted by a linking element. 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 namespace 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.

\n" + "

The two approaches to identifying linking elements are relatively simple to implement. For example, here's how the HTML A element would be declared using attributes within the XLink namespace, and then how an element within the XLink namespace might do the same:\n" + " <A xlink:type=\"simple\" xlink:href=\"http://www.w3.org/TR/wd-xlink/\"\n" + "xlink:title=\"The Xlink Working Draft\">The XLink Working Draft.</A>\n" + " <xlink:simple href=\"http://www.w3.org/TR/wd-xlink/\"\n" + "title=\"The XLink Working Draft\">The XLink Working Draft</xlink:simple>\n" + " Any arbitrary element can be made into an XLink by using the xlink:type 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 xlink namespace prefix if they existed within an arbitrary element, or that they may be used directly if they exist within an explicit Xlink element.

\n" + " \n" + "
\n" + "\n" + "\n" + "\n" + " Linking Attributes\n" + "

XLink has several attributes associated with the variety of links it may represent. These attributes define four main concepts: locators, arcs, behaviors, and semantics. Locators define where the actual resource is located. Arcs 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. Behaviors define how the link is activated, and what the application should do with the resource being linked to. Semantics define useful information that the application may use, and enables the link for such specalized targets as constricted devices and accessibility software.

\n" + " \n" + " \n" + " Locator Attributes\n" + "

The only locator attribute at this time is href. 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.

\n" + "
\n" + "\n" + " \n" + " Arc Attributes\n" + "

Arcs contain two attributes, from and to. The from attribute may contain a string containing the content of a role attribute from the resource being linked from. The purpose of the from attribute is to define where this link is being actuated from.

\n" + "

The to attribute may contain a string containing the content of a role attribute from the resource being linked to. The purpose of the to attribute is to define where this link traverses to.

\n" + "

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.

\n" + " \n" + "
\n" + "\n" + " \n" + " Behavior Attributes\n" + "

There are two attributes associated with behavior: show and actuate. The show attribute defines how the remote resource is to be revealed to the user. It has three options: new, parsed, and replace. The new option indicates that the remote resource should be shown in a new window (or other device context) without replacing the previous content. The parsed 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 replace 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.

\n" + "

The actuate attribute defines how the link is initiated. It has two options: user and auto. The user option indicates that the link must be initiated by some sort of human-initiated selection, such as clicking on an HTML anchor. The auto 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 show option.

\n" + " \n" + "
\n" + "\n" + " \n" + " Semantic Attributes\n" + "

There are two attributes associated with semantics, role and title. The role 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 role=\"stanza\". The role is also used as an identifier for the from and to attributes of arcs.

\n" + "

The title 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 title attribute contains a simple, descriptive string.

\n" + "
\n" + "
\n" + "\n" + "\n" + " Linking Elements\n" + "

There are several kinds of linking elements in XLink: simple links, locators, arcs, and extended 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.

\n" + "

The simple link is used to declare a link that approximates the functionality of the HTML A element. It has, however, a few added features to increase its value, including the potential declaration of semantics and behavior. The locator 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 arcs are used to define the traversal semantics of the link. Finally, an extended 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.

\n" + "\n" + "\n" + " Simple Links\n" + "

Simple links can be used for purposes that approximate the functionality of a basic HTML A 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. As a result of this combination, the simple linking element offers both a locator attribute and all the behavior and semantic attributes.

\n" + "

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" + " <!ELEMENT xlink:simple ANY>\n" + "<!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" + ">\n" + " And here is how to make an arbitrary element into a simple link.\n" + " <!ELEMENT xlink:simple ANY>\n" + "<!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" + ">\n" + " Here is how the first example might look in a document:\n" + "<xlink:simple href=\"http://www.w3.org/TR/wd-xlink\" role=\"working draft\" \n" + " title=\"The XLink Working Draft\" show=\"replace\" actuate=\"user\">\n" + "The XLink Working Draft.</xlink:simple>\n" + "<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\">\n" + "The XLink Working Draft.</foo>\n" + " Alternately, a simple link could be as terse as this:\n" + "<foo xlink:href=\"#stanza1\">The First Stanza.</foo>\n" + "

\n" + "

\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 ANY\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.

\n" + "

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.

\n" + "
\n" + "\n" + "\n" + "Extended Links\n" + "

An extended link 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.

\n" + "

These additional capabilities of extended links are required for: \n" + " \n" + " \n" + "

Enabling outgoing links in documents that cannot be modified to add an inline link

\n" + " \n" + " \n" + "

Creating links to and from resources in formats with no native support for embedded links (such as most multimedia formats)

\n" + "
\n" + " \n" + "

Applying and filtering sets of relevant links on demand

\n" + "
\n" + "

Enabling other advanced hypermedia capabilities

\n" + " \n" + "

\n" + "

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).

\n" + "

A linking element for an extended link contains a series of child elements 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).

\n" + "

The xlink:type attribute value for an extended link must be extended, if the link is being instantiated on an arbitrary element. Note that extended links introduce variants of the show and actuate behavior attributes. These attributes, the showdefault and actuatedefault 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.

\n" + "

However, when a linking element within an extended link has a show or actuate attribute of its own, that attribute overrides the defaults set on the extended linking element.

\n" + "

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" + "<!ELEMENT xlink:extended ((xlink:arc | xlink:locator)*)>\n" + "<!ATTLIST xlink:extended\n" + " role CDATA #IMPLIED\n" + " title CDATA #IMPLIED\n" + " showdefault (new|parsed|replace) #IMPLIED \n" + " actuatedefault (user|auto) #IMPLIED >\n" + "\n" + " The second is an example of an arbitrary element being used an extended link:\n" + "\n" + "<!ELEMENT foo ((xlink:arc | xlink:locator)*)>\n" + "<!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 >\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" + "<xlink:extended role=\"address book\" title=\"Ben's Address Book\" showdefault=\"replace\" actuatedefault=\"user\"> ... </xlink:extended>\n" + "\n" + " And the second shows how the link might appear, using an arbitrary element:\n" + "\n" + "<foo xlink:type=\"extended\" xlink:role=\"address book\" xlink:title=\"Ben's Address Book\" xlink:showdefault=\"replace\" xlink:actuatedefault=\"user\"> ... </foo>\n" + "

\n" + "\n" + "
\n" + "\n" + "\n" + " Arc Elements\n" + "

An arc is contained within an extended link for the purpose of defining traversal behavior. More than one arc may be associated with a link. Otherwise, arc elements function exactly as the arc attributes might lead on to expect.

\n" + " \n" + "
\n" + "\n" + "
\n" + "\n" + "Conformance\n" + "

An element conforms to XLink if: \n" + "

The element has an xml:link attribute whose value is\n" + "one of the attribute values prescribed by this specification, and

\n" + "

the element and all of its attributes and content adhere to the\n" + "syntactic\n" + "requirements imposed by the chosen xml:link attribute value,\n" + "as prescribed in this specification.

\n" + "

\n" + "

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.

\n" + "

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.

\n" + "
\n" + "\n" + "\n" + "Unfinished Work\n" + "\n" + "Structured Titles\n" + "

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.

\n" + "
\n" + "
\n" + "\n" + "References\n" + "\n" + "Eve Maler and Steve DeRose, editors. \n" + "XML Pointer Language (XPointer) V1.0. ArborText, Inso, and Brown\n" + "University. Burlington, Seekonk, et al.: World Wide Web Consortium, 1998.\n" + "(See http://www.w3.org/TR/WD-xptr\n" + " .)\n" + "ISO (International Organization for\n" + "Standardization). ISO/IEC 10744-1992 (E). Information technology\n" + "- Hypermedia/Time-based Structuring Language (HyTime). [Geneva]:\n" + "International Organization for Standardization, 1992. Extended\n" + "Facilities\n" + "Annex. [Geneva]: International Organization for Standardization,\n" + "1996. (See http://www.ornl.go\n" + "v/sgml/wg8/hytime/html/is10744r.html ).\n" + "IETF (Internet Engineering Task\n" + "Force). \n" + "RFC 1738: Uniform Resource Locators. 1991. (See \n" + "http://www.w3.org/Addressing/rfc1738.txt).\n" + "IETF (Internet Engineering Task\n" + "Force). \n" + "RFC 1808: Relative Uniform Resource Locators. 1995. (See http://www.w3.org/Addressing/rfc\n" + "1808.txt ).\n" + "C. M. Sperberg-McQueen and Lou Burnard, editors.\n" + "\n" + "Guidelines for Electronic Text Encoding and Interchange. 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. \n" + "]Steven J. DeRose and David G. Durand. 1995. \"The\n" + "TEI Hypertext Guidelines.\" In Computing and the Humanities\n" + "29(3).\n" + "Reprinted in Text Encoding Initiative: Background and\n" + "Context,\n" + "ed. Nancy Ide and Jean ronis , ISBN 0-7923-3704-2. \n" + "\n" + "
\n" + "\n"; + +// Correct +const char *ok_data_4 = + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + " \n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "]>\n" + "\n" + "\n" + "\n" + "PP\n" + "\n" + "\n"; + +// Erroneous +const char *error_data_1 = + "a"; // bogus character + +// Erroneous +const char *error_data_2 = + "\n" + ""; // XML tag not closed + +#endif