From 36966024c4044afa3706f2c51b544925dd438793 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Fri, 1 Aug 2008 17:31:29 +0000 Subject: 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 --- test/INDEX | 4 ++- test/Makefile | 2 +- test/css21.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/parse.c | 4 +-- 4 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 test/css21.c (limited to 'test') 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 +#include + +#include + +#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 \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; -- cgit v1.2.3