summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/css21.c29
-rw-r--r--test/dump.h106
-rw-r--r--test/dump_computed.h6
-rw-r--r--test/number.c19
-rw-r--r--test/parse-auto.c49
-rw-r--r--test/parse.c14
-rw-r--r--test/parse2-auto.c10
-rw-r--r--test/select-auto.c287
8 files changed, 279 insertions, 241 deletions
diff --git a/test/css21.c b/test/css21.c
index 47558bc..93200f5 100644
--- a/test/css21.c
+++ b/test/css21.c
@@ -11,8 +11,6 @@
#define DUMP_HASH (1)
#define DUMP_CSS (1)
-extern void parserutils_hash_dump(parserutils_hash *hash);
-
static void *myrealloc(void *ptr, size_t len, void *pw)
{
UNUSED(pw);
@@ -28,6 +26,7 @@ int main(int argc, char **argv)
#define CHUNK_SIZE (4096)
uint8_t buf[CHUNK_SIZE];
css_error error;
+ lwc_context *ctx;
if (argc != 3) {
printf("Usage: %s <aliases_file> <filename>\n", argv[0]);
@@ -36,11 +35,15 @@ int main(int argc, char **argv)
/* Initialise library */
assert(css_initialise(argv[1], myrealloc, NULL) == CSS_OK);
-
+
+ assert(lwc_create_context(myrealloc, NULL, &ctx) == lwc_error_ok);
+
+ lwc_context_ref(ctx); /* Transform weak ref to a strong ref */
+
for (int count = 0; count < ITERATIONS; count++) {
assert(css_stylesheet_create(CSS_LEVEL_21, "UTF-8", argv[2],
- NULL, CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL,
+ NULL, CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL, ctx,
myrealloc, NULL, &sheet) == CSS_OK);
fp = fopen(argv[2], "rb");
@@ -78,7 +81,7 @@ int main(int argc, char **argv)
assert(error == CSS_OK || error == CSS_IMPORTS_PENDING);
while (error == CSS_IMPORTS_PENDING) {
- css_string url;
+ lwc_string *url;
uint64_t media;
error = css_stylesheet_next_pending_import(sheet,
@@ -87,14 +90,14 @@ int main(int argc, char **argv)
if (error == CSS_OK) {
css_stylesheet *import;
- char buf[url.len + 1];
+ char buf[lwc_string_length(url) + 1];
- memcpy(buf, url.data, url.len);
- buf[url.len] = '\0';
+ memcpy(buf, lwc_string_data(url), lwc_string_length(url));
+ buf[lwc_string_length(url)] = '\0';
assert(css_stylesheet_create(CSS_LEVEL_21,
"UTF-8", buf, NULL, CSS_ORIGIN_AUTHOR,
- media, myrealloc, NULL, &import) ==
+ media, ctx, myrealloc, NULL, &import) ==
CSS_OK);
assert(css_stylesheet_data_done(import) ==
@@ -107,10 +110,6 @@ int main(int argc, char **argv)
}
}
-#if DUMP_HASH
- parserutils_hash_dump(sheet->dictionary);
-#endif
-
#if DUMP_CSS
char *out;
size_t outlen = origlen * 2;
@@ -127,7 +126,9 @@ int main(int argc, char **argv)
assert(css_finalise(myrealloc, NULL) == CSS_OK);
printf("PASS\n");
-
+
+ lwc_context_unref(ctx);
+
return 0;
}
diff --git a/test/dump.h b/test/dump.h
index 69689c3..ac780a9 100644
--- a/test/dump.h
+++ b/test/dump.h
@@ -19,7 +19,7 @@ static void dump_selector_list(css_selector *list, char **ptr);
static void dump_selector(css_selector *selector, char **ptr);
static void dump_selector_detail(css_selector_detail *detail, char **ptr);
static void dump_bytecode(css_style *style, char **ptr);
-static void dump_string(const parserutils_hash_entry *string, char **ptr);
+static void dump_string(lwc_string *string, char **ptr);
void dump_sheet(css_stylesheet *sheet, char *buf, size_t *buflen)
{
@@ -89,7 +89,7 @@ void dump_rule_import(css_rule_import *s, char **buf, size_t *buflen)
char *ptr = *buf;
ptr += sprintf(ptr, "| @import url(\"%.*s\")",
- (int) s->url->len, (const char *) s->url->data);
+ (int) lwc_string_length(s->url), lwc_string_data(s->url));
/** \todo media list */
@@ -144,11 +144,12 @@ void dump_selector_detail(css_selector_detail *detail, char **ptr)
{
switch (detail->type) {
case CSS_SELECTOR_ELEMENT:
- if (detail->name->len == 1 && detail->name->data[0] == '*' &&
+ if (lwc_string_length(detail->name) == 1 &&
+ lwc_string_data(detail->name)[0] == '*' &&
detail->next == 0) {
dump_string(detail->name, ptr);
- } else if (detail->name->len != 1 ||
- detail->name->data[0] != '*') {
+ } else if (lwc_string_length(detail->name) != 1 ||
+ lwc_string_data(detail->name)[0] != '*') {
dump_string(detail->name, ptr);
}
break;
@@ -448,11 +449,11 @@ static void dump_unit(css_fixed val, uint32_t unit, char **ptr)
}
}
-static void dump_counter(const parserutils_hash_entry *name, uint32_t value,
+static void dump_counter(lwc_string *name, uint32_t value,
char **ptr)
{
- *ptr += sprintf(*ptr,
- "counter(%.*s", (int) name->len, (char *) name->data);
+ *ptr += sprintf(*ptr, "counter(%.*s",
+ (int) lwc_string_length(name), lwc_string_data(name));
value >>= CONTENT_COUNTER_STYLE_SHIFT;
@@ -506,13 +507,14 @@ static void dump_counter(const parserutils_hash_entry *name, uint32_t value,
*ptr += sprintf(*ptr, ")");
}
-static void dump_counters(const parserutils_hash_entry *name,
- const parserutils_hash_entry *separator,
+static void dump_counters(lwc_string *name, lwc_string *separator,
uint32_t value, char **ptr)
{
*ptr += sprintf(*ptr, "counter(%.*s, %.*s",
- (int) name->len, (char *) name->data,
- (int) separator->len, (char *) separator->data);
+ (int) lwc_string_length(name),
+ lwc_string_data(name),
+ (int) lwc_string_length(separator),
+ lwc_string_data(separator));
value >>= CONTENT_COUNTER_STYLE_SHIFT;
@@ -696,13 +698,13 @@ void dump_bytecode(css_style *style, char **ptr)
break;
case BACKGROUND_IMAGE_URI:
{
- parserutils_hash_entry *he =
- *((parserutils_hash_entry **)
+ lwc_string *he =
+ *((lwc_string **)
bytecode);
ADVANCE(sizeof(he));
*ptr += sprintf(*ptr, "url('%.*s')",
- (int) he->len,
- (char *) he->data);
+ (int) lwc_string_length(he),
+ lwc_string_data(he));
}
break;
}
@@ -1032,8 +1034,8 @@ void dump_bytecode(css_style *style, char **ptr)
}
while (value != CONTENT_NORMAL) {
- parserutils_hash_entry *he =
- *((parserutils_hash_entry **)
+ lwc_string *he =
+ *((lwc_string **)
bytecode);
const char *end = "";
@@ -1044,11 +1046,11 @@ void dump_bytecode(css_style *style, char **ptr)
break;
case CONTENT_COUNTERS:
{
- parserutils_hash_entry *sep;
+ lwc_string *sep;
ADVANCE(sizeof(he));
- sep = *((parserutils_hash_entry **) bytecode);
+ sep = *((lwc_string **) bytecode);
ADVANCE(sizeof(sep));
dump_counters(he, sep, value,
@@ -1068,8 +1070,8 @@ void dump_bytecode(css_style *style, char **ptr)
ADVANCE(sizeof(he));
*ptr += sprintf(*ptr, "'%.*s'%s",
- (int) he->len,
- (char *) he->data,
+ (int) lwc_string_length(he),
+ lwc_string_data(he),
end);
break;
case CONTENT_OPEN_QUOTE:
@@ -1103,13 +1105,13 @@ void dump_bytecode(css_style *style, char **ptr)
switch (value) {
case COUNTER_INCREMENT_NAMED:
while (value != COUNTER_INCREMENT_NONE) {
- parserutils_hash_entry *he =
- *((parserutils_hash_entry **)
+ lwc_string *he =
+ *((lwc_string **)
bytecode);
ADVANCE(sizeof(he));
*ptr += sprintf(*ptr, "%.*s ",
- (int) he->len,
- (char *) he->data);
+ (int)lwc_string_length(he),
+ lwc_string_data(he));
css_fixed val =
*((css_fixed *) bytecode);
ADVANCE(sizeof(val));
@@ -1131,13 +1133,13 @@ void dump_bytecode(css_style *style, char **ptr)
break;
case OP_CURSOR:
while (value == CURSOR_URI) {
- parserutils_hash_entry *he =
- *((parserutils_hash_entry **)
+ lwc_string *he =
+ *((lwc_string **)
bytecode);
ADVANCE(sizeof(ptr));
*ptr += sprintf(*ptr, "url('%.*s'), ",
- (int) he->len,
- (char *) he->data);
+ (int) lwc_string_length(he),
+ lwc_string_data(he));
value = *((uint32_t *) bytecode);
ADVANCE(sizeof(value));
@@ -1317,13 +1319,13 @@ void dump_bytecode(css_style *style, char **ptr)
case FONT_FAMILY_STRING:
case FONT_FAMILY_IDENT_LIST:
{
- parserutils_hash_entry *he =
- *((parserutils_hash_entry **)
+ lwc_string *he =
+ *((lwc_string **)
bytecode);
ADVANCE(sizeof(he));
*ptr += sprintf(*ptr, "'%.*s'",
- (int) he->len,
- (char *) he->data);
+ (int) lwc_string_length(he),
+ lwc_string_data(he));
}
break;
case FONT_FAMILY_SERIF:
@@ -1736,13 +1738,13 @@ void dump_bytecode(css_style *style, char **ptr)
switch (value) {
case PLAY_DURING_URI:
{
- parserutils_hash_entry *he =
- *((parserutils_hash_entry **)
+ lwc_string *he =
+ *((lwc_string **)
bytecode);
ADVANCE(sizeof(he));
*ptr += sprintf(*ptr, "'%.*s'",
- (int) he->len,
- (char *) he->data);
+ (int) lwc_string_length(he),
+ lwc_string_data(he));
}
break;
case PLAY_DURING_AUTO:
@@ -1778,21 +1780,21 @@ void dump_bytecode(css_style *style, char **ptr)
switch (value) {
case QUOTES_STRING:
while (value != QUOTES_NONE) {
- parserutils_hash_entry *he =
- *((parserutils_hash_entry **)
+ lwc_string *he =
+ *((lwc_string **)
bytecode);
ADVANCE(sizeof(he));
*ptr += sprintf(*ptr, " '%.*s' ",
- (int) he->len,
- (char *) he->data);
+ (int) lwc_string_length(he),
+ lwc_string_data(he));
he =
- *((parserutils_hash_entry **)
+ *((lwc_string **)
bytecode);
ADVANCE(sizeof(he));
*ptr += sprintf(*ptr, " '%.*s' ",
- (int) he->len,
- (char *) he->data);
+ (int) lwc_string_length(he),
+ lwc_string_data(he));
value = *((uint32_t *) bytecode);
ADVANCE(sizeof(value));
@@ -2003,13 +2005,13 @@ void dump_bytecode(css_style *style, char **ptr)
case VOICE_FAMILY_STRING:
case VOICE_FAMILY_IDENT_LIST:
{
- parserutils_hash_entry *he =
- *((parserutils_hash_entry **)
+ lwc_string *he =
+ *((lwc_string **)
bytecode);
ADVANCE(sizeof(he));
*ptr += sprintf(*ptr, "'%.*s'",
- (int) he->len,
- (char *) he->data);
+ (int) lwc_string_length(he),
+ lwc_string_data(he));
}
break;
case VOICE_FAMILY_MALE:
@@ -2118,9 +2120,11 @@ void dump_bytecode(css_style *style, char **ptr)
}
-void dump_string(const parserutils_hash_entry *string, char **ptr)
+void dump_string(lwc_string *string, char **ptr)
{
- *ptr += sprintf(*ptr, "%.*s", (int) string->len, string->data);
+ *ptr += sprintf(*ptr, "%.*s",
+ (int) lwc_string_length(string),
+ lwc_string_data(string));
}
#endif
diff --git a/test/dump_computed.h b/test/dump_computed.h
index 690f6c0..7622394 100644
--- a/test/dump_computed.h
+++ b/test/dump_computed.h
@@ -142,7 +142,7 @@ static void dump_computed_style(const css_computed_style *style, char *buf,
size_t wrote = 0;
uint8_t val;
css_color color;
- const css_string *url;
+ lwc_string *url;
css_fixed len1, len2;
css_unit unit1, unit2;
@@ -180,9 +180,9 @@ static void dump_computed_style(const css_computed_style *style, char *buf,
/* background-image */
val = css_computed_background_image(style, &url);
- if (val == CSS_BACKGROUND_IMAGE_IMAGE && url->data != NULL) {
+ if (val == CSS_BACKGROUND_IMAGE_IMAGE && url != NULL) {
wrote = snprintf(ptr, *len, "background-image: url('%.*s')\n",
- (int) url->len, url->data);
+ (int) lwc_string_length(url), lwc_string_data(url));
} else if (val == CSS_BACKGROUND_IMAGE_NONE) {
wrote = snprintf(ptr, *len, "background-image: none\n");
} else {
diff --git a/test/number.c b/test/number.c
index 0140ce9..7bb57c3 100644
--- a/test/number.c
+++ b/test/number.c
@@ -8,6 +8,13 @@
#include "testutils.h"
+static void *myrealloc(void *ptr, size_t len, void *pw)
+{
+ UNUSED(pw);
+
+ return realloc(ptr, len);
+}
+
typedef struct line_ctx {
size_t buflen;
size_t bufused;
@@ -110,21 +117,27 @@ bool handle_line(const char *data, size_t datalen, void *pw)
void run_test(const uint8_t *data, size_t len, const char *exp, size_t explen)
{
- css_string in = { len, (uint8_t *) data };
+ lwc_string *in;
+ lwc_context *ctx;
size_t consumed;
css_fixed result;
char buf[256];
UNUSED(exp);
UNUSED(explen);
-
- result = number_from_css_string(&in, false, &consumed);
+
+ assert(lwc_create_context(myrealloc, NULL, &ctx) == lwc_error_ok);
+ lwc_context_ref(ctx);
+ assert(lwc_context_intern(ctx, (const char *)data, len, &in) == lwc_error_ok);
+
+ result = number_from_lwc_string(in, false, &consumed);
print_css_fixed(buf, sizeof(buf), result);
printf("got: %s expected: %.*s\n", buf, (int) explen, exp);
assert(strncmp(buf, exp, explen) == 0);
+ lwc_context_unref(ctx);
}
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 4c42359..5ed0f55 100644
--- a/test/parse-auto.c
+++ b/test/parse-auto.c
@@ -59,7 +59,7 @@ static void validate_rule_import(css_rule_import *s, exp_entry *e,
static void dump_selector_list(css_selector *list, char **ptr);
static void dump_selector(css_selector *selector, char **ptr);
static void dump_selector_detail(css_selector_detail *detail, char **ptr);
-static void dump_string(const parserutils_hash_entry *string, char **ptr);
+static void dump_string(lwc_string *string, char **ptr);
static void *myrealloc(void *data, size_t len, void *pw)
{
@@ -306,9 +306,13 @@ 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;
-
+ lwc_context *ctx;
+
+ assert(lwc_create_context(myrealloc, NULL, &ctx) == lwc_error_ok);
+ lwc_context_ref(ctx);
+
assert(css_stylesheet_create(CSS_LEVEL_21, "UTF-8", "foo", NULL,
- CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL,
+ CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL, ctx,
myrealloc, NULL, &sheet) == CSS_OK);
error = css_stylesheet_append_data(sheet, data, len);
@@ -321,7 +325,7 @@ void run_test(const uint8_t *data, size_t len, exp_entry *exp, size_t explen)
assert(error == CSS_OK || error == CSS_IMPORTS_PENDING);
while (error == CSS_IMPORTS_PENDING) {
- css_string url;
+ lwc_string *url;
uint64_t media;
error = css_stylesheet_next_pending_import(sheet,
@@ -330,14 +334,14 @@ 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[url.len + 1];
+ char buf[lwc_string_length(url) + 1];
- memcpy(buf, url.data, url.len);
- buf[url.len] = '\0';
+ memcpy(buf, lwc_string_data(url), lwc_string_length(url));
+ buf[lwc_string_length(url)] = '\0';
assert(css_stylesheet_create(CSS_LEVEL_21,
"UTF-8", buf, NULL, CSS_ORIGIN_AUTHOR,
- media, myrealloc, NULL, &import) ==
+ media, ctx, myrealloc, NULL, &import) ==
CSS_OK);
assert(css_stylesheet_register_import(sheet,
@@ -388,6 +392,7 @@ void run_test(const uint8_t *data, size_t len, exp_entry *exp, size_t explen)
css_stylesheet_destroy(sheet);
printf("Test %d: PASS\n", testnum);
+ lwc_context_unref(ctx);
}
void validate_rule_selector(css_rule_selector *s, exp_entry *e, int testnum)
@@ -438,18 +443,18 @@ void validate_rule_selector(css_rule_selector *s, exp_entry *e, int testnum)
}
if (j != e->stused) {
- const parserutils_hash_entry **p =
+ lwc_string **p =
(void *) ((uint8_t *)
s->style->bytecode + i);
- if ((*p)->len !=
+ if (lwc_string_length(*p) !=
strlen(e->stringtab[j].string) ||
- memcmp((*p)->data,
+ memcmp(lwc_string_data(*p),
e->stringtab[j].string,
- (*p)->len) != 0) {
+ lwc_string_length(*p)) != 0) {
printf("%d: Got string '%.*s'. Expected '%s'\n",
- testnum, (int) (*p)->len,
- (char *) (*p)->data,
+ testnum, (int) lwc_string_length(*p),
+ lwc_string_data(*p),
e->stringtab[j].string);
assert(0 && "Strings differ");
}
@@ -488,10 +493,10 @@ void validate_rule_charset(css_rule_charset *s, exp_entry *e, int testnum)
void validate_rule_import(css_rule_import *s, exp_entry *e, int testnum)
{
- if (strncmp((const char *) s->url->data, e->name,
- (int) s->url->len) != 0) {
+ if (strncmp(lwc_string_data(s->url), e->name,
+ lwc_string_length(s->url)) != 0) {
printf("%d: Got URL '%.*s'. Expected '%s'\n",
- testnum, (int) s->url->len, (const char *) s->url->data,
+ testnum, (int) lwc_string_length(s->url), lwc_string_data(s->url),
e->name);
assert(0 && "Mismatched URLs");
}
@@ -542,11 +547,11 @@ void dump_selector_detail(css_selector_detail *detail, char **ptr)
{
switch (detail->type) {
case CSS_SELECTOR_ELEMENT:
- if (detail->name->len == 1 && detail->name->data[0] == '*' &&
+ if (lwc_string_length(detail->name) == 1 && lwc_string_data(detail->name)[0] == '*' &&
detail->next == 0) {
dump_string(detail->name, ptr);
- } else if (detail->name->len != 1 ||
- detail->name->data[0] != '*') {
+ } else if (lwc_string_length(detail->name) != 1 ||
+ lwc_string_data(detail->name)[0] != '*') {
dump_string(detail->name, ptr);
}
break;
@@ -621,8 +626,8 @@ void dump_selector_detail(css_selector_detail *detail, char **ptr)
}
}
-void dump_string(const parserutils_hash_entry *string, char **ptr)
+void dump_string(lwc_string *string, char **ptr)
{
- *ptr += sprintf(*ptr, "%.*s", (int) string->len, string->data);
+ *ptr += sprintf(*ptr, "%.*s", (int) lwc_string_length(string), lwc_string_data(string));
}
diff --git a/test/parse.c b/test/parse.c
index cd1d701..ed0deb7 100644
--- a/test/parse.c
+++ b/test/parse.c
@@ -76,13 +76,13 @@ static css_error event_handler(css_parser_event type,
int main(int argc, char **argv)
{
css_parser_optparams params;
- parserutils_hash *dict;
css_parser *parser;
FILE *fp;
size_t len, origlen;
#define CHUNK_SIZE (4096)
uint8_t buf[CHUNK_SIZE];
css_error error;
+ lwc_context *ctx;
if (argc != 3) {
printf("Usage: %s <aliases_file> <filename>\n", argv[0]);
@@ -91,12 +91,11 @@ int main(int argc, char **argv)
/* Initialise library */
assert(css_initialise(argv[1], myrealloc, NULL) == CSS_OK);
+ assert(lwc_create_context(myrealloc, NULL, &ctx) == lwc_error_ok);
+ lwc_context_ref(ctx);
for (int i = 0; i < ITERATIONS; i++) {
- assert(parserutils_hash_create(myrealloc, NULL, &dict) ==
- PARSERUTILS_OK);
-
- assert(css_parser_create("UTF-8", CSS_CHARSET_DICTATED, dict,
+ assert(css_parser_create("UTF-8", CSS_CHARSET_DICTATED, ctx,
myrealloc, NULL, &parser) == CSS_OK);
params.event_handler.handler = event_handler;
@@ -138,13 +137,14 @@ int main(int argc, char **argv)
css_parser_destroy(parser);
- parserutils_hash_destroy(dict);
}
assert(css_finalise(myrealloc, NULL) == CSS_OK);
printf("PASS\n");
-
+
+ lwc_context_unref(ctx);
+
return 0;
}
diff --git a/test/parse2-auto.c b/test/parse2-auto.c
index 80fcd24..aedc46b 100644
--- a/test/parse2-auto.c
+++ b/test/parse2-auto.c
@@ -164,15 +164,19 @@ void run_test(const uint8_t *data, size_t len, const char *exp, size_t explen)
char *buf;
size_t buflen;
static int testnum;
+ lwc_context *ctx;
buf = malloc(2 * explen);
if (buf == NULL) {
assert(0 && "No memory for result data");
}
buflen = 2 * explen;
-
+
+ assert(lwc_create_context(myrealloc, NULL, &ctx) == lwc_error_ok);
+ lwc_context_ref(ctx);
+
assert(css_stylesheet_create(CSS_LEVEL_21, "UTF-8", "foo", NULL,
- CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL,
+ CSS_ORIGIN_AUTHOR, CSS_MEDIA_ALL, ctx,
myrealloc, NULL, &sheet) == CSS_OK);
error = css_stylesheet_append_data(sheet, data, len);
@@ -195,7 +199,7 @@ void run_test(const uint8_t *data, size_t len, const char *exp, size_t explen)
}
css_stylesheet_destroy(sheet);
-
+ lwc_context_unref(ctx);
printf("Test %d: PASS\n", testnum);
}
diff --git a/test/select-auto.c b/test/select-auto.c
index bd34a99..a0f0966 100644
--- a/test/select-auto.c
+++ b/test/select-auto.c
@@ -16,12 +16,12 @@
#include "testutils.h"
typedef struct attribute {
- char name[32];
- char value[32];
+ lwc_string *name;
+ lwc_string *value;
} attribute;
typedef struct node {
- char name[32];
+ lwc_string *name;
uint32_t n_attrs;
attribute *attrs;
@@ -53,6 +53,10 @@ typedef struct line_ctx {
uint64_t media;
uint32_t pseudo_element;
node *target;
+
+ lwc_context *dict;
+ lwc_string *attr_class;
+ lwc_string *attr_id;
} line_ctx;
static bool handle_line(const char *data, size_t datalen, void *pw);
@@ -66,39 +70,38 @@ static void parse_expected(line_ctx *ctx, const char *data, size_t len);
static void run_test(line_ctx *ctx, const char *exp, size_t explen);
static void destroy_tree(node *root);
-static css_error node_name(void *pw, void *node, const uint8_t **name,
- size_t *len);
+static css_error node_name(void *pw, void *node, lwc_context *ctx, lwc_string **name);
static css_error named_ancestor_node(void *pw, void *node,
- const uint8_t *name, size_t len,
+ lwc_string *name,
void **ancestor);
static css_error named_parent_node(void *pw, void *node,
- const uint8_t *name, size_t len,
+ lwc_string *name,
void **parent);
static css_error named_sibling_node(void *pw, void *node,
- const uint8_t *name, size_t len,
+ lwc_string *name,
void **sibling);
static css_error parent_node(void *pw, void *node, void **parent);
static css_error sibling_node(void *pw, void *node, void **sibling);
static css_error node_has_class(void *pw, void *node,
- const uint8_t *name, size_t len,
+ lwc_string *name,
bool *match);
static css_error node_has_id(void *pw, void *node,
- const uint8_t *name, size_t len,
+ lwc_string *name,
bool *match);
static css_error node_has_attribute(void *pw, void *node,
- const uint8_t *name, size_t len,
+ lwc_string *name,
bool *match);
static css_error node_has_attribute_equal(void *pw, void *node,
- const uint8_t *name, size_t nlen,
- const uint8_t *value, size_t vlen,
+ lwc_string *name,
+ lwc_string *value,
bool *match);
static css_error node_has_attribute_dashmatch(void *pw, void *node,
- const uint8_t *name, size_t nlen,
- const uint8_t *value, size_t vlen,
+ lwc_string *name,
+ lwc_string *value,
bool *match);
static css_error node_has_attribute_includes(void *pw, void *node,
- const uint8_t *name, size_t nlen,
- const uint8_t *value, size_t vlen,
+ lwc_string *name,
+ lwc_string *value,
bool *match);
static css_error node_is_first_child(void *pw, void *node, bool *match);
static css_error node_is_link(void *pw, void *node, bool *match);
@@ -107,8 +110,7 @@ static css_error node_is_hover(void *pw, void *node, bool *match);
static css_error node_is_active(void *pw, void *node, bool *match);
static css_error node_is_focus(void *pw, void *node, bool *match);
static css_error node_is_lang(void *pw, void *node,
- const uint8_t *lang, size_t len,
- bool *match);
+ lwc_string *lang, bool *match);
static css_select_handler select_handler = {
node_name,
@@ -152,8 +154,11 @@ int main(int argc, char **argv)
memset(&ctx, 0, sizeof(ctx));
+ assert(lwc_create_context(myrealloc, NULL, &ctx.dict) == lwc_error_ok);
+ lwc_context_ref(ctx.dict);
+
assert(parse_testfile(argv[2], handle_line, &ctx) == true);
-
+
/* and run final test */
if (ctx.tree != NULL)
run_test(&ctx, ctx.exp, ctx.expused);
@@ -162,8 +167,9 @@ int main(int argc, char **argv)
assert(css_finalise(myrealloc, NULL) == CSS_OK);
- printf("PASS\n");
-
+ lwc_context_unref(ctx.dict);
+
+ printf("PASS\n");
return 0;
}
@@ -343,9 +349,8 @@ void parse_tree_data(line_ctx *ctx, const char *data, size_t len)
assert(n != NULL);
memset(n, 0, sizeof(node));
-
- memcpy(n->name, name, min(namelen, sizeof(n->name)));
- n->name[min(namelen, sizeof(n->name))] = '\0';
+
+ lwc_context_intern(ctx->dict, name, namelen, &n->name);
/* Insert it into tree */
if (ctx->tree == NULL) {
@@ -390,12 +395,9 @@ void parse_tree_data(line_ctx *ctx, const char *data, size_t len)
ctx->current->attrs = temp;
attr = &ctx->current->attrs[ctx->current->n_attrs];
-
- memcpy(attr->name, name, min(namelen, sizeof(attr->name)));
- attr->name[min(namelen, sizeof(attr->name))] = '\0';
-
- memcpy(attr->value, value, min(valuelen, sizeof(attr->value)));
- attr->value[min(valuelen, sizeof(attr->value))] = '\0';
+
+ lwc_context_intern(ctx->dict, name, namelen, &attr->name);
+ lwc_context_intern(ctx->dict, value, valuelen, &attr->value);
ctx->current->n_attrs++;
}
@@ -439,7 +441,7 @@ void parse_sheet(line_ctx *ctx, const char *data, size_t len)
/** \todo How are we going to handle @import? */
assert(css_stylesheet_create(CSS_LEVEL_21, "UTF-8", "foo", "foo",
- origin, media, myrealloc, NULL, &sheet) == CSS_OK);
+ origin, media, ctx->dict, myrealloc, NULL, &sheet) == CSS_OK);
/* Extend array of sheets and append new sheet to it */
temp = realloc(ctx->sheets,
@@ -625,7 +627,7 @@ void run_test(line_ctx *ctx, const char *exp, size_t explen)
testnum++;
assert(css_select_style(select, ctx->target, ctx->pseudo_element,
- ctx->media, computed, &select_handler, NULL) == CSS_OK);
+ ctx->media, computed, &select_handler, ctx) == CSS_OK);
dump_computed_style(computed, buf, &buflen);
@@ -674,28 +676,29 @@ void destroy_tree(node *root)
}
-css_error node_name(void *pw, void *n, const uint8_t **name, size_t *len)
+css_error node_name(void *pw, void *n, lwc_context *ctx, lwc_string **name)
{
node *node = n;
UNUSED(pw);
-
- *name = (const uint8_t *) node->name;
- *len = strlen(node->name);
-
+
+ *name = lwc_context_string_ref(ctx, node->name);
+
return CSS_OK;
}
css_error named_ancestor_node(void *pw, void *n,
- const uint8_t *name, size_t len,
+ lwc_string *name,
void **ancestor)
{
node *node = n;
-
- UNUSED(pw);
+ line_ctx *ctx = pw;
for (node = node->parent; node != NULL; node = node->parent) {
- if (strncasecmp(node->name, (const char *) name, len) == 0)
+ bool match;
+ assert(lwc_context_string_caseless_isequal(ctx->dict,
+ name, node->name, &match) == lwc_error_ok);
+ if (match == true)
break;
}
@@ -705,36 +708,41 @@ css_error named_ancestor_node(void *pw, void *n,
}
css_error named_parent_node(void *pw, void *n,
- const uint8_t *name, size_t len,
+ lwc_string *name,
void **parent)
{
node *node = n;
-
- UNUSED(pw);
-
- if (node->parent != NULL && strncasecmp(node->parent->name,
- (const char *) name, len) == 0)
- *parent = (void *) node->parent;
- else
- *parent = NULL;
+ line_ctx *ctx = pw;
+
+ *parent = NULL;
+ if (node->parent != NULL) {
+ bool match;
+ assert(lwc_context_string_caseless_isequal(ctx->dict,
+ name, node->parent->name,
+ &match) == lwc_error_ok);
+ if (match == true)
+ *parent = (void *) node->parent;
+ }
return CSS_OK;
}
css_error named_sibling_node(void *pw, void *n,
- const uint8_t *name, size_t len,
+ lwc_string *name,
void **sibling)
{
node *node = n;
-
- UNUSED(pw);
-
- for (node = node->prev; node != NULL; node = node->prev) {
- if (strncasecmp(node->name, (const char *) name, len) == 0)
- break;
- }
-
- *sibling = (void *) node;
+ line_ctx *ctx = pw;
+
+ *sibling = NULL;
+ if (node->prev != NULL) {
+ bool match;
+ assert(lwc_context_string_caseless_isequal(ctx->dict,
+ name, node->prev->name,
+ &match) == lwc_error_ok);
+ if (match == true)
+ *sibling = (void *) node->prev;
+ }
return CSS_OK;
}
@@ -762,22 +770,23 @@ css_error sibling_node(void *pw, void *n, void **sibling)
}
css_error node_has_class(void *pw, void *n,
- const uint8_t *name, size_t len,
+ lwc_string *name,
bool *match)
{
node *node = n;
uint32_t i;
-
- UNUSED(pw);
+ line_ctx *ctx = pw;
for (i = 0; i < node->n_attrs; i++) {
- if (strncasecmp(node->attrs[i].name, "class", 5) == 0)
+ bool amatch;
+ assert(lwc_context_string_caseless_isequal(ctx->dict, node->attrs[i].name,
+ ctx->attr_class, &amatch) == lwc_error_ok);
+ if (amatch == true)
break;
}
/* Classes are case-sensitive in HTML */
- if (i != node->n_attrs && strncmp(node->attrs[i].value,
- (const char *) name, len) == 0)
+ if (i != node->n_attrs && name == node->attrs[i].value)
*match = true;
else
*match = false;
@@ -786,22 +795,23 @@ css_error node_has_class(void *pw, void *n,
}
css_error node_has_id(void *pw, void *n,
- const uint8_t *name, size_t len,
+ lwc_string *name,
bool *match)
{
node *node = n;
uint32_t i;
-
- UNUSED(pw);
+ line_ctx *ctx = pw;
for (i = 0; i < node->n_attrs; i++) {
- if (strncasecmp(node->attrs[i].name, "id", 2) == 0)
+ bool amatch;
+ assert(lwc_context_string_caseless_isequal(ctx->dict, node->attrs[i].name,
+ ctx->attr_id, &amatch) == lwc_error_ok);
+ if (amatch == true)
break;
}
/* IDs are case-sensitive in HTML */
- if (i != node->n_attrs && strncmp(node->attrs[i].value,
- (const char *) name, len) == 0)
+ if (i != node->n_attrs && name == node->attrs[i].value)
*match = true;
else
*match = false;
@@ -810,83 +820,82 @@ css_error node_has_id(void *pw, void *n,
}
css_error node_has_attribute(void *pw, void *n,
- const uint8_t *name, size_t len,
+ lwc_string *name,
bool *match)
{
node *node = n;
uint32_t i;
-
- UNUSED(pw);
-
+ line_ctx *ctx = pw;
+
+ *match = false;
for (i = 0; i < node->n_attrs; i++) {
- if (strncasecmp(node->attrs[i].name,
- (const char *) name, len) == 0)
- break;
+ assert(lwc_context_string_caseless_isequal(ctx->dict, node->attrs[i].name,
+ name, match) == lwc_error_ok);
+ if (*match == true)
+ break;
}
- if (i != node->n_attrs)
- *match = true;
- else
- *match = false;
-
return CSS_OK;
}
css_error node_has_attribute_equal(void *pw, void *n,
- const uint8_t *name, size_t nlen,
- const uint8_t *value, size_t vlen,
+ lwc_string *name,
+ lwc_string *value,
bool *match)
{
node *node = n;
uint32_t i;
+ line_ctx *ctx = pw;
- UNUSED(pw);
-
+ *match = false;
+
for (i = 0; i < node->n_attrs; i++) {
- if (strncasecmp(node->attrs[i].name,
- (const char *) name, nlen) == 0)
- break;
+ assert(lwc_context_string_caseless_isequal(ctx->dict, node->attrs[i].name,
+ name, match) == lwc_error_ok);
+ if (*match == true)
+ break;
}
-
- /* Attribute values are (mostly) case insensitive */
- if (i != node->n_attrs && strncasecmp(node->attrs[i].value,
- (const char *) value, vlen) == 0)
- *match = true;
- else
- *match = false;
-
+
+ if (*match == true) {
+ assert(lwc_context_string_caseless_isequal(ctx->dict, node->attrs[i].name,
+ value, match) == lwc_error_ok);
+ }
+
return CSS_OK;
}
-css_error node_has_attribute_dashmatch(void *pw, void *n,
- const uint8_t *name, size_t nlen,
- const uint8_t *value, size_t vlen,
+css_error node_has_attribute_includes(void *pw, void *n,
+ lwc_string *name,
+ lwc_string *value,
bool *match)
{
node *node = n;
uint32_t i;
+ line_ctx *ctx = pw;
+ size_t vlen = lwc_string_length(value);
- UNUSED(pw);
-
+ *match = false;
+
for (i = 0; i < node->n_attrs; i++) {
- if (strncasecmp(node->attrs[i].name,
- (const char *) name, nlen) == 0)
- break;
+ assert(lwc_context_string_caseless_isequal(ctx->dict, node->attrs[i].name,
+ name, match) == lwc_error_ok);
+ if (*match == true)
+ break;
}
- *match = false;
-
- if (i != node->n_attrs) {
+ if (*match == true) {
const char *p;
- const char *start = node->attrs[i].value;
- const char *end = start + strlen(start) + 1;
-
- for (p = node->attrs[i].value; p < end; p++) {
- if (*p == '-') {
+ const char *start = lwc_string_data(node->attrs[i].value);
+ const char *end = start + lwc_string_length(node->attrs[i].value);
+
+ *match = false;
+
+ for (p = start; p < end; p++) {
+ if (*p == ' ') {
if ((size_t) (p - start) == vlen &&
strncasecmp(start,
- (const char *) value,
- vlen) == 0) {
+ lwc_string_data(value),
+ vlen) == 0) {
*match = true;
break;
}
@@ -899,35 +908,38 @@ css_error node_has_attribute_dashmatch(void *pw, void *n,
return CSS_OK;
}
-css_error node_has_attribute_includes(void *pw, void *n,
- const uint8_t *name, size_t nlen,
- const uint8_t *value, size_t vlen,
+css_error node_has_attribute_dashmatch(void *pw, void *n,
+ lwc_string *name,
+ lwc_string *value,
bool *match)
{
node *node = n;
uint32_t i;
+ line_ctx *ctx = pw;
+ size_t vlen = lwc_string_length(value);
- UNUSED(pw);
-
+ *match = false;
+
for (i = 0; i < node->n_attrs; i++) {
- if (strncasecmp(node->attrs[i].name,
- (const char *) name, nlen) == 0)
- break;
+ assert(lwc_context_string_caseless_isequal(ctx->dict, node->attrs[i].name,
+ name, match) == lwc_error_ok);
+ if (*match == true)
+ break;
}
- *match = false;
-
- if (i != node->n_attrs) {
+ if (*match == true) {
const char *p;
- const char *start = node->attrs[i].value;
- const char *end = start + strlen(start) + 1;
-
- for (p = node->attrs[i].value; p < end; p++) {
- if (*p == ' ') {
+ const char *start = lwc_string_data(node->attrs[i].value);
+ const char *end = start + lwc_string_length(node->attrs[i].value);
+
+ *match = false;
+
+ for (p = start; p < end; p++) {
+ if (*p == '-') {
if ((size_t) (p - start) == vlen &&
strncasecmp(start,
- (const char *) value,
- vlen) == 0) {
+ lwc_string_data(value),
+ vlen) == 0) {
*match = true;
break;
}
@@ -1012,7 +1024,7 @@ css_error node_is_focus(void *pw, void *n, bool *match)
}
css_error node_is_lang(void *pw, void *n,
- const uint8_t *lang, size_t len,
+ lwc_string *lang,
bool *match)
{
node *node = n;
@@ -1020,7 +1032,6 @@ css_error node_is_lang(void *pw, void *n,
UNUSED(pw);
UNUSED(node);
UNUSED(lang);
- UNUSED(len);
*match = false;