From 8f1192bb2361fcd7907b926e86c41a171ed04ad0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 10 Nov 2020 09:45:15 +0100 Subject: Add serd_new_real_file_uri() --- test/.clang-tidy | 4 ++++ test/test_uri.c | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/.clang-tidy b/test/.clang-tidy index de654d8d..b7dd752b 100644 --- a/test/.clang-tidy +++ b/test/.clang-tidy @@ -3,6 +3,10 @@ Checks: > -*-magic-numbers, -*-uppercase-literal-suffix, -android-cloexec-fopen, + -bugprone-reserved-identifier, + -bugprone-suspicious-string-compare, + -cert-dcl37-c, + -cert-dcl51-cpp, -clang-analyzer-nullability.NullabilityBase, -clang-analyzer-nullability.NullableDereferenced, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, diff --git a/test/test_uri.c b/test/test_uri.c index 88aa342c..dff4d999 100644 --- a/test/test_uri.c +++ b/test/test_uri.c @@ -20,6 +20,11 @@ #include "serd/serd.h" +#if defined(_WIN32) && !defined(__MINGW32__) +# include +# define mkstemp(pat) _mktemp(pat) +#endif + #include #include #include @@ -79,6 +84,24 @@ test_uri_parsing(void) serd_free(out_path); } +static void +test_real_file_uri(void) +{ + char path[16]; + strncpy(path, "serd_XXXXXX", sizeof(path)); + assert(mkstemp(path) > 0); + + SerdNode* const good = serd_new_real_file_uri(path, NULL); + assert(good); + assert(!strncmp(serd_node_string(good), "file://", 7)); + serd_node_free(good); + + SerdNode* const bad = serd_new_real_file_uri("not_a_file", NULL); + assert(!bad); + + assert(!remove(path)); +} + static void test_parse_uri(void) { @@ -204,7 +227,7 @@ test_uri_resolution(void) const SerdURIView rel_foo_uri = serd_relative_uri(abs_foo_uri, base_uri); const SerdURIView resolved_uri = serd_resolve_uri(rel_foo_uri, base_uri); -SerdNode* const resolved = serd_new_parsed_uri(resolved_uri); + SerdNode* const resolved = serd_new_parsed_uri(resolved_uri); assert(!strcmp(serd_node_string(resolved), "http://example.org/a/b/c/foo")); serd_node_free(resolved); @@ -215,6 +238,7 @@ main(void) { test_uri_parsing(); test_parse_uri(); + test_real_file_uri(); test_is_within(); test_relative_uri(); test_uri_resolution(); -- cgit v1.2.1