diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/config.c | 54 | ||||
-rw-r--r-- | src/tests/fs.c | 74 |
2 files changed, 128 insertions, 0 deletions
diff --git a/src/tests/config.c b/src/tests/config.c new file mode 100644 index 0000000..8d86a2f --- /dev/null +++ b/src/tests/config.c @@ -0,0 +1,54 @@ +#include <string.h> + +#include "tests/tests.h" +#include "config.h" +#include "log.h" + +#define TESTS_DIR "tests" +#define TEST_ALBUM "tests/album.ini" + +static void +test_site_config_read_ini(void) +{ + struct site_config *config = site_config_init(); + asserteq(site_config_read_ini(TESTS_DIR, config), true); + asserteq(strcmp(config->title, "An example gallery"), 0); + asserteq(strcmp(config->base_url, "http://www.example.com/photos"), 0); + asserteq(config->max_previews, 20); + asserteq(config->images.strip, false); + asserteq(config->images.quality, 80); + asserteq(config->images.max_width, 3000); + asserteq(config->images.max_height, 2000); + asserteq(config->images.smart_resize, true); + asserteq(config->thumbnails.strip, true); + asserteq(config->thumbnails.quality, 75); + asserteq(config->thumbnails.max_width, 400); + asserteq(config->thumbnails.max_height, 270); + asserteq(config->thumbnails.smart_resize, true); + site_config_destroy(config); +} + +static void +test_album_config_read_ini(void) +{ + struct album_config *config = album_config_init(); + asserteq(album_config_read_ini(TEST_ALBUM, config), true); + asserteq(strcmp(config->title, "An example album"), 0); + asserteq(strcmp(config->desc, "Example description"), 0); + album_config_destroy(config); +} + +static void +init(void) +{ + log_set_verbosity(LOG_SILENT); +} + +int +main(void) +{ + INIT_TESTS(); + init(); + RUN_TEST(test_site_config_read_ini); + RUN_TEST(test_album_config_read_ini); +} diff --git a/src/tests/fs.c b/src/tests/fs.c new file mode 100644 index 0000000..db8ab96 --- /dev/null +++ b/src/tests/fs.c @@ -0,0 +1,74 @@ +#include "tests/tests.h" +#include "fs.h" + +#include <time.h> +#include <string.h> + +#define DATETIME_TEST_FILE "tests/empty" + +static void +test_rbasename(void) +{ + char *a = "/path/to/hello.jpg"; + const char *ob; + ob = rbasename(a); + asserteq(strcmp(ob, "hello.jpg"), 0); +} + +static void +test_joinpath(void) +{ + char *a = "hello", *b = "world.jpeg"; + char *joined = joinpath(a, b); + asserteq(strcmp(joined, "hello/world.jpeg"), 0); + free(joined); +} + +static void +test_isimage(void) +{ + char *a = "hello.jpg", *b = "goodbye.jpeg", *c = "iamge.png", *d = "b.tiff"; + char *notimg = "image.exe"; + asserteq(isimage(a), true); + asserteq(isimage(b), true); + asserteq(isimage(c), true); + asserteq(isimage(d), true); + asserteq(isimage(notimg), false); +} + +static void +test_delext(void) +{ + char *na = "hello.jpg", *nb = "goodbye.tar.gz"; + size_t bla = 16, blb = 16, blc = 4; + char bufa[bla], bufb[blb], bufc[blc]; + delext(na, bufa, bla); + asserteq(strcmp(bufa, "hello"), 0); + delext(nb, bufb, blb); + asserteq(strcmp(bufb, "goodbye.tar"), 0); + delext(nb, bufc, blc); +} + +static void +test_setdatetime_uptodate(void) +{ + time_t now = time(NULL); + struct timespec mtim = { + .tv_sec = now, + .tv_nsec = 690, + }; + asserteq(file_is_uptodate(DATETIME_TEST_FILE, &mtim), 0); + setdatetime(DATETIME_TEST_FILE, &mtim); + asserteq(file_is_uptodate(DATETIME_TEST_FILE, &mtim), 1); +} + +int +main(void) +{ + INIT_TESTS(); + RUN_TEST(test_rbasename); + RUN_TEST(test_joinpath); + RUN_TEST(test_isimage); + RUN_TEST(test_delext); + RUN_TEST(test_setdatetime_uptodate); +} |