This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository legacy-imlib2.

View the commit online.

commit 9b9abcdc1e318a23181aee06d43f13988912ca69
Author: Kim Woelders <k...@woelders.dk>
AuthorDate: Sun Jan 22 11:48:16 2023 +0100

    test: Introduce image_get_crc32()
---
 test/Makefile.am     |  7 ++++---
 test/test.cpp        | 19 +++++++++++++++++++
 test/test.h          |  8 ++++++--
 test/test_load_2.cpp | 25 +++++++------------------
 test/test_rotate.cpp |  6 +-----
 test/test_scale.cpp  | 13 ++-----------
 6 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/test/Makefile.am b/test/Makefile.am
index bd6e69c..876ed66 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -34,6 +34,7 @@ endif
 # Must have proper -lImlib2 on all progs
  LIBS  = -L$(top_builddir)/src/lib -lImlib2
  LIBS += $(GTEST_LIBS)
+ LIBS += -lz
 
 %.c: $(top_srcdir)/src/lib/%.c
 	ln -s $< $@
@@ -58,7 +59,7 @@ test_load_SOURCES = $(TEST_COMMON) test_load.cpp
 test_load_LDADD = $(LIBS)
 
 test_load_2_SOURCES = $(TEST_COMMON) test_load_2.cpp
-test_load_2_LDADD = $(LIBS) -lz
+test_load_2_LDADD = $(LIBS)
 
 test_save_SOURCES = $(TEST_COMMON) test_save.cpp
 test_save_LDADD = $(LIBS)
@@ -67,10 +68,10 @@ test_grab_SOURCES = $(TEST_COMMON) test_grab.cpp
 test_grab_LDADD = $(LIBS)
 
 test_scale_SOURCES = $(TEST_COMMON) test_scale.cpp
-test_scale_LDADD = $(LIBS) -lz
+test_scale_LDADD = $(LIBS)
 
 test_rotate_SOURCES = $(TEST_COMMON) test_rotate.cpp
-test_rotate_LDADD = $(LIBS) -lz
+test_rotate_LDADD = $(LIBS)
 
  TESTS_RUN = $(addprefix run-, $(GTESTS))
 
diff --git a/test/test.cpp b/test/test.cpp
index 54e4530..6360d15 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -1,5 +1,6 @@
 #include <gtest/gtest.h>
 
+#include "config.h"
 #include "test.h"
 
 int                 debug = 0;
@@ -30,3 +31,21 @@ main(int argc, char **argv)
 
    return RUN_ALL_TESTS();
 }
+
+#include <Imlib2.h>
+#include <zlib.h>
+
+unsigned int
+image_get_crc32(Imlib_Image im)
+{
+   const unsigned char *data;
+   unsigned int        crc, w, h;
+
+   imlib_context_set_image(im);
+   w = imlib_image_get_width();
+   h = imlib_image_get_height();
+   data = "" unsigned char *)imlib_image_get_data_for_reading_only();
+   crc = crc32(0, data, w * h * sizeof(uint32_t));
+
+   return crc;
+}
diff --git a/test/test.h b/test/test.h
index 35d20d7..6a574d8 100644
--- a/test/test.h
+++ b/test/test.h
@@ -4,9 +4,13 @@
 #define IMG_SRC		SRC_DIR "/images"
 #define IMG_GEN		BLD_DIR "/generated"
 
-#define D(...)  if (debug) printf(__VA_ARGS__)
-#define D2(...) if (debug > 1) printf(__VA_ARGS__)
+#define D(...)  do{ if (debug)     printf(__VA_ARGS__); }while(0)
+#define D2(...) do{ if (debug > 1) printf(__VA_ARGS__); }while(0)
+
+#include <Imlib2.h>
 
 extern int          debug;
 
+unsigned int        image_get_crc32(Imlib_Image im);
+
 #endif /* TEST_H */
diff --git a/test/test_load_2.cpp b/test/test_load_2.cpp
index 208b7a4..eaf839a 100644
--- a/test/test_load_2.cpp
+++ b/test/test_load_2.cpp
@@ -5,7 +5,6 @@
 #include <Imlib2.h>
 
 #include <fcntl.h>
-#include <zlib.h>
 
 #include "test.h"
 
@@ -84,11 +83,10 @@ static tii_t        tii[] = {
 
 TEST(LOAD2, load_1)
 {
-   unsigned int        i, crc, w, h;
+   unsigned int        i, crc;
    const char         *fn;
    char                buf[256];
    Imlib_Image         im;
-   unsigned char      *data;
 
    for (i = 0; i < NT3_IMGS; i++)
      {
@@ -102,32 +100,23 @@ TEST(LOAD2, load_1)
 
         im = imlib_load_image(fn);
         ASSERT_TRUE(im);
-        imlib_context_set_image(im);
-        data = "" char *)imlib_image_get_data();
-        w = imlib_image_get_width();
-        h = imlib_image_get_height();
-        crc = crc32(0, data, w * h * sizeof(uint32_t));
+        crc = image_get_crc32(im);
         EXPECT_EQ(crc, tii[i].crc);
+        imlib_context_set_image(im);
         imlib_free_image_and_decache();
 
         im = imlib_load_image_frame(fn, 0);
         ASSERT_TRUE(im);
-        imlib_context_set_image(im);
-        data = "" char *)imlib_image_get_data();
-        w = imlib_image_get_width();
-        h = imlib_image_get_height();
-        crc = crc32(0, data, w * h * sizeof(uint32_t));
+        crc = image_get_crc32(im);
         EXPECT_EQ(crc, tii[i].crc);
+        imlib_context_set_image(im);
         imlib_free_image_and_decache();
 
         im = imlib_load_image_frame(fn, 1);
         ASSERT_TRUE(im);
-        imlib_context_set_image(im);
-        data = "" char *)imlib_image_get_data();
-        w = imlib_image_get_width();
-        h = imlib_image_get_height();
-        crc = crc32(0, data, w * h * sizeof(uint32_t));
+        crc = image_get_crc32(im);
         EXPECT_EQ(crc, tii[i].crc);
+        imlib_context_set_image(im);
         imlib_free_image_and_decache();
      }
 }
diff --git a/test/test_rotate.cpp b/test/test_rotate.cpp
index 4ff70ba..2eb80a7 100644
--- a/test/test_rotate.cpp
+++ b/test/test_rotate.cpp
@@ -3,8 +3,6 @@
 #include "config.h"
 #include <Imlib2.h>
 
-#include <zlib.h>
-
 #include "test.h"
 
 #define FILE_REF1	"icon-64"       // RGB
@@ -55,7 +53,6 @@ test_rotate(int no, int aa)
    unsigned int        i, ic, crc;
    Imlib_Image         imi, imo;
    int                 err;
-   unsigned char      *data;
 
    ptd = &td[no];
 
@@ -97,8 +94,7 @@ test_rotate(int no, int aa)
         if (err)
            D("Error %d saving '%s'\n", err, fileo);
 
-        data = "" char *)imlib_image_get_data_for_reading_only();
-        crc = crc32(0, data, wo * ho * sizeof(uint32_t));
+        crc = image_get_crc32(imo);
         EXPECT_EQ(crc, ptd->tv[i].crc[ic]);
 
         imlib_context_set_image(imo);
diff --git a/test/test_scale.cpp b/test/test_scale.cpp
index 8606d4b..4858293 100644
--- a/test/test_scale.cpp
+++ b/test/test_scale.cpp
@@ -3,8 +3,6 @@
 #include "config.h"
 #include <Imlib2.h>
 
-#include <zlib.h>
-
 #include "test.h"
 
 #define FILE_REF1	"icon-64"       // RGB
@@ -34,7 +32,6 @@ test_scale(int no)
    unsigned int        i, crc;
    Imlib_Image         imi, imo;
    int                 err;
-   unsigned char      *data;
 
 #ifdef DO_MMX_ASM
    // Hmm.. MMX functions appear to produce a slightly different result
@@ -48,12 +45,7 @@ test_scale(int no)
    imi = imlib_load_image(filei);
    ASSERT_TRUE(imi);
 
-   imlib_context_set_image(imi);
-   w = imlib_image_get_width();
-   h = imlib_image_get_height();
-
-   data = "" char *)imlib_image_get_data_for_reading_only();
-   crc = crc32(0, data, w * h * sizeof(uint32_t));
+   crc = image_get_crc32(imi);
    EXPECT_EQ(crc, ptd->crcs[0]);
 
    for (i = 0; i < 4; i++)
@@ -69,8 +61,7 @@ test_scale(int no)
         w = imlib_image_get_width();
         h = imlib_image_get_height();
 
-        data = "" char *)imlib_image_get_data_for_reading_only();
-        crc = crc32(0, data, w * h * sizeof(uint32_t));
+        crc = image_get_crc32(imo);
         EXPECT_EQ(crc, ptd->crcs[i]);
 
         snprintf(fileo, sizeof(fileo), "%s/scale-%s-%dx%d.%s",

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to