fixed indentation

This commit is contained in:
Tim Ruehsen 2014-03-26 09:11:54 +01:00
parent fd6320db9e
commit 1d079fceeb
3 changed files with 79 additions and 79 deletions

View File

@ -52,66 +52,66 @@ static void test_psl(void)
unsigned it, result;
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"))) {
while ((linep = fgets(buf, sizeof(buf), fp))) {
while (isspace(*linep)) linep++; // ignore leading whitespace
if (!*linep) continue; // skip empty lines
if ((fp = fopen(DATADIR "/effective_tld_names.dat", "r"))) {
while ((linep = fgets(buf, sizeof(buf), fp))) {
while (isspace(*linep)) linep++; // ignore leading whitespace
if (!*linep) continue; // skip empty lines
if (*linep == '/' && linep[1] == '/')
continue; // skip comments
if (*linep == '/' && linep[1] == '/')
continue; // skip comments
// parse suffix rule
for (p = linep; *linep && !isspace(*linep);) linep++;
*linep = 0;
// parse suffix rule
for (p = linep; *linep && !isspace(*linep);) linep++;
*linep = 0;
if (*p == '!') { // an exception to a wildcard, e.g. !www.ck (wildcard is *.ck)
if (!(result = psl_is_public(psl, p + 1))) {
failed++;
printf("psl_is_public(%s)=%d (expected 1)\n", p, result);
} else ok++;
if (*p == '!') { // an exception to a wildcard, e.g. !www.ck (wildcard is *.ck)
if (!(result = psl_is_public(psl, p + 1))) {
failed++;
printf("psl_is_public(%s)=%d (expected 1)\n", p, result);
} else ok++;
if ((result = psl_is_public(psl, strchr(p, '.') + 1))) {
failed++;
printf("psl_is_public(%s)=%d (expected 0)\n", strchr(p, '.') + 1, 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++;
*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++;
}
if ((result = psl_is_public(psl, strchr(p, '.') + 1))) {
failed++;
printf("psl_is_public(%s)=%d (expected 0)\n", strchr(p, '.') + 1, 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);
} else {
printf("Failed to open %s\n", DATADIR "/effective_tld_names.dat");
failed++;
*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++;
}
}
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)

View File

@ -72,30 +72,30 @@ static void test_psl(void)
unsigned it;
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++) {
const struct test_data *t = &test_data[it];
int result = psl_is_public(psl, t->domain);
for (it = 0; it < countof(test_data); it++) {
const struct test_data *t = &test_data[it];
int result = psl_is_public(psl, t->domain);
if (result == t->result) {
ok++;
} else {
failed++;
printf("psl_is_public(%s)=%d (expected %d)\n", t->domain, result, t->result);
}
if (result == t->result) {
ok++;
} else {
failed++;
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());
psl_builtin_compile_time() == 0 ? failed++ : ok++;
printf("psl_builtin_compile_time()=%ld\n", psl_builtin_compile_time());
psl_builtin_compile_time() == 0 ? failed++ : ok++;
printf("psl_builtin_file_time()=%ld\n", psl_builtin_file_time());
psl_builtin_file_time() == 0 ? failed++ : ok++;
printf("psl_builtin_file_time()=%ld\n", psl_builtin_file_time());
psl_builtin_file_time() == 0 ? failed++ : ok++;
printf("psl_builtin_sha1sum()=%s\n", psl_builtin_sha1sum());
*psl_builtin_sha1sum() == 0 ? failed++ : ok++;
printf("psl_builtin_sha1sum()=%s\n", psl_builtin_sha1sum());
*psl_builtin_sha1sum() == 0 ? failed++ : ok++;
}
int main(int argc, const char * const *argv)

View File

@ -70,23 +70,23 @@ static void test_psl(void)
unsigned it;
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++) {
const struct test_data *t = &test_data[it];
int result = psl_is_public(psl, t->domain);
for (it = 0; it < countof(test_data); it++) {
const struct test_data *t = &test_data[it];
int result = psl_is_public(psl, t->domain);
if (result == t->result) {
ok++;
} else {
failed++;
printf("psl_is_public(%s)=%d (expected %d)\n", t->domain, result, t->result);
}
if (result == t->result) {
ok++;
} else {
failed++;
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)