mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-03 21:00:30 +02:00
DBG: More tests
git-svn-id: trunk@28656 -
This commit is contained in:
parent
338a45d9e6
commit
9505743f20
@ -3,7 +3,10 @@ program WatchesPrg;
|
||||
|
||||
uses sysutils;
|
||||
|
||||
procedure Foo;
|
||||
procedure Foo(
|
||||
ArgAnsiString1: AnsiString; var ArgAnsiString2: AnsiString; const ArgAnsiString3: AnsiString;
|
||||
ArgChar1: Char; var ArgChar2: Char; const ArgChar3: Char
|
||||
);
|
||||
var
|
||||
TestInt: Integer;
|
||||
TesTShortString: String[10];
|
||||
@ -13,18 +16,25 @@ var
|
||||
function SubFoo(var AVal1: Integer; AVal2: Integer) : Integer;
|
||||
begin
|
||||
AVal1 := 2 * AVal2;
|
||||
inc(AVal2);
|
||||
Result := AVal2;
|
||||
inc(AVal2); // First BreakBoint
|
||||
end;
|
||||
|
||||
begin
|
||||
TestInt := 3;
|
||||
TesTShortString := IntToStr(TestInt);
|
||||
TesTShortString := IntToStr(TestInt) + ':';
|
||||
TestAnsiString := TesTShortString + ' Foo';
|
||||
TestPChar := @TestAnsiString[2];
|
||||
SubFoo(TestInt, 5);
|
||||
writeln(TestPChar);
|
||||
writeln(ArgAnsiString1, ArgAnsiString2, ArgAnsiString3, ArgChar1, ArgChar2, ArgChar3); // breakpoint 2
|
||||
end;
|
||||
|
||||
var
|
||||
a2: ansistring;
|
||||
c2: Char;
|
||||
begin
|
||||
Foo
|
||||
a2 := 'def';
|
||||
c2 := 'Y';
|
||||
Foo('abc', a2, 'ghi', 'X', c2, 'Z');
|
||||
end.
|
||||
|
@ -1,4 +1,4 @@
|
||||
unit Testwatches;
|
||||
unit TestWatches;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
@ -33,7 +33,24 @@ type
|
||||
TTestWatches = class(TGDBTestCase)
|
||||
private
|
||||
FWatches: TBaseWatches;
|
||||
|
||||
FAVal1Watch: TTestWatch;
|
||||
FAVal2Watch: TTestWatch;
|
||||
|
||||
FTestIntWatch: TTestWatch;
|
||||
FTestShortStringWatch: TTestWatch;
|
||||
FTestAnsiStringWatch: TTestWatch;
|
||||
FTestPCharWatch: TTestWatch;
|
||||
|
||||
FArgAnsisString1: TTestWatch;
|
||||
FArgAnsisString2: TTestWatch;
|
||||
FArgAnsisString3: TTestWatch;
|
||||
FArgChar1: TTestWatch;
|
||||
FArgChar2: TTestWatch;
|
||||
FArgChar3: TTestWatch;
|
||||
public
|
||||
procedure DebugInteract(dbg: TGDBMIDebugger);
|
||||
|
||||
published
|
||||
procedure TestWatches;
|
||||
end;
|
||||
@ -63,7 +80,38 @@ end;
|
||||
|
||||
{ TTestWatches }
|
||||
|
||||
procedure TTestWatches.DebugInteract(dbg: TGDBMIDebugger);
|
||||
var s: string;
|
||||
begin
|
||||
readln(s);
|
||||
while s <> '' do begin
|
||||
dbg.TestCmd(s);
|
||||
readln(s);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestWatches.TestWatches;
|
||||
var FailText: String;
|
||||
procedure TestWatch(Name: String; AWatch: TTestWatch; Exp: String; StripQuotes: Boolean = False);
|
||||
var
|
||||
s: String;
|
||||
begin
|
||||
try
|
||||
AWatch.Master.Value; // trigger read
|
||||
AssertTrue (Name+ ' (HasValue)', AWatch.HasValue);
|
||||
AssertFalse (Name+ ' (One Value)', AWatch.HasMultiValue);
|
||||
s := AWatch.Value;
|
||||
if StripQuotes and (length(s) > 1) and
|
||||
(s[1] = '''') and (s[length(s)] = '''')
|
||||
then
|
||||
s := copy(s, 2, length(s)-2);
|
||||
AssertEquals(Name+ ' (Value)', Exp, s);
|
||||
except
|
||||
on e: Exception do
|
||||
FailText := FailText + e.Message + LineEnding;
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
TestExeName: string;
|
||||
dbg: TGDBMIDebugger;
|
||||
@ -75,12 +123,29 @@ begin
|
||||
FWatches := TBaseWatches.Create(TBaseWatch);
|
||||
dbg := TGDBMIDebugger.Create(DebuggerInfo.ExeName);
|
||||
//dbg.OnBreakPointHit := @DebuggerBreakPointHit;
|
||||
with dbg.BreakPoints.Add('WatchesPrg.pas', 16) do begin
|
||||
with dbg.BreakPoints.Add('WatchesPrg.pas', 20) do begin
|
||||
InitialEnabled := True;
|
||||
Enabled := True;
|
||||
end;
|
||||
with dbg.BreakPoints.Add('WatchesPrg.pas', 30) do begin
|
||||
InitialEnabled := True;
|
||||
Enabled := True;
|
||||
end;
|
||||
|
||||
FTestIntWatch := TTestWatch.Create(FWatches, dbg.Watches.Add('TestInt'));
|
||||
FAVal1Watch := TTestWatch.Create(FWatches, dbg.Watches.Add('AVal1'));
|
||||
FAVal2Watch := TTestWatch.Create(FWatches, dbg.Watches.Add('AVal2'));
|
||||
|
||||
FTestIntWatch := TTestWatch.Create(FWatches, dbg.Watches.Add('TestInt'));
|
||||
FTestShortStringWatch := TTestWatch.Create(FWatches, dbg.Watches.Add('TestShortString'));
|
||||
FTestAnsiStringWatch := TTestWatch.Create(FWatches, dbg.Watches.Add('TestAnsiString'));
|
||||
FTestPCharWatch := TTestWatch.Create(FWatches, dbg.Watches.Add('TestPChar'));
|
||||
|
||||
FArgAnsisString1 := TTestWatch.Create(FWatches, dbg.Watches.Add('ArgAnsiString1'));
|
||||
FArgAnsisString2 := TTestWatch.Create(FWatches, dbg.Watches.Add('ArgAnsiString2'));
|
||||
FArgAnsisString3 := TTestWatch.Create(FWatches, dbg.Watches.Add('ArgAnsiString3'));
|
||||
FArgChar1 := TTestWatch.Create(FWatches, dbg.Watches.Add('ArgChar1'));
|
||||
FArgChar2 := TTestWatch.Create(FWatches, dbg.Watches.Add('ArgChar2'));
|
||||
FArgChar3 := TTestWatch.Create(FWatches, dbg.Watches.Add('ArgChar3'));
|
||||
|
||||
dbg.Init;
|
||||
if dbg.State = dsError then
|
||||
@ -93,19 +158,35 @@ begin
|
||||
|
||||
dbg.Run;
|
||||
// hit breakpoint
|
||||
FTestIntWatch.Master.Value; // trigger read
|
||||
AssertTrue ('TestInt (HasValue)', FTestIntWatch.HasValue);
|
||||
AssertFalse ('TestInt (One Value)', FTestIntWatch.HasMultiValue);
|
||||
AssertEquals('TestInt (Value)', FTestIntWatch.Value, '10');
|
||||
//TestWatch('AVal1', FAVal1Watch, '10');
|
||||
TestWatch('AVal2', FAVal2Watch, '5');
|
||||
|
||||
TestWatch('TestInt', FTestIntWatch, '10');
|
||||
//TestWatch('TestShortString', FTestShortStringWatch, '3:', True);
|
||||
TestWatch('TestAnsiString', FTestAnsiStringWatch, '3: Foo', True);
|
||||
TestWatch('TestPChar', FTestPCharWatch, ': Foo', True);
|
||||
|
||||
dbg.Run;
|
||||
// 2nd breakpoint
|
||||
TestWatch('ArgAnsiString1', FArgAnsisString1, 'abc', True);
|
||||
//TestWatch('ArgAnsiString2', FArgAnsisString2, 'def', True);
|
||||
TestWatch('ArgAnsiString3', FArgAnsisString3, 'ghi', True);
|
||||
|
||||
TestWatch('ArgChar1', FArgChar1, '88 ''X''');
|
||||
//TestWatch('ArgChar2', FArgChar2, '89 ''Y''');
|
||||
TestWatch('ArgChar3', FArgChar3, '90 ''Z''');
|
||||
|
||||
//DebugInteract(dbg);
|
||||
|
||||
|
||||
dbg.Stop;
|
||||
finally
|
||||
dbg.Free;
|
||||
//FreeAndNil(FTestIntWatch);
|
||||
FreeAndNil(FWatches);
|
||||
end;
|
||||
|
||||
//debugln(FailText)
|
||||
if FailText <> '' then fail(FailText);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user