1/* 2 * Copyright (C) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, Level } from '@ohos/hypium'; 17import { camera } from '@kit.CameraKit'; 18import { common } from '@kit.AbilityKit'; 19import { cameraErrorCode, isEmpty } from '../common'; 20 21const TAG = "CameraXts.getSupportedSceneModesTest"; 22const abnormalIndex = -1; 23let mCameraManager: camera.CameraManager; 24let mCameraDeviceArray: Array<camera.CameraDevice>; 25let testContext: common.UIAbilityContext = AppStorage.get('testContext') as common.UIAbilityContext; 26 27function getCameraManager() { 28 console.info(TAG, 'getCameraManager.'); 29 mCameraManager = camera.getCameraManager(testContext); 30 if (isEmpty(mCameraManager)) { 31 return false; 32 } 33 return true; 34} 35 36function getSupportedCameraDeviceArray() { 37 console.info(TAG, 'getSupportedCameraDeviceArray.'); 38 mCameraDeviceArray = mCameraManager.getSupportedCameras(); 39 if (isEmpty(mCameraDeviceArray)) { 40 return false; 41 } 42 console.info(TAG, 'getSupportedCameraDeviceArray length: ' + mCameraDeviceArray.length); 43 return true; 44} 45 46function getSupportedSceneModes(done: Function, testName: string, 47 cameraDevice: camera.CameraDevice | null | undefined) { 48 console.info(TAG, testName + ' begin.'); 49 try { 50 for (let i = 0; i < mCameraDeviceArray.length; i++) { 51 let sceneModes = mCameraManager.getSupportedSceneModes(cameraDevice); 52 if (sceneModes !== null && sceneModes.length > 0) { 53 expect(isEmpty(sceneModes)).assertFalse(); 54 console.info(TAG, testName + ' camera : ' + i + ', sceneModes: ' + sceneModes); 55 } else { 56 console.info(TAG, testName + ' sceneModes is null.'); 57 expect(isEmpty(sceneModes)).assertTrue(); 58 } 59 } 60 done(); 61 } catch (error) { 62 console.error(TAG, testName + ' failed. err: ' + error.code + ', msg: ' + error.message); 63 expect(error.code == cameraErrorCode.INVALID_ARGUMENT).assertTrue(); 64 done(); 65 } 66} 67 68export default function getSupportedSceneModesTest() { 69 describe('getSupportedSceneModesTest', () => { 70 beforeAll(() => { 71 console.info(TAG, 'beforeAll case.'); 72 getCameraManager(); 73 getSupportedCameraDeviceArray(); 74 }); 75 76 beforeEach(() => { 77 console.info(TAG, 'beforeEach case.'); 78 }); 79 80 afterEach(() => { 81 console.info(TAG, 'afterEach case.'); 82 }); 83 84 afterAll(() => { 85 console.info(TAG, 'afterAll case.'); 86 }); 87 88 /** 89 * @tc.number : CAMERA_MANAGER_GET_SUPPORTED_SCENE_MODES_001 90 * @tc.name : getSupportedSceneModes_001 91 * @tc.desc : No abnormal scenarios 92 * @tc.size : MEDIUM 93 * @tc.type : Function 94 * @tc.level : Level 0 95 */ 96 it('getSupportedSceneModes_001', Level.LEVEL0, (done: Function) => { 97 const testName = 'getSupportedSceneModes_001'; 98 console.info(TAG, testName + ' begin.'); 99 try { 100 for (let i = 0; i < mCameraDeviceArray.length; i++) { 101 let sceneModes = mCameraManager.getSupportedSceneModes(mCameraDeviceArray[i]); 102 if (sceneModes !== null && sceneModes.length > 0) { 103 expect(isEmpty(sceneModes)).assertFalse(); 104 console.info(TAG, testName + ' camera : ' + i + ', sceneModes: ' + sceneModes); 105 } else { 106 console.info(TAG, testName + ' sceneModes is null.'); 107 expect().assertFail(); 108 } 109 } 110 done(); 111 } catch (error) { 112 console.error(TAG, testName + ' failed. err: ' + error.code + ', msg: ' + error.message); 113 expect().assertFail(); 114 done(); 115 } 116 }) 117 118 /** 119 * @tc.number : CAMERA_MANAGER_GET_SUPPORTED_SCENE_MODES_002 120 * @tc.name : getSupportedSceneModes_abnormal_001 121 * @tc.desc : sceneMode->invalid mode -> error_code: 7400101 122 * @tc.size : MEDIUM 123 * @tc.type : Function 124 * @tc.level : Level 2 125 */ 126 it('getSupportedSceneModes_abnormal_001', Level.LEVEL2, (done: Function) => { 127 const testName = 'getSupportedSceneModes_abnormal_001'; 128 getSupportedSceneModes(done, testName, mCameraDeviceArray[abnormalIndex]); 129 }) 130 131 /** 132 * @tc.number : CAMERA_MANAGER_GET_SUPPORTED_SCENE_MODES_003 133 * @tc.name : getSupportedSceneModes_abnormal_002 134 * @tc.desc : sceneMode->undefined -> error_code: 7400101 135 * @tc.size : MEDIUM 136 * @tc.type : Function 137 * @tc.level : Level 2 138 */ 139 it('getSupportedSceneModes_abnormal_002', Level.LEVEL2, (done: Function) => { 140 const testName = 'getSupportedSceneModes_abnormal_002'; 141 getSupportedSceneModes(done, testName, undefined); 142 }) 143 144 /** 145 * @tc.number : CAMERA_MANAGER_GET_SUPPORTED_SCENE_MODES_004 146 * @tc.name : getSupportedSceneModes_abnormal_003 147 * @tc.desc : sceneMode->null -> error_code: 7400101 148 * @tc.size : MEDIUM 149 * @tc.type : Function 150 * @tc.level : Level 2 151 */ 152 it('getSupportedSceneModes_abnormal_003', Level.LEVEL2, (done: Function) => { 153 const testName = 'getSupportedSceneModes_abnormal_003'; 154 getSupportedSceneModes(done, testName, null); 155 }) 156 }) 157}