mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-11 17:28:11 +02:00

(since macpas methods may accidentally be called like that as well, as it doesn't have any constructors/destructors) + some tests for MacPas objects from the GNU Pascal testsuite git-svn-id: trunk@5421 -
99 lines
2.6 KiB
ObjectPascal
99 lines
2.6 KiB
ObjectPascal
{ original: peter5b.pas from the GNU Pascal testsuite }
|
|
|
|
{ Mac Pascal objects }
|
|
|
|
{$mode macpas}
|
|
|
|
program peter5b;
|
|
|
|
type
|
|
Str = String[100];
|
|
BaseObject = object
|
|
v1: Str;
|
|
function m1: Str;
|
|
function m2: Str;
|
|
end;
|
|
SuperObject = object(BaseObject)
|
|
v2: Str;
|
|
v3: Str;
|
|
function m1: Str; override;
|
|
function m2: Str; override;
|
|
function m3: Str;
|
|
end;
|
|
|
|
var
|
|
good: Boolean;
|
|
|
|
function BaseObject.m1: Str;
|
|
begin
|
|
return 'BaseObject.' + v1;
|
|
end;
|
|
|
|
function BaseObject.m2: Str;
|
|
begin
|
|
return 'BaseObject.nov2';
|
|
end;
|
|
|
|
function SuperObject.m1: Str;
|
|
begin
|
|
return 'SuperObject.' + (inherited m1) + '.' + v1;
|
|
end;
|
|
|
|
function SuperObject.m2: Str;
|
|
begin
|
|
return 'SuperObject.' + (inherited m2) + '.' + v2;
|
|
end;
|
|
|
|
function SuperObject.m3: Str;
|
|
begin
|
|
return 'SuperObject.' + v3;
|
|
end;
|
|
|
|
procedure CheckEqual( const param, s1, s2: Str );
|
|
begin
|
|
if s1 <> s2 then begin
|
|
good := false;
|
|
WriteLn( 'Failed: ', param, ' = ', s1, ' is not equal to ', s2 );
|
|
end;
|
|
end;
|
|
|
|
var
|
|
base: BaseObject;
|
|
super: SuperObject;
|
|
reallysuper: BaseObject;
|
|
begin
|
|
New(base);
|
|
base.v1 := 'basev1';
|
|
|
|
New(super);
|
|
with super do begin
|
|
v1 := 'superv1';
|
|
v2 := 'superv2';
|
|
v3 := 'superv3';
|
|
end;
|
|
|
|
reallysuper := super; { reference copy only! }
|
|
|
|
good := true;
|
|
|
|
with base do begin
|
|
CheckEqual( 'base.m1', m1, 'BaseObject.basev1' );
|
|
CheckEqual( 'base.m2', m2, 'BaseObject.nov2' );
|
|
end;
|
|
CheckEqual( 'super.m1', super.m1, 'SuperObject.BaseObject.superv1.superv1' );
|
|
CheckEqual( 'super.m2', super.m2, 'SuperObject.BaseObject.nov2.superv2' );
|
|
CheckEqual( 'super.m3', super.m3, 'SuperObject.superv3' );
|
|
|
|
CheckEqual( 'reallysuper.m1', reallysuper.m1, 'SuperObject.BaseObject.superv1.superv1' );
|
|
CheckEqual( 'reallysuper.m2', reallysuper.m2, 'SuperObject.BaseObject.nov2.superv2' );
|
|
|
|
if good then begin
|
|
WriteLn( 'OK' );
|
|
end else begin
|
|
halt(1)
|
|
end;
|
|
|
|
Dispose( base );
|
|
Dispose( super );
|
|
end.
|