* Merging revisions 43555 from trunk:

------------------------------------------------------------------------
    r43555 | michael | 2019-11-22 15:25:15 +0100 (Fri, 22 Nov 2019) | 1 line
    
    * Add boolean field length correction
    ------------------------------------------------------------------------

git-svn-id: branches/fixes_3_2@43715 -
This commit is contained in:
michael 2019-12-23 13:20:53 +00:00
parent 636c4419a0
commit 7fff8e538e

View File

@ -42,6 +42,7 @@ type
function FieldSupported(const FieldType: TFieldType;
const ExportSubFormat: TDetailedExportFormats): boolean; //Checks if output dataset supports a certain field type
procedure GenericExportTest(Exporter: TCustomDatasetExporter; ExportFormat: TDetailedExportFormats);
function GetBooleanDS: TBufDataset;
function GetFileSize(const FileName: string): integer; //Gets a file's size
protected
procedure SetUp; override;
@ -55,6 +56,7 @@ type
procedure TestCSVExport_RFC4180WithHeader; //tests csv export with settings that match RFC4180
procedure TestCSVExport_TweakSettingsSemicolon; //tests semicolon delimited, custom country values
procedure TestFixedTextExport;
procedure TestFixedTextExportBoolean;
procedure TestJSONExport;
procedure TestRTFExport;
procedure TestSQLExport;
@ -565,6 +567,69 @@ begin
end;
end;
Function TTestDBExport.GetBooleanDS : TBufDataset;
Var
DS : TBufDataset;
begin
DS:=TBufDataset.Create(Nil);
try
DS.FieldDefs.Add('F',ftBoolean,0);
DS.CreateDataset;
DS.Append;
DS.Fields[0].AsBoolean:=true;
DS.Post;
DS.Append;
DS.Fields[0].AsBoolean:=False;
DS.Post;
DS.First;
except
DS.Free;
Raise;
end;
Result:=DS;
end;
procedure TTestDBExport.TestFixedTextExportBoolean;
var
DS : TBufDataset;
Exporter: TFixedLengthExporter;
F : text;
S : UTF8String;
haveFile : Boolean;
begin
haveFile:=False;
Exporter:=Nil;
DS:=GetBooleanDS;
try
Exporter := TFixedLengthExporter.Create(nil);
Exporter.FixedFormatSettings.BooleanFalse:='false';
Exporter.FixedFormatSettings.BooleanTrue:='True';
Exporter.Dataset:=DS;
Exporter.FileName := FExportTempDir + lowercase(TestName) + '.txt';
Exporter.BuildDefaultFieldMap(Exporter.ExportFields);
AssertEquals('Correct width',5, TFixedLengthExportFieldItem(Exporter.ExportFields[0]).Width);
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 first line','True ',S); // 1 extra
Readln(F,S);
AssertEquals('Correct second line','false',S);
finally
if HaveFile then
closeFile(F);
if (FKeepFilesAfterTest = False) then
DeleteFile(Exporter.FileName);
Exporter.Free;
end;
end;
procedure TTestDBExport.TestJSONExport;
var
Exporter: TSimpleJSONExporter;