From 6a50bef84ae6a0a67e03ac1356f8d85d15fe09d6 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 19 Jan 2011 23:12:37 +0000 Subject: Merge parser autogeneration and string handling refactor branch r=jmb,kinnison,vince svn path=/trunk/libcss/; revision=11408 --- test/data/parse/colours.dat | 24 ++++++++ test/data/parse2/au.dat | 42 ++++++++++++++ test/data/parse2/bg.dat | 34 +++++++++++ test/data/parse2/bgpos.dat | 38 ++++++++++++ test/data/parse2/border.dat | 35 +++++++++++ test/data/parse2/font.dat | 42 ++++++++++++++ test/data/parse2/list.dat | 63 ++++++++++++++++++++ test/data/parse2/margin.dat | 49 ++++++++++++++++ test/data/parse2/outline.dat | 49 ++++++++++++++++ test/data/parse2/padding.dat | 49 ++++++++++++++++ test/dump.h | 82 ++++++++++++++------------ test/lex-auto.c | 1 + test/number.c | 2 + test/parse-auto.c | 135 +++++++++++++++++++++++++++++++------------ test/parse2-auto.c | 10 +++- test/select-auto.c | 5 ++ 16 files changed, 586 insertions(+), 74 deletions(-) (limited to 'test') diff --git a/test/data/parse/colours.dat b/test/data/parse/colours.dat index f359a68..dbb5d02 100644 --- a/test/data/parse/colours.dat +++ b/test/data/parse/colours.dat @@ -90,3 +90,27 @@ | 0x02000018 0x7fff0000 #reset +#data +* { color: rgba(255, 0, 0, 1.1) } +#errors +#expected +| 1 * +| 0x02000018 0xffff0000 +#reset + +#data +* { color: rgba(255, 0, 0, 128) } +#errors +#expected +| 1 * +| 0x02000018 0xffff0000 +#reset + +#data +* { color: rgba(-255, 0, 0, -255) } +#errors +#expected +| 1 * +| 0x02000018 0x00000000 +#reset + diff --git a/test/data/parse2/au.dat b/test/data/parse2/au.dat index ac699f2..972e71c 100644 --- a/test/data/parse2/au.dat +++ b/test/data/parse2/au.dat @@ -104,6 +104,48 @@ | * #reset +#data +* { cue: inherit inherit; } +#errors +#expected +| * +#reset + +#data +* { cue: none inherit; } +#errors +#expected +| * +#reset + +#data +* { cue: inherit none; } +#errors +#expected +| * +#reset + +#data +* { cue: none url(foo) !important inherit; } +#errors +#expected +| * +#reset + +#data +* { cue: inherit none url(foo) !important; } +#errors +#expected +| * +#reset + +#data +* { cue: inherit url(foo) !important; } +#errors +#expected +| * +#reset + #data * { cue:} #errors diff --git a/test/data/parse2/bg.dat b/test/data/parse2/bg.dat index 2ede015..50c7340 100644 --- a/test/data/parse2/bg.dat +++ b/test/data/parse2/bg.dat @@ -60,6 +60,40 @@ | * #reset +#data +* { background: #fff inherit; } +#errors +#expected +| * +#reset + +#data +* { background: inherit #fff; } +#errors +#expected +| * +#reset + +#data +* { background: #fff inherit top left; } +#errors +#expected +| * +#reset + +#data +* { background: inherit fixed !important; } +#errors +#expected +| * +#reset + +#data +* { background: #fff url(foo) repeat fixed right bottom inherit; } +#errors +#expected +| * +#reset #data * { background: red !important; } diff --git a/test/data/parse2/bgpos.dat b/test/data/parse2/bgpos.dat index 16619f3..182b953 100644 --- a/test/data/parse2/bgpos.dat +++ b/test/data/parse2/bgpos.dat @@ -19,3 +19,41 @@ | * #reset +#data +* { background-position: left top inherit; } +#errors +#expected +| * +#reset + +#data +* { background-position: inherit left top; } +#errors +#expected +| * +#reset + +#data +* { background-position: left top; } +#errors +#expected +| * +| background-position: left top +#reset + +#data +* { background-position: left center; } +#errors +#expected +| * +| background-position: left center +#reset + +#data +* { background-position: 62% center; } +#errors +#expected +| * +| background-position: 62% center +#reset + diff --git a/test/data/parse2/border.dat b/test/data/parse2/border.dat index ecca9f7..daecf3b 100644 --- a/test/data/parse2/border.dat +++ b/test/data/parse2/border.dat @@ -597,6 +597,41 @@ | * #reset +#data +* { border: thin inherit; } +#errors +#expected +| * +#reset + +#data +* { border: inherit thin; } +#errors +#expected +| * +#reset + +#data +* { border: thin solid black inherit; } +#errors +#expected +| * +#reset + +#data +* { border: thin inherit solid; } +#errors +#expected +| * +#reset + +#data +* { border: inherit !important #ff9; } +#errors +#expected +| * +#reset + #data * { border-color: red; } diff --git a/test/data/parse2/font.dat b/test/data/parse2/font.dat index f8a46d8..04a935e 100644 --- a/test/data/parse2/font.dat +++ b/test/data/parse2/font.dat @@ -294,6 +294,48 @@ | * #reset +#data +* { font: 10pt inherit; } +#errors +#expected +| * +#reset + +#data +* { font: inherit 10pt; } +#errors +#expected +| * +#reset + +#data +* { font: 'Sonic the Hedgehog' 12pt inherit; } +#errors +#expected +| * +#reset + +#data +* { font: 'Sonic the Hedgehog' inherit 12pt; } +#errors +#expected +| * +#reset + +#data +* { font: inherit 12pt 'Sonic the Hedgehog'; } +#errors +#expected +| * +#reset + +#data +* { font: inherit inherit; } +#errors +#expected +| * +#reset + #data * { font-family: inherit; } #errors diff --git a/test/data/parse2/list.dat b/test/data/parse2/list.dat index 5f0b53f..ad47ef3 100644 --- a/test/data/parse2/list.dat +++ b/test/data/parse2/list.dat @@ -180,6 +180,69 @@ | * #reset +#data +* { list-style: inherit circle; } +#errors +#expected +| * +#reset + +#data +* { list-style: disc inherit; } +#errors +#expected +| * +#reset + +#data +* { list-style: circle inside inherit; } +#errors +#expected +| * +#reset + +#data +* { list-style: inherit disc inside; } +#errors +#expected +| * +#reset + +#data +* { list-style: disc circle; } +#errors +#expected +| * +#reset + +#data +* { list-style: inside inherit url('PicoDrive'); } +#errors +#expected +| * +#reset + +#data +* { list-style: !important disc circle; } +#errors +#expected +| * +#reset + +#data +* { list-style: !important disc inherit; } +#errors +#expected +| * +#reset + +#data +* { list-style: disc inherit !important; } +#errors +#expected +| * +#reset + diff --git a/test/data/parse2/margin.dat b/test/data/parse2/margin.dat index 287eb62..3080198 100644 --- a/test/data/parse2/margin.dat +++ b/test/data/parse2/margin.dat @@ -221,6 +221,55 @@ | * #reset +#data +* { margin: 2px inherit; } +#errors +#expected +| * +#reset + +#data +* { margin: inherit 2px; } +#errors +#expected +| * +#reset + +#data +* { margin: 2px 3em inherit; } +#errors +#expected +| * +#reset + +#data +* { margin: 2px inherit 3em; } +#errors +#expected +| * +#reset + +#data +* { margin: 2px 0 0 0 inherit; } +#errors +#expected +| * +#reset + +#data +* { margin: inherit inherit; } +#errors +#expected +| * +#reset + +#data +* { margin: inherit 0 !important; } +#errors +#expected +| * +#reset + #data diff --git a/test/data/parse2/outline.dat b/test/data/parse2/outline.dat index 4b62bd0..e39fa41 100644 --- a/test/data/parse2/outline.dat +++ b/test/data/parse2/outline.dat @@ -341,6 +341,55 @@ | * #reset +#data +* { outline: thin solid red inherit; } +#errors +#expected +| * +#reset + +#data +* { outline: inherit thin solid #fff; } +#errors +#expected +| * +#reset + +#data +* { outline: inherit thin; } +#errors +#expected +| * +#reset + +#data +* { outline: thin inherit; } +#errors +#expected +| * +#reset + +#data +* { outline: inherit inherit; } +#errors +#expected +| * +#reset + +#data +* { outline: inherit #BBC !important; } +#errors +#expected +| * +#reset + +#data +* { outline: #BBC !important inherit; } +#errors +#expected +| * +#reset + #data * { outline-color: red; } diff --git a/test/data/parse2/padding.dat b/test/data/parse2/padding.dat index d847080..c3f2841 100644 --- a/test/data/parse2/padding.dat +++ b/test/data/parse2/padding.dat @@ -159,6 +159,55 @@ | * #reset +#data +* { padding: 2px inherit; } +#errors +#expected +| * +#reset + +#data +* { padding: inherit 2px; } +#errors +#expected +| * +#reset + +#data +* { padding: 2px 3em inherit; } +#errors +#expected +| * +#reset + +#data +* { padding: 2px inherit 3em; } +#errors +#expected +| * +#reset + +#data +* { padding: 2px 0 0 0 inherit; } +#errors +#expected +| * +#reset + +#data +* { padding: inherit inherit; } +#errors +#expected +| * +#reset + +#data +* { padding: inherit 0 !important; } +#errors +#expected +| * +#reset + #data diff --git a/test/dump.h b/test/dump.h index 0422b18..4f82f14 100644 --- a/test/dump.h +++ b/test/dump.h @@ -629,7 +629,7 @@ static void dump_counters(lwc_string *name, lwc_string *separator, void dump_bytecode(css_style *style, char **ptr, uint32_t depth) { void *bytecode = style->bytecode; - size_t length = style->length; + size_t length = (style->used * sizeof(css_code_t)); uint32_t offset = 0; #define ADVANCE(n) do { \ @@ -759,10 +759,11 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) break; case BACKGROUND_IMAGE_URI: { - lwc_string *he = - *((lwc_string **) - bytecode); - ADVANCE(sizeof(he)); + uint32_t snum = *((uint32_t *) bytecode); lwc_string *he; + css_stylesheet_string_get(style->sheet, + snum, + &he); + ADVANCE(sizeof(snum)); *ptr += sprintf(*ptr, "url('%.*s')", (int) lwc_string_length(he), lwc_string_data(he)); @@ -1095,21 +1096,22 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) } while (value != CONTENT_NORMAL) { - lwc_string *he = - *((lwc_string **) - bytecode); + uint32_t snum = *((uint32_t *) bytecode); + lwc_string *he; const char *end = ""; switch (value & 0xff) { case CONTENT_COUNTER: - ADVANCE(sizeof(he)); + css_stylesheet_string_get(style->sheet, snum, &he); + ADVANCE(sizeof(snum)); dump_counter(he, value, ptr); break; + case CONTENT_COUNTERS: { lwc_string *sep; - - ADVANCE(sizeof(he)); + css_stylesheet_string_get(style->sheet, snum, &he); + ADVANCE(sizeof(snum)); sep = *((lwc_string **) bytecode); ADVANCE(sizeof(sep)); @@ -1118,9 +1120,11 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) ptr); } break; + case CONTENT_URI: case CONTENT_ATTR: case CONTENT_STRING: + css_stylesheet_string_get(style->sheet, snum, &he); if (value == CONTENT_URI) *ptr += sprintf(*ptr, "url("); if (value == CONTENT_ATTR) @@ -1128,22 +1132,26 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) if (value != CONTENT_STRING) end = ")"; - ADVANCE(sizeof(he)); + ADVANCE(sizeof(snum)); *ptr += sprintf(*ptr, "'%.*s'%s", (int) lwc_string_length(he), lwc_string_data(he), end); break; + case CONTENT_OPEN_QUOTE: *ptr += sprintf(*ptr, "open-quote"); break; + case CONTENT_CLOSE_QUOTE: *ptr += sprintf(*ptr, "close-quote"); break; + case CONTENT_NO_OPEN_QUOTE: *ptr += sprintf(*ptr, "no-open-quote"); break; + case CONTENT_NO_CLOSE_QUOTE: *ptr += sprintf(*ptr, "no-close-quote"); break; @@ -1167,10 +1175,11 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) case COUNTER_INCREMENT_NAMED: while (value != COUNTER_INCREMENT_NONE) { css_fixed val; - lwc_string *he = - *((lwc_string **) - bytecode); - ADVANCE(sizeof(he)); + uint32_t snum = *((uint32_t *) bytecode); lwc_string *he; + css_stylesheet_string_get(style->sheet, + snum, + &he); + ADVANCE(sizeof(snum)); *ptr += sprintf(*ptr, "%.*s ", (int)lwc_string_length(he), lwc_string_data(he)); @@ -1194,10 +1203,11 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) break; case CSS_PROP_CURSOR: while (value == CURSOR_URI) { - lwc_string *he = - *((lwc_string **) - bytecode); - ADVANCE(sizeof(ptr)); + uint32_t snum = *((uint32_t *) bytecode); lwc_string *he; + css_stylesheet_string_get(style->sheet, + snum, + &he); + ADVANCE(sizeof(snum)); *ptr += sprintf(*ptr, "url('%.*s'), ", (int) lwc_string_length(he), lwc_string_data(he)); @@ -1380,10 +1390,10 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) case FONT_FAMILY_STRING: case FONT_FAMILY_IDENT_LIST: { - lwc_string *he = - *((lwc_string **) - bytecode); - ADVANCE(sizeof(he)); + uint32_t snum = *((uint32_t *) bytecode); + lwc_string *he; + css_stylesheet_string_get(style->sheet, snum, &he); + ADVANCE(sizeof(snum)); *ptr += sprintf(*ptr, "'%.*s'", (int) lwc_string_length(he), lwc_string_data(he)); @@ -1799,10 +1809,10 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) switch (value) { case PLAY_DURING_URI: { - lwc_string *he = - *((lwc_string **) - bytecode); - ADVANCE(sizeof(he)); + uint32_t snum = *((uint32_t *) bytecode); + lwc_string *he; + css_stylesheet_string_get(style->sheet, snum, &he); + ADVANCE(sizeof(snum)); *ptr += sprintf(*ptr, "'%.*s'", (int) lwc_string_length(he), lwc_string_data(he)); @@ -1841,10 +1851,10 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) switch (value) { case QUOTES_STRING: while (value != QUOTES_NONE) { - lwc_string *he = - *((lwc_string **) - bytecode); - ADVANCE(sizeof(he)); + uint32_t snum = *((uint32_t *) bytecode); + lwc_string *he; + css_stylesheet_string_get(style->sheet, snum, &he); + ADVANCE(sizeof(snum)); *ptr += sprintf(*ptr, " '%.*s' ", (int) lwc_string_length(he), lwc_string_data(he)); @@ -2075,10 +2085,10 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) case VOICE_FAMILY_STRING: case VOICE_FAMILY_IDENT_LIST: { - lwc_string *he = - *((lwc_string **) - bytecode); - ADVANCE(sizeof(he)); + uint32_t snum = *((uint32_t *) bytecode); + lwc_string *he; + css_stylesheet_string_get(style->sheet, snum, &he); + ADVANCE(sizeof(snum)); *ptr += sprintf(*ptr, "'%.*s'", (int) lwc_string_length(he), lwc_string_data(he)); diff --git a/test/lex-auto.c b/test/lex-auto.c index d1378fe..70f9f44 100644 --- a/test/lex-auto.c +++ b/test/lex-auto.c @@ -84,6 +84,7 @@ int main(int argc, char **argv) run_test(ctx.buf, ctx.bufused, ctx.exp, ctx.expused); free(ctx.buf); + free(ctx.exp); printf("PASS\n"); diff --git a/test/number.c b/test/number.c index 05c3125..bd5128f 100644 --- a/test/number.c +++ b/test/number.c @@ -127,6 +127,8 @@ void run_test(const uint8_t *data, size_t len, const char *exp, size_t explen) printf("got: %s expected: %.*s\n", buf, (int) explen, exp); assert(strncmp(buf, exp, explen) == 0); + + lwc_string_unref(in); } void print_css_fixed(char *buf, size_t len, css_fixed f) diff --git a/test/parse-auto.c b/test/parse-auto.c index ffff3f2..8b0a36b 100644 --- a/test/parse-auto.c +++ b/test/parse-auto.c @@ -49,8 +49,7 @@ static bool handle_line(const char *data, size_t datalen, void *pw); static void parse_expected(line_ctx *ctx, const char *data, size_t len); static void run_test(const uint8_t *data, size_t len, exp_entry *exp, size_t explen); -static void validate_rule_selector(css_rule_selector *s, exp_entry *e, - int testnum); +static bool validate_rule_selector(css_rule_selector *s, exp_entry *e); static void validate_rule_charset(css_rule_charset *s, exp_entry *e, int testnum); static void validate_rule_import(css_rule_import *s, exp_entry *e, @@ -80,12 +79,31 @@ static css_error resolve_url(void *pw, return CSS_OK; } +static bool fail_because_lwc_leaked = false; + static void printing_lwc_iterator(lwc_string *str, void *pw) { UNUSED(pw); printf(" DICT: %*s\n", (int)(lwc_string_length(str)), lwc_string_data(str)); + fail_because_lwc_leaked = true; +} + +static void destroy_expected(line_ctx *ctx) +{ + while (ctx->expused > 0) { + exp_entry *victim = &ctx->exp[--ctx->expused]; + + if (victim->bytecode != NULL) + free(victim->bytecode); + + while (victim->stused > 0) { + free(victim->stringtab[--victim->stused].string); + } + + free(victim->stringtab); + } } int main(int argc, char **argv) @@ -125,8 +143,13 @@ int main(int argc, char **argv) free(ctx.buf); + destroy_expected(&ctx); + free(ctx.exp); + lwc_iterate_strings(printing_lwc_iterator, NULL); + assert(fail_because_lwc_leaked == false); + printf("PASS\n"); return 0; @@ -146,7 +169,7 @@ bool handle_line(const char *data, size_t datalen, void *pw) ctx->buf[0] = '\0'; ctx->bufused = 0; - ctx->expused = 0; + destroy_expected(ctx); } if (ctx->indata && strncasecmp(data+1, "errors", 6) == 0) { @@ -241,7 +264,6 @@ start_rule: goto start_rule; } - /** \todo how to deal with pointers? */ while (next < data + len) { /* Skip whitespace */ while (next < data + len && isspace(*next)) @@ -302,7 +324,7 @@ start_rule: rule->stringtab[rule->stused].string[ next - str - 1] = '\0'; - rule->bcused += sizeof(void *); + rule->bcused += sizeof(css_code_t); rule->stused++; } else { /* Assume hexnum */ @@ -317,6 +339,28 @@ start_rule: } } +static void report_fail(const uint8_t *data, size_t datalen, exp_entry *e) +{ + uint32_t bcoff; + + printf(" Data: %.*s\n", (int)datalen, data); + + printf(" Expected entry:\n"); + printf(" entry type:%d name:%s\n", e->type, e->name); + printf(" bytecode len:%ld used:%ld\n", e->bclen, e->bcused); + printf(" bytecode "); + for (bcoff = 0; bcoff < e->bcused; bcoff++) { + printf("%.2x ", ((uint8_t *) e->bytecode)[bcoff]); + } + printf("\n string table len:%ld used %ld\n", e->stlen, e->stused); +/* + struct stentry { + size_t off; + char *string; + } *stringtab; +*/ +} + void run_test(const uint8_t *data, size_t len, exp_entry *exp, size_t explen) { css_stylesheet *sheet; @@ -324,6 +368,7 @@ void run_test(const uint8_t *data, size_t len, exp_entry *exp, size_t explen) css_error error; size_t e; static int testnum; + bool failed; assert(css_stylesheet_create(CSS_LEVEL_21, "UTF-8", "foo", NULL, false, false, myrealloc, NULL, resolve_url, NULL, @@ -370,6 +415,8 @@ void run_test(const uint8_t *data, size_t len, exp_entry *exp, size_t explen) e = 0; testnum++; + printf("Test %d: ", testnum); + if (sheet->rule_count != explen) { printf("%d: Got %d rules. Expected %u\n", testnum, sheet->rule_count, (int) explen); @@ -385,32 +432,40 @@ void run_test(const uint8_t *data, size_t len, exp_entry *exp, size_t explen) switch (rule->type) { case CSS_RULE_SELECTOR: - validate_rule_selector((css_rule_selector *) rule, - &exp[e], testnum); + failed = validate_rule_selector((css_rule_selector *) rule, &exp[e]); break; case CSS_RULE_CHARSET: validate_rule_charset((css_rule_charset *) rule, &exp[e], testnum); + failed = false; break; case CSS_RULE_IMPORT: validate_rule_import((css_rule_import *) rule, &exp[e], testnum); + failed = false; break; default: printf("%d: Unhandled rule type %d\n", testnum, rule->type); + failed = false; break; } + + if (failed) { + report_fail(data, len, &exp[e]); + assert(0); + } } assert(e == explen); css_stylesheet_destroy(sheet); - printf("Test %d: PASS\n", testnum); + printf("PASS\n"); } -void validate_rule_selector(css_rule_selector *s, exp_entry *e, int testnum) + +bool validate_rule_selector(css_rule_selector *s, exp_entry *e) { char name[MAX_RULE_NAME_LEN]; char *ptr = name; @@ -428,28 +483,30 @@ void validate_rule_selector(css_rule_selector *s, exp_entry *e, int testnum) /* Compare with expected selector */ if (strcmp(e->name, name) != 0) { - printf("%d: Got name '%s'. Expected '%s'\n", - testnum, name, e->name); - assert(0 && "Mismatched names"); + printf("FAIL Mismatched names\n" + " Got name '%s'. Expected '%s'\n", + name, e->name); + return true; } /* Now compare bytecode */ if (e->bytecode != NULL && s->style == NULL) { - printf("%d: Expected bytecode but none created\n", - testnum); - assert(0 && "No bytecode"); + printf("FAIL No bytecode\n" + " Expected bytecode but none created\n"); + return true; } else if (e->bytecode == NULL && s->style != NULL) { - printf("%d: No bytecode expected but some created\n", - testnum); - assert(0 && "Unexpected bytecode"); + printf("FAIL Unexpected bytecode\n" + " No bytecode expected but some created\n"); + return true; } else if (e->bytecode != NULL && s->style != NULL) { size_t i; - if (s->style->length != e->bcused) { - printf("%d: Got length %d, Expected %u\n", - testnum, s->style->length, + if ((s->style->used * sizeof(css_code_t)) != e->bcused) { + printf("FAIL Bytecode lengths differ\n" + " Got length %ld, Expected %u\n", + (s->style->used * sizeof(css_code_t)), (int) e->bcused); - assert(0 && "Bytecode lengths differ"); + return true; } for (i = 0; i < e->bcused; i++) { @@ -461,38 +518,42 @@ void validate_rule_selector(css_rule_selector *s, exp_entry *e, int testnum) } if (j != e->stused) { - lwc_string **p = (void *) ((uint8_t *) - s->style->bytecode + i); + /* String */ + lwc_string *p; + + css_stylesheet_string_get(s->style->sheet, (s->style->bytecode[i / sizeof(css_code_t)]), &p); - if (lwc_string_length(*p) != + if (lwc_string_length(p) != strlen(e->stringtab[j].string) || - memcmp(lwc_string_data(*p), + memcmp(lwc_string_data(p), e->stringtab[j].string, - lwc_string_length(*p)) != 0) { - printf("%d: Got string '%.*s'. " - "Expected '%s'\n", - testnum, - (int) lwc_string_length(*p), - lwc_string_data(*p), + lwc_string_length(p)) != 0) { + printf("FAIL Strings differ\n" + " Got string '%.*s'. " + "Expected '%s'\n", + (int) lwc_string_length(p), + lwc_string_data(p), e->stringtab[j].string); - assert(0 && "Strings differ"); + return true; } - i += sizeof (void *) - 1; + i += sizeof (css_code_t) - 1; } else if (((uint8_t *) s->style->bytecode)[i] != e->bytecode[i]) { - printf("%d: Bytecode differs at %u\n", - testnum, (int) i); + printf("FAIL Bytecode differs\n" + " Bytecode differs at %u\n ", + (int) i); while (i < e->bcused) { printf("%.2x ", ((uint8_t *) s->style->bytecode)[i]); i++; } printf("\n"); - assert(0 && "Bytecode differs"); + return true; } } } + return false; } void validate_rule_charset(css_rule_charset *s, exp_entry *e, int testnum) diff --git a/test/parse2-auto.c b/test/parse2-auto.c index 83bab14..50426d2 100644 --- a/test/parse2-auto.c +++ b/test/parse2-auto.c @@ -53,12 +53,15 @@ static css_error resolve_url(void *pw, return CSS_OK; } +static bool fail_because_lwc_leaked = false; + static void printing_lwc_iterator(lwc_string *str, void *pw) { UNUSED(pw); printf(" DICT: %*s\n", (int)(lwc_string_length(str)), lwc_string_data(str)); + fail_because_lwc_leaked = true; } int main(int argc, char **argv) @@ -97,9 +100,12 @@ int main(int argc, char **argv) run_test(ctx.buf, ctx.bufused, ctx.exp, ctx.expused); free(ctx.buf); + free(ctx.exp); lwc_iterate_strings(printing_lwc_iterator, NULL); - + + assert(fail_because_lwc_leaked == false); + printf("PASS\n"); return 0; @@ -215,6 +221,8 @@ void run_test(const uint8_t *data, size_t len, const char *exp, size_t explen) css_stylesheet_destroy(sheet); + free(buf); + printf("Test %d: PASS\n", testnum); } diff --git a/test/select-auto.c b/test/select-auto.c index 6cefbf8..5b21b66 100644 --- a/test/select-auto.c +++ b/test/select-auto.c @@ -178,12 +178,15 @@ static css_error resolve_url(void *pw, return CSS_OK; } +static bool fail_because_lwc_leaked = false; + static void printing_lwc_iterator(lwc_string *str, void *pw) { UNUSED(pw); printf(" DICT: %*s\n", (int)(lwc_string_length(str)), lwc_string_data(str)); + fail_because_lwc_leaked = true; } int main(int argc, char **argv) @@ -217,6 +220,8 @@ int main(int argc, char **argv) lwc_iterate_strings(printing_lwc_iterator, NULL); + assert(fail_because_lwc_leaked == false); + printf("PASS\n"); return 0; } -- cgit v1.2.3