aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-11-17 21:01:59 +0100
committerDavid Robillard <d@drobilla.net>2018-12-31 11:37:49 -0500
commit086c16d97a70baa782aed938e16c500d1cda53be (patch)
tree27ec6c75ca70b481ff732fb588f54ac6d9a5f7e3
parentf910557310a42685022ee413af5501f71fad92a0 (diff)
downloadserd-086c16d97a70baa782aed938e16c500d1cda53be.tar.gz
serd-086c16d97a70baa782aed938e16c500d1cda53be.tar.bz2
serd-086c16d97a70baa782aed938e16c500d1cda53be.zip
Add stack overflow tests
-rw-r--r--tests/overflow_test.c71
-rw-r--r--wscript8
2 files changed, 77 insertions, 2 deletions
diff --git a/tests/overflow_test.c b/tests/overflow_test.c
new file mode 100644
index 00000000..d3a1816e
--- /dev/null
+++ b/tests/overflow_test.c
@@ -0,0 +1,71 @@
+/*
+ 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.
+*/
+
+#undef NDEBUG
+
+#include "serd/serd.h"
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static SerdStatus
+test(SerdWorld* world, SerdSink* sink, const char* str, size_t stack_size)
+{
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, stack_size);
+ serd_reader_start_string(reader, str, NULL);
+ const SerdStatus st = serd_reader_read_document(reader);
+ serd_reader_free(reader);
+ return st;
+}
+
+int
+main(void)
+{
+ typedef struct
+ {
+ const char* str;
+ size_t stack_size;
+ } Test;
+
+ const Test tests[] = {{":s :p :%99 .", 338},
+ {":s :p <http://", 336},
+ {":s :p eg:foo", 337},
+ {":s :p 1234", 307},
+ {":s :p 1234", 338},
+ {":s :p (1 2 3 4) .", 352},
+ {"@prefix eg: <http://example.org> .", 239},
+ {":s :p \"literal\"", 336},
+ {":s :p \"verb\"", 275},
+ {":s :p _:blank .", 307},
+ {":s :p true .", 307},
+ {":s :p true .", 341},
+ {":s :p \"\"@en .", 339},
+ {NULL, 0}};
+
+ SerdWorld* world = serd_world_new();
+ SerdSink* sink = serd_sink_new(NULL);
+
+ for (const Test* t = tests; t->str; ++t) {
+ const SerdStatus st = test(world, sink, t->str, t->stack_size);
+ assert(st == SERD_ERR_OVERFLOW);
+ }
+
+ serd_world_free(world);
+ return 0;
+}
diff --git a/wscript b/wscript
index 1f66627b..e996dde2 100644
--- a/wscript
+++ b/wscript
@@ -152,7 +152,8 @@ def build(bld):
for prog in [('serdi_static', 'src/serdi.c'),
('serd_test', 'tests/serd_test.c'),
('read_chunk_test', 'tests/read_chunk_test.c'),
- ('nodes_test', 'tests/nodes_test.c')]:
+ ('nodes_test', 'tests/nodes_test.c'),
+ ('overflow_test', 'tests/overflow_test.c')]:
bld(features = 'c cprogram',
source = prog[1],
use = 'libserd_profiled',
@@ -487,7 +488,10 @@ def test(ctx):
autowaf.pre_test(ctx, APPNAME)
autowaf.run_tests(ctx, APPNAME,
- ['serd_test', 'read_chunk_test', 'nodes_test'],
+ ['serd_test',
+ 'read_chunk_test',
+ 'nodes_test',
+ 'overflow_test'],
name='Unit')
def test_syntax_io(in_name, expected_name, lang):