diff options
Diffstat (limited to 'test/lisp/image')
-rw-r--r-- | test/lisp/image/exif-tests.el | 49 | ||||
-rw-r--r-- | test/lisp/image/gravatar-tests.el | 77 | ||||
-rw-r--r-- | test/lisp/image/image-dired-tests.el | 37 | ||||
-rw-r--r-- | test/lisp/image/image-dired-util-tests.el | 54 |
4 files changed, 217 insertions, 0 deletions
diff --git a/test/lisp/image/exif-tests.el b/test/lisp/image/exif-tests.el new file mode 100644 index 00000000000..d62eef4798d --- /dev/null +++ b/test/lisp/image/exif-tests.el @@ -0,0 +1,49 @@ +;;; exif-tests.el --- tests for exif.el -*- lexical-binding: t -*- + +;; Copyright (C) 2019-2022 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Code: + +(require 'ert) +(require 'exif) + +(defun test-image-file (name) + (expand-file-name + name (expand-file-name "data/image" + (or (getenv "EMACS_TEST_DIRECTORY") + "../../")))) + +(ert-deftest test-exif-parse () + (let ((exif (exif-parse-file (test-image-file "black.jpg")))) + (should (equal (exif-field 'make exif) "Panasonic")) + (should (equal (exif-field 'orientation exif) 1)) + (should (equal (exif-field 'x-resolution exif) '(180 . 1))) + (should (equal (exif-field 'date-time exif) "2019:09:21 16:22:13")))) + +(ert-deftest test-exif-parse-short () + (let ((exif (exif-parse-file (test-image-file "black-short.jpg")))) + (should (equal (exif-field 'make exif) "thr")) + (should (equal (exif-field 'model exif) "four")) + (should (equal (exif-field 'software exif) "em")) + (should (equal (exif-field 'artist exif) "z")))) + +(ert-deftest test-exit-direct-ascii-value () + (should (equal (exif--direct-ascii-value 28005 2 t) (string ?e ?m 0))) + (should (equal (exif--direct-ascii-value 28005 2 nil) (string ?m ?e 0)))) + +;;; exif-tests.el ends here diff --git a/test/lisp/image/gravatar-tests.el b/test/lisp/image/gravatar-tests.el new file mode 100644 index 00000000000..3b3a0ad4643 --- /dev/null +++ b/test/lisp/image/gravatar-tests.el @@ -0,0 +1,77 @@ +;;; gravatar-tests.el --- tests for gravatar.el -*- lexical-binding: t -*- + +;; Copyright (C) 2019-2022 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Code: + +(require 'ert) +(require 'gravatar) + +(ert-deftest gravatar-hash () + "Test `gravatar-hash'." + (should (equal (gravatar-hash "") "d41d8cd98f00b204e9800998ecf8427e")) + (let ((hash "acbd18db4cc2f85cedef654fccc4a4d8")) + (should (equal (gravatar-hash "foo") hash)) + (should (equal (gravatar-hash "foo ") hash)) + (should (equal (gravatar-hash " foo") hash)) + (should (equal (gravatar-hash " foo ") hash)))) + +(ert-deftest gravatar-size () + "Test query strings for `gravatar-size'." + (let ((gravatar-default-image nil) + (gravatar-force-default nil)) + (let ((gravatar-size 2048)) + (should (equal (gravatar--query-string) "r=g&s=2048"))) + (let ((gravatar-size nil)) + (should (equal (gravatar--query-string) "r=g"))))) + +(ert-deftest gravatar-default-image () + "Test query strings for `gravatar-default-image'." + (let ((gravatar-force-default nil) + (gravatar-size nil)) + (let ((gravatar-default-image nil)) + (should (equal (gravatar--query-string) "r=g"))) + (let ((gravatar-default-image "404")) + (should (equal (gravatar--query-string) "r=g&d=404"))) + (let ((gravatar-default-image "https://foo/bar.png")) + (should (equal (gravatar--query-string) + "r=g&d=https%3A%2F%2Ffoo%2Fbar.png"))))) + +(ert-deftest gravatar-force-default () + "Test query strings for `gravatar-force-default'." + (let ((gravatar-default-image nil) + (gravatar-size nil)) + (let ((gravatar-force-default nil)) + (should (equal (gravatar--query-string) "r=g"))) + (let ((gravatar-force-default t)) + (should (equal (gravatar--query-string) "r=g&f=y"))))) + +(ert-deftest gravatar-build-url () + "Test `gravatar-build-url'." + (let ((gravatar-default-image nil) + (gravatar-force-default nil) + (gravatar-size nil) + (gravatar-service 'gravatar) + url) + (gravatar-build-url "foo" (lambda (u) (setq url u))) + (while (not url) + (sleep-for 0.01)) + (should (equal url "\ +https://www.gravatar.com/avatar/acbd18db4cc2f85cedef654fccc4a4d8?r=g")))) + +;;; gravatar-tests.el ends here diff --git a/test/lisp/image/image-dired-tests.el b/test/lisp/image/image-dired-tests.el new file mode 100644 index 00000000000..00df72487fd --- /dev/null +++ b/test/lisp/image/image-dired-tests.el @@ -0,0 +1,37 @@ +;;; image-dired-tests.el --- Tests for image-dired.el -*- lexical-binding: t -*- + +;; Copyright (C) 2021-2022 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Code: + +(require 'ert) +(require 'image-dired) + +(defun image-dired-test-image-file (name) + (expand-file-name + name (expand-file-name "data/image" + (or (getenv "EMACS_TEST_DIRECTORY") + "../")))) + +(ert-deftest image-dired-tests-get-exif-file-name () + (skip-unless (image-type-available-p 'jpeg)) + (let ((img (image-dired-test-image-file "black.jpg"))) + (should (equal (image-dired-get-exif-file-name img) + "2019_09_21_16_22_13_black.jpg")))) + +;;; image-dired-tests.el ends here diff --git a/test/lisp/image/image-dired-util-tests.el b/test/lisp/image/image-dired-util-tests.el new file mode 100644 index 00000000000..39862fc6faa --- /dev/null +++ b/test/lisp/image/image-dired-util-tests.el @@ -0,0 +1,54 @@ +;;; image-dired-util-tests.el --- Tests for image-dired.el -*- lexical-binding: t -*- + +;; Copyright (C) 2022 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Code: + +(require 'ert) +(require 'ert-x) +(require 'image-dired) +(require 'image-dired-util) +(require 'xdg) + +(ert-deftest image-dired-thumb-name/standard () + (let ((image-dired-thumbnail-storage 'standard)) + (should (file-name-absolute-p (image-dired-thumb-name "foo.jpg"))) + (should (string-search (xdg-cache-home) + (image-dired-thumb-name "foo.jpg"))) + (should (string-match (rx (in "0-9a-f") ".png") + (image-dired-thumb-name "foo.jpg"))))) + +(ert-deftest image-dired-thumb-name/image-dired () + ;; Avoid trying to create `image-dired-dir'. + (ert-with-temp-directory dir + (let ((image-dired-dir dir) + (image-dired-thumbnail-storage 'image-dired)) + (should (file-name-absolute-p (image-dired-thumb-name "foo.jpg"))) + (should (equal (file-name-nondirectory + ;; The checksum is based on the directory name. + (image-dired-thumb-name "/some/path/foo.jpg")) + "foo_45fff7fcc4a0945679b7b11dec36a82d.thumb.jpg"))))) + +(ert-deftest image-dired-thumb-name/per-directory () + (let ((image-dired-thumbnail-storage 'per-directory)) + (should (file-name-absolute-p (image-dired-thumb-name "foo.jpg"))) + (should (equal (file-name-nondirectory + (image-dired-thumb-name "foo.jpg")) + "foo.thumb.jpg")))) + +;;; image-dired-util-tests.el ends here |