aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_string.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_string.c')
-rw-r--r--test/test_string.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/test/test_string.c b/test/test_string.c
index 6767e5ae..23835ca9 100644
--- a/test/test_string.c
+++ b/test/test_string.c
@@ -11,19 +11,31 @@
#include <string.h>
static void
+check_strlen(const char* const str,
+ const size_t expected_n_bytes,
+ const size_t expected_n_chars,
+ const SerdNodeFlags expected_flags)
+{
+ size_t n_bytes = 0U;
+ SerdNodeFlags flags = 0U;
+ const size_t n_chars = serd_strlen((const uint8_t*)str, &n_bytes, &flags);
+
+ assert(n_bytes == expected_n_bytes);
+ assert(n_chars == expected_n_chars);
+ assert(flags == expected_flags);
+}
+
+static void
test_strlen(void)
{
- const uint8_t str[] = {'"', '5', 0xE2, 0x82, 0xAC, '"', '\n', 0};
+ static const uint8_t utf8[] = {'"', '5', 0xE2, 0x82, 0xAC, '"', '\n', 0};
- size_t n_bytes = 0;
- SerdNodeFlags flags = 0;
- size_t len = serd_strlen(str, &n_bytes, &flags);
- assert(len == 5 && n_bytes == 7 &&
- flags == (SERD_HAS_QUOTE | SERD_HAS_NEWLINE));
- len = serd_strlen(str, NULL, &flags);
- assert(len == 5);
+ check_strlen("\"quotes\"", 8U, 8U, SERD_HAS_QUOTE);
+ check_strlen("newline\n", 8U, 8U, SERD_HAS_NEWLINE);
+ check_strlen("\rreturn", 7U, 7U, SERD_HAS_NEWLINE);
+ check_strlen((const char*)utf8, 7U, 5U, SERD_HAS_QUOTE | SERD_HAS_NEWLINE);
- assert(serd_strlen(str, &n_bytes, NULL) == 5);
+ assert(serd_strlen((const uint8_t*)"nulls", NULL, NULL) == 5U);
}
static void