1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-05 17:05:19 -05:00
Simba/Tests/PS/FileTests.mufa
Wizzup? b4d56fa979 Changes in doc and code.
git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@267 3f818213-9676-44b0-a9b4-5e4c4e03d09d
2009-12-04 20:57:00 +00:00

91 lines
2.2 KiB
Plaintext

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
TestPath = './test';
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;
myFile, myFile2: Integer;
begin
s := apppath;
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.