* Fix bug ID #36385, CSV header contains also disabled fields

git-svn-id: trunk@43639 -
This commit is contained in:
michael 2019-12-04 12:07:17 +00:00
parent cd8d75d5fa
commit 0add077916
2 changed files with 85 additions and 4 deletions

View File

@ -131,9 +131,8 @@ begin
If FormatSettings.HeaderRow then
begin
For I:=0 to ExportFields.Count-1 do
begin
FCSVOut.AppendCell(ExportFields[i].ExportedName);
end;
if ExportFields[i].Enabled then
FCSVOut.AppendCell(ExportFields[i].ExportedName);
FCSVOut.AppendRow; //close off with line ending
end;
inherited DoDataHeader;

View File

@ -57,11 +57,13 @@ type
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 TestCSVExportDisabledFields;
procedure TestFixedTextExport;
procedure TestFixedTextExportUTF8;
procedure TestFixedTextExportUTF16;
procedure TestFixedTextExportBoolean;
procedure TestFixedTextExportHeader;
procedure TestFixedTextExportHeaderDisabledFields;
procedure TestFixedTextExportSpaces;
procedure TestJSONExport;
procedure TestRTFExport;
@ -550,6 +552,46 @@ begin
end;
end;
procedure TTestDBExport.TestCSVExportDisabledFields;
var
DS : TBufDataset;
Exporter: TCSVExporter;
F : text;
S : UTF8String;
haveFile : Boolean;
begin
haveFile:=False;
Exporter:=Nil;
DS:=GetABCDS;
try
Exporter := TCSVExporter.Create(nil);
Exporter.FormatSettings.HeaderRow:=True;
Exporter.Dataset:=DS;
Exporter.FileName := FExportTempDir + lowercase(TestName) + '.csv';
Exporter.BuildDefaultFieldMap(Exporter.ExportFields);
Exporter.ExportFields[1].Enabled:=False;
AssertEquals('Output count',2,Exporter.Execute);
AssertTrue('Output file must be created', FileExists(Exporter.FileName));
AssertFalse('Output file must not be empty', (GetFileSize(Exporter.FileName) = 0));
AssignFile(F,Exporter.FileName);
Reset(F);
haveFile:=True;
Readln(F,S);
AssertEquals('Correct header line','A,C',S); // 1 extra
Readln(F,S);
AssertEquals('Correct first line','xx,zz',S); // 1 extra
Readln(F,S);
AssertEquals('Correct first line','x,z',S); // 1 extra
finally
if HaveFile then
closeFile(F);
if (FKeepFilesAfterTest = False) then
DeleteFile(Exporter.FileName);
Exporter.Free;
end;
end;
procedure TTestDBExport.TestFixedTextExport;
var
Exporter: TFixedLengthExporter;
@ -796,7 +838,7 @@ var
begin
haveFile:=False;
Exporter:=Nil;
DS:=GetBooleanDS;
DS:=GetABCDS;
try
Exporter := TFixedLengthExporter.Create(nil);
Exporter.FormatSettings.BooleanFalse:='false';
@ -827,6 +869,46 @@ begin
end;
end;
procedure TTestDBExport.TestFixedTextExportHeaderDisabledFields;
var
DS : TBufDataset;
Exporter: TFixedLengthExporter;
F : text;
S : UTF8String;
haveFile : Boolean;
begin
haveFile:=False;
Exporter:=Nil;
DS:=GetABCDS;
try
Exporter := TFixedLengthExporter.Create(nil);
Exporter.FormatSettings.HeaderRow:=True;
Exporter.Dataset:=DS;
Exporter.FileName := FExportTempDir + lowercase(TestName) + '.txt';
Exporter.BuildDefaultFieldMap(Exporter.ExportFields);
Exporter.ExportFields[1].Enabled:=False;
AssertEquals('Output count',2,Exporter.Execute);
AssertTrue('Output file must be created', FileExists(Exporter.FileName));
AssertFalse('Output file must not be empty', (GetFileSize(Exporter.FileName) = 0));
AssignFile(F,Exporter.FileName);
Reset(F);
haveFile:=True;
Readln(F,S);
AssertEquals('Correct header line','A C ',S); // 1 extra
Readln(F,S);
AssertEquals('Correct first line','xxzz',S); // 1 extra
Readln(F,S);
AssertEquals('Correct first line','x z ',S); // 1 extra
finally
if HaveFile then
closeFile(F);
if (FKeepFilesAfterTest = False) then
DeleteFile(Exporter.FileName);
Exporter.Free;
end;
end;
procedure TTestDBExport.TestFixedTextExportSpaces;
var
DS : TBufDataset;