From c40fd364ce856405f86fcc67250d36480e3712b8 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 15 Jun 2017 07:17:26 -0700 Subject: 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. --- tests/main.cpp | 2 +- tests/test_document.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/main.cpp b/tests/main.cpp index 712edda..352b58b 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -41,7 +41,7 @@ static void* custom_allocate(size_t size) else { void* ptr = memory_allocate(size); - assert(ptr); + if (!ptr) return 0; g_memory_total_size += memory_size(ptr); g_memory_total_count++; diff --git a/tests/test_document.cpp b/tests/test_document.cpp index 9860737..c7ceb8f 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -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); } +#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, "") { xml_writer_string writer; -- cgit v1.2.3