summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/INDEX1
-rw-r--r--test/Makefile2
-rw-r--r--test/data/css/INDEX1
-rw-r--r--test/data/css/blocks.css10
-rw-r--r--test/parse.c79
5 files changed, 92 insertions, 1 deletions
diff --git a/test/INDEX b/test/INDEX
index b35be5c..fcf08f5 100644
--- a/test/INDEX
+++ b/test/INDEX
@@ -6,6 +6,7 @@ libcss Library initialisation/finalisation
csdetect Character set detection csdetect
lex Lexing css
lex-auto Automated lexer tests lex
+parse Parsing css
# Regression tests
diff --git a/test/Makefile b/test/Makefile
index e2a97c6..a8363f4 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
+TESTS_$(d) := csdetect lex lex-auto libcss parse
TESTS_$(d) := $(TESTS_$(d))
# Items for top-level makefile to use
diff --git a/test/data/css/INDEX b/test/data/css/INDEX
index 531d4a5..4d46ba2 100644
--- a/test/data/css/INDEX
+++ b/test/data/css/INDEX
@@ -4,3 +4,4 @@
simple.css Reasonably simple CSS file (semantically invalid)
allzengarden.css All CSS Zen Garden stylesheets concatenated
+blocks.css Basic blocks and at-rule syntax
diff --git a/test/data/css/blocks.css b/test/data/css/blocks.css
new file mode 100644
index 0000000..9ecd720
--- /dev/null
+++ b/test/data/css/blocks.css
@@ -0,0 +1,10 @@
+@charset "UTF-8";
+
+@import "simple.css";
+
+@media screen
+{
+ body { background-color: green; }
+}
+
+
diff --git a/test/parse.c b/test/parse.c
new file mode 100644
index 0000000..f24aa76
--- /dev/null
+++ b/test/parse.c
@@ -0,0 +1,79 @@
+#include <inttypes.h>
+#include <stdio.h>
+
+#include <libcss/libcss.h>
+
+#include "charset/detect.h"
+#include "utils/utils.h"
+
+#include "parse/parse.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;
+ 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((css_stylesheet *) 10,
+ "UTF-8", CSS_CHARSET_DICTATED, myrealloc, NULL);
+ assert(parser != 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);
+ }
+
+ 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_parser_destroy(parser);
+
+ assert(css_finalise(myrealloc, NULL) == CSS_OK);
+
+ printf("PASS\n");
+
+ return 0;
+}
+