mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
Unit test for find_key_values.
* src/http.c: Add test_find_key_values. * src/test.c (main): Run new test. * src/test.h: Add test_find_key_values.
This commit is contained in:
parent
1113e78534
commit
92a889b278
44
src/http.c
44
src/http.c
@ -5000,6 +5000,50 @@ ensure_extension (struct http_stat *hs, const char *ext, int *dt)
|
||||
|
||||
#ifdef TESTING
|
||||
|
||||
const char *
|
||||
test_find_key_values (void)
|
||||
{
|
||||
static const char *header_data = "key1=val1;key2=val2 ;key3=val3; key4=val4"\
|
||||
" ; key5=val5;key6 =val6;key7= val7; "\
|
||||
"key8 = val8 ; key9 = val9 "\
|
||||
" ,key10= val10,key11,key12=val12";
|
||||
static const struct
|
||||
{
|
||||
const char *key;
|
||||
const char *val;
|
||||
} test_array[] =
|
||||
{
|
||||
{ "key1", "val1" },
|
||||
{ "key2", "val2" },
|
||||
{ "key3", "val3" },
|
||||
{ "key4", "val4" },
|
||||
{ "key5", "val5" },
|
||||
{ "key6", "val6" },
|
||||
{ "key7", "val7" },
|
||||
{ "key8", "val8" },
|
||||
{ "key9", "val9" },
|
||||
{ "key10", "val10" },
|
||||
{ "key12", "val12" }
|
||||
};
|
||||
const char *pos;
|
||||
char *key, *value;
|
||||
size_t i = 0;
|
||||
|
||||
for (pos = header_data; (pos = find_key_values (pos,
|
||||
header_data + strlen (header_data),
|
||||
&key, &value)); pos++)
|
||||
{
|
||||
mu_assert ("test_find_key_values: wrong result",
|
||||
!strcmp (test_array[i].val, value) &&
|
||||
!strcmp (test_array[i].key, key));
|
||||
xfree (key);
|
||||
xfree (value);
|
||||
i++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
test_find_key_value (void)
|
||||
{
|
||||
|
@ -50,6 +50,7 @@ all_tests(void)
|
||||
{
|
||||
#ifdef HAVE_METALINK
|
||||
mu_run_test (test_find_key_value);
|
||||
mu_run_test (test_find_key_values);
|
||||
mu_run_test (test_has_key);
|
||||
#endif
|
||||
mu_run_test (test_parse_content_disposition);
|
||||
|
@ -46,6 +46,7 @@ do { \
|
||||
|
||||
const char *test_has_key (void);
|
||||
const char *test_find_key_value (void);
|
||||
const char *test_find_key_values (void);
|
||||
const char *test_parse_content_disposition(void);
|
||||
const char *test_commands_sorted(void);
|
||||
const char *test_cmd_spec_restrict_file_names(void);
|
||||
|
Loading…
Reference in New Issue
Block a user