From bcc5d87f0932e96efdd90dc7fcc50ebab301ce62 Mon Sep 17 00:00:00 2001 From: "adam.fedor" Date: Mon, 7 Nov 2016 14:53:28 -0800 Subject: [PATCH] Add a GN target for unit tests, get them working again and added a test. BUG=webrtc:3417 Review-Url: https://codereview.webrtc.org/2050153003 Cr-Commit-Position: refs/heads/master@{#14959} --- AUTHORS | 1 + webrtc/examples/BUILD.gn | 27 ++++++ .../examples/objc/AppRTCMobile/ARDAppClient.m | 4 +- .../AppRTCMobile/tests/ARDAppClientTest.mm | 86 ++++++++++++++++--- 4 files changed, 106 insertions(+), 12 deletions(-) diff --git a/AUTHORS b/AUTHORS index 729f804803..89606dea37 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,6 +1,7 @@ # Names should be added to this file like so: # Name or Organization +Adam Fedor Alexander Brauckmann Andrew MacDonald Anil Kumar diff --git a/webrtc/examples/BUILD.gn b/webrtc/examples/BUILD.gn index faa05d3b7e..8a71895d39 100644 --- a/webrtc/examples/BUILD.gn +++ b/webrtc/examples/BUILD.gn @@ -389,6 +389,33 @@ if (is_ios || (is_mac && target_cpu != "x86")) { "icucore", ] } + + if (rtc_include_tests) { + config("rtc_apprtcmobile_config") { + defines = [ "GTEST_RELATIVE_PATH" ] + } + + rtc_test("apprtcmobile_tests") { + deps = [ + ":apprtc_signaling", + "//testing/gtest", + "//third_party/ocmock", + ] + + sources = [ + "objc/AppRTCMobile/tests/ARDAppClientTest.mm", + ] + + if (is_ios) { + info_plist = "objc/AppRTCMobile/ios/Info.plist" + } + + configs += [ + ":rtc_apprtcmobile_config", + "//build/config/compiler:enable_arc", + ] + } + } } if (is_linux || is_win) { diff --git a/webrtc/examples/objc/AppRTCMobile/ARDAppClient.m b/webrtc/examples/objc/AppRTCMobile/ARDAppClient.m index 9ef46b4742..4a073f3f1c 100644 --- a/webrtc/examples/objc/AppRTCMobile/ARDAppClient.m +++ b/webrtc/examples/objc/AppRTCMobile/ARDAppClient.m @@ -318,7 +318,9 @@ static int64_t const kARDAppClientRtcEventLogMaxSizeInBytes = 5e6; // 5 MB. _peerConnection = nil; self.state = kARDAppClientStateDisconnected; #if defined(WEBRTC_IOS) - RTCStopInternalCapture(); + if (kARDAppClientEnableTracing) { + RTCStopInternalCapture(); + } #endif } diff --git a/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClientTest.mm b/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClientTest.mm index c1fc08ca8e..20a5cf481e 100644 --- a/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClientTest.mm +++ b/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClientTest.mm @@ -10,6 +10,7 @@ #import #import +#import #include "webrtc/base/gunit.h" #include "webrtc/base/ssladapter.h" @@ -23,6 +24,9 @@ #import "ARDMessageResponse+Internal.h" #import "ARDSDPUtils.h" +static NSString *kARDAppClientTestsDomain = @"org.webrtc.ARDAppClientTests"; +static NSInteger kARDAppClientTestsExpectationTimeoutError = 100; + // These classes mimic XCTest APIs, to make eventual conversion to XCTest // easier. Conversion will happen once XCTest is supported well on build bots. @interface ARDTestExpectation : NSObject @@ -81,17 +85,20 @@ - (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout handler:(void (^)(NSError *error))handler { - NSDate *startDate = [NSDate date]; + CFTimeInterval startTime = CACurrentMediaTime(); + NSError *error = nil; while (![self areExpectationsFulfilled]) { - NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:startDate]; + CFTimeInterval duration = CACurrentMediaTime() - startTime; if (duration > timeout) { - NSAssert(NO, @"Expectation timed out."); + error = [NSError errorWithDomain:kARDAppClientTestsDomain + code:kARDAppClientTestsExpectationTimeoutError + userInfo:@{}]; break; } [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; } - handler(nil); + handler(error); } - (BOOL)areExpectationsFulfilled { @@ -137,7 +144,7 @@ [[[mockRoomServerClient stub] andDo:^(NSInvocation *invocation) { __unsafe_unretained void (^completionHandler)(ARDJoinResponse *response, NSError *error); - [invocation getArgument:&completionHandler atIndex:3]; + [invocation getArgument:&completionHandler atIndex:4]; completionHandler(joinResponse, nil); }] joinRoomWithRoomId:roomId isLoopback:NO completionHandler:[OCMArg any]]; @@ -203,7 +210,8 @@ messages:(NSArray *)messages messageHandler: (void (^)(ARDSignalingMessage *message))messageHandler - connectedHandler:(void (^)(void))connectedHandler { + connectedHandler:(void (^)(void))connectedHandler + localVideoTrackHandler:(void (^)(void))localVideoTrackHandler { id turnClient = [self mockTURNClient]; id signalingChannel = [self mockSignalingChannelForRoomId:roomId clientId:clientId @@ -220,6 +228,10 @@ connectedHandler(); }] appClient:[OCMArg any] didChangeConnectionState:RTCIceConnectionStateConnected]; + [[[delegate stub] andDo:^(NSInvocation *invocation) { + localVideoTrackHandler(); + }] appClient:[OCMArg any] + didReceiveLocalVideoTrack:[OCMArg any]]; return [[ARDAppClient alloc] initWithRoomServerClient:roomServerClient signalingChannel:signalingChannel @@ -255,8 +267,9 @@ messageHandler:^(ARDSignalingMessage *message) { ARDAppClient *strongAnswerer = weakAnswerer; [strongAnswerer channel:strongAnswerer.channel didReceiveMessage:message]; - } connectedHandler:^{ + } connectedHandler:^{ [callerConnectionExpectation fulfill]; + } localVideoTrackHandler:^{ }]; // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion // crash in Debug. @@ -272,8 +285,9 @@ messageHandler:^(ARDSignalingMessage *message) { ARDAppClient *strongCaller = weakCaller; [strongCaller channel:strongCaller.channel didReceiveMessage:message]; - } connectedHandler:^{ + } connectedHandler:^{ [answererConnectionExpectation fulfill]; + } localVideoTrackHandler:^{ }]; // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion // crash in Debug. @@ -295,7 +309,44 @@ shouldUseLevelControl:NO]; [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { if (error) { - NSLog(@"Expectations error: %@", error); + EXPECT_TRUE(0); + } + }]; +} + +// Test to see that we get a local video connection +// Note this will currently pass even when no camera is connected as a local +// video track is created regardless (Perhaps there should be a test for that...) +- (void)testSessionShouldGetLocalVideoTrackCallback { + ARDAppClient *caller = nil; + NSString *roomId = @"testRoom"; + NSString *callerId = @"testCallerId"; + + ARDTestExpectation *localVideoTrackExpectation = + [self expectationWithDescription:@"Caller got local video."]; + + caller = [self createAppClientForRoomId:roomId + clientId:callerId + isInitiator:YES + messages:[NSArray array] + messageHandler:^(ARDSignalingMessage *message) { + } connectedHandler:^{ + } localVideoTrackHandler:^{ + [localVideoTrackExpectation fulfill]; + }]; + caller.defaultPeerConnectionConstraints = + [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil + optionalConstraints:nil]; + + // Kick off connection. + [caller connectToRoomWithId:roomId + isLoopback:NO + isAudioOnly:NO + shouldMakeAecDump:NO + shouldUseLevelControl:NO]; + [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { + if (error) { + EXPECT_TRUE(0); } }]; } @@ -318,7 +369,7 @@ RTCSessionDescription *h264Desc = [ARDSDPUtils descriptionForDescription:desc preferredVideoCodec:@"H264"]; - EXPECT_TRUE([h264Desc.description isEqualToString:expectedSdp]); + EXPECT_TRUE([h264Desc.description rangeOfString:expectedSdp].location != NSNotFound); } @end @@ -340,6 +391,16 @@ TEST_F(SignalingTest, SessionTest) { } } +#if !TARGET_IPHONE_SIMULATOR +// Expected fail on iOS Simulator due to no camera support +TEST_F(SignalingTest, SessionLocalVideoCallbackTest) { + @autoreleasepool { + ARDAppClientTest *test = [[ARDAppClientTest alloc] init]; + [test testSessionShouldGetLocalVideoTrackCallback]; + } +} +#endif + TEST_F(SignalingTest, SDPTest) { @autoreleasepool { ARDSDPUtilsTest *test = [[ARDSDPUtilsTest alloc] init]; @@ -347,4 +408,7 @@ TEST_F(SignalingTest, SDPTest) { } } - +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}