diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/allocator.cpp | 44 | ||||
-rw-r--r-- | tests/autotest-local.pl | 4 | ||||
-rw-r--r-- | tests/autotest-remote-host.pl | 2 | ||||
-rw-r--r-- | tests/autotest-report.pl | 4 | ||||
-rw-r--r-- | tests/test.cpp | 15 | ||||
-rw-r--r-- | tests/test_document.cpp | 11 | ||||
-rw-r--r-- | tests/test_dom_modify.cpp | 5 | ||||
-rw-r--r-- | tests/test_parse.cpp | 1 | ||||
-rw-r--r-- | tests/test_parse_doctype.cpp | 40 | ||||
-rw-r--r-- | tests/test_write.cpp | 21 | ||||
-rw-r--r-- | tests/test_xpath_functions.cpp | 8 | ||||
-rw-r--r-- | tests/writer_string.cpp | 2 |
12 files changed, 147 insertions, 10 deletions
diff --git a/tests/allocator.cpp b/tests/allocator.cpp index 094d5e5..74bbf10 100644 --- a/tests/allocator.cpp +++ b/tests/allocator.cpp @@ -66,6 +66,50 @@ namespace VirtualProtect(rptr, aligned_size + PAGE_SIZE, PAGE_NOACCESS, &old_flags); } } +#elif defined(__APPLE__) || defined(__linux__) +# include <sys/mman.h> + +namespace +{ + const size_t PAGE_SIZE = 4096; + + size_t align_to_page(size_t value) + { + return (value + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); + } + + void* allocate_page_aligned(size_t size) + { + return mmap(0, size + PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); + } + + void* allocate(size_t size) + { + size_t aligned_size = align_to_page(size); + + void* ptr = allocate_page_aligned(aligned_size + PAGE_SIZE); + if (!ptr) return 0; + + char* end = static_cast<char*>(ptr) + aligned_size; + + int res = mprotect(end, PAGE_SIZE, PROT_NONE); + assert(res == 0); + (void)!res; + + return end - size; + } + + void deallocate(void* ptr, size_t size) + { + size_t aligned_size = align_to_page(size); + + void* rptr = static_cast<char*>(ptr) + size - aligned_size; + + int res = mprotect(rptr, aligned_size + PAGE_SIZE, PROT_NONE); + assert(res == 0); + (void)!res; + } +} #else # include <stdlib.h> diff --git a/tests/autotest-local.pl b/tests/autotest-local.pl index a419bb0..60f8b20 100644 --- a/tests/autotest-local.pl +++ b/tests/autotest-local.pl @@ -65,8 +65,8 @@ if ($fast) print "### autotest begin " . scalar localtime() . "\n"; -# print SVN revision info -print "### autotest revision $1\n" if (`svn info` =~ /Revision:\s+(\d+)/); +# print Git revision info +print "### autotest revision $1\n" if (`git rev-parse HEAD` =~ /(.+)/); # get CPU info $cpucount = &getcpucount(); diff --git a/tests/autotest-remote-host.pl b/tests/autotest-remote-host.pl index 5abef1e..63dfe68 100644 --- a/tests/autotest-remote-host.pl +++ b/tests/autotest-remote-host.pl @@ -32,6 +32,6 @@ exit unless $client; select $client; -&execprint('svn up') == 0 || die "error updating from repo\n"; +&execprint('git pull') == 0 || die "error updating from repo\n"; &execprint('perl tests/autotest-local.pl') == 0 || die "error launching tests\n"; system($exitcmd); diff --git a/tests/autotest-report.pl b/tests/autotest-report.pl index b5ebd8c..9eebf39 100644 --- a/tests/autotest-report.pl +++ b/tests/autotest-report.pl @@ -128,7 +128,7 @@ while (<>) $defines{$_} = 1 foreach (split /,/, $defineset); &insertindex(\%configurations, $fullconf); } - elsif (/^### autotest revision (\d+)/) + elsif (/^### autotest revision (.+)/) { if (defined $revision && $revision != $1) { @@ -224,6 +224,6 @@ $date = localtime; print <<END; </table><br> -Generated on $date from Subversion r$revision +Generated on $date from Git $revision </body></html> END diff --git a/tests/test.cpp b/tests/test.cpp index eb901db..6347984 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -71,6 +71,15 @@ bool test_double_nan(double value) } #ifndef PUGIXML_NO_XPATH +static size_t strlength(const pugi::char_t* s) +{ +#ifdef PUGIXML_WCHAR_MODE + return wcslen(s); +#else + return strlen(s); +#endif +} + bool test_xpath_string(const pugi::xpath_node& node, const pugi::char_t* query, pugi::xpath_variable_set* variables, const pugi::char_t* expected) { pugi::xpath_query q(query, variables); @@ -81,7 +90,11 @@ bool test_xpath_string(const pugi::xpath_node& node, const pugi::char_t* query, size_t size = q.evaluate_string(result, capacity, node); - if (size <= capacity) return test_string_equal(result, expected); + if (size != strlength(expected) + 1) + return false; + + if (size <= capacity) + return test_string_equal(result, expected); std::basic_string<pugi::char_t> buffer(size, ' '); diff --git a/tests/test_document.cpp b/tests/test_document.cpp index ebcdcd1..49428f2 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -990,6 +990,17 @@ TEST(document_load_buffer_empty_fragment) } } +TEST(document_load_buffer_null) +{ + xml_document doc; + + CHECK(doc.load_buffer(0, 12).status == status_io_error && !doc.first_child()); + CHECK(doc.load_buffer(0, 12, parse_fragment).status == status_io_error && !doc.first_child()); + + CHECK(doc.load_buffer_inplace(0, 12).status == status_io_error && !doc.first_child()); + CHECK(doc.load_buffer_inplace_own(0, 12).status == status_io_error && !doc.first_child()); +} + TEST(document_progressive_truncation) { char* original_data; diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index f8a8b2f..1feed21 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -2,7 +2,8 @@ #include <limits> #include <string> -#include <cmath> + +#include <math.h> TEST_XML(dom_attr_assign, "<node/>") { @@ -1488,7 +1489,7 @@ TEST(dom_fp_roundtrip_float) { for (size_t i = 0; i < sizeof(fp_roundtrip_base) / sizeof(fp_roundtrip_base[0]); ++i) { - float value = ldexpf(fp_roundtrip_base[i], e); + float value = ldexpf(static_cast<float>(fp_roundtrip_base[i]), e); doc.text().set(value); CHECK(doc.text().as_float() == value); diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index 321b84c..1b1e807 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -863,6 +863,7 @@ TEST(parse_declaration_error) TEST(parse_empty) { xml_document doc; + CHECK(doc.load_string(STR("")).status == status_no_document_element && !doc.first_child()); CHECK(doc.load_string(STR(""), parse_fragment) && !doc.first_child()); } diff --git a/tests/test_parse_doctype.cpp b/tests/test_parse_doctype.cpp index 14268f6..901890c 100644 --- a/tests/test_parse_doctype.cpp +++ b/tests/test_parse_doctype.cpp @@ -322,3 +322,43 @@ TEST(parse_doctype_error_ignore) CHECK(doc.load_string(STR("<!DOCTYPE root [ <![IGNORE[ <![INCLUDE[")).status == status_bad_doctype); CHECK(doc.load_string(STR("<!DOCTYPE root [ <![IGNORE[ <![INCLUDE["), parse_doctype).status == status_bad_doctype); } + +TEST(parse_doctype_stackless_group) +{ + std::basic_string<char_t> str; + + int count = 100000; + + str += STR("<!DOCTYPE "); + + for (int i = 0; i < count; ++i) + str += STR("<!G "); + + for (int j = 0; j < count; ++j) + str += STR(">"); + + str += STR(">"); + + xml_document doc; + CHECK(doc.load_string(str.c_str(), parse_fragment)); +} + +TEST(parse_doctype_stackless_ignore) +{ + std::basic_string<char_t> str; + + int count = 100000; + + str += STR("<!DOCTYPE "); + + for (int i = 0; i < count; ++i) + str += STR("<![IGNORE[ "); + + for (int j = 0; j < count; ++j) + str += STR("]]>"); + + str += STR(">"); + + xml_document doc; + CHECK(doc.load_string(str.c_str(), parse_fragment)); +} diff --git a/tests/test_write.cpp b/tests/test_write.cpp index ca230c3..59cdb3e 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -115,6 +115,25 @@ TEST(write_pi_null) CHECK_NODE(doc, STR("<?:anonymous value?>")); } +TEST(write_pi_invalid) +{ + xml_document doc; + xml_node node = doc.append_child(node_pi); + + node.set_name(STR("test")); + node.set_value(STR("?")); + + CHECK_NODE(doc, STR("<?test ?" "?>")); + + node.set_value(STR("?>")); + + CHECK_NODE(doc, STR("<?test ? >?>")); + + node.set_value(STR("<?foo?>")); + + CHECK_NODE(doc, STR("<?test <?foo? >?>")); +} + TEST_XML_FLAGS(write_declaration, "<?xml version='2.0'?>", parse_declaration | parse_fragment) { CHECK_NODE(doc, STR("<?xml version=\"2.0\"?>")); @@ -171,7 +190,7 @@ struct test_writer: xml_writer virtual void write(const void* data, size_t size) { CHECK(size % sizeof(pugi::char_t) == 0); - contents += std::basic_string<pugi::char_t>(static_cast<const pugi::char_t*>(data), static_cast<const pugi::char_t*>(data) + size / sizeof(pugi::char_t)); + contents.append(static_cast<const pugi::char_t*>(data), size / sizeof(pugi::char_t)); } }; diff --git a/tests/test_xpath_functions.cpp b/tests/test_xpath_functions.cpp index 678bc2e..eb43bb5 100644 --- a/tests/test_xpath_functions.cpp +++ b/tests/test_xpath_functions.cpp @@ -570,6 +570,14 @@ TEST(xpath_string_translate_table) CHECK_XPATH_STRING(c, STR("translate('abcde', 'abcd', concat('ABC', 'D'))"), STR("ABCDe")); } +TEST(xpath_string_translate_remove) +{ + xml_node c; + + CHECK_XPATH_STRING(c, STR("translate('000000755', '0', '')"), STR("755")); + CHECK_XPATH_STRING(c, STR("translate('000000755', concat('0', ''), '')"), STR("755")); +} + TEST_XML(xpath_nodeset_last, "<node><c1/><c1/><c2/><c3/><c3/><c3/><c3/></node>") { xml_node n = doc.child(STR("node")); diff --git a/tests/writer_string.cpp b/tests/writer_string.cpp index a09678b..661c792 100644 --- a/tests/writer_string.cpp +++ b/tests/writer_string.cpp @@ -15,7 +15,7 @@ static bool test_narrow(const std::string& result, const char* expected, size_t void xml_writer_string::write(const void* data, size_t size) { - contents += std::string(static_cast<const char*>(data), size); + contents.append(static_cast<const char*>(data), size); } std::string xml_writer_string::as_narrow() const |