"{ NameSpace: RegressionTests }"
Object subclass:#FileStreamTest
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'Stream Tests'
!
!FileStreamTest class methodsFor:'tests'!
createTestFile
"create a test file (100k size)"
|f bytes|
f := 'testFile' asFilename writeStream binary.
bytes := ByteArray new:1024.
1 to:bytes size do:[:i |
bytes at:i put:(i \\ 256).
].
100 timesRepeat:[
f nextPutAll:bytes.
].
f close.
"
self createTestFile
"
"Created: / 12.8.1998 / 13:25:25 / cg"
!
readFileExpecting:expect
"read test file, expect n bytes"
|f buffer n nRead|
f := 'testFile' asFilename readStream binary.
buffer := ByteArray new:128.
n := 0.
[f atEnd] whileFalse:[
nRead := f nextBytes:128 into:buffer.
n := n + nRead.
].
f close.
expect ~~ n ifTrue:[
self halt:('got <1p>; expected:<2p>' expandMacrosWith:n with:expect)
].
"Created: / 12.8.1998 / 13:29:41 / cg"
"Modified: / 12.8.1998 / 13:36:40 / cg"
!
test1
"read a file - check count read with files size."
|sz|
self createTestFile.
sz := 'testFile' asFilename fileSize.
self readFileExpecting:sz.
"
self test1
"
"Modified: / 12.8.1998 / 13:29:55 / cg"
!
test2
"read a file - check count read with files size.
Do this in 20 threads"
|sz|
self createTestFile.
sz := 'testFile' asFilename fileSize.
20 timesRepeat:[
[self readFileExpecting:sz. 'done' printCR.] fork.
].
"
self test2
"
"Modified: / 12.8.1998 / 13:30:55 / cg"
!
test3
"read a file - check count read with files size.
Do this and interrupt the reading thread heavily"
|sz p count nLoop|
nLoop := 1000.
self createTestFile.
sz := 'testFile' asFilename fileSize.
p := [
nLoop timesRepeat:[
self readFileExpecting:sz.
].
] forkAt:7.
count := 0.
[p isDead] whileFalse:[
Delay waitForMilliseconds:10.
p interruptWith:[count := count + 1].
].
('read file <1p> times; interrupted <2p> times'
expandMacrosWith:nLoop with:count) printCR
"
self test3
"
"Modified: / 12.8.1998 / 13:42:13 / cg"
! !
!FileStreamTest class methodsFor:'documentation'!
version
^ '$Header$'
! !