+// Test if input works with Delphi-compatible sdf output
+// Strictdelimiter:=false (default) when processing the delimitedtext
+//
+// Mainly check if reading quotes is according to Delphi sdf specs and works.
+// Based on del4.zip in bug 19610
+const
+ // Matches del4.zip in bug 19610:
+ DelimText='normal_string;"quoted_string";"quoted;delimiter";"quoted and space";"""quoted_and_starting_quote";"""quoted, starting quote, and space";"quoted_with_tab'+#9+'character";"quoted_multi'+LineEnding+
+ 'line"; UnquotedSpacesInfront;UnquotedSpacesAtTheEnd ; "Spaces before quoted string"';
+
+var
+ TestSL: TStringList;
+ Expected: TStringList;
+begin
+ //Expected values:
+ Expected:=TStringList.Create;
+ TestSL:=TStringList.Create;
+ try
+ Expected.Add('normal_string');
+ Expected.Add('quoted_string');
+ Expected.Add('quoted;delimiter');
+ Expected.Add('quoted and space');
+ Expected.Add('"quoted_and_starting_quote');
+ Expected.Add('"quoted, starting quote, and space');
+ Expected.Add('quoted_with_tab'+#9+'character');
+ Expected.Add('quoted_multi'+LineEnding+'line');
+ Expected.Add('UnquotedSpacesInfront');
+ Expected.Add('UnquotedSpacesAtTheEnd');
+ Expected.Add('Spaces before quoted string');
+
+ TestSL.Delimiter:=';'; //Match example in bug 19610, del4.zip
+ TestSL.StrictDelimiter:=false;
+ TestSL.DelimitedText:=DelimText;
+ Result:=CompareStringLists(Expected,TestSL);
+ finally
+ Expected.Free;
+ TestSL.Free;
+ end;
+end;
+
+function ReadStrictDelimTrue: string;
+// Test if input works with Delphi-compatible sdf output
+// Strictdelimiter:=true when processing the delimitedtext
+//
+// Mainly check if reading quotes is according to Delphi sdf specs and works.
+// Based on del4.zip in bug 19610
+const
+ // Matches del4.zip in bug 19610:
+ DelimText='normal_string;"quoted_string";"quoted;delimiter";"quoted and space";"""quoted_and_starting_quote";"""quoted, starting quote, and space";"quoted_with_tab'+#9+'character";"quoted_multi'+LineEnding+
+ 'line"; UnquotedSpacesInfront;UnquotedSpacesAtTheEnd ; "Spaces before quoted string"';
+
+var
+ TestSL: TStringList;
+ Expected: TStringList;
+begin
+ result:='';
+ //Expected values:
+ Expected:=TStringList.Create;
+ TestSL:=TStringList.Create;
+ try
+ Expected.Add('normal_string');
+ Expected.Add('quoted_string');
+ Expected.Add('quoted;delimiter');
+ Expected.Add('quoted and space');
+ Expected.Add('"quoted_and_starting_quote');
+ Expected.Add('"quoted, starting quote, and space');
+ Expected.Add('quoted_with_tab'+#9+'character');
+ Expected.Add('quoted_multi'+LineEnding+'line');
+ Expected.Add(' UnquotedSpacesInfront');
+ Expected.Add('UnquotedSpacesAtTheEnd ');
+ Expected.Add(' "Spaces before quoted string"');
+
+ TestSL.Delimiter:=';'; //Match example in bug 19610, del4.zip
+// Test if input works with Delphi-compatible sdf output
+// Strictdelimiter:=false (default) when processing the delimitedtext
+//
+// Has some corner cases that Delphi produces but are not evident from their
+// documentation
+// Based on del4.zip in bug 19610
+const
+ // Matches del4.zip in bug 19610:
+ DelimText='"Spaces after quoted string" ;';
+
+var
+ TestSL: TStringList;
+ Expected: TStringList;
+begin
+ result:='';
+ //Expected values:
+ Expected:=TStringList.Create;
+ TestSL:=TStringList.Create;
+ try
+ Expected.Add('Spaces after quoted string');
+ Expected.Add('');
+
+ TestSL.Delimiter:=';'; //Match example in bug 19610, del4.zip
+ TestSL.StrictDelimiter:=false;
+ TestSL.DelimitedText:=DelimText;
+ Result:=CompareStringLists(Expected,TestSL);
+ finally
+ Expected.Free;
+ TestSL.Free;
+ end;
+end;
+
+function ReadStrictDelimTrueCornerCases: string;
+// Test if input works with Delphi-compatible sdf output
+// Strictdelimiter:=true when processing the delimitedtext
+//
+// Has some corner cases that Delphi produces but are not evident from their
+// documentation
+// Based on del4.zip in bug 19610
+const
+ // Matches del4.zip in bug 19610:
+ DelimText='"Spaces after quoted string" ;';
+
+var
+ TestSL: TStringList;
+ Expected: TStringList;
+begin
+ Result:='';
+ //Expected values:
+ Expected:=TStringList.Create;
+ TestSL:=TStringList.Create;
+ try
+ // With delimiter true, we get 2 extra empty lines, also some spaces
+ Expected.Add('Spaces after quoted string');
+ Expected.Add(' ');
+ Expected.Add('');
+
+ TestSL.Delimiter:=';'; //Match example in bug 19610, del4.zip
+ TestSL.StrictDelimiter:=true;
+ TestSL.DelimitedText:=DelimText;
+ //Test:
+ Result:=CompareStringLists(Expected,TestSL);
+ finally
+ Expected.Free;
+ TestSL.Free;
+ end;
+end;
+
+function ReadStrictDelimTrueSafeQuote:string;
+// Test if input works with sdf output that has always been quoted
+// Delphi accepts this input even though it does not write it by default
+// This is a more unambiguous format than unquoted
+// Strictdelimiter:=true when processing the delimitedtext
+//
+const
+ DelimText='"normal_string";"""quoted_string""";"""quoted;delimiter""";"""quoted and space""";"""starting_quote";"string_with_tab'+#9+'character";"multi'+LineEnding+
+ 'line";" SpacesInfront";"SpacesAtTheEnd ";" ""Spaces before quoted string"""';
+
+var
+ TestSL: TStringList;
+ Expected: TStringList;
+begin
+ result:='';
+ //Expected values:
+ Expected:=TStringList.Create;
+ TestSL:=TStringList.Create;
+ try
+ Expected.Add('normal_string');
+ Expected.Add('"quoted_string"');
+ Expected.Add('"quoted;delimiter"');
+ Expected.Add('"quoted and space"');
+ Expected.Add('"starting_quote');
+ Expected.Add('string_with_tab'+#9+'character');
+ Expected.Add('multi'+LineEnding+
+ 'line');
+ Expected.Add(' SpacesInfront');
+ Expected.Add('SpacesAtTheEnd ');
+ Expected.Add(' "Spaces before quoted string"');
+
+ TestSL.Delimiter:=';'; //Match example in bug 19610, del4.zip
+ TestSL.StrictDelimiter:=true;
+ TestSL.DelimitedText:=DelimText;
+ Result:=CompareStringLists(Expected,TestSL);
+ finally
+ Expected.Free;
+ TestSL.Free;
+ end;
+end;
+
+function ReadStrictDelimFalseSafeQuote: string;
+// Test if input works with sdf output that has always been quoted
+// Delphi accepts this input even though it does not write it by default
+// This is a more unambiguous format than unquoted
+// Strictdelimiter:=false when processing the delimitedtext
+//
+const
+ DelimText='"normal_string";"""quoted_string""";"""quoted;delimiter""";"""quoted and space""";"""starting_quote";"string_with_tab'+#9+'character";"multi'+LineEnding+
+ 'line";" SpacesInfront";"SpacesAtTheEnd ";" ""Spaces before quoted string"""';
+
+var
+ TestSL: TStringList;
+ Expected: TStringList;
+begin
+ Result:='';
+ //Expected values:
+ Expected:=TStringList.Create;
+ TestSL:=TStringList.Create;
+ try
+ Expected.Add('normal_string');
+ Expected.Add('"quoted_string"');
+ Expected.Add('"quoted;delimiter"');
+ Expected.Add('"quoted and space"');
+ Expected.Add('"starting_quote');
+ Expected.Add('string_with_tab'+#9+'character');
+ Expected.Add('multi'+LineEnding+'line');
+ Expected.Add(' SpacesInfront');
+ Expected.Add('SpacesAtTheEnd ');
+ Expected.Add(' "Spaces before quoted string"');
+
+ TestSL.Delimiter:=';'; //Match example in bug 19610, del4.zip
+ TestSL.StrictDelimiter:=false;
+ TestSL.DelimitedText:=DelimText;
+ Result:=CompareStringLists(Expected,TestSL);
+ finally
+ Expected.Free;
+ TestSL.Free;
+ end;
+end;
+
+function ReadCommatext: string;
+
+// Test if input works with Delphi-compatible commatext
+const
+ CommaText='normal_string,"quoted_string","quoted,delimiter","quoted and space","""quoted_and_starting_quote","""quoted, starting quote, and space","quoted_with_tab'+#9+'character","quoted_multi'+LineEnding+
+ 'line"," UnquotedSpacesInfront","UnquotedSpacesAtTheEnd "," ""Spaces before quoted string"""';
+
+var
+ TestSL: TStringList;
+ Expected: TStringList;
+begin
+ result:='';
+ //Expected values:
+ Expected:=TStringList.Create;
+ TestSL:=TStringList.Create;
+ try
+ Expected.Add('normal_string');
+ Expected.Add('quoted_string');
+ Expected.Add('quoted,delimiter');
+ Expected.Add('quoted and space');
+ Expected.Add('"quoted_and_starting_quote');
+ Expected.Add('"quoted, starting quote, and space');
+ if (TestSL.DelimitedText<>Expected) and (TestSL.DelimitedText<>ExpectedSafeQuote) then
+ Exit('result: *'+TestSL.DelimitedText+'* while expected was: *'+Expected+'* - or, with safe quote output: *'+ExpectedSafeQuote+'*');
+end;
+
+function WriteStrictDelimFalse:string;
+
+// Test if conversion stringlist=>delimitedtext gives the right data
+// (right in this case: what Delphi outputs)
+// Strictdelimiter:=false when processing the delimitedtext
+const
+ Expected='normal_string;"""quoted_string""";"just;delimiter";"""quoted;delimiter""";"""quoted and space""";"""starting_quote";"single""quote";"""""quoted starting quote and space""";"with_tab'+#9+'character";"multi'+LineEnding+
+ 'line";" UnquotedSpacesInfront";"UnquotedSpacesAtTheEnd ";" ""Spaces before quoted string"""';
+ //If we choose to output the "safely quoted" version, we need to test for it:
+ //Though this version is not the same output as Delphi, it leads to the
+ //same input if imported again (see ReadStrictDelimFalseSafeQuote for corresponding tests)
+ ExpectedSafeQuote='"normal_string";"""quoted_string""";"just;delimiter";"""quoted;delimiter""";"""quoted and space""";"""starting_quote";"single""quote";"""""quoted starting quote and space""";"with_tab'+#9+'character";"multi'+LineEnding+
+ 'line";" UnquotedSpacesInfront";"UnquotedSpacesAtTheEnd ";" ""Spaces before quoted string"""';
+var
+ TestSL: TStringList;
+begin
+ Result:='';
+ TestSL:=TStringList.Create;
+ try
+ TestSL.Add('normal_string');
+ TestSL.Add('"quoted_string"');
+ TestSL.Add('just;delimiter');
+ TestSL.Add('"quoted;delimiter"');
+ TestSL.Add('"quoted and space"');
+ TestSL.Add('"starting_quote');
+ TestSL.Add('single"quote');
+ TestSL.Add('""quoted starting quote and space"');
+// Test if conversion stringlist=>delimitedtext gives the right data
+// (right in this case: what Delphi outputs)
+// Strictdelimiter:=true when processing the delimitedtext
+const
+ Expected='normal_string;"""quoted_string""";"just;delimiter";"""quoted;delimiter""";"""quoted and space""";"""starting_quote";"single""quote";"""""quoted starting quote and space""";with_tab'+#9+'character;multi'+LineEnding+
+ 'line; UnquotedSpacesInfront;UnquotedSpacesAtTheEnd ;" ""Spaces before quoted string"""';
+ //If we choose to output the "safely quoted" version, we need to test for it:
+ //Though this version is not the same output as Delphi, it leads to the
+ //same input if imported again (see ReadStrictDelimTrueSafeQuote for corresponding tests)
+ ExpectedSafeQuote='"normal_string";"""quoted_string""";"just;delimiter";"""quoted;delimiter""";"""quoted and space""";"""starting_quote";"single""quote";"""""quoted starting quote and space""";"with_tab'+#9+'character";"multi'+LineEnding+
+ 'line";" UnquotedSpacesInfront";"UnquotedSpacesAtTheEnd ";" ""Spaces before quoted string"""';
+
+var
+ TestSL: TStringList;
+begin
+ result:='';
+ TestSL:=TStringList.Create;
+ try
+ TestSL.Add('normal_string');
+ TestSL.Add('"quoted_string"');
+ TestSL.Add('just;delimiter');
+ TestSL.Add('"quoted;delimiter"');
+ TestSL.Add('"quoted and space"');
+ TestSL.Add('"starting_quote');
+ TestSL.Add('single"quote');
+ TestSL.Add('""quoted starting quote and space"');
+ if not CompareMem(Pointer(U8), @Bytes[0], Length(U8)) then
+ Exit('Error at 4');
+ // 2. check misc functions
+ if not (TEncoding.IsStandardEncoding(TEncoding.Unicode) or TEncoding.IsStandardEncoding(TEncoding.UTF8) or TEncoding.IsStandardEncoding(TEncoding.UTF7)) or
+ TEncoding.IsStandardEncoding(Cp866Encoding) or TEncoding.IsStandardEncoding(Cp1251Encoding) then
+ Exit('Error at 5');
+ if Cp866Encoding.EncodingName = '' then
+ Exit('Error at 6')
+ else if ShowDebugOutput then
+ WriteLn(Cp866Encoding.EncodingName);
+ if TEncoding.Default.CodePage <> DefaultSystemCodePage then
+ FailExit('writing to read-only file succeeded');
+ fileclose(l);
+ deletefile('tfile2.dat');
+
+
+ l:=filecreate('tfile2.dat');
+ if (l<0) then
+ FailExit('unable to create file (2)');
+ fileclose(l);
+ l:=fileopen('tfile2.dat',fmopenwrite);
+ if (filewrite(l,l,sizeof(l))<>sizeof(l)) then
+ FailExit('writing to write-only file failed');
+ if (fileseek(l,0,fsFromBeginning)<>0) then
+ FailExit('seeking write-only file failed');
+ if (fileread(l,l2,sizeof(l))>=0) then
+ FailExit('reading from write-only file succeeded');
+ fileclose(l);
+
+ l:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l<0) then
+ FailExit('unable to open file in read-only mode and fmShareDenyWrite mode');
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l2 < 0) then
+ FailExit('opening two files as read-only with fmShareDenyWrite failed');
+ fileclose(l2);
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareExclusive);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ FailExit('opening file first as read-only with fmShareDenyWrite, and then again as fmopenread with fmShareExclusive succeeded');
+ end;
+ fileclose(l);
+
+
+ l:=fileopen('tfile2.dat',fmopenwrite or fmShareExclusive);
+ if (l<0) then
+ FailExit('unable to open file in write-only and fmShareExclusive mode');
+ l2:=fileopen('tfile2.dat',fmopenwrite or fmShareExclusive);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ FailExit('opening two files as write-only with fmShareExclusive succeeded');
+ end;
+ l2:=fileopen('tfile2.dat',fmopenwrite or fmShareDenyWrite);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ FailExit('opening file first as write-only with fmShareExclusive, and then again as fmopenwrite with fmShareDenyWrite succeeded');
+ end;
+ fileclose(l);
+
+
+ l:=fileopen('tfile2.dat',fmopenread or fmShareExclusive);
+ if (l<0) then
+ FailExit('unable to open file in read-only and fmShareExclusive mode');
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareExclusive);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ FailExit('opening two files as read-only with fmShareExclusive succeeded');
+ end;
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ FailExit('opening file first as read-only with fmShareExclusive, and then again as fmopenread with fmShareDenyWrite succeeded');
+ end;
+ fileclose(l);
+
+
+ l:=fileopen('tfile2.dat',fmopenread);
+ if (l<0) then
+ FailExit('unable to open file in read-only mode (2)');
+ l2:=fileopen('tfile2.dat',fmopenread);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ FailExit('opening two files as read-only without sharing specified succeeded (should not, file is by default locked)');
+ end;
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ FailExit('opening two files as read-only with fmShareDenyWrite succeeded (should not, file is by default locked)');
+ end;
+ fileclose(l);
+
+
+ { should be same as no locking specified }
+ l:=fileopen('tfile2.dat',fmopenread or fmShareCompat);
+ if (l<0) then
+ FailExit('unable to open file in read-only mode (3)');
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareCompat);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ FailExit('opening two files as read-only with fmShareCompat succeeded (should be locked)');
+ end;
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ FailExit('opening file first as read-only fmShareCompat (should not have any effect), and then again as fmopenread with fmShareDenyWrite succeeded');
+ end;
+ fileclose(l);
+
+
+ l:=fileopen('tfile2.dat',fmopenread or fmShareDenyNone);
+ if (l<0) then
+ FailExit('unable to open file in read-only mode and fmShareDenyNone mode');
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyNone);
+ if (l2 < 0) then
+ FailExit('opening two files as read-only with fmShareDenyNone failed');
+ fileclose(l2);
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l2 < 0) then
+ FailExit('opening two files as read-only with fmShareDenyNone and then fmShareDenyWrite failed');
+ fileclose(l2);
+{ on Windows, fmShareExclusive checks whether the file is already open in any way by the current
+ or another process. On Unix, that is not the case, and we also cannot check against a
+ fmShareDenyNone mode
+}
+{$ifndef unix}
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareExclusive);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ FailExit('opening two files as read-only with fmShareDenyNone and then fmShareExclusive succeeded');
+ end;
+{$endif}
+ fileclose(l);
+
+ l:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l<0) then
+ FailExit('unable to open file in read-only mode and fmShareDenyWrite mode (2)');
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyNone);
+ if (l2 < 0) then
+ FailExit('opening files as read-only with fmShareDenyWrite and then fmShareDenyNone failed');
+ fileclose(l2);
+ fileclose(l);
+
+
+ l:=fileopen('tfile2.dat',fmopenwrite or fmShareDenyNone);
+ if (l<0) then
+ FailExit('unable to open file in write-only mode and fmShareDenyNone mode');
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyNone);
+ if (l2 < 0) then
+ FailExit('opening two files as read/write-only with fmShareDenyNone failed');
+ fileclose(l2);
+
+ except
+ on e: exception do
+ begin
+ writeln(e.message);
+ exitcode:=1;
+ end;
+ end;
+ finally
+ if (l>=0) then
+ fileclose(l);
+ deletefile('tfile2.dat');
+ end;
+end;
+
+Function file2 : string;
+
+VAR
+ dateTime: TDateTime;
+ f : file;
+
+BEGIN
+ if FileExists('datetest.dat') then
+ begin
+ Assign(f,'datetest.dat');
+ Erase(f);
+ end;
+ if FileExists('datetest.dat') then
+ Exit('Error at 1000');
+ FileClose(FileCreate('datetest.dat'));
+ if not(FileExists('datetest.dat')) then
+ Exit('Error at 1001');
+ dateTime := IncMonth(Now, -1);
+ if FileSetDate('datetest.dat', DateTimeToFileDate(dateTime))<>0 then
+ raise exception.create('reading from write-only file succeeded');
+ fileclose(l);
+
+ l:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l<0) then
+ raise exception.create('unable to open file in read-only mode and fmShareDenyWrite mode');
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l2 < 0) then
+ raise exception.create('opening two files as read-only with fmShareDenyWrite failed');
+ fileclose(l2);
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareExclusive);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ raise exception.create('opening file first as read-only with fmShareDenyWrite, and then again as fmopenread with fmShareExclusive succeeded');
+ end;
+ fileclose(l);
+
+
+ l:=fileopen('tfile2.dat',fmopenwrite or fmShareExclusive);
+ if (l<0) then
+ raise exception.create('unable to open file in write-only and fmShareExclusive mode');
+ l2:=fileopen('tfile2.dat',fmopenwrite or fmShareExclusive);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ raise exception.create('opening two files as write-only with fmShareExclusive succeeded');
+ end;
+ l2:=fileopen('tfile2.dat',fmopenwrite or fmShareDenyWrite);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ raise exception.create('opening file first as write-only with fmShareExclusive, and then again as fmopenwrite with fmShareDenyWrite succeeded');
+ end;
+ fileclose(l);
+
+
+ l:=fileopen('tfile2.dat',fmopenread or fmShareExclusive);
+ if (l<0) then
+ raise exception.create('unable to open file in read-only and fmShareExclusive mode');
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareExclusive);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ raise exception.create('opening two files as read-only with fmShareExclusive succeeded');
+ end;
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ raise exception.create('opening file first as read-only with fmShareExclusive, and then again as fmopenread with fmShareDenyWrite succeeded');
+ end;
+ fileclose(l);
+
+
+ l:=fileopen('tfile2.dat',fmopenread);
+ if (l<0) then
+ raise exception.create('unable to open file in read-only mode (2)');
+ l2:=fileopen('tfile2.dat',fmopenread);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ raise exception.create('opening two files as read-only without sharing specified succeeded (should not, file is by default locked)');
+ end;
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ raise exception.create('opening two files as read-only with fmShareDenyWrite succeeded (should not, file is by default locked)');
+ end;
+ fileclose(l);
+
+
+ { should be same as no locking specified }
+ l:=fileopen('tfile2.dat',fmopenread or fmShareCompat);
+ if (l<0) then
+ raise exception.create('unable to open file in read-only mode (3)');
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareCompat);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ raise exception.create('opening two files as read-only with fmShareCompat succeeded (should be locked)');
+ end;
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ raise exception.create('opening file first as read-only fmShareCompat (should not have any effect), and then again as fmopenread with fmShareDenyWrite succeeded');
+ end;
+ fileclose(l);
+
+
+ l:=fileopen('tfile2.dat',fmopenread or fmShareDenyNone);
+ if (l<0) then
+ raise exception.create('unable to open file in read-only mode and fmShareDenyNone mode');
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyNone);
+ if (l2 < 0) then
+ raise exception.create('opening two files as read-only with fmShareDenyNone failed');
+ fileclose(l2);
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l2 < 0) then
+ raise exception.create('opening two files as read-only with fmShareDenyNone and then fmShareDenyWrite failed');
+ fileclose(l2);
+{ on Windows, fmShareExclusive checks whether the file is already open in any way by the current
+ or another process. On Unix, that is not the case, and we also cannot check against a
+ fmShareDenyNone mode
+}
+{$ifndef unix}
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareExclusive);
+ if (l2 >= 0) then
+ begin
+ fileclose(l2);
+ raise exception.create('opening two files as read-only with fmShareDenyNone and then fmShareExclusive succeeded');
+ end;
+{$endif}
+ fileclose(l);
+
+ l:=fileopen('tfile2.dat',fmopenread or fmShareDenyWrite);
+ if (l<0) then
+ raise exception.create('unable to open file in read-only mode and fmShareDenyWrite mode (2)');
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyNone);
+ if (l2 < 0) then
+ raise exception.create('opening files as read-only with fmShareDenyWrite and then fmShareDenyNone failed');
+ fileclose(l2);
+ fileclose(l);
+
+
+ l:=fileopen('tfile2.dat',fmopenwrite or fmShareDenyNone);
+ if (l<0) then
+ raise exception.create('unable to open file in write-only mode and fmShareDenyNone mode');
+ l2:=fileopen('tfile2.dat',fmopenread or fmShareDenyNone);
+ if (l2 < 0) then
+ raise exception.create('opening two files as read/write-only with fmShareDenyNone failed');