summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-08-01 17:31:29 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-08-01 17:31:29 +0000
commit36966024c4044afa3706f2c51b544925dd438793 (patch)
treebe04afabdd8cb76a7384e78f9d836414bf742791 /test
parent70f8503b0fcf4253c905b01aec4a72363147ab6f (diff)
downloadlibcss-36966024c4044afa3706f2c51b544925dd438793.tar.gz
libcss-36966024c4044afa3706f2c51b544925dd438793.tar.bz2
Stub out a CSS 2.1 stage 2 parser.
Parser core doesn't need to know about css_stylesheet, so change its API. svn path=/trunk/libcss/; revision=4854
Diffstat (limited to 'test')
-rw-r--r--test/INDEX4
-rw-r--r--test/Makefile2
-rw-r--r--test/css21.c90
-rw-r--r--test/parse.c4
4 files changed, 96 insertions, 4 deletions
diff --git a/test/INDEX b/test/INDEX
index fcf08f5..91031c8 100644
--- a/test/INDEX
+++ b/test/INDEX
@@ -6,7 +6,9 @@ libcss Library initialisation/finalisation
csdetect Character set detection csdetect
lex Lexing css
lex-auto Automated lexer tests lex
-parse Parsing css
+parse Parsing (core syntax) css
+css21 Parsing (CSS2.1 specifics) css
+
# Regression tests
diff --git a/test/Makefile b/test/Makefile
index a8363f4..eecf6ad 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -35,7 +35,7 @@ d := $(DIR)
CFLAGS := $(CFLAGS) -I$(TOP)/src/ -I$(d)
# Tests
-TESTS_$(d) := csdetect lex lex-auto libcss parse
+TESTS_$(d) := csdetect css21 lex lex-auto libcss parse
TESTS_$(d) := $(TESTS_$(d))
# Items for top-level makefile to use
diff --git a/test/css21.c b/test/css21.c
new file mode 100644
index 0000000..7a8d078
--- /dev/null
+++ b/test/css21.c
@@ -0,0 +1,90 @@
+#include <inttypes.h>
+#include <stdio.h>
+
+#include <libcss/libcss.h>
+
+#include "charset/detect.h"
+#include "utils/utils.h"
+
+#include "lex/lex.h"
+#include "parse/parse.h"
+#include "parse/css21.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)
+{
+ css_parser *parser;
+ css_css21 *css21;
+ FILE *fp;
+ size_t len, origlen;
+#define CHUNK_SIZE (4096)
+ uint8_t buf[CHUNK_SIZE];
+ css_error error;
+
+ if (argc != 3) {
+ printf("Usage: %s <aliases_file> <filename>\n", argv[0]);
+ return 1;
+ }
+
+ /* Initialise library */
+ assert(css_initialise(argv[1], myrealloc, NULL) == CSS_OK);
+
+ parser = css_parser_create("UTF-8", CSS_CHARSET_DICTATED,
+ myrealloc, NULL);
+ assert(parser != NULL);
+
+ css21 = css_css21_create((css_stylesheet *) 10, parser,
+ myrealloc, NULL);
+ assert(css21 != NULL);
+
+ fp = fopen(argv[2], "rb");
+ if (fp == NULL) {
+ printf("Failed opening %s\n", argv[2]);
+ return 1;
+ }
+
+ fseek(fp, 0, SEEK_END);
+ origlen = len = ftell(fp);
+ fseek(fp, 0, SEEK_SET);
+
+ while (len >= CHUNK_SIZE) {
+ fread(buf, 1, CHUNK_SIZE, fp);
+
+ error = css_parser_parse_chunk(parser, buf, CHUNK_SIZE);
+ assert(error == CSS_OK || error == CSS_NEEDDATA);
+
+ len -= CHUNK_SIZE;
+ }
+
+ if (len > 0) {
+ fread(buf, 1, len, fp);
+
+ error = css_parser_parse_chunk(parser, buf, len);
+ assert(error == CSS_OK || error == CSS_NEEDDATA);
+
+ len = 0;
+ }
+
+ fclose(fp);
+
+ assert(css_parser_completed(parser) == CSS_OK);
+
+ css_css21_destroy(css21);
+
+ css_parser_destroy(parser);
+
+ assert(css_finalise(myrealloc, NULL) == CSS_OK);
+
+ printf("PASS\n");
+
+ return 0;
+}
+
diff --git a/test/parse.c b/test/parse.c
index ac89a4e..7ee705b 100644
--- a/test/parse.c
+++ b/test/parse.c
@@ -73,8 +73,8 @@ int main(int argc, char **argv)
/* Initialise library */
assert(css_initialise(argv[1], myrealloc, NULL) == CSS_OK);
- parser = css_parser_create((css_stylesheet *) 10,
- "UTF-8", CSS_CHARSET_DICTATED, myrealloc, NULL);
+ parser = css_parser_create("UTF-8", CSS_CHARSET_DICTATED,
+ myrealloc, NULL);
assert(parser != NULL);
params.event_handler.handler = event_handler;