summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-05 12:14:43 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-05 12:14:43 -0800
commitc52082c6e4811958dd741d67e1178b4e36a09923 (patch)
tree00c2155f76040b27c1217916ab03df5b8696da6d /test
parent77e3b389eb92b8d8f94f5b83c1d3d7cd4db5b037 (diff)
downloadxorg-lib-libXpm-c52082c6e4811958dd741d67e1178b4e36a09923.tar.gz
open-zfile: Make compress & uncompress commands optional
If compress is not found, we disable writing to .Z files, but leave the rest of the compression code active. If uncompress is not found, we use gzip to read .Z files. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'test')
-rw-r--r--test/XpmWrite.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/XpmWrite.c b/test/XpmWrite.c
index 53e010e..10b6207 100644
--- a/test/XpmWrite.c
+++ b/test/XpmWrite.c
@@ -60,6 +60,22 @@ is_compressed(const char *filepath)
}
/*
+ * If a filename ends in ".Z" or ".gz", remove that extension to avoid
+ * confusing libXpm into applying compression when not desired.
+ */
+static inline void
+strip_compress_ext(char *filepath)
+{
+ char *ext = strrchr(filepath, '.');
+
+ if ((ext != NULL) &&
+ (((ext[1] == 'Z') && (ext[2] == 0)) ||
+ ((ext[1] == 'g') && (ext[2] == 'z') && (ext[3] == 0)))) {
+ *ext = '\0';
+ }
+}
+
+/*
* XpmWriteFileFromXpmImage - Write XPM files without requiring an X Display
*/
static void
@@ -114,6 +130,7 @@ TestWriteFileFromXpmImage(const gchar *filepath)
g_assert_no_error(err);
filename = g_path_get_basename(filepath);
+ strip_compress_ext(filename);
newfilepath = g_build_filename(testdir, filename, NULL);
test_WFFXI_helper(newfilepath, &imageA, &infoA);
@@ -123,10 +140,12 @@ TestWriteFileFromXpmImage(const gchar *filepath)
test_WFFXI_helper(cmpfilepath, &imageA, &infoA);
g_free(cmpfilepath);
+#ifdef XPM_PATH_COMPRESS
cmpfilepath = g_strdup_printf("%s.Z", newfilepath);
test_WFFXI_helper(cmpfilepath, &imageA, &infoA);
g_free(cmpfilepath);
#endif
+#endif
XpmFreeXpmImage(&imageA);
XpmFreeXpmInfo(&infoA);
@@ -203,6 +222,7 @@ TestWriteFileFromData(const gchar *filepath)
g_assert_no_error(err);
filename = g_path_get_basename(filepath);
+ strip_compress_ext(filename);
newfilepath = g_build_filename(testdir, filename, NULL);
test_WFFXD_helper(newfilepath, data);
@@ -212,10 +232,12 @@ TestWriteFileFromData(const gchar *filepath)
test_WFFXD_helper(cmpfilepath, data);
g_free(cmpfilepath);
+#ifdef XPM_PATH_COMPRESS
cmpfilepath = g_strdup_printf("%s.Z", newfilepath);
test_WFFXD_helper(cmpfilepath, data);
g_free(cmpfilepath);
#endif
+#endif
XpmFree(data);
@@ -259,6 +281,7 @@ TestWriteFileFromBuffer(const gchar *filepath)
g_assert_no_error(err);
filename = g_path_get_basename(filepath);
+ strip_compress_ext(filename);
newfilepath = g_build_filename(testdir, filename, NULL);
g_test_message("...writing %s", newfilepath);