From 71327cd21e3dcc793dd6e0cf99f5295e58e0322c Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Wed, 15 Apr 2009 16:45:36 +0000 Subject: More c89isms svn path=/trunk/libcss/; revision=7100 --- test/css21.c | 21 +++++++------ test/dump.h | 87 +++++++++++++++++++++++++++--------------------------- test/lex-auto.c | 9 ++++-- test/lex.c | 3 +- test/parse-auto.c | 21 +++++++------ test/parse.c | 3 +- test/parse2-auto.c | 5 ++-- test/select-auto.c | 9 +++--- 8 files changed, 86 insertions(+), 72 deletions(-) (limited to 'test') diff --git a/test/css21.c b/test/css21.c index 47aaf2f..ec5979f 100644 --- a/test/css21.c +++ b/test/css21.c @@ -29,6 +29,7 @@ int main(int argc, char **argv) uint8_t buf[CHUNK_SIZE]; css_error error; lwc_context *ctx; + int count; if (argc != 3) { printf("Usage: %s \n", argv[0]); @@ -42,7 +43,7 @@ int main(int argc, char **argv) lwc_context_ref(ctx); /* Transform weak ref to a strong ref */ - for (int count = 0; count < ITERATIONS; count++) { + for (count = 0; count < ITERATIONS; count++) { assert(css_stylesheet_create(CSS_LEVEL_21, "UTF-8", argv[2], NULL, CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL, false, @@ -92,7 +93,7 @@ int main(int argc, char **argv) if (error == CSS_OK) { css_stylesheet *import; - char buf[lwc_string_length(url) + 1]; + char *buf = alloca(lwc_string_length(url) + 1); memcpy(buf, lwc_string_data(url), lwc_string_length(url)); @@ -114,13 +115,15 @@ int main(int argc, char **argv) } #if DUMP_CSS - char *out; - size_t outlen = origlen * 2; - out = malloc(outlen); - assert(out != NULL); - dump_sheet(sheet, out, &outlen); - fwrite(out, origlen * 2 - outlen, 1, stdout); - free(out); + { + char *out; + size_t outlen = origlen * 2; + out = malloc(outlen); + assert(out != NULL); + dump_sheet(sheet, out, &outlen); + fwrite(out, origlen * 2 - outlen, 1, stdout); + free(out); + } #endif css_stylesheet_destroy(sheet); diff --git a/test/dump.h b/test/dump.h index 54a6512..595a774 100644 --- a/test/dump.h +++ b/test/dump.h @@ -49,13 +49,14 @@ void dump_sheet(css_stylesheet *sheet, char *buf, size_t *buflen) void dump_rule_selector(css_rule_selector *s, char **buf, size_t *buflen) { + uint32_t i; char *ptr = *buf; *ptr++ = '|'; *ptr++ = ' '; /* Build selector string */ - for (uint32_t i = 0; i < s->base.items; i++) { + for (i = 0; i < s->base.items; i++) { dump_selector_list(s->selectors[i], &ptr); if (i != (uint32_t) (s->base.items - 1)) { memcpy(ptr, ", ", 2); @@ -600,10 +601,10 @@ void dump_bytecode(css_style *style, char **ptr) switch (value & ~AZIMUTH_BEHIND) { case AZIMUTH_ANGLE: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -713,10 +714,10 @@ void dump_bytecode(css_style *style, char **ptr) switch (value & 0xf0) { case BACKGROUND_POSITION_HORZ_SET: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -735,10 +736,10 @@ void dump_bytecode(css_style *style, char **ptr) switch (value & 0x0f) { case BACKGROUND_POSITION_VERT_SET: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -784,10 +785,10 @@ void dump_bytecode(css_style *style, char **ptr) switch (value) { case BORDER_SPACING_SET: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); @@ -873,10 +874,10 @@ void dump_bytecode(css_style *style, char **ptr) switch (value) { case BORDER_WIDTH_SET: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -918,10 +919,10 @@ void dump_bytecode(css_style *style, char **ptr) switch (value) { case BOTTOM_SET: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -964,11 +965,11 @@ void dump_bytecode(css_style *style, char **ptr) if (value & CLIP_RECT_TOP_AUTO) { *ptr += sprintf(*ptr, "auto"); } else { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -976,11 +977,11 @@ void dump_bytecode(css_style *style, char **ptr) if (value & CLIP_RECT_RIGHT_AUTO) { *ptr += sprintf(*ptr, "auto"); } else { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -988,11 +989,11 @@ void dump_bytecode(css_style *style, char **ptr) if (value & CLIP_RECT_BOTTOM_AUTO) { *ptr += sprintf(*ptr, "auto"); } else { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -1000,11 +1001,11 @@ void dump_bytecode(css_style *style, char **ptr) if (value & CLIP_RECT_LEFT_AUTO) { *ptr += sprintf(*ptr, "auto"); } else { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -1105,15 +1106,15 @@ void dump_bytecode(css_style *style, char **ptr) switch (value) { case COUNTER_INCREMENT_NAMED: while (value != COUNTER_INCREMENT_NONE) { + css_fixed val; lwc_string *he = - *((lwc_string **) - bytecode); + *((lwc_string **) + bytecode); ADVANCE(sizeof(he)); *ptr += sprintf(*ptr, "%.*s ", (int)lwc_string_length(he), lwc_string_data(he)); - css_fixed val = - *((css_fixed *) bytecode); + val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); dump_number(val, ptr); @@ -1265,10 +1266,10 @@ void dump_bytecode(css_style *style, char **ptr) switch (value) { case ELEVATION_ANGLE: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -1356,10 +1357,10 @@ void dump_bytecode(css_style *style, char **ptr) switch (value) { case FONT_SIZE_DIMENSION: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -1468,10 +1469,10 @@ void dump_bytecode(css_style *style, char **ptr) switch (value) { case LETTER_SPACING_SET: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -1492,10 +1493,10 @@ void dump_bytecode(css_style *style, char **ptr) break; case LINE_HEIGHT_DIMENSION: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -1572,10 +1573,10 @@ void dump_bytecode(css_style *style, char **ptr) switch (value) { case MAX_HEIGHT_SET: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -1603,10 +1604,10 @@ void dump_bytecode(css_style *style, char **ptr) switch (value) { case MIN_HEIGHT_SET: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -1709,10 +1710,10 @@ void dump_bytecode(css_style *style, char **ptr) switch (value) { case PITCH_FREQUENCY: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -1952,10 +1953,10 @@ void dump_bytecode(css_style *style, char **ptr) switch (value) { case VERTICAL_ALIGN_SET: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } @@ -2043,10 +2044,10 @@ void dump_bytecode(css_style *style, char **ptr) break; case VOLUME_DIMENSION: { + uint32_t unit; css_fixed val = *((css_fixed *) bytecode); ADVANCE(sizeof(val)); - uint32_t unit = - *((uint32_t *) bytecode); + unit = *((uint32_t *) bytecode); ADVANCE(sizeof(unit)); dump_unit(val, unit, ptr); } diff --git a/test/lex-auto.c b/test/lex-auto.c index 10f097c..56a06eb 100644 --- a/test/lex-auto.c +++ b/test/lex-auto.c @@ -138,11 +138,13 @@ bool handle_line(const char *data, size_t datalen, void *pw) void parse_expected(line_ctx *ctx, const char *data, size_t len) { + css_token_type type; const char *colon = parse_strnchr(data, len, ':'); + if (colon == NULL) colon = data + len; - css_token_type type = string_to_type(data, colon - data); + type = string_to_type(data, colon - data); /* Append to list of expected tokens */ if (ctx->expused == ctx->explen) { @@ -297,8 +299,9 @@ void run_test(const uint8_t *data, size_t len, exp_entry *exp, size_t explen) if (exp[e].textLen > 0) { if (tok->data.len != exp[e].textLen) { - printf("%d: Got length %zd, Expected %zd\n", - testnum, tok->data.len, exp[e].textLen); + printf("%d: Got length %d, Expected %d\n", + testnum, (int) tok->data.len, + (int) exp[e].textLen); assert(0 && "Text lengths differ"); } diff --git a/test/lex.c b/test/lex.c index 13a4dd0..6aadf28 100644 --- a/test/lex.c +++ b/test/lex.c @@ -128,6 +128,7 @@ int main(int argc, char **argv) uint8_t buf[CHUNK_SIZE]; css_token *tok; css_error error; + int i; if (argc != 3) { printf("Usage: %s \n", argv[0]); @@ -137,7 +138,7 @@ int main(int argc, char **argv) /* Initialise library */ assert(css_initialise(argv[1], myrealloc, NULL) == CSS_OK); - for (int i = 0; i < ITERATIONS; i++) { + for (i = 0; i < ITERATIONS; i++) { assert(parserutils_inputstream_create("UTF-8", CSS_CHARSET_DICTATED,css_charset_extract, (parserutils_alloc) myrealloc, NULL, &stream) == diff --git a/test/parse-auto.c b/test/parse-auto.c index dfd99ca..0bab4c2 100644 --- a/test/parse-auto.c +++ b/test/parse-auto.c @@ -334,7 +334,7 @@ void run_test(const uint8_t *data, size_t len, exp_entry *exp, size_t explen) if (error == CSS_OK) { css_stylesheet *import; - char buf[lwc_string_length(url) + 1]; + char *buf = alloca(lwc_string_length(url) + 1); memcpy(buf, lwc_string_data(url), lwc_string_length(url)); @@ -356,8 +356,8 @@ void run_test(const uint8_t *data, size_t len, exp_entry *exp, size_t explen) testnum++; if (sheet->rule_count != explen) { - printf("%d: Got %d rules. Expected %zu\n", - testnum, sheet->rule_count, explen); + printf("%d: Got %d rules. Expected %u\n", + testnum, sheet->rule_count, (int) explen); assert(0 && "Unexpected number of rules"); } @@ -400,9 +400,10 @@ void validate_rule_selector(css_rule_selector *s, exp_entry *e, int testnum) { char name[MAX_RULE_NAME_LEN]; char *ptr = name; + uint32_t i; /* Build selector string */ - for (uint32_t i = 0; i < s->base.items; i++) { + for (i = 0; i < s->base.items; i++) { dump_selector_list(s->selectors[i], &ptr); if (i != (uint32_t) (s->base.items - 1)) { memcpy(ptr, ", ", 2); @@ -428,14 +429,16 @@ void validate_rule_selector(css_rule_selector *s, exp_entry *e, int testnum) testnum); assert(0 && "Unexpected bytecode"); } else if (e->bytecode != NULL && s->style != NULL) { + size_t i; + if (s->style->length != e->bcused) { - printf("%d: Got length %d, Expected %zu\n", + printf("%d: Got length %d, Expected %u\n", testnum, s->style->length, - e->bcused); + (int) e->bcused); assert(0 && "Bytecode lengths differ"); } - for (size_t i = 0; i < e->bcused; i++) { + for (i = 0; i < e->bcused; i++) { size_t j; for (j = 0; j < e->stused; j++) { @@ -464,8 +467,8 @@ void validate_rule_selector(css_rule_selector *s, exp_entry *e, int testnum) i += sizeof (void *) - 1; } else if (((uint8_t *) s->style->bytecode)[i] != e->bytecode[i]) { - printf("%d: Bytecode differs at %zu\n", - testnum, i); + printf("%d: Bytecode differs at %u\n", + testnum, (int) i); while (i < e->bcused) { printf("%.2x ", ((uint8_t *) s->style->bytecode)[i]); diff --git a/test/parse.c b/test/parse.c index ed0deb7..543cfe3 100644 --- a/test/parse.c +++ b/test/parse.c @@ -83,6 +83,7 @@ int main(int argc, char **argv) uint8_t buf[CHUNK_SIZE]; css_error error; lwc_context *ctx; + int i; if (argc != 3) { printf("Usage: %s \n", argv[0]); @@ -94,7 +95,7 @@ int main(int argc, char **argv) assert(lwc_create_context(myrealloc, NULL, &ctx) == lwc_error_ok); lwc_context_ref(ctx); - for (int i = 0; i < ITERATIONS; i++) { + for (i = 0; i < ITERATIONS; i++) { assert(css_parser_create("UTF-8", CSS_CHARSET_DICTATED, ctx, myrealloc, NULL, &parser) == CSS_OK); diff --git a/test/parse2-auto.c b/test/parse2-auto.c index dd3c529..c6426be 100644 --- a/test/parse2-auto.c +++ b/test/parse2-auto.c @@ -192,8 +192,9 @@ void run_test(const uint8_t *data, size_t len, const char *exp, size_t explen) dump_sheet(sheet, buf, &buflen); if (2 * explen - buflen != explen || memcmp(buf, exp, explen) != 0) { - printf("Expected (%zu):\n%.*s\n", explen, (int) explen, exp); - printf("Result (%zu):\n%.*s\n", 2 * explen - buflen, + printf("Expected (%u):\n%.*s\n", + (int) explen, (int) explen, exp); + printf("Result (%u):\n%.*s\n", (int) (2 * explen - buflen), (int) (2 * explen - buflen), buf); assert(0 && "Result doesn't match expected"); } diff --git a/test/select-auto.c b/test/select-auto.c index 5a9bfc2..c42c82e 100644 --- a/test/select-auto.c +++ b/test/select-auto.c @@ -154,8 +154,8 @@ int main(int argc, char **argv) return 1; } - printf("css_hint: %lu\n", sizeof(css_hint)); - printf("computed: %lu\n", sizeof(css_computed_style)); + printf("css_hint: %u\n", (int) sizeof(css_hint)); + printf("computed: %u\n", (int) sizeof(css_computed_style)); assert(css_initialise(argv[1], myrealloc, NULL) == CSS_OK); @@ -642,8 +642,9 @@ void run_test(line_ctx *ctx, const char *exp, size_t explen) dump_computed_style(computed, buf, &buflen); if (8192 - buflen != explen || memcmp(buf, exp, explen) != 0) { - printf("Expected (%zu):\n%.*s\n", explen, (int) explen, exp); - printf("Result (%zu):\n%.*s\n", 8192 - buflen, + printf("Expected (%u):\n%.*s\n", + (int) explen, (int) explen, exp); + printf("Result (%u):\n%.*s\n", (int) (8192 - buflen), (int) (8192 - buflen), buf); assert(0 && "Result doesn't match expected"); } -- cgit v1.2.3