--- a/RegressionTests__FileOpenTest.st Thu Dec 13 20:01:57 2001 +0100
+++ b/RegressionTests__FileOpenTest.st Tue Dec 18 19:37:22 2001 +0100
@@ -1,12 +1,12 @@
"{ Package: 'exept:regression' }"
-"{ NameSpace: RegressionTests }"
+"{ NameSpace: Rel5 }"
TestCase subclass:#FileOpenTest
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
- category:'Tests-Regression'
+ category:'Streams-New-Tests'
!
@@ -16,11 +16,11 @@
"helper"
(fileName asFilename exists) ifTrue:[
- fileName asFilename delete
+ fileName asFilename delete
].
fileName asFilename writeStream
- nextPutAll:'1234567890';
- close.
+ nextPutAll:'1234567890';
+ close.
self assert:(fileName asFilename exists).
self assert:(fileName asFilename fileSize == 10).
@@ -35,20 +35,20 @@
|h|
('xxx1' asFilename exists) ifTrue:[
- 'xxx1' asFilename delete
+ 'xxx1' asFilename delete
].
h := OperatingSystem createFileForReadWrite:'xxx1'.
self assert:(h notNil).
self assert:(h isValid).
OperatingSystem isMSDOSlike ifTrue:[
- self assert:(h address ~~ 0).
+ self assert:(h address ~~ 0).
].
h close.
self assert:(h isValid not).
OperatingSystem isMSDOSlike ifTrue:[
- self assert:(h address == 0).
+ self assert:(h address == 0).
].
self assert:('xxx1' asFilename exists).
@@ -75,13 +75,13 @@
self assert:(h notNil).
self assert:(h isValid).
OperatingSystem isMSDOSlike ifTrue:[
- self assert:(h address ~~ 0).
+ self assert:(h address ~~ 0).
].
h close.
self assert:(h isValid not).
OperatingSystem isMSDOSlike ifTrue:[
- self assert:(h address == 0).
+ self assert:(h address == 0).
].
self assert:('xxx1' asFilename exists).
@@ -101,21 +101,21 @@
fn := (('.' asFilename construct:'foo') construct:'bar') construct:'xxx1'.
self
- should:[
- OperatingSystem createFileForReadWrite:fn name]
- raise:(OSErrorHolder nonexistentSignal).
+ should:[
+ OperatingSystem createFileForReadWrite:fn name]
+ raise:(OSErrorHolder nonexistentSignal).
"/ raised signal should be a child of inaccessibleSignal
self
- should:[
- OperatingSystem createFileForReadWrite:fn name]
- raise:(OSErrorHolder nonexistentSignal ).
+ should:[
+ OperatingSystem createFileForReadWrite:fn name]
+ raise:(OSErrorHolder nonexistentSignal ).
"/ raised signal should be a child of OsError
self
- should:[
- OperatingSystem createFileForReadWrite:fn name]
- raise:(OsError ).
+ should:[
+ OperatingSystem createFileForReadWrite:fn name]
+ raise:(OsError ).
"
self new testFailCreate1
@@ -132,9 +132,9 @@
'xxx2' asFilename delete.
self
- should:[
- h := OperatingSystem openFileForRead:'xxx2'.]
- raise:(OSErrorHolder nonexistentSignal).
+ should:[
+ h := OperatingSystem openFileForRead:'xxx2'.]
+ raise:(OSErrorHolder nonexistentSignal).
"
@@ -152,9 +152,9 @@
'xxx2' asFilename delete.
self
- should:[
- h := OperatingSystem openFileForWrite:'xxx2'.]
- raise:(OSErrorHolder nonexistentSignal).
+ should:[
+ h := OperatingSystem openFileForWrite:'xxx2'.]
+ raise:(OSErrorHolder nonexistentSignal).
"
@@ -175,13 +175,13 @@
self assert:(h notNil).
self assert:(h isValid).
OperatingSystem isMSDOSlike ifTrue:[
- self assert:(h address ~~ 0).
+ self assert:(h address ~~ 0).
].
h close.
self assert:(h isValid not).
OperatingSystem isMSDOSlike ifTrue:[
- self assert:(h address == 0).
+ self assert:(h address == 0).
].
self assert:('xxx2' asFilename fileSize == 10). "/ should not change size
@@ -205,13 +205,13 @@
self assert:(h notNil).
self assert:(h isValid).
OperatingSystem isMSDOSlike ifTrue:[
- self assert:(h address ~~ 0).
+ self assert:(h address ~~ 0).
].
h close.
self assert:(h isValid not).
OperatingSystem isMSDOSlike ifTrue:[
- self assert:(h address == 0).
+ self assert:(h address == 0).
].
self assert:('xxx2' asFilename fileSize == 10). "/ should not change size
@@ -224,6 +224,104 @@
"Modified: / 12.8.1998 / 13:29:55 / cg"
!
+testPosition1
+ |h buffer nBytesRead|
+
+ self createWithSize10:'xxx2'.
+
+ h := OperatingSystem openFileForRead:'xxx2'.
+
+ buffer := ExternalBytes new:10.
+
+ nBytesRead := h seekTo:1 from:#begin.
+ nBytesRead := h readBytes:9 into:buffer startingAt:1.
+
+ h close.
+
+ self assert:(nBytesRead == 9).
+ self assert:(buffer asString startsWith: '234567890').
+
+ 'xxx2' asFilename delete.
+
+ "
+ self new testPosition1
+ "
+!
+
+testPosition2
+ |h buffer nBytesRead|
+
+ self createWithSize10:'xxx2'.
+
+ h := OperatingSystem openFileForRead:'xxx2'.
+
+ buffer := ExternalBytes new:10.
+
+ nBytesRead := h seekTo:1 from:#begin.
+ nBytesRead := h seekTo:2 from:#current.
+ nBytesRead := h readBytes:7 into:buffer startingAt:1.
+
+ h close.
+
+ self assert:(nBytesRead == 7).
+ self assert:(buffer asString startsWith: '4567890').
+
+ 'xxx2' asFilename delete.
+
+ "
+ self new testPosition2
+ "
+!
+
+testPosition3
+ |h buffer nBytesRead|
+
+ self createWithSize10:'xxx2'.
+
+ h := OperatingSystem openFileForRead:'xxx2'.
+
+ buffer := ExternalBytes new:10.
+
+ nBytesRead := h seekTo:0 from:#end.
+ nBytesRead := h seekTo:-2 from:#current.
+ nBytesRead := h readBytes:2 into:buffer startingAt:1.
+
+ h close.
+
+ self assert:(nBytesRead == 2).
+ self assert:(buffer asString startsWith: '90').
+
+ 'xxx2' asFilename delete.
+
+ "
+ self new testPosition3
+ "
+!
+
+testPosition4
+ |h buffer nBytesRead|
+
+ self createWithSize10:'xxx2'.
+
+ h := OperatingSystem openFileForRead:'xxx2'.
+
+ buffer := ExternalBytes new:10.
+
+ nBytesRead := h seekTo:-2 from:#end.
+ nBytesRead := h readBytes:2 into:buffer startingAt:1.
+
+ h close.
+
+ self assert:(nBytesRead == 2).
+ self assert:(buffer asString startsWith: '90').
+
+ 'xxx2' asFilename delete.
+
+ "
+ self new testPosition4
+ "
+!
+
testRead1
"open an existing file for reading; should read 10 chars"
@@ -285,7 +383,7 @@
buffer replaceFrom:1 with:'1234567890'.
('xxx1' asFilename exists) ifTrue:[
- 'xxx1' asFilename delete
+ 'xxx1' asFilename delete
].
h := OperatingSystem createFileForReadWrite:'xxx1'.
@@ -351,7 +449,7 @@
self assert:(h notNil).
self assert:(h isValid).
OperatingSystem isMSDOSlike ifTrue:[
- self assert:(h address ~~ 0).
+ self assert:(h address ~~ 0).
].
h := nil.
@@ -360,7 +458,7 @@
self assert:(h isValid not).
OperatingSystem isMSDOSlike ifTrue:[
- self assert:(h address == 0).
+ self assert:(h address == 0).
].
self assert:('xxx2' asFilename fileSize == 10). "/ should not change size