Documented font-backend X resource and frame parameter.
[emacs.git] / test / newsticker-testsuite.el
blobacc02edba1c3b1ddc76465f6f63d8737efdcd94c
1 ;;; newsticker-testsuite.el --- Test suite for newsticker.
3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Ulf Jasper <ulf.jasper@web.de>
7 ;; Filename: newsticker-testsuite.el
8 ;; URL: http://www.nongnu.org/newsticker
9 ;; Keywords: News, RSS, Atom
10 ;; Time-stamp: "14. Juni 2008, 12:09:39 (ulf)"
12 ;; ======================================================================
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software: you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation, either version 3 of the License, or
19 ;; (at your option) any later version.
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 ;; ======================================================================
31 ;;; Commentary:
33 ;;; Code:
35 (require 'cl) ; assert
37 ;; ======================================================================
38 ;; Entry point
39 ;; ======================================================================
40 (defun newsticker--testsuite ()
41 "Unit test for newsticker.
42 Subtests signal errors if something goes wrong."
43 (interactive)
44 (newsticker--test--guid)
45 (newsticker--test--cache-contains)
46 (newsticker--test--decode-iso8601-date)
47 (newsticker--test--decode-rfc822-date)
48 (newsticker--test--group-manage-orphan-feeds)
49 (message "All tests passed successfully."))
51 ;; ======================================================================
52 ;; Tests for newsticker-backend
53 ;; ======================================================================
54 (defun newsticker--test--guid ()
55 "Test `newsticker-guid-*'.
56 Signals an error if something goes wrong."
57 (assert (string= "blah" (newsticker--guid-to-string "blah")))
58 (assert (string= "myguid" (newsticker--guid '("title1" "description1" "link1"
59 nil 'new 42 nil nil
60 ((guid () "myguid")))))))
62 (defun newsticker--test--cache-contains ()
63 "Test `newsticker--test--cache-contains'.
64 Signals an error if something goes wrong."
65 (let ((newsticker--cache '((feed1
66 ("title1" "description1" "link1" nil 'new 42
67 nil nil ((guid () "myguid")))))))
68 (newsticker--guid-to-string
69 (assoc 'guid (newsticker--extra '("title1" "description1"
70 "link1" nil 'new 42 nil nil
71 ((guid "myguid"))))))
72 (assert (newsticker--cache-contains newsticker--cache 'feed1 "WRONGTITLE"
73 "description1" "link1" 'new "myguid"))
74 (assert (not (newsticker--cache-contains newsticker--cache 'feed1 "title1"
75 "description1" "link1" 'new
76 "WRONG GUID")))
77 (assert (newsticker--cache-contains newsticker--cache 'feed1 "title1"
78 "description1" "link1" 'new "myguid")))
79 (let ((newsticker--cache '((feed1
80 ("title1" "description1" "link1" nil 'new 42
81 nil nil ((guid () "myguid1")))
82 ("title1" "description1" "link1" nil 'new 42
83 nil nil ((guid () "myguid2")))))))
84 (assert (not (newsticker--cache-contains newsticker--cache 'feed1 "title1"
85 "description1" "link1" 'new
86 "myguid")))
87 (assert (string= "myguid1"
88 (newsticker--guid (newsticker--cache-contains
89 newsticker--cache 'feed1 "title1"
90 "description1" "link1" 'new
91 "myguid1"))))
92 (assert (string= "myguid2"
93 (newsticker--guid (newsticker--cache-contains
94 newsticker--cache 'feed1 "title1"
95 "description1" "link1" 'new
96 "myguid2"))))))
98 (defun newsticker--do-test--decode-iso8601-date (input expected)
99 "Actually test `newsticker--decode-iso8601-date'.
100 Signals an error if iso8601-encoded INPUT does not match EXPECTED."
101 (let ((result (format-time-string "%Y-%m-%dT%H:%M:%S"
102 (newsticker--decode-iso8601-date input)
103 t)))
104 (assert (string= result expected)
105 nil "Error decoding '%s': found '%s' but expected '%s'."
106 input result expected)))
108 (defun newsticker--test--decode-iso8601-date ()
109 "Test `newsticker--decode-iso8601-date'."
110 (newsticker--decode-iso8601-date "2004-09-17T05:09:49+00:00")
111 (newsticker--decode-iso8601-date "2004-09-17T05:09+00:00")
112 (newsticker--decode-iso8601-date "2004-09-17T05:09:49")
113 (newsticker--decode-iso8601-date "2004-09-17T05:09")
114 (newsticker--decode-iso8601-date "2004-09-17")
115 (newsticker--decode-iso8601-date "2004-09")
116 (newsticker--do-test--decode-iso8601-date "2004"
117 "2004-01-01T00:00:00")
118 (newsticker--do-test--decode-iso8601-date "2004-09"
119 "2004-09-01T00:00:00")
120 (newsticker--do-test--decode-iso8601-date "2004-09-17"
121 "2004-09-17T00:00:00")
122 (newsticker--do-test--decode-iso8601-date "2004-09-17T05:09"
123 "2004-09-17T05:09:00")
124 (newsticker--do-test--decode-iso8601-date "2004-09-17T05:09:49"
125 "2004-09-17T05:09:49")
126 (newsticker--do-test--decode-iso8601-date "2004-09-17T05:09:49.123"
127 "2004-09-17T05:09:49")
128 (newsticker--do-test--decode-iso8601-date "2004-09-17T05:09+01:00"
129 "2004-09-17T04:09:00")
130 (newsticker--do-test--decode-iso8601-date "2004-09-17T05:09-02:00"
131 "2004-09-17T07:09:00"))
133 (defun newsticker--do-test--decode-rfc822-date (input expected)
134 "Actually test `newsticker--decode-rfc822-date'.
135 Signals an error if rfc822-encoded INPUT does not match EXPECTED."
136 (let ((result (format-time-string "%Y-%m-%dT%H:%M:%S"
137 (newsticker--decode-rfc822-date input)
138 t)))
139 (assert (string= result expected)
140 nil "Error decoding '%s': found '%s' but expected '%s'."
141 input result expected)))
143 (defun newsticker--test--decode-rfc822-date ()
144 "Test `newsticker--decode-rfc822-date'."
145 (newsticker--do-test--decode-rfc822-date "Mon, 10 Mar 2008 19:27:52 +0100"
146 "2008-03-10T18:27:52")
147 ;;(format-time-string "%d.%m.%y, %H:%M %T%z"
148 ;;(newsticker--decode-rfc822-date "Mon, 10 Mar 2008 19:27:52 +0200"))
150 (newsticker--do-test--decode-rfc822-date "Mon, 10 Mar 2008 19:27:52"
151 "2008-03-10T19:27:52")
152 (newsticker--do-test--decode-rfc822-date "Mon, 10 Mar 2008 19:27"
153 "2008-03-10T19:27:00")
154 (newsticker--do-test--decode-rfc822-date "10 Mar 2008 19:27"
155 "2008-03-10T19:27:00")
156 (newsticker--do-test--decode-rfc822-date "Mon, 10 Mar 2008"
157 "2008-03-10T00:00:00")
158 (newsticker--do-test--decode-rfc822-date "10 Mar 2008"
159 "2008-03-10T00:00:00")
160 (newsticker--do-test--decode-rfc822-date "Sat, 01 Dec 2007 00:05:00 +0100"
161 "2007-11-30T23:05:00")
162 (newsticker--do-test--decode-rfc822-date "Sun, 30 Dec 2007 18:58:13 +0100"
163 "2007-12-30T17:58:13"))
165 ;; ======================================================================
166 ;; Tests for newsticker-treeview
167 ;; ======================================================================
168 (defun newsticker--test--group-manage-orphan-feeds ()
169 "Test `newsticker--group-manage-orphan-feeds'.
170 Signals an error if something goes wrong."
171 (let ((newsticker-groups '("Feeds"))
172 (newsticker-url-list-defaults nil)
173 (newsticker-url-list '(("feed1") ("feed2") ("feed3"))))
174 (newsticker--group-manage-orphan-feeds)
175 (assert (equal '("Feeds" "feed3" "feed2" "feed1")
176 newsticker-groups))))
178 (provide 'newsticker-testsuite)
180 ;; arch-tag: e6c09af2-cc7a-4373-8f5f-9c36699ec34c
181 ;;; newsticker-testsuite.el ends here