OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [objc/] [execute/] [class-11.m] - Blame information for rev 307

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 307 jeremybenn
/* Contributed by Nicola Pero - Tue Mar  6 23:05:53 CET 2001 */
2
 
3
#include "../../objc-obj-c++-shared/next-mapping.h"
4
#include <objc/objc.h>
5
#include <objc/objc-api.h>
6
 
7
/* Tests creating a root class and a subclass with an ivar and
8
   accessor methods and a subclass overriding the superclass'
9
   implementation and using self to call another method of itself - in
10
   a category */
11
 
12
@interface RootClass
13
{
14
  Class isa;
15
}
16
@end
17
 
18
@implementation RootClass
19
#ifdef __NEXT_RUNTIME__                                   
20
+ initialize { return self; }
21
#endif
22
@end
23
 
24
@interface SubClass : RootClass
25
{
26
  int state;
27
}
28
- (void) setState: (int)number;
29
- (int) state;
30
@end
31
 
32
@implementation SubClass
33
- (void) setState: (int)number
34
{
35
  state = number;
36
}
37
- (int) state
38
{
39
  return state;
40
}
41
@end
42
 
43
@interface SubSubClass : SubClass
44
- (int) shift;
45
@end
46
 
47
@implementation SubSubClass
48
- (int) shift
49
{
50
  return 1;
51
}
52
@end
53
 
54
@implementation SubSubClass (Additions)
55
- (int) state
56
{
57
  return state + [self shift];
58
}
59
@end
60
 
61
#include "class-tests-1.h"
62
#define TYPE_OF_OBJECT_WITH_ACCESSOR_METHOD SubClass *
63
#include "class-tests-2.h"
64
 
65
int main (void)
66
{
67
  SubClass *object;
68
  SubSubClass *sub_object;
69
 
70
  test_class_with_superclass ("SubClass", "RootClass");
71
  test_that_class_has_instance_method ("SubClass", @selector (setState:));
72
  test_that_class_has_instance_method ("SubClass", @selector (state));
73
 
74
  test_class_with_superclass ("SubSubClass", "SubClass");
75
  test_that_class_has_instance_method ("SubSubClass", @selector (setState:));
76
  test_that_class_has_instance_method ("SubSubClass", @selector (state));
77
  test_that_class_has_instance_method ("SubSubClass", @selector (shift));
78
 
79
  object = class_create_instance (objc_lookup_class ("SubClass"));
80
  test_accessor_method (object, 0, -1, -1, 1, 1);
81
 
82
  sub_object = class_create_instance (objc_lookup_class ("SubSubClass"));
83
  test_accessor_method (sub_object, 1, -1, 0, 1, 2);
84
 
85
  return 0;
86
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.