aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-07-09 14:59:05 +0200
committerDavid Robillard <d@drobilla.net>2017-07-09 14:59:05 +0200
commit4d535bbe0390ed4f03c611e433145c9e49cbf3ad (patch)
tree3ec86327944909c214dabe419ef67c3400fb1aec /tests
parent4270fbbc761e4d36e9fc28a361b7e8d7c21166d2 (diff)
downloadserd-4d535bbe0390ed4f03c611e433145c9e49cbf3ad.tar.gz
serd-4d535bbe0390ed4f03c611e433145c9e49cbf3ad.tar.bz2
serd-4d535bbe0390ed4f03c611e433145c9e49cbf3ad.zip
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/serd_test.c21
1 files changed, 21 insertions, 0 deletions
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);