1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LLVM_LICENSE_HEADER@
5 */
6
7//
8//  refcounting.m
9//
10//  Created by Blaine Garst on 3/21/08.
11//  Copyright 2008 __MyCompanyName__. All rights reserved.
12//
13// TEST_CFLAGS -framework Foundation
14
15#import <Foundation/Foundation.h>
16#import <Block.h>
17#import <Block_private.h>
18#import "test.h"
19
20int main() {
21    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
22    int i = 10;
23    void (^blockA)(void) = ^ { printf("i is %d\n", i); };
24
25    // make sure we can retain/release it
26    for (int i = 0; i < 1000; ++i) {
27        [blockA retain];
28    }
29    for (int i = 0; i < 1000; ++i) {
30        [blockA release];
31    }
32    // smae for a copy
33    void (^blockAcopy)(void) = [blockA copy];
34    for (int i = 0; i < 1000; ++i) {
35        [blockAcopy retain];
36    }
37    for (int i = 0; i < 1000; ++i) {
38        [blockAcopy release];
39    }
40    [blockAcopy release];
41    // now for the other guy
42    blockAcopy = Block_copy(blockA);
43
44    for (int i = 0; i < 1000; ++i) {
45        void (^blockAcopycopy)(void) = Block_copy(blockAcopy);
46        if (blockAcopycopy != blockAcopy) {
47            fail("copy %p of copy %p wasn't the same!!", (void *)blockAcopycopy, (void *)blockAcopy);
48        }
49    }
50    for (int i = 0; i < 1000; ++i) {
51        Block_release(blockAcopy);
52    }
53    Block_release(blockAcopy);
54    [pool drain];
55
56    succeed(__FILE__);
57}
58