webrtc_m130/webrtc/test/mac/run_test.mm
kthelgason c097710cce Reland of GN: Enable ARC for Mac and iOS in rtc_* templates (patchset #1 id:1 of https://codereview.webrtc.org/2827223003/ )
Reason for revert:
Relanding after fixing ARC issue.

Original issue's description:
> Revert of GN: Enable ARC for Mac and iOS in rtc_* templates (patchset #3 id:40001 of https://codereview.webrtc.org/2781713004/ )
>
> Reason for revert:
> Breaks mac build
>
> Original issue's description:
> > GN: Enable ARC for Mac and iOS in rtc_* templates
> >
> > Remove all uses of retain/release and NSAutoreleasePool.
> >
> > This makes transformation to Bazel easier.
> >
> > This CL subsumes https://codereview.webrtc.org/2778163002 and depends on https://codereview.webrtc.org/2784483002/
> >
> > BUG=webrtc:6412
> >
> > Review-Url: https://codereview.webrtc.org/2781713004
> > Cr-Commit-Position: refs/heads/master@{#17780}
> > Committed: 6bda02b51d
>
> TBR=kjellander@webrtc.org,magjed@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:6412
>
> Review-Url: https://codereview.webrtc.org/2827223003
> Cr-Commit-Position: refs/heads/master@{#17784}
> Committed: 7c8786ae8f

TBR=kjellander@webrtc.org,magjed@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:6412

Review-Url: https://codereview.webrtc.org/2834273002
Cr-Commit-Position: refs/heads/master@{#17836}
2017-04-24 07:57:16 +00:00

74 lines
1.9 KiB
Plaintext

/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#import <Cocoa/Cocoa.h>
#include "webrtc/test/run_test.h"
// Converting a C++ function pointer to an Objective-C block.
typedef void(^TestBlock)();
TestBlock functionToBlock(void(*function)()) {
return [^(void) { function(); } copy];
}
// Class calling the test function on the platform specific thread.
@interface TestRunner : NSObject {
BOOL running_;
}
- (void)runAllTests:(TestBlock)ignored;
- (BOOL)running;
@end
@implementation TestRunner
- (id)init {
self = [super init];
if (self) {
running_ = YES;
}
return self;
}
- (void)runAllTests:(TestBlock)testBlock {
@autoreleasepool {
testBlock();
running_ = NO;
}
}
- (BOOL)running {
return running_;
}
@end
namespace webrtc {
namespace test {
void RunTest(void(*test)()) {
@autoreleasepool {
[NSApplication sharedApplication];
// Convert the function pointer to an Objective-C block and call on a
// separate thread, to avoid blocking the main thread.
TestRunner *testRunner = [[TestRunner alloc] init];
TestBlock testBlock = functionToBlock(test);
[NSThread detachNewThreadSelector:@selector(runAllTests:)
toTarget:testRunner
withObject:testBlock];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
while ([testRunner running] && [runLoop runMode:NSDefaultRunLoopMode
beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]])
;
}
}
} // namespace test
} // namespace webrtc