0
|
1 |
"{ NameSpace: RegressionTests }"
|
|
2 |
|
|
3 |
Object subclass:#FileStreamTest
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
1
|
7 |
category:'Tests - Streams'
|
0
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!FileStreamTest class methodsFor:'tests'!
|
|
12 |
|
|
13 |
createTestFile
|
|
14 |
"create a test file (100k size)"
|
|
15 |
|
|
16 |
|f bytes|
|
|
17 |
|
|
18 |
f := 'testFile' asFilename writeStream binary.
|
|
19 |
bytes := ByteArray new:1024.
|
|
20 |
1 to:bytes size do:[:i |
|
1
|
21 |
bytes at:i put:(i \\ 256).
|
0
|
22 |
].
|
|
23 |
|
|
24 |
100 timesRepeat:[
|
1
|
25 |
f nextPutAll:bytes.
|
0
|
26 |
].
|
|
27 |
|
|
28 |
f close.
|
|
29 |
|
|
30 |
"
|
|
31 |
self createTestFile
|
|
32 |
"
|
|
33 |
|
|
34 |
"Created: / 12.8.1998 / 13:25:25 / cg"
|
|
35 |
!
|
|
36 |
|
|
37 |
readFileExpecting:expect
|
|
38 |
"read test file, expect n bytes"
|
|
39 |
|
|
40 |
|f buffer n nRead|
|
|
41 |
|
|
42 |
f := 'testFile' asFilename readStream binary.
|
|
43 |
buffer := ByteArray new:128.
|
|
44 |
|
|
45 |
n := 0.
|
|
46 |
[f atEnd] whileFalse:[
|
1
|
47 |
nRead := f nextBytes:128 into:buffer.
|
|
48 |
n := n + nRead.
|
0
|
49 |
].
|
|
50 |
f close.
|
|
51 |
expect ~~ n ifTrue:[
|
1
|
52 |
self halt:('got <1p>; expected:<2p>' expandMacrosWith:n with:expect)
|
0
|
53 |
].
|
|
54 |
|
|
55 |
"Created: / 12.8.1998 / 13:29:41 / cg"
|
|
56 |
"Modified: / 12.8.1998 / 13:36:40 / cg"
|
|
57 |
!
|
|
58 |
|
|
59 |
test1
|
|
60 |
"read a file - check count read with files size."
|
|
61 |
|
|
62 |
|sz|
|
|
63 |
|
|
64 |
self createTestFile.
|
|
65 |
|
|
66 |
sz := 'testFile' asFilename fileSize.
|
|
67 |
|
|
68 |
self readFileExpecting:sz.
|
|
69 |
|
|
70 |
"
|
|
71 |
self test1
|
|
72 |
"
|
|
73 |
|
|
74 |
"Modified: / 12.8.1998 / 13:29:55 / cg"
|
|
75 |
!
|
|
76 |
|
|
77 |
test2
|
|
78 |
"read a file - check count read with files size.
|
|
79 |
Do this in 20 threads"
|
|
80 |
|
|
81 |
|sz|
|
|
82 |
|
|
83 |
self createTestFile.
|
|
84 |
|
|
85 |
sz := 'testFile' asFilename fileSize.
|
|
86 |
|
|
87 |
20 timesRepeat:[
|
1
|
88 |
[self readFileExpecting:sz. 'done' printCR.] fork.
|
0
|
89 |
].
|
|
90 |
|
|
91 |
"
|
|
92 |
self test2
|
|
93 |
"
|
|
94 |
|
|
95 |
"Modified: / 12.8.1998 / 13:30:55 / cg"
|
|
96 |
!
|
|
97 |
|
|
98 |
test3
|
|
99 |
"read a file - check count read with files size.
|
|
100 |
Do this and interrupt the reading thread heavily"
|
|
101 |
|
|
102 |
|sz p count nLoop|
|
|
103 |
|
|
104 |
nLoop := 1000.
|
|
105 |
|
|
106 |
self createTestFile.
|
|
107 |
|
|
108 |
sz := 'testFile' asFilename fileSize.
|
|
109 |
|
|
110 |
p := [
|
1
|
111 |
nLoop timesRepeat:[
|
|
112 |
self readFileExpecting:sz.
|
|
113 |
].
|
0
|
114 |
] forkAt:7.
|
|
115 |
|
|
116 |
count := 0.
|
|
117 |
[p isDead] whileFalse:[
|
1
|
118 |
Delay waitForMilliseconds:10.
|
|
119 |
p interruptWith:[count := count + 1].
|
0
|
120 |
].
|
|
121 |
('read file <1p> times; interrupted <2p> times'
|
1
|
122 |
expandMacrosWith:nLoop with:count) printCR
|
0
|
123 |
|
|
124 |
"
|
|
125 |
self test3
|
|
126 |
"
|
|
127 |
|
|
128 |
"Modified: / 12.8.1998 / 13:42:13 / cg"
|
|
129 |
! !
|
|
130 |
|
|
131 |
!FileStreamTest class methodsFor:'documentation'!
|
|
132 |
|
|
133 |
version
|
|
134 |
^ '$Header$'
|
|
135 |
! !
|