test: Move generated image files out of source dir

Simplifies cleaning up.
This commit is contained in:
Kim Woelders 2022-01-17 15:47:57 +01:00
parent 0d6211c501
commit da2ce0d94b
9 changed files with 43 additions and 33 deletions

3
test/.gitignore vendored
View File

@ -1,4 +1 @@
/*.d
/images/empty.*
/images/nonex.*
/images/icon-64.*.*

View File

@ -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

3
test/test_common.h Normal file
View File

@ -0,0 +1,3 @@
#define IMG_SRC SRC_DIR "/images"
#define IMG_GEN BLD_DIR "/generated"

View File

@ -3,6 +3,9 @@
#include <X11/Xutil.h>
#include <Imlib2.h>
#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();
}

View File

@ -4,6 +4,7 @@
#include <fcntl.h>
#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();
}

View File

@ -5,6 +5,7 @@
#include <zlib.h>
#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);

View File

@ -4,13 +4,12 @@
#include <zlib.h>
#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();
}

View File

@ -2,6 +2,9 @@
#include <Imlib2.h>
#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();
}

View File

@ -4,13 +4,12 @@
#include <zlib.h>
#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();
}