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>2022-01-13 23:03:41 -0500
commitc90c662f85ca1a36794a0404b2101a72de020ca3 (patch)
tree9e4e8abb5a70e955f0236aa9ebeccdbcba02c33f /test
parentf074a83f20e04e360704a190ab5f4e646f4272b7 (diff)
downloadserd-c90c662f85ca1a36794a0404b2101a72de020ca3.tar.gz
serd-c90c662f85ca1a36794a0404b2101a72de020ca3.tar.bz2
serd-c90c662f85ca1a36794a0404b2101a72de020ca3.zip
Use exess for reading and writing numeric and binary literals
Diffstat (limited to 'test')
-rw-r--r--test/meson.build32
-rw-r--r--test/test_node.c85
2 files changed, 70 insertions, 47 deletions
diff --git a/test/meson.build b/test/meson.build
index a57e2cf2..978bc779 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -17,12 +17,20 @@ 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',
+ 'subprojects' / 'rerex')]
+endif
+
foreach unit : unit_tests
test(unit,
executable('test_@0@'.format(unit),
'test_@0@.c'.format(unit),
c_args: c_warnings + platform_args + prog_args,
dependencies: serd_dep),
+ env: test_env,
suite: 'unit')
endforeach
@@ -40,7 +48,7 @@ if get_option('utils')
serd_ttl = files('../serd.ttl')[0]
- test('serd.ttl', serdi, args: [serd_ttl], suite: 'data')
+ test('serd.ttl', serdi, args: [serd_ttl], env: test_env, suite: 'data')
# Command line options
@@ -51,7 +59,7 @@ if get_option('utils')
]
foreach args : good_args
- test(args[0], serdi, args: args, suite: ['serdi', 'options'])
+ test(args[0], serdi, args: args, env: test_env, suite: ['serdi', 'options'])
endforeach
bad_args = [
@@ -78,39 +86,50 @@ if get_option('utils')
name = ' '.join(args).underscorify()
test(name, serdi,
args: args,
+ env: test_env,
should_fail: true,
suite: ['serdi', 'options'])
endforeach
- test('none', serdi, should_fail: true, suite: ['serdi', 'options'])
+ test('none',
+ serdi,
+ env: test_env,
+ should_fail: true,
+ suite: ['serdi', 'options'])
test('quiet', files('test_quiet.py'),
args: script_args + files('bad/bad-base.ttl'),
+ env: test_env,
suite: ['serdi', 'options'])
# Inputs
test('stdin', files('test_stdin.py'),
args: script_args,
+ env: test_env,
suite: ['serdi', 'input'])
test('string', serdi,
args: ['-s', '<foo> a <Bar> .'],
+ env: test_env,
should_fail: true,
suite: ['serdi', 'input'])
test('missing', serdi,
args: ['-i', 'turtle'],
+ env: test_env,
should_fail: true,
suite: ['serdi', 'input'])
test('no_such_file', serdi,
args: ['no_such_file'],
+ env: test_env,
should_fail: true,
suite: ['serdi', 'input'])
test('remote', serdi,
args: ['ftp://example.org/unsupported.ttl'],
+ env: test_env,
should_fail: true,
suite: ['serdi', 'input'])
@@ -118,16 +137,19 @@ if get_option('utils')
test('read_dir', serdi,
args: ['-e', 'file://@0@/'.format(meson.source_root())],
+ env: test_env,
should_fail: true,
suite: 'io_errors')
test('bulk_read_dir', serdi,
args: ['file://@0@/'.format(meson.source_root())],
+ env: test_env,
should_fail: true,
suite: 'io_errors')
test('write_error', files('test_write_error.py'),
args: script_args + [serd_ttl],
+ env: test_env,
suite: 'io_errors')
# RDF test suites
@@ -143,6 +165,7 @@ if get_option('utils')
base_uri = serd_base + name + '/'
test(name, run_test_suite,
args: script_args + [manifest, base_uri],
+ env: test_env,
suite: ['rdf', 'serd'],
timeout: 240)
endforeach
@@ -154,6 +177,7 @@ if get_option('utils')
### ... once with strict parsing to test the hard errors
test('lax.strict', run_test_suite,
args: script_args + [lax_manifest, lax_base_uri],
+ env: test_env,
is_parallel: false,
suite: ['rdf', 'serd'],
timeout: 240)
@@ -161,6 +185,7 @@ if get_option('utils')
### ... and once with lax parsing to tolerate them
test('lax.lax', run_test_suite,
args: script_args + [lax_manifest, lax_base_uri, '--', '-l'],
+ env: test_env,
is_parallel: false,
suite: ['rdf', 'serd'],
timeout: 240)
@@ -182,6 +207,7 @@ if get_option('utils')
test(syntax, run_test_suite,
args: script_args + args,
+ env: test_env,
suite: ['rdf', 'w3c'],
timeout: 240)
diff --git a/test/test_node.c b/test/test_node.c
index 095d8755..968d4ada 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -21,29 +21,21 @@
#include <assert.h>
#include <float.h>
#include <math.h>
-#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#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);
@@ -51,7 +43,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+24, -5e-5, 8e0, 9e-0, 2e+0};
@@ -64,42 +56,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);
@@ -139,8 +120,9 @@ test_integer_to_node(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) {
@@ -148,7 +130,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);
@@ -168,6 +150,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
@@ -301,8 +298,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_node_equals();