1/* 2 * Copyright (c) 2010 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LLVM_LICENSE_HEADER@ 5 */ 6 7// 8// weakblock.m 9// testObjects 10// 11// Created by Blaine Garst on 10/30/08. 12// Copyright 2008 __MyCompanyName__. All rights reserved. 13// 14// TEST_CFLAGS -framework Foundation 15// 16// rdar://5847976 17// Super basic test - does compiler a) compile and b) call out on assignments 18 19#import <Foundation/Foundation.h> 20#import "test.h" 21 22// provide our own version for testing 23 24int GotCalled = 0; 25 26void _Block_object_assign(void *destAddr, const void *object, const int flags) { 27 printf("_Block_object_assign(dest %p, value %p, flags %x)\n", destAddr, object, flags); 28 ++GotCalled; 29} 30 31int recovered = 0; 32 33@interface TestObject : NSObject { 34} 35@end 36 37@implementation TestObject 38- (id)retain { 39 fail("Whoops, retain called!"); 40} 41- (void)finalize { 42 ++recovered; 43 [super finalize]; 44} 45- (void)dealloc { 46 ++recovered; 47 [super dealloc]; 48} 49@end 50 51 52void testRR() { 53 // create test object 54 TestObject *to = [[TestObject alloc] init]; 55 __block TestObject *__weak testObject __unused = to; // iniitialization does NOT require support function 56} 57 58int main() { 59 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 60 GotCalled = 0; 61 testRR(); 62 if (GotCalled == 1) { 63 fail("called out to support function on initialization"); 64 return 1; 65 } 66 [pool drain]; 67 68 succeed(__FILE__); 69} 70