mirror of
https://github.com/zeux/pugixml.git
synced 2024-12-26 12:41:06 +08:00
tests: Add tests for loading special files
New tests try to load a folder as an XML document, and a device. Both are intended to exercise some otherwise non-hittable error paths in load_file implementation.
This commit is contained in:
parent
0fbc043183
commit
c40fd364ce
@ -41,7 +41,7 @@ static void* custom_allocate(size_t size)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
void* ptr = memory_allocate(size);
|
void* ptr = memory_allocate(size);
|
||||||
assert(ptr);
|
if (!ptr) return 0;
|
||||||
|
|
||||||
g_memory_total_size += memory_size(ptr);
|
g_memory_total_size += memory_size(ptr);
|
||||||
g_memory_total_count++;
|
g_memory_total_count++;
|
||||||
|
@ -383,6 +383,23 @@ TEST(document_load_file_wide_out_of_memory)
|
|||||||
CHECK(result.status == status_out_of_memory || result.status == status_file_not_found);
|
CHECK(result.status == status_out_of_memory || result.status == status_file_not_found);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__linux__) || defined(__APPLE__)
|
||||||
|
TEST(document_load_file_special_folder)
|
||||||
|
{
|
||||||
|
xml_document doc;
|
||||||
|
xml_parse_result result = doc.load_file(".");
|
||||||
|
// status_out_of_memory is somewhat counter-intuitive but on Linux ftell returns LONG_MAX for directories
|
||||||
|
CHECK(result.status == status_file_not_found || result.status == status_io_error || result.status == status_out_of_memory);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(document_load_file_special_device)
|
||||||
|
{
|
||||||
|
xml_document doc;
|
||||||
|
xml_parse_result result = doc.load_file("/dev/tty");
|
||||||
|
CHECK(result.status == status_file_not_found || result.status == status_io_error);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
TEST_XML(document_save, "<node/>")
|
TEST_XML(document_save, "<node/>")
|
||||||
{
|
{
|
||||||
xml_writer_string writer;
|
xml_writer_string writer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user