diff options
author | David Robillard <d@drobilla.net> | 2018-05-12 18:03:13 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-12-02 16:27:02 -0500 |
commit | cd89a74a2f7bf8c3efc3ecf1597cf39d6295db00 (patch) | |
tree | 3cc01ec3ac53ea4457d49691198b68581229b773 /test | |
parent | 5c02da92038072f28408854e862fc2d4edf765d4 (diff) | |
download | serd-cd89a74a2f7bf8c3efc3ecf1597cf39d6295db00.tar.gz serd-cd89a74a2f7bf8c3efc3ecf1597cf39d6295db00.tar.bz2 serd-cd89a74a2f7bf8c3efc3ecf1597cf39d6295db00.zip |
Set datatypes on integer, decimal, and base64 nodes
Diffstat (limited to 'test')
-rw-r--r-- | test/test_node.c | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/test/test_node.c b/test/test_node.c index 68bdf784..3cdff51a 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -25,6 +25,8 @@ # define NAN (INFINITY - INFINITY) #endif +#define NS_XSD "http://www.w3.org/2001/XMLSchema#" + static void test_strtod(double dbl, double max_delta) { @@ -82,14 +84,23 @@ test_double_to_node(void) NULL}; for (size_t i = 0; i < sizeof(dbl_test_nums) / sizeof(double); ++i) { - SerdNode* node = serd_new_decimal(dbl_test_nums[i], 8); + SerdNode* node = serd_new_decimal(dbl_test_nums[i], 8, NULL); const char* node_str = node ? serd_node_string(node) : NULL; 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(!node || serd_node_length(node) == strlen(node_str)); - serd_node_free(node); + + const size_t len = node_str ? strlen(node_str) : 0; + assert((!node && len == 0) || serd_node_length(node) == len); + + if (node) { + const SerdNode* const datatype = serd_node_datatype(node); + assert(datatype); + assert(!dbl_test_strs[i] || + !strcmp(serd_node_string(datatype), NS_XSD "decimal")); + serd_node_free(node); + } } } @@ -104,10 +115,15 @@ test_integer_to_node(void) "0", "0", "-23", "23", "-12340", "1000", "-1000"}; for (size_t i = 0; i < N_TEST_NUMS; ++i) { - SerdNode* node = serd_new_integer(int_test_nums[i]); + SerdNode* node = serd_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); + + const SerdNode* const datatype = serd_node_datatype(node); + assert(datatype); + assert(!strcmp(serd_node_string(datatype), NS_XSD "integer")); serd_node_free(node); } @@ -117,7 +133,7 @@ test_integer_to_node(void) static void test_blob_to_node(void) { - assert(!serd_new_blob(&SERD_URI_NULL, 0, false)); + assert(!serd_new_blob(&SERD_URI_NULL, 0, false, NULL)); for (size_t size = 1; size < 256; ++size) { uint8_t* const data = (uint8_t*)malloc(size); @@ -126,7 +142,7 @@ test_blob_to_node(void) } size_t out_size = 0; - SerdNode* blob = serd_new_blob(data, size, size % 5); + SerdNode* blob = serd_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); @@ -138,6 +154,10 @@ test_blob_to_node(void) assert(out[i] == data[i]); } + const SerdNode* const datatype = serd_node_datatype(blob); + assert(datatype); + assert(!strcmp(serd_node_string(datatype), NS_XSD "base64Binary")); + serd_node_free(blob); serd_free(out); free(data); |