[vlc-commits] https: improve file test coverage

Rémi Denis-Courmont git at videolan.org
Fri Dec 18 21:07:45 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Dec 18 21:34:14 2015 +0200| [547418a7cd1968a445afef9696572e7acc3d03c1] | committer: Rémi Denis-Courmont

https: improve file test coverage

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=547418a7cd1968a445afef9696572e7acc3d03c1
---

 modules/access/http/file_test.c |   45 +++++++++++++++++++++++++++++++++++----
 1 file changed, 41 insertions(+), 4 deletions(-)

diff --git a/modules/access/http/file_test.c b/modules/access/http/file_test.c
index a5302c1..713964c 100644
--- a/modules/access/http/file_test.c
+++ b/modules/access/http/file_test.c
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * message_test.c: HTTP request/response
+ * file_test.c: HTTP file download test
  *****************************************************************************
  * Copyright (C) 2015 Rémi Denis-Courmont
  *
@@ -38,6 +38,7 @@ static const char ua[] = PACKAGE_NAME "/" PACKAGE_VERSION " (test suite)";
 
 static const char *replies[2] = { NULL, NULL };
 static uintmax_t offset = 0;
+static bool etags = false;
 
 int main(void)
 {
@@ -63,6 +64,7 @@ int main(void)
                  "\r\n";
 
     offset = 0;
+    etags = true;
     f = vlc_http_file_create(NULL, url, ua, NULL);
     assert(f != NULL);
     assert(vlc_http_file_get_status(f) == 200);
@@ -82,6 +84,7 @@ int main(void)
     replies[0] = "HTTP/1.1 206 Partial Content\r\n"
                  "Content-Range: bytes 0-2344/2345\r\n"
                  "ETag: W/\"foobar42\"\r\n"
+                 "Last-Modified: Mon, 21 Oct 2013 20:13:22 GMT\r\n"
                  "\r\n";
 
     offset = 0;
@@ -89,20 +92,24 @@ int main(void)
     assert(f != NULL);
     assert(vlc_http_file_can_seek(f));
     assert(vlc_http_file_get_size(f) == 2345);
+    assert(vlc_http_file_read(f) == NULL);
 
     /* Seek success */
     replies[0] = "HTTP/1.1 206 Partial Content\r\n"
                  "Content-Range: bytes 1234-3455/3456\r\n"
                  "ETag: W/\"foobar42\"\r\n"
+                 "Last-Modified: Mon, 21 Oct 2013 20:13:22 GMT\r\n"
                  "\r\n";
     assert(vlc_http_file_seek(f, offset = 1234) == 0);
     assert(vlc_http_file_can_seek(f));
     assert(vlc_http_file_get_size(f) == 3456);
+    assert(vlc_http_file_read(f) == NULL);
 
     /* Seek too far */
     replies[0] = "HTTP/1.1 416 Range Not Satisfiable\r\n"
                  "Content-Range: bytes */4567\r\n"
                  "ETag: W/\"foobar42\"\r\n"
+                 "Last-Modified: Mon, 21 Oct 2013 20:13:22 GMT\r\n"
                  "\r\n";
     vlc_http_file_seek(f, offset = 5678);
     assert(vlc_http_file_can_seek(f));
@@ -139,6 +146,25 @@ int main(void)
     assert(vlc_http_file_get_redirect(f) == NULL);
     vlc_http_file_destroy(f);
 
+    /* No entity tags */
+    replies[0] = "HTTP/1.1 206 Partial Content\r\n"
+                 "Content-Range: bytes 0-2344/2345\r\n"
+                 "Last-Modified: Mon, 21 Oct 2013 20:13:22 GMT\r\n"
+                 "\r\n";
+
+    offset = 0;
+    etags = false;
+    f = vlc_http_file_create(NULL, url, ua, NULL);
+    assert(f != NULL);
+    assert(vlc_http_file_can_seek(f));
+
+    replies[0] = "HTTP/1.1 206 Partial Content\r\n"
+                 "Content-Range: bytes 1234-3455/3456\r\n"
+                 "Last-Modified: Mon, 21 Oct 2013 20:13:22 GMT\r\n"
+                 "\r\n";
+    assert(vlc_http_file_seek(f, offset = 1234) == 0);
+    vlc_http_file_destroy(f);
+
 
     /* Dummy API calls */
     f = vlc_http_file_create(NULL, "ftp://localhost/foo", NULL, NULL);
@@ -238,11 +264,22 @@ struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr,
     assert(str != NULL && !strncmp(str, "bytes=", 6)
         && strtoul(str + 6, &end, 10) == offset && *end == '-');
 
+    time_t mtime = vlc_http_msg_get_time(req, "If-Unmodified-Since");
     str = vlc_http_msg_get_header(req, "If-Match");
-    if (offset != 0)
-        assert(str != NULL && !strcmp(str, "\"foobar42\""));
+
+    if (etags)
+    {
+        if (offset != 0)
+            assert(str != NULL && !strcmp(str, "\"foobar42\""));
+        else
+        if (str != NULL)
+            assert(strcmp(str, "*") || strcmp(str, "\"foobar42\""));
+    }
     else
-        assert(str == NULL || strcmp(str, "*") || strcmp(str, "\"foobar42\""));
+    {
+        if (offset != 0)
+            assert(mtime == 1382386402);
+    }
 
     return vlc_http_stream_read_headers(&stream);
 }



More information about the vlc-commits mailing list