summaryrefslogtreecommitdiff
path: root/tests/test_parse_doctype.cpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-08-29 15:26:06 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2010-08-29 15:26:06 +0000
commit7fab1bf757700449b9dead756989d08e3114182a (patch)
tree61d4425675af600e3cdbac6721e4404b127f575a /tests/test_parse_doctype.cpp
parent049fa3906db2786943617bb1b0ce3225be9a772f (diff)
tests: Reduced allocation count
git-svn-id: http://pugixml.googlecode.com/svn/trunk@662 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test_parse_doctype.cpp')
-rw-r--r--tests/test_parse_doctype.cpp47
1 files changed, 34 insertions, 13 deletions
diff --git a/tests/test_parse_doctype.cpp b/tests/test_parse_doctype.cpp
index 57f38fb..c633467 100644
--- a/tests/test_parse_doctype.cpp
+++ b/tests/test_parse_doctype.cpp
@@ -1,42 +1,63 @@
+#define _CRT_SECURE_NO_WARNINGS
+
#include "common.hpp"
+#include <string.h>
+#include <wchar.h>
#include <string>
-static bool test_doctype_wf(const std::basic_string<char_t>& decl)
+static xml_parse_result load_concat(xml_document& doc, const char_t* a, const char_t* b = STR(""), const char_t* c = STR(""))
+{
+ char_t buffer[768];
+
+#ifdef PUGIXML_WCHAR_MODE
+ wcscpy(buffer, a);
+ wcscat(buffer, b);
+ wcscat(buffer, c);
+#else
+ strcpy(buffer, a);
+ strcat(buffer, b);
+ strcat(buffer, c);
+#endif
+
+ return doc.load(buffer);
+}
+
+static bool test_doctype_wf(const char_t* decl)
{
xml_document doc;
// standalone
- if (!doc.load(decl.c_str()) || (bool)doc.first_child()) return false;
+ if (!load_concat(doc, decl) || (bool)doc.first_child()) return false;
// pcdata pre/postfix
- if (!doc.load((STR("a") + decl).c_str()) || (bool)doc.first_child()) return false;
- if (!doc.load((decl + STR("b")).c_str()) || (bool)doc.first_child()) return false;
- if (!doc.load((STR("a") + decl + STR("b")).c_str()) || (bool)doc.first_child()) return false;
+ if (!load_concat(doc, STR("a"), decl) || (bool)doc.first_child()) return false;
+ if (!load_concat(doc, decl, STR("b")) || (bool)doc.first_child()) return false;
+ if (!load_concat(doc, STR("a"), decl, STR("b")) || (bool)doc.first_child()) return false;
// node pre/postfix
- if (!doc.load((STR("<nodea/>") + decl).c_str()) || !test_node(doc, STR("<nodea />"), STR(""), format_raw)) return false;
- if (!doc.load((decl + STR("<nodeb/>")).c_str()) || !test_node(doc, STR("<nodeb />"), STR(""), format_raw)) return false;
- if (!doc.load((STR("<nodea/>") + decl + STR("<nodeb/>")).c_str()) || !test_node(doc, STR("<nodea /><nodeb />"), STR(""), format_raw)) return false;
+ if (!load_concat(doc, STR("<nodea/>"), decl) || !test_node(doc, STR("<nodea />"), STR(""), format_raw)) return false;
+ if (!load_concat(doc, decl, STR("<nodeb/>")) || !test_node(doc, STR("<nodeb />"), STR(""), format_raw)) return false;
+ if (!load_concat(doc, STR("<nodea/>"), decl, STR("<nodeb/>")) || !test_node(doc, STR("<nodea /><nodeb />"), STR(""), format_raw)) return false;
// wrap in node to check that doctype is parsed fully (does not leave any "pcdata")
- if (!doc.load((STR("<node>") + decl + STR("</node>")).c_str()) || !test_node(doc, STR("<node />"), STR(""), format_raw)) return false;
+ if (!load_concat(doc, STR("<node>"), decl, STR("</node>")) || !test_node(doc, STR("<node />"), STR(""), format_raw)) return false;
return true;
}
-static bool test_doctype_nwf(const std::basic_string<char_t>& decl)
+static bool test_doctype_nwf(const char_t* decl)
{
xml_document doc;
// standalone
- if (doc.load(decl.c_str()).status != status_bad_doctype) return false;
+ if (load_concat(doc, decl).status != status_bad_doctype) return false;
// pcdata postfix
- if (doc.load((decl + STR("b")).c_str()).status != status_bad_doctype) return false;
+ if (load_concat(doc, decl, STR("b")).status != status_bad_doctype) return false;
// node postfix
- if (doc.load((decl + STR("<nodeb/>")).c_str()).status != status_bad_doctype) return false;
+ if (load_concat(doc, decl, STR("<nodeb/>")).status != status_bad_doctype) return false;
return true;
}