blob: 1632bf91ad1b9c142d2b6b4f6fc9a440ecf9f2f9 [file] [log] [blame]
Ted Kremenek30660a82012-03-06 20:06:33 +00001// RUN: rm -rf %t
2// RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -mt-migrate-directory %t %s -x objective-c
3// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
4
5typedef signed char BOOL;
6#define nil ((void*) 0)
7
8@interface NSObject
9+ (id)alloc;
10@end
11
12@interface NSString : NSObject
13+ (id)stringWithString:(NSString *)string;
14- (id)initWithString:(NSString *)aString;
15@end
16
17@interface NSArray : NSObject
18- (id)objectAtIndex:(unsigned long)index;
19- (id)objectAtIndexedSubscript:(int)index;
20@end
21
22@interface NSArray (NSArrayCreation)
23+ (id)array;
24+ (id)arrayWithObject:(id)anObject;
25+ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
26+ (id)arrayWithObjects:(id)firstObj, ...;
27+ (id)arrayWithArray:(NSArray *)array;
28
29- (id)initWithObjects:(const id [])objects count:(unsigned long)cnt;
30- (id)initWithObjects:(id)firstObj, ...;
31- (id)initWithArray:(NSArray *)array;
32
33- (id)objectAtIndex:(unsigned long)index;
34@end
35
36@interface NSMutableArray : NSArray
37- (void)replaceObjectAtIndex:(unsigned long)index withObject:(id)anObject;
38- (void)setObject:(id)object atIndexedSubscript:(int)index;
39@end
40
41@interface NSDictionary : NSObject
42- (id)objectForKeyedSubscript:(id)key;
43@end
44
45@interface NSDictionary (NSDictionaryCreation)
46+ (id)dictionary;
47+ (id)dictionaryWithObject:(id)object forKey:(id)key;
48+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
49+ (id)dictionaryWithObjectsAndKeys:(id)firstObject, ...;
50+ (id)dictionaryWithDictionary:(NSDictionary *)dict;
51+ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
52
53- (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(unsigned long)cnt;
54- (id)initWithObjectsAndKeys:(id)firstObject, ...;
55- (id)initWithDictionary:(NSDictionary *)otherDictionary;
56- (id)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
57
58- (id)objectForKey:(id)aKey;
59@end
60
61@interface NSMutableDictionary : NSDictionary
62- (void)setObject:(id)anObject forKey:(id)aKey;
63- (void)setObject:(id)object forKeyedSubscript:(id)key;
64@end
65
66@interface NSNumber : NSObject
67@end
68
69@interface NSNumber (NSNumberCreation)
70+ (NSNumber *)numberWithInt:(int)value;
71@end
72
73#define M(x) (x)
74#define PAIR(x) @#x, [NSNumber numberWithInt:(x)]
75#define TWO(x) ((x), (x))
76
77@interface I
78@end
79@implementation I
80-(void) foo {
81 NSString *str;
82 NSArray *arr;
83 NSDictionary *dict;
84
85 arr = [NSArray array];
86 arr = [NSArray arrayWithObject:str];
87 arr = [NSArray arrayWithObjects:str, str, nil];
88 dict = [NSDictionary dictionary];
89 dict = [NSDictionary dictionaryWithObject:arr forKey:str];
90 dict = [NSDictionary dictionaryWithObjectsAndKeys: @"value1", @"key1", @"value2", @"key2", nil];
91 dict = [NSDictionary dictionaryWithObjectsAndKeys: PAIR(1), PAIR(2), nil];
92 dict = [NSDictionary dictionaryWithObjectsAndKeys:
93 @"value1", @"key1",
94#ifdef BLAH
95 @"value2", @"key2",
96#else
97 @"value3", @"key3",
98#endif
99 nil ];
100
101 id o = [arr objectAtIndex:2];
102 o = [dict objectForKey:@"key"];
103 o = TWO([dict objectForKey:@"key"]);
104 o = [NSDictionary dictionaryWithObject:[NSDictionary dictionary] forKey:@"key"];
105 NSMutableArray *marr = 0;
106 NSMutableDictionary *mdict = 0;
107 [marr replaceObjectAtIndex:2 withObject:@"val"];
108 [mdict setObject:@"value" forKey:@"key"];
109 [marr replaceObjectAtIndex:2 withObject:[arr objectAtIndex:4]];
110 [mdict setObject:[dict objectForKey:@"key2"] forKey:@"key"];
111 [mdict setObject:[dict objectForKey:@"key2"] forKey:
112#if 1
113 @"key1"
114#else
115 @"key2"
116#endif
117 ];
118 [mdict setObject:[dict objectForKey:
119#if 2
120 @"key3"
121#else
122 @"key4"
123#endif
124 ] forKey:@"key"];
125 [mdict setObject:@"value" forKey:[dict objectForKey:
126#if 3
127 @"key5"
128#else
129 @"key6"
130#endif
131 ] ];
132 [mdict setObject:@"val" forKey:[dict objectForKey:@"key2"]];
133 [mdict setObject:[dict objectForKey:@"key1"] forKey:[dict objectForKey:[NSArray arrayWithObject:@"arrkey"]]];
134 __strong NSArray **parr = 0;
135 o = [*parr objectAtIndex:2];
136}
137@end