You've already forked lazarus-ccr
Tests:
+ added test for GetSheetByName function + Added TSpreadInternalTests.ReadDateAsUTF8 to test wp's ReadAsUTF8 forum problem report with date/time cells * Fixed displaying sheet+column where problems occur (CellNotation function) git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2859 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -145,8 +145,8 @@ begin
|
||||
MyWorkSheet.WriteDateTime(Row,0,SollDates[Row]);
|
||||
// Some checks inside worksheet itself
|
||||
if not(MyWorkSheet.ReadAsDateTime(Row,0,ActualDateTime)) then
|
||||
Fail('Failed writing date time for cell '+CellNotation(Row));
|
||||
CheckEquals(SollDates[Row],ActualDateTime,'Test date/time value mismatch cell '+CellNotation(Row));
|
||||
Fail('Failed writing date time for cell '+CellNotation(MyWorkSheet,Row));
|
||||
CheckEquals(SollDates[Row],ActualDateTime,'Test date/time value mismatch cell '+CellNotation(MyWorksheet,Row));
|
||||
end;
|
||||
MyWorkBook.WriteToFile(TempFile,sfExcel8,true);
|
||||
MyWorkbook.Free;
|
||||
@ -162,8 +162,8 @@ begin
|
||||
for Row := Low(SollDates) to High(SollDates) do
|
||||
begin
|
||||
if not(MyWorkSheet.ReadAsDateTime(Row,0,ActualDateTime)) then
|
||||
Fail('Could not read date time for cell '+CellNotation(Row));
|
||||
CheckEquals(SollDates[Row],ActualDateTime,'Test date/time value mismatch cell '+CellNotation(Row));
|
||||
Fail('Could not read date time for cell '+CellNotation(MyWorkSheet,Row));
|
||||
CheckEquals(SollDates[Row],ActualDateTime,'Test date/time value mismatch cell '+CellNotation(MyWorkSheet,Row));
|
||||
end;
|
||||
// Finalization
|
||||
MyWorkbook.Free;
|
||||
@ -186,11 +186,15 @@ begin
|
||||
MyWorksheet:=GetWorksheetByName(MyWorkBook,DatesSheet);
|
||||
if MyWorksheet=nil then
|
||||
fail('Error in test code. Failed to get named worksheet');
|
||||
// We know these are valid time/date/datetime values....
|
||||
// Just test for empty string; we'll probably end up in a maze of localized date/time stuff
|
||||
// if we don't.
|
||||
CheckNotEquals(MyWorkSheet.ReadAsUTF8Text(Row, 0), '','Could not read date time as string for cell '+CellNotation(MyWorkSheet,Row));
|
||||
|
||||
if not(MyWorkSheet.ReadAsDateTime(Row, 0, ActualDateTime)) then
|
||||
Fail('Could not read date time for cell '+CellNotation(Row));
|
||||
Fail('Could not read date time for cell '+CellNotation(MyWorkSheet,Row));
|
||||
CheckEquals(SollDates[Row],ActualDateTime,'Test date/time value mismatch '
|
||||
+'cell '+CellNotation(Row));
|
||||
+'cell '+CellNotation(MyWorksheet,Row));
|
||||
|
||||
// Finalization
|
||||
MyWorkbook.Free;
|
||||
|
@ -22,6 +22,9 @@ uses
|
||||
type
|
||||
{ TSpreadReadInternalTests }
|
||||
// Read from xls/xml file with known values
|
||||
|
||||
{ TSpreadInternalTests }
|
||||
|
||||
TSpreadInternalTests= class(TTestCase)
|
||||
private
|
||||
protected
|
||||
@ -32,6 +35,11 @@ type
|
||||
//todo: add more calls, rename sheets, try to get sheets with invalid indexes etc
|
||||
//(see strings tests for how to deal with expected exceptions)
|
||||
procedure GetSheetByIndex;
|
||||
// Verify GetSheetByName returns the correct sheet number
|
||||
// GetSheetByName was implemented in SVN revision 2857
|
||||
procedure GetSheetByName;
|
||||
// Write out date cell and try to read as UTF8; verify if contents the same
|
||||
procedure ReadDateAsUTF8;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -54,6 +62,55 @@ begin
|
||||
MyWorkbook.Free;
|
||||
end;
|
||||
|
||||
procedure TSpreadInternalTests.GetSheetByName;
|
||||
const
|
||||
AnotherSheet='AnotherSheet';
|
||||
var
|
||||
MyWorksheet: TsWorksheet;
|
||||
MyWorkbook: TsWorkbook;
|
||||
Row: Cardinal;
|
||||
begin
|
||||
MyWorkbook := TsWorkbook.Create;
|
||||
MyWorkSheet:=MyWorkBook.AddWorksheet(InternalSheet);
|
||||
MyWorkSheet:=MyWorkBook.AddWorksheet(AnotherSheet);
|
||||
MyWorkSheet:=nil;
|
||||
MyWorkSheet:=MyWorkBook.GetWorksheetByName(InternalSheet);
|
||||
CheckFalse((MyWorksheet=nil),'GetWorksheetByName should return a valid index');
|
||||
CheckEquals(MyWorksheet.Name,InternalSheet,'GetWorksheetByName should return correct name.');
|
||||
MyWorkbook.Free;
|
||||
end;
|
||||
|
||||
procedure TSpreadInternalTests.ReadDateAsUTF8;
|
||||
var
|
||||
ActualDT: TDateTime;
|
||||
ActualDTString: string; //Result from ReadAsUTF8Text
|
||||
Cell: PCell;
|
||||
MyWorksheet: TsWorksheet;
|
||||
MyWorkbook: TsWorkbook;
|
||||
Row,Column: Cardinal;
|
||||
TestDT: TDateTime;
|
||||
begin
|
||||
Row:=0;
|
||||
Column:=0;
|
||||
TestDT:=EncodeDate(1969,7,21)+EncodeTime(2,56,0,0);
|
||||
MyWorkbook:=TsWorkbook.Create;
|
||||
MyWorkSheet:=MyWorkBook.AddWorksheet(InternalSheet);
|
||||
MyWorkSheet.WriteDateTime(Row,Column,TestDT); //write date
|
||||
|
||||
// Reading as date/time should just work
|
||||
if not(MyWorksheet.ReadAsDateTime(Row,Column,ActualDT)) then
|
||||
Fail('Could not read date time for cell '+CellNotation(MyWorkSheet,Row,Column));
|
||||
CheckEquals(TestDT,ActualDT,'Test date/time value mismatch '
|
||||
+'cell '+CellNotation(MyWorkSheet,Row,Column));
|
||||
|
||||
//Check reading as string, convert to date & compare
|
||||
ActualDTString:=MyWorkSheet.ReadAsUTF8Text(Row,Column);
|
||||
ActualDT:=StrToDateTimeDef(ActualDTString,EncodeDate(1906,1,1));
|
||||
CheckEquals(TestDT,ActualDT,'Date/time mismatch using ReadAsUTF8Text');
|
||||
|
||||
MyWorkbook.Free;
|
||||
end;
|
||||
|
||||
|
||||
procedure TSpreadInternalTests.SetUp;
|
||||
begin
|
||||
|
@ -134,7 +134,7 @@ begin
|
||||
MyWorkSheet.WriteNumber(Row,0,SollNumbers[Row]);
|
||||
// Some checks inside worksheet itself
|
||||
ActualNumber:=MyWorkSheet.ReadAsNumber(Row,0);
|
||||
CheckEquals(SollNumbers[Row],ActualNumber,'Test value mismatch cell '+CellNotation(Row));
|
||||
CheckEquals(SollNumbers[Row],ActualNumber,'Test value mismatch cell '+CellNotation(MyWorkSheet,Row));
|
||||
end;
|
||||
MyWorkBook.WriteToFile(TempFile,sfExcel8,true);
|
||||
MyWorkbook.Free;
|
||||
@ -150,7 +150,7 @@ begin
|
||||
for Row := Low(SollNumbers) to High(SollNumbers) do
|
||||
begin
|
||||
ActualNumber:=MyWorkSheet.ReadAsNumber(Row,0);
|
||||
CheckEquals(SollNumbers[Row],ActualNumber,'Test value mismatch cell '+CellNotation(Row));
|
||||
CheckEquals(SollNumbers[Row],ActualNumber,'Test value mismatch cell '+CellNotation(MyWorkSheet,Row));
|
||||
end;
|
||||
// Finalization
|
||||
MyWorkbook.Free;
|
||||
@ -176,7 +176,7 @@ begin
|
||||
|
||||
ActualNumber:=MyWorkSheet.ReadAsNumber(Row, 0);
|
||||
CheckEquals(SollNumbers[Row],ActualNumber,'Test value mismatch '
|
||||
+'cell '+CellNotation(Row));
|
||||
+'cell '+CellNotation(MyWorkSheet,Row));
|
||||
|
||||
// Finalization
|
||||
MyWorkbook.Free;
|
||||
|
@ -120,7 +120,7 @@ begin
|
||||
MyWorkSheet.WriteUTF8Text(Row,0,SollStrings[Row]);
|
||||
// Some checks inside worksheet itself
|
||||
ActualString:=MyWorkSheet.ReadAsUTF8Text(Row,0);
|
||||
CheckEquals(SollStrings[Row],ActualString,'Test value mismatch cell '+CellNotation(Row));
|
||||
CheckEquals(SollStrings[Row],ActualString,'Test value mismatch cell '+CellNotation(MyWorkSheet,Row));
|
||||
end;
|
||||
MyWorkBook.WriteToFile(TempFile,sfExcel8,true);
|
||||
MyWorkbook.Free;
|
||||
@ -136,7 +136,7 @@ begin
|
||||
for Row := Low(SollStrings) to High(SollStrings) do
|
||||
begin
|
||||
ActualString:=MyWorkSheet.ReadAsUTF8Text(Row,0);
|
||||
CheckEquals(SollStrings[Row],ActualString,'Test value mismatch cell '+CellNotation(Row));
|
||||
CheckEquals(SollStrings[Row],ActualString,'Test value mismatch cell '+CellNotation(MyWorkSheet,Row));
|
||||
end;
|
||||
// Finalization
|
||||
MyWorkbook.Free;
|
||||
@ -180,7 +180,7 @@ begin
|
||||
// Some checks inside worksheet itself
|
||||
ActualString:=MyWorkSheet.ReadAsUTF8Text(Row,0);
|
||||
CheckEquals(length(LocalNormStrings[Row]),length(ActualString),
|
||||
'Test value mismatch cell '+CellNotation(Row)+
|
||||
'Test value mismatch cell '+CellNotation(MyWorkSheet,Row)+
|
||||
' for string length.');
|
||||
except
|
||||
{ When over size limit we expect to hit this:
|
||||
@ -236,11 +236,11 @@ begin
|
||||
// Allow for truncation of excessive strings by fpspreadsheet
|
||||
if length(LocalNormStrings[Row])>MaxBytesBIFF8 then
|
||||
CheckEquals(MaxBytesBIFF8,length(ActualString),
|
||||
'Test value mismatch cell '+CellNotation(Row)+
|
||||
'Test value mismatch cell '+CellNotation(MyWorkSheet,Row)+
|
||||
' for string length.')
|
||||
else
|
||||
CheckEquals(length(LocalNormStrings[Row]),length(ActualString),
|
||||
'Test value mismatch cell '+CellNotation(Row)+
|
||||
'Test value mismatch cell '+CellNotation(MyWorkSheet,Row)+
|
||||
' for string length.');
|
||||
end;
|
||||
// Finalization
|
||||
@ -267,7 +267,7 @@ begin
|
||||
|
||||
ActualString:=MyWorkSheet.ReadAsUTF8Text(Row,0);
|
||||
CheckEquals(SollStrings[Row],ActualString,'Test value mismatch '
|
||||
+'cell '+CellNotation(Row));
|
||||
+'cell '+CellNotation(MyWorkSheet,Row));
|
||||
|
||||
// Finalization
|
||||
MyWorkbook.Free;
|
||||
|
Binary file not shown.
@ -20,9 +20,8 @@ const
|
||||
NumbersSheet = 'Numbers'; //worksheet name
|
||||
StringsSheet = 'Texts'; //worksheet name
|
||||
|
||||
// Returns an A.. notation based on row (e.g. A1).
|
||||
// Useful as all test values should be put in the A column of the spreadsheet
|
||||
function CellNotation(Row: integer): string;
|
||||
// Returns an A.. notation based on sheet, row, optional column (e.g. A1).
|
||||
function CellNotation(WorkSheet: TsWorksheet; Row: integer; Column: integer=0): string;
|
||||
|
||||
// Note: using this function instead of GetWorkSheetByName for compatibility with
|
||||
// older fpspreadsheet versions that don't have that function
|
||||
@ -56,11 +55,17 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function CellNotation(Row: integer): string;
|
||||
function CellNotation(WorkSheet: TsWorksheet; Row: integer; Column: integer=0): string;
|
||||
begin
|
||||
// From 0-based to Excel A1 notation
|
||||
// Note: we're only testing in the A column, that's why we hardcode the value
|
||||
result:=DatesSheet+'!A'+inttostr(Row+1);
|
||||
// Only goes from column A to Z...
|
||||
if not(assigned(Worksheet)) then
|
||||
result:='CellNotation: error getting worksheet.'
|
||||
else
|
||||
if Column<26 then
|
||||
result:=WorkSheet.Name+'!'+char(Column+65)+inttostr(Row+1)
|
||||
else
|
||||
result:=WorkSheet.Name+'!'+inttostr(Column+1)+':'+inttostr(Row+1)
|
||||
end;
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user