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/parse-auto.c | |
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/parse-auto.c')
-rw-r--r-- | test/parse-auto.c | 44 |
1 files changed, 35 insertions, 9 deletions
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"); } } |