kwo pushed a commit to branch master.

http://git.enlightenment.org/legacy/imlib2.git/commit/?id=79a5086b58af803b4d6a7ea16e9806c41dcda650

commit 79a5086b58af803b4d6a7ea16e9806c41dcda650
Author: Kim Woelders <[email protected]>
Date:   Sun Feb 6 12:34:47 2022 +0100

    test: Merge common stuff
---
 test/Makefile.am      | 16 ++++++++--------
 test/test.cpp         | 31 +++++++++++++++++++++++++++++++
 test/test.h           | 12 ++++++++++++
 test/test_common.h    |  3 ---
 test/test_context.cpp | 38 ++------------------------------------
 test/test_file.cpp    | 20 --------------------
 test/test_grab.cpp    | 32 +-------------------------------
 test/test_load.cpp    | 32 +-------------------------------
 test/test_load_2.cpp  | 29 +----------------------------
 test/test_rotate.cpp  | 31 +------------------------------
 test/test_save.cpp    | 31 +------------------------------
 test/test_scale.cpp   | 31 +------------------------------
 12 files changed, 59 insertions(+), 247 deletions(-)

diff --git a/test/Makefile.am b/test/Makefile.am
index f4ace28..ec8b345 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -32,29 +32,29 @@ CLEANFILES = file.c img_save-*.*
 %.c: $(top_srcdir)/src/lib/%.c
        ln -s $< $@
 
-test_file_SOURCES = test_file.cpp
+test_file_SOURCES = test.cpp test_file.cpp
 nodist_test_file_SOURCES = file.c
 test_file_LDADD = $(LIBS)
 
-test_context_SOURCES = test_context.cpp
+test_context_SOURCES = test.cpp test_context.cpp
 test_context_LDADD = $(LIBS)
 
-test_load_SOURCES = test_load.cpp
+test_load_SOURCES = test.cpp test_load.cpp
 test_load_LDADD = $(LIBS)
 
-test_load_2_SOURCES = test_load_2.cpp
+test_load_2_SOURCES = test.cpp test_load_2.cpp
 test_load_2_LDADD = $(LIBS) -lz
 
-test_save_SOURCES = test_save.cpp
+test_save_SOURCES = test.cpp test_save.cpp
 test_save_LDADD = $(LIBS)
 
-test_grab_SOURCES = test_grab.cpp
+test_grab_SOURCES = test.cpp test_grab.cpp
 test_grab_LDADD = $(LIBS)
 
-test_scale_SOURCES = test_scale.cpp
+test_scale_SOURCES = test.cpp test_scale.cpp
 test_scale_LDADD = $(LIBS) -lz
 
-test_rotate_SOURCES = test_rotate.cpp
+test_rotate_SOURCES = test.cpp test_rotate.cpp
 test_rotate_LDADD = $(LIBS) -lz
 
  TESTS_RUN = $(addprefix run-, $(GTESTS))
diff --git a/test/test.cpp b/test/test.cpp
new file mode 100644
index 0000000..4d6a703
--- /dev/null
+++ b/test/test.cpp
@@ -0,0 +1,31 @@
+#include <gtest/gtest.h>
+
+#include "test.h"
+
+int                 debug = 0;
+
+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;
+          }
+     }
+
+   // Required by some tests
+   mkdir(IMG_GEN, 0755);
+
+   return RUN_ALL_TESTS();
+}
diff --git a/test/test.h b/test/test.h
new file mode 100644
index 0000000..35d20d7
--- /dev/null
+++ b/test/test.h
@@ -0,0 +1,12 @@
+#ifndef TEST_H
+#define TEST_H 1
+
+#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__)
+
+extern int          debug;
+
+#endif /* TEST_H */
diff --git a/test/test_common.h b/test/test_common.h
deleted file mode 100644
index 34b09d5..0000000
--- a/test/test_common.h
+++ /dev/null
@@ -1,3 +0,0 @@
-
-#define IMG_SRC                SRC_DIR "/images"
-#define IMG_GEN                BLD_DIR "/generated"
diff --git a/test/test_context.cpp b/test/test_context.cpp
index 5285dfb..d658350 100644
--- a/test/test_context.cpp
+++ b/test/test_context.cpp
@@ -3,23 +3,12 @@
 #include <stddef.h>
 #include <Imlib2.h>
 
+#include "test.h"
+
 #define NULC ((Imlib_Context*)0)
 
 #define HAVE_INITIAL_CTX 1
 
-int                 debug = 0;
-
-#define D(...)  if (debug) printf(__VA_ARGS__)
-#define D2(...) if (debug > 1) printf(__VA_ARGS__)
-#if 0
-EAPI Imlib_Context  imlib_context_new(void);
-EAPI void           imlib_context_free(Imlib_Context context);
-
-EAPI void           imlib_context_push(Imlib_Context context);
-EAPI void           imlib_context_pop(void);
-EAPI Imlib_Context  imlib_context_get(void);
-#endif
-
 TEST(CTX, ctx)
 {
    Imlib_Context       ctx, ctx0, ctx1;
@@ -119,26 +108,3 @@ TEST(CTX, ctx)
    D("%d: ctx  = %p\n", __LINE__, ctx);
    EXPECT_EQ(ctx, ctx0);        // Ctx still default
 }
-
-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();
-}
diff --git a/test/test_file.cpp b/test/test_file.cpp
index 084cf37..dd69200 100644
--- a/test/test_file.cpp
+++ b/test/test_file.cpp
@@ -6,31 +6,18 @@ extern "C" {
 }
 /**INDENT-ON**/
 
-#if 0
-#define D(...) printf(__VA_ARGS__)
-#else
-#define D(...)
-#endif
-
 #define EXPECT_OK(x)  EXPECT_FALSE(x)
 #define EXPECT_ERR(x) EXPECT_TRUE(x)
 
 #if 0
 char               *__imlib_FileRealFile(const char *file);
-char               *__imlib_FileExtension(const char *file);
 
-//int                 __imlib_FileExists(const char *s);
-//int                 __imlib_FileIsFile(const char *s);
-//int                 __imlib_FileIsDir(const char *s);
 char              **__imlib_FileDir(const char *dir, int *num);
 void                __imlib_FileFreeDirList(char **l, int num);
 void                __imlib_FileDel(const char *s);
 time_t              __imlib_FileModDate(const char *s);
 char               *__imlib_FileHomeDir(int uid);
 int                 __imlib_FilePermissions(const char *s);
-
-//int                 __imlib_FileCanRead(const char *s);
-int                 __imlib_IsRealFile(const char *s);
 #endif
 
 #define USE_REAL_FILE 0
@@ -248,10 +235,3 @@ TEST(FILE, file_key)
    EXPECT_FALSE(key);
    free(key);
 }
-
-int
-main(int argc, char **argv)
-{
-   ::testing::InitGoogleTest(&argc, argv);
-   return RUN_ALL_TESTS();
-}
diff --git a/test/test_grab.cpp b/test/test_grab.cpp
index 06165cb..bc38468 100644
--- a/test/test_grab.cpp
+++ b/test/test_grab.cpp
@@ -4,7 +4,7 @@
 #include <Imlib2.h>
 
 #include "config.h"
-#include "test_common.h"
+#include "test.h"
 
 typedef struct {
    Display            *dpy;
@@ -19,10 +19,6 @@ typedef struct {
 } xd_t;
 
 static xd_t         xd;
-int                 debug = 0;
-
-#define D(...)  if (debug) printf(__VA_ARGS__)
-#define D2(...) if (debug > 1) printf(__VA_ARGS__)
 
 static Visual      *
 _x11_vis_argb(void)
@@ -323,29 +319,3 @@ TEST(GRAB, grab_offs_32_sd2)
 {
    _test_grab("grab_offs_32_sd2", 32, -2, 1);
 }
-
-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':
-             while (*s++ == 'd')
-                debug++;
-             break;
-          }
-     }
-
-   mkdir(IMG_GEN, 0755);
-
-   return RUN_ALL_TESTS();
-}
diff --git a/test/test_load.cpp b/test/test_load.cpp
index 744b762..a3573ff 100644
--- a/test/test_load.cpp
+++ b/test/test_load.cpp
@@ -4,12 +4,7 @@
 #include <fcntl.h>
 
 #include "config.h"
-#include "test_common.h"
-
-int                 debug = 0;
-
-#define D(...)  if (debug) printf(__VA_ARGS__)
-#define D2(...) if (debug > 1) printf(__VA_ARGS__)
+#include "test.h"
 
 #define EXPECT_OK(x)  EXPECT_FALSE(x)
 #define EXPECT_ERR(x) EXPECT_TRUE(x)
@@ -169,28 +164,3 @@ TEST(LOAD, load_2)
    imlib_context_set_progress_granularity(10);
    test_load();
 }
-
-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;
-          }
-     }
-
-   mkdir(IMG_GEN, 0755);
-
-   return RUN_ALL_TESTS();
-}
diff --git a/test/test_load_2.cpp b/test/test_load_2.cpp
index f79df0d..ab9dd87 100644
--- a/test/test_load_2.cpp
+++ b/test/test_load_2.cpp
@@ -5,11 +5,7 @@
 #include <zlib.h>
 
 #include "config.h"
-#include "test_common.h"
-
-int                 debug = 0;
-
-#define D(...) if (debug) printf(__VA_ARGS__)
+#include "test.h"
 
 #define EXPECT_OK(x)  EXPECT_FALSE(x)
 #define EXPECT_ERR(x) EXPECT_TRUE(x)
@@ -89,26 +85,3 @@ TEST(LOAD2, load_1)
         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();
-}
diff --git a/test/test_rotate.cpp b/test/test_rotate.cpp
index 5a25d11..86fb6d2 100644
--- a/test/test_rotate.cpp
+++ b/test/test_rotate.cpp
@@ -4,11 +4,7 @@
 #include <zlib.h>
 
 #include "config.h"
-#include "test_common.h"
-
-int                 debug = 0;
-
-#define D(...)  if (debug) printf(__VA_ARGS__)
+#include "test.h"
 
 #define FILE_REF1      "icon-64"       // RGB
 #define FILE_REF2      "xeyes" // ARGB (shaped)
@@ -131,28 +127,3 @@ TEST(ROTAT, rotate_2_noaa)
 {
    test_rotate(1, 0);
 }
-
-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;
-          }
-     }
-
-   mkdir(IMG_GEN, 0755);
-
-   return RUN_ALL_TESTS();
-}
diff --git a/test/test_save.cpp b/test/test_save.cpp
index eed94b1..5ce0b27 100644
--- a/test/test_save.cpp
+++ b/test/test_save.cpp
@@ -3,11 +3,7 @@
 #include <Imlib2.h>
 
 #include "config.h"
-#include "test_common.h"
-
-int                 debug = 0;
-
-#define D(...)  if (debug) printf(__VA_ARGS__)
+#include "test.h"
 
 #define EXPECT_OK(x)  EXPECT_FALSE(x)
 #define EXPECT_ERR(x) EXPECT_TRUE(x)
@@ -164,28 +160,3 @@ TEST(SAVE, save_2_argb)
 {
    test_save(FILE_REF2, 1);
 }
-
-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;
-          }
-     }
-
-   mkdir(IMG_GEN, 0755);
-
-   return RUN_ALL_TESTS();
-}
diff --git a/test/test_scale.cpp b/test/test_scale.cpp
index 6771cbe..8c66dd7 100644
--- a/test/test_scale.cpp
+++ b/test/test_scale.cpp
@@ -4,11 +4,7 @@
 #include <zlib.h>
 
 #include "config.h"
-#include "test_common.h"
-
-int                 debug = 0;
-
-#define D(...)  if (debug) printf(__VA_ARGS__)
+#include "test.h"
 
 #define FILE_REF1      "icon-64"       // RGB
 #define FILE_REF2      "xeyes" // ARGB (shaped)
@@ -102,28 +98,3 @@ TEST(SCALE, scale_1_argb)
 {
    test_scale(1);
 }
-
-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;
-          }
-     }
-
-   mkdir(IMG_GEN, 0755);
-
-   return RUN_ALL_TESTS();
-}

-- 


Reply via email to