1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
unit bug8432;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, fpcunit, testregistry, testglobals,
maps;
type
{ TTestBug8432 }
TTestBug8432= class(TTestCase)
private
FMap: TMap;
protected
procedure SetUp; override;
procedure TearDown; override;
published
procedure Test_itu4_1;
procedure Test_itu4_2;
procedure Test_itu8_1;
procedure Test_itu8_2;
end;
implementation
procedure TTestBug8432.SetUp;
begin
inherited SetUp;
end;
procedure TTestBug8432.TearDown;
begin
FMap.Free;
inherited TearDown;
end;
procedure TTestBug8432.Test_itu4_1;
var
Key: Integer;
AInt: Integer;
begin
FMap:=TMap.Create(itu4,SizeOf(Integer));
with FMap do
begin
for Key := 1 to 3 do
begin
AInt:=Key* 10;
Add(Key,AInt);
end;
Key := 1;
GetData(Key,AInt);
AssertEquals('Wrong entry for 1', 10, AInt);
Key := 2;
GetData(Key,AInt);
AssertEquals('Wrong entry for 2', 20, AInt);
Key := 3;
GetData(Key,AInt);
AssertEquals('Wrong entry for 3', 30, AInt);
end;
end;
procedure TTestBug8432.Test_itu4_2;
var
i: integer;
AInt: Integer;
ID: DWord;
begin
FMap:=TMap.Create(itu4,SizeOf(Integer));
with FMap do
begin
for i := 0 to 255 do begin
ID := dword(i) shl 24;
AInt:=i;
Add(ID,AInt);
end;
for i := 0 to 255 do begin
AInt:= 0;
ID := dword(i) shl 24;
GetData(ID,AInt);
AssertEquals('Wrong entry for '+ IntToStr(i), i, AInt);
end;
end;
end;
procedure TTestBug8432.Test_itu8_1;
var
AInt: Integer;
ID1, ID2, ID3: QWord;
begin
FMap:=TMap.Create(itu8,SizeOf(Integer));
with FMap do
begin
ID1 := 1; AInt:=10;
Add(ID1,AInt);
ID2 := 2; AInt:=20;
Add(ID2,AInt);
ID3 := 3; AInt:=30;
Add(ID3,AInt);
GetData(ID1,AInt);
AssertEquals('Wrong entry for 1', 10, AInt);
GetData(ID2,AInt);
AssertEquals('Wrong entry for 2', 20, AInt);
GetData(ID3,AInt);
AssertEquals('Wrong entry for 3', 30, AInt);
end;
end;
procedure TTestBug8432.Test_itu8_2;
var
AInt: Integer;
ID1, ID2, ID3: QWord;
begin
FMap:=TMap.Create(itu8,SizeOf(Integer));
with FMap do
begin
ID1 := 1 shl 32; AInt:=10;
Add(ID1, AInt);
AssertEquals('Wrong ID1', $100000000, ID1);
ID2 := 2 shl 32; AInt:=20;
Add(ID2, AInt);
ID3 := 3 shl 32; AInt:=30;
Add(ID3, AInt);
GetData(ID1,AInt);
AssertEquals('Wrong entry for 1', 10, AInt);
GetData(ID2,AInt);
AssertEquals('Wrong entry for 2', 20, AInt);
GetData(ID3,AInt);
AssertEquals('Wrong entry for 3', 30, AInt);
end;
end;
initialization
AddToBugsTestSuite(TTestSuite.Create(TTestBug8432, '8432'));
end.
|