From 58dba94bf0cb121873476dff866d0cb08b0260a6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 24 Dec 2011 18:42:30 +0000 Subject: Test serd_strlen and serd_strerror. git-svn-id: http://svn.drobilla.net/serd/trunk@265 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/serd_test.c | 27 +++++++++++++++++++++++++++ src/string.c | 1 + 2 files changed, 28 insertions(+) diff --git a/src/serd_test.c b/src/serd_test.c index 1607373d..cf211e7b 100644 --- a/src/serd_test.c +++ b/src/serd_test.c @@ -125,6 +125,33 @@ main() serd_node_free(&node); } + // Test serd_strlen + const uint8_t str[] = { '"', '5', 0xE2, 0x82, 0xAC, '"', '\n', 0 }; + + size_t n_bytes; + SerdNodeFlags flags; + const size_t len = serd_strlen(str, &n_bytes, &flags); + if (len != 5 || n_bytes != 7 + || flags != (SERD_HAS_QUOTE|SERD_HAS_NEWLINE)) { + fprintf(stderr, "Bad serd_strlen(%s) len=%zu n_bytes=%zu flags=%u\n", + str, len, n_bytes, flags); + return 1; + } + + // Test serd_strerror + const uint8_t* msg = NULL; + if (strcmp((const char*)(msg = serd_strerror(SERD_SUCCESS)), "Success")) { + fprintf(stderr, "Bad message `%s' for SERD_SUCCESS\n", msg); + return 1; + } + for (int i = SERD_FAILURE; i <= SERD_ERR_NOT_FOUND; ++i) { + msg = serd_strerror((SerdStatus)i); + if (!strcmp((const char*)msg, "Success")) { + fprintf(stderr, "Bad message `%s' for (SerdStatus)%d\n", msg, i); + return 1; + } + } + printf("Success\n"); return 0; } diff --git a/src/string.c b/src/string.c index 35a3bbc8..40828612 100644 --- a/src/string.c +++ b/src/string.c @@ -39,6 +39,7 @@ serd_strlen(const uint8_t* str, size_t* n_bytes, SerdNodeFlags* flags) { size_t n_chars = 0; size_t i = 0; + *flags = 0; for (; str[i]; ++i) { if ((str[i] & 0xC0) != 0x80) { // Does not start with `10', start of a new character -- cgit v1.2.1