84static css_error node_classes(
void *pw,
void *n,
85 lwc_string ***classes, uint32_t *n_classes)
94 for (i = 0; i < *n_classes; i++)
101static css_error node_id(
void *pw,
void *n,
110 assert(lwc_string_caseless_isequal(
125static css_error named_ancestor_node(
void *pw,
void *n,
134 assert(lwc_string_caseless_isequal(
136 &match) == lwc_error_ok);
141 *ancestor = (
void *)
node;
146static css_error named_parent_node(
void *pw,
void *n,
156 assert(lwc_string_caseless_isequal(
166static css_error named_sibling_node(
void *pw,
void *n,
176 assert(lwc_string_caseless_isequal(
186static css_error named_generic_sibling_node(
void *pw,
void *n,
195 assert(lwc_string_caseless_isequal(
197 &match) == lwc_error_ok);
202 *sibling = (
void *)
node;
207static css_error parent_node(
void *pw,
void *n,
void **parent)
218static css_error sibling_node(
void *pw,
void *n,
void **sibling)
229static css_error node_has_name(
void *pw,
void *n,
236 if (lwc_string_length(qname->
name) == 1 &&
237 lwc_string_data(qname->
name)[0] ==
'*')
241 qname->
name, match) == lwc_error_ok);
246static css_error node_has_class(
void *pw,
void *n,
256 assert(lwc_string_caseless_isequal(
258 &amatch) == lwc_error_ok);
272static css_error node_has_id(
void *pw,
void *n,
282 assert(lwc_string_caseless_isequal(
298static css_error node_has_attribute(
void *pw,
void *n,
308 assert(lwc_string_caseless_isequal(
318static css_error node_has_attribute_equal(
void *pw,
void *n,
330 assert(lwc_string_caseless_isequal(
337 if (*match ==
true) {
338 assert(lwc_string_caseless_isequal(
346static css_error node_has_attribute_includes(
void *pw,
void *n,
353 size_t vlen = lwc_string_length(value);
359 assert(lwc_string_caseless_isequal(
366 if (*match ==
true) {
369 const char *end = start +
374 for (p = start; p < end; p++) {
376 if ((
size_t) (p - start) == vlen &&
378 lwc_string_data(value),
392static css_error node_has_attribute_dashmatch(
void *pw,
void *n,
399 size_t vlen = lwc_string_length(value);
405 assert(lwc_string_caseless_isequal(
412 if (*match ==
true) {
415 const char *end = start +
420 for (p = start; p < end; p++) {
422 if ((
size_t) (p - start) == vlen &&
424 lwc_string_data(value),
438static css_error node_has_attribute_prefix(
void *pw,
void *n,
450 assert(lwc_string_caseless_isequal(
457 if (*match ==
true) {
461 size_t vlen = lwc_string_length(value);
462 const char *vdata = lwc_string_data(value);
467 *match = (strncasecmp(data, vdata, vlen) == 0);
473static css_error node_has_attribute_suffix(
void *pw,
void *n,
485 assert(lwc_string_caseless_isequal(
492 if (*match ==
true) {
496 size_t vlen = lwc_string_length(value);
497 const char *vdata = lwc_string_data(value);
499 size_t suffix_start = len - vlen;
504 *match = (strncasecmp(data + suffix_start,
512static css_error node_has_attribute_substring(
void *pw,
void *n,
524 assert(lwc_string_caseless_isequal(
531 if (*match ==
true) {
535 size_t vlen = lwc_string_length(value);
536 const char *vdata = lwc_string_data(value);
538 const char *last_start = data + len - vlen;
543 while (data <= last_start) {
544 if (strncasecmp(data, vdata, vlen) == 0) {
552 if (data > last_start)
560static css_error node_is_root(
void *pw,
void *n,
bool *match)
570static css_error node_count_siblings(
void *pw,
void *n,
571 bool same_name,
bool after, int32_t *count)
582 assert(lwc_string_caseless_isequal(
597 assert(lwc_string_caseless_isequal(
616static css_error node_is_empty(
void *pw,
void *n,
bool *match)
626static css_error node_is_link(
void *pw,
void *n,
bool *match)
638static css_error node_is_visited(
void *pw,
void *n,
bool *match)
650static css_error node_is_hover(
void *pw,
void *n,
bool *match)
662static css_error node_is_active(
void *pw,
void *n,
bool *match)
674static css_error node_is_focus(
void *pw,
void *n,
bool *match)
686static css_error node_is_enabled(
void *pw,
void *n,
bool *match)
698static css_error node_is_disabled(
void *pw,
void *n,
bool *match)
710static css_error node_is_checked(
void *pw,
void *n,
bool *match)
722static css_error node_is_target(
void *pw,
void *n,
bool *match)
734static css_error node_is_lang(
void *pw,
void *n,
749static css_error node_presentational_hint(
void *pw,
void *
node,
761static css_error ua_default_for_property(
void *pw, uint32_t property,
css_hint *hint)
786static css_error set_libcss_node_data(
void *pw,
void *n,
787 void *libcss_node_data)
797static css_error get_libcss_node_data(
void *pw,
void *n,
798 void **libcss_node_data)
823 named_generic_sibling_node,
830 node_has_attribute_equal,
831 node_has_attribute_dashmatch,
832 node_has_attribute_includes,
833 node_has_attribute_prefix,
834 node_has_attribute_suffix,
835 node_has_attribute_substring,
849 node_presentational_hint,
850 ua_default_for_property,
852 set_libcss_node_data,
853 get_libcss_node_data,
857 const char *base, lwc_string *rel, lwc_string **abs)
863 *abs = lwc_string_ref(rel);
868static bool fail_because_lwc_leaked =
false;
871printing_lwc_iterator(lwc_string *str,
void *pw)
875 printf(
" DICT: %*s\n", (
int)(lwc_string_length(str)), lwc_string_data(str));
876 fail_because_lwc_leaked =
true;
879static css_error css_font_resolution_func(
void *pw, lwc_string *name,
884 if (system_font == NULL) {
890 if (strncmp(lwc_string_data(name),
"special-system-font",
891 lwc_string_length(name)) != 0) {
902 err = lwc_intern_string(
"special-system-font",
903 strlen(
"special-system-font"),
905 if (err != lwc_error_ok) {
912static void css__parse_sheet(
line_ctx *ctx,
const char *data,
size_t len)
916 const char *end = data + len;
925 for (p = data; p < end; p++) {
930 if (p - data == 6 && strncasecmp(data,
"author", 6) == 0)
932 else if (p - data == 4 && strncasecmp(data,
"user", 4) == 0)
934 else if (p - data == 2 && strncasecmp(data,
"ua", 2) == 0)
937 assert(0 &&
"Unknown stylesheet origin");
940 while (p < end && isspace(*p))
944 media = malloc(end - p + 1);
946 memcpy(media, p, end - p);
947 media[end - p] =
'\0';
953 params.
title =
"foo";
962 params.
font = css_font_resolution_func;
969 temp = realloc(ctx->
sheets,
982static void css__parse_media_list(
const char **data,
size_t *len,
css_media *media)
984 const char *p = *data;
985 const char *end = p + *len;
991 const char *start = p;
994 while (isspace(*p) ==
false && *p !=
',')
997 if (p - start == 10 &&
998 strncasecmp(start,
"projection", 10) == 0)
1000 else if (p - start == 8 &&
1001 strncasecmp(start,
"handheld", 8) == 0)
1003 else if (p - start == 8 &&
1004 strncasecmp(start,
"embossed", 8) == 0)
1006 else if (p - start == 7 &&
1007 strncasecmp(start,
"braille", 7) == 0)
1009 else if (p - start == 6 &&
1010 strncasecmp(start,
"speech", 6) == 0)
1012 else if (p - start == 6 &&
1013 strncasecmp(start,
"screen", 6) == 0)
1015 else if (p - start == 5 &&
1016 strncasecmp(start,
"print", 5) == 0)
1018 else if (p - start == 5 &&
1019 strncasecmp(start,
"aural", 5) == 0)
1021 else if (p - start == 3 &&
1022 strncasecmp(start,
"tty", 3) == 0)
1024 else if (p - start == 3 &&
1025 strncasecmp(start,
"all", 3) == 0)
1027 else if (p - start == 2 &&
1028 strncasecmp(start,
"tv", 2) == 0)
1031 assert(0 &&
"Unknown media type");
1034 while (p < end && isspace(*p))
1038 if (p == end || *p !=
',')
1045 while (p < end && isspace(*p))
1049 media->
type = result;
1055static void css__parse_pseudo_list(
const char **data,
size_t *len, uint32_t *element)
1057 const char *p = *data;
1058 const char *end = p + *len;
1065 const char *start = p;
1068 while (isspace(*p) ==
false && *p !=
',')
1072 if (p - start == 12 &&
1073 strncasecmp(start,
"first-letter", 12) == 0)
1075 else if (p - start == 10 &&
1076 strncasecmp(start,
"first-line", 10) == 0)
1078 else if (p - start == 6 &&
1079 strncasecmp(start,
"before", 6) == 0)
1081 else if (p - start == 5 &&
1082 strncasecmp(start,
"after", 5) == 0)
1085 assert(0 &&
"Unknown pseudo");
1088 while (p < end && isspace(*p))
1092 if (p == end || *p !=
',')
1099 while (p < end && isspace(*p))
1107static void css__parse_tree(
line_ctx *ctx,
const char *data,
size_t len)
1109 const char *p = data;
1110 const char *end = data + len;
1119 while (p < end && isspace(*p))
1125 css__parse_media_list(&p, &left, &ctx->
media);
1137static void css__parse_expected(
line_ctx *ctx,
const char *data,
size_t len)
1140 size_t required = ctx->
explen == 0 ? 64 : ctx->
explen * 2;
1141 char *temp = realloc(ctx->
exp, required);
1143 assert(0 &&
"No memory for expected output");
1155static void css__parse_tree_data(
line_ctx *ctx,
const char *data,
size_t len)
1157 const char *p = data;
1158 const char *end = data + len;
1159 const char *name = NULL;
1160 const char *value = NULL;
1162 size_t valuelen = 0;
1164 bool target =
false;
1172 while (p < end && isspace(*p)) {
1180 while (p < end && *p !=
'=' && *p !=
'*' && isspace(*p) ==
false) {
1186 while (p < end && isspace(*p))
1189 if (p < end && *p ==
'=') {
1195 while (p < end && isspace(*p) ==
false) {
1199 }
else if (p < end && *p ==
'*') {
1204 if (value == NULL) {
1209 memset(n, 0,
sizeof(
node));
1211 lwc_intern_string(name, namelen, &n->
name);
1214 if (ctx->
tree == NULL) {
1218 assert(depth <= ctx->depth + 1);
1221 while (depth <= ctx->depth) {
1247 bool amatch =
false;
1259 lwc_intern_string(name, namelen, &attr->
name);
1260 lwc_intern_string(value, valuelen, &attr->
value);
1262 assert(lwc_string_caseless_isequal(
1265 if (amatch ==
true) {
1266 n->
classes = realloc(NULL,
sizeof(lwc_string **));
1269 n->
classes[0] = lwc_string_ref(
1282 char *buf,
size_t *buflen)
1285 struct node *n = NULL;
1293 &select_handler, ctx, &
sr) ==
CSS_OK);
1310 buf, buflen, &unit_ctx);
1318 run_test_select_tree(select, n, ctx, buf, buflen);
1322static void show_differences(
size_t len,
const char *exp,
const char *res)
1324 const char *pos_exp, *opos_exp;
1325 const char *pos_res, *opos_res;
1327 opos_exp = pos_exp = exp;
1328 opos_res = pos_res = res;
1330 printf(
"Line differences:\n");
1331 while (pos_exp < exp + len && pos_res < res + len) {
1332 if (*pos_exp ==
'\n' && *pos_res ==
'\n') {
1333 if (pos_exp - opos_exp != pos_res - opos_res ||
1334 memcmp(opos_exp, opos_res,
1335 pos_exp - opos_exp) != 0) {
1336 printf(
"Expected:\t%.*s\n",
1337 (
int)(pos_exp - opos_exp),
1339 printf(
" Result:\t%.*s\n",
1340 (
int)(pos_res - opos_res),
1344 opos_exp = ++pos_exp;
1345 opos_res = ++pos_res;
1346 }
else if (*pos_exp ==
'\n') {
1348 }
else if (*pos_res ==
'\n') {
1357static void destroy_tree(
node *root)
1362 for (n = root->
children; n != NULL; n = p) {
1370 for (i = 0; i < root->
n_attrs; ++i) {
1378 lwc_string_unref(root->
classes[i]);
1388 lwc_string_unref(root->
name);
1392static void run_test(
line_ctx *ctx,
const char *exp,
size_t explen)
1405 assert(0 &&
"No memory for result data");
1411 for (i = 0; i < ctx->
n_sheets; i++) {
1419 run_test_select_tree(select, ctx->
tree, ctx, buf, &buflen);
1424 if (8192 - buflen != explen || memcmp(buf, exp, explen) != 0) {
1425 size_t len = 8192 - buflen < explen ? 8192 - buflen : explen;
1426 printf(
"Expected (%u):\n%.*s\n",
1427 (
int) explen, (
int) explen, exp);
1428 printf(
"Result (%u):\n%.*s\n", (
int) (8192 - buflen),
1429 (
int) (8192 - buflen), buf);
1431 show_differences(len, exp, buf);
1432 assert(0 &&
"Result doesn't match expected");
1437 destroy_tree(ctx->
tree);
1439 for (i = 0; i < ctx->
n_sheets; i++) {
1454 printf(
"Test %d: PASS\n", testnum);
1457static bool handle_line(
const char *data,
size_t datalen,
void *pw)
1462 if (data[0] ==
'#') {
1464 if (strncasecmp(data+1,
"errors", 6) == 0) {
1471 css__parse_sheet(ctx, data + 1, datalen - 1);
1479 if (strncasecmp(data+1,
"errors", 6) == 0) {
1488 }
else if (strncasecmp(data+1,
"ua", 2) == 0 ||
1489 strncasecmp(data+1,
"user", 4) == 0 ||
1490 strncasecmp(data+1,
"author", 6) == 0) {
1495 css__parse_sheet(ctx, data + 1, datalen - 1);
1499 (
const uint8_t *) data,
1509 }
else if (ctx->
inexp) {
1521 if (strncasecmp(data+1,
"tree", 4) == 0) {
1522 css__parse_tree(ctx, data + 5, datalen - 5);
1533 css__parse_tree_data(ctx, data + 1, datalen - 1);
1537 (
const uint8_t *) data, datalen);
1539 }
else if (ctx->
inexp) {
1540 css__parse_expected(ctx, data, datalen);
1552 printf(
"Usage: %s <filename>\n", argv[0]);
1556 memset(&ctx, 0,
sizeof(ctx));
1560 lwc_intern_string(
"id",
SLEN(
"id"), &ctx.
attr_id);
1565 if (ctx.
tree != NULL)
1571 lwc_string_unref(ctx.
attr_id);
1573 lwc_iterate_strings(printing_lwc_iterator, NULL);
1575 assert(fail_because_lwc_leaked ==
false);
css_error
Definition errors.h:18
@ CSS_INVALID
Definition errors.h:23
@ CSS_NOMEM
Definition errors.h:21
@ CSS_BADPARM
Definition errors.h:22
@ CSS_NEEDDATA
Definition errors.h:25
@ CSS_OK
Definition errors.h:19
#define UNUSED(x)
Definition example1.c:18
#define INTTOFIX(a)
Definition fpmath.h:127
#define CSS_RADIX_POINT
Definition fpmath.h:20
css_error css_computed_style_destroy(css_computed_style *style)
Definition computed.c:101
css_error css_computed_style_compose(const css_computed_style *restrict parent, const css_computed_style *restrict child, const css_unit_ctx *unit_ctx, css_computed_style **restrict result)
Definition computed.c:290
@ CSS_FONT_STYLE_NORMAL
Definition properties.h:526
@ CSS_FONT_WEIGHT_NORMAL
Definition properties.h:539
@ CSS_PROP_VOICE_FAMILY
Definition properties.h:109
@ CSS_PROP_FONT_FAMILY
Definition properties.h:53
@ CSS_PROP_COLOR
Definition properties.h:41
@ CSS_PROP_QUOTES
Definition properties.h:91
@ CSS_FONT_FAMILY_SANS_SERIF
Definition properties.h:504
@ CSS_FONT_VARIANT_NORMAL
Definition properties.h:533
@ CSS_COLOR_COLOR
Definition properties.h:316
@ CSS_QUOTES_NONE
Definition properties.h:781
css_error css_select_results_destroy(css_select_results *results)
Definition select.c:1535
css_error css_select_style(css_select_ctx *ctx, void *node, const css_unit_ctx *unit_ctx, const css_media *media, const css_stylesheet *inline_style, css_select_handler *handler, void *pw, css_select_results **result)
Definition select.c:1255
css_error css_select_ctx_destroy(css_select_ctx *ctx)
Definition select.c:276
css_error css_libcss_node_data_handler(css_select_handler *handler, css_node_data_action action, void *pw, void *node, void *clone_node, void *libcss_node_data)
Definition select.c:184
@ CSS_SELECT_HANDLER_VERSION_1
Definition select.h:48
css_error css_select_ctx_append_sheet(css_select_ctx *ctx, const css_stylesheet *sheet, css_origin origin, const char *media)
Definition select.c:309
@ CSS_NODE_DELETED
Definition select.h:165
@ CSS_PSEUDO_ELEMENT_AFTER
Definition select.h:28
@ CSS_PSEUDO_ELEMENT_BEFORE
Definition select.h:27
@ CSS_PSEUDO_ELEMENT_NONE
Definition select.h:24
@ CSS_PSEUDO_ELEMENT_FIRST_LINE
Definition select.h:25
@ CSS_PSEUDO_ELEMENT_FIRST_LETTER
Definition select.h:26
css_error css_select_ctx_create(css_select_ctx **result)
Definition select.c:240
css_error css_stylesheet_data_done(css_stylesheet *sheet)
Definition stylesheet.c:334
@ CSS_STYLESHEET_PARAMS_VERSION_1
Definition stylesheet.h:92
css_error css_stylesheet_append_data(css_stylesheet *sheet, const uint8_t *data, size_t len)
Definition stylesheet.c:314
css_error css_stylesheet_destroy(css_stylesheet *sheet)
Definition stylesheet.c:255
css_error css_stylesheet_create(const css_stylesheet_params *params, css_stylesheet **stylesheet)
Definition stylesheet.c:128
lwc_string * value
Definition select.c:20
lwc_string * name
Definition select.c:19
Definition autogenerated_computed.h:282
uint8_t status
Definition hint.h:53
lwc_string ** strings
Definition hint.h:49
css_color color
Definition hint.h:38
lwc_string * name
Definition types.h:259
css_computed_style * styles[CSS_PSEUDO_ELEMENT_COUNT]
Definition select.h:44
Definition stylesheet.h:98
const char * url
Definition stylesheet.h:108
css_font_resolution_fn font
Definition stylesheet.h:133
css_color_resolution_fn color
Definition stylesheet.h:128
const char * charset
Definition stylesheet.h:106
bool allow_quirks
Definition stylesheet.h:113
void * import_pw
Definition stylesheet.h:125
void * color_pw
Definition stylesheet.h:130
const char * title
Definition stylesheet.h:110
css_import_notification_fn import
Definition stylesheet.h:123
void * resolve_pw
Definition stylesheet.h:120
uint32_t params_version
Definition stylesheet.h:100
css_url_resolution_fn resolve
Definition stylesheet.h:118
void * font_pw
Definition stylesheet.h:135
css_language_level level
Definition stylesheet.h:103
bool inline_style
Definition stylesheet.h:115
Definition stylesheet.h:170
Definition stylesheet.h:63
enum css_font_style_e style
Definition stylesheet.h:64
struct css_system_font::@6 line_height
enum css_font_weight_e weight
Definition stylesheet.h:66
css_unit unit
Definition stylesheet.h:69
css_fixed size
Definition stylesheet.h:68
lwc_string * family
Definition stylesheet.h:76
enum css_font_variant_e variant
Definition stylesheet.h:65
css_fixed font_size_default
Definition unit.h:53
const css_computed_style * root_style
Definition unit.h:67
css_media media
Definition select.c:65
node * current
Definition select.c:59
lwc_string * attr_class
Definition select.c:69
exp_entry * exp
Definition lex-auto.c:32
size_t explen
Definition lex-auto.c:30
bool inexp
Definition lex-auto.c:36
bool inerrors
Definition parse-auto.c:42
bool intree
Definition select.c:53
lwc_string * attr_id
Definition select.c:70
bool insheet
Definition select.c:54
uint32_t depth
Definition select.c:60
node * target
Definition select.c:67
uint32_t pseudo_element
Definition select.c:66
uint32_t n_sheets
Definition select.c:62
size_t expused
Definition lex-auto.c:31
node * tree
Definition select.c:58
sheet_ctx * sheets
Definition select.c:63
struct node * parent
Definition select.c:35
struct node * children
Definition select.c:38
attribute * attrs
Definition select.c:30
struct node * prev
Definition select.c:37
uint32_t n_attrs
Definition select.c:29
css_select_results * sr
Definition select.c:32
lwc_string ** classes
Definition select.c:27
struct node * next
Definition select.c:36
lwc_string * name
Definition select.c:24
void * libcss_node_data
Definition select.c:33
uint32_t n_classes
Definition select.c:26
struct node * last_child
Definition select.c:39
char * media
Definition select.c:45
css_origin origin
Definition select.c:44
css_stylesheet * sheet
Definition select.c:43
int main(int argc, char **argv)
Definition select.c:1547
#define assert(expr)
Definition testutils.h:32
bool css__parse_testfile(const char *filename, line_func callback, void *pw)
Definition testutils.h:51
@ CSS_LEVEL_21
Definition types.h:43
@ CSS_UNIT_EM
Definition types.h:85
@ CSS_UNIT_PT
Definition types.h:89
css_origin
Definition types.h:72
@ CSS_ORIGIN_USER
Definition types.h:74
@ CSS_ORIGIN_UA
Definition types.h:73
@ CSS_ORIGIN_AUTHOR
Definition types.h:75
@ CSS_MEDIA_BRAILLE
Definition types.h:53
@ CSS_MEDIA_TTY
Definition types.h:60
@ CSS_MEDIA_EMBOSSED
Definition types.h:54
@ CSS_MEDIA_SCREEN
Definition types.h:58
@ CSS_MEDIA_TV
Definition types.h:61
@ CSS_MEDIA_ALL
Definition types.h:62
@ CSS_MEDIA_PRINT
Definition types.h:56
@ CSS_MEDIA_HANDHELD
Definition types.h:55
@ CSS_MEDIA_PROJECTION
Definition types.h:57
@ CSS_MEDIA_AURAL
Definition types.h:52
@ CSS_MEDIA_SPEECH
Definition types.h:59
#define SLEN(s)
Definition utils.h:26