\
\ file.4th --- test some file functions
\ (duz 15Apr95)
\

CR .( file access word set)
CR .( ====================)
CR

MARKER FORGET-FILE-TESTS

[UNDEFINED] Y [IF] : Y -1 = 0= . ; [THEN]
[UNDEFINED] N [IF] : N     . ; [THEN]
[UNDEFINED] D [IF] : D     DEPTH . ; [THEN]

\ create a file
: TEST-FN1  S" TESTFN1" ;
: TEST-FN2  S" TESTFN2" ;

TEST-FN1 R/W CREATE-FILE . VALUE TEST-FILE
D CR

\ after creation length = position = 0
TEST-FILE FILE-POSITION D. .
TEST-FILE FILE-SIZE D. .
D CR

\ write something
: TEST-TEXT S" THIS IS JUST SOME TEXT" ;

TEST-TEXT         TEST-FILE WRITE-FILE .
TEST-TEXT NIP S>D TEST-FILE FILE-POSITION DROP D= Y
D CR

\ read it back and compare it
0. TEST-FILE REPOSITION-FILE .
PAD  DUP  TEST-TEXT NIP  TEST-FILE  READ-FILE .
TEST-TEXT COMPARE .
D CR


\ resize the file
 1024. TEST-FILE RESIZE-FILE . TEST-FILE FILE-SIZE .  1024. D= Y SPACE
TEST-FILE FILE-POSITION . TEST-TEXT NIP S>D D= Y SPACE

10240. TEST-FILE RESIZE-FILE . TEST-FILE FILE-SIZE . 10240. D= Y SPACE
 2048. TEST-FILE RESIZE-FILE . TEST-FILE FILE-SIZE .  2048. D= Y SPACE
  100. TEST-FILE RESIZE-FILE . TEST-FILE FILE-SIZE .   100. D= Y SPACE
D CR

TEST-FILE CLOSE-FILE .
TEST-FN1 TEST-FN2 RENAME-FILE .

TEST-FN2 FILE-STATUS . R/W = Y
TEST-FN2 DELETE-FILE .
D CR


FORGET-FILE-TESTS
