summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/main.cpp2
-rw-r--r--tests/test_compact.cpp34
-rw-r--r--tests/test_document.cpp17
3 files changed, 52 insertions, 1 deletions
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_compact.cpp b/tests/test_compact.cpp
index f9560c9..f5dc4ee 100644
--- a/tests/test_compact.cpp
+++ b/tests/test_compact.cpp
@@ -111,4 +111,38 @@ TEST_XML(compact_out_of_memory_remove, "<n a='v'/>")
CHECK_ALLOC_FAIL(CHECK(!n.remove_attribute(a)));
CHECK_ALLOC_FAIL(CHECK(!doc.remove_child(n)));
}
+
+TEST_XML(compact_pointer_attribute_list, "<n a='v'/>")
+{
+ xml_node n = doc.child(STR("n"));
+ xml_attribute a = n.attribute(STR("a"));
+
+ // make sure we fill the page with node x
+ for (int i = 0; i < 1000; ++i)
+ doc.append_child(STR("x"));
+
+ // this requires extended encoding for prev_attribute_c/next_attribute
+ n.append_attribute(STR("b"));
+
+ // this requires extended encoding for first_attribute
+ n.remove_attribute(a);
+
+ CHECK(!n.attribute(STR("a")));
+ CHECK(n.attribute(STR("b")));
+}
+
+TEST_XML(compact_pointer_node_list, "<n/>")
+{
+ xml_node n = doc.child(STR("n"));
+
+ // make sure we fill the page with node x
+ // this requires extended encoding for prev_sibling_c/next_sibling
+ for (int i = 0; i < 1000; ++i)
+ doc.append_child(STR("x"));
+
+ // this requires extended encoding for first_child
+ n.append_child(STR("child"));
+
+ CHECK(n.child(STR("child")));
+}
#endif
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, "<node/>")
{
xml_writer_string writer;