+ sqldb: db test framework:

- consolidate csv export test from issue #20268 
- fix output filenames so that naming collisions are less likely

git-svn-id: trunk@23165 -
This commit is contained in:
reiniero 2012-12-17 15:56:40 +00:00
parent 1ce4f17261
commit f62269a111

View File

@ -42,7 +42,9 @@ type
procedure TestDBFExport_DBaseIV;
procedure TestDBFExport_DBaseVII;
procedure TestDBFExport_FoxPro;
procedure TestCSVExport;
procedure TestCSVExport; //tests csv export with default values
procedure TestCSVExport_RFC4180WithHeader; //tests csv export with settings that match RFC4180
procedure TestCSVExport_TweakSettingsSemicolon; //tests semicolon delimited, custom country values
procedure TestFixedTextExport;
procedure TestJSONExport;
procedure TestRTFExport;
@ -169,7 +171,8 @@ begin
ExportFormat:=efDBaseVII;
ExportSettings.TableFormat:=tfDBaseVII;
// Use export subtype position to differentiate output filenames:
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -194,7 +197,8 @@ begin
try
ExportFormat:=efDBaseIV;
ExportSettings.TableFormat:=tfDBaseIV;
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -219,7 +223,8 @@ begin
try
ExportFormat:=efFoxpro;
ExportSettings.TableFormat:=tfFoxPro;
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -246,7 +251,8 @@ begin
ExportFormat:=efXMLXSDAccess;
ExportSettings.CreateXSD:=false;
ExportSettings.DecimalSeparator:='.'; //override
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -273,7 +279,8 @@ begin
ExportFormat:=efXMLXSDAccess;
ExportSettings.CreateXSD:=false;
ExportSettings.DecimalSeparator:=char(''); //don't override
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -300,7 +307,8 @@ begin
ExportFormat:=efXMLXSDAccess;
ExportSettings.CreateXSD:=true;
ExportSettings.DecimalSeparator:='.'; //override
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -327,7 +335,8 @@ begin
ExportFormat:=efXMLXSDAccess;
ExportSettings.CreateXSD:=true;
ExportSettings.DecimalSeparator:=char(''); //don't override
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -354,7 +363,8 @@ begin
ExportSettings.ExportFormat:=ADONETCompatible;
ExportFormat:=efXMLXSDADONet;
ExportSettings.CreateXSD:=false;
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -380,7 +390,8 @@ begin
ExportSettings.ExportFormat:=ADONETCompatible;
ExportFormat:=efXMLXSDADONet;
ExportSettings.CreateXSD:=true;
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -402,12 +413,79 @@ var
begin
Exporter := TCSVExporter.Create(nil);
ExportSettings:=TCSVFormatSettings.Create(true);
//todo: set settings to match RFC4180 as much as possible as that is the only
// sane CSV format to test for (and perhaps Excel-compatible as far as that
// can be defined)
try
ExportFormat:=efCSV;
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
AssertTrue('Output file must be created', FileExists(Exporter.FileName));
AssertFalse('Output file must not be empty', (GetFileSize(Exporter.FileName) = 0));
finally
if (FKeepFilesAfterTest = False) then
DeleteFile(Exporter.FileName);
ExportSettings.Free;
Exporter.Free;
end;
end;
procedure TTestDBExport.TestCSVExport_RFC4180WithHeader;
var
Exporter: TCSVExporter;
ExportFormat: TDetailedExportFormats;
ExportSettings: TCSVFormatSettings;
begin
Exporter := TCSVExporter.Create(nil);
ExportSettings:=TCSVFormatSettings.Create(true);
try
ExportSettings.FieldDelimiter:=','; //RFC 4180 specified commas as delimiter
ExportSettings.HeaderRow:=true; //...allows an optional header line
ExportSettings.StringQuoteChar:='"'; //...requires quoting with " (if quoting)
// Fields containing line breaks (CRLF), double quotes,
// and commas should be enclosed in double-quotes.
// => this probably won't get tested with this test set.
ExportFormat:=efCSV;
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
AssertTrue('Output file must be created', FileExists(Exporter.FileName));
AssertFalse('Output file must not be empty', (GetFileSize(Exporter.FileName) = 0));
finally
if (FKeepFilesAfterTest = False) then
DeleteFile(Exporter.FileName);
ExportSettings.Free;
Exporter.Free;
end;
end;
procedure TTestDBExport.TestCSVExport_TweakSettingsSemicolon;
var
Exporter: TCSVExporter;
ExportFormat: TDetailedExportFormats;
ExportSettings: TCSVFormatSettings;
begin
Exporter := TCSVExporter.Create(nil);
ExportSettings:=TCSVFormatSettings.Create(true);
try
ExportSettings.FieldDelimiter:=';';
ExportSettings.QuoteStrings:=[qsAlways,qsSpace,qsDelimiter]; //quote everything we can
ExportSettings.StringQuoteChar:='"'; //try explicit assignment
ExportSettings.RowDelimiter:=#10; //Unix/Linux format
ExportSettings.BooleanFalse:='onwaar'; //why not a Dutch output format?
ExportSettings.BooleanTrue:='waar'; //why not a Dutch output format?
ExportSettings.CurrencyDigits:=3;
ExportSettings.CurrencySymbol:='€'; //euro sign
ExportSettings.DateFormat:='d-mm-yyyy'; //Dutch setting
ExportSettings.DateTimeFormat:='d-mm-yyyy hh:nn:ss'; //Dutch setting
ExportSettings.DecimalSeparator:=','; //another Dutch setting
ExportSettings.TimeFormat:='hh:nn:ss'; //Dutch setting
ExportSettings.IntegerFormat:='0000';//Strange but nice ;)
ExportFormat:=efCSV;
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -429,7 +507,8 @@ begin
Exporter := TFixedLengthExporter.Create(nil);
try
ExportFormat:=efFixedLengthText;
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
GenericExportTest(Exporter, ExportFormat);
AssertTrue('Output file must be created', FileExists(Exporter.FileName));
@ -451,9 +530,9 @@ begin
ExportSettings:=TSimpleJSONFormatSettings.Create(true);
try
ExportFormat:=efJSON;
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) + lowercase(rightstr(TestName,5))+
inttostr(ord(ExportFormat))+
TDetailedExportExtensions[ExportFormat]; Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
AssertTrue('Output file must be created', FileExists(Exporter.FileName));
AssertFalse('Output file must not be empty', (GetFileSize(Exporter.FileName) = 0));
@ -475,7 +554,8 @@ begin
ExportSettings:=TRTFExportFormatSettings.Create(true);
try
ExportFormat:=efRTF;
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5))+
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -500,7 +580,8 @@ begin
try
ExportSettings.TableName:='ATABLE'; //required for export to succeed
ExportFormat:=efSQL;
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5))+
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -524,7 +605,8 @@ begin
ExportSettings:=TTeXExportFormatSettings.Create(true);
try
ExportFormat:=efTeX;
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir +
inttostr(ord(ExportFormat)) + lowercase(rightstr(TestName,5))+
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -548,7 +630,8 @@ begin
ExportSettings:=TSimpleXMLFormatSettings.Create(true);
try
ExportFormat:=efXML;
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -573,7 +656,8 @@ begin
try
ExportSettings.ExportFormat:=DelphiClientDataset;
ExportFormat:=efXMLXSDClientDataset;
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);
@ -598,7 +682,8 @@ begin
try
ExportSettings.ExportFormat:=ExcelCompatible;
ExportFormat:=efXMLXSDExcel;
Exporter.FileName := FExportTempDir + 'expt'+inttostr(ord(ExportFormat))+
Exporter.FileName := FExportTempDir + inttostr(ord(ExportFormat)) +
lowercase(rightstr(TestName,5)) +
TDetailedExportExtensions[ExportFormat];
Exporter.FormatSettings:=ExportSettings;
GenericExportTest(Exporter, ExportFormat);