39 !ReadStreamTest methodsFor:'helpers'! |
39 !ReadStreamTest methodsFor:'helpers'! |
40 |
40 |
41 checkReadStreamFor:testCollection |
41 checkReadStreamFor:testCollection |
42 "check for correct common behavior of Stream reading" |
42 "check for correct common behavior of Stream reading" |
43 |
43 |
44 |stream| |
|
45 |
|
46 "The stream is opened in a way so that it can be used for both |
44 "The stream is opened in a way so that it can be used for both |
47 ReadStreams and ReadWriteStreams. Do not use #on:!!" |
45 ReadStreams and ReadWriteStreams. Do not use #on:!!" |
48 |
46 |
49 stream := self streamClass with:testCollection. |
47 ^ self checkReadStreamFor:testCollection useWith:true |
|
48 ! |
|
49 |
|
50 checkReadStreamFor:testCollection useWith:useWith |
|
51 "check for correct common behavior of Stream reading" |
|
52 |
|
53 |stream| |
|
54 |
|
55 "The stream is opened in a way so that it can be used for both |
|
56 ReadStreams and ReadWriteStreams. Do not use #on:!!" |
|
57 |
|
58 useWith ifTrue:[ |
|
59 stream := self streamClass with:testCollection. |
|
60 ] ifFalse:[ |
|
61 stream := self streamClass on:testCollection. |
|
62 ]. |
50 stream reset. "for ReadWriteStreams" |
63 stream reset. "for ReadWriteStreams" |
51 self assert:(stream size == testCollection size). |
64 self assert:(stream size == testCollection size). |
52 self assert:(stream isEmpty not). |
65 testCollection size == 0 ifTrue:[ |
|
66 self assert:(stream isEmpty). |
|
67 ] ifFalse:[ |
|
68 self assert:(stream isEmpty not). |
|
69 ]. |
53 testCollection |
70 testCollection |
54 keysAndValuesDo:[:pos :element | |
71 keysAndValuesDo:[:pos :element | |
55 self assert:(stream atEnd not). |
72 self assert:(stream atEnd not). |
56 self assert:(stream peek == element). |
73 self assert:(stream peek == element). |
57 self assert:(stream position == (pos + startPosition - 1)). |
74 self assert:(stream position == (pos + startPosition - 1)). |
104 self assert:(stream size == 5). |
121 self assert:(stream size == 5). |
105 ! |
122 ! |
106 |
123 |
107 testReadStream |
124 testReadStream |
108 |
125 |
|
126 self checkReadStreamFor:''. |
109 self checkReadStreamFor:'12345'. |
127 self checkReadStreamFor:'12345'. |
110 self checkReadStreamFor:'12345'asByteArray. |
128 self checkReadStreamFor:'12345'asByteArray. |
111 self checkReadStreamFor:#[1 2 3 4 5]. |
129 self checkReadStreamFor:#[1 2 3 4 5]. |
112 self checkReadStreamFor:#(1 2 3 4 5). |
130 self checkReadStreamFor:#(1 2 3 4 5). |
113 self checkReadStreamFor:#(1 2 3 4 5) asOrderedCollection. |
131 self checkReadStreamFor:#(1 2 3 4 5) asOrderedCollection. |
114 |
132 |
|
133 self checkReadStreamFor:'' useWith:false. |
|
134 self checkReadStreamFor:'12345' useWith:false. |
|
135 self checkReadStreamFor:'12345'asByteArray useWith:false. |
|
136 self checkReadStreamFor:#[1 2 3 4 5] useWith:false. |
|
137 self checkReadStreamFor:#(1 2 3 4 5) useWith:false. |
|
138 self checkReadStreamFor:#(1 2 3 4 5) asOrderedCollection useWith:false. |
115 |
139 |
116 " |
140 " |
117 (self selector:#testReadStream) runCase |
141 (self selector:#testReadStream) runCase |
118 " |
142 " |
119 ! |
143 ! |
178 |
202 |
179 |stream| |
203 |stream| |
180 |
204 |
181 stream := self streamClass with:'12345'. |
205 stream := self streamClass with:'12345'. |
182 self assert:(stream position == (startPosition+5)). |
206 self assert:(stream position == (startPosition+5)). |
|
207 ! |
|
208 |
|
209 xxtestReadBinary |
|
210 |stream byte| |
|
211 |
|
212 stream := self streamClass on:'hello'. |
|
213 stream binary. |
|
214 |
|
215 self assert:(byte := stream next) == $h asciiValue. |
|
216 self assert:(byte := stream next) == $e asciiValue. |
|
217 self assert:(byte := stream next) == $l asciiValue. |
|
218 self assert:(byte := stream next) == $l asciiValue. |
|
219 self assert:(byte := stream next) == $o asciiValue. |
|
220 self assert:(stream atEnd) |
|
221 |
|
222 |
|
223 " |
|
224 (self selector:#testReadBinary) runCase |
|
225 " |
183 ! ! |
226 ! ! |
184 |
227 |
185 !ReadStreamTest class methodsFor:'documentation'! |
228 !ReadStreamTest class methodsFor:'documentation'! |
186 |
229 |
187 version |
230 version |