#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* libcss requires a URL resolver; relative resolution is not what is under test here, so just duplicate the reference. */ static css_error pt_resolve_url(void *pw, const char *base, lwc_string *rel, lwc_string **abs) { (void) pw; (void) base; *abs = lwc_string_ref(rel); return CSS_OK; } /* libnsgif needs a bitmap callback table; nothing is decoded here, so these are only enough to satisfy nsgif_create(). */ static void *pt_bitmap_create(int w, int h) { (void) w; (void) h; return NULL; } static void pt_bitmap_destroy(void *bm) { (void) bm; } static uint8_t *pt_bitmap_get_buffer(void *bm) { (void) bm; return NULL; } static const nsgif_bitmap_cb_vt pt_gif_bitmap_cbs = { .create = pt_bitmap_create, .destroy = pt_bitmap_destroy, .get_buffer = pt_bitmap_get_buffer, }; int main(void) { lwc_string *a = NULL, *b = NULL; bool same = false; parserutils_buffer *buf = NULL; size_t len = 0; unsigned char comp[128]; uLongf clen = sizeof(comp); int gzok = 0; const char *s = "MontaukOS"; /* libwapcaplet: interning must make equal strings identical */ lwc_intern_string("netsurf", 7, &a); lwc_intern_string("netsurf", 7, &b); /* assign the result: the macro ends in a comma expression, so discarding it warns under -Wall */ lwc_error lwcerr = lwc_string_isequal(a, b, &same); (void) lwcerr; /* libparserutils: buffer + utf8 length */ parserutils_buffer_create(&buf); parserutils_buffer_append(buf, (const uint8_t *)s, strlen(s)); parserutils_charset_utf8_length((const uint8_t *)s, strlen(s), &len); /* zlib: gzip-wrapper inflate is the path NetSurf uses for Content-Encoding: gzip, so exercise that rather than plain compress() */ { z_stream z; unsigned char back[128]; int r; memset(&z, 0, sizeof(z)); deflateInit2(&z, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15+16, 8, Z_DEFAULT_STRATEGY); z.next_in = (Bytef *)s; z.avail_in = strlen(s); z.next_out = comp; z.avail_out = sizeof(comp); deflate(&z, Z_FINISH); clen = z.total_out; deflateEnd(&z); memset(&z, 0, sizeof(z)); inflateInit2(&z, 15+16); z.next_in = comp; z.avail_in = clen; z.next_out = back; z.avail_out = sizeof(back); r = inflate(&z, Z_FINISH); inflateEnd(&z); gzok = (r == Z_STREAM_END && z.total_out == strlen(s) && memcmp(back, s, strlen(s)) == 0); } printf("libwapcaplet: intern-equal=%s length=%zu\n", same ? "PASS" : "FAIL", (size_t)lwc_string_length(a)); printf("libparserutils: buffer=%zu utf8len=%zu %s\n", buf->length, len, (buf->length == strlen(s) && len == strlen(s)) ? "PASS" : "FAIL"); printf("zlib %s: gzip roundtrip %lu->%lu %s\n", zlibVersion(), (unsigned long)strlen(s), (unsigned long)clen, gzok ? "PASS" : "FAIL"); /* libhubbub / libcss / libdom: construct the real objects rather than just resolving symbols -- a stub-out or a broken static init would still link but fail here. */ { hubbub_parser *hp = NULL; css_stylesheet *sheet = NULL; css_stylesheet_params sp; dom_document *doc = NULL; dom_exception de; hubbub_error he; he = hubbub_parser_create("UTF-8", false, &hp); printf("libhubbub: parser_create %s\n", (he == HUBBUB_OK && hp != NULL) ? "PASS" : "FAIL"); if (hp != NULL) hubbub_parser_destroy(hp); memset(&sp, 0, sizeof(sp)); sp.params_version = CSS_STYLESHEET_PARAMS_VERSION_1; sp.level = CSS_LEVEL_21; sp.charset = "UTF-8"; sp.url = "http://montaukos.local/"; sp.resolve = pt_resolve_url; if (css_stylesheet_create(&sp, &sheet) == CSS_OK && sheet != NULL) { const char data[] = "body { color: #123456; margin: 4px; }"; css_error ce = css_stylesheet_append_data(sheet, (const uint8_t *) data, sizeof(data) - 1); if (ce == CSS_NEEDDATA) ce = CSS_OK; if (ce == CSS_OK) ce = css_stylesheet_data_done(sheet); printf("libcss: parse stylesheet %s\n", ce == CSS_OK ? "PASS" : "FAIL"); css_stylesheet_destroy(sheet); } else { printf("libcss: stylesheet_create FAIL\n"); } de = dom_implementation_create_document(DOM_IMPLEMENTATION_HTML, NULL, NULL, NULL, NULL, NULL, &doc); printf("libdom: create_document %s\n", (de == DOM_NO_ERR && doc != NULL) ? "PASS" : "FAIL"); if (doc != NULL) dom_node_unref(doc); } /* Support libraries: construct/query rather than just resolve symbols. */ { uint64_t ms = 0; nsgif_t *gif = NULL; const utf8proc_property_t *prop; printf("libnsutils: monotonic time %s\n", (nsu_getmonotonic_ms(&ms) == NSUERROR_OK) ? "PASS" : "FAIL"); printf("libnsgif: create %s\n", (nsgif_create(&pt_gif_bitmap_cbs, NSGIF_BITMAP_FMT_R8G8B8A8, &gif) == NSGIF_OK && gif != NULL) ? "PASS" : "FAIL"); if (gif != NULL) nsgif_destroy(gif); /* U+00E9 LATIN SMALL LETTER E WITH ACUTE -> category Ll */ prop = utf8proc_get_property(0x00E9); printf("libutf8proc: property lookup %s\n", (prop != NULL && prop->category == UTF8PROC_CATEGORY_LL) ? "PASS" : "FAIL"); } lwc_string_unref(a); lwc_string_unref(b); parserutils_buffer_destroy(buf); return 0; }