diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2008-03-21 13:20:22 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2008-03-21 13:20:22 +0000 |
commit | 4da6a038c15a5fa3d1c754b7278ae47627a44718 (patch) | |
tree | bd3f06540ff87963913848c6fea5cb1b7eec62e3 /test/tree.c | |
parent | eebff1268e029fa6a31d391c175a66e159a45ecf (diff) | |
download | libhubbub-4da6a038c15a5fa3d1c754b7278ae47627a44718.tar.gz libhubbub-4da6a038c15a5fa3d1c754b7278ae47627a44718.tar.bz2 |
hubbub_strings may now be either an offset into the data buffer or a pointer to constant data.
Fix up tokeniser and treebuilder to deal with this.
Fix up testcases, too.
The tokeniser will only ever emit strings of type HUBBUB_STRING_OFF. Anything else is a bug which should be fixed.
The treebuilder may emit strings of either type.
svn path=/trunk/hubbub/; revision=4014
Diffstat (limited to 'test/tree.c')
-rw-r--r-- | test/tree.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/test/tree.c b/test/tree.c index 04ce026..f4e6c3c 100644 --- a/test/tree.c +++ b/test/tree.c @@ -11,7 +11,7 @@ #include "testutils.h" -#define NODE_REF_CHUNK 1024 +#define NODE_REF_CHUNK 8192 static uint16_t *node_ref; static uintptr_t node_ref_alloc; static uintptr_t node_counter; @@ -72,6 +72,22 @@ static void *myrealloc(void *ptr, size_t len, void *pw) return realloc(ptr, len); } +static const uint8_t *ptr_from_hubbub_string(const hubbub_string *string) +{ + const uint8_t *data; + + switch (string->type) { + case HUBBUB_STRING_OFF: + data = pbuffer + string->data.off; + break; + case HUBBUB_STRING_PTR: + data = string->data.ptr; + break; + } + + return data; +} + int main(int argc, char **argv) { hubbub_parser *parser; @@ -188,7 +204,7 @@ void buffer_handler(const uint8_t *buffer, size_t len, void *pw) int create_comment(void *ctx, const hubbub_string *data, void **result) { printf("Creating (%u) [comment '%.*s']\n", ++node_counter, - data->len, pbuffer + data->data_off); + data->len, ptr_from_hubbub_string(data)); GROW_REF node_ref[node_counter] = 0; @@ -208,7 +224,7 @@ int create_doctype(void *ctx, const hubbub_string *qname, UNUSED(system_id); printf("Creating (%u) [doctype '%.*s']\n", ++node_counter, - qname->len, pbuffer + qname->data_off); + qname->len, ptr_from_hubbub_string(qname)); GROW_REF node_ref[node_counter] = 0; @@ -223,7 +239,7 @@ int create_doctype(void *ctx, const hubbub_string *qname, int create_element(void *ctx, const hubbub_tag *tag, void **result) { printf("Creating (%u) [element '%.*s']\n", ++node_counter, - tag->name.len, pbuffer + tag->name.data_off); + tag->name.len, ptr_from_hubbub_string(&tag->name)); GROW_REF node_ref[node_counter] = 0; @@ -254,7 +270,7 @@ int create_element_verbatim(void *ctx, const uint8_t *name, size_t len, int create_text(void *ctx, const hubbub_string *data, void **result) { printf("Creating (%u) [text '%.*s']\n", ++node_counter, - data->len, pbuffer + data->data_off); + data->len, ptr_from_hubbub_string(data)); GROW_REF node_ref[node_counter] = 0; |