aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-10 14:54:51 +0200
committerDavid Robillard <d@drobilla.net>2018-11-25 22:12:47 +0100
commit3f8ff1646ef9c69e3508526d4514aa641b563e53 (patch)
treebf2ec6a37cc515f5b241545d9184dffb3548097e
parent065a062cd210ce9a86e57d6e751ea591dd984147 (diff)
downloadserd-3f8ff1646ef9c69e3508526d4514aa641b563e53.tar.gz
serd-3f8ff1646ef9c69e3508526d4514aa641b563e53.tar.bz2
serd-3f8ff1646ef9c69e3508526d4514aa641b563e53.zip
Add test for reading chunks
-rw-r--r--tests/read_chunk_test.c109
-rw-r--r--wscript5
2 files changed, 112 insertions, 2 deletions
diff --git a/tests/read_chunk_test.c b/tests/read_chunk_test.c
new file mode 100644
index 00000000..b3adca35
--- /dev/null
+++ b/tests/read_chunk_test.c
@@ -0,0 +1,109 @@
+/*
+ Copyright 2018 David Robillard <http://drobilla.net>
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#include "test_utils.h"
+
+#include "serd/serd.h"
+
+static size_t n_base = 0;
+static size_t n_prefix = 0;
+static size_t n_statement = 0;
+static size_t n_end = 0;
+
+static SerdStatus
+on_base(void* handle, const SerdNode* uri)
+{
+ ++n_base;
+ return SERD_SUCCESS;
+}
+
+static SerdStatus
+on_prefix(void* handle, const SerdNode* name, const SerdNode* uri)
+{
+ ++n_prefix;
+ return SERD_SUCCESS;
+}
+
+static SerdStatus
+on_statement(void* handle,
+ SerdStatementFlags flags,
+ const SerdStatement* statement)
+{
+ ++n_statement;
+ return SERD_SUCCESS;
+}
+
+static SerdStatus
+on_end(void* handle, const SerdNode* node)
+{
+ ++n_end;
+ return SERD_SUCCESS;
+}
+
+int
+main(int argc, char** argv)
+{
+ SerdWorld* world = serd_world_new();
+ SerdSink* sink = serd_sink_new(NULL);
+ serd_sink_set_base_func(sink, on_base);
+ serd_sink_set_prefix_func(sink, on_prefix);
+ serd_sink_set_statement_func(sink, on_statement);
+ serd_sink_set_end_func(sink, on_end);
+
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
+ if (!reader) {
+ FAIL("Failed to create reader\n");
+ }
+
+ if (serd_reader_start_string(reader,
+ "@prefix eg: <http://example.org/> .\n"
+ "@base <http://example.org/base> .\n"
+ "eg:s1 eg:p1 eg:o1 ;\n"
+ " eg:p2 eg:o2 ,\n"
+ " eg:o3 .\n"
+ "eg:s2 eg:p1 eg:o1 ;\n"
+ " eg:p2 eg:o2 .\n"
+ "eg:s3 eg:p1 eg:o1 .\n"
+ "eg:s4 eg:p1 [ eg:p3 eg:o1 ] .\n",
+ NULL)) {
+ FAIL("Failed to start string read\n");
+ }
+
+ if (serd_reader_read_chunk(reader) || n_prefix != 1) {
+ FAILF("%zu prefixes after chunk, expected 1\n", n_prefix);
+ } else if (serd_reader_read_chunk(reader) || n_base != 1) {
+ FAILF("%zu bases after chunk, expected 1\n", n_base);
+ } else if (serd_reader_read_chunk(reader) || n_statement != 3) {
+ FAILF("%zu statements after chunk, expected 3\n", n_statement);
+ } else if (serd_reader_read_chunk(reader) || n_statement != 5) {
+ FAILF("%zu statements after chunk, expected 5\n", n_statement);
+ } else if (serd_reader_read_chunk(reader) || n_statement != 6) {
+ FAILF("%zu statements after chunk, expected 6\n", n_statement);
+ } else if (serd_reader_read_chunk(reader) || n_statement != 8) {
+ FAILF("%zu statements after chunk, expected 8\n", n_statement);
+ } else if (serd_reader_read_chunk(reader) != SERD_FAILURE) {
+ FAIL("Successfully read past end of input\n");
+ } else if (n_end != 1) {
+ FAILF("Expected end after %zu statements\n", n_statement);
+ } else if (serd_reader_read_chunk(reader) != SERD_FAILURE) {
+ FAIL("Successfully read past end of input\n");
+ }
+
+ serd_reader_free(reader);
+ serd_sink_free(sink);
+ serd_world_free(world);
+ return 0;
+}
diff --git a/wscript b/wscript
index 165a81a7..1a7fa8d9 100644
--- a/wscript
+++ b/wscript
@@ -146,7 +146,8 @@ def build(bld):
# Test programs
for prog in [('serdi_static', 'src/serdi.c'),
- ('serd_test', 'tests/serd_test.c')]:
+ ('serd_test', 'tests/serd_test.c'),
+ ('read_chunk_test', 'tests/read_chunk_test.c')]:
bld(features = 'c cprogram',
source = prog[1],
use = 'libserd_profiled',
@@ -447,7 +448,7 @@ def test(ctx):
os.environ['PATH'] = '.' + os.pathsep + os.getenv('PATH')
autowaf.pre_test(ctx, APPNAME)
- autowaf.run_tests(ctx, APPNAME, ['serd_test'], name='Unit')
+ autowaf.run_tests(ctx, APPNAME, ['serd_test', 'read_chunk_test'], name='Unit')
def test_syntax_io(in_name, expected_name, lang):
in_path = 'tests/good/%s' % in_name