diff options
| author | Lars Ingebrigtsen | 2017-04-21 06:12:53 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2017-04-21 06:13:06 +0200 |
| commit | b1fe497a445a8be1b50c5b5952f3380ee9546710 (patch) | |
| tree | cb86e8d533fcaa5e72e5f3e95059363ea3539e52 | |
| parent | 0ca61907cf4fe8afc723ed1e89e1a15ee69507ce (diff) | |
| download | emacs-b1fe497a445a8be1b50c5b5952f3380ee9546710.tar.gz emacs-b1fe497a445a8be1b50c5b5952f3380ee9546710.zip | |
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.
| -rw-r--r-- | test/data/image/blank-200x100.png | bin | 0 -> 338 bytes | |||
| -rw-r--r-- | test/manual/image-size-tests.el | 64 |
2 files changed, 64 insertions, 0 deletions
diff --git a/test/data/image/blank-200x100.png b/test/data/image/blank-200x100.png new file mode 100644 index 00000000000..d516ad51d31 --- /dev/null +++ b/test/data/image/blank-200x100.png | |||
| Binary files differ | |||
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 @@ | |||
| 1 | ;;; image-size-tests.el -- tests for image scaling | ||
| 2 | |||
| 3 | ;; Copyright (C) 2017 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | ;; This program is free software; you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published by | ||
| 9 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 10 | ;; (at your option) any later version. | ||
| 11 | |||
| 12 | ;; This program is distributed in the hope that it will be useful, | ||
| 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | ;; GNU General Public License for more details. | ||
| 16 | |||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | ;; To test: Load the file and eval (image-size-tests). | ||
| 21 | ;; A non-erroring result is a success. | ||
| 22 | |||
| 23 | ;;; Code: | ||
| 24 | |||
| 25 | (defmacro im-should (form) | ||
| 26 | `(unless ,form | ||
| 27 | (error "%s didn't succeed" ',form))) | ||
| 28 | |||
| 29 | (defun im-image (&rest props) | ||
| 30 | (let ((image-scaling-factor 1)) | ||
| 31 | (apply | ||
| 32 | #'create-image | ||
| 33 | (expand-file-name "test/data/image/blank-200x100.png" source-directory) | ||
| 34 | 'imagemagick nil props))) | ||
| 35 | |||
| 36 | (defun im-compare (image width height) | ||
| 37 | (let ((size (image-size image t))) | ||
| 38 | (and (= (car size) width) | ||
| 39 | (= (cdr size) height)))) | ||
| 40 | |||
| 41 | (defun image-size-tests () | ||
| 42 | (unless (imagemagick-types) | ||
| 43 | (error "This only makes sense if ImageMagick is installed")) | ||
| 44 | ;; Default sizes. | ||
| 45 | (im-should (im-compare (im-image) 200 100)) | ||
| 46 | ;; Changing one dimension changes the other. | ||
| 47 | (im-should (im-compare (im-image :width 100) 100 50)) | ||
| 48 | (im-should (im-compare (im-image :height 50) 100 50)) | ||
| 49 | ;; The same with :max-width etc. | ||
| 50 | (im-should (im-compare (im-image :max-width 100) 100 50)) | ||
| 51 | (im-should (im-compare (im-image :max-height 50) 100 50)) | ||
| 52 | ;; :width wins over :max-width etc | ||
| 53 | (im-should (im-compare (im-image :width 300 :max-width 100) 300 150)) | ||
| 54 | (im-should (im-compare (im-image :height 200 :max-height 100) 400 200)) | ||
| 55 | ;; Specifying both width and height is fine. | ||
| 56 | (im-should (im-compare (im-image :width 300 :height 50) 300 50)) | ||
| 57 | ;; A too-large :max-width (etc) has no effect. | ||
| 58 | (im-should (im-compare (im-image :max-width 300) 200 100)) | ||
| 59 | (im-should (im-compare (im-image :max-height 300) 200 100)) | ||
| 60 | ;; Both max-width/height. | ||
| 61 | (im-should (im-compare (im-image :max-width 100 :max-height 75) 100 50)) | ||
| 62 | (im-should (im-compare (im-image :max-width 100 :max-height 25) 50 25))) | ||
| 63 | |||
| 64 | ;;; image-size-tests.el ends here | ||