FpDebug, tests: More tests. Array[Enum] / Array Element access

git-svn-id: trunk@61496 -
This commit is contained in:
martin 2019-06-30 19:16:53 +00:00
parent 7da8446021
commit 553557be16
4 changed files with 144 additions and 11 deletions

View File

@ -449,7 +449,6 @@ procedure TTestWatches.TestWatchesScope;
var
ExeName: String;
dbg: TDebuggerIntf;
t: TWatchExpectationList;
Src: TCommonSource;
begin
@ -461,7 +460,6 @@ begin
TestCompile(Src, ExeName);
AssertTrue('Start debugger', Debugger.StartDebugger(AppDir, ExeName));
dbg := Debugger.LazDebugger;
try
t := TWatchExpectationList.Create(Self);
@ -716,41 +714,54 @@ end;
if not(ALoc in [tlPointer]) then begin
t.add(AName, p+'CharDynArray'+e, weDynArray([] ));
t.add(AName, p+'CharDynArray2'+e, weDynArray(weChar(['N', AChr1, 'M']) )).SkipIf(ALoc = tlConst);
t.AddIndexFromPrevious(['0','1','2'], [0,1,2]);
end;
t.add(AName, p+'CharDynArray3'+e, weDynArray([], 'TCharDynArray'));
t.Add(AName, p+'CharDynArray4'+e, weDynArray(weChar(['J', AChr1, 'M']), 'TCharDynArray')).SkipIf(ALoc = tlConst);
t.AddIndexFromPrevious(['0','1','2'], [0,1,2]);
if not(ALoc in [tlPointer]) then begin
t.Add(AName, p+'WCharDynArray'+e, weDynArray([] ));
t.Add(AName, p+'WCharDynArray2'+e,weDynArray(weChar(['W', AChr1, 'M']) )).SkipIf(ALoc = tlConst);
t.Add(AName, p+'WCharDynArray2'+e,weDynArray(weWideChar(['W', AChr1, 'M']) )).SkipIf(ALoc = tlConst);
t.AddIndexFromPrevious(['0','1','2'], [0,1,2]);
end;
t.Add(AName, p+'WCharDynArray3'+e,weDynArray([] ));
t.Add(AName, p+'WCharDynArray4'+e,weDynArray(weChar(['K', AChr1, 'M']) )).SkipIf(ALoc = tlConst);
t.Add(AName, p+'WCharDynArray4'+e,weDynArray(weWideChar(['K', AChr1, 'M']) )).SkipIf(ALoc = tlConst);
t.AddIndexFromPrevious(['0','1','2'], [0,1,2]);
if not(ALoc in [tlPointer]) then begin
t.add(AName, p+'IntDynArray'+e, weDynArray([] ));
t.add(AName, p+'IntDynArray2'+e, weDynArray(weInteger([11, 30+AOffs, 60]) )).SkipIf(ALoc = tlConst);
t.AddIndexFromPrevious(['0','1','2'], [0,1,2]);
end;
t.add(AName, p+'IntDynArray3'+e, weDynArray([], 'TIntDynArray'));
t.Add(AName, p+'IntDynArray4'+e, weDynArray(weInteger([12, 30+AOffs, 60]), 'TIntDynArray')).SkipIf(ALoc = tlConst);
t.AddIndexFromPrevious(['0','1','2'], [0,1,2]);
t.add(AName, p+'IntDynArray5'+e, weDynArray([], 'TIntDynArray'));
if not(ALoc in [tlPointer]) then begin
t.add(AName, p+'AnsiDynArray'+e, weDynArray([] ));
t.add(AName, p+'AnsiDynArray2'+e, weDynArray(weAnsiStr(['N123', AChr1+'ab', 'M'#9]) )).SkipIf(ALoc = tlConst);
// TODO: currently gets skPointer instead of skAnsiString (dwarf 2)
// t.AddIndexFromPrevious(['0','1','2'], [0,1,2]);
end;
t.add(AName, p+'AnsiDynArray3'+e, weDynArray([], 'TAnsiDynArray'));
t.Add(AName, p+'AnsiDynArray4'+e, weDynArray(weAnsiStr(['J123', AChr1+'ab', 'M'#9]), 'TAnsiDynArray')).SkipIf(ALoc = tlConst);
// TODO: currently gets skPointer instead of skAnsiString (dwarf 2)
// t.AddIndexFromPrevious(['0','1','2'], [0,1,2]);
if not(ALoc in [tlPointer]) then begin
t.add(AName, p+'ShortStrDynArray'+e, weDynArray([] ));
t.add(AName, p+'ShortStrDynArray2'+e, weDynArray(weShortStr(['N123', AChr1+'ac', 'M'#9]) ))
t.add(AName, p+'ShortStrDynArray2'+e, weDynArray(weShortStr(['N123', AChr1+'ac', 'M'#9], 'ShortStr10') ))
.SkipIf(ALoc = tlConst);
t.AddIndexFromPrevious(['0','1','2'], [0,1,2]);
end;
t.add(AName, p+'ShortStrDynArray3'+e, weDynArray([], 'TShortStrDynArray'));
t.Add(AName, p+'ShortStrDynArray4'+e, weDynArray(weShortStr(['J123', AChr1+'ac', 'M'#9]), 'TShortStrDynArray'))
t.Add(AName, p+'ShortStrDynArray4'+e, weDynArray(weShortStr(['J123', AChr1+'ac', 'M'#9], 'ShortStr10'), 'TShortStrDynArray'))
.SkipIf(ALoc = tlConst);
t.AddIndexFromPrevious(['0','1','2'], [0,1,2]);
if not(ALoc in [tlConst]) then begin
t.Add(AName, p+'DynDynArrayInt'+e, weDynArray([
@ -827,6 +838,49 @@ end;
//TODO: element by index
t.Add(AName, p+'ArrayEnum1'+e, weStatArray(weInteger([500+n,701,702,703]) ))
.SkipIf(ALoc = tlParam).SkipIf(ALoc = tlPointer);
t.AddIndexFromPrevious(['EnVal1','EnVal2','EnVal3','EnVal4',
'gvEnum', 'gvEnumA', 'gvEnum1', 'gcEnum', 'gcEnumA', 'gcEnum1', p+'Enum'+e, p+'EnumA'+e, p+'Enum1'+e],
[0,1,2,3, 2,0,1, 2,0,1, 2,0,1]);
t.Add(AName, p+'ArrayEnum3'+e, weStatArray(weInteger([200+n,701,702,703]), 'TArrayEnum'));
t.AddIndexFromPrevious(['EnVal1','EnVal2','EnVal3','EnVal4',
'gvEnum', 'gvEnumA', 'gvEnum1', 'gcEnum', 'gcEnumA', 'gcEnum1', p+'Enum'+e, p+'EnumA'+e, p+'Enum1'+e],
[0,1,2,3, 2,0,1, 2,0,1, 2,0,1]);
t.Add(AName, p+'ArrayEnumSub1'+e, weStatArray(weInteger([600+n,801]) ))
.SkipIf(ALoc = tlParam).SkipIf(ALoc = tlPointer);
t.AddIndexFromPrevious(['EnVal1','EnVal2',
'gvEnumA', 'gvEnum1', 'gcEnumA', 'gcEnum1', p+'EnumA'+e, p+'Enum1'+e],
[0,1, 0,1, 0,1, 0,1]);
t.Add(AName, p+'ArrayEnumSub3'+e, weStatArray(weInteger([100+n,801]), 'TArrayEnumSub'));
t.AddIndexFromPrevious(['EnVal1','EnVal2',
'gvEnumA', 'gvEnum1', 'gcEnumA', 'gcEnum1', p+'EnumA'+e, p+'Enum1'+e],
[0,1, 0,1, 0,1, 0,1]);
t.Add(AName, p+'ArrayEnum2'+e, weStatArray(weInteger([300+n,701,702,703]) ))
.SkipIf(ALoc = tlParam).SkipIf(ALoc = tlPointer);
t.AddIndexFromPrevious(['EnVal1','EnVal2','EnVal3','EnVal4',
'gvEnum', 'gvEnumA', 'gvEnum1', 'gcEnum', 'gcEnumA', 'gcEnum1', p+'Enum'+e, p+'EnumA'+e, p+'Enum1'+e],
[0,1,2,3, 2,0,1, 2,0,1, 2,0,1]);
t.Add(AName, p+'ArrayEnum4'+e, weStatArray(weInteger([800+n,701,702,703]), 'TArrayEnumElem'));
t.AddIndexFromPrevious(['EnVal1','EnVal2','EnVal3','EnVal4',
'gvEnum', 'gvEnumA', 'gvEnum1', 'gcEnum', 'gcEnumA', 'gcEnum1', p+'Enum'+e, p+'EnumA'+e, p+'Enum1'+e],
[0,1,2,3, 2,0,1, 2,0,1, 2,0,1]);
t.Add(AName, p+'ArrayEnumSub2'+e, weStatArray(weInteger([400+n,801]) ))
.SkipIf(ALoc = tlParam).SkipIf(ALoc = tlPointer);
t.AddIndexFromPrevious(['EnVal1','EnVal2',
'gvEnumA', 'gvEnum1', 'gcEnumA', 'gcEnum1', p+'EnumA'+e, p+'Enum1'+e],
[0,1, 0,1, 0,1, 0,1]);
t.Add(AName, p+'ArrayEnumSub4'+e, weStatArray(weInteger([700+n,801]), 'TArrayEnumSubElem'));
t.AddIndexFromPrevious(['EnVal1','EnVal2',
'gvEnumA', 'gvEnum1', 'gcEnumA', 'gcEnum1', p+'EnumA'+e, p+'Enum1'+e],
[0,1, 0,1, 0,1, 0,1]);
t.Add(AName, p+'Enum'+e, weEnum('EnVal3', 'TEnum'));
t.Add(AName, p+'Enum1'+e, weEnum('EnVal2', 'TEnumSub'));
t.Add(AName, p+'Enum2'+e, weEnum('EnVal21', 'TEnum2'));
@ -1396,13 +1450,13 @@ procedure TTestWatches.TestWatchesTypeCast;
e := APostFix;
t2.Clear;
if not(ALoc in [tlConst]) then begin
t2.AddWithoutExpect(AName, p+'Instance1_Int'+e);
t2.AddWithoutExpect(AName, p+'Ansi5_Int'+e);
t2.AddWithoutExpect(AName, p+'IntDynArray4_Int'+e);
t2.EvaluateWatches;
Thread := Debugger.Threads.Threads.CurrentThreadId;
if not(ALoc in [tlConst]) then begin
val := t2.Tests[0]^.TstWatch.Values[Thread, 0].Value;
t.Add(AName+' Int', 'PtrUInt('+p+'Instance1'+e+')', weCardinal(StrToQWordDef(val, qword(-7)), 'PtrUInt', -1));
t.Add(AName+' TClass1', 'TClass1('+p+'Instance1_Int'+e+')', weMatch('FAnsi *=[ $0-9A-F()]*'''+AChr1+'T', skClass));
@ -1425,8 +1479,8 @@ if not(Compiler.SymbolType in stDwarf3Up) then begin
t.Add(AName, 'TIntDynArray('+p+'IntDynArray4_Int'+e+')', weDynArray(weInteger([12, 30+AOffs, 60]), 'TIntDynArray'));
t.Add(AName, 'TIntDynArray('+val+')', weDynArray(weInteger([12, 30+AOffs, 60]), 'TIntDynArray'));
end;
end;
end;
t.Add(AName+' Cardinal', 'Cardinal('+p+'Rec3S'+e+')', weMatch('.', skSimple)).ExpectError();
t.Add(AName+' QWord', 'QWord('+p+'Rec3S'+e+')', weMatch('.', skSimple)).ExpectError();

View File

@ -98,6 +98,11 @@ type
TEnum2 = (EnVal21= 3, EnVal22=4, EnVal23=7, EnVal24=10, EnVal25=30);
TSet = set of TEnum;
TArrayEnum = array [TEnum] of word;
TArrayEnumSub = array [TEnumSub] of word;
TArrayEnumElem = array [EnVal1..EnVal4] of word;
TArrayEnumSubElem = array [EnVal1..EnVal2] of word;
type
(* LOCATION: field in baseclass *)
TMyBaseClass = class

View File

@ -261,7 +261,7 @@
// **** Static ARRAY ****
{$IFnDEF TestParam}
{$IFnDEF TestArg}
{$IFnDEF TestPointer}
{$IFnDEF TestPointer}
{$IFnDEF TestAssign}
pre__CharStatArray{e} _O2_ array[1..5] of char _EQ_ (CHR1, 'b',CHR1, 'B','c'); //@@ _pre3_CharStatArray;
pre__WCharStatArray{e} _O2_ array[1..5] of widechar _EQ_ (CHR1, 'b',CHR1, 'B','d'); //@@ _pre3_WCharStatArray;
@ -273,6 +273,11 @@
// pre__FiveStatArrayPack2{e} _O2_ packed array [2..4] of record a:longint; b: byte end _EQ_ ((a:-9;b:44), (a:-8-ADD;b:33), (a:-7;b:22)); //@@ _pre3_FiveStatArrayPack2;
// pre__FivePackStatArray2{e} _O2_ array [2..4] of packed record a:longint; b: byte end _EQ_ ((a:-9;b:44), (a:-8-ADD;b:33), (a:-7;b:22)); //@@ _pre3_FivePackStatArray2;
// pre__FivePackStatArrayPack2{e} _O2_ packed array [2..4] of packed record a:longint; b: byte end _EQ_ ((a:-9;b:44), (a:-8-ADD;b:33), (a:-7;b:22)); //@@ _pre3_FivePackStatArrayPack2;
pre__ArrayEnum1{e} _O2_ array [TEnum] of word _EQ_ (500+ADD,701,702,703); //@@ _pre3_ArrayEnum1;
pre__ArrayEnumSub1{e} _O2_ array [TEnumSub] of word _EQ_ (600+ADD,801); //@@ _pre3_ArrayEnumSub1;
pre__ArrayEnum2{e} _O2_ array [EnVal1..EnVal4] of word _EQ_ (300+ADD,701,702,703); //@@ _pre3_ArrayEnum2;
pre__ArrayEnumSub2{e} _O2_ array [EnVal1..EnVal2] of word _EQ_ (400+ADD,801); //@@ _pre3_ArrayEnumSub2;
{$ELSE}
pre__CharStatArray{e} := _pre2_CharStatArray; pre__CharStatArray{e}[1] := CHR1; pre__CharStatArray{e}[3] := CHR1; //@@ _pre3_CharStatArray; // }}}
pre__WCharStatArray{e} := _pre2_WCharStatArray; pre__WCharStatArray{e}[1] := CHR1; pre__WCharStatArray{e}[3] := CHR1; //@@ _pre3_WCharStatArray; // }}}
@ -284,8 +289,13 @@
// pre__FiveStatArrayPack2{e} := _pre2_FiveStatArrayPack2; pre__FiveStatArrayPack2{e} [3].a := -8-ADD; //@@ _pre3_FiveStatArrayPack2;
// pre__FivePackStatArray2{e} := _pre2_FivePackStatArray2; pre__FivePackStatArray2{e} [3].a := -8-ADD; //@@ _pre3_FivePackStatArray2;
// pre__FivePackStatArrayPack2{e} := _pre2_FivePackStatArrayPack2; pre__FivePackStatArrayPack2{e}[3].a := -8-ADD; //@@ _pre3_FivePackStatArrayPack2;
pre__ArrayEnum1{e} := _pre2_ArrayEnum1; pre__ArrayEnum1{e}[EnVal1] := 500+ADD; //@@ _pre3_ArrayEnum1; // }}
pre__ArrayEnumSub1{e} := _pre2_ArrayEnumSub1; pre__ArrayEnumSub1{e}[EnVal1] := 600+ADD; //@@ _pre3_ArrayEnumSub1; // }}
pre__ArrayEnum2{e} := _pre2_ArrayEnum2; pre__ArrayEnum2{e}[EnVal1] := 300+ADD; //@@ _pre3_ArrayEnum2; // }}
pre__ArrayEnumSub2{e} := _pre2_ArrayEnumSub2; pre__ArrayEnumSub2{e}[EnVal1] := 400+ADD; //@@ _pre3_ArrayEnumSub2; // }}
{$ENDIF}
{$ENDIF} // TestPointer
{$ENDIF} // TestPointer
{$ENDIF}
{$ENDIF}
@ -304,6 +314,11 @@
pre__RecFiveStatPackArray{e} _O2_ TRecFiveStatPackArray _EQ_ ((a:-9;b:44), (a:-8-ADD;b:33), (a:-7;b:22)); //@@ _pre3_RecFiveStatPackArray; // }}}
pre__RecFivePackStatArray{e} _O2_ TRecFivePackStatArray _EQ_ ((a:-9;b:44), (a:-8-ADD;b:33), (a:-7;b:22)); //@@ _pre3_RecFivePackStatArray; // }}}
pre__RecFivePackStatPackArray{e} _O2_ TRecFivePackStatPackArray _EQ_ ((a:-9;b:44), (a:-8-ADD;b:33), (a:-7;b:22)); //@@ _pre3_RecFivePackStatPackArray; // }}}
pre__ArrayEnum3{e} _O2_ TArrayEnum _EQ_ (200+ADD,701,702,703); //@@ _pre3_ArrayEnum3;
pre__ArrayEnumSub3{e} _O2_ TArrayEnumSub _EQ_ (100+ADD,801); //@@ _pre3_ArrayEnumSub3;
pre__ArrayEnum4{e} _O2_ TArrayEnumElem _EQ_ (800+ADD,701,702,703); //@@ _pre3_ArrayEnum4;
pre__ArrayEnumSub4{e} _O2_ TArrayEnumSubElem _EQ_ (700+ADD,801); //@@ _pre3_ArrayEnumSub4;
{$ELSE}
pre__CharStatArray2{e} := _pre2_CharStatArray2; pre__CharStatArray2{e}[1] := CHR1; pre__CharStatArray2{e}[3] := CHR1; //@@ _pre3_CharStatArray2; // }}}
pre__WCharStatArray2{e} := _pre2_WCharStatArray2; pre__WCharStatArray2{e}[1] := CHR1; pre__WCharStatArray2{e}[3] := CHR1; //@@ _pre3_WCharStatArray2; // }}}
@ -319,9 +334,15 @@
pre__RecFiveStatPackArray{e} := _pre2_RecFiveStatPackArray; pre__RecFiveStatPackArray{e} [3].a := -8-ADD; //@@ _pre3_RecFiveStatPackArray; // }}}
pre__RecFivePackStatArray{e} := _pre2_RecFivePackStatArray; pre__RecFivePackStatArray{e} [3].a := -8-ADD; //@@ _pre3_RecFivePackStatArray; // }}}
pre__RecFivePackStatPackArray{e} := _pre2_RecFivePackStatPackArray; pre__RecFivePackStatPackArray{e}[3].a := -8-ADD; //@@ _pre3_RecFivePackStatPackArray; // }}}
pre__ArrayEnum3{e} := _pre2_ArrayEnum3; pre__ArrayEnum3{e}[EnVal1] := 200+ADD; //@@ _pre3_ArrayEnum3; // }}
pre__ArrayEnumSub3{e} := _pre2_ArrayEnumSub3; pre__ArrayEnumSub3{e}[EnVal1] := 100+ADD; //@@ _pre3_ArrayEnumSub3; // }}
pre__ArrayEnum4{e} := _pre2_ArrayEnum4; pre__ArrayEnum4{e}[EnVal1] := 800+ADD; //@@ _pre3_ArrayEnum4; // }}
pre__ArrayEnumSub4{e} := _pre2_ArrayEnumSub4; pre__ArrayEnumSub4{e}[EnVal1] := 700+ADD; //@@ _pre3_ArrayEnumSub4; // }}
{$ENDIF}
pre__Enum{e} _OP_ TEnum(EnVal3); //@@ _pre3_Enum;
pre__EnumA{e} _OP_ TEnum(EnVal1); //@@ _pre3_EnumA;
pre__Enum1{e} _OP_ TEnumSub(EnVal2); //@@ _pre3_Enum1; // subset;
pre__Enum2{e} _OP_ TEnum2(EnVal21); //@@ _pre3_Enum2;
pre__Enum3{e} _OP_ TEnum2(EnVal25); //@@ _pre3_Enum3;
@ -350,6 +371,8 @@
{$ENDIF}
// array dyn/stat / nested of record/class/char/num ... bitpacked
// record
// object

View File

@ -79,6 +79,9 @@ type
function NotImplemented(ASymTypes: TSymbolTypes = []): TWatchExpectationResult;
function NotImplementedData(ASymTypes: TSymbolTypes = []): TWatchExpectationResult;
procedure MakeCopy;
case ExpResultKind: TWatchExpectationResultKind of
rkMatch: ();
rkInteger: (
@ -239,6 +242,10 @@ type
AStackFrame: Integer = 0; AMinFpc: Integer = 0; AMinDbg: Integer = 0
): PWatchExpectation;
procedure AddIndexFromPrevious(IndexNames: array of string;
ValueIndex: array of integer; AnPreviousOffset: Integer = 0);
procedure Clear;
function Count: Integer;
procedure EvaluateWatches;
@ -278,6 +285,7 @@ function weDynArray(const AExpVal: Array of TWatchExpectationResult; AExpFullLen
// common arrays: weTttArray(weChar([...]))
function weChar(const AExpVal: array of char; ATypeName: String=#1): TWatchExpectationResultArray;
function weWideChar(const AExpVal: array of char; ATypeName: String=#1): TWatchExpectationResultArray;
function weInteger(const AExpVal: array of Int64; ATypeName: String=#1; ASize: Integer = 4): TWatchExpectationResultArray;
function weAnsiStr(const AExpVal: array of string; ATypeName: String=#1): TWatchExpectationResultArray;
function weShortStr(const AExpVal: array of string; ATypeName: String=#1): TWatchExpectationResultArray;
@ -543,6 +551,16 @@ begin
Result[i] := weChar(AExpVal[i], ATypeName);
end;
function weWideChar(const AExpVal: array of char; ATypeName: String
): TWatchExpectationResultArray;
var
i: Integer;
begin
SetLength(Result, Length(AExpVal));
for i := 0 to Length(AExpVal) - 1 do
Result[i] := weWideChar(AExpVal[i], ATypeName);
end;
function weInteger(const AExpVal: array of Int64; ATypeName: String;
ASize: Integer): TWatchExpectationResultArray;
var
@ -695,6 +713,16 @@ begin
Result := Self.AddFlag(ehNotImplementedData, ASymTypes);
end;
procedure TWatchExpectationResult.MakeCopy;
var
i: Integer;
begin
ExpSubResults := copy(ExpSubResults, low(ExpSubResults), high(ExpSubResults));
ExpSetData := copy(ExpSetData, low(ExpSetData), high(ExpSetData));
for i := low(ExpSubResults) to high(ExpSubResults) do
ExpSubResults[i].MakeCopy;
end;
{ TWatchExpectationHelper }
function TWatchExpectationHelper.AddFlag(AFlag: TWatchExpErrorHandlingFlag;
@ -1532,6 +1560,29 @@ begin
Result := Add('', AnExpr, AnExpect, AStackFrame, AMinFpc, AMinDbg);
end;
procedure TWatchExpectationList.AddIndexFromPrevious(
IndexNames: array of string; ValueIndex: array of integer;
AnPreviousOffset: Integer);
var
prev: TWatchExpectation;
i: Integer;
t: PWatchExpectation;
st: TSymbolType;
begin
prev := FList[Count-1-AnPreviousOffset];
for i := 0 to high(IndexNames) do begin
t := Add(Prev.TstTestName + ' ['+IndexNames[i]+']',
prev.TstWatch.Expression+ '['+IndexNames[i]+']',
prev.TstExpected.ExpSubResults[ValueIndex[i]],
prev.TstStackFrame, prev.TstMinFpc, prev.TstMinDbg
);
t^.TstExpected.MakeCopy;
// copy flags from expectation for whole array
for st := low(TSymbolTypes) to high(TSymbolTypes) do
t^.AddFlag(prev.TstExpected.ExpErrorHandlingFlags[st], [st]);
end;
end;
procedure TWatchExpectationList.AddTypeNameAlias(ATypeName, AnAliases: String);
begin
ATypeName := UpperCase(ATypeName);