@@ -13,18 +13,38 @@ * file. */ #include "config.h" -#import "TestsAppDelegate.h" +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface RuntimeARCTests: OTTestCase +@end + +@interface RuntimeARCTestClass: OFObject +@end + +@implementation RuntimeARCTests +- (void)testExceptionsDuringInit +{ + OTAssertThrows((void)[[RuntimeARCTestClass alloc] init]); +} + +- (void)testWeakReferences +{ + id object = [[OFObject alloc] init]; + __weak id weak = object; -static OFString *const module = @"Runtime (ARC)"; + OTAssertEqual(weak, object); -@interface RuntimeARCTest: OFObject + object = nil; + OTAssertNil(weak); +} @end -@implementation RuntimeARCTest +@implementation RuntimeARCTestClass - (instancetype)init { self = [super init]; #if defined(OF_WINDOWS) && defined(OF_AMD64) @@ -38,24 +58,6 @@ @throw [OFException exception]; #endif return self; } -@end - -@implementation TestsAppDelegate (RuntimeARCTests) -- (void)runtimeARCTests -{ - id object; - __weak id weak; - - EXPECT_EXCEPTION(@"Exceptions in init", OFException, - object = [[RuntimeARCTest alloc] init]) - - object = [[OFObject alloc] init]; - weak = object; - TEST(@"weakly referencing an object", weak == object) - - object = nil; - TEST(@"weak references becoming nil", weak == nil) -} @end