Revision: 174
http://xmlwrapp.svn.sourceforge.net/xmlwrapp/?rev=174&view=rev
Author: vaclavslavik
Date: 2010-03-11 15:29:23 +0000 (Thu, 11 Mar 2010)
Log Message:
-----------
Test if text data are escaped as expected.
When creating a text node with e.g. '&' in it, it should be serialized
as valid XML, with special characters replaced with entities. So
creating a text node or setting node's content to "M & M" should result
in "M & M" markup.
Modified Paths:
--------------
trunk/tests/node/test_node.cxx
Added Paths:
-----------
trunk/tests/node/data/special_chars.xml
Added: trunk/tests/node/data/special_chars.xml
===================================================================
--- trunk/tests/node/data/special_chars.xml (rev 0)
+++ trunk/tests/node/data/special_chars.xml 2010-03-11 15:29:23 UTC (rev 174)
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<root>Marlow & Sons</root>
Modified: trunk/tests/node/test_node.cxx
===================================================================
--- trunk/tests/node/test_node.cxx 2010-03-10 18:24:44 UTC (rev 173)
+++ trunk/tests/node/test_node.cxx 2010-03-11 15:29:23 UTC (rev 174)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2001-2003 Peter J Jones (pj...@pm...)
- * Copyright (C) 2009 Vaclav Slavik (vs...@fa...)
+ * Copyright (C) 2009-2010 Vaclav Slavik (vs...@fa...)
* All Rights Reserved
*
* Redistribution and use in source and binary forms, with or without
@@ -566,4 +566,50 @@
}
+/*
+ * Test correct (expected) handling of text escaping.
+ */
+
+BOOST_AUTO_TEST_CASE( text_substitute_entities )
+{
+ xml::tree_parser parser(test_file_path("node/data/special_chars.xml").c_str());
+ xml::node &root = parser.get_document().get_root_node();
+
+ const std::string content = root.get_content();
+
+ BOOST_CHECK_EQUAL( content, "Marlow & Sons" );
+}
+
+
+BOOST_AUTO_TEST_CASE( escape_node_with_content )
+{
+ xml::node n("root", "Marlow & Sons");
+
+ BOOST_CHECK_EQUAL( n.get_content(), "Marlow & Sons" );
+ BOOST_CHECK( is_same_as_file(n, "node/data/special_chars.xml") );
+}
+
+
+BOOST_AUTO_TEST_CASE( escape_text_node )
+{
+ xml::node n("root");
+ n.push_back(xml::node(xml::node::text("Marlow & Sons")));
+
+ BOOST_CHECK_EQUAL( n.get_content(), "Marlow & Sons" );
+ BOOST_CHECK( is_same_as_file(n, "node/data/special_chars.xml") );
+}
+
+
+BOOST_AUTO_TEST_CASE( escape_set_content )
+{
+ xml::node n("root");
+ // Note that set_content() takes CDATA content as argument, so "&"
+ // has to be written as "&".
+ n.set_content("Marlow & Sons");
+
+ BOOST_CHECK_EQUAL( n.get_content(), "Marlow & Sons" );
+ BOOST_CHECK( is_same_as_file(n, "node/data/special_chars.xml") );
+}
+
+
BOOST_AUTO_TEST_SUITE_END()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|