diff options
-rw-r--r-- | test/.clang-tidy | 1 | ||||
-rw-r--r-- | test/test_node.c | 1 | ||||
-rw-r--r-- | test/test_reader.c | 1 | ||||
-rw-r--r-- | test/test_reader_writer.c | 5 | ||||
-rw-r--r-- | test/test_uri.c | 51 | ||||
-rw-r--r-- | test/test_writer.c | 3 |
6 files changed, 30 insertions, 32 deletions
diff --git a/test/.clang-tidy b/test/.clang-tidy index 99a3264a..80737308 100644 --- a/test/.clang-tidy +++ b/test/.clang-tidy @@ -7,7 +7,6 @@ Checks: > -bugprone-assert-side-effect, -bugprone-easily-swappable-parameters, -cert-err33-c, - -clang-analyzer-nullability.NullableDereferenced, -clang-analyzer-optin.core.EnumCastOutOfRange, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, -concurrency-mt-unsafe, diff --git a/test/test_node.c b/test/test_node.c index b65d83bc..c2fccf08 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -123,6 +123,7 @@ test_blob_to_node(void) { for (size_t size = 1; size < 256; ++size) { uint8_t* const data = (uint8_t*)malloc(size); + assert(data); for (size_t i = 0; i < size; ++i) { data[i] = (uint8_t)((size + i) % 256); } diff --git a/test/test_reader.c b/test/test_reader.c index 4db83eee..6c38e447 100644 --- a/test/test_reader.c +++ b/test/test_reader.c @@ -408,6 +408,7 @@ main(void) const size_t nq_name_len = strlen(nq_name); const size_t path_len = tmp_len + 1 + ttl_name_len; char* const path = (char*)calloc(path_len + 1, 1); + assert(path); memcpy(path, tmp, tmp_len + 1); path[tmp_len] = '/'; diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index 829caff5..8f432767 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -233,7 +233,9 @@ test_writer(const char* const path) static void test_reader(const char* const path) { - ReaderTest* rt = (ReaderTest*)calloc(1, sizeof(ReaderTest)); + ReaderTest* const rt = (ReaderTest*)calloc(1, sizeof(ReaderTest)); + assert(rt); + SerdReader* reader = serd_reader_new( SERD_TURTLE, rt, free, NULL, NULL, test_statement_sink, NULL); @@ -286,6 +288,7 @@ main(void) const size_t ttl_name_len = strlen(ttl_name); const size_t path_len = tmp_len + 1 + ttl_name_len; char* const path = (char*)calloc(path_len + 1, 1); + assert(path); memcpy(path, tmp, tmp_len + 1); path[tmp_len] = '/'; diff --git a/test/test_uri.c b/test/test_uri.c index 44afc4d3..96fde600 100644 --- a/test/test_uri.c +++ b/test/test_uri.c @@ -52,6 +52,7 @@ check_file_uri(const char* const hostname, uint8_t* out_path = serd_file_uri_parse((const uint8_t*)node.buf, &out_hostname); + assert(out_path); assert(!strcmp((const char*)node.buf, expected_uri)); assert((hostname && out_hostname) || (!hostname && !out_hostname)); assert(!hostname || !strcmp(hostname, (const char*)out_hostname)); @@ -68,40 +69,27 @@ check_file_uri(const char* const hostname, #endif static void -test_uri_to_path(void) +check_uri_to_path(const char* const uri, const char* const expected_path) { - assert(!strcmp( - (const char*)serd_uri_to_path((const uint8_t*)"file:///home/user/foo.ttl"), - "/home/user/foo.ttl")); - - assert(!strcmp((const char*)serd_uri_to_path( - (const uint8_t*)"file://localhost/home/user/foo.ttl"), - "/home/user/foo.ttl")); - - assert(!serd_uri_to_path((const uint8_t*)"file:illegal/file/uri")); - - assert(!strcmp( - (const char*)serd_uri_to_path((const uint8_t*)"file:///c:/awful/system"), - "c:/awful/system")); - - assert(!strcmp( - (const char*)serd_uri_to_path((const uint8_t*)"file:///c:awful/system"), - "/c:awful/system")); - - assert(!strcmp((const char*)serd_uri_to_path((const uint8_t*)"file:///0/1"), - "/0/1")); - - assert( - !strcmp((const char*)serd_uri_to_path((const uint8_t*)"C:\\Windows\\Sucks"), - "C:\\Windows\\Sucks")); - - assert( - !strcmp((const char*)serd_uri_to_path((const uint8_t*)"C|/Windows/Sucks"), - "C|/Windows/Sucks")); + const uint8_t* const path = serd_uri_to_path((const uint8_t*)uri); + assert(path); + assert(!strcmp((const char*)path, expected_path)); +} +static void +test_uri_to_path(void) +{ + assert(!serd_uri_to_path((const uint8_t*)"file:invalid/file/uri")); assert(!serd_uri_to_path((const uint8_t*)"http://example.org/path")); - assert(!strcmp((const char*)serd_uri_to_path((const uint8_t*)"rel"), "rel")); + check_uri_to_path("file:///home/user/foo.ttl", "/home/user/foo.ttl"); + check_uri_to_path("file://localhost/home/user/foo.ttl", "/home/user/foo.ttl"); + check_uri_to_path("file:///c:/awful/system", "c:/awful/system"); + check_uri_to_path("file:///c:awful/system", "/c:awful/system"); + check_uri_to_path("file:///0/1", "/0/1"); + check_uri_to_path("C:\\Windows\\Sucks", "C:\\Windows\\Sucks"); + check_uri_to_path("C|/Windows/Sucks", "C|/Windows/Sucks"); + check_uri_to_path("rel", "rel"); } #if defined(__GNUC__) @@ -171,16 +159,19 @@ test_uri_parsing(void) // Test tolerance of NULL hostname parameter uint8_t* const hosted = serd_file_uri_parse(USTR("file://host/path"), NULL); + assert(hosted); assert(!strcmp((const char*)hosted, "/path")); serd_free(hosted); // Test tolerance of parsing junk URI escapes uint8_t* const junk1 = serd_file_uri_parse(USTR("file:///foo/%0Xbar"), NULL); + assert(junk1); assert(!strcmp((const char*)junk1, "/foo/bar")); serd_free(junk1); uint8_t* const junk2 = serd_file_uri_parse(USTR("file:///foo/%X0bar"), NULL); + assert(junk2); assert(!strcmp((const char*)junk2, "/foo/bar")); serd_free(junk2); } diff --git a/test/test_writer.c b/test/test_writer.c index 7f8d2f94..00fdc459 100644 --- a/test/test_writer.c +++ b/test/test_writer.c @@ -40,6 +40,7 @@ test_write_long_literal(void) "<http://example.org/s>\n" "\t<http://example.org/p> \"\"\"hello \"\"\\\"world\"\"\\\"!\"\"\" .\n"; + assert(out); assert(!strcmp((char*)out, expected)); serd_free(out); } @@ -112,6 +113,7 @@ test_write_nested_anon(void) "\t\t<http://example.org/p4> <http://example.org/o4>\n" "\t] .\n"; + assert(out); assert(!strcmp((char*)out, expected)); serd_free(out); } @@ -290,6 +292,7 @@ test_chunk_sink(void) serd_writer_free(writer); uint8_t* out = serd_chunk_sink_finish(&chunk); + assert(out); assert(!strcmp((const char*)out, "@base <http://example.org/base> .\n")); serd_free(out); serd_env_free(env); |