1/* 2 * Copyright (c) 2010 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LLVM_LICENSE_HEADER@ 5 */ 6 7// 8// nestedBlock.m 9// testObjects 10// 11// Created by Blaine Garst on 6/24/08. 12// Copyright 2008 __MyCompanyName__. All rights reserved. 13// 14 15// test non-GC -retain 16 17// TEST_CONFIG MEM=mrc 18// TEST_CFLAGS -framework Foundation 19 20#import <stdio.h> 21#import <Block.h> 22#import <Foundation/Foundation.h> 23#import "test.h" 24 25int Retained = 0; 26 27@interface TestObject : NSObject 28@end 29@implementation TestObject 30- (id)retain { 31 Retained = 1; 32 return [super retain]; 33} 34@end 35 36void callVoidVoid(void (^closure)(void)) { 37 closure(); 38} 39 40int main(int argc, char *argv[] __unused) { 41 TestObject *to = [[TestObject alloc] init]; 42 int i = argc; 43 44 // use a copy & see that it updates i 45 callVoidVoid(Block_copy(^{ 46 if (i > 0) { 47 callVoidVoid(^{ [to self]; }); 48 } 49 })); 50 51 if (Retained == 0) { 52 fail("didn't update Retained"); 53 } 54 55 succeed(__FILE__); 56} 57