]> granicus.if.org Git - esp-idf/commitdiff
HTTP Server : Unit test added for httpd_uri_match_wildcard() function as given in...
authorAnurag Kar <anurag.kar@espressif.com>
Wed, 9 Jan 2019 21:29:23 +0000 (02:59 +0530)
committerAnurag Kar <anurag.kar@espressif.com>
Mon, 14 Jan 2019 03:29:55 +0000 (08:59 +0530)
components/esp_http_server/test/test_http_server.c

index e343c99ca41e5b656340407e2cce938c22976951..682a54d039a492f5473cc6532a71c4db67c7f1c6 100644 (file)
@@ -167,3 +167,68 @@ TEST_CASE("Basic Functionality Tests", "[HTTP SERVER]")
     test_handler_limit(hd);
     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++;
+    }
+}