* tests: test WriteToFile AOverwriteExisting, hopefully catches error reported in

http://forum.lazarus.freepascal.org/index.php/topic,23051.msg137012.html#msg137012



git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2869 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
bigchimp
2013-12-27 09:32:10 +00:00
parent 75b5c4188f
commit 449252cbe6

View File

@ -17,11 +17,12 @@ uses
// Instead, add .. to unit search path
Classes, SysUtils, fpcunit, testutils, testregistry,
fpsallformats, fpspreadsheet, xlsbiff8 {and a project requirement for lclbase for utf8 handling},
testsutility;
testsutility, md5;
type
{ TSpreadReadInternalTests }
// Read from xls/xml file with known values
// Tests fpspreadsheet functionality, especially internal functions
// Excel/LibreOffice/OpenOffice import/export compatibility should *NOT* be tested here
{ TSpreadInternalTests }
@ -38,6 +39,8 @@ type
// Verify GetSheetByName returns the correct sheet number
// GetSheetByName was implemented in SVN revision 2857
procedure GetSheetByName;
// Tests whether overwriting existing file works
procedure OverwriteExistingFile;
// Write out date cell and try to read as UTF8; verify if contents the same
procedure ReadDateAsUTF8;
end;
@ -80,6 +83,44 @@ begin
MyWorkbook.Free;
end;
procedure TSpreadInternalTests.OverwriteExistingFile;
const
FirstFileCellText='Old version';
SecondFileCellText='New version';
var
FirstFileHash: string;
MyWorksheet: TsWorksheet;
MyWorkbook: TsWorkbook;
TempFile: string;
begin
TempFile:=GetTempFileName;
if fileexists(TempFile) then
DeleteFile(TempFile);
// Write out first file
MyWorkbook:=TsWorkbook.Create;
try
MyWorkSheet:=MyWorkBook.AddWorksheet(InternalSheet);
MyWorkSheet.WriteUTF8Text(0,0,FirstFileCellText);
MyWorkBook.WriteToFile(TempFile,sfExcel8,false);
finally
MyWorkbook.Free;
end;
FirstFileHash:=MD5Print(MD5File(TempFile));
// Now overwrite with second file
MyWorkbook:=TsWorkbook.Create;
try
MyWorkSheet:=MyWorkBook.AddWorksheet(InternalSheet);
MyWorkSheet.WriteUTF8Text(0,0,SecondFileCellText);
MyWorkBook.WriteToFile(TempFile,sfExcel8,true);
finally
MyWorkbook.Free;
end;
if FirstFileHash=MD5Print(MD5File(TempFile)) then
fail('File contents are still those of the first file.');
end;
procedure TSpreadInternalTests.ReadDateAsUTF8;
var
ActualDT: TDateTime;