OSDN Git Service

Added.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc / execute / formal_protocol-2.m
1 /* Contributed by Nicola Pero - Fri Mar  9 21:35:47 CET 2001 */
2 #include <objc/objc.h>
3 #include <objc/Object.h>
4
5 /* Test defining a protocol, a class adopting it, and using an object
6    of type `id <protocol>'. */
7
8 @protocol Enabling
9 - (BOOL) isEnabled;
10 - (void) setEnabled: (BOOL)flag;
11 @end
12
13 @interface Feature : Object <Enabling>
14 {
15   const char *name;
16   BOOL isEnabled;
17 }
18 @end
19
20 @implementation Feature
21 - (BOOL) isEnabled
22 {
23   return isEnabled;
24 }
25 - (void) setEnabled: (BOOL)flag
26 {
27   isEnabled = flag;
28 }
29 @end
30
31 int main (void)
32 {
33   id <Enabling> object;
34
35   object = [Feature new];
36
37   [object setEnabled: YES];
38   if (![object isEnabled])
39     {
40       abort ();
41     }
42
43   return 0;
44 }
45