@@ -245,4 +245,157 @@ final class PhotoCaptureTests: XCTestCase {
245245
246246 waitForExpectations ( timeout : 30 , handler : nil )
247247 }
248+
249+ func testCaptureToFile_setsMaxPhotoDimensionsWhenResolutionPresetIsMax ( ) throws {
250+ guard #available( iOS 16 . 0 , * ) else {
251+ throw XCTSkip ( " maxPhotoDimensions requires iOS 16. " )
252+ }
253+
254+ let settingsExpectation = expectation (
255+ description : " Must set maxPhotoDimensions to the output's configured value. " )
256+ let captureSessionQueue = DispatchQueue ( label : " capture_session_queue " )
257+ captureSessionQueue . setSpecific (
258+ key : captureSessionQueueSpecificKey , value : captureSessionQueueSpecificValue )
259+
260+ let configuration = CameraTestUtils . createTestCameraConfiguration ( )
261+ configuration . captureSessionQueue = captureSessionQueue
262+ configuration . mediaSettings = CameraTestUtils . createDefaultMediaSettings (
263+ resolutionPreset : PlatformResolutionPreset . max )
264+ let cam = CameraTestUtils . createTestCamera ( configuration )
265+
266+ let expectedDimensions = CMVideoDimensions ( width : 4032 , height : 3024 )
267+ let mockOutput = MockCapturePhotoOutput ( )
268+ mockOutput . maxPhotoDimensions = expectedDimensions
269+ mockOutput . capturePhotoWithSettingsStub = { settings , photoDelegate in
270+ XCTAssertEqual ( settings . maxPhotoDimensions . width , expectedDimensions . width )
271+ XCTAssertEqual ( settings . maxPhotoDimensions . height , expectedDimensions . height )
272+ let delegate = cam . inProgressSavePhotoDelegates [ settings . uniqueID ]
273+ let ioQueue = DispatchQueue ( label : " io_queue " )
274+ ioQueue . async {
275+ delegate ? . completionHandler ( delegate ? . filePath , nil )
276+ }
277+ settingsExpectation . fulfill ( )
278+ }
279+ cam . capturePhotoOutput = mockOutput
280+
281+ captureSessionQueue . async {
282+ cam . captureToFile { _ in }
283+ }
284+
285+ waitForExpectations ( timeout : 30 , handler : nil )
286+ }
287+
288+ func testCaptureToFile_doesNotSetMaxPhotoDimensionsWhenResolutionPresetIsNotMax ( ) throws {
289+ guard #available( iOS 16 . 0 , * ) else {
290+ throw XCTSkip ( " maxPhotoDimensions requires iOS 16. " )
291+ }
292+
293+ let settingsExpectation = expectation (
294+ description : " Must leave maxPhotoDimensions unset for non-max presets. " )
295+ let captureSessionQueue = DispatchQueue ( label : " capture_session_queue " )
296+ captureSessionQueue . setSpecific (
297+ key : captureSessionQueueSpecificKey , value : captureSessionQueueSpecificValue )
298+ let cam = createCam ( with : captureSessionQueue )
299+
300+ let mockOutput = MockCapturePhotoOutput ( )
301+ mockOutput . maxPhotoDimensions = CMVideoDimensions ( width : 4032 , height : 3024 )
302+ mockOutput . capturePhotoWithSettingsStub = { settings , photoDelegate in
303+ XCTAssertEqual ( settings . maxPhotoDimensions . width , 0 )
304+ XCTAssertEqual ( settings . maxPhotoDimensions . height , 0 )
305+ let delegate = cam . inProgressSavePhotoDelegates [ settings . uniqueID ]
306+ let ioQueue = DispatchQueue ( label : " io_queue " )
307+ ioQueue . async {
308+ delegate ? . completionHandler ( delegate ? . filePath , nil )
309+ }
310+ settingsExpectation . fulfill ( )
311+ }
312+ cam . capturePhotoOutput = mockOutput
313+
314+ captureSessionQueue . async {
315+ cam . captureToFile { _ in }
316+ }
317+
318+ waitForExpectations ( timeout : 30 , handler : nil )
319+ }
320+
321+ func testCaptureToFile_setsMaxPhotoDimensionsWhenFileFormatIsHeif ( ) throws {
322+ guard #available( iOS 16 . 0 , * ) else {
323+ throw XCTSkip ( " maxPhotoDimensions requires iOS 16. " )
324+ }
325+
326+ let settingsExpectation = expectation (
327+ description : " Must set maxPhotoDimensions on the HEIF settings instance. " )
328+ let captureSessionQueue = DispatchQueue ( label : " capture_session_queue " )
329+ captureSessionQueue . setSpecific (
330+ key : captureSessionQueueSpecificKey , value : captureSessionQueueSpecificValue )
331+
332+ let configuration = CameraTestUtils . createTestCameraConfiguration ( )
333+ configuration . captureSessionQueue = captureSessionQueue
334+ configuration . mediaSettings = CameraTestUtils . createDefaultMediaSettings (
335+ resolutionPreset : PlatformResolutionPreset . max )
336+ let cam = CameraTestUtils . createTestCamera ( configuration )
337+ cam . setImageFileFormat ( PlatformImageFileFormat . heif )
338+
339+ let expectedDimensions = CMVideoDimensions ( width : 4032 , height : 3024 )
340+ let mockOutput = MockCapturePhotoOutput ( )
341+ mockOutput . availablePhotoCodecTypes = [ AVVideoCodecType . hevc ]
342+ mockOutput . maxPhotoDimensions = expectedDimensions
343+ mockOutput . capturePhotoWithSettingsStub = { settings , photoDelegate in
344+ XCTAssertEqual ( settings . maxPhotoDimensions . width , expectedDimensions . width )
345+ XCTAssertEqual ( settings . maxPhotoDimensions . height , expectedDimensions . height )
346+ let delegate = cam . inProgressSavePhotoDelegates [ settings . uniqueID ]
347+ let ioQueue = DispatchQueue ( label : " io_queue " )
348+ ioQueue . async {
349+ delegate ? . completionHandler ( delegate ? . filePath , nil )
350+ }
351+ settingsExpectation . fulfill ( )
352+ }
353+ cam . capturePhotoOutput = mockOutput
354+
355+ captureSessionQueue . async {
356+ cam . captureToFile { _ in }
357+ }
358+
359+ waitForExpectations ( timeout : 30 , handler : nil )
360+ }
361+
362+ func testCaptureToFile_setsMaxPhotoDimensionsWhenJpegQualityIsBelow100 ( ) throws {
363+ guard #available( iOS 16 . 0 , * ) else {
364+ throw XCTSkip ( " maxPhotoDimensions requires iOS 16. " )
365+ }
366+
367+ let settingsExpectation = expectation (
368+ description : " Must set maxPhotoDimensions on the reduced-quality JPEG settings instance. " )
369+ let captureSessionQueue = DispatchQueue ( label : " capture_session_queue " )
370+ captureSessionQueue . setSpecific (
371+ key : captureSessionQueueSpecificKey , value : captureSessionQueueSpecificValue )
372+
373+ let configuration = CameraTestUtils . createTestCameraConfiguration ( )
374+ configuration . captureSessionQueue = captureSessionQueue
375+ configuration . mediaSettings = CameraTestUtils . createDefaultMediaSettings (
376+ resolutionPreset : PlatformResolutionPreset . max )
377+ let cam = CameraTestUtils . createTestCamera ( configuration )
378+ cam . setJpegImageQuality ( 80 )
379+
380+ let expectedDimensions = CMVideoDimensions ( width : 4032 , height : 3024 )
381+ let mockOutput = MockCapturePhotoOutput ( )
382+ mockOutput . maxPhotoDimensions = expectedDimensions
383+ mockOutput . capturePhotoWithSettingsStub = { settings , photoDelegate in
384+ XCTAssertEqual ( settings . maxPhotoDimensions . width , expectedDimensions . width )
385+ XCTAssertEqual ( settings . maxPhotoDimensions . height , expectedDimensions . height )
386+ let delegate = cam . inProgressSavePhotoDelegates [ settings . uniqueID ]
387+ let ioQueue = DispatchQueue ( label : " io_queue " )
388+ ioQueue . async {
389+ delegate ? . completionHandler ( delegate ? . filePath , nil )
390+ }
391+ settingsExpectation . fulfill ( )
392+ }
393+ cam . capturePhotoOutput = mockOutput
394+
395+ captureSessionQueue . async {
396+ cam . captureToFile { _ in }
397+ }
398+
399+ waitForExpectations ( timeout : 30 , handler : nil )
400+ }
248401}
0 commit comments