Skip to content

Commit b6de97b

Browse files
committed
Further tests for TFormat_XX, TFormat_ESCAPE and TFormat_Radxix64, testing that exceptions are properly raised.
1 parent 61ecc9c commit b6de97b

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Unit Tests/Tests/TestDECFormat.pas

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ TestTFormat_Radix64 = class(TFormatTestsBase)
377377
procedure TearDown; override;
378378

379379
procedure DoSetCharsPerLine0;
380+
procedure DoTestCRCException;
380381
published
381382
procedure TestEncodeBytes;
382383
procedure TestEncodeRawByteString;
@@ -391,6 +392,7 @@ TestTFormat_Radix64 = class(TFormatTestsBase)
391392
procedure TestClassByName;
392393
procedure TestIdentity;
393394
procedure SetCharsPerLine0Exception;
395+
procedure TestCRCException;
394396
end;
395397

396398
// Test methods for class TFormat_UU
@@ -644,6 +646,8 @@ TestTFormat_XX = class(TFormatTestsBase)
644646
public
645647
procedure SetUp; override;
646648
procedure TearDown; override;
649+
private
650+
procedure DoTestDecodeException;
647651
published
648652
procedure TestEncodeBytes;
649653
procedure TestEncodeRawByteString;
@@ -656,6 +660,7 @@ TestTFormat_XX = class(TFormatTestsBase)
656660
procedure TestIsValidRawByteString;
657661
procedure TestClassByName;
658662
procedure TestIdentity;
663+
procedure TestDecodeException;
659664
end;
660665

661666
// Test methods for class TFormat_ESCAPE
@@ -745,6 +750,10 @@ TestTFormat_ESCAPE = class(TFormatTestsBase)
745750
public
746751
procedure SetUp; override;
747752
procedure TearDown; override;
753+
protected
754+
procedure DoTestDecodeExceptionWrongChar;
755+
procedure DoTestDecodeExceptionWrongChar2;
756+
procedure DoTestDecodeExceptionWrongLength;
748757
published
749758
procedure TestEncodeBytes;
750759
procedure TestEncodeRawByteString;
@@ -757,6 +766,7 @@ TestTFormat_ESCAPE = class(TFormatTestsBase)
757766
procedure TestIsValidRawByteString;
758767
procedure TestClassByName;
759768
procedure TestIdentity;
769+
procedure TestDecodeException;
760770
end;
761771

762772
// Test methods for class TFormat_BigEndian16
@@ -1304,6 +1314,11 @@ procedure TestTFormat_Radix64.DoSetCharsPerLine0;
13041314
FFormat_Radix64.SetCharsPerLine(0);
13051315
end;
13061316

1317+
procedure TestTFormat_Radix64.DoTestCRCException;
1318+
begin
1319+
FFormat_Radix64.Decode('VGVzdAoJqlU=' + #13 + #10 +'=XtiN');
1320+
end;
1321+
13071322
procedure TestTFormat_Radix64.SetCharsPerLine0Exception;
13081323
begin
13091324
CheckException(DoSetCharsPerLine0, EArgumentOutOfRangeException);
@@ -1367,6 +1382,11 @@ procedure TestTFormat_Radix64.TestClassByName;
13671382
CheckEquals(TFormat_Radix64, ReturnValue, 'Class is not registered');
13681383
end;
13691384

1385+
procedure TestTFormat_Radix64.TestCRCException;
1386+
begin
1387+
CheckException(DoTestCRCException, EDECFormatException);
1388+
end;
1389+
13701390
procedure TestTFormat_Radix64.TestDecodeBytes;
13711391
begin
13721392
DoTestEncodeDecode(FFormat_Radix64.Decode, cTestDataDecode);
@@ -1662,6 +1682,11 @@ procedure TestTFormat_UU.TestIsValidTypeless;
16621682
end;
16631683
end;
16641684

1685+
procedure TestTFormat_XX.DoTestDecodeException;
1686+
begin
1687+
FFormat_XX.Decode('ä');
1688+
end;
1689+
16651690
procedure TestTFormat_XX.SetUp;
16661691
begin
16671692
FFormat_XX := TFormat_XX.Create;
@@ -1686,6 +1711,11 @@ procedure TestTFormat_XX.TestDecodeBytes;
16861711
DoTestEncodeDecode(FFormat_XX.Decode, cTestDataDecode);
16871712
end;
16881713

1714+
procedure TestTFormat_XX.TestDecodeException;
1715+
begin
1716+
CheckException(DoTestDecodeException, EDECFormatException);
1717+
end;
1718+
16891719
procedure TestTFormat_XX.TestDecodeRawByteString;
16901720
begin
16911721
DoTestEncodeDecodeRawByteString(FFormat_XX.Decode, cTestDataDecode);
@@ -1837,6 +1867,21 @@ procedure TestTFormat_XX.TestIsValidTypeless;
18371867
end;
18381868
end;
18391869

1870+
procedure TestTFormat_ESCAPE.DoTestDecodeExceptionWrongChar;
1871+
begin
1872+
FFormat_ESCAPE.Decode(RawByteString('\xä'));
1873+
end;
1874+
1875+
procedure TestTFormat_ESCAPE.DoTestDecodeExceptionWrongChar2;
1876+
begin
1877+
FFormat_ESCAPE.Decode(RawByteString('\xaä'));
1878+
end;
1879+
1880+
procedure TestTFormat_ESCAPE.DoTestDecodeExceptionWrongLength;
1881+
begin
1882+
FFormat_ESCAPE.Decode(RawByteString('\xaa\x'));
1883+
end;
1884+
18401885
procedure TestTFormat_ESCAPE.SetUp;
18411886
begin
18421887
FFormat_ESCAPE := TFormat_ESCAPE.Create;
@@ -1861,6 +1906,13 @@ procedure TestTFormat_ESCAPE.TestDecodeBytes;
18611906
DoTestEncodeDecode(FFormat_ESCAPE.Decode, cTestDataDecode);
18621907
end;
18631908

1909+
procedure TestTFormat_ESCAPE.TestDecodeException;
1910+
begin
1911+
CheckException(DoTestDecodeExceptionWrongChar, EDECFormatException);
1912+
CheckException(DoTestDecodeExceptionWrongChar2, EDECFormatException);
1913+
CheckException(DoTestDecodeExceptionWrongLength, EDECFormatException);
1914+
end;
1915+
18641916
procedure TestTFormat_ESCAPE.TestDecodeRawByteString;
18651917
begin
18661918
DoTestEncodeDecodeRawByteString(FFormat_ESCAPE.Decode, cTestDataDecode);

0 commit comments

Comments
 (0)