about summary refs log tree commit diff stats
path: root/tests/unittests
diff options
context:
space:
mode:
authorWilliam Wennerström <william@wstrm.dev>2020-12-06 17:02:09 +0100
committerWilliam Wennerström <william@wstrm.dev>2020-12-06 17:02:09 +0100
commitac030378479cf999fefc0889d5c0932cfcabc4fc (patch)
treeaece65906a09f1fc01550e98ecda4511b352a8d7 /tests/unittests
parent1d2c0a8836123c3b484826b974f87a0061bc110b (diff)
downloadprofani-tty-ac030378479cf999fefc0889d5c0932cfcabc4fc.tar.gz
Rework url to filename
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_common.c80
1 files changed, 63 insertions, 17 deletions
diff --git a/tests/unittests/test_common.c b/tests/unittests/test_common.c
index 462676cc..2dee8722 100644
--- a/tests/unittests/test_common.c
+++ b/tests/unittests/test_common.c
@@ -334,77 +334,123 @@ typedef struct
 {
     char* url;
     char* path;
-    char* filename;
+    char* target;
+    char* basename;
 } unique_filename_from_url_t;
 
 void
 unique_filename_from_url_td(void** state)
 {
-    enum table { num_tests = 11 };
+
+    enum table { num_tests = 15 };
+    char* pwd = g_get_current_dir();
 
     unique_filename_from_url_t tests[num_tests] = {
         (unique_filename_from_url_t){
             .url = "https://host.test/image.jpeg",
-            .path = "./",
-            .filename = "./image.jpeg",
+            .path = "./.",
+            .target = pwd,
+            .basename = "image.jpeg",
+        },
+        (unique_filename_from_url_t){
+            .url = "https://host.test/image.jpeg",
+            .path = NULL,
+            .target = pwd,
+            .basename = "image.jpeg",
         },
         (unique_filename_from_url_t){
             .url = "https://host.test/image.jpeg#somefragment",
             .path = "./",
-            .filename = "./image.jpeg",
+            .target = pwd,
+            .basename = "image.jpeg",
         },
         (unique_filename_from_url_t){
             .url = "https://host.test/image.jpeg?query=param",
             .path = "./",
-            .filename = "./image.jpeg",
+            .target = pwd,
+            .basename = "image.jpeg",
         },
         (unique_filename_from_url_t){
             .url = "https://host.test/image.jpeg?query=param&another=one",
             .path = "./",
-            .filename = "./image.jpeg",
+            .target = pwd,
+            .basename = "image.jpeg",
+        },
+        (unique_filename_from_url_t){
+            .url = "https://host.test/image.jpeg?query=param&another=one",
+            .path = "/tmp/",
+            .target = "/tmp/",
+            .basename = "image.jpeg",
+        },
+        (unique_filename_from_url_t){
+            .url = "https://host.test/image.jpeg?query=param&another=one",
+            .path = "/tmp/hopefully/this/file/does/not/exist",
+            .target = "/tmp/hopefully/this/file/does/not/",
+            .basename = "exist",
+        },
+        (unique_filename_from_url_t){
+            .url = "https://host.test/image.jpeg?query=param&another=one",
+            .path = "/tmp/hopefully/this/file/does/not/exist/",
+            .target = "/tmp/hopefully/this/file/does/not/exist/",
+            .basename = "image.jpeg",
         },
         (unique_filename_from_url_t){
             .url = "https://host.test/images/",
             .path = "./",
-            .filename = "./images",
+            .target = pwd,
+            .basename = "images",
         },
         (unique_filename_from_url_t){
             .url = "https://host.test/images/../../file",
             .path = "./",
-            .filename = "./file",
+            .target = pwd,
+            .basename = "file",
         },
         (unique_filename_from_url_t){
             .url = "https://host.test/images/../../file/..",
             .path = "./",
-            .filename = "./index.html",
+            .target = pwd,
+            .basename = "index",
         },
         (unique_filename_from_url_t){
             .url = "https://host.test/images/..//",
             .path = "./",
-            .filename = "./index.html",
+            .target = pwd,
+            .basename = "index",
         },
         (unique_filename_from_url_t){
             .url = "https://host.test/",
             .path = "./",
-            .filename = "./index.html",
+            .target = pwd,
+            .basename = "index",
         },
         (unique_filename_from_url_t){
             .url = "https://host.test",
             .path = "./",
-            .filename = "./index.html",
+            .target = pwd,
+            .basename = "index",
         },
         (unique_filename_from_url_t){
             .url = "aesgcm://host.test",
             .path = "./",
-            .filename = "./index.html",
+            .target = pwd,
+            .basename = "index",
         },
     };
 
-    char* filename;
+    char* got_filename;
+    char* exp_filename;
     for (int i = 0; i < num_tests; i++) {
-        filename = unique_filename_from_url(tests[i].url, tests[i].path);
-        assert_string_equal(filename, tests[i].filename);
+        got_filename = unique_filename_from_url(tests[i].url, tests[i].path);
+        exp_filename = g_build_filename(tests[i].target, tests[i].basename, NULL);
+
+        assert_string_equal(got_filename, exp_filename);
+
+        free(got_filename);
+        free(exp_filename);
     }
+
+    g_free(pwd);
 }
 
 gboolean