aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-04-15 18:34:17 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:06 -0500
commita970f06aba98736223214a6fa995f4e82acd7132 (patch)
treefc243e4bf26f4c1f95df6f62abdd6740d87d8afd /test
parent44feb2724a8fe34992999867f5b6468228b6fc01 (diff)
downloadserd-a970f06aba98736223214a6fa995f4e82acd7132.tar.gz
serd-a970f06aba98736223214a6fa995f4e82acd7132.tar.bz2
serd-a970f06aba98736223214a6fa995f4e82acd7132.zip
[WIP] Use exess for reading and writing numeric and binary literals
Diffstat (limited to 'test')
-rw-r--r--test/meson.build35
-rw-r--r--test/test_node.c84
2 files changed, 71 insertions, 48 deletions
diff --git a/test/meson.build b/test/meson.build
index ad3797df..0ee7cd23 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -131,6 +131,12 @@ unit_tests = [
'writer',
]
+test_env = []
+if build_machine.system() == 'windows' and host_machine.system() == 'windows'
+ # For Windows, we need to add to PATH so that DLLs are found
+ test_env = ['PATH=@0@;@1@'.format('subprojects' / 'exess')]
+endif
+
foreach unit : unit_tests
test(
unit,
@@ -140,6 +146,7 @@ foreach unit : unit_tests
c_args: c_suppressions,
dependencies: serd_dep,
),
+ env: test_env,
suite: 'unit',
)
endforeach
@@ -186,7 +193,7 @@ if is_variable('serdi')
serd_ttl = files('../serd.ttl')[0]
bad_input_file = files('extra/bad/bad-base.ttl')
- test('serd_ttl', serdi, args: [serd_ttl], suite: 'data')
+ test('serd_ttl', serdi, args: [serd_ttl], env: test_env, suite: 'data')
# Command line options
@@ -198,18 +205,20 @@ if is_variable('serdi')
' '.join(args).substring(1).underscorify(),
serdi,
args: args,
+ env: test_env,
should_fail: kind == 'bad',
suite: cmd_suite,
)
endforeach
endforeach
- test('none', serdi, should_fail: true, suite: cmd_suite)
+ test('none', serdi, env: test_env, should_fail: true, suite: cmd_suite)
test(
'quiet',
files('test_quiet.py'),
args: script_args + [bad_input_file],
+ env: test_env,
suite: cmd_suite,
)
@@ -224,10 +233,24 @@ if is_variable('serdi')
}
foreach name, args : bad_input_tests
- test(name, serdi, args: args, should_fail: true, suite: input_suite)
+ test(
+ name,
+ serdi,
+ args: args,
+ env: test_env,
+ should_fail: true,
+ suite: input_suite,
+ )
endforeach
- test('stdin', files('test_stdin.py'), args: script_args, suite: input_suite)
+ test(
+ 'stdin',
+ files('test_stdin.py'),
+ args: script_args,
+ env: test_env,
+ suite: input_suite,
+ )
+
# IO errors
@@ -238,13 +261,14 @@ if is_variable('serdi')
}
foreach name, args : io_error_tests
- test(name, serdi, args: args, should_fail: true, suite: 'io')
+ test(name, serdi, args: args, env: test_env, should_fail: true, suite: 'io')
endforeach
test(
'write_error',
files('test_write_error.py'),
args: script_args + [serd_ttl],
+ env: test_env,
suite: 'io',
)
endif
@@ -387,6 +411,7 @@ if is_variable('serdi')
name,
run_suite,
args: script_args + args,
+ env: test_env,
suite: ['suite'],
timeout: 240,
)
diff --git a/test/test_node.c b/test/test_node.c
index b7d43972..9660f43e 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -18,23 +18,16 @@
#include <stdlib.h>
#include <string.h>
-#ifndef INFINITY
-# define INFINITY (DBL_MAX + DBL_MAX)
-#endif
-#ifndef NAN
-# define NAN (INFINITY - INFINITY)
-#endif
-
#define NS_XSD "http://www.w3.org/2001/XMLSchema#"
#define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
static void
-test_strtod(double dbl, double max_delta)
+check_strtod(const double dbl, const double max_delta)
{
char buf[1024];
snprintf(buf, sizeof(buf), "%f", dbl);
- char* endptr = NULL;
+ const char* endptr = NULL;
const double out = serd_strtod(buf, &endptr);
const double diff = fabs(out - dbl);
@@ -42,7 +35,7 @@ test_strtod(double dbl, double max_delta)
}
static void
-test_string_to_double(void)
+test_strtod(void)
{
const double expt_test_nums[] = {
2.0E18, -5e19, +8e20, 2e+22, -5e-5, 8e0, 9e-0, 2e+0};
@@ -55,42 +48,31 @@ test_string_to_double(void)
const double delta = fabs(num - expt_test_nums[i]);
assert(delta <= DBL_EPSILON);
- test_strtod(expt_test_nums[i], DBL_EPSILON);
+ check_strtod(expt_test_nums[i], DBL_EPSILON);
}
}
static void
-test_double_to_node(void)
+test_new_decimal(void)
{
- const double dbl_test_nums[] = {0.0,
- 9.0,
- 10.0,
- .01,
- 2.05,
- -16.00001,
- 5.000000005,
- 0.0000000001,
- NAN,
- INFINITY};
-
- const char* dbl_test_strs[] = {"0.0",
- "9.0",
- "10.0",
- "0.01",
- "2.05",
- "-16.00001",
- "5.00000001",
- "0.0",
- NULL,
- NULL};
+ static const double dbl_test_nums[] = {
+ 0.0, 9.0, 10.0, .01, 2.05, -16.00001, 5.000000005, 0.0000000001};
+
+ static const char* const dbl_test_strs[] = {"0.0",
+ "9.0",
+ "10.0",
+ "0.01",
+ "2.05",
+ "-16.00001",
+ "5.000000005",
+ "0.0000000001"};
for (size_t i = 0; i < sizeof(dbl_test_nums) / sizeof(double); ++i) {
- 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);
+ SerdNode* node = serd_new_decimal(dbl_test_nums[i], NULL);
+ assert(node);
+
+ const char* node_str = serd_node_string(node);
+ assert(!strcmp(node_str, dbl_test_strs[i]));
const size_t len = node_str ? strlen(node_str) : 0;
assert((!node && len == 0) || serd_node_length(node) == len);
@@ -154,8 +136,9 @@ test_boolean(void)
static void
test_blob_to_node(void)
{
- assert(!serd_new_blob(&SERD_URI_NULL, 0, false, NULL));
+ assert(!serd_new_base64(&SERD_URI_NULL, 0, NULL));
+ // Test valid base64 blobs with a range of sizes
for (size_t size = 1; size < 256; ++size) {
uint8_t* const data = (uint8_t*)malloc(size);
for (size_t i = 0; i < size; ++i) {
@@ -163,7 +146,7 @@ test_blob_to_node(void)
}
size_t out_size = 0;
- SerdNode* blob = serd_new_blob(data, size, size % 5, NULL);
+ SerdNode* blob = serd_new_base64(data, size, 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);
@@ -183,6 +166,21 @@ test_blob_to_node(void)
serd_free(out);
free(data);
}
+
+ // Test invalid base64 blob
+
+ SerdNode* const blob = serd_new_typed_literal(
+ serd_string("!nval!d$"), serd_string(NS_XSD "base64Binary"));
+
+ const char* const blob_str = serd_node_string(blob);
+ size_t out_size = 42;
+ uint8_t* out =
+ (uint8_t*)serd_base64_decode(blob_str, serd_node_length(blob), &out_size);
+
+ assert(!out);
+ assert(out_size == 0);
+
+ serd_node_free(blob);
}
static void
@@ -319,8 +317,8 @@ test_blank(void)
int
main(void)
{
- test_string_to_double();
- test_double_to_node();
+ test_strtod();
+ test_new_decimal();
test_integer_to_node();
test_blob_to_node();
test_boolean();