OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/base/gunit.h" | |
12 #include "webrtc/base/ssladapter.h" | |
13 | |
11 #import <Foundation/Foundation.h> | 14 #import <Foundation/Foundation.h> |
tkchin_webrtc
2016/03/11 20:47:38
system libraries first (foundation, ocmock)
then
hjon_webrtc
2016/03/11 22:44:15
I also seem to recall #includes before #imports, c
tkchin_webrtc
2016/03/11 23:33:23
yeah. This looks good.
| |
12 #import <OCMock/OCMock.h> | 15 #import <OCMock/OCMock.h> |
16 #import "webrtc/api/objc/RTCMediaConstraints.h" | |
17 #import "webrtc/api/objc/RTCPeerConnectionFactory.h" | |
18 #import "webrtc/api/objc/RTCSessionDescription.h" | |
13 | 19 |
14 #import "ARDAppClient+Internal.h" | 20 #import "ARDAppClient+Internal.h" |
15 #import "ARDJoinResponse+Internal.h" | 21 #import "ARDJoinResponse+Internal.h" |
16 #import "ARDMessageResponse+Internal.h" | 22 #import "ARDMessageResponse+Internal.h" |
17 #import "ARDSDPUtils.h" | 23 #import "ARDSDPUtils.h" |
18 #import "RTCMediaConstraints.h" | |
19 #import "RTCPeerConnectionFactory.h" | |
20 #import "RTCSessionDescription.h" | |
21 | |
22 #include "webrtc/base/gunit.h" | |
23 #include "webrtc/base/ssladapter.h" | |
24 | 24 |
25 // These classes mimic XCTest APIs, to make eventual conversion to XCTest | 25 // These classes mimic XCTest APIs, to make eventual conversion to XCTest |
26 // easier. Conversion will happen once XCTest is supported well on build bots. | 26 // easier. Conversion will happen once XCTest is supported well on build bots. |
27 @interface ARDTestExpectation : NSObject | 27 @interface ARDTestExpectation : NSObject |
28 | 28 |
29 @property(nonatomic, readonly) NSString *description; | 29 @property(nonatomic, readonly) NSString *description; |
30 @property(nonatomic, readonly) BOOL isFulfilled; | 30 @property(nonatomic, readonly) BOOL isFulfilled; |
31 | 31 |
32 - (instancetype)initWithDescription:(NSString *)description; | 32 - (instancetype)initWithDescription:(NSString *)description; |
33 - (void)fulfill; | 33 - (void)fulfill; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 id roomServerClient = | 210 id roomServerClient = |
211 [self mockRoomServerClientForRoomId:roomId | 211 [self mockRoomServerClientForRoomId:roomId |
212 clientId:clientId | 212 clientId:clientId |
213 isInitiator:isInitiator | 213 isInitiator:isInitiator |
214 messages:messages | 214 messages:messages |
215 messageHandler:messageHandler]; | 215 messageHandler:messageHandler]; |
216 id delegate = | 216 id delegate = |
217 [OCMockObject niceMockForProtocol:@protocol(ARDAppClientDelegate)]; | 217 [OCMockObject niceMockForProtocol:@protocol(ARDAppClientDelegate)]; |
218 [[[delegate stub] andDo:^(NSInvocation *invocation) { | 218 [[[delegate stub] andDo:^(NSInvocation *invocation) { |
219 connectedHandler(); | 219 connectedHandler(); |
220 }] appClient:[OCMArg any] didChangeConnectionState:RTCICEConnectionConnected]; | 220 }] appClient:[OCMArg any] |
221 didChangeConnectionState:RTCIceConnectionStateConnected]; | |
221 | 222 |
222 return [[ARDAppClient alloc] initWithRoomServerClient:roomServerClient | 223 return [[ARDAppClient alloc] initWithRoomServerClient:roomServerClient |
223 signalingChannel:signalingChannel | 224 signalingChannel:signalingChannel |
224 turnClient:turnClient | 225 turnClient:turnClient |
225 delegate:delegate]; | 226 delegate:delegate]; |
226 } | 227 } |
227 | 228 |
228 // Tests that an ICE connection is established between two ARDAppClient objects | 229 // Tests that an ICE connection is established between two ARDAppClient objects |
229 // where one is set up as a caller and the other the answerer. Network | 230 // where one is set up as a caller and the other the answerer. Network |
230 // components are mocked out and messages are relayed directly from object to | 231 // components are mocked out and messages are relayed directly from object to |
231 // object. It's expected that both clients reach the RTCICEConnectionConnected | 232 // object. It's expected that both clients reach the |
232 // state within a reasonable amount of time. | 233 // RTCIceConnectionStateConnected state within a reasonable amount of time. |
233 - (void)testSession { | 234 - (void)testSession { |
234 // Need block arguments here because we're setting up a callbacks before we | 235 // Need block arguments here because we're setting up a callbacks before we |
235 // create the clients. | 236 // create the clients. |
236 ARDAppClient *caller = nil; | 237 ARDAppClient *caller = nil; |
237 ARDAppClient *answerer = nil; | 238 ARDAppClient *answerer = nil; |
238 __block __weak ARDAppClient *weakCaller = nil; | 239 __block __weak ARDAppClient *weakCaller = nil; |
239 __block __weak ARDAppClient *weakAnswerer = nil; | 240 __block __weak ARDAppClient *weakAnswerer = nil; |
240 NSString *roomId = @"testRoom"; | 241 NSString *roomId = @"testRoom"; |
241 NSString *callerId = @"testCallerId"; | 242 NSString *callerId = @"testCallerId"; |
242 NSString *answererId = @"testAnswererId"; | 243 NSString *answererId = @"testAnswererId"; |
243 | 244 |
244 ARDTestExpectation *callerConnectionExpectation = | 245 ARDTestExpectation *callerConnectionExpectation = |
245 [self expectationWithDescription:@"Caller PC connected."]; | 246 [self expectationWithDescription:@"Caller PC connected."]; |
246 ARDTestExpectation *answererConnectionExpectation = | 247 ARDTestExpectation *answererConnectionExpectation = |
247 [self expectationWithDescription:@"Answerer PC connected."]; | 248 [self expectationWithDescription:@"Answerer PC connected."]; |
248 | 249 |
249 caller = [self createAppClientForRoomId:roomId | 250 caller = [self createAppClientForRoomId:roomId |
250 clientId:callerId | 251 clientId:callerId |
251 isInitiator:YES | 252 isInitiator:YES |
252 messages:[NSArray array] | 253 messages:[NSArray array] |
253 messageHandler:^(ARDSignalingMessage *message) { | 254 messageHandler:^(ARDSignalingMessage *message) { |
254 ARDAppClient *strongAnswerer = weakAnswerer; | 255 ARDAppClient *strongAnswerer = weakAnswerer; |
255 [strongAnswerer channel:strongAnswerer.channel didReceiveMessage:message]; | 256 [strongAnswerer channel:strongAnswerer.channel didReceiveMessage:message]; |
256 } connectedHandler:^{ | 257 } connectedHandler:^{ |
257 [callerConnectionExpectation fulfill]; | 258 [callerConnectionExpectation fulfill]; |
258 }]; | 259 }]; |
259 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion | 260 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion |
260 // crash in Debug. | 261 // crash in Debug. |
261 caller.defaultPeerConnectionConstraints = [[RTCMediaConstraints alloc] init]; | 262 caller.defaultPeerConnectionConstraints = |
263 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil | |
264 optionalConstraints:nil]; | |
262 weakCaller = caller; | 265 weakCaller = caller; |
263 | 266 |
264 answerer = [self createAppClientForRoomId:roomId | 267 answerer = [self createAppClientForRoomId:roomId |
265 clientId:answererId | 268 clientId:answererId |
266 isInitiator:NO | 269 isInitiator:NO |
267 messages:[NSArray array] | 270 messages:[NSArray array] |
268 messageHandler:^(ARDSignalingMessage *message) { | 271 messageHandler:^(ARDSignalingMessage *message) { |
269 ARDAppClient *strongCaller = weakCaller; | 272 ARDAppClient *strongCaller = weakCaller; |
270 [strongCaller channel:strongCaller.channel didReceiveMessage:message]; | 273 [strongCaller channel:strongCaller.channel didReceiveMessage:message]; |
271 } connectedHandler:^{ | 274 } connectedHandler:^{ |
272 [answererConnectionExpectation fulfill]; | 275 [answererConnectionExpectation fulfill]; |
273 }]; | 276 }]; |
274 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion | 277 // TODO(tkchin): Figure out why DTLS-SRTP constraint causes thread assertion |
275 // crash in Debug. | 278 // crash in Debug. |
276 answerer.defaultPeerConnectionConstraints = | 279 answerer.defaultPeerConnectionConstraints = |
277 [[RTCMediaConstraints alloc] init]; | 280 [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil |
281 optionalConstraints:nil]; | |
278 weakAnswerer = answerer; | 282 weakAnswerer = answerer; |
279 | 283 |
280 // Kick off connection. | 284 // Kick off connection. |
281 [caller connectToRoomWithId:roomId isLoopback:NO isAudioOnly:NO]; | 285 [caller connectToRoomWithId:roomId isLoopback:NO isAudioOnly:NO]; |
282 [answerer connectToRoomWithId:roomId isLoopback:NO isAudioOnly:NO]; | 286 [answerer connectToRoomWithId:roomId isLoopback:NO isAudioOnly:NO]; |
283 [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { | 287 [self waitForExpectationsWithTimeout:20 handler:^(NSError *error) { |
284 if (error) { | 288 if (error) { |
285 NSLog(@"Expectations error: %@", error); | 289 NSLog(@"Expectations error: %@", error); |
286 } | 290 } |
287 }]; | 291 }]; |
288 } | 292 } |
289 | 293 |
290 @end | 294 @end |
291 | 295 |
292 @interface ARDSDPUtilsTest : ARDTestCase | 296 @interface ARDSDPUtilsTest : ARDTestCase |
293 - (void)testPreferVideoCodec; | 297 - (void)testPreferVideoCodec; |
294 @end | 298 @end |
295 | 299 |
296 @implementation ARDSDPUtilsTest | 300 @implementation ARDSDPUtilsTest |
297 | 301 |
298 - (void)testPreferVideoCodec { | 302 - (void)testPreferVideoCodec { |
299 NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120\n" | 303 NSString *sdp = @("m=video 9 RTP/SAVPF 100 116 117 96 120\n" |
300 "a=rtpmap:120 H264/90000\n"); | 304 "a=rtpmap:120 H264/90000\n"); |
301 NSString *expectedSdp = @("m=video 9 RTP/SAVPF 120 100 116 117 96\n" | 305 NSString *expectedSdp = @("m=video 9 RTP/SAVPF 120 100 116 117 96\n" |
302 "a=rtpmap:120 H264/90000\n"); | 306 "a=rtpmap:120 H264/90000\n"); |
303 RTCSessionDescription* desc = | 307 RTCSessionDescription* desc = |
304 [[RTCSessionDescription alloc] initWithType:@"offer" sdp:sdp]; | 308 [[RTCSessionDescription alloc] initWithType:RTCSdpTypeOffer sdp:sdp]; |
305 RTCSessionDescription *h264Desc = | 309 RTCSessionDescription *h264Desc = |
306 [ARDSDPUtils descriptionForDescription:desc | 310 [ARDSDPUtils descriptionForDescription:desc |
307 preferredVideoCodec:@"H264"]; | 311 preferredVideoCodec:@"H264"]; |
308 EXPECT_TRUE([h264Desc.description isEqualToString:expectedSdp]); | 312 EXPECT_TRUE([h264Desc.description isEqualToString:expectedSdp]); |
309 } | 313 } |
310 | 314 |
311 @end | 315 @end |
312 | 316 |
313 class SignalingTest : public ::testing::Test { | 317 class SignalingTest : public ::testing::Test { |
314 protected: | 318 protected: |
(...skipping 13 matching lines...) Expand all Loading... | |
328 } | 332 } |
329 | 333 |
330 TEST_F(SignalingTest, SDPTest) { | 334 TEST_F(SignalingTest, SDPTest) { |
331 @autoreleasepool { | 335 @autoreleasepool { |
332 ARDSDPUtilsTest *test = [[ARDSDPUtilsTest alloc] init]; | 336 ARDSDPUtilsTest *test = [[ARDSDPUtilsTest alloc] init]; |
333 [test testPreferVideoCodec]; | 337 [test testPreferVideoCodec]; |
334 } | 338 } |
335 } | 339 } |
336 | 340 |
337 | 341 |
OLD | NEW |