summaryrefslogtreecommitdiff
path: root/third-party/s-xml-rpc/test/test-xml-rpc.lisp
blob: 3933a88befa75efb3dd5eb4c06cb678262dcff73 (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
;;;; -*- mode: lisp -*-
;;;;
;;;; $Id: test-xml-rpc.lisp,v 1.4 2008-02-15 15:42:40 scaekenberghe Exp $
;;;;
;;;; Unit and functional tests for xml-rpc.lisp
;;;;
;;;; Copyright (C) 2002, 2004 Sven Van Caekenberghe, Beta Nine BVBA.
;;;;
;;;; You are granted the rights to distribute and use this software
;;;; as governed by the terms of the Lisp Lesser General Public License
;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.

(in-package :s-xml-rpc)

(assert
 (let ((now (get-universal-time)))
   (equal (iso8601->universal-time (universal-time->iso8601 now))
	  now)))

(assert
 (equal (with-input-from-string (in (encode-xml-rpc-call "add" 1 2))
	  (decode-xml-rpc in))
	'("add" 1 2)))

(assert
 (equal (with-input-from-string (in (encode-xml-rpc-result '(1 2)))
	  (car (decode-xml-rpc in)))
	'(1 2)))

(let ((condition (with-input-from-string (in (encode-xml-rpc-fault "Fatal Error" 100))
		   (decode-xml-rpc in))))
  (assert (typep condition 'xml-rpc-fault))
  (assert (equal (xml-rpc-fault-string condition) "Fatal Error"))
  (assert (equal (xml-rpc-fault-code condition) 100)))

(assert
 (xml-rpc-time-p (xml-rpc-call (encode-xml-rpc-call "currentTime.getCurrentTime")
			       :host "time.xmlrpc.com")))

(assert
 (equal (xml-rpc-call (encode-xml-rpc-call "examples.getStateName" 41)
		      :host "betty.userland.com")
	"South Dakota"))

(assert
 (equal (call-xml-rpc-server '(:host "betty.userland.com") "examples.getStateName" 41)
	"South Dakota"))

#-clisp
(assert
 (let ((server-process (start-xml-rpc-server :port 8080)))
   (import 's-xml-rpc::xml-rpc-implementation-version :s-xml-rpc-exports)
   (sleep 1) ; give the server some time to come up ;-)
   (unwind-protect
       (equal (xml-rpc-call (encode-xml-rpc-call "XML-RPC-IMPLEMENTATION-VERSION") :port 8080)
	      (xml-rpc-implementation-version))
     (s-sysdeps:kill-process server-process)
     (unintern 's-xml-rpc::xml-rpc-implementation-version :s-xml-rpc-exports))))

(assert
    (let* ((struct-in (xml-rpc-struct :foo 100 :bar ""))
           (xml (with-output-to-string (out)
                  (encode-xml-rpc-value struct-in out)))
           (struct-out (with-input-from-string (in xml)
                         (decode-xml-rpc in))))
      (xml-rpc-struct-equal struct-in struct-out)))

;; testing whitespace handling

(assert (null (decode-xml-rpc (make-string-input-stream 
"<array>
  <data>  
  </data>
</array>")))) 

(assert (equalp (decode-xml-rpc (make-string-input-stream
"<params>
  <param>
    <value>
       foo
    </value>
  </param>
  <param>
    <value>
      <array>
        <data>
          <value><i4>12</i4></value>
          <value><string>Egypt</string></value>
          <value><boolean>1</boolean></value>
          <value> <string>      </string> </value>
          <value>   </value>
          <value> fgo </value>
          <value><i4>-31</i4></value>
          <value></value>
          <double>		-12.214 </double>
          <dateTime.iso8601>
                 19980717T14:08:55 </dateTime.iso8601>
          <base64>eW91IGNhbid0IHJlYWQgdGhpcyE=</base64>
        </data>
      </array>
    </value>
  </param>
</params>"))
`("
       foo
    " 
  (12 
   "Egypt" 
   T 
   "      " 
   "   " 
   " fgo " 
   -31 
   "" 
   -12.214D0 
   ,(xml-rpc-time (iso8601->universal-time  "19980717T14:08:55")) 
   #(121 111 117 32 99 97 110 39 116 32 114 101 97 100 32 116 104 105 115 33)))))

(assert (equalp (decode-xml-rpc (make-string-input-stream 
"<array>
  <data>
    <value></value>
  </data>
</array>"))
'("")))

(assert (equalp (decode-xml-rpc (make-string-input-stream 
"<array>
  <data>
    <value>
      <string>XYZ</string>
    </value>
  </data>
</array>"))
'("XYZ")))

;; double decoding

(assert (< (abs (- (decode-xml-rpc (make-string-input-stream "<value><double>3.141592653589793</double></value>"))
                   pi))
           0.000000000001D0))

;; string decoding

(assert (equal (decode-xml-rpc (make-string-input-stream "<value><string>foo</string></value>"))
               "foo"))

(assert (equal (decode-xml-rpc (make-string-input-stream "<value>foo</value>"))
               "foo"))

(assert (equal (decode-xml-rpc (make-string-input-stream "<value><string></string></value>"))
               ""))

(assert (equal (decode-xml-rpc (make-string-input-stream "<value></value>"))
               ""))

;; boolean encoding

(assert (equal (with-output-to-string (out)
                 (encode-xml-rpc-value t out))
               "<value><boolean>1</boolean></value>"))

(assert (equal (with-output-to-string (out)
                 (encode-xml-rpc-value nil out))
               "<value><boolean>0</boolean></value>"))


;; boolean decoding

(assert (equal (decode-xml-rpc (make-string-input-stream "<value><boolean>1</boolean></value>"))
               t))

(assert (equal (decode-xml-rpc (make-string-input-stream "<value><boolean>0</boolean></value>"))
               nil))

;;;; eof