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