From e589018b48f802d69f62ab1e7e266df1c7d8cf68 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 24 Apr 2017 07:56:31 +0200 Subject: [PATCH] Add image sizing tests for an image that's narrow --- test/data/image/blank-100x200.png | Bin 0 -> 423 bytes test/manual/image-size-tests.el | 62 ++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 test/data/image/blank-100x200.png diff --git a/test/data/image/blank-100x200.png b/test/data/image/blank-100x200.png new file mode 100644 index 0000000000000000000000000000000000000000..ad26949e9838267f614a12ec43884c9a35fc1882 GIT binary patch literal 423 zcmeAS@N?(olHy`uVBq!ia0vp^DL{OJg9%7ZjJrGyNO2Z;L>4nJa0`PlBg3pY5H=O_J=GIES83vo91N$g(OQ{BTAg}b8}PkN*J7rQWHy3QxwWGOEMJPJ$(bh8~MZ; z7#I~jT^vIyZoR$0$jHFJ!L;Dj|McAt7-k$$leAjyFij_NQ_9I81#d7zbAl?EA#!38 yn8B5D63k!)ssS;WK#GBkMzF3)ONWK_3)OA!S$Yk;d{luU%HZkh=d#Wzp$Pz$@s~3I literal 0 HcmV?d00001 diff --git a/test/manual/image-size-tests.el b/test/manual/image-size-tests.el index 301352eddb0..577c7658791 100644 --- a/test/manual/image-size-tests.el +++ b/test/manual/image-size-tests.el @@ -22,15 +22,21 @@ ;;; Code: -(defmacro im-should (width height &rest props) - `(unless (im-compare (im-image ,@props) ,width ,height) - (error "%s didn't succeed" ',props))) +(defmacro im-should (image width height &rest props) + `(let ((im (im-image ,image ,@props))) + (unless (im-compare im ,width ,height) + (error "%s didn't succeed; size is %s" + ',props (image-size im t))))) -(defun im-image (&rest props) +(defun im-image (type &rest props) (let ((image-scaling-factor 1)) (apply #'create-image - (expand-file-name "test/data/image/blank-200x100.png" source-directory) + (expand-file-name + (if (eq type :w) + "test/data/image/blank-200x100.png" + "test/data/image/blank-100x200.png") + source-directory) 'imagemagick nil props))) (defun im-compare (image width height) @@ -41,24 +47,46 @@ (defun image-size-tests () (unless (imagemagick-types) (error "This only makes sense if ImageMagick is installed")) + ;; Test the image that's wider than it is tall. ;; Default sizes. - (im-should 200 100) + (im-should :w 200 100) ;; Changing one dimension changes the other. - (im-should 100 50 :width 100) - (im-should 100 50 :height 50) + (im-should :w 100 50 :width 100) + (im-should :w 100 50 :height 50) ;; The same with :max-width etc. - (im-should 100 50 :max-width 100) - (im-should 100 50 :max-height 50) + (im-should :w 100 50 :max-width 100) + (im-should :w 100 50 :max-height 50) ;; :width wins over :max-width etc - (im-should 300 150 :width 300 :max-width 100) - (im-should 400 200 :height 200 :max-height 100) + (im-should :w 300 150 :width 300 :max-width 100) + (im-should :w 400 200 :height 200 :max-height 100) ;; Specifying both width and height is fine. - (im-should 300 50 :width 300 :height 50) + (im-should :w 300 50 :width 300 :height 50) ;; A too-large :max-width (etc) has no effect. - (im-should 200 100 :max-width 300) - (im-should 200 100 :max-height 300) + (im-should :w 200 100 :max-width 300) + (im-should :w 200 100 :max-height 300) ;; Both max-width/height. - (im-should 100 50 :max-width 100 :max-height 75) - (im-should 50 25 :max-width 100 :max-height 25)) + (im-should :w 100 50 :max-width 100 :max-height 75) + (im-should :w 50 25 :max-width 100 :max-height 25) + + ;; Test the image that's taller than it is wide. + (im-should :h 100 200) + ;; Changing one dimension changes the other. + (im-should :h 50 100 :width 50) + (im-should :h 50 100 :height 100) + ;; The same with :max-width etc. + (im-should :h 50 100 :max-width 50) + (im-should :h 50 100 :max-height 100) + ;; :width wins over :max-width etc + (im-should :h 300 600 :width 300 :max-width 100) + (im-should :h 150 300 :height 300 :max-height 100) + ;; Specifying both width and height is fine. + (im-should :h 300 50 :width 300 :height 50) + ;; A too-large :max-width (etc) has no effect. + (im-should :h 100 200 :max-width 300) + (im-should :h 100 200 :max-height 300) + ;; Both max-width/height. + (im-should :h 50 100 :max-width 75 :max-height 100) + (im-should :h 25 50 :max-width 25 :max-height 100) + ) ;;; image-size-tests.el ends here -- 2.39.5