diff options
author | David Robillard <d@drobilla.net> | 2011-12-24 18:42:30 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-12-24 18:42:30 +0000 |
commit | 58dba94bf0cb121873476dff866d0cb08b0260a6 (patch) | |
tree | bcca2261f5a6ba4aa77e10608f17ea725830d465 /src | |
parent | d7c7e4910aae57156d70ceea5918477d8455c4d8 (diff) | |
download | serd-58dba94bf0cb121873476dff866d0cb08b0260a6.tar.gz serd-58dba94bf0cb121873476dff866d0cb08b0260a6.tar.bz2 serd-58dba94bf0cb121873476dff866d0cb08b0260a6.zip |
Test serd_strlen and serd_strerror.
git-svn-id: http://svn.drobilla.net/serd/trunk@265 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src')
-rw-r--r-- | src/serd_test.c | 27 | ||||
-rw-r--r-- | src/string.c | 1 |
2 files changed, 28 insertions, 0 deletions
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 |