diff --git a/src/http.c b/src/http.c index 0d652d63..e2e98f5a 100644 --- a/src/http.c +++ b/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) { diff --git a/src/test.c b/src/test.c index 8ba40c9d..9599ac40 100644 --- a/src/test.c +++ b/src/test.c @@ -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); diff --git a/src/test.h b/src/test.h index a8ccaf96..6d5cbbe5 100644 --- a/src/test.h +++ b/src/test.h @@ -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);