1 #import <Foundation/Foundation.h>
5 @interface MyString : MyBase {
11 @property(retain) NSString * str_property;
12 @property BOOL descriptionPauses;
14 - (id)initWithNSString:(NSString *)string;
17 @implementation MyString
18 @synthesize descriptionPauses = _desc_pauses;
19 @synthesize str_property = str;
21 - (id)initWithNSString:(NSString *)string
23 if (self = [super init])
25 str = [NSString stringWithString:string];
28 self.descriptionPauses = NO;
39 - (NSString *)description
41 // Set a breakpoint on '-[MyString description]' and test expressions:
42 // expression (char *)sel_getName(_cmd)
43 if (self.descriptionPauses) // Break here for description test
45 printf ("\nAbout to sleep.\n");
49 return [str stringByAppendingFormat:@" with timestamp: %@", date];
56 SEL sel = @selector(length);
57 printf("sel = %p\n", sel);
58 // Expressions to test here for selector:
59 // expression (char *)sel_getName(sel)
60 // The expression above should return "sel" as it should be just
61 // a uniqued C string pointer. We were seeing the result pointer being
62 // truncated with recent LLDBs.
63 return 0; // Break here for selector: tests
67 Test_NSString (const char *program)
69 NSString *str = [NSString stringWithFormat:@"Hello from '%s'", program];
70 NSLog(@"NSString instance: %@", str);
71 printf("str = '%s'\n", [str cStringUsingEncoding: [NSString defaultCStringEncoding]]);
72 printf("[str length] = %zu\n", (size_t)[str length]);
73 printf("[str description] = %s\n", [[str description] UTF8String]);
75 // Expressions to test here for NSString:
76 // expression (char *)sel_getName(sel)
77 // expression [str length]
78 // expression [str_id length]
79 // expression [str description]
80 // expression [str_id description]
81 // expression str.length
82 // expression str.description
83 // expression str = @"new"
84 // expression str = [NSString stringWithFormat: @"%cew", 'N']
85 return 0; // Break here for NSString tests
88 NSString *my_global_str = NULL;
91 Test_MyString (const char *program)
93 my_global_str = @"This is a global string";
94 NSString *str = [NSString stringWithFormat:@"Hello from '%s'", program];
95 MyString *my = [[MyString alloc] initWithNSString:str];
96 NSLog(@"MyString instance: %@", [my description]);
97 my.descriptionPauses = YES; // Set break point at this line. Test 'expression -o -- my'.
98 NSLog(@"MyString instance: %@", [my description]);
104 NSMutableArray *nil_mutable_array = nil;
105 NSArray *array1 = [NSArray arrayWithObjects: @"array1 object1", @"array1 object2", @"array1 object3", nil];
106 NSArray *array2 = [NSArray arrayWithObjects: array1, @"array2 object2", @"array2 object3", nil];
107 // Expressions to test here for NSArray:
108 // expression [nil_mutable_array count]
109 // expression [array1 count]
110 // expression array1.count
111 // expression [array2 count]
112 // expression array2.count
114 // After each object at index call, use expression and validate object
115 obj = [array1 objectAtIndex: 0]; // Break here for NSArray tests
116 obj = [array1 objectAtIndex: 1];
117 obj = [array1 objectAtIndex: 2];
119 obj = [array2 objectAtIndex: 0];
120 obj = [array2 objectAtIndex: 1];
121 obj = [array2 objectAtIndex: 2];
122 NSUInteger count = [nil_mutable_array count];
127 int main (int argc, char const *argv[])
129 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
132 Test_NSString (argv[0]);
133 Test_MyString (argv[0]);
135 printf("sizeof(id) = %zu\n", sizeof(id));
136 printf("sizeof(Class) = %zu\n", sizeof(Class));
137 printf("sizeof(SEL) = %zu\n", sizeof(SEL));