• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { isEmpty } from '../common';
20
21const TAG = "CameraXts.getSupportedCamerasTest";
22
23let mCameraManager: camera.CameraManager;
24let testContext: common.UIAbilityContext = AppStorage.get('testContext') as common.UIAbilityContext;
25
26function getCameraManager() {
27  console.info(TAG, 'getCameraManager.');
28  mCameraManager = camera.getCameraManager(testContext);
29  if (isEmpty(mCameraManager)) {
30    return false;
31  }
32  return true;
33}
34
35export default function getSupportedCamerasTest() {
36  describe('getSupportedCamerasTest', () => {
37    beforeAll(() => {
38      console.info(TAG, 'beforeAll case.');
39      getCameraManager();
40    });
41
42    beforeEach(() => {
43      console.info(TAG, 'beforeEach case.');
44    });
45
46    afterEach(() => {
47      console.info(TAG, 'afterEach case.');
48    });
49
50    afterAll(() => {
51      console.info(TAG, 'afterAll case.');
52    });
53
54    /**
55     * @tc.number    : CAMERA_MANAGER_GET_SUPPORTED_CAMERAS_001
56     * @tc.name      : getSupportedCameras_001
57     * @tc.desc      : No abnormal scenarios--Get supported camera device objects
58     * @tc.size      : MEDIUM
59     * @tc.type      : Function
60     * @tc.level     : Level 0
61     */
62    it('getSupportedCameras_001', Level.LEVEL0, (done: Function) => {
63      const testName = 'getSupportedCameras_001';
64      console.info(TAG, testName + ' begin.');
65      try {
66        if (isEmpty(mCameraManager)) {
67          console.info(TAG, testName + ' cameraManager is null.');
68          expect().assertFail();
69        } else {
70          let cameraDeviceArray: Array<camera.CameraDevice> = mCameraManager.getSupportedCameras();
71          console.info(TAG, testName + ' supported camera list: ' + JSON.stringify(cameraDeviceArray));
72          if (cameraDeviceArray !== null && cameraDeviceArray.length > 0) {
73            for (let i = 0; i < cameraDeviceArray.length; i++) {
74              let cameraId = cameraDeviceArray[i].cameraId;
75              expect(isEmpty(cameraId)).assertFalse();
76              console.info(TAG, testName + ' camera : ' + i + ', id: ' + cameraId);
77              let cameraPosition = cameraDeviceArray[i].cameraPosition;
78              expect(isEmpty(cameraPosition)).assertFalse();
79              console.info(TAG, testName + ' camera : ' + i + ', position: ' + cameraPosition);
80              let cameraType = cameraDeviceArray[i].cameraType;
81              expect(isEmpty(cameraType)).assertFalse();
82              console.info(TAG, testName + ' camera : ' + i + ', type: ' + cameraType);
83              let connectionType = cameraDeviceArray[i].connectionType;
84              expect(isEmpty(connectionType)).assertFalse();
85              console.info(TAG, testName + ' camera : ' + i + ', connection type: ' + connectionType);
86              let cameraOrientation = cameraDeviceArray[i].cameraOrientation;
87              expect(isEmpty(cameraOrientation)).assertFalse();
88              console.info(TAG, testName + ' camera : ' + i + ', orientation: ' + cameraOrientation);
89              let hostDeviceName = cameraDeviceArray[i].hostDeviceName;
90              expect(isEmpty(hostDeviceName)).assertFalse();
91              console.info(TAG, testName + ' camera : ' + i + ', host device name: ' + hostDeviceName);
92              let hostDeviceType = cameraDeviceArray[i].hostDeviceType;
93              expect(isEmpty(hostDeviceType)).assertFalse();
94              console.info(TAG, testName + ' camera : ' + i + ', host device type: ' + hostDeviceType);
95            }
96          } else {
97            expect().assertFail();
98            console.info(TAG, testName + ' cameraDeviceArray is null.');
99          }
100        }
101        done();
102      } catch (error) {
103        console.error(TAG, testName + ' failed. err: ' + error.code + ', msg: ' + error.message);
104        expect().assertFail();
105        done();
106      }
107    })
108  })
109}