mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-01 03:34:32 +02:00
HTTP Server : Unit test added for httpd_uri_match_wildcard() function as given in https://github.com/espressif/esp-idf/pull/2581#issuecomment-430788473
This commit is contained in:
@@ -167,3 +167,68 @@ TEST_CASE("Basic Functionality Tests", "[HTTP SERVER]")
|
|||||||
test_handler_limit(hd);
|
test_handler_limit(hd);
|
||||||
TEST_ASSERT(httpd_stop(hd) == ESP_OK);
|
TEST_ASSERT(httpd_stop(hd) == ESP_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("URI Wildcard Matcher Tests", "[HTTP SERVER]")
|
||||||
|
{
|
||||||
|
struct uritest {
|
||||||
|
const char *template;
|
||||||
|
const char *uri;
|
||||||
|
bool matches;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct uritest uris[] = {
|
||||||
|
{"/", "/", true},
|
||||||
|
{"", "", true},
|
||||||
|
{"/", "", false},
|
||||||
|
{"/wrong", "/", false},
|
||||||
|
{"/", "/wrong", false},
|
||||||
|
{"/asdfghjkl/qwertrtyyuiuioo", "/asdfghjkl/qwertrtyyuiuioo", true},
|
||||||
|
{"/path", "/path", true},
|
||||||
|
{"/path", "/path/", false},
|
||||||
|
{"/path/", "/path", false},
|
||||||
|
|
||||||
|
{"?", "", false}, // this is not valid, but should not crash
|
||||||
|
{"?", "sfsdf", false},
|
||||||
|
|
||||||
|
{"/path/?", "/pa", false},
|
||||||
|
{"/path/?", "/path", true},
|
||||||
|
{"/path/?", "/path/", true},
|
||||||
|
{"/path/?", "/path/alalal", false},
|
||||||
|
|
||||||
|
{"/path/*", "/path", false},
|
||||||
|
{"/path/*", "/", false},
|
||||||
|
{"/path/*", "/path/", true},
|
||||||
|
{"/path/*", "/path/blabla", true},
|
||||||
|
|
||||||
|
{"*", "", true},
|
||||||
|
{"*", "/", true},
|
||||||
|
{"*", "/aaa", true},
|
||||||
|
|
||||||
|
{"/path/?*", "/pat", false},
|
||||||
|
{"/path/?*", "/pathb", false},
|
||||||
|
{"/path/?*", "/pathxx", false},
|
||||||
|
{"/path/?*", "/pathblabla", false},
|
||||||
|
{"/path/?*", "/path", true},
|
||||||
|
{"/path/?*", "/path/", true},
|
||||||
|
{"/path/?*", "/path/blabla", true},
|
||||||
|
|
||||||
|
{"/path/*?", "/pat", false},
|
||||||
|
{"/path/*?", "/pathb", false},
|
||||||
|
{"/path/*?", "/pathxx", false},
|
||||||
|
{"/path/*?", "/path", true},
|
||||||
|
{"/path/*?", "/path/", true},
|
||||||
|
{"/path/*?", "/path/blabla", true},
|
||||||
|
|
||||||
|
{"/path/*/xxx", "/path/", false},
|
||||||
|
{"/path/*/xxx", "/path/*/xxx", true},
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct uritest *ut = &uris[0];
|
||||||
|
|
||||||
|
while(ut->template != 0) {
|
||||||
|
bool match = httpd_uri_match_wildcard(ut->template, ut->uri, strlen(ut->uri));
|
||||||
|
TEST_ASSERT(match == ut->matches);
|
||||||
|
ut++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user