RegressionTests__FileStreamTest.st
changeset 120 01f2cb81dc38
parent 119 11246c09ec93
child 181 a56517005229
--- a/RegressionTests__FileStreamTest.st	Tue Dec 11 16:31:26 2001 +0100
+++ b/RegressionTests__FileStreamTest.st	Tue Dec 11 16:34:53 2001 +0100
@@ -10,7 +10,7 @@
 !
 
 
-!FileStreamTest methodsFor:'tests'!
+!FileStreamTest methodsFor:'helpers'!
 
 createTestFile
     "create a test file (100k size)"
@@ -36,6 +36,44 @@
     "Created: / 12.8.1998 / 13:25:25 / cg"
 !
 
+doTestWrite:size
+    "basic writing"
+
+    |file s sz buffer byte|
+
+    buffer := ByteArray new:size.
+    1 to:buffer size do:[:idx |
+        buffer at:idx put:(idx \\ 256)
+    ].
+
+    file := Filename newTemporary.
+    s := file writeStream.
+
+    s binary.
+    s nextPutAll:buffer.
+    s close.
+
+    sz := file fileSize.
+    sz ~= size ifTrue:[self error:'size mismatch'].
+
+    s := file readStream.
+    s binary.
+    1 to:size do:[:idx |
+        byte := s next.
+        byte ~~ (idx \\ 256) ifTrue:[self error:'read data mismatch'].
+    ].
+    s close.
+
+    (file binaryContentsOfEntireFile ~= buffer) ifTrue:[
+        self error:'read data mismatch2'
+    ].
+    file delete.
+
+    "
+     self testWrite:1024
+    "
+!
+
 readFileExpecting:expect
     "read test file, expect n bytes"
 
@@ -56,7 +94,9 @@
 
     "Created: / 12.8.1998 / 13:29:41 / cg"
     "Modified: / 12.8.1998 / 13:36:40 / cg"
-!
+! !
+
+!FileStreamTest methodsFor:'tests'!
 
 testAppend1
     "basic open for appending."
@@ -179,136 +219,6 @@
     "Modified: / 12.8.1998 / 13:42:13 / cg"
 !
 
-testReadCheckPipe4
-    "readCheck a pipe.
-     Do this and interrupt the reading thread heavily"
-
-    | s p count nLoop|
-
-    nLoop := 1000.
-
-    self createTestFile.
-
-    s := PipeStream readingFrom:'sleep 5'.
-
-    p := [
-        s readWait.
-        'readWait finished' printCR.
-    ] forkAt:7.
-
-    count := 0.
-    [p isDead] whileFalse:[
-        Delay waitForMilliseconds:5.
-        p interruptWith:[count := count + 1].
-    ].
-    ('readWait interrupted <1p> times' expandMacrosWith:count) printCR.
-
-    s close.
-
-    "
-     self new testReadCheckPipe4
-    "
-
-    "Modified: / 12.8.1998 / 13:42:13 / cg"
-!
-
-testReadCheckPipe5
-    "readCheck a pipe.
-     Do this and interrupt the reading thread heavily"
-
-    | s p count nLoop|
-
-    nLoop := 1000.
-
-    self createTestFile.
-
-    s := PipeStream readingFrom:'sleep 5; echo hello'.
-
-    p := [
-        s readWait.
-        'readWait finished' printCR.
-    ] forkAt:7.
-
-    count := 0.
-    [p isDead] whileFalse:[
-        Delay waitForMilliseconds:5.
-        p interruptWith:[count := count + 1].
-    ].
-    ('readWait interrupted <1p> times' expandMacrosWith:count) printCR.
-
-    s close.
-
-    "
-     self new testReadCheckPipe5
-    "
-
-    "Modified: / 12.8.1998 / 13:42:13 / cg"
-!
-
-testReadPipe6
-    "read a pipe.
-     Do this and interrupt the reading thread heavily"
-
-    | s p count nLoop|
-
-    nLoop := 1000.
-
-    self createTestFile.
-
-    s := PipeStream readingFrom:'sleep 5'.
-
-    p := [
-        'read: ' print. s nextLine printCR.
-    ] forkAt:7.
-
-    count := 0.
-    [p isDead] whileFalse:[
-        Delay waitForMilliseconds:5.
-        p interruptWith:[count := count + 1].
-    ].
-    ('read interrupted <1p> times' expandMacrosWith:count) printCR.
-
-    s close.
-
-    "
-     self new testReadPipe6
-    "
-
-    "Modified: / 12.8.1998 / 13:42:13 / cg"
-!
-
-testReadPipe7
-    "read a pipe.
-     Do this and interrupt the reading thread heavily"
-
-    |sz s p count nLoop|
-
-    nLoop := 1000.
-
-    self createTestFile.
-
-    s := PipeStream readingFrom:'sleep 5; echo hello'.
-
-    p := [
-        'read: ' print. s nextLine printCR.
-    ] forkAt:7.
-
-    count := 0.
-    [p isDead] whileFalse:[
-        Delay waitForMilliseconds:5.
-        p interruptWith:[count := count + 1].
-    ].
-    ('read interrupted <1p> times' expandMacrosWith:count) printCR.
-
-    s close.
-
-    "
-     self test7
-    "
-
-    "Modified: / 12.8.1998 / 13:42:13 / cg"
-!
-
 testRewrite1
     "basic open for writing (with truncation)."
 
@@ -338,7 +248,7 @@
     file delete.
 
     "
-     self testRewrite1
+     self new testRewrite1
     "
 !
 
@@ -372,27 +282,27 @@
     file delete.
 
     "
-     self testRewrite2
+     self new testRewrite2
     "
 !
 
 testWrite1
     "basic writing"
 
-    self testWrite:1024.
-    self testWrite:2048.
-    self testWrite:4096.
-    self testWrite:8192.
-    self testWrite:8192*2.
-    self testWrite:8192*4.
-    self testWrite:8192*8.
-    self testWrite:8192*16.
-    self testWrite:8192*32.
-    self testWrite:8192*64.
-    self testWrite:8192*128.
+    self doTestWrite:1024.
+    self doTestWrite:2048.
+    self doTestWrite:4096.
+    self doTestWrite:8192.
+    self doTestWrite:8192*2.
+    self doTestWrite:8192*4.
+    self doTestWrite:8192*8.
+    self doTestWrite:8192*16.
+    self doTestWrite:8192*32.
+    self doTestWrite:8192*64.
+    self doTestWrite:8192*128.
 
     "
-     self testWrite1
+     self new testWrite1
     "
 !
 
@@ -404,7 +314,7 @@
     ].
 
     "
-     self testWrite2
+     self new testWrite2
     "
 !
 
@@ -428,45 +338,7 @@
     ].
 
     "
-     self testWrite3
-    "
-!
-
-testWrite:size
-    "basic writing"
-
-    |file s sz buffer byte|
-
-    buffer := ByteArray new:size.
-    1 to:buffer size do:[:idx |
-        buffer at:idx put:(idx \\ 256)
-    ].
-
-    file := Filename newTemporary.
-    s := file writeStream.
-
-    s binary.
-    s nextPutAll:buffer.
-    s close.
-
-    sz := file fileSize.
-    sz ~= size ifTrue:[self error:'size mismatch'].
-
-    s := file readStream.
-    s binary.
-    1 to:size do:[:idx |
-        byte := s next.
-        byte ~~ (idx \\ 256) ifTrue:[self error:'read data mismatch'].
-    ].
-    s close.
-
-    (file binaryContentsOfEntireFile ~= buffer) ifTrue:[
-        self error:'read data mismatch2'
-    ].
-    file delete.
-
-    "
-     self testWrite:1024
+     self new testWrite3
     "
 ! !