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..5721b81e87df59c43b77491008f5a7505d0fd2b8 100644 |
--- a/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClientTest.mm |
+++ b/webrtc/examples/objc/AppRTCMobile/tests/ARDAppClientTest.mm |
@@ -9,6 +9,7 @@ |
*/ |
#import <Foundation/Foundation.h> |
+#import <QuartzCore/CoreAnimation.h> |
tkchin_webrtc
2016/11/07 19:14:21
alphabetize
|
#import <OCMock/OCMock.h> |
#include "webrtc/base/gunit.h" |
@@ -56,8 +57,8 @@ - (void)fulfill { |
@interface ARDTestCase : NSObject |
- (ARDTestExpectation *)expectationWithDescription:(NSString *)description; |
-- (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout |
- handler:(void (^)(NSError *error))handler; |
+- (void)waitForExpectationsWithTimeout:(CFTimeInterval)timeout |
+ handler:(void (^)(BOOL didError))handler; |
tkchin_webrtc
2016/11/07 19:14:21
This was meant to mirror XCTest interfaces so make
afedor
2016/11/07 20:25:25
OK, but to maintain the interface, I should also p
|
@end |
@@ -79,19 +80,20 @@ - (ARDTestExpectation *)expectationWithDescription:(NSString *)description { |
return expectation; |
} |
-- (void)waitForExpectationsWithTimeout:(NSTimeInterval)timeout |
- handler:(void (^)(NSError *error))handler { |
- NSDate *startDate = [NSDate date]; |
+- (void)waitForExpectationsWithTimeout:(CFTimeInterval)timeout |
+ handler:(void (^)(BOOL didError))handler { |
+ CFTimeInterval startTime = CACurrentMediaTime(); |
+ BOOL didErrorExp = NO; |
tkchin_webrtc
2016/11/07 19:14:21
CFTimeInterval change looks good, but please retur
|
while (![self areExpectationsFulfilled]) { |
- NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:startDate]; |
+ CFTimeInterval duration = CACurrentMediaTime() - startTime; |
if (duration > timeout) { |
- NSAssert(NO, @"Expectation timed out."); |
+ didErrorExp = YES; |
break; |
} |
[[NSRunLoop currentRunLoop] |
runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; |
} |
- handler(nil); |
+ handler(didErrorExp); |
} |
- (BOOL)areExpectationsFulfilled { |
@@ -137,7 +139,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 +205,7 @@ - (ARDAppClient *)createAppClientForRoomId:(NSString *)roomId |
messages:(NSArray *)messages |
messageHandler: |
(void (^)(ARDSignalingMessage *message))messageHandler |
- connectedHandler:(void (^)(void))connectedHandler { |
+ connectedHandler:(void (^)(NSString *))connectedHandler { |
tkchin_webrtc
2016/11/07 19:14:21
instead of passing the name of the method, just in
|
id turnClient = [self mockTURNClient]; |
id signalingChannel = [self mockSignalingChannelForRoomId:roomId |
clientId:clientId |
@@ -217,9 +219,13 @@ - (ARDAppClient *)createAppClientForRoomId:(NSString *)roomId |
id delegate = |
[OCMockObject niceMockForProtocol:@protocol(ARDAppClientDelegate)]; |
[[[delegate stub] andDo:^(NSInvocation *invocation) { |
- connectedHandler(); |
+ connectedHandler(NSStringFromSelector([invocation selector])); |
}] appClient:[OCMArg any] |
didChangeConnectionState:RTCIceConnectionStateConnected]; |
+ [[[delegate stub] andDo:^(NSInvocation *invocation) { |
+ connectedHandler(NSStringFromSelector([invocation selector])); |
+ }] appClient:[OCMArg any] |
+ didReceiveLocalVideoTrack:[OCMArg any]]; |
return [[ARDAppClient alloc] initWithRoomServerClient:roomServerClient |
signalingChannel:signalingChannel |
@@ -255,8 +261,10 @@ - (void)testSession { |
messageHandler:^(ARDSignalingMessage *message) { |
ARDAppClient *strongAnswerer = weakAnswerer; |
[strongAnswerer channel:strongAnswerer.channel didReceiveMessage:message]; |
- } connectedHandler:^{ |
- [callerConnectionExpectation fulfill]; |
+ } connectedHandler:^(NSString *connectedSelectorString){ |
+ if ([connectedSelectorString |
+ isEqualToString:@"appClient:didChangeConnectionState:"]) |
+ [callerConnectionExpectation fulfill]; |
}]; |
// TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion |
// crash in Debug. |
@@ -272,8 +280,10 @@ - (void)testSession { |
messageHandler:^(ARDSignalingMessage *message) { |
ARDAppClient *strongCaller = weakCaller; |
[strongCaller channel:strongCaller.channel didReceiveMessage:message]; |
- } connectedHandler:^{ |
- [answererConnectionExpectation fulfill]; |
+ } connectedHandler:^(NSString *connectedSelectorString){ |
+ if ([connectedSelectorString |
+ isEqualToString:@"appClient:didChangeConnectionState:"]) |
+ [answererConnectionExpectation fulfill]; |
}]; |
// TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion |
// crash in Debug. |
@@ -293,9 +303,48 @@ - (void)testSession { |
isAudioOnly:NO |
shouldMakeAecDump:NO |
shouldUseLevelControl:NO]; |
- [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { |
- if (error) { |
- NSLog(@"Expectations error: %@", error); |
+ [self waitForExpectationsWithTimeout:20 handler:^(BOOL didError) { |
+ if (didError) { |
+ 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."]; |
tkchin_webrtc
2016/11/07 19:14:21
indent 4
|
+ |
+ caller = [self createAppClientForRoomId:roomId |
+ clientId:callerId |
+ isInitiator:YES |
+ messages:[NSArray array] |
+ messageHandler:^(ARDSignalingMessage *message) { |
tkchin_webrtc
2016/11/07 19:14:21
please follow formatting as in other methods
do no
|
+ } |
+ connectedHandler:^(NSString *connectedSelectorString) { |
+ if ([connectedSelectorString |
+ isEqualToString:@"appClient:didReceiveLocalVideoTrack:"]) |
+ [callerConnectionExpectation fulfill]; |
+ }]; |
+ caller.defaultPeerConnectionConstraints = |
+ [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil |
tkchin_webrtc
2016/11/07 19:14:21
indent 4
|
+ optionalConstraints:nil]; |
+ |
+ // Kick off connection. |
+ [caller connectToRoomWithId:roomId |
+ isLoopback:NO |
+ isAudioOnly:NO |
+ shouldMakeAecDump:NO |
+ shouldUseLevelControl:NO]; |
+ [self waitForExpectationsWithTimeout:20 handler:^(BOOL didError) { |
+ if (didError) { |
+ EXPECT_TRUE(0); |
} |
}]; |
} |
@@ -318,7 +367,7 @@ - (void)testPreferVideoCodec { |
RTCSessionDescription *h264Desc = |
[ARDSDPUtils descriptionForDescription:desc |
preferredVideoCodec:@"H264"]; |
- EXPECT_TRUE([h264Desc.description isEqualToString:expectedSdp]); |
+ EXPECT_TRUE([h264Desc.description rangeOfString: expectedSdp].location != NSNotFound); |
tkchin_webrtc
2016/11/07 19:14:21
nit: no space after :
EXPECT_NE?
|
} |
@end |
@@ -340,6 +389,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 +406,7 @@ static void TearDownTestCase() { |
} |
} |
- |
+int main(int argc, char **argv) { |
+ ::testing::InitGoogleTest(&argc, argv); |
+ return RUN_ALL_TESTS(); |
+} |