brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 5356749 Raw
99 lines · plain
1#import <Foundation/Foundation.h>2#include <unistd.h>3 4@interface MyClass : NSObject5@end6 7@implementation MyClass : NSObject8@end9 10@implementation MyClass (MyCategory)11 12 13- (void) myCategoryFunction {14    NSLog (@"myCategoryFunction");15}16 17@end18 19 20    21int22Test_Selector ()23{24    SEL sel = @selector(length);25    printf("sel = %p\n", sel);26    // Expressions to test here for selector: 27    // expression (char *)sel_getName(sel)28    //      The expression above should return "sel" as it should be just29    //      a uniqued C string pointer. We were seeing the result pointer being30    //      truncated with recent LLDBs.31    return 0; // Break here for selector: tests32}33 34int35Test_NSString (const char *program)36{37    NSString *str = [NSString stringWithFormat:@"Hello from '%s'", program];38    NSLog(@"NSString instance: %@", str);39    printf("str = '%s'\n", [str cStringUsingEncoding: [NSString defaultCStringEncoding]]);40    printf("[str length] = %zu\n", (size_t)[str length]);41    printf("[str description] = %s\n", [[str description] UTF8String]);42    id str_id = str;43    // Expressions to test here for NSString:44    // expression (char *)sel_getName(sel)45    // expression [str length]46    // expression [str_id length]47    // expression [str description]48    // expression [str_id description]49    // expression str.length50    // expression str.description51    // expression str = @"new"52    // expression str = [NSString stringWithFormat: @"%cew", 'N']53    return 0; // Break here for NSString tests54}55 56NSString *my_global_str = NULL;57 58int59Test_NSArray ()60{61    NSMutableArray *nil_mutable_array = nil;62    NSArray *array1 = [NSArray arrayWithObjects: @"array1 object1", @"array1 object2", @"array1 object3", nil];63    NSArray *array2 = [NSArray arrayWithObjects: array1, @"array2 object2", @"array2 object3", nil];64    // Expressions to test here for NSArray:65    // expression [nil_mutable_array count]66    // expression [array1 count]67    // expression array1.count68    // expression [array2 count]69    // expression array2.count70    id obj;71    // After each object at index call, use expression and validate object72    obj = [array1 objectAtIndex: 0]; // Break here for NSArray tests73    obj = [array1 objectAtIndex: 1];74    obj = [array1 objectAtIndex: 2];75 76    obj = [array2 objectAtIndex: 0];77    obj = [array2 objectAtIndex: 1];78    obj = [array2 objectAtIndex: 2];79    NSUInteger count = [nil_mutable_array count];80    return 0;81}82 83 84int main (int argc, char const *argv[])85{86    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];87    Test_Selector(); // Set breakpoint here88    Test_NSArray ();89    Test_NSString (argv[0]);90    MyClass *my_class = [[MyClass alloc] init];91    [my_class myCategoryFunction];92    printf("sizeof(id) = %zu\n", sizeof(id));93    printf("sizeof(Class) = %zu\n", sizeof(Class));94    printf("sizeof(SEL) = %zu\n", sizeof(SEL));95 96    [pool release];97    return 0;98}99