From b1fe497a445a8be1b50c5b5952f3380ee9546710 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 21 Apr 2017 06:12:53 +0200 Subject: [PATCH] Add tests to check image scaling functionality This is in preparation to doing further work in this area to avoid regressions. * test/data/image/blank-200x100.png: New file for testing image scaling. * test/manual/image-size-tests.el: New file. --- test/data/image/blank-200x100.png | Bin 0 -> 338 bytes test/manual/image-size-tests.el | 64 ++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 test/data/image/blank-200x100.png create mode 100644 test/manual/image-size-tests.el diff --git a/test/data/image/blank-200x100.png b/test/data/image/blank-200x100.png new file mode 100644 index 0000000000000000000000000000000000000000..d516ad51d314d71f06970f00cdafa82747d756d0 GIT binary patch literal 338 zcmeAS@N?(olHy`uVBq!ia0vp^CxAGGg9%9bJb4iVq&N#aB8wRqxP?KOkzv*x37{Z* ziKnkC`$HBHF-fgt_1(=tA=%83h!W@g+}zZ>5+Ij>!MP|ku_QG`p**uBL&4qCHy}kX zl^rO4!qdeuq~g}wONN3B3>-%c4(xw^oQ2t0Y2kIhpn_bL0}&G3$&DKg#Evl~C+hUD z9y literal 0 HcmV?d00001 diff --git a/test/manual/image-size-tests.el b/test/manual/image-size-tests.el new file mode 100644 index 00000000000..972361aa63a --- /dev/null +++ b/test/manual/image-size-tests.el @@ -0,0 +1,64 @@ +;;; image-size-tests.el -- tests for image scaling + +;; Copyright (C) 2017 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;; To test: Load the file and eval (image-size-tests). +;; A non-erroring result is a success. + +;;; Code: + +(defmacro im-should (form) + `(unless ,form + (error "%s didn't succeed" ',form))) + +(defun im-image (&rest props) + (let ((image-scaling-factor 1)) + (apply + #'create-image + (expand-file-name "test/data/image/blank-200x100.png" source-directory) + 'imagemagick nil props))) + +(defun im-compare (image width height) + (let ((size (image-size image t))) + (and (= (car size) width) + (= (cdr size) height)))) + +(defun image-size-tests () + (unless (imagemagick-types) + (error "This only makes sense if ImageMagick is installed")) + ;; Default sizes. + (im-should (im-compare (im-image) 200 100)) + ;; Changing one dimension changes the other. + (im-should (im-compare (im-image :width 100) 100 50)) + (im-should (im-compare (im-image :height 50) 100 50)) + ;; The same with :max-width etc. + (im-should (im-compare (im-image :max-width 100) 100 50)) + (im-should (im-compare (im-image :max-height 50) 100 50)) + ;; :width wins over :max-width etc + (im-should (im-compare (im-image :width 300 :max-width 100) 300 150)) + (im-should (im-compare (im-image :height 200 :max-height 100) 400 200)) + ;; Specifying both width and height is fine. + (im-should (im-compare (im-image :width 300 :height 50) 300 50)) + ;; A too-large :max-width (etc) has no effect. + (im-should (im-compare (im-image :max-width 300) 200 100)) + (im-should (im-compare (im-image :max-height 300) 200 100)) + ;; Both max-width/height. + (im-should (im-compare (im-image :max-width 100 :max-height 75) 100 50)) + (im-should (im-compare (im-image :max-width 100 :max-height 25) 50 25))) + +;;; image-size-tests.el ends here -- 2.39.5