From 837ced350c5123c21c32154f1f2dc483238f7629 Mon Sep 17 00:00:00 2001 From: mloy Date: Thu, 30 Oct 2014 14:30:05 +0100 Subject: load_buffer_impl always checks if buffer is valid pointer and size > 0 added some tests to force invalid buffer and size = 0 --- tests/test_parse.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index c45b783..56ea049 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -865,6 +865,8 @@ TEST(parse_empty) xml_document doc; CHECK(doc.load(STR("")).status == status_no_document_element && !doc.first_child()); CHECK(doc.load(STR(""), parse_fragment) && !doc.first_child()); + CHECK(doc.load_buffer(NULL, 12).status == status_no_document_element); + CHECK(doc.load_buffer("foo", 0).status == status_no_document_element); } TEST(parse_out_of_memory) -- cgit v1.2.3 From 617f302808d24fa11fab49b21b71fe644ca7b053 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 17 Jan 2015 18:39:29 -0800 Subject: tests: Use Git instead of Subversion in autotest --- tests/autotest-local.pl | 4 ++-- tests/autotest-remote-host.pl | 2 +- tests/autotest-report.pl | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') 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 <
-Generated on $date from Subversion r$revision +Generated on $date from Git $revision END -- cgit v1.2.3 From 3181a305edc9159c71036ff0070f1c3153ec3f1d Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sat, 17 Jan 2015 18:40:09 -0800 Subject: tests: Fix MSVC 2008 compilation warning Also include math.h to fix issues on some compilers. --- tests/test_dom_modify.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index 1fb9dd3..5167358 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -2,7 +2,8 @@ #include #include -#include + +#include TEST_XML(dom_attr_assign, "") { @@ -1483,7 +1484,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(fp_roundtrip_base[i]), e); doc.text().set(value); CHECK(doc.text().as_float() == value); -- cgit v1.2.3 From 650a4c6cca98e3d1c973d86b91797e85f4861e6d Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 20 Jan 2015 20:37:14 -0800 Subject: Use string::append in implementations of xml_writer The current code is not optimal; since users actually read samples/tests change them to use faster (and shorter!) code. --- tests/test_write.cpp | 2 +- tests/writer_string.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_write.cpp b/tests/test_write.cpp index ca230c3..da83745 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -171,7 +171,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(static_cast(data), static_cast(data) + size / sizeof(pugi::char_t)); + contents.append(static_cast(data), size / sizeof(pugi::char_t)); } }; 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(data), size); + contents.append(static_cast(data), size); } std::string xml_writer_string::as_narrow() const -- cgit v1.2.3 From e94552c9ca883f8c4f2cead24355a60ecba0efb2 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 12 Feb 2015 08:12:12 -0800 Subject: DOCTYPE parsing is now stackless This prevents malformed input XML with very deeply recursive DOCTYPE sections from crashing the parser. Fixes #29. --- tests/test_parse_doctype.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests') diff --git a/tests/test_parse_doctype.cpp b/tests/test_parse_doctype.cpp index 14268f6..646ebbf 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(" str; + + int count = 100000; + + str += ""); + + str += ">"; + + xml_document doc; + CHECK(doc.load_string(str.c_str(), parse_fragment)); +} + +TEST(parse_doctype_stackless_ignore) +{ + std::basic_string str; + + int count = 100000; + + str += ""); + + str += ">"; + + xml_document doc; + CHECK(doc.load_string(str.c_str(), parse_fragment)); +} -- cgit v1.2.3 From 78353022978140e9c8e21d37509e8137989339c6 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 12 Feb 2015 08:54:44 -0800 Subject: tests: Fix tests for wchar mode --- tests/test_parse_doctype.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_parse_doctype.cpp b/tests/test_parse_doctype.cpp index 646ebbf..901890c 100644 --- a/tests/test_parse_doctype.cpp +++ b/tests/test_parse_doctype.cpp @@ -329,7 +329,7 @@ TEST(parse_doctype_stackless_group) int count = 100000; - str += ""); - str += ">"; + str += STR(">"); xml_document doc; CHECK(doc.load_string(str.c_str(), parse_fragment)); @@ -349,7 +349,7 @@ TEST(parse_doctype_stackless_ignore) int count = 100000; - str += ""); - str += ">"; + str += STR(">"); xml_document doc; CHECK(doc.load_string(str.c_str(), parse_fragment)); -- cgit v1.2.3 From ee4e2b866993f264349ea294d0114a12d3696aa7 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Sun, 1 Mar 2015 20:57:22 -0800 Subject: tests: Implement page heap for OSX/Linux Align allocations to right end of page boundary to catch buffer overruns, instead of unmapping on deallocations mark the page as no-access to guarantee a page fault on use-after-free. --- tests/allocator.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests') 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 + +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(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(ptr) + size - aligned_size; + + int res = mprotect(rptr, aligned_size + PAGE_SIZE, PROT_NONE); + assert(res == 0); + (void)!res; + } +} #else # include -- cgit v1.2.3 From 5a848de085e8f2b0458ee7afba5a3d95572f11c2 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 4 Mar 2015 10:40:18 -0800 Subject: tests: Fix XPath string comparison Also add new tests for translate. These are technically redundant since other tests would catch the bug with the fixed comparison, but more tests is better. --- tests/test.cpp | 15 ++++++++++++++- tests/test_xpath_functions.cpp | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'tests') 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 buffer(size, ' '); 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, "") { xml_node n = doc.child(STR("node")); -- cgit v1.2.3 From 9749920c8204930f868fed7fcf38ea2cc2b5a2ec Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 5 Mar 2015 11:35:39 -0800 Subject: Refactor contents=0 behavior Also change the error code to status_io_error --- tests/test_parse.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index 500e44c..131840c 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -872,14 +872,16 @@ TEST(parse_load_buffer_null) { xml_document doc; - CHECK(doc.load_buffer(0, 12).status == status_no_document_element && !doc.first_child()); + 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()); } TEST(parse_load_buffer_empty) { xml_document doc; - CHECK(doc.load_buffer("foo", 0).status == status_no_document_element); + CHECK(doc.load_buffer("foo", 0).status == status_no_document_element && !doc.first_child()); + CHECK(doc.load_buffer("foo", 0, parse_fragment) && !doc.first_child()); } TEST(parse_out_of_memory) -- cgit v1.2.3 From 12e137d12fe6e6492e669cfa6c333f4a8911b1b2 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 5 Mar 2015 11:46:34 -0800 Subject: tests: Move null buffer tests to test_document Remove size=0 test since a better test is already there. --- tests/test_document.cpp | 11 +++++++++++ tests/test_parse.cpp | 16 ---------------- 2 files changed, 11 insertions(+), 16 deletions(-) (limited to 'tests') 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_parse.cpp b/tests/test_parse.cpp index 131840c..1b1e807 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -868,22 +868,6 @@ TEST(parse_empty) CHECK(doc.load_string(STR(""), parse_fragment) && !doc.first_child()); } -TEST(parse_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()); -} - -TEST(parse_load_buffer_empty) -{ - xml_document doc; - - CHECK(doc.load_buffer("foo", 0).status == status_no_document_element && !doc.first_child()); - CHECK(doc.load_buffer("foo", 0, parse_fragment) && !doc.first_child()); -} - TEST(parse_out_of_memory) { test_runner::_memory_fail_threshold = 256; -- cgit v1.2.3 From 604861e520d2d6579674a1c2bd5e59cb10f7ecd2 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 10 Mar 2015 09:03:22 -0700 Subject: Escape ?> sequence in PI value during printing This prevents malformed PI value from breaking the document structure. --- tests/test_write.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/test_write.cpp b/tests/test_write.cpp index da83745..59cdb3e 100644 --- a/tests/test_write.cpp +++ b/tests/test_write.cpp @@ -115,6 +115,25 @@ TEST(write_pi_null) CHECK_NODE(doc, STR("")); } +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("")); + + node.set_value(STR("?>")); + + CHECK_NODE(doc, STR("?>")); + + node.set_value(STR("")); + + CHECK_NODE(doc, STR("?>")); +} + TEST_XML_FLAGS(write_declaration, "", parse_declaration | parse_fragment) { CHECK_NODE(doc, STR("")); -- cgit v1.2.3