RegressionTests__FileStreamTest.st
changeset 1 0ad7950613c8
parent 0 cce7631f99b0
child 30 22531aeb4ce5
equal deleted inserted replaced
0:cce7631f99b0 1:0ad7950613c8
     2 
     2 
     3 Object subclass:#FileStreamTest
     3 Object subclass:#FileStreamTest
     4 	instanceVariableNames:''
     4 	instanceVariableNames:''
     5 	classVariableNames:''
     5 	classVariableNames:''
     6 	poolDictionaries:''
     6 	poolDictionaries:''
     7 	category:'Stream Tests'
     7 	category:'Tests - Streams'
     8 !
     8 !
     9 
     9 
    10 
    10 
    11 !FileStreamTest class methodsFor:'tests'!
    11 !FileStreamTest class methodsFor:'tests'!
    12 
    12 
    16     |f bytes|
    16     |f bytes|
    17 
    17 
    18     f := 'testFile' asFilename writeStream binary.
    18     f := 'testFile' asFilename writeStream binary.
    19     bytes := ByteArray new:1024.
    19     bytes := ByteArray new:1024.
    20     1 to:bytes size do:[:i |
    20     1 to:bytes size do:[:i |
    21         bytes at:i put:(i \\ 256).
    21 	bytes at:i put:(i \\ 256).
    22     ].
    22     ].
    23 
    23 
    24     100 timesRepeat:[
    24     100 timesRepeat:[
    25         f nextPutAll:bytes.
    25 	f nextPutAll:bytes.
    26     ].
    26     ].
    27 
    27 
    28     f close.
    28     f close.
    29 
    29 
    30     "
    30     "
    42     f := 'testFile' asFilename readStream binary.
    42     f := 'testFile' asFilename readStream binary.
    43     buffer := ByteArray new:128.
    43     buffer := ByteArray new:128.
    44 
    44 
    45     n := 0.
    45     n := 0.
    46     [f atEnd] whileFalse:[
    46     [f atEnd] whileFalse:[
    47         nRead := f nextBytes:128 into:buffer.
    47 	nRead := f nextBytes:128 into:buffer.
    48         n := n + nRead.
    48 	n := n + nRead.
    49     ].
    49     ].
    50     f close.
    50     f close.
    51     expect ~~ n ifTrue:[
    51     expect ~~ n ifTrue:[
    52         self halt:('got <1p>; expected:<2p>' expandMacrosWith:n with:expect)
    52 	self halt:('got <1p>; expected:<2p>' expandMacrosWith:n with:expect)
    53     ].
    53     ].
    54 
    54 
    55     "Created: / 12.8.1998 / 13:29:41 / cg"
    55     "Created: / 12.8.1998 / 13:29:41 / cg"
    56     "Modified: / 12.8.1998 / 13:36:40 / cg"
    56     "Modified: / 12.8.1998 / 13:36:40 / cg"
    57 !
    57 !
    83     self createTestFile.
    83     self createTestFile.
    84 
    84 
    85     sz := 'testFile' asFilename fileSize.
    85     sz := 'testFile' asFilename fileSize.
    86 
    86 
    87     20 timesRepeat:[
    87     20 timesRepeat:[
    88         [self readFileExpecting:sz. 'done' printCR.] fork.
    88 	[self readFileExpecting:sz. 'done' printCR.] fork.
    89     ].
    89     ].
    90 
    90 
    91     "
    91     "
    92      self test2
    92      self test2
    93     "
    93     "
   106     self createTestFile.
   106     self createTestFile.
   107 
   107 
   108     sz := 'testFile' asFilename fileSize.
   108     sz := 'testFile' asFilename fileSize.
   109 
   109 
   110     p := [
   110     p := [
   111         nLoop timesRepeat:[
   111 	nLoop timesRepeat:[
   112             self readFileExpecting:sz.
   112 	    self readFileExpecting:sz.
   113         ].
   113 	].
   114     ] forkAt:7.
   114     ] forkAt:7.
   115 
   115 
   116     count := 0.
   116     count := 0.
   117     [p isDead] whileFalse:[
   117     [p isDead] whileFalse:[
   118         Delay waitForMilliseconds:10.
   118 	Delay waitForMilliseconds:10.
   119         p interruptWith:[count := count + 1].
   119 	p interruptWith:[count := count + 1].
   120     ].
   120     ].
   121     ('read file <1p> times; interrupted <2p> times' 
   121     ('read file <1p> times; interrupted <2p> times' 
   122         expandMacrosWith:nLoop with:count) printCR
   122 	expandMacrosWith:nLoop with:count) printCR
   123 
   123 
   124     "
   124     "
   125      self test3
   125      self test3
   126     "
   126     "
   127 
   127