Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 5bae312

Browse files
committed
[camera]add unit test for flash mode related functions
1 parent 4a1c7be commit 5bae312

File tree

7 files changed

+58
-16
lines changed

7 files changed

+58
-16
lines changed

packages/camera/camera/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
## NEXT
2+
3+
* Minor iOS internal code cleanup related to flash mode.
4+
15
## 0.9.4+8
26

37
* Fixes a bug where ImageFormatGroup was ignored in `startImageStream` on iOS.
48

59
## 0.9.4+7
610

711
* Fixes a crash in iOS when passing null queue pointer into AVFoundation API due to race condition.
8-
* Minor iOS internal code cleanup.
12+
* Minor iOS internal code cleanup related to dispatch queue.
913

1014
## 0.9.4+6
1115

packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
2323
E01EE4A82799F3A5008C1950 /* QueueHelperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E01EE4A72799F3A5008C1950 /* QueueHelperTests.m */; };
2424
E032F250279F5E94009E9028 /* CameraCaptureSessionQueueRaceConditionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E032F24F279F5E94009E9028 /* CameraCaptureSessionQueueRaceConditionTests.m */; };
25+
E032F2A727A0BF2D009E9028 /* FlashModeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E032F2A627A0BF2D009E9028 /* FlashModeTests.m */; };
2526
E0C6E2002770F01A00EA6AA3 /* ThreadSafeMethodChannelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E0C6E1FD2770F01A00EA6AA3 /* ThreadSafeMethodChannelTests.m */; };
2627
E0C6E2012770F01A00EA6AA3 /* ThreadSafeTextureRegistryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E0C6E1FE2770F01A00EA6AA3 /* ThreadSafeTextureRegistryTests.m */; };
2728
E0C6E2022770F01A00EA6AA3 /* ThreadSafeEventChannelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E0C6E1FF2770F01A00EA6AA3 /* ThreadSafeEventChannelTests.m */; };
@@ -81,6 +82,7 @@
8182
A24F9E418BA48BCC7409B117 /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = "<group>"; };
8283
E01EE4A72799F3A5008C1950 /* QueueHelperTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QueueHelperTests.m; sourceTree = "<group>"; };
8384
E032F24F279F5E94009E9028 /* CameraCaptureSessionQueueRaceConditionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CameraCaptureSessionQueueRaceConditionTests.m; sourceTree = "<group>"; };
85+
E032F2A627A0BF2D009E9028 /* FlashModeTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FlashModeTests.m; sourceTree = "<group>"; };
8486
E0C6E1FD2770F01A00EA6AA3 /* ThreadSafeMethodChannelTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThreadSafeMethodChannelTests.m; sourceTree = "<group>"; };
8587
E0C6E1FE2770F01A00EA6AA3 /* ThreadSafeTextureRegistryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThreadSafeTextureRegistryTests.m; sourceTree = "<group>"; };
8688
E0C6E1FF2770F01A00EA6AA3 /* ThreadSafeEventChannelTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThreadSafeEventChannelTests.m; sourceTree = "<group>"; };
@@ -125,6 +127,7 @@
125127
F6EE622E2710A6FC00905E4A /* MockFLTThreadSafeFlutterResult.m */,
126128
F63F9EED27143B19002479BF /* MockFLTThreadSafeFlutterResult.h */,
127129
E032F24F279F5E94009E9028 /* CameraCaptureSessionQueueRaceConditionTests.m */,
130+
E032F2A627A0BF2D009E9028 /* FlashModeTests.m */,
128131
);
129132
path = RunnerTests;
130133
sourceTree = "<group>";
@@ -388,6 +391,7 @@
388391
buildActionMask = 2147483647;
389392
files = (
390393
03F6F8B226CBB4670024B8D3 /* ThreadSafeFlutterResultTests.m in Sources */,
394+
E032F2A727A0BF2D009E9028 /* FlashModeTests.m in Sources */,
391395
033B94BE269C40A200B4DF97 /* CameraMethodChannelTests.m in Sources */,
392396
03BB766B2665316900CE5A93 /* CameraFocusTests.m in Sources */,
393397
E487C86026D686A10034AC92 /* CameraPreviewPauseTests.m in Sources */,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import <XCTest/XCTest.h>
6+
#import "FlashMode.h"
7+
8+
@interface FlashModeTests : XCTestCase
9+
10+
@end
11+
12+
@implementation FlashModeTests
13+
14+
- (void)testGetFlashModeForString {
15+
XCTAssertEqual(FlashModeOff, getFlashModeForString(@"off"));
16+
XCTAssertEqual(FlashModeAuto, getFlashModeForString(@"auto"));
17+
XCTAssertEqual(FlashModeAlways, getFlashModeForString(@"always"));
18+
XCTAssertEqual(FlashModeTorch, getFlashModeForString(@"torch"));
19+
XCTAssertThrows(getFlashModeForString(@"unkwown"));
20+
}
21+
22+
- (void)testGetAVCaptureFlashModeForFlashMode {
23+
XCTAssertEqual(AVCaptureFlashModeOff, getAVCaptureFlashModeForFlashMode(FlashModeOff));
24+
XCTAssertEqual(AVCaptureFlashModeAuto, getAVCaptureFlashModeForFlashMode(FlashModeAuto));
25+
XCTAssertEqual(AVCaptureFlashModeOn, getAVCaptureFlashModeForFlashMode(FlashModeAlways));
26+
XCTAssertEqual(-1, getAVCaptureFlashModeForFlashMode(FlashModeTorch));
27+
}
28+
29+
@end

packages/camera/camera/ios/Classes/CameraPlugin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
#import <CoreMotion/CoreMotion.h>
1111
#import <libkern/OSAtomic.h>
1212
#import <uuid/uuid.h>
13-
#import "FlashMode.h"
1413
#import "FLTThreadSafeEventChannel.h"
1514
#import "FLTThreadSafeFlutterResult.h"
1615
#import "FLTThreadSafeMethodChannel.h"
1716
#import "FLTThreadSafeTextureRegistry.h"
17+
#import "FlashMode.h"
1818

1919
@interface FLTSavePhotoDelegate : NSObject <AVCapturePhotoCaptureDelegate>
2020
@property(readonly, nonatomic) NSString *path;
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
//
2-
// FlashMode.h
3-
// camera
4-
//
5-
// Created by Huan Lin on 1/25/22.
6-
//
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
74

85
#import <AVFoundation/AVFoundation.h>
96
#import <Foundation/Foundation.h>
107

118
NS_ASSUME_NONNULL_BEGIN
129

13-
// Mirrors FlashMode in flash_mode.dart
10+
/**
11+
* Represents camera's flash mode. Mirrors `FlashMode` enum in flash_mode.dart.
12+
*/
1413
typedef enum {
1514
FlashModeOff,
1615
FlashModeAuto,
1716
FlashModeAlways,
1817
FlashModeTorch,
1918
} FlashMode;
2019

20+
/**
21+
* Gets FlashMode from its string representation.
22+
* @param mode a string representation of the FlashMode.
23+
*/
2124
FlashMode getFlashModeForString(NSString *mode);
25+
26+
/**
27+
* Gets AVCaptureFlashMode from FlashMode.
28+
* @param mode flash mode.
29+
*/
2230
AVCaptureFlashMode getAVCaptureFlashModeForFlashMode(FlashMode mode);
2331

2432
NS_ASSUME_NONNULL_END

packages/camera/camera/ios/Classes/FlashMode.m

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
//
2-
// FlashMode.m
3-
// camera
4-
//
5-
// Created by Huan Lin on 1/25/22.
6-
//
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
74

85
#import "FlashMode.h"
96

@@ -40,4 +37,3 @@ AVCaptureFlashMode getAVCaptureFlashModeForFlashMode(FlashMode mode) {
4037
return -1;
4138
}
4239
}
43-

packages/camera/camera/ios/Classes/camera-umbrella.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#import <camera/FLTThreadSafeFlutterResult.h>
99
#import <camera/FLTThreadSafeMethodChannel.h>
1010
#import <camera/FLTThreadSafeTextureRegistry.h>
11+
#import <camera/FlashMode.h>
1112
#import <camera/QueueHelper.h>
1213

1314
FOUNDATION_EXPORT double cameraVersionNumber;

0 commit comments

Comments
 (0)