Finish converting RTCCameraVideoCapturerTests to XCTest
Failed gunit assertions in these XCTestCase classes cannot result in failed tests. Bug: webrtc:8382 Change-Id: I47b50b74f60029fafeff4ca885775482a85dfdd3 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/288603 Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Commit-Queue: Kári Helgason <kthelgason@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38995}
This commit is contained in:
parent
b7f9113b72
commit
8bec181bfc
@ -15,14 +15,20 @@
|
|||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "rtc_base/gunit.h"
|
|
||||||
|
|
||||||
#import "base/RTCVideoFrame.h"
|
#import "base/RTCVideoFrame.h"
|
||||||
#import "components/capturer/RTCCameraVideoCapturer.h"
|
#import "components/capturer/RTCCameraVideoCapturer.h"
|
||||||
#import "helpers/AVCaptureSession+DevicePosition.h"
|
#import "helpers/AVCaptureSession+DevicePosition.h"
|
||||||
#import "helpers/RTCDispatcher.h"
|
#import "helpers/RTCDispatcher.h"
|
||||||
#import "helpers/scoped_cftyperef.h"
|
#import "helpers/scoped_cftyperef.h"
|
||||||
|
|
||||||
|
#define WAIT(timeoutMs) \
|
||||||
|
do { \
|
||||||
|
id expectation = [[XCTestExpectation alloc] initWithDescription:@"Dummy"]; \
|
||||||
|
XCTWaiterResult res = [XCTWaiter waitForExpectations:@[ expectation ] \
|
||||||
|
timeout:timeoutMs / 1000.0]; \
|
||||||
|
XCTAssertEqual(XCTWaiterResultTimedOut, res); \
|
||||||
|
} while (false);
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
// Helper method.
|
// Helper method.
|
||||||
CMSampleBufferRef createTestSampleBufferRef() {
|
CMSampleBufferRef createTestSampleBufferRef() {
|
||||||
@ -107,19 +113,19 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
|
|
||||||
- (void)testSetupSession {
|
- (void)testSetupSession {
|
||||||
AVCaptureSession *session = self.capturer.captureSession;
|
AVCaptureSession *session = self.capturer.captureSession;
|
||||||
EXPECT_TRUE(session != nil);
|
XCTAssertTrue(session != nil);
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
EXPECT_EQ(session.sessionPreset, AVCaptureSessionPresetInputPriority);
|
XCTAssertEqual(session.sessionPreset, AVCaptureSessionPresetInputPriority);
|
||||||
EXPECT_EQ(session.usesApplicationAudioSession, NO);
|
XCTAssertEqual(session.usesApplicationAudioSession, NO);
|
||||||
#endif
|
#endif
|
||||||
EXPECT_EQ(session.outputs.count, 1u);
|
XCTAssertEqual(session.outputs.count, 1u);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testSetupSessionOutput {
|
- (void)testSetupSessionOutput {
|
||||||
AVCaptureVideoDataOutput *videoOutput = self.capturer.captureSession.outputs[0];
|
AVCaptureVideoDataOutput *videoOutput = self.capturer.captureSession.outputs[0];
|
||||||
EXPECT_EQ(videoOutput.alwaysDiscardsLateVideoFrames, NO);
|
XCTAssertEqual(videoOutput.alwaysDiscardsLateVideoFrames, NO);
|
||||||
EXPECT_EQ(videoOutput.sampleBufferDelegate, self.capturer);
|
XCTAssertEqual(videoOutput.sampleBufferDelegate, self.capturer);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testSupportedFormatsForDevice {
|
- (void)testSupportedFormatsForDevice {
|
||||||
@ -152,10 +158,10 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
[RTC_OBJC_TYPE(RTCCameraVideoCapturer) supportedFormatsForDevice:self.deviceMock];
|
[RTC_OBJC_TYPE(RTCCameraVideoCapturer) supportedFormatsForDevice:self.deviceMock];
|
||||||
|
|
||||||
// then
|
// then
|
||||||
EXPECT_EQ(supportedFormats.count, 3u);
|
XCTAssertEqual(supportedFormats.count, 3u);
|
||||||
EXPECT_TRUE([supportedFormats containsObject:validFormat1]);
|
XCTAssertTrue([supportedFormats containsObject:validFormat1]);
|
||||||
EXPECT_TRUE([supportedFormats containsObject:validFormat2]);
|
XCTAssertTrue([supportedFormats containsObject:validFormat2]);
|
||||||
EXPECT_TRUE([supportedFormats containsObject:invalidFormat]);
|
XCTAssertTrue([supportedFormats containsObject:invalidFormat]);
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
[validFormat1 stopMocking];
|
[validFormat1 stopMocking];
|
||||||
@ -180,9 +186,12 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
[self.delegateMock verify];
|
[self.delegateMock verify];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// See crbug.com/1404878 - XCTExpectFailure and XCTSkip are considered failures
|
||||||
|
|
||||||
- (void)testDelegateCallbackWithValidBufferAndOrientationUpdate {
|
- (void)testDelegateCallbackWithValidBufferAndOrientationUpdate {
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
XCTExpectFailure(@"Setting orientation on UIDevice is not supported");
|
||||||
[UIDevice.currentDevice setValue:@(UIDeviceOrientationPortraitUpsideDown) forKey:@"orientation"];
|
[UIDevice.currentDevice setValue:@(UIDeviceOrientationPortraitUpsideDown) forKey:@"orientation"];
|
||||||
CMSampleBufferRef sampleBuffer = createTestSampleBufferRef();
|
CMSampleBufferRef sampleBuffer = createTestSampleBufferRef();
|
||||||
|
|
||||||
@ -190,7 +199,7 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
[[self.delegateMock expect] capturer:self.capturer
|
[[self.delegateMock expect] capturer:self.capturer
|
||||||
didCaptureVideoFrame:[OCMArg checkWithBlock:^BOOL(RTC_OBJC_TYPE(RTCVideoFrame) *
|
didCaptureVideoFrame:[OCMArg checkWithBlock:^BOOL(RTC_OBJC_TYPE(RTCVideoFrame) *
|
||||||
expectedFrame) {
|
expectedFrame) {
|
||||||
EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_270);
|
XCTAssertEqual(expectedFrame.rotation, RTCVideoRotation_270);
|
||||||
return YES;
|
return YES;
|
||||||
}]];
|
}]];
|
||||||
|
|
||||||
@ -199,7 +208,7 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
[center postNotificationName:UIDeviceOrientationDidChangeNotification object:nil];
|
[center postNotificationName:UIDeviceOrientationDidChangeNotification object:nil];
|
||||||
|
|
||||||
// We need to wait for the dispatch to finish.
|
// We need to wait for the dispatch to finish.
|
||||||
WAIT(0, 1000);
|
WAIT(1000);
|
||||||
|
|
||||||
[self.capturer captureOutput:self.capturer.captureSession.outputs[0]
|
[self.capturer captureOutput:self.capturer.captureSession.outputs[0]
|
||||||
didOutputSampleBuffer:sampleBuffer
|
didOutputSampleBuffer:sampleBuffer
|
||||||
@ -226,6 +235,7 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
OCMStub(inputPortMock.device).andReturn(captureDeviceMock);
|
OCMStub(inputPortMock.device).andReturn(captureDeviceMock);
|
||||||
OCMStub(captureDeviceMock.position).andReturn(camera);
|
OCMStub(captureDeviceMock.position).andReturn(camera);
|
||||||
|
|
||||||
|
XCTExpectFailure(@"Setting orientation on UIDevice is not supported");
|
||||||
[UIDevice.currentDevice setValue:@(deviceOrientation) forKey:@"orientation"];
|
[UIDevice.currentDevice setValue:@(deviceOrientation) forKey:@"orientation"];
|
||||||
|
|
||||||
CMSampleBufferRef sampleBuffer = createTestSampleBufferRef();
|
CMSampleBufferRef sampleBuffer = createTestSampleBufferRef();
|
||||||
@ -235,15 +245,15 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
expectedFrame) {
|
expectedFrame) {
|
||||||
if (camera == AVCaptureDevicePositionFront) {
|
if (camera == AVCaptureDevicePositionFront) {
|
||||||
if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {
|
if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {
|
||||||
EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_180);
|
XCTAssertEqual(expectedFrame.rotation, RTCVideoRotation_180);
|
||||||
} else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {
|
} else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {
|
||||||
EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_0);
|
XCTAssertEqual(expectedFrame.rotation, RTCVideoRotation_0);
|
||||||
}
|
}
|
||||||
} else if (camera == AVCaptureDevicePositionBack) {
|
} else if (camera == AVCaptureDevicePositionBack) {
|
||||||
if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {
|
if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {
|
||||||
EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_0);
|
XCTAssertEqual(expectedFrame.rotation, RTCVideoRotation_0);
|
||||||
} else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {
|
} else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {
|
||||||
EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_180);
|
XCTAssertEqual(expectedFrame.rotation, RTCVideoRotation_180);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return YES;
|
return YES;
|
||||||
@ -253,7 +263,7 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
[center postNotificationName:UIDeviceOrientationDidChangeNotification object:nil];
|
[center postNotificationName:UIDeviceOrientationDidChangeNotification object:nil];
|
||||||
|
|
||||||
// We need to wait for the dispatch to finish.
|
// We need to wait for the dispatch to finish.
|
||||||
WAIT(0, 1000);
|
WAIT(1000);
|
||||||
|
|
||||||
[self.capturer captureOutput:self.capturer.captureSession.outputs[0]
|
[self.capturer captureOutput:self.capturer.captureSession.outputs[0]
|
||||||
didOutputSampleBuffer:sampleBuffer
|
didOutputSampleBuffer:sampleBuffer
|
||||||
@ -285,6 +295,8 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
withOrientation:UIDeviceOrientationLandscapeRight];
|
withOrientation:UIDeviceOrientationLandscapeRight];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
- (void)setExif:(CMSampleBufferRef)sampleBuffer {
|
- (void)setExif:(CMSampleBufferRef)sampleBuffer {
|
||||||
rtc::ScopedCFTypeRef<CFMutableDictionaryRef> exif(CFDictionaryCreateMutable(
|
rtc::ScopedCFTypeRef<CFMutableDictionaryRef> exif(CFDictionaryCreateMutable(
|
||||||
kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
|
kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
|
||||||
@ -292,6 +304,9 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
CMSetAttachment(sampleBuffer, CFSTR("{Exif}"), exif.get(), kCMAttachmentMode_ShouldPropagate);
|
CMSetAttachment(sampleBuffer, CFSTR("{Exif}"), exif.get(), kCMAttachmentMode_ShouldPropagate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// See crbug.com/1404878 - XCTExpectFailure and XCTSkip are considered failures
|
||||||
|
|
||||||
- (void)testRotationFrame {
|
- (void)testRotationFrame {
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
// Mock the AVCaptureConnection as we will get the camera position from the connection's
|
// Mock the AVCaptureConnection as we will get the camera position from the connection's
|
||||||
@ -306,6 +321,7 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
OCMStub(inputPortMock.device).andReturn(captureDeviceMock);
|
OCMStub(inputPortMock.device).andReturn(captureDeviceMock);
|
||||||
OCMStub(captureDeviceMock.position).andReturn(AVCaptureDevicePositionFront);
|
OCMStub(captureDeviceMock.position).andReturn(AVCaptureDevicePositionFront);
|
||||||
|
|
||||||
|
XCTExpectFailure(@"Setting orientation on UIDevice is not supported");
|
||||||
[UIDevice.currentDevice setValue:@(UIDeviceOrientationLandscapeLeft) forKey:@"orientation"];
|
[UIDevice.currentDevice setValue:@(UIDeviceOrientationLandscapeLeft) forKey:@"orientation"];
|
||||||
|
|
||||||
CMSampleBufferRef sampleBuffer = createTestSampleBufferRef();
|
CMSampleBufferRef sampleBuffer = createTestSampleBufferRef();
|
||||||
@ -315,7 +331,7 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
expectedFrame) {
|
expectedFrame) {
|
||||||
// Front camera and landscape left should return 180. But the frame's exif
|
// Front camera and landscape left should return 180. But the frame's exif
|
||||||
// we add below says its from the back camera, so rotation should be 0.
|
// we add below says its from the back camera, so rotation should be 0.
|
||||||
EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_0);
|
XCTAssertEqual(expectedFrame.rotation, RTCVideoRotation_0);
|
||||||
return YES;
|
return YES;
|
||||||
}]];
|
}]];
|
||||||
|
|
||||||
@ -323,7 +339,7 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
[center postNotificationName:UIDeviceOrientationDidChangeNotification object:nil];
|
[center postNotificationName:UIDeviceOrientationDidChangeNotification object:nil];
|
||||||
|
|
||||||
// We need to wait for the dispatch to finish.
|
// We need to wait for the dispatch to finish.
|
||||||
WAIT(0, 1000);
|
WAIT(1000);
|
||||||
|
|
||||||
[self setExif:sampleBuffer];
|
[self setExif:sampleBuffer];
|
||||||
|
|
||||||
@ -336,6 +352,8 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
- (void)testImageExif {
|
- (void)testImageExif {
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
CMSampleBufferRef sampleBuffer = createTestSampleBufferRef();
|
CMSampleBufferRef sampleBuffer = createTestSampleBufferRef();
|
||||||
@ -343,7 +361,7 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
|
|
||||||
AVCaptureDevicePosition cameraPosition = [AVCaptureSession
|
AVCaptureDevicePosition cameraPosition = [AVCaptureSession
|
||||||
devicePositionForSampleBuffer:sampleBuffer];
|
devicePositionForSampleBuffer:sampleBuffer];
|
||||||
EXPECT_EQ(cameraPosition, AVCaptureDevicePositionBack);
|
XCTAssertEqual(cameraPosition, AVCaptureDevicePositionBack);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,7 +468,7 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
format:format
|
format:format
|
||||||
fps:30
|
fps:30
|
||||||
completionHandler:^(NSError *error) {
|
completionHandler:^(NSError *error) {
|
||||||
EXPECT_EQ(error, nil);
|
XCTAssertEqual(error, nil);
|
||||||
completedStart = YES;
|
completedStart = YES;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
@ -463,8 +481,8 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
dispatch_semaphore_wait(completedStopSemaphore,
|
dispatch_semaphore_wait(completedStopSemaphore,
|
||||||
dispatch_time(DISPATCH_TIME_NOW, 15.0 * NSEC_PER_SEC));
|
dispatch_time(DISPATCH_TIME_NOW, 15.0 * NSEC_PER_SEC));
|
||||||
OCMVerifyAllWithDelay(_captureSessionMock, 15);
|
OCMVerifyAllWithDelay(_captureSessionMock, 15);
|
||||||
EXPECT_TRUE(completedStart);
|
XCTAssertTrue(completedStart);
|
||||||
EXPECT_TRUE(completedStop);
|
XCTAssertTrue(completedStop);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testStartCaptureFailingToLockForConfigurationWithCallback {
|
- (void)testStartCaptureFailingToLockForConfigurationWithCallback {
|
||||||
@ -495,8 +513,8 @@ CMSampleBufferRef createTestSampleBufferRef() {
|
|||||||
|
|
||||||
long ret = dispatch_semaphore_wait(completedStartSemaphore,
|
long ret = dispatch_semaphore_wait(completedStartSemaphore,
|
||||||
dispatch_time(DISPATCH_TIME_NOW, 15.0 * NSEC_PER_SEC));
|
dispatch_time(DISPATCH_TIME_NOW, 15.0 * NSEC_PER_SEC));
|
||||||
EXPECT_EQ(ret, 0);
|
XCTAssertEqual(ret, 0);
|
||||||
EXPECT_EQ(callbackError, errorMock);
|
XCTAssertEqual(callbackError, errorMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user