diff --git a/Makefile.am b/Makefile.am index f0cc385..948b50d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,12 +21,26 @@ dist-hook: cp -p $(PSL_TESTFILE) $(distdir)/list/tests clean-local: - rm -rf */*.gc?? libpsl.info lcov + rm -rf */*.gc?? */*/*.gc?? libpsl.info lcov check-coverage: - $(MAKE) clean - lcov --no-external --capture --initial --directory . --output-file libpsl.info - CFLAGS=$$CFLAGS" --coverage" LDFLAGS=$$LDFLAGS" --coverage" ./configure && $(MAKE) check - lcov --no-external --capture --directory . --output-file libpsl.info -# lcov --remove libpsl.info 'tests/*.c' 'src/lookup_*' 'src/psl2c.c' -o libpsl.info + if test -z "$(XLIB)"; then \ + CFLAGS=$$CFLAGS" --coverage -O0" LDFLAGS=$$LDFLAGS" --coverage" ./configure --disable-runtime --disable-builtin; \ + else \ + CFLAGS=$$CFLAGS" --coverage -O0" LDFLAGS=$$LDFLAGS" --coverage" ./configure --enable-runtime=$(XLIB) --enable-builtin=$(XLIB); \ + fi + $(MAKE) clean && $(MAKE) + lcov --no-external --capture --initial --directory src --output-file libpsl.info + $(MAKE) check + lcov --no-external --capture --directory src --output-file libpsl.info + lcov --remove libpsl.info 'src/psl2c.c' -o libpsl.info genhtml --prefix . --ignore-errors source libpsl.info --legend --title "libpsl" --output-directory=lcov + +check-coverage-libidn: + XLIB=libidn $(MAKE) check-coverage + +check-coverage-libidn2: + XLIB=libidn2 $(MAKE) check-coverage + +check-coverage-libicu: + XLIB=libicu $(MAKE) check-coverage diff --git a/src/psl.c b/src/psl.c index e829dcf..4add23e 100644 --- a/src/psl.c +++ b/src/psl.c @@ -1728,7 +1728,7 @@ out: if ((tmp = u8_tolower((uint8_t *)str, len, 0, UNINORM_NFKC, NULL, &len))) { ret = PSL_SUCCESS; if (lower) { - *lower = tmp; + *lower = (char*)tmp; tmp = NULL; } else free(tmp); diff --git a/tests/Makefile.am b/tests/Makefile.am index c71cd99..d3e9667 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -23,3 +23,12 @@ check_PROGRAMS = $(PSL_TESTS) TESTS_ENVIRONMENT = TESTS_VALGRIND="@VALGRIND_ENVIRONMENT@" TESTS = $(PSL_TESTS) + +# dafsa.psl must be created before any test is executed +# check-local target works in parallel to the tests, so the test suite will likely fail +BUILT_SOURCES = dafsa.psl +dafsa.psl: + $(top_srcdir)/src/psl-make-dafsa --input-format=psl --output-format=binary "$(PSL_FILE)" psl.dafsa + +clean-local: + rm -f psl.dafsa \ No newline at end of file diff --git a/tests/test-is-cookie-domain-acceptable.c b/tests/test-is-cookie-domain-acceptable.c index c50342d..6bac1a4 100644 --- a/tests/test-is-cookie-domain-acceptable.c +++ b/tests/test-is-cookie-domain-acceptable.c @@ -65,6 +65,7 @@ static void test_psl(void) { "www.his.name", "his.name", 1 }, { "www.his.name", "name", 0 }, { "www.example.com", "www.example.com", 1 }, + { "www.example.com", "wwww.example.com", 0 }, { "www.example.com", "example.com", 1 }, { "www.example.com", "com", 0 }, /* not accepted by normalization (PSL rule 'com') */ { "www.example.com", "example.org", 0 }, @@ -77,6 +78,8 @@ static void test_psl(void) { "2a00:1450:4013:c01::8b", ":1450:4013:c01::8b", 0 }, /* IPv6 address, partial match */ { "::ffff:192.1.123.2", "::ffff:192.1.123.2", 1 }, /* IPv6 address dotted-quad, full match */ { "::ffff:192.1.123.2", ".1.123.2", 0 }, /* IPv6 address dotted-quad, partial match */ + { NULL, ".1.123.2", 0 }, + { "hiho", NULL, 0 }, }; unsigned it; psl_ctx_t *psl; @@ -98,6 +101,9 @@ static void test_psl(void) } } + /* do checks to cover more code paths in libpsl */ + psl_is_cookie_domain_acceptable(NULL, "example.com", "example.com"); + psl_free(psl); } diff --git a/tests/test-is-public-all.c b/tests/test-is-public-all.c index f4b7494..f76cfb8 100644 --- a/tests/test-is-public-all.c +++ b/tests/test-is-public-all.c @@ -131,7 +131,7 @@ static void test_psl_entry(const psl_ctx_t *psl, const char *domain, int type) static void test_psl(void) { FILE *fp; - psl_ctx_t *psl; + psl_ctx_t *psl, *psl3; const psl_ctx_t *psl2; int type = 0; char buf[256], *linep, *p; @@ -142,6 +142,11 @@ static void test_psl(void) psl2 = psl_builtin(); printf("builtin PSL has %d suffixes and %d exceptions\n", psl_suffix_count(psl2), psl_suffix_exception_count(psl2)); + if (!(psl3 = psl_load_file("psl.dafsa"))) { + fprintf(stderr, "Failed to load 'psl.dafsa'\n"); + failed++; + } + if ((fp = fopen(PSL_FILE, "r"))) { #ifdef HAVE_CLOCK_GETTIME clock_gettime(CLOCK_REALTIME, &ts1); @@ -174,6 +179,9 @@ static void test_psl(void) if (psl2) test_psl_entry(psl2, p, type); + + if (psl3) + test_psl_entry(psl3, p, type); } #ifdef HAVE_CLOCK_GETTIME @@ -187,6 +195,7 @@ static void test_psl(void) psl_free(psl); psl_free((psl_ctx_t *)psl2); + psl_free(psl3); } int main(int argc, const char * const *argv) diff --git a/tests/test-is-public.c b/tests/test-is-public.c index 5d32425..d1567b7 100644 --- a/tests/test-is-public.c +++ b/tests/test-is-public.c @@ -84,6 +84,7 @@ static void test_psl(void) { "adfhoweirh", 1 }, /* unknown TLD */ }; unsigned it; + int result, ver; psl_ctx_t *psl; psl = psl_load_file(PSL_FILE); @@ -92,7 +93,7 @@ static void test_psl(void) for (it = 0; it < countof(test_data); it++) { const struct test_data *t = &test_data[it]; - int result = psl_is_public_suffix(psl, t->domain); + result = psl_is_public_suffix(psl, t->domain); if (result == t->result) { ok++; @@ -102,6 +103,68 @@ static void test_psl(void) } } + /* do some checks to cover more code paths in libpsl */ + psl_is_public_suffix(NULL, "xxx"); + + if ((ver = psl_check_version_number(0)) == 0) { + printf("psl_check_version_number(0) is 0\n"); + failed++; + } else { + if (((result = psl_check_version_number(ver)) != ver)) { + printf("psl_check_version_number(%06X) is %06X\n", ver, result); + failed++; + } + + if (((result = psl_check_version_number(ver - 1)) != 0)) { + printf("psl_check_version_number(%06X) is %06X\n", ver - 1, result); + failed++; + } + + if (((result = psl_check_version_number(ver + 1)) != ver)) { + printf("psl_check_version_number(%06X) is %06X\n", ver, result); + failed++; + } + } + + psl_str_to_utf8lower("www.example.com", "utf-8", "en", NULL); + psl_str_to_utf8lower(NULL, "utf-8", "en", NULL); + + { + char *lower = NULL; + + psl_str_to_utf8lower("www.example.com", NULL, "de", &lower); + free(lower); lower = NULL; + + psl_str_to_utf8lower("\374bel.de", NULL, "de", &lower); + free(lower); lower = NULL; + + psl_str_to_utf8lower("\374bel.de", "iso-8859-1", NULL, &lower); + free(lower); lower = NULL; + + psl_str_to_utf8lower(NULL, "utf-8", "en", &lower); + free(lower); lower = NULL; + } + + psl_get_version(); + psl_builtin_filename(); + psl_builtin_outdated(); + psl_builtin_file_time(); + psl_builtin_sha1sum(); + psl_suffix_wildcard_count(NULL); + psl_suffix_wildcard_count(psl); + psl_suffix_wildcard_count(psl_builtin()); + psl_suffix_count(NULL); + psl_suffix_exception_count(NULL); + psl_load_file(NULL); + psl_load_fp(NULL); + psl_registrable_domain(NULL, ""); + psl_registrable_domain(psl, NULL); + psl_registrable_domain(psl, "www.example.com"); + psl_unregistrable_domain(NULL, ""); + psl_unregistrable_domain(psl, NULL); + psl_is_public_suffix2(NULL, "", PSL_TYPE_ANY); + psl_is_public_suffix2(psl, NULL, PSL_TYPE_ANY); + psl_free(psl); }