Compare commits

...

4 Commits

Author SHA1 Message Date
Arseny Kapoulkine
c237489a6c Fix access modifier offset 2018-10-17 21:14:43 -07:00
Arseny Kapoulkine
3c75d4d612 Fix compilation by setting clang-format standard to C++03 2018-10-17 20:57:34 -07:00
Arseny Kapoulkine
e61dbc5e88 Reformat 2018-10-17 20:53:02 -07:00
Arseny Kapoulkine
7d6901bff2 Add .clang-format and Makefile rule for formatting 2018-10-17 20:52:58 -07:00
40 changed files with 14703 additions and 13713 deletions

12
.clang-format Normal file
View File

@ -0,0 +1,12 @@
Standard: Cpp03
UseTab: ForIndentation
TabWidth: 4
IndentWidth: 4
AccessModifierOffset: -4
BreakBeforeBraces: Allman
IndentCaseLabels: false
ColumnLimit: 0
PointerAlignment: Left
BreakConstructorInitializersBeforeComma: true
NamespaceIndentation: None
AlignEscapedNewlines: DontAlign

View File

@ -74,6 +74,9 @@ release: build/pugixml-$(VERSION).tar.gz build/pugixml-$(VERSION).zip
docs: docs/quickstart.html docs/manual.html
format:
clang-format -i src/*.cpp src/*.hpp tests/*.cpp tests/*.hpp
build/pugixml-%: .FORCE | $(RELEASE)
@mkdir -p $(BUILD)
TIMESTAMP=`git show v$(VERSION) -s --format=%ct` && python scripts/archive.py $@ pugixml-$(VERSION) $$TIMESTAMP $|

File diff suppressed because it is too large Load Diff

View File

@ -32,8 +32,8 @@
// Include STL headers
#ifndef PUGIXML_NO_STL
# include <iterator>
#include <iosfwd>
#include <iterator>
#include <string>
#endif
@ -128,7 +128,7 @@ namespace pugi
// String type used for operations that work with STL string; depends on PUGIXML_WCHAR_MODE
typedef std::basic_string<PUGIXML_CHAR, std::char_traits<PUGIXML_CHAR>, std::allocator<PUGIXML_CHAR> > string_t;
#endif
}
} // namespace pugi
// The PugiXML namespace
namespace pugi
@ -280,13 +280,16 @@ namespace pugi
#endif
// Range-based for loop support
template <typename It> class xml_object_range
template <typename It>
class xml_object_range
{
public:
typedef It const_iterator;
typedef It iterator;
xml_object_range(It b, It e): _begin(b), _end(e)
xml_object_range(It b, It e)
: _begin(b)
, _end(e)
{
}
@ -579,9 +582,11 @@ namespace pugi
xml_parse_result append_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
// Find attribute using predicate. Returns first attribute for which predicate returned true.
template <typename Predicate> xml_attribute find_attribute(Predicate pred) const
template <typename Predicate>
xml_attribute find_attribute(Predicate pred) const
{
if (!_root) return xml_attribute();
if (!_root)
return xml_attribute();
for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute())
if (pred(attrib))
@ -591,9 +596,11 @@ namespace pugi
}
// Find child node using predicate. Returns first child for which predicate returned true.
template <typename Predicate> xml_node find_child(Predicate pred) const
template <typename Predicate>
xml_node find_child(Predicate pred) const
{
if (!_root) return xml_node();
if (!_root)
return xml_node();
for (xml_node node = first_child(); node; node = node.next_sibling())
if (pred(node))
@ -603,23 +610,30 @@ namespace pugi
}
// Find node from subtree using predicate. Returns first node from subtree (depth-first), for which predicate returned true.
template <typename Predicate> xml_node find_node(Predicate pred) const
template <typename Predicate>
xml_node find_node(Predicate pred) const
{
if (!_root) return xml_node();
if (!_root)
return xml_node();
xml_node cur = first_child();
while (cur._root && cur._root != _root)
{
if (pred(cur)) return cur;
if (pred(cur))
return cur;
if (cur.first_child()) cur = cur.first_child();
else if (cur.next_sibling()) cur = cur.next_sibling();
if (cur.first_child())
cur = cur.first_child();
else if (cur.next_sibling())
cur = cur.next_sibling();
else
{
while (!cur.next_sibling() && cur._root != _root) cur = cur.parent();
while (!cur.next_sibling() && cur._root != _root)
cur = cur.parent();
if (cur._root != _root) cur = cur.next_sibling();
if (cur._root != _root)
cur = cur.next_sibling();
}
}
@ -1413,7 +1427,7 @@ namespace pugi
// Get current memory management functions
allocation_function PUGIXML_FUNCTION get_memory_allocation_function();
deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function();
}
} // namespace pugi
#if !defined(PUGIXML_NO_STL) && (defined(_MSC_VER) || defined(__ICC))
namespace std
@ -1422,7 +1436,7 @@ namespace std
std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_node_iterator&);
std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_attribute_iterator&);
std::bidirectional_iterator_tag PUGIXML_FUNCTION _Iter_cat(const pugi::xml_named_node_iterator&);
}
} // namespace std
#endif
#if !defined(PUGIXML_NO_STL) && defined(__SUNPRO_CC)
@ -1432,7 +1446,7 @@ namespace std
std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_node_iterator&);
std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_attribute_iterator&);
std::bidirectional_iterator_tag PUGIXML_FUNCTION __iterator_category(const pugi::xml_named_node_iterator&);
}
} // namespace std
#endif
#endif

View File

@ -1,8 +1,8 @@
#include "allocator.hpp"
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
// Address sanitizer
#if defined(__has_feature)
@ -58,7 +58,8 @@ namespace
size_t aligned_size = align_to_page(size);
void* ptr = allocate_page_aligned(aligned_size + page_size);
if (!ptr) return 0;
if (!ptr)
return 0;
char* end = static_cast<char*>(ptr) + aligned_size;
@ -77,7 +78,7 @@ namespace
DWORD old_flags;
VirtualProtect(rptr, aligned_size + page_size, PAGE_NOACCESS, &old_flags);
}
}
} // namespace
#elif (defined(__APPLE__) || defined(__linux__)) && (defined(__i386) || defined(__x86_64)) && !ADDRESS_SANITIZER
#include <sys/mman.h>
@ -102,7 +103,8 @@ namespace
size_t aligned_size = align_to_page(size);
void* ptr = allocate_page_aligned(aligned_size + page_size);
if (!ptr) return 0;
if (!ptr)
return 0;
char* end = static_cast<char*>(ptr) + aligned_size;
@ -123,7 +125,7 @@ namespace
assert(res == 0);
(void)!res;
}
}
} // namespace
#else
namespace
{
@ -138,7 +140,7 @@ namespace
free(ptr);
}
}
} // namespace
#endif
// High-level allocation functions
@ -147,7 +149,8 @@ const size_t memory_alignment = sizeof(double) > sizeof(void*) ? sizeof(double)
void* memory_allocate(size_t size)
{
void* result = allocate(size + memory_alignment);
if (!result) return 0;
if (!result)
return 0;
memcpy(result, &size, sizeof(size_t));
@ -166,10 +169,10 @@ size_t memory_size(void* ptr)
void memory_deallocate(void* ptr)
{
if (!ptr) return;
if (!ptr)
return;
size_t size = memory_size(ptr);
deallocate(static_cast<char*>(ptr) - memory_alignment, size + memory_alignment);
}

View File

@ -5,7 +5,8 @@
#include <utility>
template <typename T> static void generic_bool_ops_test(const T& obj)
template <typename T>
static void generic_bool_ops_test(const T& obj)
{
T null;
@ -33,7 +34,8 @@ template <typename T> static void generic_bool_ops_test(const T& obj)
CHECK(obj || obj);
}
template <typename T> static void generic_eq_ops_test(const T& obj1, const T& obj2)
template <typename T>
static void generic_eq_ops_test(const T& obj1, const T& obj2)
{
T null = T();
@ -54,7 +56,8 @@ template <typename T> static void generic_eq_ops_test(const T& obj1, const T& ob
CHECK(!(T(obj1) != obj1));
}
template <typename T> static void generic_rel_ops_test(T obj1, T obj2)
template <typename T>
static void generic_rel_ops_test(T obj1, T obj2)
{
T null = T();
@ -103,7 +106,8 @@ template <typename T> static void generic_rel_ops_test(T obj1, T obj2)
CHECK(!(obj1 >= obj2));
}
template <typename T> static void generic_empty_test(const T& obj)
template <typename T>
static void generic_empty_test(const T& obj)
{
T null;

View File

@ -1,10 +1,10 @@
#include "test.hpp"
#include "allocator.hpp"
#include "test.hpp"
#include <assert.h>
#include <float.h>
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <assert.h>
#include <string>
@ -41,7 +41,8 @@ static void* custom_allocate(size_t size)
else
{
void* ptr = memory_allocate(size);
if (!ptr) return 0;
if (!ptr)
return 0;
g_memory_total_size += memory_size(ptr);
g_memory_total_count++;
@ -91,7 +92,7 @@ namespace std
{
_CRTIMP2 _Prhand _Raise_handler;
_CRTIMP2 void __cdecl _Throw(const exception&) {}
}
} // namespace std
#endif
static bool run_test(test_runner* test, const char* test_name, pugi::allocation_function allocate)

View File

@ -5,8 +5,8 @@
#include "writer_string.hpp"
#include <math.h>
#include <float.h>
#include <math.h>
#include <string.h>
#include <wchar.h>
@ -33,10 +33,12 @@ static void build_document_order(std::vector<pugi::xpath_node>& result, pugi::xm
cur = cur.next_sibling();
else
{
while (cur && !cur.next_sibling()) cur = cur.parent();
while (cur && !cur.next_sibling())
cur = cur.parent();
cur = cur.next_sibling();
if (!cur) break;
if (!cur)
break;
}
}
}
@ -83,7 +85,8 @@ static size_t strlength(const pugi::char_t* s)
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);
if (!q) return false;
if (!q)
return false;
const size_t capacity = 64;
pugi::char_t result[capacity];
@ -104,7 +107,8 @@ bool test_xpath_string(const pugi::xpath_node& node, const pugi::char_t* query,
bool test_xpath_boolean(const pugi::xpath_node& node, const pugi::char_t* query, pugi::xpath_variable_set* variables, bool expected)
{
pugi::xpath_query q(query, variables);
if (!q) return false;
if (!q)
return false;
return q.evaluate_boolean(node) == expected;
}
@ -112,7 +116,8 @@ bool test_xpath_boolean(const pugi::xpath_node& node, const pugi::char_t* query,
bool test_xpath_number(const pugi::xpath_node& node, const pugi::char_t* query, pugi::xpath_variable_set* variables, double expected)
{
pugi::xpath_query q(query, variables);
if (!q) return false;
if (!q)
return false;
double value = q.evaluate_number(node);
double absolute_error = fabs(value - expected);
@ -124,7 +129,8 @@ bool test_xpath_number(const pugi::xpath_node& node, const pugi::char_t* query,
bool test_xpath_number_nan(const pugi::xpath_node& node, const pugi::char_t* query, pugi::xpath_variable_set* variables)
{
pugi::xpath_query q(query, variables);
if (!q) return false;
if (!q)
return false;
return test_double_nan(q.evaluate_number(node));
}
@ -155,12 +161,15 @@ void xpath_node_set_tester::check(bool condition)
}
}
xpath_node_set_tester::xpath_node_set_tester(const pugi::xpath_node_set& set, const char* message_): last(0), message(message_)
xpath_node_set_tester::xpath_node_set_tester(const pugi::xpath_node_set& set, const char* message_)
: last(0)
, message(message_)
{
result = set;
// only sort unsorted sets so that we're able to verify reverse order for some axes
if (result.type() == pugi::xpath_node_set::type_unsorted) result.sort();
if (result.type() == pugi::xpath_node_set::type_unsorted)
result.sort();
if (result.empty())
{

View File

@ -36,7 +36,8 @@ struct test_runner
bool test_string_equal(const pugi::char_t* lhs, const pugi::char_t* rhs);
template <typename Node> inline bool test_node_name_value(const Node& node, const pugi::char_t* name, const pugi::char_t* value)
template <typename Node>
inline bool test_node_name_value(const Node& node, const pugi::char_t* name, const pugi::char_t* value)
{
return test_string_equal(node.name(), name) && test_string_equal(node.value(), value);
}
@ -71,7 +72,9 @@ struct xpath_node_set_tester
#endif
struct dummy_fixture {};
struct dummy_fixture
{
};
#define TEST_FIXTURE(name, fixture) \
struct test_runner_helper_##name : fixture \
@ -80,7 +83,10 @@ struct dummy_fixture {};
}; \
static struct test_runner_##name : test_runner \
{ \
test_runner_##name(): test_runner(#name) {} \
test_runner_##name() \
: test_runner(#name) \
{ \
} \
\
virtual void run() PUGIXML_OVERRIDE \
{ \
@ -113,7 +119,11 @@ struct dummy_fixture {};
#define CHECK_JOIN(text, file, line) text " at " file ":" #line
#define CHECK_JOIN2(text, file, line) CHECK_JOIN(text, file, line)
#define CHECK_TEXT(condition, text) if (condition) ; else test_runner::_failure_message = CHECK_JOIN2(text, __FILE__, __LINE__), longjmp(test_runner::_failure_buffer, 1)
#define CHECK_TEXT(condition, text) \
if (condition) \
; \
else \
test_runner::_failure_message = CHECK_JOIN2(text, __FILE__, __LINE__), longjmp(test_runner::_failure_buffer, 1)
#define CHECK_FORCE_FAIL(text) test_runner::_failure_message = CHECK_JOIN2(text, __FILE__, __LINE__), longjmp(test_runner::_failure_buffer, 1)
#if (defined(_MSC_VER) && _MSC_VER == 1200) || defined(__MWERKS__) || (defined(__BORLANDC__) && __BORLANDC__ <= 0x540)
@ -147,9 +157,29 @@ struct dummy_fixture {};
#endif
#ifdef PUGIXML_NO_EXCEPTIONS
#define CHECK_ALLOC_FAIL(code) do { CHECK(!test_runner::_memory_fail_triggered); code; CHECK(test_runner::_memory_fail_triggered); test_runner::_memory_fail_triggered = false; } while (test_runner::_memory_fail_triggered)
#define CHECK_ALLOC_FAIL(code) \
do \
{ \
CHECK(!test_runner::_memory_fail_triggered); \
code; \
CHECK(test_runner::_memory_fail_triggered); \
test_runner::_memory_fail_triggered = false; \
} while (test_runner::_memory_fail_triggered)
#else
#define CHECK_ALLOC_FAIL(code) do { CHECK(!test_runner::_memory_fail_triggered); try { code; } catch (std::bad_alloc&) {} CHECK(test_runner::_memory_fail_triggered); test_runner::_memory_fail_triggered = false; } while (test_runner::_memory_fail_triggered)
#define CHECK_ALLOC_FAIL(code) \
do \
{ \
CHECK(!test_runner::_memory_fail_triggered); \
try \
{ \
code; \
} \
catch (std::bad_alloc&) \
{ \
} \
CHECK(test_runner::_memory_fail_triggered); \
test_runner::_memory_fail_triggered = false; \
} while (test_runner::_memory_fail_triggered)
#endif
#define STR(text) PUGIXML_TEXT(text)

View File

@ -15,8 +15,8 @@
#include <fstream>
#include <sstream>
#include <string>
#include <algorithm>
#include <string>
#ifndef PUGIXML_NO_EXCEPTIONS
#include <stdexcept>
@ -35,7 +35,8 @@ using namespace pugi;
static bool load_file_in_memory(const char* path, char*& data, size_t& size)
{
FILE* file = fopen(path, "rb");
if (!file) return false;
if (!file)
return false;
fseek(file, 0, SEEK_END);
long length = ftell(file);
@ -55,7 +56,8 @@ static bool test_file_contents(const char* path, const char* data, size_t size)
{
char* fdata;
size_t fsize;
if (!load_file_in_memory(path, fdata, fsize)) return false;
if (!load_file_in_memory(path, fdata, fsize))
return false;
bool result = (size == fsize && memcmp(data, fdata, size) == 0);
@ -199,7 +201,8 @@ TEST(document_load_stream_wide_error_previous)
CHECK(!doc.first_child());
}
template <typename T> class char_array_buffer: public std::basic_streambuf<T>
template <typename T>
class char_array_buffer : public std::basic_streambuf<T>
{
public:
char_array_buffer(T* begin, T* end)
@ -234,7 +237,8 @@ TEST(document_load_stream_nonseekable_large)
{
std::basic_string<char_t> str;
str += STR("<node>");
for (int i = 0; i < 10000; ++i) str += STR("<node/>");
for (int i = 0; i < 10000; ++i)
str += STR("<node/>");
str += STR("</node>");
char_array_buffer<char_t> buffer(&str[0], &str[0] + str.length());
@ -273,7 +277,8 @@ TEST(document_load_stream_nonseekable_out_of_memory_large)
{
std::basic_string<char> str;
str += "<node>";
for (int i = 0; i < 10000; ++i) str += "<node />";
for (int i = 0; i < 10000; ++i)
str += "<node />";
str += "</node>";
char_array_buffer<char> buffer(&str[0], &str[0] + str.length());
@ -289,7 +294,8 @@ TEST(document_load_stream_wide_nonseekable_out_of_memory_large)
{
std::basic_string<wchar_t> str;
str += L"<node>";
for (int i = 0; i < 10000; ++i) str += L"<node />";
for (int i = 0; i < 10000; ++i)
str += L"<node />";
str += L"</node>";
char_array_buffer<wchar_t> buffer(&str[0], &str[0] + str.length());
@ -301,12 +307,14 @@ TEST(document_load_stream_wide_nonseekable_out_of_memory_large)
CHECK_ALLOC_FAIL(CHECK(doc.load(in).status == status_out_of_memory));
}
template <typename T> class seek_fail_buffer: public std::basic_streambuf<T>
template <typename T>
class seek_fail_buffer : public std::basic_streambuf<T>
{
public:
int seeks;
seek_fail_buffer(): seeks(0)
seek_fail_buffer()
: seeks(0)
{
}
@ -337,12 +345,14 @@ TEST(document_load_stream_wide_seekable_fail_seek)
CHECK(doc.load(in).status == status_io_error);
}
template <typename T> class tell_fail_buffer: public std::basic_streambuf<T>
template <typename T>
class tell_fail_buffer : public std::basic_streambuf<T>
{
public:
int seeks;
tell_fail_buffer(): seeks(0)
tell_fail_buffer()
: seeks(0)
{
}
@ -378,7 +388,8 @@ TEST(document_load_stream_wide_seekable_fail_tell)
}
#ifndef PUGIXML_NO_EXCEPTIONS
template <typename T> class read_fail_buffer: public std::basic_streambuf<T>
template <typename T>
class read_fail_buffer : public std::basic_streambuf<T>
{
public:
typename std::basic_streambuf<T>::int_type underflow() PUGIXML_OVERRIDE
@ -409,12 +420,14 @@ TEST(document_load_stream_wide_nonseekable_fail_read)
CHECK(doc.load(in).status == status_io_error);
}
template <typename T> class read_fail_seekable_buffer: public std::basic_streambuf<T>
template <typename T>
class read_fail_seekable_buffer : public std::basic_streambuf<T>
{
public:
typename std::basic_streambuf<T>::pos_type offset;
read_fail_seekable_buffer(): offset(0)
read_fail_seekable_buffer()
: offset(0)
{
}
@ -431,9 +444,15 @@ public:
{
switch (dir)
{
case std::ios_base::beg: offset = off; break;
case std::ios_base::cur: offset += off; break;
case std::ios_base::end: offset = 16 + off; break;
case std::ios_base::beg:
offset = off;
break;
case std::ios_base::cur:
offset += off;
break;
case std::ios_base::end:
offset = 16 + off;
break;
default:;
}
return offset;
@ -498,7 +517,8 @@ TEST(document_load_file_large)
std::basic_string<char_t> str;
str += STR("<node>");
for (int i = 0; i < 10000; ++i) str += STR("<node/>");
for (int i = 0; i < 10000; ++i)
str += STR("<node/>");
str += STR("</node>");
CHECK_NODE(doc, str.c_str());
@ -941,8 +961,7 @@ TEST(document_load_file_convert_auto)
"tests/data/utftest_utf32_le_nodecl.xml",
"tests/data/utftest_utf8.xml",
"tests/data/utftest_utf8_bom.xml",
"tests/data/utftest_utf8_nodecl.xml"
};
"tests/data/utftest_utf8_nodecl.xml"};
xml_encoding encodings[] =
{
@ -950,8 +969,7 @@ TEST(document_load_file_convert_auto)
encoding_utf16_le, encoding_utf16_le, encoding_utf16_le,
encoding_utf32_be, encoding_utf32_be, encoding_utf32_be,
encoding_utf32_le, encoding_utf32_le, encoding_utf32_le,
encoding_utf8, encoding_utf8, encoding_utf8
};
encoding_utf8, encoding_utf8, encoding_utf8};
for (unsigned int i = 0; i < sizeof(files) / sizeof(files[0]); ++i)
{
@ -982,8 +1000,7 @@ TEST(document_load_file_convert_specific)
"tests/data/utftest_utf32_le_nodecl.xml",
"tests/data/utftest_utf8.xml",
"tests/data/utftest_utf8_bom.xml",
"tests/data/utftest_utf8_nodecl.xml"
};
"tests/data/utftest_utf8_nodecl.xml"};
xml_encoding encodings[] =
{
@ -991,8 +1008,7 @@ TEST(document_load_file_convert_specific)
encoding_utf16_le, encoding_utf16_le, encoding_utf16_le,
encoding_utf32_be, encoding_utf32_be, encoding_utf32_be,
encoding_utf32_le, encoding_utf32_le, encoding_utf32_le,
encoding_utf8, encoding_utf8, encoding_utf8
};
encoding_utf8, encoding_utf8, encoding_utf8};
for (unsigned int i = 0; i < sizeof(files) / sizeof(files[0]); ++i)
{
@ -1037,14 +1053,12 @@ TEST(document_load_file_convert_native_endianness)
"tests/data/utftest_utf32_le.xml",
"tests/data/utftest_utf32_le_bom.xml",
"tests/data/utftest_utf32_le_nodecl.xml",
}
};
}};
xml_encoding encodings[] =
{
encoding_utf16, encoding_utf16, encoding_utf16,
encoding_utf32, encoding_utf32, encoding_utf32
};
encoding_utf32, encoding_utf32, encoding_utf32};
for (unsigned int i = 0; i < sizeof(files[0]) / sizeof(files[0][0]); ++i)
{
@ -1091,7 +1105,6 @@ struct file_data_t
size_t size;
};
TEST(document_contents_preserve)
{
file_data_t files[] =
@ -1100,8 +1113,7 @@ TEST(document_contents_preserve)
{"tests/data/utftest_utf16_le_clean.xml", encoding_utf16_le, 0, 0},
{"tests/data/utftest_utf32_be_clean.xml", encoding_utf32_be, 0, 0},
{"tests/data/utftest_utf32_le_clean.xml", encoding_utf32_le, 0, 0},
{"tests/data/utftest_utf8_clean.xml", encoding_utf8, 0, 0}
};
{"tests/data/utftest_utf8_clean.xml", encoding_utf8, 0, 0}};
// load files in memory
for (unsigned int i = 0; i < sizeof(files) / sizeof(files[0]); ++i)
@ -1135,8 +1147,7 @@ TEST(document_contents_preserve_latin1)
file_data_t files[] =
{
{"tests/data/latintest_utf8.xml", encoding_utf8, 0, 0},
{"tests/data/latintest_latin1.xml", encoding_latin1, 0, 0}
};
{"tests/data/latintest_latin1.xml", encoding_latin1, 0, 0}};
// load files in memory
for (unsigned int i = 0; i < sizeof(files) / sizeof(files[0]); ++i)
@ -1226,8 +1237,7 @@ TEST(document_load_buffer_empty)
encoding_utf32_be,
encoding_utf32,
encoding_wchar,
encoding_latin1
};
encoding_latin1};
char buffer[1];
@ -1262,8 +1272,7 @@ TEST(document_load_buffer_empty_fragment)
encoding_utf32_be,
encoding_utf32,
encoding_wchar,
encoding_latin1
};
encoding_latin1};
char buffer[1];
@ -1395,7 +1404,8 @@ TEST(document_load_exceptions)
try
{
xml_document doc;
if (!doc.load_string(STR("<node attribute='value"))) throw std::bad_alloc();
if (!doc.load_string(STR("<node attribute='value")))
throw std::bad_alloc();
CHECK_FORCE_FAIL("Expected parsing failure");
}
@ -1600,8 +1610,7 @@ TEST(document_convert_out_of_memory)
{"tests/data/utftest_utf32_be_clean.xml", encoding_utf32_be, 0, 0},
{"tests/data/utftest_utf32_le_clean.xml", encoding_utf32_le, 0, 0},
{"tests/data/utftest_utf8_clean.xml", encoding_utf8, 0, 0},
{"tests/data/latintest_latin1.xml", encoding_latin1, 0, 0}
};
{"tests/data/latintest_latin1.xml", encoding_latin1, 0, 0}};
// load files in memory
for (unsigned int i = 0; i < sizeof(files) / sizeof(files[0]); ++i)

View File

@ -3,9 +3,9 @@
#include <limits>
#include <string>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <limits.h>
using namespace pugi;
@ -926,7 +926,8 @@ TEST(dom_string_out_of_memory)
const unsigned int length = 65536;
static char_t string[length + 1];
for (unsigned int i = 0; i < length; ++i) string[i] = 'a';
for (unsigned int i = 0; i < length; ++i)
string[i] = 'a';
string[length] = 0;
xml_document doc;
@ -1005,7 +1006,8 @@ TEST(dom_node_memory_limit)
const unsigned int length = 65536;
static char_t string[length + 1];
for (unsigned int i = 0; i < length; ++i) string[i] = 'a';
for (unsigned int i = 0; i < length; ++i)
string[i] = 'a';
string[length] = 0;
test_runner::_memory_fail_threshold = 32768 * 2 + sizeof(string);
@ -1024,7 +1026,8 @@ TEST(dom_node_memory_limit_pi)
const unsigned int length = 65536;
static char_t string[length + 1];
for (unsigned int i = 0; i < length; ++i) string[i] = 'a';
for (unsigned int i = 0; i < length; ++i)
string[i] = 'a';
string[length] = 0;
test_runner::_memory_fail_threshold = 32768 * 2 + sizeof(string);
@ -1112,7 +1115,6 @@ TEST_XML(dom_node_append_buffer_convert, "<node>test</node>")
CHECK_NODE(doc, STR("<node>test<n/><n/></node>"));
}
TEST_XML(dom_node_append_buffer_remove, "<node>test</node>")
{
xml_node node = doc.child(STR("node"));
@ -1127,15 +1129,21 @@ TEST_XML(dom_node_append_buffer_remove, "<node>test</node>")
CHECK_NODE(doc, STR("<node>test<child1 id=\"1\"/><child2>text</child2><child3/><child1 id=\"1\"/><child2>text</child2><child3/></node>"));
while (node.remove_child(STR("child2"))) {}
while (node.remove_child(STR("child2")))
{
}
CHECK_NODE(doc, STR("<node>test<child1 id=\"1\"/><child3/><child1 id=\"1\"/><child3/></node>"));
while (node.remove_child(STR("child1"))) {}
while (node.remove_child(STR("child1")))
{
}
CHECK_NODE(doc, STR("<node>test<child3/><child3/></node>"));
while (node.remove_child(STR("child3"))) {}
while (node.remove_child(STR("child3")))
{
}
CHECK_NODE(doc, STR("<node>test</node>"));
@ -1665,7 +1673,8 @@ TEST(dom_node_copy_declaration_empty_name)
CHECK_STRING(decl2.name(), STR(""));
}
template <typename T> bool fp_equal(T lhs, T rhs)
template <typename T>
bool fp_equal(T lhs, T rhs)
{
// Several compilers compare float/double values on x87 stack without proper rounding
// This causes roundtrip tests to fail, although they correctly preserve the data.

View File

@ -4,28 +4,34 @@
#include "test.hpp"
#include <string.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <utility>
#include <vector>
#include <iterator>
#include <string>
#include <utility>
#include <vector>
#include "helpers.hpp"
using namespace pugi;
#ifdef PUGIXML_NO_STL
template <typename I> static I move_iter(I base, int n)
template <typename I>
static I move_iter(I base, int n)
{
if (n > 0) while (n--) ++base;
else while (n++) --base;
if (n > 0)
while (n--)
++base;
else
while (n++)
--base;
return base;
}
#else
template <typename I> static I move_iter(I base, int n)
template <typename I>
static I move_iter(I base, int n)
{
std::advance(base, n);
return base;
@ -659,11 +665,13 @@ struct find_predicate_const
{
bool result;
find_predicate_const(bool result_): result(result_)
find_predicate_const(bool result_)
: result(result_)
{
}
template <typename T> bool operator()(const T&) const
template <typename T>
bool operator()(const T&) const
{
return result;
}
@ -673,11 +681,13 @@ struct find_predicate_prefix
{
const char_t* prefix;
find_predicate_prefix(const char_t* prefix_): prefix(prefix_)
find_predicate_prefix(const char_t* prefix_)
: prefix(prefix_)
{
}
template <typename T> bool operator()(const T& obj) const
template <typename T>
bool operator()(const T& obj) const
{
#ifdef PUGIXML_WCHAR_MODE
// can't use wcsncmp here because of a bug in DMC
@ -788,7 +798,9 @@ struct test_walker: xml_tree_walker
unsigned int call_count;
unsigned int stop_count;
test_walker(unsigned int stop_count_ = 0): call_count(0), stop_count(stop_count_)
test_walker(unsigned int stop_count_ = 0)
: call_count(0)
, stop_count(stop_count_)
{
}

View File

@ -1,3 +1,2 @@
// Tests header guards
#include "../src/pugixml.hpp"
#include "../src/pugixml.hpp"

View File

@ -1,3 +1,3 @@
// Tests compatibility with iosfwd
#include <iosfwd>
#include "../src/pugixml.hpp"
#include <iosfwd>

View File

@ -1,3 +1,3 @@
// Tests compatibility with iostream
#include <iostream>
#include "../src/pugixml.hpp"
#include <iostream>

View File

@ -5,7 +5,6 @@
// Check header guards
#include "../src/pugixml.hpp"
#include "../src/pugixml.hpp"
using namespace pugi;

View File

@ -5,7 +5,6 @@
// Check header guards
#include "../src/pugixml.hpp"
#include "../src/pugixml.hpp"
using namespace pugi;

View File

@ -1,3 +1,3 @@
// Tests compatibility with string
#include <string>
#include "../src/pugixml.hpp"
#include <string>

View File

@ -1,5 +1,5 @@
// Tests compatibility with string/iostream
#include <string>
#include "../src/pugixml.hpp"
#include <istream>
#include <ostream>
#include <string>

View File

@ -1,7 +1,7 @@
#include "test.hpp"
#include "writer_string.hpp"
#include "allocator.hpp"
#include "writer_string.hpp"
#include <string>
#include <vector>
@ -30,7 +30,7 @@ namespace
page_deallocs += is_page(memory_size(ptr));
memory_deallocate(ptr);
}
}
} // namespace
TEST(memory_custom_memory_management)
{
@ -229,7 +229,8 @@ TEST(memory_string_allocate_decreasing)
std::basic_string<char_t> s = STR("ab");
for (int i = 0; i < 17; ++i) s += s;
for (int i = 0; i < 17; ++i)
s += s;
for (int j = 0; j < 17; ++j)
{
@ -286,7 +287,8 @@ TEST(memory_string_allocate_decreasing_inplace)
std::basic_string<char_t> s = STR("ab");
for (int i = 0; i < 17; ++i) s += s;
for (int i = 0; i < 17; ++i)
s += s;
for (int j = 0; j < 17; ++j)
{

View File

@ -464,8 +464,7 @@ TEST(parse_pcdata_trim)
{STR("<node> test&amp;&amp;&amp;&amp;&amp;&amp;&amp; </node>"), STR("test&amp;&amp;&amp;&amp;&amp;&amp;&amp;"), 0},
{STR("<node> test&amp;&amp;&amp;&amp;&amp;&amp;&amp; </node>"), STR("test&&&&&&&"), parse_escapes},
{STR(" test&amp;&amp;&amp;&amp;&amp;&amp;&amp; "), STR("test&&&&&&&"), parse_fragment | parse_escapes},
{ STR("<node>\r\n\t text \t\n\r m&amp;&amp;e \r\n\t</node>"), STR("text \t\n\n m&&e"), parse_eol | parse_escapes }
};
{STR("<node>\r\n\t text \t\n\r m&amp;&amp;e \r\n\t</node>"), STR("text \t\n\n m&&e"), parse_eol | parse_escapes}};
for (size_t i = 0; i < sizeof(test_data) / sizeof(test_data[0]); ++i)
{
@ -696,7 +695,6 @@ TEST(parse_attribute_variations)
}
}
TEST(parse_attribute_error)
{
xml_document doc;
@ -1175,8 +1173,7 @@ TEST(parse_fuzz_doctype)
0x3b, 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45, 0xef, 0xbb, 0xbf, 0x3c, 0x3f, 0x78,
0x6d, 0x6c, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x22, 0x31, 0x2e, 0x30, 0x22,
0x3f, 0x3e, 0x3c, 0x21, 0x2d, 0x2d, 0x20, 0xe9, 0x80, 0xb1, 0xe5, 0xa0, 0xb1, 0xe3, 0x82, 0xb4,
0xe3, 0x83, 0xb3, 0x20, 0xef, 0x83, 0x97, 0xe3, 0xa9, 0x2a, 0x20, 0x2d, 0x2d, 0x3e
};
0xe3, 0x83, 0xb3, 0x20, 0xef, 0x83, 0x97, 0xe3, 0xa9, 0x2a, 0x20, 0x2d, 0x2d, 0x3e};
xml_document doc;
CHECK(doc.load_buffer(data, sizeof(data)).status == status_bad_doctype);

View File

@ -3,8 +3,8 @@
#include "test.hpp"
#include <string.h>
#include <wchar.h>
#include <string>
#include <wchar.h>
using namespace pugi;
@ -30,17 +30,24 @@ static bool test_doctype_wf(const char_t* decl)
xml_document doc;
// standalone
if (!load_concat(doc, decl) || !doc.first_child().empty()) return false;
if (!load_concat(doc, decl) || !doc.first_child().empty())
return false;
// pcdata pre/postfix
if (!load_concat(doc, STR("a"), decl) || !test_node(doc, STR("a"), STR(""), format_raw)) return false;
if (!load_concat(doc, decl, STR("b")) || !test_node(doc, STR("b"), STR(""), format_raw)) return false;
if (!load_concat(doc, STR("a"), decl, STR("b")) || !test_node(doc, STR("ab"), STR(""), format_raw)) return false;
if (!load_concat(doc, STR("a"), decl) || !test_node(doc, STR("a"), STR(""), format_raw))
return false;
if (!load_concat(doc, decl, STR("b")) || !test_node(doc, STR("b"), STR(""), format_raw))
return false;
if (!load_concat(doc, STR("a"), decl, STR("b")) || !test_node(doc, STR("ab"), STR(""), format_raw))
return false;
// node pre/postfix
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;
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;
// check load-store contents preservation
CHECK(doc.load_string(decl, parse_doctype | parse_fragment));
@ -54,13 +61,16 @@ static bool test_doctype_nwf(const char_t* decl)
xml_document doc;
// standalone
if (load_concat(doc, decl).status != status_bad_doctype) return false;
if (load_concat(doc, decl).status != status_bad_doctype)
return false;
// pcdata postfix
if (load_concat(doc, decl, STR("b")).status != status_bad_doctype) return false;
if (load_concat(doc, decl, STR("b")).status != status_bad_doctype)
return false;
// node postfix
if (load_concat(doc, decl, STR("<nodeb/>")).status != status_bad_doctype) return false;
if (load_concat(doc, decl, STR("<nodeb/>")).status != status_bad_doctype)
return false;
return true;
}

View File

@ -2,9 +2,9 @@
#include "writer_string.hpp"
#include <string>
#include <sstream>
#include <stdexcept>
#include <string>
using namespace pugi;
@ -313,7 +313,8 @@ TEST(write_encoding_huge)
// make a large utf16 name consisting of 6-byte char pairs (6 does not divide internal buffer size, so will need split correction)
std::string s_utf16 = std::string("\x00<", 2);
for (unsigned int i = 0; i < N; ++i) s_utf16 += "\x20\xAC\xd8\x52\xdf\x62";
for (unsigned int i = 0; i < N; ++i)
s_utf16 += "\x20\xAC\xd8\x52\xdf\x62";
s_utf16 += std::string("\x00/\x00>", 4);
@ -322,7 +323,8 @@ TEST(write_encoding_huge)
std::string s_utf8 = "<";
for (unsigned int j = 0; j < N; ++j) s_utf8 += "\xE2\x82\xAC\xF0\xA4\xAD\xA2";
for (unsigned int j = 0; j < N; ++j)
s_utf8 += "\xE2\x82\xAC\xF0\xA4\xAD\xA2";
s_utf8 += " />\n";
@ -340,7 +342,8 @@ TEST(write_encoding_huge_invalid)
// make a large utf16 name consisting of leading surrogate chars
std::basic_string<wchar_t> s_utf16;
for (unsigned int i = 0; i < N; ++i) s_utf16 += static_cast<wchar_t>(0xd852);
for (unsigned int i = 0; i < N; ++i)
s_utf16 += static_cast<wchar_t>(0xd852);
xml_document doc;
doc.append_child().set_name(s_utf16.c_str());
@ -356,7 +359,8 @@ TEST(write_encoding_huge)
// make a large utf8 name consisting of 3-byte chars (3 does not divide internal buffer size, so will need split correction)
std::string s_utf8 = "<";
for (unsigned int i = 0; i < N; ++i) s_utf8 += "\xE2\x82\xAC";
for (unsigned int i = 0; i < N; ++i)
s_utf8 += "\xE2\x82\xAC";
s_utf8 += "/>";
@ -365,7 +369,8 @@ TEST(write_encoding_huge)
std::string s_utf16 = std::string("\x00<", 2);
for (unsigned int j = 0; j < N; ++j) s_utf16 += "\x20\xAC";
for (unsigned int j = 0; j < N; ++j)
s_utf16 += "\x20\xAC";
s_utf16 += std::string("\x00 \x00/\x00>\x00\n", 8);
@ -379,7 +384,8 @@ TEST(write_encoding_huge_invalid)
// make a large utf8 name consisting of non-leading chars
std::string s_utf8;
for (unsigned int i = 0; i < N; ++i) s_utf8 += "\x82";
for (unsigned int i = 0; i < N; ++i)
s_utf8 += "\x82";
xml_document doc;
doc.append_child().set_name(s_utf8.c_str());
@ -573,15 +579,13 @@ TEST(write_pcdata_whitespace_fixedpoint)
0,
parse_ws_pcdata,
parse_ws_pcdata_single,
parse_trim_pcdata
};
parse_trim_pcdata};
static const unsigned int flags_format[] =
{
0,
format_raw,
format_indent
};
format_indent};
for (unsigned int i = 0; i < sizeof(flags_parse) / sizeof(flags_parse[0]); ++i)
{

View File

@ -5,10 +5,10 @@
#include <string.h>
#include <wchar.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits>
#include <string>
#include <vector>
using namespace pugi;
@ -24,7 +24,8 @@ TEST(xpath_allocator_many_pages)
{
std::basic_string<char_t> query = STR("0");
for (int i = 0; i < 128; ++i) query += STR("+string-length('abcdefgh')");
for (int i = 0; i < 128; ++i)
query += STR("+string-length('abcdefgh')");
CHECK_XPATH_NUMBER(xml_node(), query.c_str(), 1024);
}
@ -33,7 +34,8 @@ TEST(xpath_allocator_large_page)
{
std::basic_string<char_t> query;
for (int i = 0; i < 1024; ++i) query += STR("abcdefgh");
for (int i = 0; i < 1024; ++i)
query += STR("abcdefgh");
CHECK_XPATH_NUMBER(xml_node(), (STR("string-length('") + query + STR("')")).c_str(), 8192);
}
@ -162,7 +164,8 @@ TEST(xpath_sort_random_medium)
xpath_node_set_tester tester(copy, "sorted order failed");
for (unsigned int i = 2; i < 39; ++i) tester % i;
for (unsigned int i = 2; i < 39; ++i)
tester % i;
}
TEST(xpath_sort_random_large)
@ -191,7 +194,8 @@ TEST(xpath_sort_random_large)
xpath_node_set_tester tester(copy, "sorted order failed");
for (unsigned int i = 2; i < 129; ++i) tester % i;
for (unsigned int i = 2; i < 129; ++i)
tester % i;
}
TEST(xpath_long_numbers_parse)
@ -247,7 +251,8 @@ TEST(xpath_denorm_numbers)
// 10^-318 - double denormal
for (int i = 0; i < 106; ++i)
{
if (i != 0) query += STR(" * ");
if (i != 0)
query += STR(" * ");
query += STR("0.001");
}
@ -728,7 +733,8 @@ TEST(xpath_allocate_string_out_of_memory)
{
std::basic_string<char_t> query;
for (int i = 0; i < 1024; ++i) query += STR("abcdefgh");
for (int i = 0; i < 1024; ++i)
query += STR("abcdefgh");
test_runner::_memory_fail_threshold = 8 * 1024;

View File

@ -430,7 +430,6 @@ TEST_XML(xpath_api_nodeset_move_ctor, "<node><foo/><foo/><bar/></node>")
CHECK(move[1] == doc.first_child().first_child());
}
TEST_XML(xpath_api_nodeset_move_ctor_single, "<node><foo/><foo/><bar/></node>")
{
xpath_node_set set = doc.select_nodes(STR("node/bar"));

View File

@ -829,7 +829,8 @@ TEST(xpath_string_translate_table_out_of_memory)
for (size_t i = 0; i < count; ++i)
{
if (i != 0) query += STR(",");
if (i != 0)
query += STR(",");
query += STR("translate('a','a','A')");
}

View File

@ -109,8 +109,7 @@ TEST(xpath_parse_paths_valid)
STR("/foo|/bar[@id='1234']"), STR("count(//author/attribute::*)"), STR("/child::node()/child::node()[@id='_13563275']"),
STR("10 + (count(descendant::author) * 5)"), STR("10 + count(descendant::author) * 5"), STR("2 + (2 * 5)"), STR("//foo:bar"),
STR("count(//author)+5"), STR("count(//author)+count(//author/attribute::*)"), STR("/foo/bar[@a='1' and @c!='2']"),
STR("12 + (count(//author)+count(//author/attribute::*)) div 2"), STR("text()[.='foo']"), STR("/*/*[@id='123']")
STR("/foo/bar[@a='1' and @b='2']"), STR("/foo/bar[@a='1' and @b!='2']"), STR("//attribute::*[.!='crunchy']"),
STR("12 + (count(//author)+count(//author/attribute::*)) div 2"), STR("text()[.='foo']"), STR("/*/*[@id='123']") STR("/foo/bar[@a='1' and @b='2']"), STR("/foo/bar[@a='1' and @b!='2']"), STR("//attribute::*[.!='crunchy']"),
STR("'//*[contains(string(text()),\"yada yada\")]'"),
// From ajaxslt tests
@ -173,8 +172,7 @@ TEST(xpath_parse_paths_valid)
STR("**..**"),
// Miscellaneous
STR("..***..***.***.***..***..***..")
};
STR("..***..***.***.***..***..***..")};
for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); ++i)
{
@ -189,33 +187,85 @@ TEST(xpath_parse_paths_valid_unicode)
const wchar_t* paths[] =
{
#ifdef U_LITERALS
L"/descendant-or-self::\u90e8\u5206", L"//\u90e8\u5206", L"substring('\uff11\uff12\uff13\uff14\uff15', 0, 3)", L"//\u30bf\u30a4\u30c8\u30eb | //\u30ea\u30f3\u30af",
L"\u8b0e//\u30bf\u30a4\u30c8\u30eb", L"//*[@\u30c7\u30b9\u30c6\u30a3\u30cd\u30a4\u30b7\u30e7\u30f3]", L"\u30da\u30fc\u30b8 = '\u304b\u3089'",
L"/descendant-or-self::\u90e8\u5206",
L"//\u90e8\u5206",
L"substring('\uff11\uff12\uff13\uff14\uff15', 0, 3)",
L"//\u30bf\u30a4\u30c8\u30eb | //\u30ea\u30f3\u30af",
L"\u8b0e//\u30bf\u30a4\u30c8\u30eb",
L"//*[@\u30c7\u30b9\u30c6\u30a3\u30cd\u30a4\u30b7\u30e7\u30f3]",
L"\u30da\u30fc\u30b8 = '\u304b\u3089'",
L"concat(substring-before(@\u30a4\u30e1\u30fc\u30b8,'\u76ee\u5370'),'\u30a2\u30a4\u30b3\u30f3',substring-after(@\u30a4\u30e1\u30fc\u30b8,'\u76ee\u5370'))",
L"\u30bd\u30fc\u30b9|\u30c7\u30b9\u30c6\u30a3\u30cd\u30a4\u30b7\u30e7\u30f3", L"\u30da\u30fc\u30b8 != '\u307e\u3067' and \u30da\u30fc\u30b8 != '\u304b\u3089'",
L"substring-after(\u30a2\u30a4\u30b3\u30f3/@\u30a4\u30e1\u30fc\u30b8, '/\u5730\u56f3\u30d5\u30a1\u30a4\u30eb/\u76ee\u5370')", L"child::\u6bb5\u843d",
L"substring-before(\u6587\u5b57\u5217, \u6587\u5b57)", L"\u30bb\u30b0\u30e1\u30f3\u30c8/@\u6642\u523b", L"attribute::\u540d\u524d", L"descendant::\u6bb5\u843d",
L"ancestor::\u90e8\u5206", L"ancestor-or-self::\u90e8\u5206", L"descendant-or-self::\u6bb5\u843d", L"self::\u6bb5\u843d", L"child::\u7ae0/descendant::\u6bb5\u843d",
L"child::*/child::\u6bb5\u843d", L"/descendant::\u6bb5\u843d", L"/descendant::\u9806\u5e8f\u30ea\u30b9\u30c8/child::\u9805\u76ee", L"child::\u6bb5\u843d[position()=1]",
L"child::\u6bb5\u843d[position()=last()]", L"child::\u6bb5\u843d[position()=last()-1]", L"child::\u6bb5\u843d[position()>1]", L"following-sibling::\u7ae0[position()=1]",
L"preceding-sibling::\u7ae0[position()=1]", L"/descendant::\u56f3\u8868[position()=42]", L"/child::\u6587\u66f8/child::\u7ae0[position()=5]/child::\u7bc0[position()=2]",
L"child::\u6bb5\u843d[attribute::\u30bf\u30a4\u30d7='\u8b66\u544a']", L"child::\u6bb5\u843d[attribute::\u30bf\u30a4\u30d7='\u8b66\u544a'][position()=5]",
L"child::\u6bb5\u843d[position()=5][attribute::\u30bf\u30a4\u30d7='\u8b66\u544a']", L"child::\u7ae0[child::\u30bf\u30a4\u30c8\u30eb='\u306f\u3058\u3081\u306b']",
L"child::\u7ae0[child::\u30bf\u30a4\u30c8\u30eb]", L"child::*[self::\u7ae0 or self::\u4ed8\u9332]", L"child::*[self::\u7ae0 or self::\u4ed8\u9332][position()=last()]",
L"\u30bd\u30fc\u30b9|\u30c7\u30b9\u30c6\u30a3\u30cd\u30a4\u30b7\u30e7\u30f3",
L"\u30da\u30fc\u30b8 != '\u307e\u3067' and \u30da\u30fc\u30b8 != '\u304b\u3089'",
L"substring-after(\u30a2\u30a4\u30b3\u30f3/@\u30a4\u30e1\u30fc\u30b8, '/\u5730\u56f3\u30d5\u30a1\u30a4\u30eb/\u76ee\u5370')",
L"child::\u6bb5\u843d",
L"substring-before(\u6587\u5b57\u5217, \u6587\u5b57)",
L"\u30bb\u30b0\u30e1\u30f3\u30c8/@\u6642\u523b",
L"attribute::\u540d\u524d",
L"descendant::\u6bb5\u843d",
L"ancestor::\u90e8\u5206",
L"ancestor-or-self::\u90e8\u5206",
L"descendant-or-self::\u6bb5\u843d",
L"self::\u6bb5\u843d",
L"child::\u7ae0/descendant::\u6bb5\u843d",
L"child::*/child::\u6bb5\u843d",
L"/descendant::\u6bb5\u843d",
L"/descendant::\u9806\u5e8f\u30ea\u30b9\u30c8/child::\u9805\u76ee",
L"child::\u6bb5\u843d[position()=1]",
L"child::\u6bb5\u843d[position()=last()]",
L"child::\u6bb5\u843d[position()=last()-1]",
L"child::\u6bb5\u843d[position()>1]",
L"following-sibling::\u7ae0[position()=1]",
L"preceding-sibling::\u7ae0[position()=1]",
L"/descendant::\u56f3\u8868[position()=42]",
L"/child::\u6587\u66f8/child::\u7ae0[position()=5]/child::\u7bc0[position()=2]",
L"child::\u6bb5\u843d[attribute::\u30bf\u30a4\u30d7='\u8b66\u544a']",
L"child::\u6bb5\u843d[attribute::\u30bf\u30a4\u30d7='\u8b66\u544a'][position()=5]",
L"child::\u6bb5\u843d[position()=5][attribute::\u30bf\u30a4\u30d7='\u8b66\u544a']",
L"child::\u7ae0[child::\u30bf\u30a4\u30c8\u30eb='\u306f\u3058\u3081\u306b']",
L"child::\u7ae0[child::\u30bf\u30a4\u30c8\u30eb]",
L"child::*[self::\u7ae0 or self::\u4ed8\u9332]",
L"child::*[self::\u7ae0 or self::\u4ed8\u9332][position()=last()]",
#else
L"/descendant-or-self::\x90e8\x5206", L"//\x90e8\x5206", L"substring('\xff11\xff12\xff13\xff14\xff15', 0, 3)", L"//\x30bf\x30a4\x30c8\x30eb | //\x30ea\x30f3\x30af",
L"\x8b0e//\x30bf\x30a4\x30c8\x30eb", L"//*[@\x30c7\x30b9\x30c6\x30a3\x30cd\x30a4\x30b7\x30e7\x30f3]", L"\x30da\x30fc\x30b8 = '\x304b\x3089'",
L"/descendant-or-self::\x90e8\x5206",
L"//\x90e8\x5206",
L"substring('\xff11\xff12\xff13\xff14\xff15', 0, 3)",
L"//\x30bf\x30a4\x30c8\x30eb | //\x30ea\x30f3\x30af",
L"\x8b0e//\x30bf\x30a4\x30c8\x30eb",
L"//*[@\x30c7\x30b9\x30c6\x30a3\x30cd\x30a4\x30b7\x30e7\x30f3]",
L"\x30da\x30fc\x30b8 = '\x304b\x3089'",
L"concat(substring-before(@\x30a4\x30e1\x30fc\x30b8,'\x76ee\x5370'),'\x30a2\x30a4\x30b3\x30f3',substring-after(@\x30a4\x30e1\x30fc\x30b8,'\x76ee\x5370'))",
L"\x30bd\x30fc\x30b9|\x30c7\x30b9\x30c6\x30a3\x30cd\x30a4\x30b7\x30e7\x30f3", L"\x30da\x30fc\x30b8 != '\x307e\x3067' and \x30da\x30fc\x30b8 != '\x304b\x3089'",
L"substring-after(\x30a2\x30a4\x30b3\x30f3/@\x30a4\x30e1\x30fc\x30b8, '/\x5730\x56f3\x30d5\x30a1\x30a4\x30eb/\x76ee\x5370')", L"child::\x6bb5\x843d",
L"substring-before(\x6587\x5b57\x5217, \x6587\x5b57)", L"\x30bb\x30b0\x30e1\x30f3\x30c8/@\x6642\x523b", L"attribute::\x540d\x524d", L"descendant::\x6bb5\x843d",
L"ancestor::\x90e8\x5206", L"ancestor-or-self::\x90e8\x5206", L"descendant-or-self::\x6bb5\x843d", L"self::\x6bb5\x843d", L"child::\x7ae0/descendant::\x6bb5\x843d",
L"child::*/child::\x6bb5\x843d", L"/descendant::\x6bb5\x843d", L"/descendant::\x9806\x5e8f\x30ea\x30b9\x30c8/child::\x9805\x76ee", L"child::\x6bb5\x843d[position()=1]",
L"child::\x6bb5\x843d[position()=last()]", L"child::\x6bb5\x843d[position()=last()-1]", L"child::\x6bb5\x843d[position()>1]", L"following-sibling::\x7ae0[position()=1]",
L"preceding-sibling::\x7ae0[position()=1]", L"/descendant::\x56f3\x8868[position()=42]", L"/child::\x6587\x66f8/child::\x7ae0[position()=5]/child::\x7bc0[position()=2]",
L"child::\x6bb5\x843d[attribute::\x30bf\x30a4\x30d7='\x8b66\x544a']", L"child::\x6bb5\x843d[attribute::\x30bf\x30a4\x30d7='\x8b66\x544a'][position()=5]",
L"child::\x6bb5\x843d[position()=5][attribute::\x30bf\x30a4\x30d7='\x8b66\x544a']", L"child::\x7ae0[child::\x30bf\x30a4\x30c8\x30eb='\x306f\x3058\x3081\x306b']",
L"child::\x7ae0[child::\x30bf\x30a4\x30c8\x30eb]", L"child::*[self::\x7ae0 or self::\x4ed8\x9332]", L"child::*[self::\x7ae0 or self::\x4ed8\x9332][position()=last()]",
L"\x30bd\x30fc\x30b9|\x30c7\x30b9\x30c6\x30a3\x30cd\x30a4\x30b7\x30e7\x30f3",
L"\x30da\x30fc\x30b8 != '\x307e\x3067' and \x30da\x30fc\x30b8 != '\x304b\x3089'",
L"substring-after(\x30a2\x30a4\x30b3\x30f3/@\x30a4\x30e1\x30fc\x30b8, '/\x5730\x56f3\x30d5\x30a1\x30a4\x30eb/\x76ee\x5370')",
L"child::\x6bb5\x843d",
L"substring-before(\x6587\x5b57\x5217, \x6587\x5b57)",
L"\x30bb\x30b0\x30e1\x30f3\x30c8/@\x6642\x523b",
L"attribute::\x540d\x524d",
L"descendant::\x6bb5\x843d",
L"ancestor::\x90e8\x5206",
L"ancestor-or-self::\x90e8\x5206",
L"descendant-or-self::\x6bb5\x843d",
L"self::\x6bb5\x843d",
L"child::\x7ae0/descendant::\x6bb5\x843d",
L"child::*/child::\x6bb5\x843d",
L"/descendant::\x6bb5\x843d",
L"/descendant::\x9806\x5e8f\x30ea\x30b9\x30c8/child::\x9805\x76ee",
L"child::\x6bb5\x843d[position()=1]",
L"child::\x6bb5\x843d[position()=last()]",
L"child::\x6bb5\x843d[position()=last()-1]",
L"child::\x6bb5\x843d[position()>1]",
L"following-sibling::\x7ae0[position()=1]",
L"preceding-sibling::\x7ae0[position()=1]",
L"/descendant::\x56f3\x8868[position()=42]",
L"/child::\x6587\x66f8/child::\x7ae0[position()=5]/child::\x7bc0[position()=2]",
L"child::\x6bb5\x843d[attribute::\x30bf\x30a4\x30d7='\x8b66\x544a']",
L"child::\x6bb5\x843d[attribute::\x30bf\x30a4\x30d7='\x8b66\x544a'][position()=5]",
L"child::\x6bb5\x843d[position()=5][attribute::\x30bf\x30a4\x30d7='\x8b66\x544a']",
L"child::\x7ae0[child::\x30bf\x30a4\x30c8\x30eb='\x306f\x3058\x3081\x306b']",
L"child::\x7ae0[child::\x30bf\x30a4\x30c8\x30eb]",
L"child::*[self::\x7ae0 or self::\x4ed8\x9332]",
L"child::*[self::\x7ae0 or self::\x4ed8\x9332][position()=last()]",
#endif
};
@ -250,8 +300,8 @@ TEST(xpath_parse_invalid)
STR("|/gjs"), STR("+3"), STR("/html/body/p != ---'div'/a"), STR(""), STR("@"), STR("#akf"), STR(",")
// Miscellaneous
STR("..."), STR("...."), STR("**"), STR("****"), STR("******"), STR("..***..***.***.***..***..***..*"), STR("/[1]")
};
STR("..."),
STR("...."), STR("**"), STR("****"), STR("******"), STR("..***..***.***.***..***..***..*"), STR("/[1]")};
for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); ++i)
{

View File

@ -4,8 +4,8 @@
#include "test.hpp"
#include <string>
#include <algorithm>
#include <string>
using namespace pugi;

View File

@ -111,7 +111,6 @@ TEST_XML(xpath_xalan_match_1, "<root><x spot='a' num='1'/><x spot='b' num='2'/><
CHECK_XPATH_NODESET(c, STR("x[(((((2*10)-4)+9) div 5) mod 3)]")) % 6;
}
TEST_XML(xpath_xalan_match_2, "<doc><l1><v2>doc-l1-v2</v2><x2>doc-l1-x2</x2><l2><v3>doc-l1-l2-v3</v3><w3>doc-l1-l2-w3</w3><x3>doc-l1-l2-x3</x3><y3>doc-l1-l2-y3</y3><l3><v4>doc-l1-l2-l3-v4</v4><x4>doc-l1-l2-l3-x4</x4></l3></l2></l1></doc>")
{
CHECK_XPATH_STRING(doc, STR("doc/l1/v2"), STR("doc-l1-v2"));

View File

@ -5,10 +5,12 @@
static bool test_narrow(const std::string& result, const char* expected, size_t length)
{
// check result
if (result != std::string(expected, expected + length)) return false;
if (result != std::string(expected, expected + length))
return false;
// check comparison operator (incorrect implementation can theoretically early-out on zero terminators...)
if (length > 0 && result == std::string(expected, expected + length - 1) + "?") return false;
if (length > 0 && result == std::string(expected, expected + length - 1) + "?")
return false;
return true;
}