From eae480cfc976a52570bd5b0adc202fa0f8a52ee3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 9 Nov 2020 17:22:12 +0100 Subject: Split out URI tests --- test/test_serd.c | 136 ------------------------------------------------------- 1 file changed, 136 deletions(-) (limited to 'test/test_serd.c') diff --git a/test/test_serd.c b/test/test_serd.c index 05fb0461..34661fd5 100644 --- a/test/test_serd.c +++ b/test/test_serd.c @@ -104,31 +104,6 @@ eof_test_error(void* stream) return 0; } -static void -test_file_uri(const char* hostname, - const char* path, - bool escape, - const char* expected_uri, - const char* expected_path) -{ - if (!expected_path) { - expected_path = path; - } - - SerdNode node = serd_node_new_file_uri( - USTR(path), USTR(hostname), 0, escape); - - uint8_t* out_hostname = NULL; - uint8_t* out_path = serd_file_uri_parse(node.buf, &out_hostname); - assert(!strcmp((const char*)node.buf, expected_uri)); - assert((hostname && out_hostname) || (!hostname && !out_hostname)); - assert(!strcmp((const char*)out_path, (const char*)expected_path)); - - serd_free(out_path); - serd_free(out_hostname); - serd_node_free(&node); -} - static void test_read_chunks(void) { @@ -309,57 +284,6 @@ test_strerror(void) assert(!strcmp((const char*)msg, "Unknown error")); } -static void -test_uri_to_path(void) -{ - const uint8_t* uri = (const uint8_t*)"file:///home/user/foo.ttl"; - assert(!strcmp((const char*)serd_uri_to_path(uri), "/home/user/foo.ttl")); - - uri = (const uint8_t*)"file://localhost/home/user/foo.ttl"; - assert(!strcmp((const char*)serd_uri_to_path(uri), "/home/user/foo.ttl")); - - uri = (const uint8_t*)"file:illegal/file/uri"; - assert(!serd_uri_to_path(uri)); - - uri = (const uint8_t*)"file:///c:/awful/system"; - assert(!strcmp((const char*)serd_uri_to_path(uri), "c:/awful/system")); - - uri = (const uint8_t*)"file:///c:awful/system"; - assert(!strcmp((const char*)serd_uri_to_path(uri), "/c:awful/system")); - - uri = (const uint8_t*)"file:///0/1"; - assert(!strcmp((const char*)serd_uri_to_path(uri), "/0/1")); - - uri = (const uint8_t*)"C:\\Windows\\Sucks"; - assert(!strcmp((const char*)serd_uri_to_path(uri), "C:\\Windows\\Sucks")); - - uri = (const uint8_t*)"C|/Windows/Sucks"; - assert(!strcmp((const char*)serd_uri_to_path(uri), "C|/Windows/Sucks")); -} - -static void -test_uri_parsing(void) -{ - test_file_uri(NULL, "C:/My 100%", true, - "file:///C:/My%20100%%", NULL); - test_file_uri("ahost", "C:\\Pointless Space", true, - "file://ahost/C:/Pointless%20Space", "C:/Pointless Space"); - test_file_uri(NULL, "/foo/bar", true, - "file:///foo/bar", NULL); - test_file_uri("bhost", "/foo/bar", true, - "file://bhost/foo/bar", NULL); - test_file_uri(NULL, "a/relative path", false, - "a/relative path", NULL); - test_file_uri(NULL, "a/relative ", true, - "a/relative%20%3Cpath%3E", NULL); - - // Test tolerance of parsing junk URI escapes - - uint8_t* out_path = serd_file_uri_parse(USTR("file:///foo/%0Xbar"), NULL); - assert(!strcmp((const char*)out_path, "/foo/bar")); - serd_free(out_path); -} - static void test_node_equals(void) { @@ -406,62 +330,6 @@ test_node_from_substring(void) !strncmp((const char*)a_b.buf, "a\"bc", 4)); } -static void -test_uri_from_string(void) -{ - SerdNode nonsense = serd_node_new_uri_from_string(NULL, NULL, NULL); - assert(nonsense.type == SERD_NOTHING); - - SerdURI base_uri; - SerdNode base = serd_node_new_uri_from_string(USTR("http://example.org/"), - NULL, &base_uri); - SerdNode nil = serd_node_new_uri_from_string(NULL, &base_uri, NULL); - SerdNode nil2 = serd_node_new_uri_from_string(USTR(""), &base_uri, NULL); - assert(nil.type == SERD_URI); - assert(!strcmp((const char*)nil.buf, (const char*)base.buf)); - assert(nil2.type == SERD_URI); - assert(!strcmp((const char*)nil2.buf, (const char*)base.buf)); - serd_node_free(&nil); - serd_node_free(&nil2); - - serd_node_free(&base); -} - -static void -test_relative_uri(void) -{ - SerdURI base_uri; - SerdNode base = serd_node_new_uri_from_string(USTR("http://example.org/"), - NULL, &base_uri); - - SerdNode abs = serd_node_from_string(SERD_URI, USTR("http://example.org/foo/bar")); - SerdURI abs_uri; - serd_uri_parse(abs.buf, &abs_uri); - - SerdURI rel_uri; - SerdNode rel = serd_node_new_relative_uri(&abs_uri, &base_uri, NULL, &rel_uri); - assert(!strcmp((const char*)rel.buf, "/foo/bar")); - - SerdNode up = serd_node_new_relative_uri(&base_uri, &abs_uri, NULL, NULL); - assert(!strcmp((const char*)up.buf, "../")); - - SerdNode noup = serd_node_new_relative_uri(&base_uri, &abs_uri, &abs_uri, NULL); - assert(!strcmp((const char*)noup.buf, "http://example.org/")); - - SerdNode x = serd_node_from_string(SERD_URI, USTR("http://example.org/foo/x")); - SerdURI x_uri; - serd_uri_parse(x.buf, &x_uri); - - SerdNode x_rel = serd_node_new_relative_uri(&x_uri, &abs_uri, &abs_uri, NULL); - assert(!strcmp((const char*)x_rel.buf, "x")); - - serd_node_free(&x_rel); - serd_node_free(&noup); - serd_node_free(&up); - serd_node_free(&rel); - serd_node_free(&base); -} - static void test_writer(const char* const path) { @@ -646,13 +514,9 @@ main(void) test_blob_to_node(); test_strlen(); test_strerror(); - test_uri_to_path(); - test_uri_parsing(); test_node_equals(); test_node_from_string(); test_node_from_substring(); - test_uri_from_string(); - test_relative_uri(); test_read_chunks(); const char* const path = "serd_test.ttl"; -- cgit v1.2.1