1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00
profanity/tests/unittests/test_http_download.c

76 lines
1.9 KiB
C
Raw Normal View History

#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "config.h"
#include "tools/http_download.h"
2020-07-20 07:01:05 -04:00
typedef struct
{
char* url;
char* basename;
} url_test_t;
2020-07-20 07:01:05 -04:00
void
http_basename_from_url_td(void** state)
{
int num_tests = 11;
url_test_t tests[] = {
2020-07-20 07:01:05 -04:00
(url_test_t){
.url = "https://host.test/image.jpeg",
.basename = "image.jpeg",
},
(url_test_t){
.url = "https://host.test/image.jpeg#somefragment",
.basename = "image.jpeg",
},
(url_test_t){
.url = "https://host.test/image.jpeg?query=param",
.basename = "image.jpeg",
},
(url_test_t){
.url = "https://host.test/image.jpeg?query=param&another=one",
.basename = "image.jpeg",
},
(url_test_t){
.url = "https://host.test/images/",
.basename = "images",
},
(url_test_t){
.url = "https://host.test/images/../../file",
.basename = "file",
},
(url_test_t){
.url = "https://host.test/images/../../file/..",
.basename = "index.html",
},
(url_test_t){
.url = "https://host.test/images/..//",
.basename = "index.html",
},
(url_test_t){
.url = "https://host.test/",
.basename = "index.html",
},
(url_test_t){
.url = "https://host.test",
.basename = "index.html",
},
(url_test_t){
.url = "aesgcm://host.test",
.basename = "index.html",
},
};
2020-07-20 07:01:05 -04:00
char* basename;
for (int i = 0; i < num_tests; i++) {
basename = http_basename_from_url(tests[i].url);
assert_string_equal(basename, tests[i].basename);
}
}