diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-02-14 17:20:19 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-02-14 17:20:19 +0000 |
commit | 1d8b0aad719898be0f1b8a862be41c2b51075c80 (patch) | |
tree | 1efac87b00dba4be396a3aa9ef1c45e023272ff0 /test | |
parent | 03c0b36fdb90960b4a4c1e6f86084c850463195b (diff) | |
download | libcss-1d8b0aad719898be0f1b8a862be41c2b51075c80.tar.gz libcss-1d8b0aad719898be0f1b8a862be41c2b51075c80.tar.bz2 |
Rework handling of imported stylesheets.
No longer is the client called back mid-parse. Instead, they must acquire details of and process imported stylesheets after css_stylesheet_data_done() has been called on the parent sheet. The return code of css_stylesheet_data_done() informs the client of the need to process imported sheets.
svn path=/trunk/libcss/; revision=6504
Diffstat (limited to 'test')
-rw-r--r-- | test/css21.c | 37 | ||||
-rw-r--r-- | test/dump.h | 7 | ||||
-rw-r--r-- | test/parse-auto.c | 44 | ||||
-rw-r--r-- | test/parse2-auto.c | 2 | ||||
-rw-r--r-- | test/select-auto.c | 3 |
5 files changed, 73 insertions, 20 deletions
diff --git a/test/css21.c b/test/css21.c index 3da2bfb..47558bc 100644 --- a/test/css21.c +++ b/test/css21.c @@ -40,8 +40,8 @@ int main(int argc, char **argv) for (int count = 0; count < ITERATIONS; count++) { assert(css_stylesheet_create(CSS_LEVEL_21, "UTF-8", argv[2], - NULL, CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL, NULL, - NULL, myrealloc, NULL, &sheet) == CSS_OK); + NULL, CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL, + myrealloc, NULL, &sheet) == CSS_OK); fp = fopen(argv[2], "rb"); if (fp == NULL) { @@ -74,7 +74,38 @@ int main(int argc, char **argv) fclose(fp); - assert(css_stylesheet_data_done(sheet) == CSS_OK); + error = css_stylesheet_data_done(sheet); + assert(error == CSS_OK || error == CSS_IMPORTS_PENDING); + + while (error == CSS_IMPORTS_PENDING) { + css_string url; + uint64_t media; + + error = css_stylesheet_next_pending_import(sheet, + &url, &media); + assert(error == CSS_OK || error == CSS_INVALID); + + if (error == CSS_OK) { + css_stylesheet *import; + char buf[url.len + 1]; + + memcpy(buf, url.data, url.len); + buf[url.len] = '\0'; + + assert(css_stylesheet_create(CSS_LEVEL_21, + "UTF-8", buf, NULL, CSS_ORIGIN_AUTHOR, + media, myrealloc, NULL, &import) == + CSS_OK); + + assert(css_stylesheet_data_done(import) == + CSS_OK); + + assert(css_stylesheet_register_import(sheet, + import) == CSS_OK); + + error = CSS_IMPORTS_PENDING; + } + } #if DUMP_HASH parserutils_hash_dump(sheet->dictionary); diff --git a/test/dump.h b/test/dump.h index 98ec1bb..4626894 100644 --- a/test/dump.h +++ b/test/dump.h @@ -87,11 +87,8 @@ void dump_rule_import(css_rule_import *s, char **buf, size_t *buflen) { char *ptr = *buf; - if (s->sheet == NULL) { - assert(0 && "No imported sheet"); - } - - ptr += sprintf(ptr, "| @import url(\"%s\")", s->sheet->url); + ptr += sprintf(ptr, "| @import url(\"%.*s\")", + (int) s->url->len, (const char *) s->url->data); /** \todo media list */ diff --git a/test/parse-auto.c b/test/parse-auto.c index bef54cd..4c42359 100644 --- a/test/parse-auto.c +++ b/test/parse-auto.c @@ -308,7 +308,7 @@ void run_test(const uint8_t *data, size_t len, exp_entry *exp, size_t explen) static int testnum; assert(css_stylesheet_create(CSS_LEVEL_21, "UTF-8", "foo", NULL, - CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL, NULL, NULL, + CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL, myrealloc, NULL, &sheet) == CSS_OK); error = css_stylesheet_append_data(sheet, data, len); @@ -317,7 +317,35 @@ void run_test(const uint8_t *data, size_t len, exp_entry *exp, size_t explen) assert(0); } - assert(css_stylesheet_data_done(sheet) == CSS_OK); + error = css_stylesheet_data_done(sheet); + assert(error == CSS_OK || error == CSS_IMPORTS_PENDING); + + while (error == CSS_IMPORTS_PENDING) { + css_string url; + uint64_t media; + + error = css_stylesheet_next_pending_import(sheet, + &url, &media); + assert(error == CSS_OK || error == CSS_INVALID); + + if (error == CSS_OK) { + css_stylesheet *import; + char buf[url.len + 1]; + + memcpy(buf, url.data, url.len); + buf[url.len] = '\0'; + + assert(css_stylesheet_create(CSS_LEVEL_21, + "UTF-8", buf, NULL, CSS_ORIGIN_AUTHOR, + media, myrealloc, NULL, &import) == + CSS_OK); + + assert(css_stylesheet_register_import(sheet, + import) == CSS_OK); + + error = CSS_IMPORTS_PENDING; + } + } e = 0; testnum++; @@ -460,13 +488,11 @@ void validate_rule_charset(css_rule_charset *s, exp_entry *e, int testnum) void validate_rule_import(css_rule_import *s, exp_entry *e, int testnum) { - if (s->sheet == NULL) { - assert(0 && "No imported sheet"); - } - - if (strcmp(s->sheet->url, e->name) != 0) { - printf("%d: Got URL '%s'. Expected '%s'\n", - testnum, s->sheet->url, e->name); + if (strncmp((const char *) s->url->data, e->name, + (int) s->url->len) != 0) { + printf("%d: Got URL '%.*s'. Expected '%s'\n", + testnum, (int) s->url->len, (const char *) s->url->data, + e->name); assert(0 && "Mismatched URLs"); } } diff --git a/test/parse2-auto.c b/test/parse2-auto.c index 59ae220..80fcd24 100644 --- a/test/parse2-auto.c +++ b/test/parse2-auto.c @@ -172,7 +172,7 @@ void run_test(const uint8_t *data, size_t len, const char *exp, size_t explen) buflen = 2 * explen; assert(css_stylesheet_create(CSS_LEVEL_21, "UTF-8", "foo", NULL, - CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL, NULL, NULL, + CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL, myrealloc, NULL, &sheet) == CSS_OK); error = css_stylesheet_append_data(sheet, data, len); diff --git a/test/select-auto.c b/test/select-auto.c index 3f859a0..bd34a99 100644 --- a/test/select-auto.c +++ b/test/select-auto.c @@ -439,8 +439,7 @@ void parse_sheet(line_ctx *ctx, const char *data, size_t len) /** \todo How are we going to handle @import? */ assert(css_stylesheet_create(CSS_LEVEL_21, "UTF-8", "foo", "foo", - origin, media, NULL, NULL, myrealloc, NULL, &sheet) == - CSS_OK); + origin, media, myrealloc, NULL, &sheet) == CSS_OK); /* Extend array of sheets and append new sheet to it */ temp = realloc(ctx->sheets, |