From 29cfc326f8f64d8327597f2218f0caefeed4560f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 May 2018 18:03:13 +0200 Subject: Set datatypes on integer, decimal, and base64 nodes --- tests/serd_test.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/serd_test.c b/tests/serd_test.c index c1bbd5da..a77bcbbb 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 int test_strtod(double dbl, double max_delta) { @@ -179,13 +181,17 @@ main(void) }; for (unsigned 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_get_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_get_length(node) == (node_str ? strlen(node_str) : 0)); + const size_t len = node_str ? strlen(node_str) : 0; + assert(serd_node_get_length(node) == len); + assert(!dbl_test_strs[i] || + !strcmp(serd_node_get_string(serd_node_get_datatype(node)), + NS_XSD "decimal")); serd_node_free(node); } @@ -200,10 +206,13 @@ main(void) }; for (unsigned 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_get_string(node); assert(!strcmp(node_str, int_test_strs[i])); - assert(serd_node_get_length(node) == strlen(node_str)); + const size_t len = strlen(node_str); + assert(serd_node_get_length(node) == len); + assert(!strcmp(serd_node_get_string(serd_node_get_datatype(node)), + NS_XSD "integer")); serd_node_free(node); } @@ -215,7 +224,7 @@ main(void) } size_t out_size; - 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_get_string(blob); uint8_t* out = (uint8_t*)serd_base64_decode( blob_str, serd_node_get_length(blob), &out_size); @@ -227,6 +236,9 @@ main(void) assert(out[i] == data[i]); } + assert(!strcmp(serd_node_get_string(serd_node_get_datatype(blob)), + NS_XSD "base64Binary")); + serd_node_free(blob); serd_free(out); free(data); -- cgit v1.2.1