fixed indentation
This commit is contained in:
parent
fd6320db9e
commit
1d079fceeb
|
@ -52,66 +52,66 @@ static void test_psl(void)
|
||||||
unsigned it, result;
|
unsigned it, result;
|
||||||
char buf[256], domain[64], *linep, *p;
|
char buf[256], domain[64], *linep, *p;
|
||||||
|
|
||||||
psl = psl_load_file(DATADIR "/effective_tld_names.dat");
|
psl = psl_load_file(DATADIR "/effective_tld_names.dat");
|
||||||
|
|
||||||
printf("loaded %d suffixes and %d exceptions\n", psl_suffix_count(psl), psl_suffix_exception_count(psl));
|
printf("loaded %d suffixes and %d exceptions\n", psl_suffix_count(psl), psl_suffix_exception_count(psl));
|
||||||
|
|
||||||
if ((fp = fopen(DATADIR "/effective_tld_names.dat", "r"))) {
|
if ((fp = fopen(DATADIR "/effective_tld_names.dat", "r"))) {
|
||||||
while ((linep = fgets(buf, sizeof(buf), fp))) {
|
while ((linep = fgets(buf, sizeof(buf), fp))) {
|
||||||
while (isspace(*linep)) linep++; // ignore leading whitespace
|
while (isspace(*linep)) linep++; // ignore leading whitespace
|
||||||
if (!*linep) continue; // skip empty lines
|
if (!*linep) continue; // skip empty lines
|
||||||
|
|
||||||
if (*linep == '/' && linep[1] == '/')
|
if (*linep == '/' && linep[1] == '/')
|
||||||
continue; // skip comments
|
continue; // skip comments
|
||||||
|
|
||||||
// parse suffix rule
|
// parse suffix rule
|
||||||
for (p = linep; *linep && !isspace(*linep);) linep++;
|
for (p = linep; *linep && !isspace(*linep);) linep++;
|
||||||
*linep = 0;
|
*linep = 0;
|
||||||
|
|
||||||
if (*p == '!') { // an exception to a wildcard, e.g. !www.ck (wildcard is *.ck)
|
if (*p == '!') { // an exception to a wildcard, e.g. !www.ck (wildcard is *.ck)
|
||||||
if (!(result = psl_is_public(psl, p + 1))) {
|
if (!(result = psl_is_public(psl, p + 1))) {
|
||||||
failed++;
|
failed++;
|
||||||
printf("psl_is_public(%s)=%d (expected 1)\n", p, result);
|
printf("psl_is_public(%s)=%d (expected 1)\n", p, result);
|
||||||
} else ok++;
|
} else ok++;
|
||||||
|
|
||||||
if ((result = psl_is_public(psl, strchr(p, '.') + 1))) {
|
if ((result = psl_is_public(psl, strchr(p, '.') + 1))) {
|
||||||
failed++;
|
failed++;
|
||||||
printf("psl_is_public(%s)=%d (expected 0)\n", strchr(p, '.') + 1, result);
|
printf("psl_is_public(%s)=%d (expected 0)\n", strchr(p, '.') + 1, result);
|
||||||
} else ok++;
|
} else ok++;
|
||||||
}
|
|
||||||
else if (*p == '*') { // a wildcard, e.g. *.ck
|
|
||||||
if ((result = psl_is_public(psl, p + 1))) {
|
|
||||||
failed++;
|
|
||||||
printf("psl_is_public(%s)=%d (expected 0)\n", p + 1, result);
|
|
||||||
} else ok++;
|
|
||||||
|
|
||||||
*p = 'x';
|
|
||||||
if ((result = psl_is_public(psl, p))) {
|
|
||||||
failed++;
|
|
||||||
printf("psl_is_public(%s)=%d (expected 0)\n", p, result);
|
|
||||||
} else ok++;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ((result = psl_is_public(psl, p))) {
|
|
||||||
failed++;
|
|
||||||
printf("psl_is_public(%s)=%d (expected 0)\n", p, result);
|
|
||||||
} else ok++;
|
|
||||||
|
|
||||||
snprintf(domain, sizeof(domain), "xxxx.%s", p);
|
|
||||||
if (!(result = psl_is_public(psl, domain))) {
|
|
||||||
failed++;
|
|
||||||
printf("psl_is_public(%s)=%d (expected 1)\n", domain, result);
|
|
||||||
} else ok++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if (*p == '*') { // a wildcard, e.g. *.ck
|
||||||
|
if ((result = psl_is_public(psl, p + 1))) {
|
||||||
|
failed++;
|
||||||
|
printf("psl_is_public(%s)=%d (expected 0)\n", p + 1, result);
|
||||||
|
} else ok++;
|
||||||
|
|
||||||
fclose(fp);
|
*p = 'x';
|
||||||
} else {
|
if ((result = psl_is_public(psl, p))) {
|
||||||
printf("Failed to open %s\n", DATADIR "/effective_tld_names.dat");
|
failed++;
|
||||||
failed++;
|
printf("psl_is_public(%s)=%d (expected 0)\n", p, result);
|
||||||
|
} else ok++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ((result = psl_is_public(psl, p))) {
|
||||||
|
failed++;
|
||||||
|
printf("psl_is_public(%s)=%d (expected 0)\n", p, result);
|
||||||
|
} else ok++;
|
||||||
|
|
||||||
|
snprintf(domain, sizeof(domain), "xxxx.%s", p);
|
||||||
|
if (!(result = psl_is_public(psl, domain))) {
|
||||||
|
failed++;
|
||||||
|
printf("psl_is_public(%s)=%d (expected 1)\n", domain, result);
|
||||||
|
} else ok++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
psl_free(&psl);
|
fclose(fp);
|
||||||
|
} else {
|
||||||
|
printf("Failed to open %s\n", DATADIR "/effective_tld_names.dat");
|
||||||
|
failed++;
|
||||||
|
}
|
||||||
|
|
||||||
|
psl_free(&psl);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char * const *argv)
|
int main(int argc, const char * const *argv)
|
||||||
|
|
|
@ -72,30 +72,30 @@ static void test_psl(void)
|
||||||
unsigned it;
|
unsigned it;
|
||||||
const psl_ctx_t *psl;
|
const psl_ctx_t *psl;
|
||||||
|
|
||||||
psl = psl_builtin();
|
psl = psl_builtin();
|
||||||
|
|
||||||
printf("have %d suffixes and %d exceptions\n", psl_suffix_count(psl), psl_suffix_exception_count(psl));
|
printf("have %d suffixes and %d exceptions\n", psl_suffix_count(psl), psl_suffix_exception_count(psl));
|
||||||
|
|
||||||
for (it = 0; it < countof(test_data); it++) {
|
for (it = 0; it < countof(test_data); it++) {
|
||||||
const struct test_data *t = &test_data[it];
|
const struct test_data *t = &test_data[it];
|
||||||
int result = psl_is_public(psl, t->domain);
|
int result = psl_is_public(psl, t->domain);
|
||||||
|
|
||||||
if (result == t->result) {
|
if (result == t->result) {
|
||||||
ok++;
|
ok++;
|
||||||
} else {
|
} else {
|
||||||
failed++;
|
failed++;
|
||||||
printf("psl_is_public(%s)=%d (expected %d)\n", t->domain, result, t->result);
|
printf("psl_is_public(%s)=%d (expected %d)\n", t->domain, result, t->result);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
printf("psl_builtin_compile_time()=%ld\n", psl_builtin_compile_time());
|
printf("psl_builtin_compile_time()=%ld\n", psl_builtin_compile_time());
|
||||||
psl_builtin_compile_time() == 0 ? failed++ : ok++;
|
psl_builtin_compile_time() == 0 ? failed++ : ok++;
|
||||||
|
|
||||||
printf("psl_builtin_file_time()=%ld\n", psl_builtin_file_time());
|
printf("psl_builtin_file_time()=%ld\n", psl_builtin_file_time());
|
||||||
psl_builtin_file_time() == 0 ? failed++ : ok++;
|
psl_builtin_file_time() == 0 ? failed++ : ok++;
|
||||||
|
|
||||||
printf("psl_builtin_sha1sum()=%s\n", psl_builtin_sha1sum());
|
printf("psl_builtin_sha1sum()=%s\n", psl_builtin_sha1sum());
|
||||||
*psl_builtin_sha1sum() == 0 ? failed++ : ok++;
|
*psl_builtin_sha1sum() == 0 ? failed++ : ok++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char * const *argv)
|
int main(int argc, const char * const *argv)
|
||||||
|
|
|
@ -70,23 +70,23 @@ static void test_psl(void)
|
||||||
unsigned it;
|
unsigned it;
|
||||||
psl_ctx_t *psl;
|
psl_ctx_t *psl;
|
||||||
|
|
||||||
psl = psl_load_file(DATADIR "/effective_tld_names.dat");
|
psl = psl_load_file(DATADIR "/effective_tld_names.dat");
|
||||||
|
|
||||||
printf("loaded %d suffixes and %d exceptions\n", psl_suffix_count(psl), psl_suffix_exception_count(psl));
|
printf("loaded %d suffixes and %d exceptions\n", psl_suffix_count(psl), psl_suffix_exception_count(psl));
|
||||||
|
|
||||||
for (it = 0; it < countof(test_data); it++) {
|
for (it = 0; it < countof(test_data); it++) {
|
||||||
const struct test_data *t = &test_data[it];
|
const struct test_data *t = &test_data[it];
|
||||||
int result = psl_is_public(psl, t->domain);
|
int result = psl_is_public(psl, t->domain);
|
||||||
|
|
||||||
if (result == t->result) {
|
if (result == t->result) {
|
||||||
ok++;
|
ok++;
|
||||||
} else {
|
} else {
|
||||||
failed++;
|
failed++;
|
||||||
printf("psl_is_public(%s)=%d (expected %d)\n", t->domain, result, t->result);
|
printf("psl_is_public(%s)=%d (expected %d)\n", t->domain, result, t->result);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
psl_free(&psl);
|
psl_free(&psl);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char * const *argv)
|
int main(int argc, const char * const *argv)
|
||||||
|
|
Loading…
Reference in New Issue