| 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..8e7c40db714efad06487476f0e3ae7fcef7d2ee8 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.");
|
| + error = [NSError errorWithDomain:@"ARDAppClientTest"
|
| + 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.
|
| @@ -295,13 +306,62 @@ - (void)testSession {
|
| 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 *callerConnectionExpectation =
|
| + [self expectationWithDescription:@"Caller PC connected."];
|
| +
|
| + caller = [self createAppClientForRoomId:roomId
|
| + clientId:callerId
|
| + isInitiator:YES
|
| + messages:[NSArray array]
|
| + messageHandler:^(ARDSignalingMessage *message) {
|
| + }
|
| + connectedHandler:^(NSInvocation *invocation){
|
| + 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
|
| - (void)testPreferVideoCodec;
|
| @end
|
| @@ -318,7 +378,7 @@ - (void)testPreferVideoCodec {
|
| RTCSessionDescription *h264Desc =
|
| [ARDSDPUtils descriptionForDescription:desc
|
| preferredVideoCodec:@"H264"];
|
| - EXPECT_TRUE([h264Desc.description isEqualToString:expectedSdp]);
|
| + EXPECT_TRUE([h264Desc.description webrtc_containsString: expectedSdp]);
|
| }
|
|
|
| @end
|
| @@ -340,6 +400,16 @@ static void TearDownTestCase() {
|
| }
|
| }
|
|
|
| +#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 +417,7 @@ static void TearDownTestCase() {
|
| }
|
| }
|
|
|
| -
|
| +int main(int argc, char **argv) {
|
| + ::testing::InitGoogleTest(&argc, argv);
|
| + return RUN_ALL_TESTS();
|
| +}
|
|
|