1447
|
1 |
"{ Package: 'stx:goodies/regression' }"
|
163
|
2 |
|
208
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
163
|
5 |
TestCase subclass:#XMLCoderTests
|
219
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
1551
|
9 |
category:'tests-Regression-XML'
|
163
|
10 |
!
|
|
11 |
|
|
12 |
!XMLCoderTests class methodsFor:'documentation'!
|
|
13 |
|
|
14 |
documentation
|
|
15 |
"
|
|
16 |
documentation to be added.
|
|
17 |
|
|
18 |
[author:]
|
1447
|
19 |
Stefan Vogel (stefan@zwerg)
|
163
|
20 |
|
|
21 |
[see also:]
|
|
22 |
|
|
23 |
[instance variables:]
|
|
24 |
|
|
25 |
[class variables:]
|
|
26 |
"
|
|
27 |
! !
|
|
28 |
|
|
29 |
!XMLCoderTests methodsFor:'helpers'!
|
|
30 |
|
|
31 |
encodeAndDecode:anObject
|
|
32 |
"test, that encoding and decoding an Object results in anObject"
|
|
33 |
|
|
34 |
|encodedString decodedObject|
|
|
35 |
|
|
36 |
encodedString := XMLStandardCoder new encodingOf:anObject.
|
|
37 |
decodedObject := (XMLStandardDecoder on:encodedString readStream) next.
|
|
38 |
|
|
39 |
self should:anObject = decodedObject.
|
|
40 |
|
|
41 |
encodedString := XMLStandardCoder new aspect:#encodeInstanceVariables; encodingOf:anObject.
|
|
42 |
decodedObject := (XMLStandardDecoder on:encodedString readStream) useSend:true; next.
|
|
43 |
|
|
44 |
self should:anObject = decodedObject.
|
|
45 |
|
|
46 |
^ decodedObject.
|
|
47 |
! !
|
|
48 |
|
|
49 |
!XMLCoderTests methodsFor:'initialize / release'!
|
|
50 |
|
|
51 |
setUp
|
|
52 |
"common setup - invoked before testing"
|
|
53 |
|
1661
|
54 |
(Smalltalk classNamed:'stx_goodies_xml_stx') isNil ifTrue:[
|
|
55 |
(Smalltalk loadPackage:'stx:goodies/xml/stx') ifFalse:[
|
|
56 |
self error:'stx:goodies/xml/stx cannot be loaded'.
|
|
57 |
].
|
|
58 |
].
|
|
59 |
(Smalltalk classNamed:'stx_goodies_xml_stx') load.
|
|
60 |
|
|
61 |
"Modified: / 31-07-2017 / 10:47:07 / mawalch"
|
163
|
62 |
!
|
|
63 |
|
|
64 |
tearDown
|
|
65 |
"common cleanup - invoked after testing"
|
|
66 |
|
|
67 |
super tearDown
|
|
68 |
! !
|
|
69 |
|
|
70 |
!XMLCoderTests methodsFor:'tests'!
|
|
71 |
|
|
72 |
testArray
|
|
73 |
"test encoding an decoding of an integer"
|
|
74 |
|
|
75 |
|arr|
|
|
76 |
|
|
77 |
arr := Array new:10.
|
|
78 |
arr at:1 put:true.
|
|
79 |
arr at:2 put:'hallo'.
|
|
80 |
arr at:3 put:#symbol.
|
|
81 |
arr at:4 put:nil.
|
|
82 |
"/ arr at:6 put:arr.
|
|
83 |
|
|
84 |
self encodeAndDecode:arr
|
|
85 |
|
|
86 |
"
|
|
87 |
self run:#testArray
|
|
88 |
"
|
|
89 |
!
|
|
90 |
|
|
91 |
testBytes
|
|
92 |
"test encoding an decoding of an ByteArray"
|
|
93 |
|
|
94 |
self encodeAndDecode:#[1].
|
|
95 |
self encodeAndDecode:#[1 2].
|
|
96 |
self encodeAndDecode:#[1 2 3].
|
|
97 |
self encodeAndDecode:#[1 2 3 4].
|
|
98 |
self encodeAndDecode:#[1 2 3 4 5].
|
|
99 |
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].
|
|
100 |
|
|
101 |
"
|
|
102 |
self run:#testBytes
|
|
103 |
"
|
|
104 |
!
|
|
105 |
|
|
106 |
testCharacter
|
|
107 |
"test encoding an decoding of a Character"
|
|
108 |
|
|
109 |
self encodeAndDecode:$a.
|
|
110 |
self encodeAndDecode:$ä.
|
|
111 |
|
|
112 |
"
|
|
113 |
self run:#testCharacter
|
|
114 |
"
|
|
115 |
!
|
|
116 |
|
|
117 |
testComplex
|
|
118 |
"test encoding an decoding of an OrderedCollection"
|
|
119 |
|
|
120 |
|coll r decodedObject|
|
|
121 |
|
|
122 |
coll := OrderedCollection new.
|
|
123 |
coll add:true.
|
|
124 |
coll add:'hallo'.
|
|
125 |
coll add:#symbol.
|
|
126 |
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]).
|
|
127 |
coll add:#symbol.
|
|
128 |
coll add:r.
|
|
129 |
coll add:coll copy.
|
|
130 |
|
|
131 |
decodedObject := self encodeAndDecode:coll.
|
|
132 |
|
|
133 |
self should:(decodedObject at:4) == (decodedObject at:6).
|
|
134 |
|
|
135 |
"
|
|
136 |
self run:#testComplex
|
|
137 |
"
|
|
138 |
!
|
|
139 |
|
|
140 |
testDictionary
|
|
141 |
"test encoding an decoding of an integer"
|
|
142 |
|
|
143 |
|dict|
|
|
144 |
|
|
145 |
dict := Dictionary new.
|
|
146 |
dict at:true put:1234.
|
|
147 |
dict at:#murks put:'hallo'.
|
|
148 |
dict at:5 put:#symbol.
|
1447
|
149 |
|
163
|
150 |
self encodeAndDecode:dict
|
|
151 |
|
|
152 |
"
|
164
|
153 |
self run:#testDictionary
|
|
154 |
"
|
|
155 |
!
|
|
156 |
|
|
157 |
testEmptyCollection
|
|
158 |
"test encoding an decoding of an OrderedCollection"
|
|
159 |
|
|
160 |
|set|
|
|
161 |
|
|
162 |
set := OrderedCollection new.
|
|
163 |
|
|
164 |
self encodeAndDecode:set
|
|
165 |
|
|
166 |
"
|
163
|
167 |
self run:#testEmptyCollection
|
|
168 |
"
|
|
169 |
!
|
|
170 |
|
217
|
171 |
testFloat
|
163
|
172 |
"test encoding an decoding of an integer"
|
|
173 |
|
|
174 |
-1.0 to: 1.0 by:0.5 do:[:i|
|
1447
|
175 |
self encodeAndDecode:i
|
163
|
176 |
].
|
|
177 |
|
|
178 |
"
|
|
179 |
self run:#testFloat
|
|
180 |
"
|
|
181 |
!
|
|
182 |
|
217
|
183 |
testFraction
|
163
|
184 |
"test encoding an decoding of an integer"
|
|
185 |
|
|
186 |
(-3/4) to:(3/4) by:(1/4) do:[:i|
|
1447
|
187 |
self encodeAndDecode:i
|
163
|
188 |
].
|
|
189 |
|
|
190 |
"
|
|
191 |
self run:#testFraction
|
|
192 |
"
|
|
193 |
!
|
|
194 |
|
|
195 |
testIdentityDictionary
|
|
196 |
"test encoding an decoding of an integer"
|
|
197 |
|
|
198 |
|dict|
|
|
199 |
|
|
200 |
dict := IdentityDictionary new.
|
|
201 |
dict at:true put:1234.
|
|
202 |
dict at:#test put:'hallo'.
|
|
203 |
dict at:5 put:#symbol.
|
1447
|
204 |
|
163
|
205 |
self encodeAndDecode:dict
|
|
206 |
|
|
207 |
"
|
|
208 |
self run:#testIdentityDictionary
|
|
209 |
"
|
|
210 |
!
|
218
|
211 |
|
|
212 |
testInteger
|
|
213 |
"test encoding an decoding of an integer"
|
163
|
214 |
|
219
|
215 |
#( 0 1 10 100 1000 10000 100000 1000000 16rFFFF 16rFFFFFF) do:[:i|
|
1447
|
216 |
self encodeAndDecode:i.
|
|
217 |
self encodeAndDecode:i negated.
|
218
|
218 |
].
|
163
|
219 |
|
|
220 |
"
|
219
|
221 |
self run:#testInteger
|
163
|
222 |
"
|
|
223 |
!
|
|
224 |
|
166
|
225 |
testInterval
|
|
226 |
"test encoding an decoding of a set"
|
|
227 |
|
|
228 |
|interval|
|
|
229 |
|
|
230 |
interval := Interval from:1 to:100.
|
|
231 |
|
|
232 |
self encodeAndDecode:interval
|
|
233 |
|
|
234 |
"
|
|
235 |
self run:#testInterval
|
|
236 |
"
|
|
237 |
!
|
|
238 |
|
217
|
239 |
testLargeInteger
|
|
240 |
"test encoding an decoding of an integer"
|
|
241 |
|
1447
|
242 |
#(
|
|
243 |
16r1FFFFFFF 16r20000000
|
|
244 |
16r3FFFFFFF 16r40000000
|
|
245 |
16r7FFFFFFF 16r80000000
|
|
246 |
16rFFFFFFFF 16r100000000
|
217
|
247 |
|
1447
|
248 |
16r1FFFFFFFF 16r200000000
|
|
249 |
16r3FFFFFFFF 16r400000000
|
|
250 |
16r7FFFFFFFF 16r800000000
|
|
251 |
16rFFFFFFFFF 16r1000000000
|
217
|
252 |
|
1447
|
253 |
16r1FFFFFFFFF 16r2000000000
|
|
254 |
16r3FFFFFFFFF 16r4000000000
|
|
255 |
16r7FFFFFFFFF 16r8000000000
|
|
256 |
16rFFFFFFFFFF 16r10000000000
|
217
|
257 |
|
1447
|
258 |
16r1FFFFFFFFFF 16r20000000000
|
|
259 |
16r3FFFFFFFFFF 16r40000000000
|
|
260 |
16r7FFFFFFFFFF 16r80000000000
|
|
261 |
16rFFFFFFFFFFF 16r100000000000
|
217
|
262 |
|
1447
|
263 |
16r1FFFFFFFFFFF 16r200000000000
|
|
264 |
16r3FFFFFFFFFFF 16r400000000000
|
|
265 |
16r7FFFFFFFFFFF 16r800000000000
|
|
266 |
16rFFFFFFFFFFFF 16r1000000000000
|
217
|
267 |
|
1447
|
268 |
16r1FFFFFFFFFFFFFF 16r200000000000000
|
|
269 |
16r3FFFFFFFFFFFFFF 16r400000000000000
|
|
270 |
16r7FFFFFFFFFFFFFF 16r800000000000000
|
|
271 |
16rFFFFFFFFFFFFFFF 16r1000000000000000
|
217
|
272 |
|
|
273 |
) do:[:i|
|
1447
|
274 |
self encodeAndDecode:i.
|
|
275 |
self encodeAndDecode:i negated.
|
217
|
276 |
].
|
|
277 |
|
|
278 |
"
|
|
279 |
self run:#testLargeInteger
|
|
280 |
self basicNew testLargeInteger
|
|
281 |
"
|
|
282 |
!
|
|
283 |
|
163
|
284 |
testOrderedCollection
|
|
285 |
"test encoding an decoding of an OrderedCollection"
|
|
286 |
|
|
287 |
|set|
|
|
288 |
|
|
289 |
set := OrderedCollection new.
|
|
290 |
set add:true.
|
|
291 |
set add:'hallo'.
|
|
292 |
set add:#symbol.
|
|
293 |
|
|
294 |
self encodeAndDecode:set
|
|
295 |
|
|
296 |
"
|
|
297 |
self run:#testOrderedCollection
|
|
298 |
"
|
|
299 |
!
|
|
300 |
|
217
|
301 |
testPoint
|
|
302 |
"test encoding an decoding of a point"
|
|
303 |
|
|
304 |
-4 to:4 do:[:x |
|
1447
|
305 |
-4 to:4 do:[:y |
|
|
306 |
self encodeAndDecode:(x @ y)
|
|
307 |
]
|
217
|
308 |
].
|
|
309 |
|
|
310 |
"
|
|
311 |
self run:#testPoint
|
|
312 |
"
|
|
313 |
!
|
|
314 |
|
1551
|
315 |
testRecursiveArray
|
|
316 |
|arr encodedString decodedObject|
|
|
317 |
|
|
318 |
arr := Array new:3.
|
|
319 |
arr at:1 put:1.
|
|
320 |
arr at:2 put:arr.
|
|
321 |
arr at:3 put:3.
|
|
322 |
|
|
323 |
encodedString := XMLStandardCoder new encodingOf:arr.
|
|
324 |
decodedObject := (XMLStandardDecoder on:encodedString readStream) next.
|
|
325 |
self assert:(decodedObject at:1) == 1.
|
|
326 |
self assert:(decodedObject at:3) == 3.
|
|
327 |
self assert:(decodedObject at:2) == decodedObject.
|
|
328 |
"
|
|
329 |
self run:#testRecursiveArray
|
|
330 |
"
|
|
331 |
|
|
332 |
!
|
|
333 |
|
163
|
334 |
testSet
|
|
335 |
"test encoding an decoding of a set"
|
|
336 |
|
|
337 |
|set|
|
|
338 |
|
|
339 |
set := Set new.
|
|
340 |
set add:true.
|
|
341 |
set add:'hallo'.
|
|
342 |
set add:#symbol.
|
|
343 |
|
|
344 |
self encodeAndDecode:set
|
|
345 |
|
|
346 |
"
|
|
347 |
self run:#testSet
|
|
348 |
"
|
|
349 |
!
|
|
350 |
|
|
351 |
testString
|
|
352 |
"test encoding an decoding of a String"
|
165
|
353 |
|
217
|
354 |
self encodeAndDecode:'hello world'.
|
|
355 |
self encodeAndDecode:'hello world üö#*ß'.
|
1447
|
356 |
self encodeAndDecode:Character tab asString , 'with',
|
|
357 |
Character tab asString, Character tab asString, 'tabs',
|
|
358 |
Character tab asString.
|
|
359 |
self encodeAndDecode:Character tab asString , '& with',
|
|
360 |
Character tab asString, Character tab asString, 'tabs',
|
|
361 |
Character tab asString.
|
163
|
362 |
|
|
363 |
"
|
208
|
364 |
self run:#testString
|
|
365 |
"
|
|
366 |
!
|
|
367 |
|
|
368 |
testUUID
|
|
369 |
"test encoding an decoding of an ByteArray"
|
|
370 |
|
|
371 |
self encodeAndDecode:UUID genUUID.
|
|
372 |
|
|
373 |
"
|
163
|
374 |
self run:#testUUID
|
|
375 |
"
|
1551
|
376 |
|
163
|
377 |
! !
|
|
378 |
|
217
|
379 |
!XMLCoderTests class methodsFor:'documentation'!
|
163
|
380 |
|
|
381 |
version
|
|
382 |
^ '$Header$'
|
|
383 |
! !
|
1551
|
384 |
|