From f7d10ea309fb52d09a58b2832fe4a09a120b16aa Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 10 Nov 2020 09:45:15 +0100 Subject: Add serd_canonical_path() --- test/.clang-tidy | 1 + test/test_string.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/.clang-tidy b/test/.clang-tidy index 4e2b14eb..dd609218 100644 --- a/test/.clang-tidy +++ b/test/.clang-tidy @@ -6,6 +6,7 @@ Checks: > -android-cloexec-fopen, -bugprone-easily-swappable-parameters, -bugprone-reserved-identifier, + -bugprone-suspicious-string-compare, -clang-analyzer-nullability.NullabilityBase, -clang-analyzer-nullability.NullableDereferenced, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, diff --git a/test/test_string.c b/test/test_string.c index 472b464a..5bc304d1 100644 --- a/test/test_string.c +++ b/test/test_string.c @@ -18,6 +18,11 @@ #include "serd/serd.h" +#if defined(_WIN32) && !defined(__MINGW32__) +# include +# define mkstemp(pat) _mktemp(pat) +#endif + #include #include #include @@ -48,11 +53,34 @@ test_strerror(void) assert(!strcmp(msg, "Unknown error")); } +static void +test_canonical_path(const char* const path) +{ + char* const canonical = serd_canonical_path(path); + + assert(canonical); + assert(!strstr(canonical, "../")); + +#if defined(_WIN32) + assert(strlen(canonical) > 2); + assert(canonical[0] >= 'A' && canonical[0] <= 'Z'); + assert(canonical[1] == ':'); + assert(!strstr(canonical, "..\\")); +#else + assert(canonical[0] == '/'); +#endif + + serd_free(canonical); +} + int -main(void) +main(int argc, char** argv) { + (void)argc; + test_strlen(); test_strerror(); + test_canonical_path(argv[0]); printf("Success\n"); return 0; -- cgit v1.2.1