File: test01.m

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (74 lines) | stat: -rw-r--r-- 2,099 bytes parent folder | download | duplicates (2)
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
68
69
70
71
72
73
74
#import "Testing.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSString.h>
#import <Foundation/NSArray.h>

#if defined(GNUSTEP_BASE_LIBRARY)
@interface NSObject (ISCLASS)
// This method doesn't exist on Cocoa
- (BOOL) isClass;
@end

@interface MyEvilClass : NSObject
{
 Class class;
 const char *name;
 long version;
 unsigned long info;
 /* not sure which of these is correct */
 Class class_;
 const char *name_;
 long version_;
 unsigned long info_;
}
-(void)setInfo:(unsigned long)info;
@end

@implementation MyEvilClass 
-(void)setInfo:(unsigned long)theInfo
{
  info = theInfo;
}
@end
#endif

int main()
{
  NSAutoreleasePool   *arp = [NSAutoreleasePool new];
  id evilObject;

#if defined(GNUSTEP_BASE_LIBRARY)
  PASS([NSObject isClass] &&
       [NSString isClass] &&
       [NSArray isClass],
       "-isClass returns YES on a Class");
  
  PASS((![[[NSObject new] autorelease] isClass] &&
       ![[NSString stringWithCString:"foo"] isClass] &&
       ![[[NSArray new] autorelease] isClass]),
       "-isClass returns NO on an instance");
  
  evilObject = AUTORELEASE([MyEvilClass new]);
  [evilObject setInfo:1];
  PASS(![evilObject isClass], 
       "-isClass returns NO on an instance (special test for broken libobjc)");
#endif
  
  PASS(([[[NSObject new] autorelease] isKindOfClass:[NSObject class]] &&
       [[[NSString new] autorelease] isKindOfClass:[NSString class]] &&
       ![[[NSObject new] autorelease] isKindOfClass:[NSString class]] &&
       [[[NSString new] autorelease] isKindOfClass:[NSObject class]] &&
       ![[[NSString new] autorelease] isKindOfClass:[NSArray class]] &&
       [[[NSMutableString new] autorelease] isKindOfClass:[NSString class]]),
       "-isKindOfClass: works"); 
  
     /* should return YES if receiver and argument are both NSObject */
  PASS([NSObject isKindOfClass:[NSObject class]] &&
       ![NSString isKindOfClass:[NSString class]] &&  
       ![NSObject isKindOfClass:[NSString class]] &&
       [NSString isKindOfClass:[NSObject class]],
       "+isKindOfClass: works");

  [arp release]; arp = nil;
  return 0;
}