From 7fab1bf757700449b9dead756989d08e3114182a Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Sun, 29 Aug 2010 15:26:06 +0000 Subject: tests: Reduced allocation count git-svn-id: http://pugixml.googlecode.com/svn/trunk@662 99668b35-9821-0410-8761-19e4c4f06640 --- tests/test_parse_doctype.cpp | 47 ++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'tests/test_parse_doctype.cpp') 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 +#include #include -static bool test_doctype_wf(const std::basic_string& 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("") + decl).c_str()) || !test_node(doc, STR(""), STR(""), format_raw)) return false; - if (!doc.load((decl + STR("")).c_str()) || !test_node(doc, STR(""), STR(""), format_raw)) return false; - if (!doc.load((STR("") + decl + STR("")).c_str()) || !test_node(doc, STR(""), STR(""), format_raw)) return false; + if (!load_concat(doc, STR(""), decl) || !test_node(doc, STR(""), STR(""), format_raw)) return false; + if (!load_concat(doc, decl, STR("")) || !test_node(doc, STR(""), STR(""), format_raw)) return false; + if (!load_concat(doc, STR(""), decl, STR("")) || !test_node(doc, STR(""), STR(""), format_raw)) return false; // wrap in node to check that doctype is parsed fully (does not leave any "pcdata") - if (!doc.load((STR("") + decl + STR("")).c_str()) || !test_node(doc, STR(""), STR(""), format_raw)) return false; + if (!load_concat(doc, STR(""), decl, STR("")) || !test_node(doc, STR(""), STR(""), format_raw)) return false; return true; } -static bool test_doctype_nwf(const std::basic_string& 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("")).c_str()).status != status_bad_doctype) return false; + if (load_concat(doc, decl, STR("")).status != status_bad_doctype) return false; return true; } -- cgit v1.2.3