RegressionTests__FileOpenTest.st
author Claus Gittinger <cg@exept.de>
Tue, 11 Dec 2001 20:00:03 +0100
changeset 126 8b42761a09ef
parent 125 c2d1c9253563
child 127 ea86e9e95e4b
permissions -rw-r--r--
checkin from browser

"{ Package: 'exept:regression' }"

"{ NameSpace: RegressionTests }"

TestCase subclass:#FileOpenTest
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Tests-Regression'
!


!FileOpenTest methodsFor:'tests'!

createWithSize10:fileName
    "helper"

    (fileName asFilename exists) ifTrue:[
        fileName asFilename delete
    ].
    fileName asFilename writeStream 
        nextPutAll:'1234567890';
        close.
    self assert:(fileName asFilename exists).
    self assert:(fileName asFilename fileSize == 10).

    "
     self new createWithSize10:'xxx1'
    "
!

testCreate1
    "create a new file (initially not existing)"

    |h|

    ('xxx1' asFilename exists) ifTrue:[
        'xxx1' asFilename delete
    ].

    h := OperatingSystem createFileForReadWrite:'xxx1'.
    self assert:(h notNil).
    self assert:(h isValid).
    OperatingSystem isMSDOSlike ifTrue:[
        self assert:(h address ~~ 0).
    ].

    h close.
    self assert:(h isValid not).
    OperatingSystem isMSDOSlike ifTrue:[
        self assert:(h address == 0).
    ].

    self assert:('xxx1' asFilename exists).
    self assert:('xxx1' asFilename fileSize == 0).

    'xxx1' asFilename delete

    "
     self new testCreate1
    "

    "Modified: / 12.8.1998 / 13:29:55 / cg"
!

testCreate2
    "create a file; checks if the file is truncated if already existing"

    |h|

    self createWithSize10:'xxx1'.


    h := OperatingSystem createFileForReadWrite:'xxx1'.
    self assert:(h notNil).
    self assert:(h isValid).
    OperatingSystem isMSDOSlike ifTrue:[
        self assert:(h address ~~ 0).
    ].

    h close.
    self assert:(h isValid not).
    OperatingSystem isMSDOSlike ifTrue:[
        self assert:(h address == 0).
    ].

    self assert:('xxx1' asFilename exists).
    self assert:('xxx1' asFilename fileSize == 0).

    "
     self new testCreate2
    "

    "Modified: / 12.8.1998 / 13:29:55 / cg"
!

testFailCreate1
    "try to create an uncreatable new file (directory not existing)"

    |fn|

    fn := (('.' asFilename construct:'foo')  construct:'bar') construct:'xxx1'.
    self 
        should:[
            OperatingSystem createFileForReadWrite:fn name]
        raise:(OSErrorHolder unavailableReferentSignal).

    "/ raised signal should be a child of inaccessibleSignal
    self 
        should:[
            OperatingSystem createFileForReadWrite:fn name]
        raise:(OSErrorHolder inaccessibleSignal ).

    "/ raised signal should be a child of OsError
    self 
        should:[
            OperatingSystem createFileForReadWrite:fn name]
        raise:(OsError ).

    "
     self new testFailCreate1
    "

    "Modified: / 12.8.1998 / 13:29:55 / cg"
!

testFailOpen1
    "open a non-existing file; must fail"

    |h|

    'xxx2' asFilename delete.

    self 
        should:[
                h := OperatingSystem openFileForRead:'xxx2'.]
        raise:(OSErrorHolder nonexistentSignal).


    "
     self new testFailOpen1
    "

    "Modified: / 12.8.1998 / 13:29:55 / cg"
!

testOpen1
    "open an existing file"

    |h|

    self createWithSize10:'xxx2'.

    h := OperatingSystem openFileForRead:'xxx2'.
    self assert:(h notNil).
    self assert:(h isValid).
    OperatingSystem isMSDOSlike ifTrue:[
        self assert:(h address ~~ 0).
    ].

    h close.
    self assert:(h isValid not).
    OperatingSystem isMSDOSlike ifTrue:[
        self assert:(h address == 0).
    ].

    'xxx2' asFilename delete.

    "
     self new testOpen1
    "

    "Modified: / 12.8.1998 / 13:29:55 / cg"
! !

!FileOpenTest class methodsFor:'documentation'!

version
    ^ '$Header$'
! !