diff options
author | David Robillard <d@drobilla.net> | 2018-05-12 18:03:13 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-10-27 13:13:58 +0100 |
commit | 4f4408029cd8cefc1804d75a03f5c3f0ee7922fa (patch) | |
tree | f4e97788064e7659e06e31f68170ac9ce645f54a /tests | |
parent | 8b20b3e3bfd186b7b0bbd082a979c7fb86a52479 (diff) | |
download | serd-4f4408029cd8cefc1804d75a03f5c3f0ee7922fa.tar.gz serd-4f4408029cd8cefc1804d75a03f5c3f0ee7922fa.tar.bz2 serd-4f4408029cd8cefc1804d75a03f5c3f0ee7922fa.zip |
Set datatypes on integer, decimal, and base64 nodes
Diffstat (limited to 'tests')
-rw-r--r-- | tests/serd_test.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/tests/serd_test.c b/tests/serd_test.c index 168c4ee8..72f5db84 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -34,6 +34,8 @@ # define NAN (INFINITY - INFINITY) #endif +#define NS_XSD "http://www.w3.org/2001/XMLSchema#" + static void test_strtod(double dbl, double max_delta) { @@ -270,13 +272,17 @@ test_double_to_node(void) }; for (size_t i = 0; i < sizeof(dbl_test_nums) / sizeof(double); ++i) { - SerdNode* node = serd_node_new_decimal(dbl_test_nums[i], 8); + SerdNode* node = serd_node_new_decimal(dbl_test_nums[i], 8, NULL); const char* node_str = serd_node_string(node); const bool pass = (node_str && dbl_test_strs[i]) ? !strcmp(node_str, dbl_test_strs[i]) : (node_str == dbl_test_strs[i]); assert(pass); - assert(serd_node_length(node) == (node_str ? strlen(node_str) : 0)); + const size_t len = node_str ? strlen(node_str) : 0; + assert(serd_node_length(node) == len); + assert(!dbl_test_strs[i] || + !strcmp(serd_node_string(serd_node_datatype(node)), + NS_XSD "decimal")); serd_node_free(node); } } @@ -293,10 +299,13 @@ test_integer_to_node(void) }; for (size_t i = 0; i < sizeof(int_test_nums) / sizeof(double); ++i) { - SerdNode* node = serd_node_new_integer(int_test_nums[i]); + SerdNode* node = serd_node_new_integer(int_test_nums[i], NULL); const char* node_str = serd_node_string(node); assert(!strcmp(node_str, int_test_strs[i])); - assert(serd_node_length(node) == strlen(node_str)); + const size_t len = strlen(node_str); + assert(serd_node_length(node) == len); + assert(!strcmp(serd_node_string(serd_node_datatype(node)), + NS_XSD "integer")); serd_node_free(node); } } @@ -304,8 +313,8 @@ test_integer_to_node(void) static void test_blob_to_node(void) { - assert(!serd_node_new_blob(NULL, 0, true)); - assert(!serd_node_new_blob("data", 0, true)); + assert(!serd_node_new_blob(NULL, 0, true, NULL)); + assert(!serd_node_new_blob("data", 0, true, NULL)); for (size_t size = 1; size < 256; ++size) { uint8_t* data = size > 0 ? (uint8_t*)malloc(size) : NULL; @@ -314,7 +323,7 @@ test_blob_to_node(void) } size_t out_size = 0; - SerdNode* blob = serd_node_new_blob(data, size, size % 5); + SerdNode* blob = serd_node_new_blob(data, size, size % 5, NULL); const char* blob_str = serd_node_string(blob); uint8_t* out = (uint8_t*)serd_base64_decode( blob_str, serd_node_length(blob), &out_size); @@ -326,6 +335,9 @@ test_blob_to_node(void) assert(out[i] == data[i]); } + assert(!strcmp(serd_node_string(serd_node_datatype(blob)), + NS_XSD "base64Binary")); + serd_node_free(blob); serd_free(out); free(data); |