kwo pushed a commit to branch master. http://git.enlightenment.org/legacy/imlib2.git/commit/?id=81b4e7b56bdc5351ddf73629f0a5f22733f2dd3d
commit 81b4e7b56bdc5351ddf73629f0a5f22733f2dd3d Author: Kim Woelders <[email protected]> Date: Thu Oct 7 06:56:38 2021 +0200 test: Add test_load_2 Checking signature (CRC) of loaded images. --- test/Makefile.am | 4 +++ test/test_load_2.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/test/Makefile.am b/test/Makefile.am index 779faf1..aa631af 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -8,6 +8,7 @@ CLEANFILES = file.c img_save-*.* GTESTS = test_file GTESTS += test_load + GTESTS += test_load_2 GTESTS += test_save AM_CFLAGS = -Wall -Wextra -Werror -Wno-unused-parameter @@ -34,6 +35,9 @@ test_file_LDADD = $(LIBS) test_load_SOURCES = test_load.cpp test_load_LDADD = $(LIBS) +test_load_2_SOURCES = test_load_2.cpp +test_load_2_LDADD = $(LIBS) -lz + test_save_SOURCES = test_save.cpp test_save_LDADD = $(LIBS) diff --git a/test/test_load_2.cpp b/test/test_load_2.cpp new file mode 100644 index 0000000..766a60d --- /dev/null +++ b/test/test_load_2.cpp @@ -0,0 +1,95 @@ +#include <gtest/gtest.h> + +#include <Imlib2.h> +#include <fcntl.h> +#include <zlib.h> + +int debug = 0; + +#define D(...) if (debug) printf(__VA_ARGS__) + +#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; +} tii_t; + +static tii_t tii[] = { +/**INDENT-OFF**/ + { "icon-64.argb", 1153555547 }, + { "icon-64.bmp", 1153555547 }, + { "icon-64.ff", 1153555547 }, + { "icon-64.ff.bz2", 1153555547 }, + { "icon-64.gif", 1768448874 }, + { "icon-64.ico", 1153555547 }, + { "icon-64.ilbm", 1153555547 }, + { "icon-64.jpeg", 4132154843 }, + { "icon-64.jpg", 4132154843 }, + { "icon-64.jpg.mp3", 4132154843 }, + { "icon-64.pbm", 907392323 }, + { "icon-64.png", 1153555547 }, + { "icon-64.ppm", 1153555547 }, + { "icon-64.tga", 1153555547 }, + { "icon-64.tiff", 1153555547 }, + { "icon-64.webp", 1698406918 }, + { "icon-64.xbm", 907392323 }, + { "icon-64.xpm", 1768448874 }, +/**INDENT-ON**/ +}; +#define NT3_IMGS (sizeof(tii) / sizeof(tii_t)) + +TEST(LOAD2, load_1) +{ + unsigned int i, crc, w, h; + const char *fn; + char buf[256]; + Imlib_Image im; + unsigned char *data; + + for (i = 0; i < NT3_IMGS; i++) + { + fn = tii[i].name; + if (*fn != '/') + { + snprintf(buf, sizeof(buf), "%s/%s", IMGDIR, fn); + fn = buf; + } + D("Load '%s'\n", fn); + im = imlib_load_image(fn); + ASSERT_TRUE(im); + imlib_context_set_image(im); + data = (unsigned char *)imlib_image_get_data(); + w = imlib_image_get_width(); + h = imlib_image_get_height(); + crc = crc32(0, data, w * h * sizeof(DATA32)); + EXPECT_EQ(crc, tii[i].crc); + } +} + +int +main(int argc, char **argv) +{ + const char *s; + + ::testing::InitGoogleTest(&argc, argv); + + for (argc--, argv++; argc > 0; argc--, argv++) + { + s = argv[0]; + if (*s++ != '-') + break; + switch (*s) + { + case 'd': + debug++; + break; + } + } + + return RUN_ALL_TESTS(); +} --
