mirror of
https://github.com/mirror/wget.git
synced 2024-12-27 13:20:23 +08:00
* src/netrc.c (test_parse_netrc): New unit test function
This commit is contained in:
parent
446afdca21
commit
74a9d9e7c4
50
src/netrc.c
50
src/netrc.c
@ -481,6 +481,56 @@ free_netrc(acc_t *l)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TESTING
|
||||
#include "../tests/unit-tests.h"
|
||||
const char *
|
||||
test_parse_netrc(void)
|
||||
{
|
||||
static const struct test {
|
||||
const char *pw_in;
|
||||
const char *pw_expected;
|
||||
} tests[] = {
|
||||
{ "a\\b", "ab" },
|
||||
{ "a\\\\b", "a\\b" },
|
||||
{ "\"a\\\\b\"", "a\\b" },
|
||||
{ "\"a\\\"b\"", "a\"b" },
|
||||
{ "a\"b", "a\"b" },
|
||||
{ "a\\\\\\\\b", "a\\\\b" },
|
||||
{ "a\\\\", "a\\" },
|
||||
{ "\"a\\\\\"", "a\\" },
|
||||
{ "a\\", "a" },
|
||||
{ "\"a b\"", "a b" },
|
||||
{ "a b", "a" },
|
||||
};
|
||||
unsigned i;
|
||||
static char errmsg[128];
|
||||
|
||||
for (i = 0; i < countof(tests); ++i)
|
||||
{
|
||||
const struct test *t = &tests[i];
|
||||
char netrc[128];
|
||||
FILE *fp;
|
||||
acc_t *acc;
|
||||
int n;
|
||||
|
||||
n = snprintf (netrc, sizeof(netrc), "machine localhost\n\tlogin me\n\tpassword %s", t->pw_in);
|
||||
mu_assert ("test_parse_netrc: failed to fmemopen() netrc", (fp = fmemopen(netrc, n, "r")) != NULL);
|
||||
|
||||
acc = parse_netrc_fp ("memory", fp);
|
||||
fclose(fp);
|
||||
|
||||
if (strcmp(acc->passwd, t->pw_expected))
|
||||
{
|
||||
snprintf(errmsg, sizeof(errmsg), "test_parse_netrc: wrong result [%u]. Expected '%s', got '%s'",
|
||||
i, t->pw_expected, acc->passwd);
|
||||
return errmsg;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef STANDALONE
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -65,6 +65,7 @@ all_tests(void)
|
||||
mu_run_test (test_hsts_url_rewrite_congruent);
|
||||
mu_run_test (test_hsts_read_database);
|
||||
#endif
|
||||
mu_run_test (test_parse_netrc);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ const char *test_hsts_new_entry(void);
|
||||
const char *test_hsts_url_rewrite_superdomain(void);
|
||||
const char *test_hsts_url_rewrite_congruent(void);
|
||||
const char *test_hsts_read_database(void);
|
||||
const char *test_parse_netrc(void);
|
||||
|
||||
#endif /* TEST_H */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user