summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/data/select/tests1.dat9
-rw-r--r--test/dump_computed.h106
-rw-r--r--test/select-auto.c14
3 files changed, 121 insertions, 8 deletions
diff --git a/test/data/select/tests1.dat b/test/data/select/tests1.dat
index dac5fbf..d8a55b0 100644
--- a/test/data/select/tests1.dat
+++ b/test/data/select/tests1.dat
@@ -6,14 +6,13 @@
#ua
div, p { display: block; }
#user
-.green { color: red !important; }
+.green { color: #f00 !important; }
#author
div#foo { background-color: #bbc; }
-.green { color: green; }
+.green { color: #0f0; }
#errors
#expected
-background-color: #bbbbcc00
-color: red;
+color: #ff000000
display: block
#reset
@@ -25,7 +24,7 @@ div { display: block; }
div { display: inline; }
#errors
#expected
-display: block;
+display: block
#reset
#tree all active
diff --git a/test/dump_computed.h b/test/dump_computed.h
new file mode 100644
index 0000000..dda07c1
--- /dev/null
+++ b/test/dump_computed.h
@@ -0,0 +1,106 @@
+#include <libcss/computed.h>
+#include <libcss/properties.h>
+
+static void dump_computed_style(const css_computed_style *style, char *buf,
+ size_t *len)
+{
+ char *ptr = buf;
+ size_t wrote = 0;
+ uint8_t val;
+ css_color color;
+
+ val = css_computed_background_attachment(style);
+ switch (val) {
+ case CSS_BACKGROUND_ATTACHMENT_FIXED:
+ wrote = snprintf(ptr, *len, "background-attachment: fixed\n");
+ break;
+ case CSS_BACKGROUND_ATTACHMENT_SCROLL:
+ wrote = snprintf(ptr, *len, "background-attachment: scroll\n");
+ break;
+ default:
+ wrote = 0;
+ break;
+ }
+ ptr += wrote;
+ *len -= wrote;
+
+ val = css_computed_background_color(style, &color);
+ switch (val) {
+ case CSS_BACKGROUND_COLOR_TRANSPARENT:
+ wrote = snprintf(ptr, *len, "background-color: transparent\n");
+ break;
+ case CSS_BACKGROUND_COLOR_COLOR:
+ wrote = snprintf(ptr, *len, "background-color: #%08x\n", color);
+ break;
+ default:
+ wrote = 0;
+ break;
+ }
+ ptr += wrote;
+ *len -= wrote;
+
+ val = css_computed_color(style, &color);
+ if (val == CSS_COLOR_COLOR) {
+ wrote = snprintf(ptr, *len, "color: #%08x\n", color);
+ ptr += wrote;
+ *len -= wrote;
+ }
+
+ val = css_computed_display(style);
+ switch (val) {
+ case CSS_DISPLAY_INLINE:
+ wrote = snprintf(ptr, *len, "display: inline\n");
+ break;
+ case CSS_DISPLAY_BLOCK:
+ wrote = snprintf(ptr, *len, "display: block\n");
+ break;
+ case CSS_DISPLAY_LIST_ITEM:
+ wrote = snprintf(ptr, *len, "display: list-item\n");
+ break;
+ case CSS_DISPLAY_RUN_IN:
+ wrote = snprintf(ptr, *len, "display: run-in\n");
+ break;
+ case CSS_DISPLAY_INLINE_BLOCK:
+ wrote = snprintf(ptr, *len, "display: inline-block\n");
+ break;
+ case CSS_DISPLAY_TABLE:
+ wrote = snprintf(ptr, *len, "display: table\n");
+ break;
+ case CSS_DISPLAY_INLINE_TABLE:
+ wrote = snprintf(ptr, *len, "display: inline-table\n");
+ break;
+ case CSS_DISPLAY_TABLE_ROW_GROUP:
+ wrote = snprintf(ptr, *len, "display: table-row-group\n");
+ break;
+ case CSS_DISPLAY_TABLE_HEADER_GROUP:
+ wrote = snprintf(ptr, *len, "display: table-header-group\n");
+ break;
+ case CSS_DISPLAY_TABLE_FOOTER_GROUP:
+ wrote = snprintf(ptr, *len, "display: table-footer-group\n");
+ break;
+ case CSS_DISPLAY_TABLE_ROW:
+ wrote = snprintf(ptr, *len, "display: table-row\n");
+ break;
+ case CSS_DISPLAY_TABLE_COLUMN_GROUP:
+ wrote = snprintf(ptr, *len, "display: table-column-group\n");
+ break;
+ case CSS_DISPLAY_TABLE_COLUMN:
+ wrote = snprintf(ptr, *len, "display: table-column\n");
+ break;
+ case CSS_DISPLAY_TABLE_CELL:
+ wrote = snprintf(ptr, *len, "display: table-cell\n");
+ break;
+ case CSS_DISPLAY_TABLE_CAPTION:
+ wrote = snprintf(ptr, *len, "display: table-caption\n");
+ break;
+ case CSS_DISPLAY_NONE:
+ wrote = snprintf(ptr, *len, "display: none\n");
+ break;
+ default:
+ wrote = 0;
+ break;
+ }
+ ptr += wrote;
+ *len -= wrote;
+}
+
diff --git a/test/select-auto.c b/test/select-auto.c
index 8960dca..75558c4 100644
--- a/test/select-auto.c
+++ b/test/select-auto.c
@@ -12,6 +12,7 @@
#include "utils/utils.h"
+#include "dump_computed.h"
#include "testutils.h"
typedef struct attribute {
@@ -182,6 +183,14 @@ bool handle_line(const char *data, size_t datalen, void *pw)
ctx->insheet = false;
ctx->inerrors = true;
ctx->inexp = false;
+ } else if (strncasecmp(data+1, "ua", 2) == 0 ||
+ strncasecmp(data+1, "user", 4) == 0 ||
+ strncasecmp(data+1, "author", 6) == 0) {
+ assert(css_stylesheet_data_done(
+ ctx->sheets[ctx->n_sheets - 1])
+ == CSS_OK);
+
+ parse_sheet(ctx, data + 1, datalen - 1);
} else {
error = css_stylesheet_append_data(
ctx->sheets[ctx->n_sheets - 1],
@@ -636,15 +645,14 @@ void run_test(line_ctx *ctx, const char *exp, size_t explen)
ctx->pseudo_classes, ctx->media, computed,
&select_handler, NULL) == CSS_OK);
- /** \todo dump_computed_style(sheet, buf, &buflen); */
-#if 0
+ dump_computed_style(computed, 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,
(int) (2 * explen - buflen), buf);
assert(0 && "Result doesn't match expected");
}
-#endif
/* Clean up */
css_computed_style_destroy(computed);