aboutsummaryrefslogtreecommitdiffstats
path: root/test/manual/image-circular-tests.el
diff options
context:
space:
mode:
authorVibhav Pant2020-08-21 14:04:35 +0530
committerVibhav Pant2020-08-21 14:04:35 +0530
commitf0f8d7b82492e741950c363a03b886965c91b1b0 (patch)
tree19b716830b1ebabc0d7d75949c4e6800c0f104ad /test/manual/image-circular-tests.el
parent9e64a087c4d167e7ec1c4e22bea3e6af53b563de (diff)
parentc818c29771d3cb51875643b2f6c894073e429dd2 (diff)
downloademacs-feature/native-comp-macos-fixes.tar.gz
emacs-feature/native-comp-macos-fixes.zip
Merge branch 'feature/native-comp' into feature/native-comp-macos-fixesfeature/native-comp-macos-fixes
Diffstat (limited to 'test/manual/image-circular-tests.el')
-rw-r--r--test/manual/image-circular-tests.el144
1 files changed, 144 insertions, 0 deletions
diff --git a/test/manual/image-circular-tests.el b/test/manual/image-circular-tests.el
new file mode 100644
index 00000000000..33ea3ea9547
--- /dev/null
+++ b/test/manual/image-circular-tests.el
@@ -0,0 +1,144 @@
1;;; image-tests.el --- Test suite for image-related functions.
2
3;; Copyright (C) 2019 Free Software Foundation, Inc.
4
5;; Author: Pip Cet <pipcet@gmail.com>
6;; Keywords: internal
7;; Human-Keywords: internal
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software: you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
23
24;;; Commentary:
25
26;;; Code:
27
28(require 'ert)
29
30(ert-deftest image-test-duplicate-keywords ()
31 "Test that duplicate keywords in an image spec lead to rejection."
32 (should-error (image-size `(image :type xbm :type xbm :width 1 :height 1
33 :data ,(bool-vector t))
34 t)))
35
36(ert-deftest image-test-circular-plist ()
37 "Test that a circular image spec is rejected."
38 (should-error
39 (let ((l `(image :type xbm :width 1 :height 1 :data ,(bool-vector t))))
40 (setcdr (last l) '#1=(:invalid . #1#))
41 (image-size l t))))
42
43(ert-deftest image-test-:type-property-value ()
44 "Test that :type is allowed as a property value in an image spec."
45 (should (equal (image-size `(image :dummy :type :type xbm :width 1 :height 1
46 :data ,(bool-vector t))
47 t)
48 (cons 1 1))))
49
50(ert-deftest image-test-circular-specs ()
51 "Test that circular image spec property values do not cause infinite recursion."
52 (should
53 (let* ((circ1 (cons :dummy nil))
54 (circ2 (cons :dummy nil))
55 (spec1 `(image :type xbm :width 1 :height 1
56 :data ,(bool-vector 1) :ignored ,circ1))
57 (spec2 `(image :type xbm :width 1 :height 1
58 :data ,(bool-vector 1) :ignored ,circ2)))
59 (setcdr circ1 circ1)
60 (setcdr circ2 circ2)
61 (and (equal (image-size spec1 t) (cons 1 1))
62 (equal (image-size spec2 t) (cons 1 1))))))
63
64(provide 'image-tests)
65;;; image-tests.el ends here.
66;;; image-tests.el --- tests for image.el -*- lexical-binding: t -*-
67
68;; Copyright (C) 2019-2020 Free Software Foundation, Inc.
69
70;; This file is part of GNU Emacs.
71
72;; GNU Emacs is free software: you can redistribute it and/or modify
73;; it under the terms of the GNU General Public License as published by
74;; the Free Software Foundation, either version 3 of the License, or
75;; (at your option) any later version.
76
77;; GNU Emacs is distributed in the hope that it will be useful,
78;; but WITHOUT ANY WARRANTY; without even the implied warranty of
79;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80;; GNU General Public License for more details.
81
82;; You should have received a copy of the GNU General Public License
83;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
84
85;;; Code:
86
87(require 'ert)
88(require 'image)
89(eval-when-compile
90 (require 'cl-lib))
91
92(defconst image-tests--emacs-images-directory
93 (expand-file-name "../etc/images" (getenv "EMACS_TEST_DIRECTORY"))
94 "Directory containing Emacs images.")
95
96(ert-deftest image--set-property ()
97 "Test `image--set-property' behavior."
98 (let ((image (list 'image)))
99 ;; Add properties.
100 (setf (image-property image :scale) 1)
101 (should (equal image '(image :scale 1)))
102 (setf (image-property image :width) 8)
103 (should (equal image '(image :scale 1 :width 8)))
104 (setf (image-property image :height) 16)
105 (should (equal image '(image :scale 1 :width 8 :height 16)))
106 ;; Delete properties.
107 (setf (image-property image :type) nil)
108 (should (equal image '(image :scale 1 :width 8 :height 16)))
109 (setf (image-property image :scale) nil)
110 (should (equal image '(image :width 8 :height 16)))
111 (setf (image-property image :height) nil)
112 (should (equal image '(image :width 8)))
113 (setf (image-property image :width) nil)
114 (should (equal image '(image)))))
115
116(ert-deftest image-type-from-file-header-test ()
117 "Test image-type-from-file-header."
118 (should (eq (if (image-type-available-p 'svg) 'svg)
119 (image-type-from-file-header
120 (expand-file-name "splash.svg"
121 image-tests--emacs-images-directory)))))
122
123(ert-deftest image-rotate ()
124 "Test `image-rotate'."
125 (cl-letf* ((image (list 'image))
126 ((symbol-function 'image--get-imagemagick-and-warn)
127 (lambda () image)))
128 (let ((current-prefix-arg '(4)))
129 (call-interactively #'image-rotate))
130 (should (equal image '(image :rotation 270.0)))
131 (call-interactively #'image-rotate)
132 (should (equal image '(image :rotation 0.0)))
133 (image-rotate)
134 (should (equal image '(image :rotation 90.0)))
135 (image-rotate 0)
136 (should (equal image '(image :rotation 90.0)))
137 (image-rotate 1)
138 (should (equal image '(image :rotation 91.0)))
139 (image-rotate 1234.5)
140 (should (equal image '(image :rotation 245.5)))
141 (image-rotate -154.5)
142 (should (equal image '(image :rotation 91.0)))))
143
144;;; image-tests.el ends here