tests: fixed hints on fpc 3.1.1

git-svn-id: trunk@50159 -
This commit is contained in:
mattias 2015-10-24 21:47:10 +00:00
parent 43a2597cc9
commit d75c8aba79
7 changed files with 72 additions and 36 deletions

View File

@ -14,7 +14,7 @@ unit TestFileProc;
interface
uses
Classes, SysUtils, fpcunit, testglobals, LazFileUtils, FileProcs;
Classes, SysUtils, fpcunit, testglobals, LazFileUtils, LazUTF8;
type

View File

@ -11,6 +11,7 @@
./runtests --format=plain --suite=TestSimpleFormat
./runtests --format=plain --suite=TestDateToCfgStr
./runtests --format=plain --suite=TestFilenameIsMatching
./runtests --format=plain --suite=TestExtractFileUnitname
./runtests --format=plain --suite=TestChangeLineEndings
}
unit TestBasicCodetools;
@ -40,6 +41,7 @@ type
// FileProcs
procedure TestDateToCfgStr;
procedure TestFilenameIsMatching;
procedure TestExtractFileUnitname;
// SourceLog
procedure TestChangeLineEndings;
end;
@ -374,6 +376,28 @@ begin
t('*.{p{as,p,},inc}','c.lfm',true,false);
end;
procedure TTestBasicCodeTools.TestExtractFileUnitname;
procedure t(Filename: string; WithNameSpace: boolean; Expected: string);
begin
AssertEquals('ExtractFileUnitname('''+Filename+''')',Expected,ExtractFileUnitname(Filename,WithNameSpace));
end;
begin
t('a.pas',true,'a');
t('a.pp',true,'a');
t('a.p',true,'a');
t('ab.pas',true,'ab');
t('a.pas',false,'a');
t('ab.pas',false,'ab');
t('a.b.pas',true,'a.b');
t('a.b.pas',false,'b');
t('ab.c.pas',true,'ab.c');
t('ab.c.pas',false,'c');
t('ab.c.d.pas',true,'ab.c.d');
t('ab.c.d.pas',false,'d');
end;
procedure TTestBasicCodeTools.TestChangeLineEndings;
procedure t(s, NewLineEnding, Expected: string);

View File

@ -12,7 +12,8 @@ unit TestLConvEncoding;
interface
uses
Classes, SysUtils, fpcunit, LConvEncoding, LazLogger, testglobals, LazUTF8;
Classes, SysUtils, fpcunit, LConvEncoding, LazLogger, testglobals, FileProcs,
LazUTF8;
type
@ -30,40 +31,41 @@ implementation
procedure TTestLConvEncoding.Test_CP_UTF8_CP;
procedure Test(CodePageName: string; const CP2UTF8,UTF82CP: TConvertEncodingFunction);
procedure Test(CodePageName: string);
var
c: Char;
AsUTF8, Back: string;
l: integer;
Encoded: boolean;
begin
for c:=#1 to High(Char) do begin
AsUTF8:=CP2UTF8(c);
AsUTF8:=ConvertEncodingToUTF8(c,CodePageName,Encoded);
if AsUTF8='' then
AssertEquals('CodePage '+CodePageName+' to UTF8 creates empty string for character #'+IntToStr(ord(c)),true,false);
Back:=UTF82CP(AsUTF8);
Back:=ConvertEncodingFromUTF8(AsUTF8,CodePageName,Encoded);
if Back<>c then
AssertEquals('CodePage '+CodePageName+' ('+IntToStr(ord(c))+') to UTF8 ('+dbgs(UTF8CharacterToUnicode(PChar(AsUTF8),l))+') and back differ for character #'+IntToStr(ord(c)),DbgStr(c),dbgstr(Back));
end;
end;
begin
Test('ISO_8859_1',@ISO_8859_1ToUTF8,@UTF8ToISO_8859_1);
Test('ISO_8859_2',@ISO_8859_2ToUTF8,@UTF8ToISO_8859_2);
Test('ISO_8859_15',@ISO_8859_15ToUTF8,@UTF8ToISO_8859_15);
Test('437',@CP437ToUTF8,@UTF8ToCP437);
Test('850',@CP850ToUTF8,@UTF8ToCP850);
Test('852',@CP852ToUTF8,@UTF8ToCP852);
Test('866',@CP866ToUTF8,@UTF8ToCP866);
Test('874',@CP874ToUTF8,@UTF8ToCP874);
Test('1250',@CP1250ToUTF8,@UTF8ToCP1250);
Test('1251',@CP1251ToUTF8,@UTF8ToCP1251);
Test('1252',@CP1252ToUTF8,@UTF8ToCP1252);
Test('1253',@CP1253ToUTF8,@UTF8ToCP1253);
Test('1254',@CP1254ToUTF8,@UTF8ToCP1254);
Test('1255',@CP1255ToUTF8,@UTF8ToCP1255);
Test('1256',@CP1256ToUTF8,@UTF8ToCP1256);
Test('1257',@CP1257ToUTF8,@UTF8ToCP1257);
Test('1258',@CP1258ToUTF8,@UTF8ToCP1258);
Test(EncodingCPIso1);
Test(EncodingCPIso2);
Test(EncodingCPIso15);
Test(EncodingCP437);
Test(EncodingCP850);
Test(EncodingCP852);
Test(EncodingCP866);
Test(EncodingCP874);
Test(EncodingCP1250);
Test(EncodingCP1251);
Test(EncodingCP1252);
Test(EncodingCP1253);
Test(EncodingCP1254);
Test(EncodingCP1255);
Test(EncodingCP1256);
Test(EncodingCP1257);
Test(EncodingCP1258);
end;
initialization

View File

@ -44,7 +44,7 @@ begin
R := UTF8ToUTF16(SUTF8);
AssertEquals('UTF8ToUTF16 of unicode char: ' + IntToHex(U, 6) + ' error! ' + DbgWideStr(SUTF16) + ' ' + DbgWideStr(R),
SUTF16, R);
UTF8Encode(SUTF16), UTF8Encode(R));
end;
for I1 := 0 to High(Limits) do // test two char string with limit char values
@ -60,7 +60,7 @@ begin
AssertEquals('UTF8ToUTF16 of two unicode chars: ' +
IntToHex(Limits[I1], 6) + IntToHex(Limits[I2], 6) + ' error!',
SUTF16, R);
UTF8Encode(SUTF16), UTF8Encode(R));
end;
end;
end;
@ -69,7 +69,7 @@ procedure TTestUnicode.TestUTF16ToUTF8;
var
U: Cardinal;
I1, I2: Integer;
SUTF8, S1UTF8, R: UTF8String;
SUTF8, S1UTF8, R: String;
SUTF16, S1UTF16: WideString;
begin
for U := 0 to $10FFFF do
@ -80,7 +80,7 @@ begin
SUTF16 := UnicodeToUTF16(U);
R := UTF16ToUTF8(SUTF16);
AssertEquals('UTF16ToUTF8 of unicode char: ' + IntToHex(U, 6) + ' error! ' + DbgStr(SUTF16) + ' ' + DbgStr(R),
AssertEquals('UTF16ToUTF8 of unicode char: ' + IntToHex(U, 6) + ' error! "' + DbgStr(PChar(SUTF16),length(SUTF16)*2) + '" "' + DbgStr(R)+'"',
SUTF8, R);
end;
@ -116,14 +116,21 @@ begin
end;
procedure TTestUnicode.TestUnicodeToUTF16;
procedure t(a,b: widestring);
begin
if a=b then exit;
AssertEquals(dbgstr(PChar(a),length(a)*2), dbgstr(PChar(b),length(b)*2));
end;
begin
AssertEquals(#0, UnicodeToUTF16(0));
AssertEquals(#$D7FF, UnicodeToUTF16($D7FF));
AssertEquals(#$E000, UnicodeToUTF16($E000));
AssertEquals(#$FFFF, UnicodeToUTF16($FFFF));
AssertEquals(#$D800#$DC00, UnicodeToUTF16($10000));
AssertEquals(#$D800#$DC01, UnicodeToUTF16($10001));
AssertEquals(#$DBFF#$DFFD, UnicodeToUTF16($10FFFD));
t(widestring(#0), UnicodeToUTF16(0));
t(widestring(#$D7FF), UnicodeToUTF16($D7FF));
t(widestring(#$E000), UnicodeToUTF16($E000));
t(widestring(#$FFFF), UnicodeToUTF16($FFFF));
t(widestring(#$D800#$DC00), UnicodeToUTF16($10000));
t(widestring(#$D800#$DC01), UnicodeToUTF16($10001));
t(widestring(#$DBFF#$DFFD), UnicodeToUTF16($10FFFD));
end;
procedure TTestUnicode.TestUTF8CharacterToUnicode;

View File

@ -90,6 +90,7 @@
<Unit1>
<Filename Value="testlpi.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="TestLpi"/>
</Unit1>
<Unit2>
<Filename Value="bugtestcase.pas"/>
@ -102,6 +103,7 @@
<Unit4>
<Filename Value="lcltests\testunicode.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="TestUnicode"/>
</Unit4>
<Unit5>
<Filename Value="testunits.pas"/>
@ -151,6 +153,7 @@
<Unit16>
<Filename Value="lazutils\testlconvencoding.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="TestLConvEncoding"/>
</Unit16>
</Units>
</ProjectOptions>

View File

@ -82,8 +82,8 @@ var
var
n: TDOMElement;
begin
n := Doc.CreateElement(name);
n.AppendChild(Doc.CreateTextNode(value));
n := Doc.CreateElement(UTF8Decode(name));
n.AppendChild(Doc.CreateTextNode(UTF8Decode(value)));
env.AppendChild(n);
end;
begin

View File

@ -24,7 +24,7 @@ interface
uses
Classes, SysUtils, strutils, fpcunit, testregistry, process, UTF8Process,
InterfaceBase, LazFileUtils, LazUTF8,
InterfaceBase, LazFileUtils, LazUTF8, FileUtil,
TestGlobals;
type