diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/INDEX | 1 | ||||
-rw-r--r-- | test/Makefile | 2 | ||||
-rw-r--r-- | test/data/parse2/INDEX | 3 | ||||
-rw-r--r-- | test/data/parse2/calc.dat | 195 | ||||
-rw-r--r-- | test/data/select/INDEX | 1 | ||||
-rw-r--r-- | test/data/select/calc.dat | 112 | ||||
-rw-r--r-- | test/data/select2/INDEX | 5 | ||||
-rw-r--r-- | test/data/select2/calc.dat | 223 | ||||
-rw-r--r-- | test/dump.h | 61 | ||||
-rw-r--r-- | test/dump_computed.h | 24 | ||||
-rw-r--r-- | test/select.c | 3 | ||||
-rw-r--r-- | test/select2.c | 4 |
12 files changed, 629 insertions, 5 deletions
@@ -11,6 +11,7 @@ number Conversion of numbers to fixed point number parse-auto Automated parser tests (bytecode) parse parse2-auto Automated parser tests (om & invalid) parse2 select Automated selection engine tests select +select2 Automated selection engine tests (resolved units) select2 # Regression tests diff --git a/test/Makefile b/test/Makefile index 18124ce..fdd03d8 100644 --- a/test/Makefile +++ b/test/Makefile @@ -2,6 +2,6 @@ DIR_TEST_ITEMS := csdetect:csdetect.c css21:css21.c lex:lex.c \ lex-auto:lex-auto.c number:number.c \ parse:parse.c parse-auto:parse-auto.c parse2-auto:parse2-auto.c \ - select:select.c + select:select.c select2:select2.c include $(NSBUILD)/Makefile.subdir diff --git a/test/data/parse2/INDEX b/test/data/parse2/INDEX index 95534f6..59dc83b 100644 --- a/test/data/parse2/INDEX +++ b/test/data/parse2/INDEX @@ -24,4 +24,5 @@ multicol.dat Multi-column layout property tests flexbox.dat Flexbox properties and shorthands tests units.dat Length unit tests dodgy-media-block.dat Media block with incomplete ruleset -svg.dat SVG property tests +svg.dat SVG property tests +calc.dat calc() tests diff --git a/test/data/parse2/calc.dat b/test/data/parse2/calc.dat new file mode 100644 index 0000000..f743411 --- /dev/null +++ b/test/data/parse2/calc.dat @@ -0,0 +1,195 @@ +#data +* { height: calc(50vh + 10px)} +#errors +#expected +| * +| height: /* -> 0px */ calc(50vh 10px + =) +#reset + +#data +* { line-height: calc(50vh + 10px)} +#errors +#expected +| * +| line-height: /* -> 0any */ calc(50vh 10px + =) +#reset + +#data +* { line-height: calc( / 2)} +#errors +#expected +| * +#reset + +#data +* { line-height: calc( + 2)} +#errors +#expected +| * +#reset + +#data +* { line-height: calc(2 / 2px)} +#errors +#expected +| * +#reset + +#data +* { width: calc(50vh + 10px)} +#errors +#expected +| * +| width: /* -> 0px */ calc(50vh 10px + =) +#reset + +#data +* { z-index: calc(2 * 3)} +#errors +#expected +| * +| z-index: /* -> 0number */ calc(2 3 * =) +#reset + +#data +* { z-index: calc(4 + 5 / 9)} +#errors +#expected +| * +| z-index: /* -> 0number */ calc(4 5 9 / + =) +#reset + +#data +* { z-index: calc(1 + 2 + 3 + 4)} +#errors +#expected +| * +| z-index: /* -> 0number */ calc(1 2 + 3 + 4 + =) +#reset + +#data +* { z-index: calc(1 + 2 * 3 + 4)} +#errors +#expected +| * +| z-index: /* -> 0number */ calc(1 2 3 * + 4 + =) +#reset + +#data +* { z-index: calc((1 + 2) * (3 + 4))} +#errors +#expected +| * +| z-index: /* -> 0number */ calc(1 2 + 3 4 + * =) +#reset + +#data +* { z-index: calc(1 + 2} +#errors +#expected +| * +#reset + +#data +* { z-index: calc(} +#errors +#expected +| * +#reset + +#data +* { z-index: calc} +#errors +#expected +| * +#reset + +#data +* { z-index: calc (1 + 2)} +#errors +#expected +| * +#reset + +#data +* { z-index: calc(1)} +#errors +#expected +| * +| z-index: /* -> 0number */ calc(1 =) +#reset + +#data +* { z-index: calc()} +#errors +#expected +| * +#reset + +#data +* { z-index: calc((1 + 2)} +#errors +#expected +| * +#reset + +#data +* { z-index: calc(((1 + 2)))} +#errors +#expected +| * +| z-index: /* -> 0number */ calc(1 2 + =) +#reset + +#data +* { z-index: calc( ( ( 1 + 2 ) ) )} +#errors +#expected +| * +| z-index: /* -> 0number */ calc(1 2 + =) +#reset + +#data +* { z-index: calc( ( 3 / ( 1 + 2 ) ) )} +#errors +#expected +| * +#reset + +#data +* { width: calc(50vh + 10hz)} +#errors +#expected +| * +#reset + +#data +* { width: calc(50% + 10px)} +#errors +#expected +| * +| width: /* -> 0px */ calc(50% 10px + =) +#reset + +#data +* { word-spacing: calc(50% + 10px)} +#errors +#expected +| * +#reset + +#data +* { word-spacing: calc(0.4em + 10px)} +#errors +#expected +| * +| word-spacing: /* -> 0px */ calc(0.400em 10px + =) +#reset + +#data +* { width: calc(1em + 1px) !important } +#errors +#expected +| * +| width: /* -> 0px */ calc(1em 1px + =) !important +#reset diff --git a/test/data/select/INDEX b/test/data/select/INDEX index c05567a..9c8aad2 100644 --- a/test/data/select/INDEX +++ b/test/data/select/INDEX @@ -4,3 +4,4 @@ tests1.dat Basic tests defaulting.dat Explicit defaulting tests +calc.dat Tests involving calc
\ No newline at end of file diff --git a/test/data/select/calc.dat b/test/data/select/calc.dat new file mode 100644 index 0000000..928f997 --- /dev/null +++ b/test/data/select/calc.dat @@ -0,0 +1,112 @@ +#tree +| div* +#ua +div { width: calc(10% + 16px); } +#user +div { width: 10px; } +#errors +#expected +align-content: stretch +align-items: stretch +align-self: auto +background-attachment: scroll +background-color: #00000000 +background-image: none +background-position: 0% 0% +background-repeat: repeat +border-collapse: separate +border-spacing: 0px 0px +border-top-color: #ff000000 +border-right-color: #ff000000 +border-bottom-color: #ff000000 +border-left-color: #ff000000 +border-top-style: none +border-right-style: none +border-bottom-style: none +border-left-style: none +border-top-width: 2px +border-right-width: 2px +border-bottom-width: 2px +border-left-width: 2px +bottom: auto +box-sizing: content-box +break-after: auto +break-before: auto +break-inside: auto +caption-side: top +clear: none +clip: auto +color: #ff000000 +column-count: auto +column-fill: balance +column-gap: normal +column-rule-color: #ff000000 +column-rule-style: none +column-rule-width: 2px +column-span: none +column-width: auto +content: normal +counter-increment: none +counter-reset: none +cursor: auto +direction: ltr +display: inline +empty-cells: show +fill-opacity: 1.000 +flex-basis: auto +flex-direction: row +flex-grow: 0.000 +flex-shrink: 1.000 +flex-wrap: nowrap +float: none +font-family: sans-serif +font-size: 16px +font-style: normal +font-variant: normal +font-weight: normal +height: auto +justify-content: flex-start +left: auto +letter-spacing: normal +line-height: normal +list-style-image: none +list-style-position: outside +list-style-type: disc +margin-top: 0px +margin-right: 0px +margin-bottom: 0px +margin-left: 0px +max-height: none +max-width: none +min-height: 0px +min-width: 0px +opacity: 1.000 +order: 0 +outline-color: invert +outline-style: none +outline-width: 2px +overflow-x: visible +overflow-y: visible +padding-top: 0px +padding-right: 0px +padding-bottom: 0px +padding-left: 0px +position: static +quotes: none +right: auto +stroke-opacity: 1.000 +table-layout: auto +text-align: default +text-decoration: none +text-indent: 0px +text-transform: none +top: auto +unicode-bidi: normal +vertical-align: baseline +visibility: visible +white-space: normal +width: 10px +word-spacing: normal +writing-mode: horizontal-tb +z-index: auto +#reset diff --git a/test/data/select2/INDEX b/test/data/select2/INDEX new file mode 100644 index 0000000..fbd834d --- /dev/null +++ b/test/data/select2/INDEX @@ -0,0 +1,5 @@ +# Index file for automated parser tests +# +# Test Description + +calc.dat Tests involving calc diff --git a/test/data/select2/calc.dat b/test/data/select2/calc.dat new file mode 100644 index 0000000..b3a5ef5 --- /dev/null +++ b/test/data/select2/calc.dat @@ -0,0 +1,223 @@ +#tree +| div* +#ua +div { width: calc(10% + 16px); } +#user +div { width: 10px; } +#errors +#expected +align-content: stretch +align-items: stretch +align-self: auto +background-attachment: scroll +background-color: #00000000 +background-image: none +background-position: 0% 0% +background-repeat: repeat +border-collapse: separate +border-spacing: 0px 0px +border-top-color: #ff000000 +border-right-color: #ff000000 +border-bottom-color: #ff000000 +border-left-color: #ff000000 +border-top-style: none +border-right-style: none +border-bottom-style: none +border-left-style: none +border-top-width: 2px +border-right-width: 2px +border-bottom-width: 2px +border-left-width: 2px +bottom: auto +box-sizing: content-box +break-after: auto +break-before: auto +break-inside: auto +caption-side: top +clear: none +clip: auto +color: #ff000000 +column-count: auto +column-fill: balance +column-gap: normal +column-rule-color: #ff000000 +column-rule-style: none +column-rule-width: 2px +column-span: none +column-width: auto +content: normal +counter-increment: none +counter-reset: none +cursor: auto +direction: ltr +display: inline +empty-cells: show +fill-opacity: 1.000 +flex-basis: auto +flex-direction: row +flex-grow: 0.000 +flex-shrink: 1.000 +flex-wrap: nowrap +float: none +font-family: sans-serif +font-size: 16px +font-style: normal +font-variant: normal +font-weight: normal +height: auto +justify-content: flex-start +left: auto +letter-spacing: normal +line-height: normal +list-style-image: none +list-style-position: outside +list-style-type: disc +margin-top: 0px +margin-right: 0px +margin-bottom: 0px +margin-left: 0px +max-height: none +max-width: none +min-height: 0px +min-width: 0px +opacity: 1.000 +order: 0 +outline-color: invert +outline-style: none +outline-width: 2px +overflow-x: visible +overflow-y: visible +padding-top: 0px +padding-right: 0px +padding-bottom: 0px +padding-left: 0px +position: static +quotes: none +right: auto +stroke-opacity: 1.000 +table-layout: auto +text-align: default +text-decoration: none +text-indent: 0px +text-transform: none +top: auto +unicode-bidi: normal +vertical-align: baseline +visibility: visible +white-space: normal +width: 10 pixels +word-spacing: normal +writing-mode: horizontal-tb +z-index: auto +#reset + +#tree +| div* +#ua +div { width: calc(10% + 16px); } +#errors +#expected +align-content: stretch +align-items: stretch +align-self: auto +background-attachment: scroll +background-color: #00000000 +background-image: none +background-position: 0% 0% +background-repeat: repeat +border-collapse: separate +border-spacing: 0px 0px +border-top-color: #ff000000 +border-right-color: #ff000000 +border-bottom-color: #ff000000 +border-left-color: #ff000000 +border-top-style: none +border-right-style: none +border-bottom-style: none +border-left-style: none +border-top-width: 2px +border-right-width: 2px +border-bottom-width: 2px +border-left-width: 2px +bottom: auto +box-sizing: content-box +break-after: auto +break-before: auto +break-inside: auto +caption-side: top +clear: none +clip: auto +color: #ff000000 +column-count: auto +column-fill: balance +column-gap: normal +column-rule-color: #ff000000 +column-rule-style: none +column-rule-width: 2px +column-span: none +column-width: auto +content: normal +counter-increment: none +counter-reset: none +cursor: auto +direction: ltr +display: inline +empty-cells: show +fill-opacity: 1.000 +flex-basis: auto +flex-direction: row +flex-grow: 0.000 +flex-shrink: 1.000 +flex-wrap: nowrap +float: none +font-family: sans-serif +font-size: 16px +font-style: normal +font-variant: normal +font-weight: normal +height: auto +justify-content: flex-start +left: auto +letter-spacing: normal +line-height: normal +list-style-image: none +list-style-position: outside +list-style-type: disc +margin-top: 0px +margin-right: 0px +margin-bottom: 0px +margin-left: 0px +max-height: none +max-width: none +min-height: 0px +min-width: 0px +opacity: 1.000 +order: 0 +outline-color: invert +outline-style: none +outline-width: 2px +overflow-x: visible +overflow-y: visible +padding-top: 0px +padding-right: 0px +padding-bottom: 0px +padding-left: 0px +position: static +quotes: none +right: auto +stroke-opacity: 1.000 +table-layout: auto +text-align: default +text-decoration: none +text-indent: 0px +text-transform: none +top: auto +unicode-bidi: normal +vertical-align: baseline +visibility: visible +white-space: normal +width: 118 pixels +word-spacing: normal +writing-mode: horizontal-tb +z-index: auto +#reset diff --git a/test/dump.h b/test/dump.h index 09a35b0..3d7038a 100644 --- a/test/dump.h +++ b/test/dump.h @@ -131,7 +131,7 @@ void dump_rule_media(css_rule_media *s, char **buf, size_t *buflen) char *ptr = *buf; css_rule *rule; - ptr += sprintf(ptr, "| @media %s%03lx", + ptr += sprintf(ptr, "| @media %s%03" PRIx64, s->media->negate_type ? "not " : "", s->media->type); @@ -642,6 +642,12 @@ static void dump_unit(css_fixed val, uint32_t unit, char **ptr) case UNIT_KHZ: *ptr += sprintf(*ptr, "kHz"); break; + case UNIT_CALC_ANY: + *ptr += sprintf(*ptr, "any"); + break; + case UNIT_CALC_NUMBER: + *ptr += sprintf(*ptr, "number"); + break; } } @@ -798,6 +804,59 @@ void dump_bytecode(css_style *style, char **ptr, uint32_t depth) *ptr += sprintf(*ptr, "revert"); } else if (getFlagValue(opv) == FLAG_VALUE_UNSET) { *ptr += sprintf(*ptr, "unset"); + } else if (isCalc(opv)) { + lwc_string *calc_expr = NULL; + const uint8_t *codeptr = NULL; + css_code_t calc_opcode; + uint32_t unit, snum; + /* First entry is a unit */ + unit = *((uint32_t *)bytecode); + ADVANCE(sizeof(unit)); + /* Second entry is an lwc_string of the expression */ + snum = *((uint32_t *)bytecode); + ADVANCE(sizeof(snum)); + css__stylesheet_string_get(style->sheet, snum, &calc_expr); + codeptr = (const uint8_t *)lwc_string_data(calc_expr); + *ptr += sprintf(*ptr, "/* -> "); + dump_unit(0, unit, ptr); + *ptr += sprintf(*ptr, " */ calc("); + while ((calc_opcode = *((css_code_t *)(void *)codeptr)) != CALC_FINISH) { + codeptr += sizeof(calc_opcode); + switch (calc_opcode) { + case CALC_ADD: + *ptr += sprintf(*ptr, "+ "); + break; + case CALC_SUBTRACT: + *ptr += sprintf(*ptr, "- "); + break; + case CALC_MULTIPLY: + *ptr += sprintf(*ptr, "* "); + break; + case CALC_DIVIDE: + *ptr += sprintf(*ptr, "/ "); + break; + case CALC_PUSH_VALUE: { + css_fixed num = *((css_fixed *)(void *)codeptr); + codeptr += sizeof(num); + uint32_t unit = *((uint32_t *)(void *)codeptr); + codeptr += sizeof(unit); + dump_unit(num, unit, ptr); + *ptr += sprintf(*ptr, " "); + break; + } + case CALC_PUSH_NUMBER: { + css_fixed num = *((css_fixed *)(void *)codeptr); + codeptr += sizeof(num); + dump_number(num, ptr); + *ptr += sprintf(*ptr, " "); + break; + } + default: + *ptr += sprintf(*ptr, "??%d ", calc_opcode); + break; + } + } + *ptr += sprintf(*ptr, "=)"); } else { value = getValue(opv); diff --git a/test/dump_computed.h b/test/dump_computed.h index f769075..d9d5923 100644 --- a/test/dump_computed.h +++ b/test/dump_computed.h @@ -159,6 +159,9 @@ static size_t dump_css_unit(css_fixed val, css_unit unit, char *ptr, size_t len) case CSS_UNIT_KHZ: ret += snprintf(ptr + ret, len - ret, "kHz"); break; + case CSS_UNIT_CALC: + ret += snprintf(ptr + ret, len - ret, "calc()"); + break; } return ret; @@ -166,7 +169,7 @@ static size_t dump_css_unit(css_fixed val, css_unit unit, char *ptr, size_t len) static void dump_computed_style(const css_computed_style *style, char *buf, - size_t *len) + size_t *len, css_unit_ctx *unit_ctx) { char *ptr = buf; size_t wrote = 0; @@ -182,6 +185,11 @@ static void dump_computed_style(const css_computed_style *style, char *buf, const css_computed_counter *counter = NULL; lwc_string **string_list = NULL; int32_t integer = 0; +#ifdef USE_DEVICE + int pixels = 0; +#endif + + (void)unit_ctx; /* Avoid unused argument warnings in select.c case */ /* align-content */ val = css_computed_align_content(style); @@ -3138,7 +3146,11 @@ static void dump_computed_style(const css_computed_style *style, char *buf, *len -= wrote; /* width */ +#ifdef USE_DEVICE + val = css_computed_width_px(style, unit_ctx, 1024, &pixels); +#else val = css_computed_width(style, &len1, &unit1); +#endif switch (val) { case CSS_WIDTH_INHERIT: wrote = snprintf(ptr, *len, "width: inherit\n"); @@ -3151,9 +3163,19 @@ static void dump_computed_style(const css_computed_style *style, char *buf, ptr += wrote; *len -= wrote; +#ifdef USE_DEVICE + wrote = dump_css_number(INTTOFIX(pixels), ptr, *len); + ptr += wrote; + *len -= wrote; + + wrote = snprintf(ptr, *len, " pixels"); + ptr += wrote; + *len -= wrote; +#else wrote = dump_css_unit(len1, unit1, ptr, *len); ptr += wrote; *len -= wrote; +#endif wrote = snprintf(ptr, *len, "\n"); break; diff --git a/test/select.c b/test/select.c index 5bc7856..4bab187 100644 --- a/test/select.c +++ b/test/select.c @@ -808,6 +808,7 @@ static css_error get_libcss_node_data(void *pw, void *n, static css_unit_ctx unit_ctx = { .font_size_default = 16 * (1 << CSS_RADIX_POINT), + .device_dpi = 96 * (1 << CSS_RADIX_POINT), }; static css_select_handler select_handler = { @@ -1306,7 +1307,7 @@ static void run_test_select_tree(css_select_ctx *select, if (node == ctx->target) { dump_computed_style(sr->styles[ctx->pseudo_element], - buf, buflen); + buf, buflen, &unit_ctx); } if (node->parent == NULL) { diff --git a/test/select2.c b/test/select2.c new file mode 100644 index 0000000..bd9762b --- /dev/null +++ b/test/select2.c @@ -0,0 +1,4 @@ +/* This is a slightly modification of the select.c behaviour */ + +#define USE_DEVICE +#include "select.c" |