aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_node.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-12 18:03:13 +0200
committerDavid Robillard <d@drobilla.net>2021-03-07 15:32:24 -0500
commitd4ae57afbd7da668dbf89f7b7e66e2f064437a98 (patch)
treeed521f64a0e844ce9fbd0cd7794739a6f292d766 /test/test_node.c
parent471ef4960aba6b5e1c9445229cddc0b3eb9ca148 (diff)
downloadserd-d4ae57afbd7da668dbf89f7b7e66e2f064437a98.tar.gz
serd-d4ae57afbd7da668dbf89f7b7e66e2f064437a98.tar.bz2
serd-d4ae57afbd7da668dbf89f7b7e66e2f064437a98.zip
Set datatypes on integer, decimal, and base64 nodes
Diffstat (limited to 'test/test_node.c')
-rw-r--r--test/test_node.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/test/test_node.c b/test/test_node.c
index eeafe5fc..93a408d6 100644
--- a/test/test_node.c
+++ b/test/test_node.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)
{
@@ -91,14 +93,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);
+ }
}
}
@@ -111,10 +122,15 @@ test_integer_to_node(void)
"0", "0", "-23", "23", "-12340", "1000", "-1000"};
for (size_t i = 0; i < sizeof(int_test_nums) / sizeof(double); ++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);
}
}
@@ -122,7 +138,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);
@@ -131,7 +147,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);
@@ -143,6 +159,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);