mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-13 12:59:19 +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;
|
uses sysutils;
|
||||||
|
|
||||||
procedure Foo;
|
procedure Foo(
|
||||||
|
ArgAnsiString1: AnsiString; var ArgAnsiString2: AnsiString; const ArgAnsiString3: AnsiString;
|
||||||
|
ArgChar1: Char; var ArgChar2: Char; const ArgChar3: Char
|
||||||
|
);
|
||||||
var
|
var
|
||||||
TestInt: Integer;
|
TestInt: Integer;
|
||||||
TesTShortString: String[10];
|
TesTShortString: String[10];
|
||||||
@ -13,18 +16,25 @@ var
|
|||||||
function SubFoo(var AVal1: Integer; AVal2: Integer) : Integer;
|
function SubFoo(var AVal1: Integer; AVal2: Integer) : Integer;
|
||||||
begin
|
begin
|
||||||
AVal1 := 2 * AVal2;
|
AVal1 := 2 * AVal2;
|
||||||
inc(AVal2);
|
Result := AVal2;
|
||||||
|
inc(AVal2); // First BreakBoint
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
TestInt := 3;
|
TestInt := 3;
|
||||||
TesTShortString := IntToStr(TestInt);
|
TesTShortString := IntToStr(TestInt) + ':';
|
||||||
TestAnsiString := TesTShortString + ' Foo';
|
TestAnsiString := TesTShortString + ' Foo';
|
||||||
TestPChar := @TestAnsiString[2];
|
TestPChar := @TestAnsiString[2];
|
||||||
SubFoo(TestInt, 5);
|
SubFoo(TestInt, 5);
|
||||||
writeln(TestPChar);
|
writeln(TestPChar);
|
||||||
|
writeln(ArgAnsiString1, ArgAnsiString2, ArgAnsiString3, ArgChar1, ArgChar2, ArgChar3); // breakpoint 2
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
a2: ansistring;
|
||||||
|
c2: Char;
|
||||||
begin
|
begin
|
||||||
Foo
|
a2 := 'def';
|
||||||
|
c2 := 'Y';
|
||||||
|
Foo('abc', a2, 'ghi', 'X', c2, 'Z');
|
||||||
end.
|
end.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
unit Testwatches;
|
unit TestWatches;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
@ -33,7 +33,24 @@ type
|
|||||||
TTestWatches = class(TGDBTestCase)
|
TTestWatches = class(TGDBTestCase)
|
||||||
private
|
private
|
||||||
FWatches: TBaseWatches;
|
FWatches: TBaseWatches;
|
||||||
|
|
||||||
|
FAVal1Watch: TTestWatch;
|
||||||
|
FAVal2Watch: TTestWatch;
|
||||||
|
|
||||||
FTestIntWatch: 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
|
published
|
||||||
procedure TestWatches;
|
procedure TestWatches;
|
||||||
end;
|
end;
|
||||||
@ -63,7 +80,38 @@ end;
|
|||||||
|
|
||||||
{ TTestWatches }
|
{ 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;
|
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
|
var
|
||||||
TestExeName: string;
|
TestExeName: string;
|
||||||
dbg: TGDBMIDebugger;
|
dbg: TGDBMIDebugger;
|
||||||
@ -75,12 +123,29 @@ begin
|
|||||||
FWatches := TBaseWatches.Create(TBaseWatch);
|
FWatches := TBaseWatches.Create(TBaseWatch);
|
||||||
dbg := TGDBMIDebugger.Create(DebuggerInfo.ExeName);
|
dbg := TGDBMIDebugger.Create(DebuggerInfo.ExeName);
|
||||||
//dbg.OnBreakPointHit := @DebuggerBreakPointHit;
|
//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;
|
InitialEnabled := True;
|
||||||
Enabled := True;
|
Enabled := True;
|
||||||
end;
|
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;
|
dbg.Init;
|
||||||
if dbg.State = dsError then
|
if dbg.State = dsError then
|
||||||
@ -93,19 +158,35 @@ begin
|
|||||||
|
|
||||||
dbg.Run;
|
dbg.Run;
|
||||||
// hit breakpoint
|
// hit breakpoint
|
||||||
FTestIntWatch.Master.Value; // trigger read
|
//TestWatch('AVal1', FAVal1Watch, '10');
|
||||||
AssertTrue ('TestInt (HasValue)', FTestIntWatch.HasValue);
|
TestWatch('AVal2', FAVal2Watch, '5');
|
||||||
AssertFalse ('TestInt (One Value)', FTestIntWatch.HasMultiValue);
|
|
||||||
AssertEquals('TestInt (Value)', FTestIntWatch.Value, '10');
|
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;
|
dbg.Stop;
|
||||||
finally
|
finally
|
||||||
dbg.Free;
|
dbg.Free;
|
||||||
//FreeAndNil(FTestIntWatch);
|
|
||||||
FreeAndNil(FWatches);
|
FreeAndNil(FWatches);
|
||||||
end;
|
|
||||||
|
|
||||||
|
//debugln(FailText)
|
||||||
|
if FailText <> '' then fail(FailText);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user