Index: webrtc/examples/objc/AppRTCMobile/tests/ARDAppClientTest.mm |
diff --git a/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClientTest.mm b/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClientTest.mm |
index c1fc08ca8e94e5b5ae7a6500711e45658165cdae..7facaa563c00defd5fa7cfce87553056e8f8a112 100644 |
--- a/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClientTest.mm |
+++ b/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClientTest.mm |
@@ -82,16 +82,19 @@ - (ARDTestExpectation *)expectationWithDescription:(NSString *)description { |
- (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout |
handler:(void (^)(NSError *error))handler { |
NSDate *startDate = [NSDate date]; |
+ NSError *error = nil; |
while (![self areExpectationsFulfilled]) { |
NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:startDate]; |
if (duration > timeout) { |
- NSAssert(NO, @"Expectation timed out."); |
daniela-webrtc
2016/10/17 11:33:31
By removing the NSAssert here you'll break the `te
|
+ error = [NSError errorWithDomain:@"ARDAppClient" |
daniela-webrtc
2016/10/17 11:33:31
I think you can use:
error = [[NSError alloc] in
|
+ code:101 |
+ userInfo:@{NSLocalizedDescriptionKey : @"Expectation timed out"}]; |
break; |
} |
[[NSRunLoop currentRunLoop] |
runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; |
} |
- handler(nil); |
+ handler(error); |
} |
- (BOOL)areExpectationsFulfilled { |
@@ -137,7 +140,7 @@ - (id)mockRoomServerClientForRoomId:(NSString *)roomId |
[[[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 +206,7 @@ - (ARDAppClient *)createAppClientForRoomId:(NSString *)roomId |
messages:(NSArray *)messages |
messageHandler: |
(void (^)(ARDSignalingMessage *message))messageHandler |
- connectedHandler:(void (^)(void))connectedHandler { |
+ connectedHandler:(void (^)(NSInvocation *))connectedHandler { |
id turnClient = [self mockTURNClient]; |
id signalingChannel = [self mockSignalingChannelForRoomId:roomId |
clientId:clientId |
@@ -217,9 +220,13 @@ - (ARDAppClient *)createAppClientForRoomId:(NSString *)roomId |
id delegate = |
[OCMockObject niceMockForProtocol:@protocol(ARDAppClientDelegate)]; |
[[[delegate stub] andDo:^(NSInvocation *invocation) { |
- connectedHandler(); |
+ connectedHandler(invocation); |
}] appClient:[OCMArg any] |
didChangeConnectionState:RTCIceConnectionStateConnected]; |
+ [[[delegate stub] andDo:^(NSInvocation *invocation) { |
+ connectedHandler(invocation); |
+ }] appClient:[OCMArg any] |
+ didReceiveLocalVideoTrack:[OCMArg any]]; |
return [[ARDAppClient alloc] initWithRoomServerClient:roomServerClient |
signalingChannel:signalingChannel |
@@ -255,8 +262,10 @@ - (void)testSession { |
messageHandler:^(ARDSignalingMessage *message) { |
ARDAppClient *strongAnswerer = weakAnswerer; |
[strongAnswerer channel:strongAnswerer.channel didReceiveMessage:message]; |
- } connectedHandler:^{ |
- [callerConnectionExpectation fulfill]; |
+ } connectedHandler:^(NSInvocation *invocation){ |
+ if ([NSStringFromSelector([invocation selector]) |
+ isEqualToString:@"appClient:didChangeConnectionState:"]) |
+ [callerConnectionExpectation fulfill]; |
}]; |
// TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion |
// crash in Debug. |
@@ -272,8 +281,10 @@ - (void)testSession { |
messageHandler:^(ARDSignalingMessage *message) { |
ARDAppClient *strongCaller = weakCaller; |
[strongCaller channel:strongCaller.channel didReceiveMessage:message]; |
- } connectedHandler:^{ |
- [answererConnectionExpectation fulfill]; |
+ } connectedHandler:^(NSInvocation *invocation){ |
+ if ([NSStringFromSelector([invocation selector]) |
+ isEqualToString:@"appClient:didChangeConnectionState:"]) |
+ [answererConnectionExpectation fulfill]; |
}]; |
// TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion |
// crash in Debug. |
@@ -300,6 +311,54 @@ - (void)testSession { |
}]; |
} |
+// 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)testSession_ShouldGetLocalVideoTrackCallback { |
daniela-webrtc
2016/10/17 11:33:31
Please remove the underscore from the name of the
|
+ ARDAppClient *caller = nil; |
+ NSString *roomId = @"testRoom"; |
+ NSString *callerId = @"testCallerId"; |
+ |
+ ARDTestExpectation *callerConnectionExpectation = |
+ [self expectationWithDescription:@"Caller PC connected."]; |
+ |
+ caller = [self createAppClientForRoomId:roomId |
+ clientId:callerId |
+ isInitiator:YES |
+ messages:[NSArray array] |
+ messageHandler:^(ARDSignalingMessage *message) { |
+ } connectedHandler:^(NSInvocation *invocation){ |
daniela-webrtc
2016/10/17 11:33:31
Nit: move connectedHandler parameter to next line
|
+ if ([NSStringFromSelector([invocation selector]) |
+ isEqualToString:@"appClient:didReceiveLocalVideoTrack:"]) |
+ [callerConnectionExpectation 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); |
+ } |
+ }]; |
+} |
+ |
+@end |
+ |
+@interface NSString (WebRTCTests) |
+- (BOOL) webrtc_containsString: (NSString *)otherString; |
+@end |
+@implementation NSString (WebRTCTests) |
+- (BOOL) webrtc_containsString: (NSString *)otherString |
+{ |
+ return (otherString && [self rangeOfString: otherString].location != NSNotFound); |
+} |
@end |
@interface ARDSDPUtilsTest : ARDTestCase |
@@ -308,17 +367,19 @@ - (void)testPreferVideoCodec; |
@implementation ARDSDPUtilsTest |
+ |
daniela-webrtc
2016/10/17 11:33:31
Nit: remove extra line
|
- (void)testPreferVideoCodec { |
NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120\n" |
"a=rtpmap:120 H264/90000\n"); |
- NSString *expectedSdp = @("m=video 9 RTP/SAVPF 120 100 116 117 96\n" |
- "a=rtpmap:120 H264/90000\n"); |
+ NSArray *expectedSdpLines = @[@"m=video 9 RTP/SAVPF 120 100 116 117 96\n", |
+ @"a=rtpmap:120 H264/90000\n"]; |
RTCSessionDescription* desc = |
[[RTCSessionDescription alloc] initWithType:RTCSdpTypeOffer sdp:sdp]; |
RTCSessionDescription *h264Desc = |
[ARDSDPUtils descriptionForDescription:desc |
preferredVideoCodec:@"H264"]; |
- EXPECT_TRUE([h264Desc.description isEqualToString:expectedSdp]); |
+ EXPECT_TRUE([h264Desc.description webrtc_containsString: expectedSdpLines[0]] |
daniela-webrtc
2016/10/17 11:33:31
There seems to be no apparent change in the ARDSDP
afedor
2016/10/19 03:10:47
I get:
"RTCSessionDescription:\n
offer\n
m=video
|
+ && [h264Desc.description webrtc_containsString: expectedSdpLines[1]]); |
} |
@end |
@@ -340,6 +401,13 @@ static void TearDownTestCase() { |
} |
} |
+TEST_F(SignalingTest, SessionLocalVideoCallbackTest) { |
+ @autoreleasepool { |
+ ARDAppClientTest *test = [[ARDAppClientTest alloc] init]; |
+ [test testSession_ShouldGetLocalVideoTrackCallback]; |
+ } |
+} |
+ |
TEST_F(SignalingTest, SDPTest) { |
@autoreleasepool { |
ARDSDPUtilsTest *test = [[ARDSDPUtilsTest alloc] init]; |
@@ -347,4 +415,7 @@ static void TearDownTestCase() { |
} |
} |
- |
+int main(int argc, char **argv) { |
+ ::testing::InitGoogleTest(&argc, argv); |
+ return RUN_ALL_TESTS(); |
+} |