#include "lib/self_test.h" #include "ps/XML/XML.h" #include "ps/XML/XMLWriter.h" class TestXmlWriter : public CxxTest::TestSuite { public: void test1() { XML_Start(); { XML_Element("Root"); { XML_Comment("Comment test."); XML_Comment("Comment test again."); { XML_Element("a"); XML_Attribute("one", 1); XML_Attribute("two", "TWO"); XML_Text("b"); XML_Text(" (etc)"); } { XML_Element("c"); XML_Text("d"); } XML_Setting("c2", "d2"); { XML_Element("e"); { { XML_Element("f"); XML_Text("g"); } { XML_Element("h"); } { XML_Element("i"); XML_Attribute("j", 1.23); { XML_Element("k"); XML_Attribute("l", 2.34); XML_Text("m"); } } } } } } CStr output = XML_GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n" "\n" "\n" "\t\n" "\t\n" "\tb (etc)\n" "\td\n" "\td2\n" "\t\n" "\t\tg\n" "\t\t\n" "\t\t\n" "\t\t\tm\n" "\t\t\n" "\t\n" "" ); } void test_basic() { XML_Start(); { XML_Element("Test"); { XML_Element("example"); { XML_Element("content"); XML_Text("text"); } } } CStr output = XML_GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n" "\n" "\n" "\t\n" "\t\ttext\n" "\t\n" "" ); } void test_nonpretty() { XML_Start(); XML_SetPrettyPrint(false); { XML_Element("Test"); { XML_Element("example"); { XML_Element("content"); XML_Text("text"); } } } CStr output = XML_GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n" "text" ); } void test_text() { XML_Start(); { XML_Element("Test"); XML_Text("a"); XML_Text("b"); } CStr output = XML_GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n" "\n" "ab" ); } void test_utf8() { XML_Start(); { XML_Element("Test"); { const wchar_t text[] = { 0x0251, 0 }; XML_Text(text); } } CStr output = XML_GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n\n" "\xC9\x91" ); } void test_attr_escape() { XML_Start(); { XML_Element("Test"); XML_Attribute("example", "abc > ]]> < & \"\" "); } CStr output = XML_GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n\n" " ]]> < & "" \"/>" ); } void test_chardata_escape() { XML_Start(); { XML_Element("Test"); XML_Text("abc > ]]> < & \"\" "); } CStr output = XML_GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n\n" "abc > ]]> < & \"\" " ); } void test_comment_escape() { XML_Start(); { XML_Element("Test"); XML_Comment("test - -- --- ---- test"); } CStr output = XML_GetOutput(); TS_ASSERT_STR_EQUALS(output, "\n\n" "\n" "\t\n" "" ); } };