brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · 519bec5 Raw
142 lines · plain
1#import <Foundation/Foundation.h>2#include <unistd.h>3#import "my-base.h"4 5@interface MyString : MyBase {6    NSString *str;7    NSDate *date;8    BOOL _desc_pauses;9}10 11@property(retain) NSString * str_property;12@property BOOL descriptionPauses;13 14- (id)initWithNSString:(NSString *)string;15@end16 17@implementation MyString18@synthesize descriptionPauses = _desc_pauses;19@synthesize str_property = str;20 21- (id)initWithNSString:(NSString *)string22{23    if (self = [super init])24    {25        str = [NSString stringWithString:string];26        date = [NSDate date];27    }28    self.descriptionPauses = NO;29    return self;30}31 32- (void)dealloc33{34    [date release];35    [str release];36    [super dealloc];37}38 39- (NSString *)description40{41    // Set a breakpoint on '-[MyString description]' and test expressions:42    // expression (char *)sel_getName(_cmd)43  if (self.descriptionPauses)  // Break here for description test44    {45        printf ("\nAbout to sleep.\n");46        usleep(100000);47    }48 49    return [str stringByAppendingFormat:@" with timestamp: %@", date];50}51@end52 53int54Test_Selector ()55{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 just61    //      a uniqued C string pointer. We were seeing the result pointer being62    //      truncated with recent LLDBs.63    return 0; // Break here for selector: tests64}65 66int67Test_NSString (const char *program)68{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]);74    id str_id = str;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.length82    // expression str.description83    // expression str = @"new"84    // expression str = [NSString stringWithFormat: @"%cew", 'N']85    return 0; // Break here for NSString tests86}87 88NSString *my_global_str = NULL;89 90void91Test_MyString (const char *program)92{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]);99}100 101int102Test_NSArray ()103{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.count111    // expression [array2 count]112    // expression array2.count113    id obj;114    // After each object at index call, use expression and validate object115    obj = [array1 objectAtIndex: 0]; // Break here for NSArray tests116    obj = [array1 objectAtIndex: 1];117    obj = [array1 objectAtIndex: 2];118 119    obj = [array2 objectAtIndex: 0];120    obj = [array2 objectAtIndex: 1];121    obj = [array2 objectAtIndex: 2];122    NSUInteger count = [nil_mutable_array count];123    return 0;124}125 126 127int main (int argc, char const *argv[])128{129    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];130    Test_Selector();131    Test_NSArray ();132    Test_NSString (argv[0]);133    Test_MyString (argv[0]);134 135    printf("sizeof(id) = %zu\n", sizeof(id));136    printf("sizeof(Class) = %zu\n", sizeof(Class));137    printf("sizeof(SEL) = %zu\n", sizeof(SEL));138 139    [pool release];140    return 0;141}142