diff options
author | David Robillard <d@drobilla.net> | 2011-12-30 08:10:23 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-12-30 08:10:23 +0000 |
commit | 847e56d9e696b813d1cdf3da6d54df5e7b389eae (patch) | |
tree | c4492906739264f39a3cdd9a0cacc3c6a4d908c7 /tests | |
parent | e0f18e34021004a19709f0c627db51af1a27afcf (diff) | |
download | serd-847e56d9e696b813d1cdf3da6d54df5e7b389eae.tar.gz serd-847e56d9e696b813d1cdf3da6d54df5e7b389eae.tar.bz2 serd-847e56d9e696b813d1cdf3da6d54df5e7b389eae.zip |
Add serd_node_new_blob and serd_base64_decode for handling arbitrary binary
data via base64 encoding.
git-svn-id: http://svn.drobilla.net/serd/trunk@280 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'tests')
-rw-r--r-- | tests/serd_test.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/serd_test.c b/tests/serd_test.c index 7eb9a67e..095437fb 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -133,7 +133,6 @@ main() }; for (unsigned i = 0; i < sizeof(int_test_nums) / sizeof(double); ++i) { - fprintf(stderr, "\n*** TEST %ld\n", int_test_nums[i]); SerdNode node = serd_node_new_integer(int_test_nums[i]); if (strcmp((const char*)node.buf, (const char*)int_test_strs[i])) { fprintf(stderr, "error: Serialised `%s' != %s\n", @@ -149,6 +148,40 @@ main() serd_node_free(&node); } + // Test serd_node_new_blob + for (size_t size = 0; size < 256; ++size) { + uint8_t* data = malloc(size); + for (size_t i = 0; i < size; ++i) { + data[i] = (uint8_t)(rand() % 256); + } + + SerdNode blob = serd_node_new_blob(data, size, size % 5); + + if (blob.n_bytes != blob.n_chars) { + fprintf(stderr, "error: Blob %zu bytes != %zu chars\n", + blob.n_bytes, blob.n_chars); + return 1; + } + + size_t out_size; + uint8_t* out = serd_base64_decode(blob.buf, blob.n_bytes, &out_size); + if (out_size != size) { + fprintf(stderr, "error: Blob size %zu != %zu\n", out_size, size); + return 1; + } + + for (size_t i = 0; i < size; ++i) { + if (out[i] != data[i]) { + fprintf(stderr, "error: Corrupt blob at byte %zu\n", i); + return 1; + } + } + + serd_node_free(&blob); + free(out); + free(data); + } + // Test serd_strlen const uint8_t str[] = { '"', '5', 0xE2, 0x82, 0xAC, '"', '\n', 0 }; |