Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Ae69wJS7sueQMUwNxV3nX
62 lines
2.4 KiB
C
62 lines
2.4 KiB
C
#include <libwapcaplet/libwapcaplet.h>
|
|
#include <parserutils/parserutils.h>
|
|
#include <parserutils/charset/utf8.h>
|
|
#include <parserutils/utils/buffer.h>
|
|
#include <zlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
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");
|
|
lwc_string_unref(a); lwc_string_unref(b);
|
|
parserutils_buffer_destroy(buf);
|
|
return 0;
|
|
}
|