mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-21 12:49:33 +02:00
* Fixed merge conflicts
git-svn-id: branches/fixes_3_2@43756 -
This commit is contained in:
parent
b8a22b8e6d
commit
f55addba35
@ -44,6 +44,7 @@ type
|
||||
procedure GenericExportTest(Exporter: TCustomDatasetExporter; ExportFormat: TDetailedExportFormats);
|
||||
function GetBooleanDS: TBufDataset;
|
||||
function GetFileSize(const FileName: string): integer; //Gets a file's size
|
||||
function GetWideStringDS: TBufDataset;
|
||||
protected
|
||||
procedure SetUp; override;
|
||||
procedure TearDown; override;
|
||||
@ -57,6 +58,8 @@ type
|
||||
procedure TestCSVExport_TweakSettingsSemicolon; //tests semicolon delimited, custom country values
|
||||
procedure TestFixedTextExport;
|
||||
procedure TestFixedTextExportBoolean;
|
||||
procedure TestFixedTextExportUTF8;
|
||||
procedure TestFixedTextExportUTF16;
|
||||
procedure TestJSONExport;
|
||||
procedure TestRTFExport;
|
||||
procedure TestSQLExport;
|
||||
@ -104,11 +107,9 @@ begin
|
||||
efTeX: result:=true;
|
||||
efXML: result:=true;
|
||||
efXMLXSDAccess, efXMLXSDADONet, efXMLXSDClientDataset, efXMLXSDExcel: result:=true;
|
||||
else
|
||||
begin
|
||||
result:=false;
|
||||
Fail('Error in test code itself: FieldSupported unknown ExportSubFormat '+inttostr(ord(ExportSubFormat)));
|
||||
end;
|
||||
else
|
||||
result:=false;
|
||||
Fail('Error in test code itself: FieldSupported unknown ExportSubFormat '+inttostr(ord(ExportSubFormat)));
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -168,7 +169,7 @@ begin
|
||||
DBConnector.StartTest(TestName);
|
||||
FExportTempDir:=IncludeTrailingPathDelimiter(ExpandFileName(''))+'exporttests'+PathDelim; //Store output in subdirectory
|
||||
ForceDirectories(FExportTempDir);
|
||||
FKeepFilesAfterTest:=true; //keep test files; consistent with other units right now
|
||||
// FKeepFilesAfterTest:=true; //keep test files; consistent with other units right now
|
||||
end;
|
||||
|
||||
procedure TTestDBExport.TearDown;
|
||||
@ -630,6 +631,125 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
Const
|
||||
// UTF8 code page assumed !
|
||||
WidestringLine1 = '这是一个测验';
|
||||
WidestringLine2 = 'Это тест.';
|
||||
WidestringLine3 = 'ça roule.';
|
||||
WidestringResLine1 = '这是一';
|
||||
WidestringResLine2 = 'Это';
|
||||
WidestringResLine3 = 'ça ';
|
||||
|
||||
Function TTestDBExport.GetWideStringDS : TBufDataset;
|
||||
|
||||
Var
|
||||
DS : TBufDataset;
|
||||
|
||||
begin
|
||||
DS:=TBufDataset.Create(Nil);
|
||||
try
|
||||
DS.FieldDefs.Add('F',ftWideString,10);
|
||||
DS.CreateDataset;
|
||||
DS.Append;
|
||||
DS.Fields[0].AsWideString:=UTF8Decode(WideStringLine1);
|
||||
DS.Post;
|
||||
DS.Append;
|
||||
DS.Fields[0].AsWideString:=UTF8Decode(WideStringLine2);
|
||||
DS.Post;
|
||||
DS.Append;
|
||||
DS.Fields[0].AsWideString:=UTF8Decode(WideStringLine3);
|
||||
DS.Post;
|
||||
DS.First;
|
||||
except
|
||||
DS.Free;
|
||||
Raise;
|
||||
end;
|
||||
Result:=DS;
|
||||
end;
|
||||
|
||||
|
||||
procedure TTestDBExport.TestFixedTextExportUTF8;
|
||||
|
||||
var
|
||||
DS : TBufDataset;
|
||||
Exporter: TFixedLengthExporter;
|
||||
F : text;
|
||||
S : UTF8String;
|
||||
haveFile : Boolean;
|
||||
|
||||
begin
|
||||
haveFile:=False;
|
||||
Exporter:=Nil;
|
||||
DS:=GetWideStringDS;
|
||||
try
|
||||
Exporter := TFixedLengthExporter.Create(nil);
|
||||
Exporter.Dataset:=DS;
|
||||
Exporter.FixedFormatSettings.CharMode:=cmUTF8;
|
||||
Exporter.FileName := FExportTempDir + lowercase(TestName) + '.txt';
|
||||
Exporter.BuildDefaultFieldMap(Exporter.ExportFields);
|
||||
TFixedLengthExportFieldItem(Exporter.ExportFields[0]).Width:=3;
|
||||
AssertEquals('Output count',3,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',UTF8Decode(WideStringResLine1),UTF8Decode(S));
|
||||
Readln(F,S);
|
||||
AssertEquals('Correct second line',UTF8Decode(WideStringResLine2),UTF8Decode(S));
|
||||
Readln(F,S);
|
||||
AssertEquals('Correct second line',UTF8Decode(WideStringResLine3),UTF8Decode(S));
|
||||
finally
|
||||
if HaveFile then
|
||||
closeFile(F);
|
||||
if (FKeepFilesAfterTest = False) then
|
||||
DeleteFile(Exporter.FileName);
|
||||
Exporter.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestDBExport.TestFixedTextExportUTF16;
|
||||
|
||||
var
|
||||
DS : TBufDataset;
|
||||
Exporter: TFixedLengthExporter;
|
||||
F : text;
|
||||
S : UnicodeString;
|
||||
haveFile : Boolean;
|
||||
|
||||
begin
|
||||
haveFile:=False;
|
||||
Exporter:=Nil;
|
||||
DS:=GetWideStringDS;
|
||||
try
|
||||
Exporter := TFixedLengthExporter.Create(nil);
|
||||
Exporter.Dataset:=DS;
|
||||
Exporter.FixedFormatSettings.CharMode:=cmUTF16;
|
||||
Exporter.FileName := FExportTempDir + lowercase(TestName) + '.txt';
|
||||
Exporter.BuildDefaultFieldMap(Exporter.ExportFields);
|
||||
TFixedLengthExportFieldItem(Exporter.ExportFields[0]).Width:=3;
|
||||
AssertEquals('Output count',3,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',UTF8Decode(WideStringResLine1),S);
|
||||
Readln(F,S);
|
||||
AssertEquals('Correct second line',UTF8Decode(WideStringResLine2),S);
|
||||
Readln(F,S);
|
||||
AssertEquals('Correct second line',UTF8Decode(WideStringResLine3),S);
|
||||
finally
|
||||
if HaveFile then
|
||||
closeFile(F);
|
||||
if (FKeepFilesAfterTest = False) then
|
||||
DeleteFile(Exporter.FileName);
|
||||
Exporter.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestDBExport.TestJSONExport;
|
||||
var
|
||||
Exporter: TSimpleJSONExporter;
|
||||
|
Loading…
Reference in New Issue
Block a user