From 015fb4ac1c84485c563934087884f8a7dfe51955 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Tue, 6 Sep 2022 13:03:40 +0200 Subject: [PATCH] Add tests for opening different image formats * test/src/image-tests.el (image-tests-make-load-image-test): New macro. (image-tests-load-image/gif) (image-tests-load-image/jpeg) (image-tests-load-image/pbm) (image-tests-load-image/png) (image-tests-load-image/svg) (image-tests-load-image/tiff) (image-tests-load-image/webp) (image-tests-load-image/xbm) (image-tests-load-image/xpm): New tests. --- test/src/image-tests.el | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/test/src/image-tests.el b/test/src/image-tests.el index c05582ada75..0a13db67d45 100644 --- a/test/src/image-tests.el +++ b/test/src/image-tests.el @@ -33,11 +33,12 @@ `(skip-unless (and (display-images-p) (image-type-available-p ,format)))) -;;;; Images + +;;;; Image data (defconst image-tests--images `((gif . ,(expand-file-name "test/data/image/black.gif" - source-directory)) + source-directory)) (jpeg . ,(expand-file-name "test/data/image/black.jpg" source-directory)) (pbm . ,(find-image '((:file "splash.svg" :type svg)))) @@ -51,6 +52,34 @@ (xbm . ,(find-image '((:file "gnus/gnus.xbm" :type xbm)))) (xpm . ,(find-image '((:file "splash.xpm" :type xpm)))))) + +;;;; Load image + +(defmacro image-tests-make-load-image-test (type) + `(ert-deftest ,(intern (format "image-tests-load-image/%s" + (eval type t))) + () + (image-skip-unless ,type) + (let* ((img (cdr (assq ,type image-tests--images))) + (file (if (listp img) + (plist-get (cdr img) :file) + img))) + (find-file file)) + (should (equal major-mode 'image-mode)) + ;; Cleanup + (kill-buffer (current-buffer)))) + +(image-tests-make-load-image-test 'gif) +(image-tests-make-load-image-test 'jpeg) +(image-tests-make-load-image-test 'pbm) +(image-tests-make-load-image-test 'png) +(image-tests-make-load-image-test 'svg) +(image-tests-make-load-image-test 'tiff) +(image-tests-make-load-image-test 'webp) +(image-tests-make-load-image-test 'xbm) +(image-tests-make-load-image-test 'xpm) + + ;;;; image-test-size (declare-function image-size "image.c" (spec &optional pixels frame)) @@ -126,6 +155,7 @@ (skip-unless (not (display-images-p))) (should-error (image-size 'invalid-spec))) + ;;;; image-mask-p (declare-function image-mask-p "image.c" (spec &optional frame)) @@ -178,6 +208,7 @@ (skip-unless (not (display-images-p))) (should-error (image-mask-p (cdr (assq 'xpm image-tests--images))))) + ;;;; image-metadata (declare-function image-metadata "image.c" (spec &optional frame)) @@ -235,6 +266,7 @@ (skip-unless (not (display-images-p))) (should-error (image-metadata (cdr (assq 'xpm image-tests--images))))) + ;;;; ImageMagick (ert-deftest image-tests-imagemagick-types () @@ -242,6 +274,7 @@ (when (fboundp 'imagemagick-types) (should (listp (imagemagick-types))))) + ;;;; Initialization (ert-deftest image-tests-init-image-library () -- 2.39.2