From 4d535bbe0390ed4f03c611e433145c9e49cbf3ad Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 9 Jul 2017 14:59:05 +0200 Subject: Add serd_node_from_substring() This allows creating nodes in-place from substrings of other strings to allow zero-copy serialization from existing delimited buffers. --- tests/serd_test.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/serd_test.c') diff --git a/tests/serd_test.c b/tests/serd_test.c index 39ebc117..1eace3fd 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -366,6 +366,27 @@ main(void) return failure("Creating node from NULL string failed\n"); } + // Test serd_node_from_substring + + SerdNode empty = serd_node_from_substring(SERD_LITERAL, NULL, 32); + if (empty.buf || empty.n_bytes || empty.n_chars || empty.flags || empty.type) { + return failure("Successfully created node from NULL substring\n"); + } + + SerdNode a_b = serd_node_from_substring(SERD_LITERAL, USTR("a\"bc"), 3); + if (a_b.n_bytes != 3 || a_b.n_chars != 3 || a_b.flags != SERD_HAS_QUOTE + || strncmp((const char*)a_b.buf, "a\"b", 3)) { + return failure("Bad node %s %zu %zu %d %d\n", + a_b.buf, a_b.n_bytes, a_b.n_chars, a_b.flags, a_b.type); + } + + a_b = serd_node_from_substring(SERD_LITERAL, USTR("a\"bc"), 10); + if (a_b.n_bytes != 4 || a_b.n_chars != 4 || a_b.flags != SERD_HAS_QUOTE + || strncmp((const char*)a_b.buf, "a\"bc", 4)) { + return failure("Bad node %s %zu %zu %d %d\n", + a_b.buf, a_b.n_bytes, a_b.n_chars, a_b.flags, a_b.type); + } + // Test serd_node_new_uri_from_string SerdNode nonsense = serd_node_new_uri_from_string(NULL, NULL, NULL); -- cgit v1.2.1