-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirephp-tests.lisp
122 lines (108 loc) · 5.69 KB
/
firephp-tests.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
(defpackage #:firephp-tests
(:use :cl :hu.dwim.stefil)
(:documentation
"FirePHP protocol server implementation tests"))
(in-package :firephp-tests)
(defmacro with-replaced-function (fdef &rest body)
(let ((oldf (gensym))
(result (gensym))
(name (car fdef))
(args (cadr fdef))
(rbody (cddr fdef)))
`(let ((,oldf (symbol-function ',name)))
(setf (symbol-function ',name) (lambda ,args ,@rbody))
(let ((,result (progn ,@body)))
(setf (symbol-function ',name) ,oldf)
,result))))
(defsuite* all-tests)
(defun do-all-tests ()
(all-tests))
(defmacro with-temporary-reply (&body body)
`(let ((hunchentoot:*reply* (make-instance 'hunchentoot:reply)))
,@body))
(defun headers-are-present (headers)
(loop for i in headers do
(is
(string=
(hunchentoot:header-out (car i))
(cdr i)))))
(deftest sends-right-headers-on-dump-with-label ()
(with-temporary-reply
(firephp:send-message "Test" :label "TestLabel")
(headers-are-present
'((:X-WF-1-INDEX . "1")
(:X-WF-1-2-1-1 . "20|{\"TestLabel\":\"Test\"}|")
(:X-WF-1-STRUCTURE-2 . "http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1")
(:X-WF-1-PLUGIN-1 . "http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3")
(:X-WF-PROTOCOL-1 . "http://meta.wildfirehq.org/Protocol/JsonStream/0.2")))))
(deftest sends-right-headers-on-dump ()
(with-temporary-reply
(firephp:send-message "Test")
(headers-are-present
'((:X-WF-1-INDEX . "1")
(:X-WF-1-2-1-1 . "6|\"Test\"|")
(:X-WF-1-STRUCTURE-2 . "http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1")
(:X-WF-1-PLUGIN-1 . "http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3")
(:X-WF-PROTOCOL-1 . "http://meta.wildfirehq.org/Protocol/JsonStream/0.2")))))
(deftest sends-right-headers-on-log ()
(with-temporary-reply
(firephp:send-message "Test" :type :log)
(headers-are-present
'((:X-WF-1-INDEX . "1")
(:X-WF-1-1-1-1 . "23|[{\"Type\":\"LOG\"},\"Test\"]|")
(:X-WF-1-STRUCTURE-1 . "http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1")
(:X-WF-1-PLUGIN-1 . "http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3")
(:X-WF-PROTOCOL-1 . "http://meta.wildfirehq.org/Protocol/JsonStream/0.2")))))
(deftest sends-right-headers-on-log-with-label ()
(with-temporary-reply
(firephp:send-message "Test" :type :log :label "TestLabel")
(headers-are-present
'((:X-WF-1-INDEX . "1")
(:X-WF-1-1-1-1 . "43|[{\"Type\":\"LOG\",\"Label\":\"TestLabel\"},\"Test\"]|")
(:X-WF-1-STRUCTURE-1 . "http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1")
(:X-WF-1-PLUGIN-1 . "http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3")
(:X-WF-PROTOCOL-1 . "http://meta.wildfirehq.org/Protocol/JsonStream/0.2")))))
(deftest sends-right-headers-on-fb-call-1 ()
(with-temporary-reply
(firephp:fb "Test" "strings")
(headers-are-present
'((:X-WF-1-INDEX . "1")
(:X-WF-1-1-1-1 . "72|[{\"Type\":\"LOG\"},\"#1 "Test"<br\\/>#2 "strings"<br\\/>\"]|")
(:X-WF-1-STRUCTURE-1 . "http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1")
(:X-WF-1-PLUGIN-1 . "http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3")
(:X-WF-PROTOCOL-1 . "http://meta.wildfirehq.org/Protocol/JsonStream/0.2")
(:CONTENT-TYPE . "text/html")))))
(deftest sends-right-headers-on-fb-call-2 ()
(let ((firephp:*escape-html-p* nil))
(with-temporary-reply
(firephp:fb "Test" "strings")
(headers-are-present
'((:X-WF-1-INDEX . "1")
(:X-WF-1-1-1-1 . "48|[{\"Type\":\"LOG\"},\"#1 \\\"Test\\\"\\n#2 \\\"strings\\\"\\n\"]|")
(:X-WF-1-STRUCTURE-1 . "http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1")
(:X-WF-1-PLUGIN-1 . "http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3")
(:X-WF-PROTOCOL-1 . "http://meta.wildfirehq.org/Protocol/JsonStream/0.2")
(:CONTENT-TYPE . "text/html"))))))
(deftest sends-right-headers-on-descr-call-1 ()
(with-temporary-reply
(firephp:descr "Test" "strings")
(headers-are-present
'((:X-WF-1-INDEX . "1")
(:X-WF-1-1-1-1
. "212|[{\"Type\":\"LOG\"},\""Test"<br\\/> [simple-string]<br\\/><br\\/>Element-type: CHARACTER<br\\/>Length: 4<br\\/>"strings"<br\\/> [simple-string]<br\\/><br\\/>Element-type: CHARACTER<br\\/>Length: 7<br\\/>\"]|")
(:X-WF-1-STRUCTURE-1 . "http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1")
(:X-WF-1-PLUGIN-1 . "http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3")
(:X-WF-PROTOCOL-1 . "http://meta.wildfirehq.org/Protocol/JsonStream/0.2")
(:CONTENT-TYPE . "text/html")))))
(deftest sends-right-headers-on-descr-call-2 ()
(let ((firephp:*escape-html-p* nil))
(with-temporary-reply
(firephp:descr "Test" "strings")
(headers-are-present
'((:X-WF-1-INDEX . "1")
(:X-WF-1-1-1-1
. "156|[{\"Type\":\"LOG\"},\"\\\"Test\\\"\\n [simple-string]\\n\\nElement-type: CHARACTER\\nLength: 4\\n\\\"strings\\\"\\n [simple-string]\\n\\nElement-type: CHARACTER\\nLength: 7\\n\"]|")
(:X-WF-1-STRUCTURE-1 . "http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1")
(:X-WF-1-PLUGIN-1 . "http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3")
(:X-WF-PROTOCOL-1 . "http://meta.wildfirehq.org/Protocol/JsonStream/0.2")
(:CONTENT-TYPE . "text/html"))))))