OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 - (void)expectStateChange:(RTCDataChannelState)state { | 132 - (void)expectStateChange:(RTCDataChannelState)state { |
133 [_expectedStateChanges addObject:@(state)]; | 133 [_expectedStateChanges addObject:@(state)]; |
134 } | 134 } |
135 | 135 |
136 - (void)expectMessage:(NSData*)message isBinary:(BOOL)isBinary { | 136 - (void)expectMessage:(NSData*)message isBinary:(BOOL)isBinary { |
137 RTCDataBuffer* buffer = [[RTCDataBuffer alloc] initWithData:message | 137 RTCDataBuffer* buffer = [[RTCDataBuffer alloc] initWithData:message |
138 isBinary:isBinary]; | 138 isBinary:isBinary]; |
139 [_expectedMessages addObject:buffer]; | 139 [_expectedMessages addObject:buffer]; |
140 } | 140 } |
141 | 141 |
142 - (void)waitForAllExpectationsToBeSatisfied { | 142 - (BOOL)waitForAllExpectationsToBeSatisfiedWithTimeout:(NSTimeInterval)timeout { |
| 143 NSParameterAssert(timeout >= 0); |
143 // TODO (fischman): Revisit. Keeping in sync with the Java version, but | 144 // TODO (fischman): Revisit. Keeping in sync with the Java version, but |
144 // polling is not optimal. | 145 // polling is not optimal. |
145 // https://code.google.com/p/libjingle/source/browse/trunk/talk/app/webrtc/jav
atests/src/org/webrtc/PeerConnectionTest.java?line=212#212 | 146 // https://code.google.com/p/libjingle/source/browse/trunk/talk/app/webrtc/jav
atests/src/org/webrtc/PeerConnectionTest.java?line=212#212 |
| 147 NSDate *startTime = [NSDate date]; |
146 while (![self areAllExpectationsSatisfied]) { | 148 while (![self areAllExpectationsSatisfied]) { |
| 149 if (startTime.timeIntervalSinceNow < -timeout) { |
| 150 return NO; |
| 151 } |
147 [[NSRunLoop currentRunLoop] | 152 [[NSRunLoop currentRunLoop] |
148 runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; | 153 runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]]; |
149 } | 154 } |
| 155 return YES; |
150 } | 156 } |
151 | 157 |
152 #pragma mark - RTCPeerConnectionDelegate methods | 158 #pragma mark - RTCPeerConnectionDelegate methods |
153 | 159 |
154 - (void)peerConnection:(RTCPeerConnection*)peerConnection | 160 - (void)peerConnection:(RTCPeerConnection*)peerConnection |
155 signalingStateChanged:(RTCSignalingState)stateChanged { | 161 signalingStateChanged:(RTCSignalingState)stateChanged { |
156 int expectedState = [self popFirstElementAsInt:_expectedSignalingChanges]; | 162 int expectedState = [self popFirstElementAsInt:_expectedSignalingChanges]; |
157 NSString* message = | 163 NSString* message = |
158 [NSString stringWithFormat:@"RTCPeerConnectionDelegate::" | 164 [NSString stringWithFormat:@"RTCPeerConnectionDelegate::" |
159 @"onSignalingStateChange [%d] expected[%d]", | 165 @"onSignalingStateChange [%d] expected[%d]", |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 @"Unexpected message received"); | 248 @"Unexpected message received"); |
243 RTCDataBuffer* expectedBuffer = [_expectedMessages objectAtIndex:0]; | 249 RTCDataBuffer* expectedBuffer = [_expectedMessages objectAtIndex:0]; |
244 NSAssert(expectedBuffer.isBinary == buffer.isBinary, | 250 NSAssert(expectedBuffer.isBinary == buffer.isBinary, |
245 @"Buffer isBinary should match"); | 251 @"Buffer isBinary should match"); |
246 NSAssert([expectedBuffer.data isEqual:buffer.data], | 252 NSAssert([expectedBuffer.data isEqual:buffer.data], |
247 @"Buffer data should match"); | 253 @"Buffer data should match"); |
248 [_expectedMessages removeObjectAtIndex:0]; | 254 [_expectedMessages removeObjectAtIndex:0]; |
249 } | 255 } |
250 | 256 |
251 @end | 257 @end |
OLD | NEW |