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