You've already forked lazarus-ccr
fpspreadsheet: Add unit test cases for pane support and showing/hiding of grid lines and sheet headers (write/read of BIFF5 and BIFF8). Passed.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3006 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
257
components/fpspreadsheet/tests/optiontests.pas
Normal file
257
components/fpspreadsheet/tests/optiontests.pas
Normal file
@ -0,0 +1,257 @@
|
|||||||
|
unit optiontests;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
{ Tests for spreadsheet options
|
||||||
|
This unit tests writing out to and reading back from files.
|
||||||
|
}
|
||||||
|
|
||||||
|
uses
|
||||||
|
// Not using Lazarus package as the user may be working with multiple versions
|
||||||
|
// Instead, add .. to unit search path
|
||||||
|
Classes, SysUtils, fpcunit, testregistry,
|
||||||
|
fpspreadsheet, xlsbiff2, xlsbiff5, xlsbiff8 {and a project requirement for lclbase for utf8 handling},
|
||||||
|
testsutility;
|
||||||
|
|
||||||
|
type
|
||||||
|
{ TSpreadWriteReadColorTests }
|
||||||
|
//Write to xls/xml file and read back
|
||||||
|
TSpreadWriteReadOptionsTests = class(TTestCase)
|
||||||
|
private
|
||||||
|
protected
|
||||||
|
// Set up expected values:
|
||||||
|
procedure SetUp; override;
|
||||||
|
procedure TearDown; override;
|
||||||
|
procedure TestWriteReadPanes(AFormat: TsSpreadsheetFormat;
|
||||||
|
ALeftPaneWidth, ATopPaneHeight: Integer);
|
||||||
|
procedure TestWriteReadGridHeaders(AFormat: TsSpreadsheetFormat;
|
||||||
|
AShowGridLines, AShowHeaders: Boolean);
|
||||||
|
|
||||||
|
published
|
||||||
|
// Writes out colors & reads back.
|
||||||
|
|
||||||
|
{ BIFF2 file format tests }
|
||||||
|
// procedure TestWriteReadBIFF2_Font_InternalPal; // internal palette for BIFF2 file format
|
||||||
|
|
||||||
|
{ BIFF5 file format tests }
|
||||||
|
procedure TestWriteReadBIFF5_GridLines_Headers;
|
||||||
|
procedure TestWriteReadBIFF5_GridLines;
|
||||||
|
procedure TestWriteReadBIFF5_Headers;
|
||||||
|
procedure TestWriteReadBIFF5_NoGridLines_NoHeaders;
|
||||||
|
|
||||||
|
procedure TestWriteReadBIFF5_Panes_HorVert;
|
||||||
|
procedure TestWriteReadBIFF5_Panes_Hor;
|
||||||
|
procedure TestWriteReadBIFF5_Panes_Vert;
|
||||||
|
procedure TestWriteReadBIFF5_Panes_None;
|
||||||
|
|
||||||
|
{ BIFF8 file format tests }
|
||||||
|
procedure TestWriteReadBIFF8_GridLines_Headers;
|
||||||
|
procedure TestWriteReadBIFF8_GridLines;
|
||||||
|
procedure TestWriteReadBIFF8_Headers;
|
||||||
|
procedure TestWriteReadBIFF8_NoGridLines_NoHeaders;
|
||||||
|
|
||||||
|
procedure TestWriteReadBIFF8_Panes_HorVert;
|
||||||
|
procedure TestWriteReadBIFF8_Panes_Hor;
|
||||||
|
procedure TestWriteReadBIFF8_Panes_Vert;
|
||||||
|
procedure TestWriteReadBIFF8_Panes_None;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
const
|
||||||
|
OptionsSheet = 'Options';
|
||||||
|
|
||||||
|
{ TSpreadWriteReadOptions }
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.SetUp;
|
||||||
|
begin
|
||||||
|
inherited SetUp;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TearDown;
|
||||||
|
begin
|
||||||
|
inherited TearDown;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ Test for grid lines and sheet headers }
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadGridHeaders(AFormat: TsSpreadsheetFormat;
|
||||||
|
AShowGridLines, AShowHeaders: Boolean);
|
||||||
|
var
|
||||||
|
MyWorksheet: TsWorksheet;
|
||||||
|
MyWorkbook: TsWorkbook;
|
||||||
|
TempFile: string; //write xls/xml to this file and read back from it
|
||||||
|
begin
|
||||||
|
TempFile := GetTempFileName;
|
||||||
|
{// Not needed: use workbook.writetofile with overwrite=true
|
||||||
|
if fileexists(TempFile) then
|
||||||
|
DeleteFile(TempFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write out show/hide grid lines/sheet headers
|
||||||
|
MyWorkbook := TsWorkbook.Create;
|
||||||
|
MyWorkSheet:= MyWorkBook.AddWorksheet(OptionsSheet);
|
||||||
|
if AShowGridLines then
|
||||||
|
MyWorksheet.Options := MyWorksheet.Options + [soShowGridLines]
|
||||||
|
else
|
||||||
|
MyWorksheet.Options := MyWorksheet.Options - [soShowGridLines];
|
||||||
|
if AShowHeaders then
|
||||||
|
MyWorksheet.Options := MyWorksheet.Options + [soShowHeaders]
|
||||||
|
else
|
||||||
|
MyWorksheet.Options := MyWorksheet.Options - [soShowHeaders];
|
||||||
|
|
||||||
|
MyWorkBook.WriteToFile(TempFile, AFormat, true);
|
||||||
|
MyWorkbook.Free;
|
||||||
|
|
||||||
|
// Read back presence of grid lines/sheet headers
|
||||||
|
MyWorkbook := TsWorkbook.Create;
|
||||||
|
MyWorkbook.ReadFromFile(TempFile, AFormat);
|
||||||
|
if AFormat = sfExcel2 then
|
||||||
|
MyWorksheet := MyWorkbook.GetFirstWorksheet
|
||||||
|
else
|
||||||
|
MyWorksheet := GetWorksheetByName(MyWorkBook, OptionsSheet);
|
||||||
|
if MyWorksheet=nil then
|
||||||
|
fail('Error in test code. Failed to get named worksheet');
|
||||||
|
CheckEquals(soShowGridLines in MyWorksheet.Options, AShowGridLines,
|
||||||
|
'Test saved show grid lines mismatch');
|
||||||
|
CheckEquals(soShowHeaders in MyWorksheet.Options, AShowHeaders,
|
||||||
|
'Test saved show headers mismatch');
|
||||||
|
MyWorkbook.Free;
|
||||||
|
|
||||||
|
DeleteFile(TempFile);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ Tests for BIFF5 grid lines and/or headers }
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_GridLines_Headers;
|
||||||
|
begin
|
||||||
|
TestWriteReadGridHeaders(sfExcel5, true, true);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_GridLines;
|
||||||
|
begin
|
||||||
|
TestWriteReadGridHeaders(sfExcel5, true, false);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_Headers;
|
||||||
|
begin
|
||||||
|
TestWriteReadGridHeaders(sfExcel5, false, true);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_NoGridLines_NoHeaders;
|
||||||
|
begin
|
||||||
|
TestWriteReadGridHeaders(sfExcel5, false, false);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ Tests for BIFF8 grid lines and/or headers }
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_GridLines_Headers;
|
||||||
|
begin
|
||||||
|
TestWriteReadGridHeaders(sfExcel8, true, true);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_GridLines;
|
||||||
|
begin
|
||||||
|
TestWriteReadGridHeaders(sfExcel8, true, false);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_Headers;
|
||||||
|
begin
|
||||||
|
TestWriteReadGridHeaders(sfExcel8, false, true);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_NoGridLines_NoHeaders;
|
||||||
|
begin
|
||||||
|
TestWriteReadGridHeaders(sfExcel8, false, false);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ Test for frozen panes }
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadPanes(AFormat: TsSpreadsheetFormat;
|
||||||
|
ALeftPaneWidth, ATopPaneHeight: Integer);
|
||||||
|
var
|
||||||
|
MyWorksheet: TsWorksheet;
|
||||||
|
MyWorkbook: TsWorkbook;
|
||||||
|
TempFile: string; //write xls/xml to this file and read back from it
|
||||||
|
begin
|
||||||
|
TempFile := GetTempFileName;
|
||||||
|
{// Not needed: use workbook.writetofile with overwrite=true
|
||||||
|
if fileexists(TempFile) then
|
||||||
|
DeleteFile(TempFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write out pane sizes
|
||||||
|
MyWorkbook := TsWorkbook.Create;
|
||||||
|
MyWorkSheet:= MyWorkBook.AddWorksheet(OptionsSheet);
|
||||||
|
MyWorksheet.LeftPaneWidth := ALeftPaneWidth;
|
||||||
|
MyWorksheet.TopPaneHeight := ATopPaneHeight;
|
||||||
|
MyWorksheet.Options := MyWorksheet.Options + [soHasFrozenPanes];
|
||||||
|
MyWorkBook.WriteToFile(TempFile, AFormat, true);
|
||||||
|
MyWorkbook.Free;
|
||||||
|
|
||||||
|
// Read back pane sizes
|
||||||
|
MyWorkbook := TsWorkbook.Create;
|
||||||
|
MyWorkbook.ReadFromFile(TempFile, AFormat);
|
||||||
|
if AFormat = sfExcel2 then
|
||||||
|
MyWorksheet := MyWorkbook.GetFirstWorksheet
|
||||||
|
else
|
||||||
|
MyWorksheet := GetWorksheetByName(MyWorkBook, OptionsSheet);
|
||||||
|
if MyWorksheet=nil then
|
||||||
|
fail('Error in test code. Failed to get named worksheet');
|
||||||
|
CheckEquals(soHasFrozenPanes in MyWorksheet.Options, true,
|
||||||
|
'Test saved frozen panes mismatch');
|
||||||
|
CheckEquals(MyWorksheet.LeftPaneWidth, ALeftPaneWidth,
|
||||||
|
'Test saved left pane width mismatch');
|
||||||
|
CheckEquals(MyWorksheet.TopPaneHeight, ATopPaneHeight,
|
||||||
|
'Test save top pane height mismatch');
|
||||||
|
MyWorkbook.Free;
|
||||||
|
|
||||||
|
DeleteFile(TempFile);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ Tests for BIFF5 frozen panes }
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_Panes_HorVert;
|
||||||
|
begin
|
||||||
|
TestWriteReadPanes(sfExcel5, 1, 2);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_Panes_Hor;
|
||||||
|
begin
|
||||||
|
TestWriteReadPanes(sfExcel5, 1, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_Panes_Vert;
|
||||||
|
begin
|
||||||
|
TestWriteReadPanes(sfExcel5, 0, 2);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_Panes_None;
|
||||||
|
begin
|
||||||
|
TestWriteReadPanes(sfExcel5, 0, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ Tests for BIFF8 frozen panes }
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_Panes_HorVert;
|
||||||
|
begin
|
||||||
|
TestWriteReadPanes(sfExcel8, 1, 2);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_Panes_Hor;
|
||||||
|
begin
|
||||||
|
TestWriteReadPanes(sfExcel8, 1, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_Panes_Vert;
|
||||||
|
begin
|
||||||
|
TestWriteReadPanes(sfExcel8, 0, 2);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_Panes_None;
|
||||||
|
begin
|
||||||
|
TestWriteReadPanes(sfExcel8, 0, 0);
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterTest(TSpreadWriteReadOptionsTests);
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
@ -79,7 +79,7 @@
|
|||||||
<PackageName Value="FCL"/>
|
<PackageName Value="FCL"/>
|
||||||
</Item4>
|
</Item4>
|
||||||
</RequiredPackages>
|
</RequiredPackages>
|
||||||
<Units Count="10">
|
<Units Count="11">
|
||||||
<Unit0>
|
<Unit0>
|
||||||
<Filename Value="spreadtestgui.lpr"/>
|
<Filename Value="spreadtestgui.lpr"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
@ -130,6 +130,11 @@
|
|||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
<UnitName Value="fonttests"/>
|
<UnitName Value="fonttests"/>
|
||||||
</Unit9>
|
</Unit9>
|
||||||
|
<Unit10>
|
||||||
|
<Filename Value="optiontests.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="optiontests"/>
|
||||||
|
</Unit10>
|
||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
|
@ -4,7 +4,8 @@ program spreadtestgui;
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Interfaces, Forms, GuiTestRunner, datetests, stringtests, numberstests,
|
Interfaces, Forms, GuiTestRunner, datetests, stringtests, numberstests,
|
||||||
manualtests, testsutility, internaltests, formattests, colortests, fonttests;
|
manualtests, testsutility, internaltests, formattests, colortests, fonttests,
|
||||||
|
optiontests;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Application.Initialize;
|
Application.Initialize;
|
||||||
|
@ -917,9 +917,9 @@ end;
|
|||||||
|
|
||||||
{ Reads the WINDOW2 record containing information like "show grid lines",
|
{ Reads the WINDOW2 record containing information like "show grid lines",
|
||||||
"show sheet headers", "panes are frozen", etc.
|
"show sheet headers", "panes are frozen", etc.
|
||||||
The record structure is different for BIFF5 and BIFF8, but we use here only
|
The record structure is slightly different for BIFF5 and BIFF8, but we use
|
||||||
the common part.
|
here only the common part.
|
||||||
BIFF2 is completely different and has to be overridden. }
|
BIFF2 has a different structure and has to be re-written. }
|
||||||
procedure TsSpreadBIFFReader.ReadWindow2(AStream: TStream);
|
procedure TsSpreadBIFFReader.ReadWindow2(AStream: TStream);
|
||||||
var
|
var
|
||||||
flags: Word;
|
flags: Word;
|
||||||
|
Reference in New Issue
Block a user