summaryrefslogtreecommitdiff
path: root/test/regression
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-05-01 16:34:46 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-05-01 16:34:46 +0000
commit2777a04ed2ba4fd36138b991d66a32a283361f7e (patch)
treeb0c3730533c36ca41402b6d0c5b98413f0a57bee /test/regression
downloadlibparserutils-2777a04ed2ba4fd36138b991d66a32a283361f7e.tar.gz
libparserutils-2777a04ed2ba4fd36138b991d66a32a283361f7e.tar.bz2
Import parser construction utility library
svn path=/trunk/libparserutils/; revision=4111
Diffstat (limited to 'test/regression')
-rw-r--r--test/regression/cscodec-segv.c38
-rw-r--r--test/regression/filter-segv.c39
-rw-r--r--test/regression/stream-nomem.c94
3 files changed, 171 insertions, 0 deletions
diff --git a/test/regression/cscodec-segv.c b/test/regression/cscodec-segv.c
new file mode 100644
index 0000000..5802fdf
--- /dev/null
+++ b/test/regression/cscodec-segv.c
@@ -0,0 +1,38 @@
+#include <stdio.h>
+
+#include "charset/charset.h"
+#include <parserutils/charset/codec.h>
+
+#include "testutils.h"
+
+static void *myrealloc(void *ptr, size_t len, void *pw)
+{
+ UNUSED(pw);
+
+ return realloc(ptr, len);
+}
+
+int main(int argc, char **argv)
+{
+ parserutils_charset_codec *codec;
+
+ if (argc != 2) {
+ printf("Usage: %s <aliases_file>\n", argv[0]);
+ return 1;
+ }
+
+ assert(parserutils_charset_initialise(argv[1], myrealloc, NULL) ==
+ PARSERUTILS_OK);
+
+ codec = parserutils_charset_codec_create("UTF-8", myrealloc, NULL);
+ assert(codec != NULL);
+
+ parserutils_charset_codec_destroy(codec);
+
+ assert(parserutils_charset_finalise(myrealloc, NULL) ==
+ PARSERUTILS_OK);
+
+ printf("PASS\n");
+
+ return 0;
+}
diff --git a/test/regression/filter-segv.c b/test/regression/filter-segv.c
new file mode 100644
index 0000000..761caab
--- /dev/null
+++ b/test/regression/filter-segv.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <parserutils/parserutils.h>
+
+#include "input/filter.h"
+
+#include "testutils.h"
+
+static void *myrealloc(void *ptr, size_t len, void *pw)
+{
+ UNUSED(pw);
+
+ return realloc(ptr, len);
+}
+
+int main(int argc, char **argv)
+{
+ parserutils_filter *input;
+
+ if (argc != 2) {
+ printf("Usage: %s <filename>\n", argv[0]);
+ return 1;
+ }
+
+ assert(parserutils_initialise(argv[1], myrealloc, NULL) ==
+ PARSERUTILS_OK);
+
+ input = parserutils_filter_create("UTF-8", myrealloc, NULL);
+ assert(input);
+
+ parserutils_filter_destroy(input);
+
+ assert(parserutils_finalise(myrealloc, NULL) == PARSERUTILS_OK);
+
+ printf("PASS\n");
+
+ return 0;
+}
diff --git a/test/regression/stream-nomem.c b/test/regression/stream-nomem.c
new file mode 100644
index 0000000..f62b392
--- /dev/null
+++ b/test/regression/stream-nomem.c
@@ -0,0 +1,94 @@
+#include <stdio.h>
+#include <string.h>
+
+#include <parserutils/parserutils.h>
+#include <parserutils/input/inputstream.h>
+
+#include "utils/utils.h"
+
+#include "testutils.h"
+
+static void *myrealloc(void *ptr, size_t len, void *pw)
+{
+ UNUSED(pw);
+
+ return realloc(ptr, len);
+}
+
+int main(int argc, char **argv)
+{
+ parserutils_inputstream *stream;
+
+ /* This is specially calculated so that the inputstream is forced to
+ * reallocate (it assumes that the inputstream's buffer chunk size
+ * is 4k) */
+#define BUFFER_SIZE (4096 + 4)
+ uint8_t input_buffer[BUFFER_SIZE];
+// uint8_t *buffer;
+// size_t buflen;
+ uintptr_t c;
+ size_t clen;
+
+ if (argc != 2) {
+ printf("Usage: %s <aliases_file>\n", argv[0]);
+ return 1;
+ }
+
+ /* Populate the buffer with something sane */
+ memset(input_buffer, 'a', BUFFER_SIZE);
+ /* Now, set up our test data */
+ input_buffer[BUFFER_SIZE - 1] = '5';
+ input_buffer[BUFFER_SIZE - 2] = '4';
+ input_buffer[BUFFER_SIZE - 3] = '\xbd';
+ input_buffer[BUFFER_SIZE - 4] = '\xbf';
+ /* This byte will occupy the 4095th byte in the buffer and
+ * thus cause the entirety of U+FFFD to be buffered until after
+ * the buffer has been enlarged */
+ input_buffer[BUFFER_SIZE - 5] = '\xef';
+ input_buffer[BUFFER_SIZE - 6] = '3';
+ input_buffer[BUFFER_SIZE - 7] = '2';
+ input_buffer[BUFFER_SIZE - 8] = '1';
+
+ assert(parserutils_initialise(argv[1], myrealloc, NULL) ==
+ PARSERUTILS_OK);
+
+ stream = parserutils_inputstream_create("UTF-8", 0,
+ NULL, myrealloc, NULL);
+ assert(stream != NULL);
+
+ assert(parserutils_inputstream_append(stream,
+ input_buffer, BUFFER_SIZE) == PARSERUTILS_OK);
+
+ assert(parserutils_inputstream_append(stream, NULL, 0) ==
+ PARSERUTILS_OK);
+
+ while ((c = parserutils_inputstream_peek(stream, 0, &clen)) !=
+ PARSERUTILS_INPUTSTREAM_EOF)
+ parserutils_inputstream_advance(stream, clen);
+
+/*
+ assert(css_inputstream_claim_buffer(stream, &buffer, &buflen) ==
+ CSS_OK);
+
+ assert(buflen == BUFFER_SIZE);
+
+ printf("Buffer: '%.*s'\n", 8, buffer + (BUFFER_SIZE - 8));
+
+ assert( buffer[BUFFER_SIZE - 6] == '3' &&
+ buffer[BUFFER_SIZE - 5] == (uint8_t) '\xef' &&
+ buffer[BUFFER_SIZE - 4] == (uint8_t) '\xbf' &&
+ buffer[BUFFER_SIZE - 3] == (uint8_t) '\xbd' &&
+ buffer[BUFFER_SIZE - 2] == '4');
+
+ free(buffer);
+*/
+
+ parserutils_inputstream_destroy(stream);
+
+ assert(parserutils_finalise(myrealloc, NULL) == PARSERUTILS_OK);
+
+ printf("PASS\n");
+
+ return 0;
+}
+