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