163
|
1 |
"{ Package: 'exept:regression' }"
|
|
2 |
|
|
3 |
TestCase subclass:#XMLCoderTests
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'XML-Presentation'
|
|
8 |
!
|
|
9 |
|
|
10 |
!XMLCoderTests class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
documentation
|
|
13 |
"
|
|
14 |
documentation to be added.
|
|
15 |
|
|
16 |
[author:]
|
|
17 |
Stefan Vogel (stefan@zwerg)
|
|
18 |
|
|
19 |
[see also:]
|
|
20 |
|
|
21 |
[instance variables:]
|
|
22 |
|
|
23 |
[class variables:]
|
|
24 |
"
|
|
25 |
!
|
|
26 |
|
|
27 |
history
|
|
28 |
"Created: / 26.6.2002 / 10:32:14 / stefan"
|
|
29 |
!
|
|
30 |
|
|
31 |
history
|
|
32 |
"Created: / 26.6.2002 / 10:32:14 / stefan"
|
|
33 |
! !
|
|
34 |
|
|
35 |
!XMLCoderTests methodsFor:'helpers'!
|
|
36 |
|
|
37 |
encodeAndDecode:anObject
|
|
38 |
"test, that encoding and decoding an Object results in anObject"
|
|
39 |
|
|
40 |
|encodedString decodedObject|
|
|
41 |
|
|
42 |
encodedString := XMLStandardCoder new encodingOf:anObject.
|
|
43 |
decodedObject := (XMLStandardDecoder on:encodedString readStream) next.
|
|
44 |
|
|
45 |
self should:anObject = decodedObject.
|
|
46 |
|
|
47 |
encodedString := XMLStandardCoder new aspect:#encodeInstanceVariables; encodingOf:anObject.
|
|
48 |
decodedObject := (XMLStandardDecoder on:encodedString readStream) useSend:true; next.
|
|
49 |
|
|
50 |
self should:anObject = decodedObject.
|
|
51 |
|
|
52 |
^ decodedObject.
|
|
53 |
! !
|
|
54 |
|
|
55 |
!XMLCoderTests methodsFor:'initialize / release'!
|
|
56 |
|
|
57 |
setUp
|
|
58 |
"common setup - invoked before testing"
|
|
59 |
|
|
60 |
super setUp
|
|
61 |
!
|
|
62 |
|
|
63 |
tearDown
|
|
64 |
"common cleanup - invoked after testing"
|
|
65 |
|
|
66 |
super tearDown
|
|
67 |
! !
|
|
68 |
|
|
69 |
!XMLCoderTests methodsFor:'tests'!
|
|
70 |
|
|
71 |
testArray
|
|
72 |
"test encoding an decoding of an integer"
|
|
73 |
|
|
74 |
|arr|
|
|
75 |
|
|
76 |
arr := Array new:10.
|
|
77 |
arr at:1 put:true.
|
|
78 |
arr at:2 put:'hallo'.
|
|
79 |
arr at:3 put:#symbol.
|
|
80 |
arr at:4 put:nil.
|
|
81 |
"/ arr at:6 put:arr.
|
|
82 |
|
|
83 |
self encodeAndDecode:arr
|
|
84 |
|
|
85 |
"
|
|
86 |
self run:#testArray
|
|
87 |
"
|
|
88 |
!
|
|
89 |
|
|
90 |
testBytes
|
|
91 |
"test encoding an decoding of an ByteArray"
|
|
92 |
|
|
93 |
self encodeAndDecode:#[1].
|
|
94 |
self encodeAndDecode:#[1 2].
|
|
95 |
self encodeAndDecode:#[1 2 3].
|
|
96 |
self encodeAndDecode:#[1 2 3 4].
|
|
97 |
self encodeAndDecode:#[1 2 3 4 5].
|
|
98 |
self encodeAndDecode:#[1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 9 0 12 3 4 56 7 8 9 0].
|
|
99 |
|
|
100 |
"
|
|
101 |
self run:#testBytes
|
|
102 |
"
|
|
103 |
!
|
|
104 |
|
|
105 |
testCharacter
|
|
106 |
"test encoding an decoding of a Character"
|
|
107 |
|
|
108 |
self encodeAndDecode:$a.
|
|
109 |
self encodeAndDecode:$ä.
|
|
110 |
|
|
111 |
"
|
|
112 |
self run:#testCharacter
|
|
113 |
"
|
|
114 |
!
|
|
115 |
|
|
116 |
testComplex
|
|
117 |
"test encoding an decoding of an OrderedCollection"
|
|
118 |
|
|
119 |
|coll r decodedObject|
|
|
120 |
|
|
121 |
coll := OrderedCollection new.
|
|
122 |
coll add:true.
|
|
123 |
coll add:'hallo'.
|
|
124 |
coll add:#symbol.
|
|
125 |
coll add:(r:= #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23]).
|
|
126 |
coll add:#symbol.
|
|
127 |
coll add:r.
|
|
128 |
coll add:coll copy.
|
|
129 |
|
|
130 |
decodedObject := self encodeAndDecode:coll.
|
|
131 |
|
|
132 |
self should:(decodedObject at:4) == (decodedObject at:6).
|
|
133 |
|
|
134 |
"
|
|
135 |
self run:#testComplex
|
|
136 |
"
|
|
137 |
!
|
|
138 |
|
|
139 |
testDictionary
|
|
140 |
"test encoding an decoding of an integer"
|
|
141 |
|
|
142 |
|dict|
|
|
143 |
|
|
144 |
dict := Dictionary new.
|
|
145 |
dict at:true put:1234.
|
|
146 |
dict at:#murks put:'hallo'.
|
|
147 |
dict at:5 put:#symbol.
|
|
148 |
|
|
149 |
self encodeAndDecode:dict
|
|
150 |
|
|
151 |
"
|
164
|
152 |
self run:#testDictionary
|
|
153 |
"
|
|
154 |
!
|
|
155 |
|
|
156 |
testEmptyCollection
|
|
157 |
"test encoding an decoding of an OrderedCollection"
|
|
158 |
|
|
159 |
|set|
|
|
160 |
|
|
161 |
set := OrderedCollection new.
|
|
162 |
|
|
163 |
self encodeAndDecode:set
|
|
164 |
|
|
165 |
"
|
163
|
166 |
self run:#testEmptyCollection
|
|
167 |
"
|
|
168 |
!
|
|
169 |
|
|
170 |
self encodeAndDecode:i
|
|
171 |
"test encoding an decoding of an integer"
|
|
172 |
|
|
173 |
-1.0 to: 1.0 by:0.5 do:[:i|
|
|
174 |
self encodeAndDecode:i
|
|
175 |
].
|
|
176 |
|
|
177 |
"
|
|
178 |
self run:#testFloat
|
|
179 |
"
|
|
180 |
!
|
|
181 |
|
|
182 |
self encodeAndDecode:i
|
|
183 |
"test encoding an decoding of an integer"
|
|
184 |
|
|
185 |
(-3/4) to:(3/4) by:(1/4) do:[:i|
|
|
186 |
self encodeAndDecode:i
|
|
187 |
].
|
|
188 |
|
|
189 |
"
|
|
190 |
self run:#testFraction
|
|
191 |
"
|
|
192 |
!
|
|
193 |
|
|
194 |
testIdentityDictionary
|
|
195 |
"test encoding an decoding of an integer"
|
|
196 |
|
|
197 |
|dict|
|
|
198 |
|
|
199 |
dict := IdentityDictionary new.
|
|
200 |
dict at:true put:1234.
|
|
201 |
dict at:#test put:'hallo'.
|
|
202 |
dict at:5 put:#symbol.
|
|
203 |
|
|
204 |
self encodeAndDecode:dict
|
|
205 |
|
|
206 |
"
|
|
207 |
self run:#testIdentityDictionary
|
|
208 |
"
|
|
209 |
!
|
|
210 |
-100 to: 100 do:[:i|
|
|
211 |
self encodeAndDecode:i
|
|
212 |
|
|
213 |
-100 to: 100 do:[:i|
|
|
214 |
self encodeAndDecode:i
|
|
215 |
self run:#test1
|
|
216 |
|
|
217 |
"
|
|
218 |
self run:#test1
|
|
219 |
"
|
|
220 |
!
|
|
221 |
|
|
222 |
testOrderedCollection
|
|
223 |
"test encoding an decoding of an OrderedCollection"
|
|
224 |
|
|
225 |
|set|
|
|
226 |
|
|
227 |
set := OrderedCollection new.
|
|
228 |
set add:true.
|
|
229 |
set add:'hallo'.
|
|
230 |
set add:#symbol.
|
|
231 |
|
|
232 |
self encodeAndDecode:set
|
|
233 |
|
|
234 |
"
|
|
235 |
self run:#testOrderedCollection
|
|
236 |
"
|
|
237 |
!
|
|
238 |
|
|
239 |
testSet
|
|
240 |
"test encoding an decoding of a set"
|
|
241 |
|
|
242 |
|set|
|
|
243 |
|
|
244 |
set := Set new.
|
|
245 |
set add:true.
|
|
246 |
set add:'hallo'.
|
|
247 |
set add:#symbol.
|
|
248 |
|
|
249 |
self encodeAndDecode:set
|
|
250 |
|
|
251 |
"
|
|
252 |
self run:#testSet
|
|
253 |
"
|
|
254 |
!
|
|
255 |
|
|
256 |
testString
|
|
257 |
"test encoding an decoding of a String"
|
165
|
258 |
|
|
259 |
Character tab asString, Character tab asString, 'tabs',
|
|
260 |
Character tab asString.
|
|
261 |
self encodeAndDecode:Character tab asString , 'with',
|
|
262 |
Character tab asString, Character tab asString, 'tabs',
|
|
263 |
Character tab asString.
|
163
|
264 |
self encodeAndDecode:Character tab asString , '& with',
|
|
265 |
Character tab asString, Character tab asString, 'tabs',
|
|
266 |
Character tab asString.
|
|
267 |
|
|
268 |
"
|
|
269 |
self run:#testUUID
|
|
270 |
"
|
|
271 |
! !
|
|
272 |
|
|
273 |
^ '$Header$'
|
|
274 |
|
|
275 |
version
|
|
276 |
^ '$Header$'
|
|
277 |
! !
|