--- a/RegressionTests__FileStreamTest.st Tue Sep 12 22:55:18 2000 +0200
+++ b/RegressionTests__FileStreamTest.st Thu Sep 21 11:17:56 2000 +0200
@@ -58,7 +58,70 @@
"Modified: / 12.8.1998 / 13:36:40 / cg"
!
-test1
+runAllTests
+ self testRead1.
+ self testRead2.
+ self testRead3.
+ self testReadCheckPipe4.
+ self testReadCheckPipe5.
+ self testReadPipe6.
+ self testReadPipe7.
+
+ "
+ self runAllTests
+ "
+!
+
+testAppend1
+ "basic open for appending."
+
+ |file s sz|
+
+ file := Filename newTemporary.
+ s := file writeStream.
+ s binary.
+ s nextPutAll:(1 to:100).
+ s close.
+
+ sz := file fileSize.
+ sz ~= 100 ifTrue:[self error:'size mismatch'].
+
+ s := file appendingWriteStream.
+ s binary.
+ s nextPutAll:(101 to:200).
+ s close.
+
+ sz := file fileSize.
+ sz ~= 200 ifTrue:[self error:'size mismatch'].
+
+ (file binaryContentsOfEntireFile ~= (1 to:200) asByteArray) ifTrue:[
+ self error:'contents mismatch'
+ ].
+
+ file delete.
+
+ "
+ self testAppend1
+ "
+!
+
+testOpenRead1
+ "basic open for reading."
+
+ |sz|
+
+ self createTestFile.
+
+ sz := 'testFile' asFilename fileSize.
+
+ self readFileExpecting:sz.
+
+ "
+ self testOpenRead1
+ "
+!
+
+testRead1
"read a file - check count read with files size."
|sz|
@@ -76,7 +139,7 @@
"Modified: / 12.8.1998 / 13:29:55 / cg"
!
-test2
+testRead2
"read a file - check count read with files size.
Do this in 20 threads"
@@ -87,7 +150,7 @@
sz := 'testFile' asFilename fileSize.
20 timesRepeat:[
- [self readFileExpecting:sz. 'done' printCR.] fork.
+ [self readFileExpecting:sz. 'done' printCR.] fork.
].
"
@@ -97,7 +160,7 @@
"Modified: / 12.8.1998 / 13:30:55 / cg"
!
-test3
+testRead3
"read a file - check count read with files size.
Do this and interrupt the reading thread heavily"
@@ -110,18 +173,18 @@
sz := 'testFile' asFilename fileSize.
p := [
- nLoop timesRepeat:[
- self readFileExpecting:sz.
- ].
+ nLoop timesRepeat:[
+ self readFileExpecting:sz.
+ ].
] forkAt:7.
count := 0.
[p isDead] whileFalse:[
- Delay waitForMilliseconds:5.
- p interruptWith:[count := count + 1].
+ Delay waitForMilliseconds:5.
+ p interruptWith:[count := count + 1].
].
('read file <1p> times; interrupted <2p> times'
- expandMacrosWith:nLoop with:count) printCR
+ expandMacrosWith:nLoop with:count) printCR
"
self test3
@@ -130,7 +193,7 @@
"Modified: / 12.8.1998 / 13:42:13 / cg"
!
-test4
+testReadCheckPipe4
"readCheck a pipe.
Do this and interrupt the reading thread heavily"
@@ -143,17 +206,16 @@
s := PipeStream readingFrom:'sleep 5'.
p := [
- s readWait.
- 'readWait finished' printCR.
+ s readWait.
+ 'readWait finished' printCR.
] forkAt:7.
count := 0.
[p isDead] whileFalse:[
- Delay waitForMilliseconds:5.
- p interruptWith:[count := count + 1].
+ Delay waitForMilliseconds:5.
+ p interruptWith:[count := count + 1].
].
- ('readWait interrupted <1p> times'
- expandMacrosWith:count) printCR.
+ ('readWait interrupted <1p> times' expandMacrosWith:count) printCR.
s close.
@@ -164,7 +226,7 @@
"Modified: / 12.8.1998 / 13:42:13 / cg"
!
-test5
+testReadCheckPipe5
"readCheck a pipe.
Do this and interrupt the reading thread heavily"
@@ -177,17 +239,16 @@
s := PipeStream readingFrom:'sleep 5; echo hello'.
p := [
- s readWait.
- 'readWait finished' printCR.
+ s readWait.
+ 'readWait finished' printCR.
] forkAt:7.
count := 0.
[p isDead] whileFalse:[
- Delay waitForMilliseconds:5.
- p interruptWith:[count := count + 1].
+ Delay waitForMilliseconds:5.
+ p interruptWith:[count := count + 1].
].
- ('readWait interrupted <1p> times'
- expandMacrosWith:count) printCR.
+ ('readWait interrupted <1p> times' expandMacrosWith:count) printCR.
s close.
@@ -198,7 +259,7 @@
"Modified: / 12.8.1998 / 13:42:13 / cg"
!
-test6
+testReadPipe6
"read a pipe.
Do this and interrupt the reading thread heavily"
@@ -211,16 +272,15 @@
s := PipeStream readingFrom:'sleep 5'.
p := [
- 'read: ' print. s nextLine printCR.
+ 'read: ' print. s nextLine printCR.
] forkAt:7.
count := 0.
[p isDead] whileFalse:[
- Delay waitForMilliseconds:5.
- p interruptWith:[count := count + 1].
+ Delay waitForMilliseconds:5.
+ p interruptWith:[count := count + 1].
].
- ('read interrupted <1p> times'
- expandMacrosWith:count) printCR.
+ ('read interrupted <1p> times' expandMacrosWith:count) printCR.
s close.
@@ -231,7 +291,7 @@
"Modified: / 12.8.1998 / 13:42:13 / cg"
!
-test7
+testReadPipe7
"read a pipe.
Do this and interrupt the reading thread heavily"
@@ -244,16 +304,15 @@
s := PipeStream readingFrom:'sleep 5; echo hello'.
p := [
- 'read: ' print. s nextLine printCR.
+ 'read: ' print. s nextLine printCR.
] forkAt:7.
count := 0.
[p isDead] whileFalse:[
- Delay waitForMilliseconds:5.
- p interruptWith:[count := count + 1].
+ Delay waitForMilliseconds:5.
+ p interruptWith:[count := count + 1].
].
- ('read interrupted <1p> times'
- expandMacrosWith:count) printCR.
+ ('read interrupted <1p> times' expandMacrosWith:count) printCR.
s close.
@@ -262,6 +321,73 @@
"
"Modified: / 12.8.1998 / 13:42:13 / cg"
+!
+
+testRewrite1
+ "basic open for writing (with truncation)."
+
+ |file s sz|
+
+ file := Filename newTemporary.
+ s := file writeStream.
+ s binary.
+ s nextPutAll:(1 to:200).
+ s close.
+
+ sz := file fileSize.
+ sz ~= 200 ifTrue:[self error:'size mismatch'].
+
+ s := file writeStream.
+ s binary.
+ s nextPutAll:(101 to:200).
+ s close.
+
+ sz := file fileSize.
+ sz ~= 100 ifTrue:[self error:'size mismatch'].
+
+ (file binaryContentsOfEntireFile ~= (101 to:200) asByteArray) ifTrue:[
+ self error:'contents mismatch'
+ ].
+
+ file delete.
+
+ "
+ self testRewrite1
+ "
+!
+
+testRewrite2
+ "basic open for re-writing (without truncation)."
+
+ |file s sz|
+
+ file := Filename newTemporary.
+ s := file writeStream.
+ s binary.
+ s nextPutAll:(1 to:200).
+ s close.
+
+ sz := file fileSize.
+ sz ~= 200 ifTrue:[self error:'size mismatch'].
+
+ s := file readWriteStream.
+ s binary.
+ s nextPutAll:(101 to:200).
+ s close.
+
+ sz := file fileSize.
+ sz ~= 200 ifTrue:[self error:'size mismatch'].
+
+ (file binaryContentsOfEntireFile ~=
+ ((101 to:200) asByteArray , (101 to:200) asByteArray)) ifTrue:[
+ self error:'contents mismatch'
+ ].
+
+ file delete.
+
+ "
+ self testRewrite2
+ "
! !
!FileStreamTest class methodsFor:'documentation'!