From 2f41ed2fafe2596ef2bee6cf5103403ccbbd430c Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 13 Jul 2024 12:24:03 -0400 Subject: Add download() tests --- tests/test_download.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/test_download.c diff --git a/tests/test_download.c b/tests/test_download.c new file mode 100644 index 0000000..cee7683 --- /dev/null +++ b/tests/test_download.c @@ -0,0 +1,50 @@ +#include "testing.h" + +void test_download() { + struct testcase { + const char *url; + long http_code; + const char *data; + const char *errmsg; + }; + struct testcase tc[] = { + {.url = "https://ssb.stsci.edu/jhunk/stasis_test/test_download.txt", .http_code = 200L, .data = "It works!\n", .errmsg = NULL}, + {.url = "https://ssb.stsci.edu/jhunk/stasis_test/test_download.broken", .http_code = 404L, .data = "= 0) { + STASIS_ASSERT(data != NULL, "data should not be null"); + STASIS_ASSERT(strncmp(data[0], tc[i].data, strlen(tc[i].data)) == 0, "data file does not match the expected contents"); + } else { + STASIS_ASSERT(http_code == -1, "http_code should be -1 on fatal curl error"); + STASIS_ASSERT(data == NULL, "data should be NULL on fatal curl error"); + } + guard_free(data); + remove(filename); + } +} + +int main(int argc, char *argv[]) { + STASIS_TEST_BEGIN_MAIN(); + STASIS_TEST_FUNC *tests[] = { + test_download, + }; + STASIS_TEST_RUN(tests); + STASIS_TEST_END_MAIN(); +} \ No newline at end of file -- cgit