diff options
author | David Robillard <d@drobilla.net> | 2017-07-09 20:43:26 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2017-07-10 12:06:56 +0200 |
commit | d292cd3ac24f954069bc6ecb3d9356b20d8f6100 (patch) | |
tree | 619ff3638f4cf6de82a7279c78086fcb7dfd4c6a /tests/serd_test.c | |
parent | 58f153dcdf1c5424ed3cefb3ce59e63b30f68f27 (diff) | |
download | serd-d292cd3ac24f954069bc6ecb3d9356b20d8f6100.tar.gz serd-d292cd3ac24f954069bc6ecb3d9356b20d8f6100.tar.bz2 serd-d292cd3ac24f954069bc6ecb3d9356b20d8f6100.zip |
Gracefully handle applications that write corrupt UTF-8
Diffstat (limited to 'tests/serd_test.c')
-rw-r--r-- | tests/serd_test.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/tests/serd_test.c b/tests/serd_test.c index 6c854241..9399f822 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -531,6 +531,7 @@ main(void) { &SERD_NODE_NULL, &p, &o, NULL, NULL }, { &s, &o, &o, NULL, NULL }, { &o, &p, &o, NULL, NULL }, + { &s, &p, &SERD_NODE_NULL, NULL, NULL }, { NULL, NULL, NULL, NULL, NULL } }; for (unsigned i = 0; i < sizeof(junk) / (sizeof(SerdNode*) * 5); ++i) { if (!serd_writer_write_statement( @@ -560,10 +561,16 @@ main(void) } } - // Write 1 statement with bad UTF-8 (should be replaced) + // Write statements with bad UTF-8 (should be replaced) + const uint8_t bad_str[] = { 0xFF, 0x90, 'h', 'i', 0 }; + SerdNode bad_lit = serd_node_from_string(SERD_LITERAL, bad_str); + SerdNode bad_uri = serd_node_from_string(SERD_URI, bad_str); if (serd_writer_write_statement(writer, 0, NULL, - &s, &p, &o, NULL, NULL)) { - return failure("Failed to write junk UTF-8\n"); + &s, &p, &bad_lit, NULL, NULL)) { + return failure("Failed to write junk UTF-8 literal\n"); + } else if (serd_writer_write_statement(writer, 0, NULL, + &s, &p, &bad_uri, NULL, NULL)) { + return failure("Failed to write junk UTF-8 URI\n"); } // Write 1 valid statement @@ -624,7 +631,7 @@ main(void) const SerdStatus st = serd_reader_read_file(reader, USTR(path)); if (st) { return failure("Error reading file (%s)\n", serd_strerror(st)); - } else if (rt->n_statements != 12) { + } else if (rt->n_statements != 13) { return failure("Bad statement count %d\n", rt->n_statements); } else if (!rt->graph || !rt->graph->buf || strcmp((const char*)rt->graph->buf, "http://example.org/")) { |