diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m index def2c5246..08b98449c 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m @@ -15,19 +15,12 @@ #import #import +#import #import #import #import #import -#define RUN_RUNLOOP_WHILE(CONDITION) \ -{ \ - NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \ - while ((CONDITION) && [timeout timeIntervalSinceNow] > 0) { \ - [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \ - } \ -} - @interface RCTJavaScriptContext : NSObject @property (nonatomic, assign, readonly) JSGlobalContextRef ctx; @@ -131,7 +124,7 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a (void)bridge; } - RUN_RUNLOOP_WHILE(module.isValid) + RCT_RUN_RUNLOOP_WHILE(module.isValid) XCTAssertFalse(module.isValid, @"AllocationTestModule should have been invalidated by the bridge"); } @@ -150,7 +143,7 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a (void)bridge; } - RUN_RUNLOOP_WHILE(weakModule) + RCT_RUN_RUNLOOP_WHILE(weakModule) XCTAssertNil(weakModule, @"AllocationTestModule should have been deallocated"); } @@ -163,7 +156,7 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a XCTAssertNotNil(method, @"RCTModuleMethod should have been created"); } - RUN_RUNLOOP_WHILE(weakMethod) + RCT_RUN_RUNLOOP_WHILE(weakMethod) XCTAssertNil(weakMethod, @"RCTModuleMethod should have been deallocated"); } @@ -175,7 +168,7 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a __weak UIView *rootContentView; @autoreleasepool { RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"" initialProperties:nil]; - RUN_RUNLOOP_WHILE(!(rootContentView = [rootView valueForKey:@"contentView"])) + RCT_RUN_RUNLOOP_WHILE(!(rootContentView = [rootView valueForKey:@"contentView"])) XCTAssertTrue(rootContentView.userInteractionEnabled, @"RCTContentView should be valid"); (void)rootView; } @@ -197,7 +190,7 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a [bridge reload]; } - RUN_RUNLOOP_WHILE(batchedBridge != nil) + RCT_RUN_RUNLOOP_WHILE(batchedBridge != nil) XCTAssertNotNil(bridge, @"RCTBridge should not have been deallocated"); XCTAssertNil(batchedBridge, @"RCTBatchedBridge should have been deallocated"); @@ -209,7 +202,7 @@ RCT_EXPORT_METHOD(test:(__unused NSString *)a bridge = nil; } - RUN_RUNLOOP_WHILE(batchedBridge != nil); + RCT_RUN_RUNLOOP_WHILE(batchedBridge != nil); XCTAssertNil(batchedBridge); } diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m index e823994bf..f40331c5c 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m @@ -15,24 +15,13 @@ #import #import +#import #import #import #import #import #import -#define RUN_RUNLOOP_WHILE(CONDITION) \ -{ \ - NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \ - while ((CONDITION)) { \ - [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \ - if ([timeout timeIntervalSinceNow] <= 0) { \ - XCTFail(@"Runloop timed out before condition was met"); \ - break; \ - } \ - } \ -} - static const NSUInteger kNameIndex = 0; static const NSUInteger kConstantsIndex = 1; static const NSUInteger kMethodsIndex = 2; @@ -183,14 +172,14 @@ RCT_EXPORT_MODULE(TestModule) _testMethodCalled = NO; [_bridge invalidate]; - RUN_RUNLOOP_WHILE(_jsExecutor.isValid); + RCT_RUN_RUNLOOP_WHILE(_jsExecutor.isValid); _bridge = nil; } - (void)testHookRegistration { NSString *injectedStuff; - RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"])); + RCT_RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"])); XCTAssertNotNil(injectedStuff); __block NSNumber *testModuleID = nil; @@ -217,7 +206,7 @@ RCT_EXPORT_MODULE(TestModule) - (void)testCallNativeMethod { NSString *injectedStuff; - RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"])); + RCT_RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"])); XCTAssertNotNil(injectedStuff); __block NSNumber *testModuleID = nil; @@ -249,7 +238,7 @@ RCT_EXPORT_MODULE(TestModule) - (void)testCallUnregisteredModuleMethod { NSString *injectedStuff; - RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"])); + RCT_RUN_RUNLOOP_WHILE(!(injectedStuff = _jsExecutor.injectedStuff[@"__fbBatchedBridgeConfig"])); XCTAssertNotNil(injectedStuff); __block NSNumber *testModuleID = nil; diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTComponentPropsTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTComponentPropsTests.m index b6ab4b769..622c3d99f 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTComponentPropsTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTComponentPropsTests.m @@ -14,22 +14,11 @@ #import +#import #import #import #import -#define RUN_RUNLOOP_WHILE(CONDITION) \ -{ \ - NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \ - while ((CONDITION)) { \ - [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \ - if ([timeout timeIntervalSinceNow] <= 0) { \ - XCTFail(@"Runloop timed out before condition was met"); \ - break; \ - } \ - } \ -} - @interface RCTUIManager () - (void)createView:(NSNumber *)reactTag @@ -99,7 +88,7 @@ RCT_CUSTOM_VIEW_PROPERTY(customProp, NSString, RCTPropsTestView) _bridge = [[RCTBridge alloc] initWithBundleURL:[bundle URLForResource:@"UIExplorerUnitTestsBundle" withExtension:@"js"] moduleProvider:nil launchOptions:nil]; - RUN_RUNLOOP_WHILE(_bridge.isLoading); + RCT_RUN_RUNLOOP_WHILE(_bridge.isLoading); } - (void)testSetProps @@ -123,7 +112,7 @@ RCT_CUSTOM_VIEW_PROPERTY(customProp, NSString, RCTPropsTestView) [uiManager setNeedsLayout]; }); - RUN_RUNLOOP_WHILE(view == nil); + RCT_RUN_RUNLOOP_WHILE(view == nil); } - (void)testResetProps @@ -153,7 +142,7 @@ RCT_CUSTOM_VIEW_PROPERTY(customProp, NSString, RCTPropsTestView) [uiManager setNeedsLayout]; }); - RUN_RUNLOOP_WHILE(view == nil); + RCT_RUN_RUNLOOP_WHILE(view == nil); } - (void)testResetBackgroundColor @@ -177,7 +166,7 @@ RCT_CUSTOM_VIEW_PROPERTY(customProp, NSString, RCTPropsTestView) [uiManager setNeedsLayout]; }); - RUN_RUNLOOP_WHILE(view == nil); + RCT_RUN_RUNLOOP_WHILE(view == nil); } @end diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTDevMenuTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTDevMenuTests.m index d86ccf31a..958991913 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTDevMenuTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTDevMenuTests.m @@ -14,22 +14,11 @@ #import +#import #import #import #import -#define RUN_RUNLOOP_WHILE(CONDITION) \ -{ \ - NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \ - while ((CONDITION)) { \ - [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \ - if ([timeout timeIntervalSinceNow] <= 0) { \ - XCTFail(@"Runloop timed out before condition was met"); \ - break; \ - } \ - } \ -} - typedef void(^RCTDevMenuAlertActionHandler)(UIAlertAction *action); @interface RCTDevMenu () @@ -56,7 +45,7 @@ typedef void(^RCTDevMenuAlertActionHandler)(UIAlertAction *action); moduleProvider:nil launchOptions:nil]; - RUN_RUNLOOP_WHILE(_bridge.isLoading); + RCT_RUN_RUNLOOP_WHILE(_bridge.isLoading); } - (void)testShowCreatingActionSheet diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTGzipTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTGzipTests.m index c41bb35c8..172997f8c 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTGzipTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTGzipTests.m @@ -14,17 +14,10 @@ #import +#import #import #import -#define RUN_RUNLOOP_WHILE(CONDITION) \ -{ \ - NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \ - while ((CONDITION) && [timeout timeIntervalSinceNow] > 0) { \ - [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \ - } \ -} - extern BOOL RCTIsGzippedData(NSData *data); @interface RCTNetworking (Private) @@ -83,7 +76,7 @@ extern BOOL RCTIsGzippedData(NSData *data); request = _request; }]; - RUN_RUNLOOP_WHILE(request == nil); + RCT_RUN_RUNLOOP_WHILE(request == nil); XCTAssertNotNil(request); XCTAssertNotNil(request.HTTPBody); diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitNotificationRaceTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitNotificationRaceTests.m index 78d10d83b..256a227f6 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitNotificationRaceTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitNotificationRaceTests.m @@ -15,6 +15,7 @@ #import #import +#import #import #import #import @@ -22,18 +23,6 @@ #import #import -#define RUN_RUNLOOP_WHILE(CONDITION) \ -{ \ - NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \ - while ((CONDITION)) { \ - [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \ - if ([timeout timeIntervalSinceNow] <= 0) { \ - XCTFail(@"Runloop timed out before condition was met"); \ - break; \ - } \ - } \ -} - @interface RCTTestViewManager : RCTViewManager @end @@ -127,7 +116,7 @@ RCT_EXPORT_MODULE() - (void)testViewManagerNotInitializedBeforeSetBridgeModule { - RUN_RUNLOOP_WHILE(!_notificationObserver.didDetectViewManagerInit); + RCT_RUN_RUNLOOP_WHILE(!_notificationObserver.didDetectViewManagerInit); } @end diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitTests.m index 08ca7a33e..09da21e78 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleInitTests.m @@ -15,25 +15,13 @@ #import #import +#import #import #import #import #import #import -#define RUN_RUNLOOP_WHILE(CONDITION) \ -{ \ - NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \ - while ((CONDITION)) { \ - [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \ - if ([timeout timeIntervalSinceNow] <= 0) { \ - XCTFail(@"Runloop timed out before condition was met"); \ - break; \ - } \ - } \ -} - - @interface RCTTestInjectedModule : NSObject @end @@ -205,13 +193,13 @@ RCT_EXPORT_MODULE() XCTAssertEqual(_injectedModule, [_bridge moduleForClass:[RCTTestInjectedModule class]]); XCTAssertEqual(_injectedModule.bridge, _bridge.batchedBridge); XCTAssertNotNil(_injectedModule.methodQueue); - RUN_RUNLOOP_WHILE(!_injectedModuleInitNotificationSent); + RCT_RUN_RUNLOOP_WHILE(!_injectedModuleInitNotificationSent); XCTAssertTrue(_injectedModuleInitNotificationSent); } - (void)testCustomInitModuleInitializedAtBridgeStartup { - RUN_RUNLOOP_WHILE(!_customInitModuleNotificationSent); + RCT_RUN_RUNLOOP_WHILE(!_customInitModuleNotificationSent); XCTAssertTrue(_customInitModuleNotificationSent); RCTTestCustomInitModule *module = [_bridge moduleForClass:[RCTTestCustomInitModule class]]; XCTAssertTrue(module.initializedOnMainQueue); @@ -228,7 +216,7 @@ RCT_EXPORT_MODULE() module = [self->_bridge moduleForClass:[RCTTestCustomSetBridgeModule class]]; }); - RUN_RUNLOOP_WHILE(!module); + RCT_RUN_RUNLOOP_WHILE(!module); XCTAssertTrue(_customSetBridgeModuleNotificationSent); XCTAssertFalse(module.setBridgeOnMainQueue); XCTAssertEqual(module.bridge, _bridge.batchedBridge); @@ -237,10 +225,10 @@ RCT_EXPORT_MODULE() - (void)testExportConstantsModuleInitializedAtBridgeStartup { - RUN_RUNLOOP_WHILE(!_exportConstantsModuleNotificationSent); + RCT_RUN_RUNLOOP_WHILE(!_exportConstantsModuleNotificationSent); XCTAssertTrue(_exportConstantsModuleNotificationSent); RCTTestExportConstantsModule *module = [_bridge moduleForClass:[RCTTestExportConstantsModule class]]; - RUN_RUNLOOP_WHILE(!module.exportedConstants); + RCT_RUN_RUNLOOP_WHILE(!module.exportedConstants); XCTAssertTrue(module.exportedConstants); XCTAssertTrue(module.exportedConstantsOnMainQueue); XCTAssertEqual(module.bridge, _bridge.batchedBridge); @@ -256,7 +244,7 @@ RCT_EXPORT_MODULE() module = [self->_bridge moduleForClass:[RCTLazyInitModule class]]; }); - RUN_RUNLOOP_WHILE(!module); + RCT_RUN_RUNLOOP_WHILE(!module); XCTAssertTrue(_lazyInitModuleNotificationSent); XCTAssertFalse(_lazyInitModuleNotificationSentOnMainQueue); XCTAssertNotNil(module); diff --git a/Libraries/RCTTest/RCTTestRunner.h b/Libraries/RCTTest/RCTTestRunner.h index 790bcd0c1..d8e909a49 100644 --- a/Libraries/RCTTest/RCTTestRunner.h +++ b/Libraries/RCTTest/RCTTestRunner.h @@ -15,6 +15,18 @@ #define FB_REFERENCE_IMAGE_DIR "" #endif +#define RCT_RUN_RUNLOOP_WHILE(CONDITION) \ +{ \ + NSDate *timeout = [NSDate dateWithTimeIntervalSinceNow:5]; \ + while ((CONDITION)) { \ + [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; \ + if ([timeout timeIntervalSinceNow] <= 0) { \ + XCTFail(@"Runloop timed out before condition was met"); \ + break; \ + } \ + } \ +} + /** * Use the RCTInitRunnerForApp macro for typical usage. See FBSnapshotTestCase.h for more information * on how to configure the snapshotting system.