aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-07-10 12:10:24 -0400
committerDavid Robillard <d@drobilla.net>2022-01-13 20:05:40 -0500
commit045c52b442a48c0ef9002539f63854eb198acadd (patch)
treec5a20ecbaad9488a192f1fccc0227b88caeab041
parenta25c9927ce648bc83064bb8ea91c9ca8b8a9582f (diff)
downloadserd-045c52b442a48c0ef9002539f63854eb198acadd.tar.gz
serd-045c52b442a48c0ef9002539f63854eb198acadd.tar.bz2
serd-045c52b442a48c0ef9002539f63854eb198acadd.zip
Improve URI tests
-rw-r--r--test/test_uri.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/test/test_uri.c b/test/test_uri.c
index 60d93831..4eb4cc29 100644
--- a/test/test_uri.c
+++ b/test/test_uri.c
@@ -24,10 +24,31 @@
#include <string.h>
static void
-test_file_uri(const char* hostname,
- const char* path,
- const char* expected_uri,
- const char* expected_path)
+test_uri_string_has_scheme(void)
+{
+ assert(!serd_uri_string_has_scheme("relative"));
+ assert(!serd_uri_string_has_scheme("http"));
+ assert(!serd_uri_string_has_scheme("5nostartdigit"));
+ assert(!serd_uri_string_has_scheme("+nostartplus"));
+ assert(!serd_uri_string_has_scheme("-nostartminus"));
+ assert(!serd_uri_string_has_scheme(".nostartdot"));
+ assert(!serd_uri_string_has_scheme(":missing"));
+ assert(!serd_uri_string_has_scheme("a/slash/is/not/a/scheme/char"));
+
+ assert(serd_uri_string_has_scheme("http://example.org/"));
+ assert(serd_uri_string_has_scheme("https://example.org/"));
+ assert(serd_uri_string_has_scheme("allapha:path"));
+ assert(serd_uri_string_has_scheme("w1thd1g1t5:path"));
+ assert(serd_uri_string_has_scheme("with.dot:path"));
+ assert(serd_uri_string_has_scheme("with+plus:path"));
+ assert(serd_uri_string_has_scheme("with-minus:path"));
+}
+
+static void
+test_file_uri(const char* const hostname,
+ const char* const path,
+ const char* const expected_uri,
+ const char* expected_path)
{
if (!expected_path) {
expected_path = path;
@@ -39,6 +60,7 @@ test_file_uri(const char* hostname,
char* out_path = serd_parse_file_uri(node_str, &out_hostname);
assert(!strcmp(node_str, expected_uri));
assert((hostname && out_hostname) || (!hostname && !out_hostname));
+ assert(!hostname || !strcmp(hostname, out_hostname));
assert(!strcmp(out_path, expected_path));
serd_free(out_path);
@@ -50,12 +72,9 @@ static void
test_uri_parsing(void)
{
test_file_uri(NULL, "C:/My 100%", "file:///C:/My%20100%%", NULL);
- test_file_uri("ahost",
- "C:\\Pointless Space",
- "file://ahost/C:/Pointless%20Space",
- "C:/Pointless Space");
+ test_file_uri("me", "C:\\Sp Ace", "file://me/C:/Sp%20Ace", "C:/Sp Ace");
test_file_uri(NULL, "/foo/bar", "file:///foo/bar", NULL);
- test_file_uri("bhost", "/foo/bar", "file://bhost/foo/bar", NULL);
+ test_file_uri("you", "/foo/bar", "file://you/foo/bar", NULL);
test_file_uri(NULL, "a/relative <path>", "a/relative%20%3Cpath%3E", NULL);
// Missing trailing '/' after authority
@@ -207,6 +226,7 @@ test_uri_resolution(void)
int
main(void)
{
+ test_uri_string_has_scheme();
test_uri_parsing();
test_parse_uri();
test_is_within();