fc147745296fdc7c30dade805f0b57cc194ee6c0
[riece] / lisp / test / test-riece-log.el
1 (require 'riece-log)
2
3 (luna-define-class test-riece-log (lunit-test-case))
4
5 (defun test-riece-log-delete-directory (directory)
6   (let (file-name-coding-system
7         default-file-name-coding-system
8          (files (directory-files directory t nil t)))
9     (while files
10       (if (file-directory-p (car files))
11           (unless (member (file-name-nondirectory (car files)) '("." ".."))
12             (test-riece-log-delete-directory (car files)))
13         (delete-file (car files)))
14       (setq files (cdr files)))
15     (delete-directory directory)))
16
17 (luna-define-method lunit-test-case-setup ((case test-riece-log))
18   (setq riece-log-directory
19         (expand-file-name (make-temp-name "test-riece-log")
20                            (if (featurep 'xemacs)
21                                (temp-directory)
22                              temporary-file-directory))
23         test-riece-log-directory
24         (expand-file-name "=23riece" riece-log-directory))
25   (make-directory riece-log-directory)
26   (make-directory test-riece-log-directory)
27   (write-region "03:14 <test> a b c\n03:15 <test> a b c\n" nil
28                 (expand-file-name "19700102.txt" test-riece-log-directory)
29                 t 0)
30   (write-region "03:14 <test> 1 2 3\n" nil
31                 (expand-file-name "19700101.txt" test-riece-log-directory)
32                 t 0))
33
34 (luna-define-method lunit-test-case-teardown ((case test-riece-log))
35   (test-riece-log-delete-directory riece-log-directory))
36
37 (luna-define-method test-riece-log-insert-1 ((case test-riece-log))
38   (let (riece-log-directory-map)
39     (lunit-assert-2
40      case
41      (equal
42       (concat "03:14 <test> 1 2 3 (1970/01/01)\n"
43               "03:14 <test> a b c (1970/01/02)\n"
44               "03:15 <test> a b c (1970/01/02)\n")
45       (with-temp-buffer
46         (riece-log-insert (riece-make-identity "#riece" "") 3)
47         (buffer-string))))))
48
49 (luna-define-method test-riece-log-insert-2 ((case test-riece-log))
50   (let (riece-log-directory-map)
51     (lunit-assert-2
52      case
53      (equal ""
54             (with-temp-buffer
55               (riece-log-insert (riece-make-identity "#riece" "") t)
56               (buffer-string))))))
57
58 (luna-define-method test-riece-log-encode-file-name ((case test-riece-log))
59   (let (riece-log-file-name-coding-system)
60     (lunit-assert-2
61      case
62      (equal "=23riece"
63             (riece-log-encode-file-name "#riece")))
64     (lunit-assert-2
65      case
66      (equal "=23riece=3A=2A=2Ejp"
67             (riece-log-encode-file-name "#riece:*.jp")))
68     (lunit-assert-2
69      case
70      (equal "=23riece=="
71             (riece-log-encode-file-name "#riece=")))))
72
73 (luna-define-method test-riece-log-encode-file-name-mule
74   ((case test-riece-log))
75   (let ((riece-log-file-name-coding-system 'iso-8859-1))
76     (lunit-assert-2
77      case
78      (equal "=23\xABriece\xBB"
79             (riece-log-encode-file-name
80              (format "#%criece%c"
81                      (make-char 'latin-iso8859-1 43)
82                      (make-char 'latin-iso8859-1 59))))))
83   (let ((riece-log-file-name-coding-system 'iso-2022-jp))
84     (lunit-assert-2
85      case
86      (equal "=23=1B=24B=24j=21=3C=249=1B=28B"
87             (riece-log-encode-file-name
88              (format "#%c%c%c"
89                     (make-char 'japanese-jisx0208 36 106)
90                     (make-char 'japanese-jisx0208 33 60)
91                     (make-char 'japanese-jisx0208 36 57)))))))
92
93 (luna-define-method test-riece-log-decode-file-name ((case test-riece-log))
94   (let (riece-log-file-name-coding-system)
95     (lunit-assert-2
96      case
97      (equal "#riece"
98             (riece-log-decode-file-name "=23riece")))
99     (lunit-assert-2
100      case
101      (equal "#riece:*.jp"
102             (riece-log-decode-file-name "=23riece=3A=2A=2Ejp")))
103     (lunit-assert-2
104      case
105      (equal "#riece="
106             (riece-log-decode-file-name "=23riece==")))))
107
108 (luna-define-method test-riece-log-decode-file-name-mule
109   ((case test-riece-log))
110   (let ((riece-log-file-name-coding-system 'iso-8859-1))
111     (lunit-assert-2
112      case
113      (equal (format "#%criece%c"
114                      (make-char 'latin-iso8859-1 43)
115                      (make-char 'latin-iso8859-1 59))
116             (riece-log-decode-file-name
117              "=23\xABriece\xBB"))))
118   (let ((riece-log-file-name-coding-system 'iso-2022-jp))
119     (lunit-assert-2
120      case
121      (equal (format "#%c%c%c"
122                     (make-char 'japanese-jisx0208 36 106)
123                     (make-char 'japanese-jisx0208 33 60)
124                     (make-char 'japanese-jisx0208 36 57))
125             (riece-log-decode-file-name
126              "=23=1B=24B=24j=21=3C=249=1B=28B")))))
127
128 (luna-define-method test-riece-log-display-message-function
129   ((case test-riece-log))
130   (let ((riece-log-file-name-coding-system 'euc-jp)
131         (riece-log-enabled t)
132         riece-log-directory-map
133         (riece-server-process-alist
134          (list (cons "" (start-process "" (current-buffer) "true")))))
135     (put 'riece-log 'riece-addon-enabled t)
136     (riece-log-display-message-function
137      (riece-make-message
138       (riece-make-identity "ueno" "")
139       (riece-make-identity (format "#%c%c%c"
140                                    (make-char 'japanese-jisx0208 36 106)
141                                    (make-char 'japanese-jisx0208 33 60)
142                                    (make-char 'japanese-jisx0208 36 57))
143                            "")
144       "a b c\n" nil t))
145     (put 'riece-log 'riece-addon-enabled nil))
146   (let (file-name-coding-system
147         default-file-name-coding-system)
148     (lunit-assert-2
149      case
150      (file-directory-p
151       (expand-file-name
152        (encode-coding-string
153         (format "=23%c%c%c"
154                 (make-char 'japanese-jisx0208 36 106)
155                 (make-char 'japanese-jisx0208 33 60)
156                 (make-char 'japanese-jisx0208 36 57))
157         'euc-jp)
158        riece-log-directory)))))