Unit test for has_key.

* src/http.c: Add test_has_key.
* src/test.c (main): Run new test.
* src/test.h: Add test_has_key.
This commit is contained in:
Hubert Tarasiuk 2015-06-23 16:46:39 +02:00 committed by Giuseppe Scrivano
parent 70cbd59ed6
commit 1113e78534
3 changed files with 34 additions and 0 deletions

View File

@ -5048,6 +5048,38 @@ test_find_key_value (void)
return NULL;
}
const char *
test_has_key (void)
{
static const char *header_data = "key1=val2;token1;xyz; token2;xyz;token3 ;"\
"xyz; token4 ;xyz; token5 ";
struct
{
const char *token;
bool result;
} test_array[] =
{
{ "key1=val2", true },
{ "token1", true },
{ "token2", true },
{ "token3", true },
{ "token4", true },
{ "token5", true },
{ "token6", false },
{ "oken1", false },
{ "poken1", false },
{ "key1=val2", true }
};
size_t i;
for (i = 0; i < countof (test_array); ++i)
mu_assert ("test_has_key: wrong result",
has_key (header_data, header_data + strlen (header_data),
test_array[i].token) == test_array[i].result);
return NULL;
}
const char *
test_parse_content_disposition(void)
{

View File

@ -50,6 +50,7 @@ all_tests(void)
{
#ifdef HAVE_METALINK
mu_run_test (test_find_key_value);
mu_run_test (test_has_key);
#endif
mu_run_test (test_parse_content_disposition);
mu_run_test (test_subdir_p);

View File

@ -44,6 +44,7 @@ do { \
} while (0)
const char *test_has_key (void);
const char *test_find_key_value (void);
const char *test_parse_content_disposition(void);
const char *test_commands_sorted(void);