From da2ce0d94b8f05f1b7a62c846b8bef2c233e201c Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Mon, 17 Jan 2022 15:47:57 +0100 Subject: test: Move generated image files out of source dir Simplifies cleaning up. --- test/.gitignore | 3 --- test/Makefile.am | 2 +- test/test_common.h | 3 +++ test/test_grab.cpp | 7 ++++++- test/test_load.cpp | 20 +++++++++++--------- test/test_load_2.cpp | 6 ++---- test/test_rotate.cpp | 9 +++++---- test/test_save.cpp | 17 ++++++++++------- test/test_scale.cpp | 9 +++++---- 9 files changed, 43 insertions(+), 33 deletions(-) create mode 100644 test/test_common.h diff --git a/test/.gitignore b/test/.gitignore index 375cb30..ab836ea 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,4 +1 @@ /*.d -/images/empty.* -/images/nonex.* -/images/icon-64.*.* diff --git a/test/Makefile.am b/test/Makefile.am index fcbd305..f4ace28 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -22,7 +22,7 @@ CLEANFILES = file.c img_save-*.* AM_CPPFLAGS = -I $(top_builddir) -I $(top_srcdir)/src/lib AM_CPPFLAGS += -I $(top_builddir)/src/lib - AM_CPPFLAGS += -D SRC_DIR='"$(top_srcdir)"' + AM_CPPFLAGS += -D SRC_DIR='"$(srcdir)"' -D BLD_DIR='"$(builddir)"' AM_CPPFLAGS += -D BUILD_TEST=1 # Must have proper -lImlib2 on all progs diff --git a/test/test_common.h b/test/test_common.h new file mode 100644 index 0000000..34b09d5 --- /dev/null +++ b/test/test_common.h @@ -0,0 +1,3 @@ + +#define IMG_SRC SRC_DIR "/images" +#define IMG_GEN BLD_DIR "/generated" diff --git a/test/test_grab.cpp b/test/test_grab.cpp index 665cfc5..06165cb 100644 --- a/test/test_grab.cpp +++ b/test/test_grab.cpp @@ -3,6 +3,9 @@ #include #include +#include "config.h" +#include "test_common.h" + typedef struct { Display *dpy; Window root; @@ -157,7 +160,7 @@ _test_grab_1(int w, int h, int x0, int y0) im = imlib_create_scaled_image_from_drawable(None, x0, y0, w, h, ws, hs, 0, 0); imlib_context_set_image(im); - snprintf(buf, sizeof(buf), "%s-%%d.png", xd.test); + snprintf(buf, sizeof(buf), "%s/%s-%%d.png", IMG_GEN, xd.test); _img_dump(im, buf); dptr = imlib_image_get_data_for_reading_only(); @@ -342,5 +345,7 @@ main(int argc, char **argv) } } + mkdir(IMG_GEN, 0755); + return RUN_ALL_TESTS(); } diff --git a/test/test_load.cpp b/test/test_load.cpp index 1728263..6a3e3b2 100644 --- a/test/test_load.cpp +++ b/test/test_load.cpp @@ -4,6 +4,7 @@ #include #include "config.h" +#include "test_common.h" int debug = 0; @@ -13,8 +14,6 @@ int debug = 0; #define EXPECT_OK(x) EXPECT_FALSE(x) #define EXPECT_ERR(x) EXPECT_TRUE(x) -#define TOPDIR SRC_DIR -#define IMGDIR TOPDIR "/test/images" #define FILE_REF "icon-64.png" static const char *const pfxs[] = { @@ -78,7 +77,7 @@ test_load(void) int fd; int err; - snprintf(filei, sizeof(filei), "%s/%s", IMGDIR, FILE_REF); + snprintf(filei, sizeof(filei), "%s/%s", IMG_SRC, FILE_REF); D("Load '%s'\n", filei); im = imlib_load_image(filei); @@ -89,7 +88,7 @@ test_load(void) for (i = 0; i < N_PFX; i++) { // Load files of all types - snprintf(fileo, sizeof(fileo), "%s/%s.%s", IMGDIR, "icon-64", pfxs[i]); + snprintf(fileo, sizeof(fileo), "%s/%s.%s", IMG_SRC, "icon-64", pfxs[i]); D("Load '%s'\n", fileo); im = imlib_load_image_with_error_return(fileo, &lerr); EXPECT_TRUE(im); @@ -103,11 +102,12 @@ test_load(void) if (strchr(pfxs[i], '.') == 0) { - snprintf(filei, sizeof(filei), "%s.%s", "icon-64", pfxs[i]); + snprintf(filei, sizeof(filei), + "../%s/%s.%s", IMG_SRC, "icon-64", pfxs[i]); for (j = 0; j < N_PFX; j++) { // Load certain types pretending they are something else - snprintf(fileo, sizeof(fileo), "%s/%s.%s.%s", IMGDIR, + snprintf(fileo, sizeof(fileo), "%s/%s.%s.%s", IMG_GEN, "icon-64", pfxs[i], pfxs[j]); unlink(fileo); symlink(filei, fileo); @@ -123,7 +123,7 @@ test_load(void) } // Empty files of all types - snprintf(fileo, sizeof(fileo), "%s/%s.%s", IMGDIR, "empty", pfxs[i]); + snprintf(fileo, sizeof(fileo), "%s/%s.%s", IMG_GEN, "empty", pfxs[i]); unlink(fileo); fp = fopen(fileo, "wb"); fclose(fp); @@ -133,7 +133,7 @@ test_load(void) EXPECT_TRUE(lerr == IMLIB_LOAD_ERROR_UNKNOWN); // Non-existing files of all types - snprintf(fileo, sizeof(fileo), "%s/%s.%s", IMGDIR, "nonex", pfxs[i]); + snprintf(fileo, sizeof(fileo), "%s/%s.%s", IMG_GEN, "nonex", pfxs[i]); unlink(fileo); symlink("non-existing", fileo); D("Load non-existing '%s'\n", fileo); @@ -141,7 +141,7 @@ test_load(void) EXPECT_EQ(lerr, IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST); // Load via fd - snprintf(fileo, sizeof(fileo), "%s/%s.%s", IMGDIR, "icon-64", pfxs[i]); + snprintf(fileo, sizeof(fileo), "%s/%s.%s", IMG_SRC, "icon-64", pfxs[i]); fd = open(fileo, O_RDONLY); D("Load fd %d '%s'\n", fd, fileo); snprintf(fileo, sizeof(fileo), ".%s", pfxs[i]); @@ -186,5 +186,7 @@ main(int argc, char **argv) } } + mkdir(IMG_GEN, 0755); + return RUN_ALL_TESTS(); } diff --git a/test/test_load_2.cpp b/test/test_load_2.cpp index 59b10ac..8ae1f01 100644 --- a/test/test_load_2.cpp +++ b/test/test_load_2.cpp @@ -5,6 +5,7 @@ #include #include "config.h" +#include "test_common.h" int debug = 0; @@ -13,9 +14,6 @@ int debug = 0; #define EXPECT_OK(x) EXPECT_FALSE(x) #define EXPECT_ERR(x) EXPECT_TRUE(x) -#define TOPDIR SRC_DIR -#define IMGDIR TOPDIR "/test/images" - typedef struct { const char *name; unsigned int crc; @@ -71,7 +69,7 @@ TEST(LOAD2, load_1) fn = tii[i].name; if (*fn != '/') { - snprintf(buf, sizeof(buf), "%s/%s", IMGDIR, fn); + snprintf(buf, sizeof(buf), "%s/%s", IMG_SRC, fn); fn = buf; } D("Load '%s'\n", fn); diff --git a/test/test_rotate.cpp b/test/test_rotate.cpp index df467bc..5a25d11 100644 --- a/test/test_rotate.cpp +++ b/test/test_rotate.cpp @@ -4,13 +4,12 @@ #include #include "config.h" +#include "test_common.h" int debug = 0; #define D(...) if (debug) printf(__VA_ARGS__) -#define TOPDIR SRC_DIR -#define FILE_DIR "test/images" #define FILE_REF1 "icon-64" // RGB #define FILE_REF2 "xeyes" // ARGB (shaped) @@ -70,7 +69,7 @@ test_rotate(int no, int aa) ic += 2; #endif - snprintf(filei, sizeof(filei), "%s/%s/%s.png", TOPDIR, FILE_DIR, ptd->file); + snprintf(filei, sizeof(filei), "%s/%s.png", IMG_SRC, ptd->file); D("Load '%s'\n", filei); imi = imlib_load_image(filei); ASSERT_TRUE(imi); @@ -93,7 +92,7 @@ test_rotate(int no, int aa) ho = imlib_image_get_height(); snprintf(fileo, sizeof(fileo), "%s/rotate-%s-%dx%d-%d.%s", - ".", ptd->file, wo, ho, i, "png"); + IMG_GEN, ptd->file, wo, ho, i, "png"); imlib_image_set_format("png"); D("Save '%s'\n", fileo); imlib_save_image_with_error_return(fileo, &lerr); @@ -153,5 +152,7 @@ main(int argc, char **argv) } } + mkdir(IMG_GEN, 0755); + return RUN_ALL_TESTS(); } diff --git a/test/test_save.cpp b/test/test_save.cpp index 96c19c2..eed94b1 100644 --- a/test/test_save.cpp +++ b/test/test_save.cpp @@ -2,6 +2,9 @@ #include +#include "config.h" +#include "test_common.h" + int debug = 0; #define D(...) if (debug) printf(__VA_ARGS__) @@ -9,8 +12,6 @@ int debug = 0; #define EXPECT_OK(x) EXPECT_FALSE(x) #define EXPECT_ERR(x) EXPECT_TRUE(x) -#define TOPDIR SRC_DIR -#define FILE_DIR "test/images" #define FILE_REF1 "icon-64" // RGB #define FILE_REF2 "xeyes" // ARGB (shaped) @@ -58,7 +59,7 @@ test_save(const char *file, int prog) imlib_context_set_progress_granularity(10); } - snprintf(filei, sizeof(filei), "%s/%s/%s.png", TOPDIR, FILE_DIR, file); + snprintf(filei, sizeof(filei), "%s/%s.png", IMG_SRC, file); D("Load '%s'\n", filei); im = imlib_load_image(filei); ASSERT_TRUE(im); @@ -86,7 +87,7 @@ test_save(const char *file, int prog) w = imlib_image_get_width(); h = imlib_image_get_height(); snprintf(fileo, sizeof(fileo), "%s/save-%s-%dx%d.%s", - ".", file, w, h, pfxs[i]); + IMG_GEN, file, w, h, pfxs[i]); D("Save '%s'\n", fileo); imlib_save_image_with_error_return(fileo, &lerr); EXPECT_EQ(lerr, 0); @@ -98,7 +99,7 @@ test_save(const char *file, int prog) w = imlib_image_get_width(); h = imlib_image_get_height(); snprintf(fileo, sizeof(fileo), "%s/save-%s-%dx%d.%s", - ".", file, w, h, pfxs[i]); + IMG_GEN, file, w, h, pfxs[i]); D("Save '%s'\n", fileo); imlib_save_image_with_error_return(fileo, &lerr); EXPECT_EQ(lerr, 0); @@ -110,7 +111,7 @@ test_save(const char *file, int prog) w = imlib_image_get_width(); h = imlib_image_get_height(); snprintf(fileo, sizeof(fileo), "%s/save-%s-%dx%d.%s", - ".", file, w, h, pfxs[i]); + IMG_GEN, file, w, h, pfxs[i]); D("Save '%s'\n", fileo); imlib_save_image_with_error_return(fileo, &lerr); EXPECT_EQ(lerr, 0); @@ -122,7 +123,7 @@ test_save(const char *file, int prog) w = imlib_image_get_width(); h = imlib_image_get_height(); snprintf(fileo, sizeof(fileo), "%s/save-%s-%dx%d.%s", - ".", file, w, h, pfxs[i]); + IMG_GEN, file, w, h, pfxs[i]); D("Save '%s'\n", fileo); imlib_save_image_with_error_return(fileo, &lerr); EXPECT_EQ(lerr, 0); @@ -184,5 +185,7 @@ main(int argc, char **argv) } } + mkdir(IMG_GEN, 0755); + return RUN_ALL_TESTS(); } diff --git a/test/test_scale.cpp b/test/test_scale.cpp index c5f2894..6771cbe 100644 --- a/test/test_scale.cpp +++ b/test/test_scale.cpp @@ -4,13 +4,12 @@ #include #include "config.h" +#include "test_common.h" int debug = 0; #define D(...) if (debug) printf(__VA_ARGS__) -#define TOPDIR SRC_DIR -#define FILE_DIR "test/images" #define FILE_REF1 "icon-64" // RGB #define FILE_REF2 "xeyes" // ARGB (shaped) @@ -47,7 +46,7 @@ test_scale(int no) #endif ptd = &td[no]; - snprintf(filei, sizeof(filei), "%s/%s/%s.png", TOPDIR, FILE_DIR, ptd->file); + snprintf(filei, sizeof(filei), "%s/%s.png", IMG_SRC, ptd->file); D("Load '%s'\n", filei); imi = imlib_load_image(filei); ASSERT_TRUE(imi); @@ -78,7 +77,7 @@ test_scale(int no) EXPECT_EQ(crc, ptd->crcs[i]); snprintf(fileo, sizeof(fileo), "%s/scale-%s-%dx%d.%s", - ".", ptd->file, w, h, "png"); + IMG_GEN, ptd->file, w, h, "png"); imlib_image_set_format("png"); D("Save '%s'\n", fileo); imlib_save_image_with_error_return(fileo, &lerr); @@ -124,5 +123,7 @@ main(int argc, char **argv) } } + mkdir(IMG_GEN, 0755); + return RUN_ALL_TESTS(); } -- cgit v1.2.1