1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-26 19:12:18 -05:00
Simba/Tests/PS/FileTests.simba

92 lines
2.3 KiB
Plaintext
Raw Normal View History

2010-04-09 16:02:20 -04:00
program Hoi;
{
Description: Test file to test the consistency of
the following Functions:
AppPath, DirectoryExists, FileExists, ExeExt,
DirectorySeperator, OpenFile, CreateFile, RewriteFile,
WriteFileString, ReadFileString, SetFileCharPointer,
FileSize, EndOfFile, FileContents.
Notes:
Needs: GetFiles.
Bugs:
Using ./test as TestPath crashes on Linux.
Usage:
Run it. Set the TestPath to a different directory if you are on Windows. :)
}
Const
fsFromBeginning = 0; // offset must be pos or 0
fsFromCurrent = 1; // offset pos or neg
fsFromEnd = 2; // offset only neg or 0
var
s, s2: string;
2010-04-16 11:04:50 -04:00
testPath : string;
2010-04-09 16:02:20 -04:00
myFile, myFile2: Integer;
begin
2010-04-16 11:04:50 -04:00
testPath := scriptpath +'Test';
s := ScriptPath;
2010-04-09 16:02:20 -04:00
Writeln('Our current path is: ' + s);
{ If DirectoryExists(s) Then
writeln('Directory ' + s + ' exists.'); }
{ If FileExists(s + DirectorySeperator + 'Cogat' + ExeExt) Then
writeln('We exist!'); }
myFile := CreateFile(TestPath);
WriteFileString(myFile, 'wat');
WriteFileString(myFile, 'watnumber2');
CloseFile(myFile);
myFile := OpenFile(TestPath, False);
ReadFileString(myFile, s2, 2);
writeln('s2: ' + s2);
CloseFile(myFile);
myFile := CreateFile(TestPath + '2');
WriteFileString(myFile, 'wat222');
CloseFile(myFile);
// TestPath now contains; 'watwatnumber2'. We will make it write 'number',
// and then 2.
myFile := OpenFile(TestPath, False);
SetFileCharPointer(myFile, 6, fsFromBeginning);
ReadFileString(myFile, s2, 6);
writeln('s2: ' + s2);
s2 := '';
SetFileCharPointer(myFile, -1, fsFromEnd);
ReadFileString(myFile, s2, 1);
writeln('s2: ' + s2);
CloseFile(myFile);
// myFile2 should be -1.
myFile := RewriteFile(TestPath, False);
myFile2 := RewriteFile(TestPath, False);
writeln(inttostr(myFile) + ' : ' + inttostr(myFile2));
// myFile2 should be -1.
myFile2 := OpenFile(TestPath, False);
writeln(inttostr(myFile) + ' : ' + inttostr(myFile2));
// Now, we will test EndOfFile, and FileSize.
While Not EndOfFile(myFile) Do
Begin
ReadFileString(myFile, s2, 1);
Writeln(s2);
End;
CloseFile(myFile);
//Writeln(FileContents(TestPath));
writeln('wat');
end.