131
|
1 |
"{ Package: 'exept:regression' }"
|
|
2 |
|
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
|
5 |
TestCase subclass:#ReadStreamTest
|
|
6 |
instanceVariableNames:'startPosition streamClass'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Tests-Regression'
|
|
10 |
!
|
|
11 |
|
|
12 |
!ReadStreamTest class methodsFor:'documentation'!
|
|
13 |
|
|
14 |
documentation
|
|
15 |
"
|
|
16 |
documentation to be added.
|
|
17 |
|
|
18 |
[author:]
|
|
19 |
Stefan Vogel (stefan@zwerg)
|
|
20 |
|
|
21 |
[see also:]
|
|
22 |
|
|
23 |
[instance variables:]
|
|
24 |
|
|
25 |
[class variables:]
|
|
26 |
"
|
|
27 |
!
|
|
28 |
|
|
29 |
history
|
|
30 |
"Created: / 13.12.2001 / 17:13:17 / stefan"
|
|
31 |
! !
|
|
32 |
|
|
33 |
!ReadStreamTest methodsFor:'accessing'!
|
|
34 |
|
|
35 |
streamClass
|
|
36 |
^ streamClass
|
|
37 |
! !
|
|
38 |
|
|
39 |
!ReadStreamTest methodsFor:'helpers'!
|
|
40 |
|
|
41 |
checkReadStreamFor:testCollection
|
|
42 |
"check for correct common behavior of Stream reading"
|
|
43 |
|
148
|
44 |
"The stream is opened in a way so that it can be used for both
|
|
45 |
ReadStreams and ReadWriteStreams. Do not use #on:!!"
|
|
46 |
|
|
47 |
^ self checkReadStreamFor:testCollection useWith:true
|
|
48 |
!
|
|
49 |
|
|
50 |
checkReadStreamFor:testCollection useWith:useWith
|
|
51 |
"check for correct common behavior of Stream reading"
|
|
52 |
|
131
|
53 |
|stream|
|
|
54 |
|
137
|
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 |
|
148
|
58 |
useWith ifTrue:[
|
|
59 |
stream := self streamClass with:testCollection.
|
|
60 |
] ifFalse:[
|
|
61 |
stream := self streamClass on:testCollection.
|
|
62 |
].
|
131
|
63 |
stream reset. "for ReadWriteStreams"
|
|
64 |
self assert:(stream size == testCollection size).
|
148
|
65 |
testCollection size == 0 ifTrue:[
|
|
66 |
self assert:(stream isEmpty).
|
|
67 |
] ifFalse:[
|
|
68 |
self assert:(stream isEmpty not).
|
|
69 |
].
|
131
|
70 |
testCollection
|
|
71 |
keysAndValuesDo:[:pos :element |
|
|
72 |
self assert:(stream atEnd not).
|
|
73 |
self assert:(stream peek == element).
|
|
74 |
self assert:(stream position == (pos + startPosition - 1)).
|
|
75 |
self assert:(stream next == element).
|
|
76 |
self assert:(stream position == (pos + startPosition))
|
|
77 |
].
|
|
78 |
self assert:(stream atEnd).
|
|
79 |
self assert:(stream peek isNil).
|
|
80 |
self assert:(stream next isNil).
|
|
81 |
streamClass endOfStreamSignal
|
|
82 |
handle:[:ex | ex return]
|
|
83 |
do:[
|
|
84 |
self should:(stream next) raise:streamClass endOfStreamSignal.
|
|
85 |
self should:(stream peek) raise:streamClass endOfStreamSignal.
|
|
86 |
self shouldnt:(stream peekOrNil) raise:streamClass endOfStreamSignal
|
|
87 |
]
|
|
88 |
! !
|
|
89 |
|
|
90 |
!ReadStreamTest methodsFor:'setup'!
|
|
91 |
|
|
92 |
setUp
|
148
|
93 |
self streamClass:Rel5::ReadStream.
|
131
|
94 |
!
|
|
95 |
|
|
96 |
streamClass:aClass
|
|
97 |
streamClass := aClass.
|
|
98 |
startPosition := streamClass zeroPosition
|
|
99 |
! !
|
|
100 |
|
|
101 |
!ReadStreamTest methodsFor:'tests'!
|
|
102 |
|
|
103 |
testBasic
|
|
104 |
|stream|
|
|
105 |
|
|
106 |
stream := self streamClass on:''.
|
|
107 |
self assert:(stream isReadable).
|
|
108 |
self assert:(stream isPositionable).
|
|
109 |
self assert:(stream isWritable not).
|
|
110 |
self assert:(stream size == 0).
|
|
111 |
self assert:(stream isEmpty)
|
|
112 |
!
|
|
113 |
|
137
|
114 |
testOn
|
|
115 |
|
|
116 |
|stream|
|
131
|
117 |
|
137
|
118 |
stream := self streamClass on:'12345'.
|
|
119 |
self assert:(stream position == startPosition).
|
|
120 |
self assert:(stream isEmpty not).
|
|
121 |
self assert:(stream size == 5).
|
131
|
122 |
!
|
|
123 |
|
|
124 |
testReadStream
|
|
125 |
|
148
|
126 |
self checkReadStreamFor:''.
|
131
|
127 |
self checkReadStreamFor:'12345'.
|
|
128 |
self checkReadStreamFor:'12345'asByteArray.
|
|
129 |
self checkReadStreamFor:#[1 2 3 4 5].
|
|
130 |
self checkReadStreamFor:#(1 2 3 4 5).
|
|
131 |
self checkReadStreamFor:#(1 2 3 4 5) asOrderedCollection.
|
|
132 |
|
148
|
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.
|
131
|
139 |
|
|
140 |
"
|
|
141 |
(self selector:#testReadStream) runCase
|
|
142 |
"
|
|
143 |
!
|
|
144 |
|
|
145 |
testSkipAny
|
|
146 |
|stream skipChars|
|
|
147 |
|
|
148 |
stream := self streamClass
|
|
149 |
on:'some numbers1234with\in other99 stuff' withCRs.
|
|
150 |
skipChars := 'abcdefghijklmnopqrstuvwxyz\ ' withCRs.
|
|
151 |
self assert:(stream skipAny:skipChars) == $1.
|
|
152 |
self assert:(Integer readFrom:stream) == 1234.
|
|
153 |
self assert:(stream skipAny:skipChars) == $9.
|
|
154 |
self assert:(Integer readFrom:stream) == 99
|
|
155 |
!
|
|
156 |
|
|
157 |
testSkipSeparators
|
137
|
158 |
|stream sep|
|
131
|
159 |
|
|
160 |
stream := self streamClass on:'one two\three' withCRs.
|
137
|
161 |
self assert:((sep := stream skipSeparators) == $o).
|
131
|
162 |
self assert:(stream nextWord = 'one').
|
|
163 |
self assert:(stream skipSeparators == $t).
|
|
164 |
self assert:(stream nextWord = 'two').
|
|
165 |
self assert:(stream skipSeparators == $t).
|
|
166 |
self assert:(stream nextWord = 'three').
|
|
167 |
self assert:(stream atEnd).
|
|
168 |
self assert:(stream skipSeparators isNil)
|
|
169 |
!
|
|
170 |
|
|
171 |
testSkipSeparatorsExceptCR
|
|
172 |
|stream|
|
|
173 |
|
|
174 |
stream := self streamClass on:'one two\three' withCRs.
|
|
175 |
self assert:(stream skipSeparatorsExceptCR == $o).
|
|
176 |
self assert:(stream nextWord = 'one').
|
|
177 |
self assert:(stream skipSeparatorsExceptCR == $t).
|
|
178 |
self assert:(stream nextWord = 'two').
|
|
179 |
self assert:(stream skipSeparatorsExceptCR == Character cr).
|
|
180 |
self assert:(stream next = Character cr).
|
|
181 |
self assert:(stream nextWord = 'three').
|
|
182 |
self assert:(stream atEnd).
|
|
183 |
self assert:(stream skipSeparatorsExceptCR isNil)
|
|
184 |
!
|
|
185 |
|
|
186 |
testSkipSpaces
|
|
187 |
|stream|
|
|
188 |
|
|
189 |
stream := self streamClass on:'one two\three' withCRs.
|
|
190 |
self assert:(stream skipSpaces == $o).
|
|
191 |
self assert:(stream nextWord = 'one').
|
|
192 |
self assert:(stream skipSpaces == $t).
|
|
193 |
self assert:(stream nextWord = 'two').
|
|
194 |
self assert:(stream skipSpaces == Character cr).
|
|
195 |
self assert:(stream next = Character cr).
|
|
196 |
self assert:(stream nextWord = 'three').
|
|
197 |
self assert:(stream atEnd).
|
|
198 |
self assert:(stream skipSpaces isNil)
|
137
|
199 |
!
|
|
200 |
|
|
201 |
testWith
|
|
202 |
|
|
203 |
|stream|
|
|
204 |
|
|
205 |
stream := self streamClass with:'12345'.
|
|
206 |
self assert:(stream position == (startPosition+5)).
|
148
|
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 |
"
|
131
|
226 |
! !
|
|
227 |
|
|
228 |
!ReadStreamTest class methodsFor:'documentation'!
|
|
229 |
|
|
230 |
version
|
|
231 |
^ '$Header$'
|
|
232 |
! !
|