summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/test/tobjc22a.pp
blob: 0614733dd2b4ce05a6e913bc79e93c30db3bcb4a (plain)
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
{ %target=darwin }
{ %cpu=powerpc,powerpc64,i386,x86_64,arm }

{ Written by Jonas Maebe in 2009, released into the public domain }

program protocoltest;

{$mode objfpc}{$H+}
{$modeswitch objectivec1}

type
  MyProtocolA = objcprotocol
    function newMethod: longint; message 'n';
  end;

  MyProtocolB = objcprotocol(MyProtocolA)
    class function newClassMethod: longint; message 'newClassMethod';
  end;


  { TMyObject }

  TMyObjectA = objcclass(NSObject, MyProtocolA)
    function newMethod: longint;
  end;

  TMyObjectB = objcclass(NSObject,MyProtocolB)
    function newMethod: longint;
    class function newClassMethod: longint;
  end;

{ TMyObjectA }

function TMyObjectA.newMethod: longint;
begin
  result:=1;
end;

{ TMyObjectB }

function TMyObjectB.newMethod: longint;
begin
  result:=3;
end;

class function TMyObjectB.newClassMethod: longint;
begin
  result:=4;
end;


var
  a   : MyProtocolA;
  b   : MyProtocolB;
begin
  a:=TMyObjectA.alloc.init;
  b:=TMyObjectB.alloc.init;
  if a.newMethod<>1 then
    halt(1);
  if b.newMethod<>3 then
    halt(3);
  if b.newclassmethod<>4 then
    halt(4);
  id(a).release;
  id(b).release;
end.