Ticket #10338: Ticket10338.txt

File Ticket10338.txt, 1.4 KB (added by pbtud@…, 8 years ago)

Unit Test

Line 
1BOOST_AUTO_TEST_CASE(ReadAndWriteWithSpecialCharacters)
2{
3 using boost::property_tree::ptree;
4
5 // the xml that will be turned into a ptree. Note the linefeed between Level_1 and Level_2 tags
6 std::string XmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Level_1>\n<Level_2><Item>0</Item></Level_2></Level_1>";
7
8 std::stringstream StringStream1(XmlString);
9 std::stringstream StringStream2;
10
11 // read the xml string
12 ptree Level1Tree;
13 read_xml(StringStream1,Level1Tree);
14
15 // write the sub-tree at level 1 to string stream 2 as an xml
16 ptree Level2Tree = Level1Tree.get_child("Level_1");
17 write_xml(StringStream2,Level2Tree);
18
19 // show that the xml string has an xml declaration followed by \n&#10; (boost version 1.56)
20 // or an xml declaration followed by \n\n (boost version 1.55 and earlier)
21 std::string Level2XmlString = StringStream2.str();
22
23 if (BOOST_VERSION >= 105600)
24 {
25 BOOST_CHECK(Level2XmlString == "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n&#10;<Level_2><Item>0</Item></Level_2>");
26 }
27 else
28 {
29 BOOST_CHECK(Level2XmlString == "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n<Level_2><Item>0</Item></Level_2>");
30 }
31
32 // reading the xml from string stream 2 throws an exception in boost 1.56 but not in boost 1.55
33 ptree OutputTree;
34 BOOST_CHECK_NO_THROW(read_xml(StringStream2,OutputTree));
35}