aboutsummaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/lang/objc/radar-9691614/main.m
blob: bb87d673452c3a990cd5076170e8556602273c79 (plain) (blame)
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
#import <Foundation/Foundation.h>
#include <stdio.h>

@interface MyString : NSObject {
    NSString *str;
    NSDate *date;
    BOOL _is_valid;
}

- (id)initWithNSString:(NSString *)string;
- (BOOL)isValid;
@end

@implementation MyString
- (id)initWithNSString:(NSString *)string
{
    if (self = [super init])
    {
        str = [NSString stringWithString:string];
        date = [NSDate date];
    }
    _is_valid = YES;
    return self;
}

- (BOOL)isValid
{
    return _is_valid;
}

- (void)dealloc
{
    [date release];
    [str release];
    [super dealloc];
}

- (NSString *)description
{
    return [str stringByAppendingFormat:@" with timestamp: %@", date];
}
@end

void
Test_MyString (const char *program)
{
    NSString *str = [NSString stringWithFormat:@"Hello from '%s'", program];
    MyString *my = [[MyString alloc] initWithNSString:str];
    if ([my isValid])
        printf("my is valid!\n");

    NSLog(@"NSString instance: %@", [str description]); // Set breakpoint here.
                                                        // Test 'p (int)[my isValid]'.
                                                        // The expression parser should not crash -- rdar://problem/9691614.

    NSLog(@"MyString instance: %@", [my description]);
}

int main (int argc, char const *argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    Test_MyString (argv[0]);

    [pool release];
    return 0;
}