From cac1d8ad9f602e74841acb05596396ee00994ebb Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 30 Jan 2017 08:57:42 -0800 Subject: tests: Add an error propagation test for XPath This test is supposed to test error coverage in different expressions that are nested in other expressions to reduce the number of never-taken branches in tests (and make sure we aren't missing any). --- tests/test_xpath_parse.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/test_xpath_parse.cpp') diff --git a/tests/test_xpath_parse.cpp b/tests/test_xpath_parse.cpp index b6de42e..1f51118 100644 --- a/tests/test_xpath_parse.cpp +++ b/tests/test_xpath_parse.cpp @@ -313,4 +313,26 @@ TEST(xpath_parse_result_default) CHECK(result.offset == 0); } +TEST(xpath_parse_error_propagation) +{ + char_t query[] = STR("(//foo[count(. | @*)] | /foo | /foo/bar//more/ancestor-or-self::foobar | /text() | a[1 + 2 * 3 div (1+0) mod 2]//b[1]/c | a[$x])[true()]"); + + xpath_variable_set vars; + vars.set(STR("x"), 1.0); + + xpath_query q(query, &vars); + CHECK(q); + + for (size_t i = 0; i + 1 < sizeof(query) / sizeof(query[0]); ++i) + { + char_t ch = query[i]; + + query[i] = '%'; + + CHECK_XPATH_FAIL(query); + + query[i] = ch; + } +} + #endif -- cgit v1.2.3 From 02cee98492233f4ae91f025fc38f9df8b4bc0efe Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 30 Jan 2017 21:36:05 -0800 Subject: tests: Add more tests for branch coverage gcov -b surfaced many lines with partial coverage, where branch is only ever taken or not taken, or one of the expressions in a complex conditional is always either true or false. This change adds a series of tests (mostly focusing on XPath) to reduce the number of partially covered lines. --- tests/test_xpath_parse.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/test_xpath_parse.cpp') diff --git a/tests/test_xpath_parse.cpp b/tests/test_xpath_parse.cpp index 1f51118..c39481b 100644 --- a/tests/test_xpath_parse.cpp +++ b/tests/test_xpath_parse.cpp @@ -335,4 +335,12 @@ TEST(xpath_parse_error_propagation) } } +TEST_XML(xpath_parse_location_path, "") +{ + CHECK_XPATH_NODESET(doc, STR("/node")) % 2; + CHECK_XPATH_NODESET(doc, STR("/@*")); + CHECK_XPATH_NODESET(doc, STR("/.")) % 1; + CHECK_XPATH_NODESET(doc, STR("/..")); + CHECK_XPATH_NODESET(doc, STR("/*")) % 2; +} #endif -- cgit v1.2.3 From a1bc15c8d525ff2cac165cc0e5d08b272d79fc33 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 30 Jan 2017 23:24:20 -0800 Subject: tests: Add more coverage tests Expand out of memory coverage during XPath parsing and evaluation and add some other small tests. --- tests/test_xpath_parse.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'tests/test_xpath_parse.cpp') diff --git a/tests/test_xpath_parse.cpp b/tests/test_xpath_parse.cpp index c39481b..9b28478 100644 --- a/tests/test_xpath_parse.cpp +++ b/tests/test_xpath_parse.cpp @@ -274,7 +274,7 @@ TEST_XML(xpath_parse_absolute, "
") TEST(xpath_parse_out_of_memory_first_page) { - test_runner::_memory_fail_threshold = 1; + test_runner::_memory_fail_threshold = 128; CHECK_ALLOC_FAIL(CHECK_XPATH_FAIL(STR("1"))); } @@ -335,6 +335,29 @@ TEST(xpath_parse_error_propagation) } } +TEST(xpath_parse_oom_propagation) +{ + const char_t* query_base = STR("(//foo[count(. | @*)] | /foo | /foo/bar//more/ancestor-or-self::foobar | /text() | a[1 + 2 * 3 div (1+0) mod 2]//b[1]/c | a[$x])[true()]"); + + xpath_variable_set vars; + vars.set(STR("x"), 1.0); + + test_runner::_memory_fail_threshold = 4096 + 128; + + { + xpath_query q(query_base, &vars); + CHECK(q); + } + + for (size_t i = 3200; i < 4200; ++i) + { + std::basic_string literal(i, 'a'); + std::basic_string query = STR("processing-instruction('") + literal + STR("') | ") + query_base; + + CHECK_ALLOC_FAIL(CHECK_XPATH_FAIL(query.c_str())); + } +} + TEST_XML(xpath_parse_location_path, "") { CHECK_XPATH_NODESET(doc, STR("/node")) % 2; -- cgit v1.2.3 From ef64bef5c3e80144f4e0d1ca0cc07c68e3ad5a6b Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 31 Jan 2017 00:35:15 -0800 Subject: tests: More XPath coverage tests --- tests/test_xpath_parse.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'tests/test_xpath_parse.cpp') diff --git a/tests/test_xpath_parse.cpp b/tests/test_xpath_parse.cpp index 9b28478..8819a5d 100644 --- a/tests/test_xpath_parse.cpp +++ b/tests/test_xpath_parse.cpp @@ -293,6 +293,27 @@ TEST(xpath_parse_out_of_memory_string_to_number) CHECK_ALLOC_FAIL(CHECK_XPATH_FAIL(STR("0.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"))); } +TEST(xpath_parse_out_of_memory_quoted_string) +{ + test_runner::_memory_fail_threshold = 4096 + 128; + + std::basic_string literal(5000, 'a'); + std::basic_string query = STR("'") + literal + STR("'"); + + CHECK_ALLOC_FAIL(CHECK_XPATH_FAIL(query.c_str())); +} + +TEST(xpath_parse_out_of_memory_variable) +{ + test_runner::_memory_fail_threshold = 4096 + 128; + + std::basic_string literal(5000, 'a'); + std::basic_string query = STR("$") + literal; + + xpath_variable_set vars; + CHECK_ALLOC_FAIL(CHECK_XPATH_FAIL_VAR(query.c_str(), &vars)); +} + TEST(xpath_parse_qname_error) { CHECK_XPATH_FAIL(STR("foo: bar")); @@ -315,7 +336,7 @@ TEST(xpath_parse_result_default) TEST(xpath_parse_error_propagation) { - char_t query[] = STR("(//foo[count(. | @*)] | /foo | /foo/bar//more/ancestor-or-self::foobar | /text() | a[1 + 2 * 3 div (1+0) mod 2]//b[1]/c | a[$x])[true()]"); + char_t query[] = STR("(//foo[count(. | @*)] | ((a)//b)[1] | /foo | /foo/bar//more/ancestor-or-self::foobar | /text() | a[1 + 2 * 3 div (1+0) mod 2]//b[1]/c | a[$x])[true()]"); xpath_variable_set vars; vars.set(STR("x"), 1.0); @@ -337,7 +358,7 @@ TEST(xpath_parse_error_propagation) TEST(xpath_parse_oom_propagation) { - const char_t* query_base = STR("(//foo[count(. | @*)] | /foo | /foo/bar//more/ancestor-or-self::foobar | /text() | a[1 + 2 * 3 div (1+0) mod 2]//b[1]/c | a[$x])[true()]"); + const char_t* query_base = STR("(//foo[count(. | @*)] | ((a)//b)[1] | /foo | /foo/bar//more/ancestor-or-self::foobar | /text() | a[1 + 2 * 3 div (1+0) mod 2]//b[1]/c | a[$x])[true()]"); xpath_variable_set vars; vars.set(STR("x"), 1.0); -- cgit v1.2.3