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 16 #ifndef CAMERA_BASE_FUNCTION_MODULETEST_H 17 #define CAMERA_BASE_FUNCTION_MODULETEST_H 18 19 #include <vector> 20 21 #include "gtest/gtest.h" 22 #include "input/camera_manager.h" 23 #include "input/camera_manager_for_sys.h" 24 #include "photo_output_callback.h" 25 #include "session/capture_session.h" 26 #include "session/capture_session_for_sys.h" 27 28 namespace OHOS { 29 namespace CameraStandard { 30 // camera manager 31 class TestCameraMuteListener : public CameraMuteListener { 32 public: 33 TestCameraMuteListener() = default; 34 virtual ~TestCameraMuteListener() = default; 35 void OnCameraMute(bool muteMode) const override; 36 }; 37 class TestTorchListener : public TorchListener { 38 public: 39 TestTorchListener() = default; 40 virtual ~TestTorchListener() = default; 41 void OnTorchStatusChange(const TorchStatusInfo &torchStatusInfo) const override; 42 }; 43 class TestFoldListener : public FoldListener { 44 public: 45 TestFoldListener() = default; 46 virtual ~TestFoldListener() = default; 47 void OnFoldStatusChanged(const FoldStatusInfo &foldStatusInfo) const override; 48 }; 49 class TestControlCenterStatusListener : public ControlCenterStatusListener { 50 public: 51 TestControlCenterStatusListener() = default; 52 virtual ~TestControlCenterStatusListener() = default; 53 void OnControlCenterStatusChanged(bool status) const override; 54 }; 55 // capture session 56 class TestSessionCallback : public SessionCallback { 57 public: 58 TestSessionCallback() = default; 59 virtual ~TestSessionCallback() = default; 60 void OnError(int32_t errorCode) override; 61 }; 62 class TestExposureCallback : public ExposureCallback { 63 public: 64 TestExposureCallback() = default; 65 virtual ~TestExposureCallback() = default; 66 void OnExposureState(ExposureState state) override; 67 }; 68 class TestFocusCallback : public FocusCallback { 69 public: 70 TestFocusCallback() = default; 71 virtual ~TestFocusCallback() = default; 72 void OnFocusState(FocusState state) override; 73 }; 74 class TestMacroStatusCallback : public MacroStatusCallback { 75 public: 76 TestMacroStatusCallback() = default; 77 virtual ~TestMacroStatusCallback() = default; 78 void OnMacroStatusChanged(MacroStatus status) override; 79 }; 80 class TestMoonCaptureBoostStatusCallback : public MoonCaptureBoostStatusCallback { 81 public: 82 TestMoonCaptureBoostStatusCallback() = default; 83 virtual ~TestMoonCaptureBoostStatusCallback() = default; 84 void OnMoonCaptureBoostStatusChanged(MoonCaptureBoostStatus status) override; 85 }; 86 class TestFeatureDetectionStatusCallback : public FeatureDetectionStatusCallback { 87 public: 88 TestFeatureDetectionStatusCallback() = default; 89 virtual ~TestFeatureDetectionStatusCallback() = default; 90 void OnFeatureDetectionStatusChanged(SceneFeature feature, FeatureDetectionStatus status) override; 91 bool IsFeatureSubscribed(SceneFeature feature) override; 92 }; 93 class TestSmoothZoomCallback : public SmoothZoomCallback { 94 public: 95 TestSmoothZoomCallback() = default; 96 virtual ~TestSmoothZoomCallback() = default; 97 void OnSmoothZoom(int32_t duration) override; 98 }; 99 class TestARCallback : public ARCallback { 100 public: 101 TestARCallback() = default; 102 virtual ~TestARCallback() = default; 103 void OnResult(const ARStatusInfo &arStatusInfo) const override; 104 }; 105 class TestEffectSuggestionCallback : public EffectSuggestionCallback { 106 public: 107 TestEffectSuggestionCallback() = default; 108 virtual ~TestEffectSuggestionCallback() = default; 109 void OnEffectSuggestionChange(EffectSuggestionType effectSuggestionType) override; 110 }; 111 class TestLcdFlashStatusCallback : public LcdFlashStatusCallback { 112 public: 113 TestLcdFlashStatusCallback() = default; 114 virtual ~TestLcdFlashStatusCallback() = default; 115 void OnLcdFlashStatusChanged(LcdFlashStatusInfo lcdFlashStatusInfo) override; 116 }; 117 class TestAutoDeviceSwitchCallback : public AutoDeviceSwitchCallback { 118 public: 119 TestAutoDeviceSwitchCallback() = default; 120 virtual ~TestAutoDeviceSwitchCallback() = default; 121 void OnAutoDeviceSwitchStatusChange(bool isDeviceSwitched, bool isDeviceCapabilityChanged) const override; 122 }; 123 class TestMetadataStateCallback : public MetadataStateCallback { 124 public: 125 TestMetadataStateCallback() = default; 126 virtual ~TestMetadataStateCallback() = default; 127 void OnError(int32_t errorCode) const override; 128 }; 129 130 class TestThumbnailCallback : public ThumbnailCallback { 131 public: 132 TestThumbnailCallback() = default; 133 virtual ~TestThumbnailCallback() = default; 134 void OnThumbnailAvailable( 135 const int32_t captureId, const int64_t timestamp, unique_ptr<Media::PixelMap> pixelMap) const override; 136 }; 137 138 // ms 139 static const int32_t DURATION_AFTER_SESSION_START = 200; 140 static const int32_t DURATION_BEFORE_SESSION_STOP = 200; 141 static const int32_t DURATION_AFTER_CAPTURE = 200; 142 static const int32_t DURATION_DURING_RECORDING = 500; 143 static const int32_t DURATION_AFTER_RECORDING = 200; 144 static const int32_t DURATION_AFTER_DEVICE_CLOSE = 200; 145 static const int32_t DURATION_WAIT_CALLBACK = 200; 146 147 static const int32_t PHOTO_DEFAULT_WIDTH = 1280; 148 static const int32_t PHOTO_DEFAULT_HEIGHT = 960; 149 static const int32_t PREVIEW_DEFAULT_WIDTH = 1280; 150 static const int32_t PREVIEW_DEFAULT_HEIGHT = 720; 151 static const int32_t VIDEO_DEFAULT_WIDTH = 1280; 152 static const int32_t VIDEO_DEFAULT_HEIGHT = 720; 153 154 static const int32_t PRVIEW_WIDTH_176 = 176; 155 static const int32_t PRVIEW_HEIGHT_144 = 144; 156 static const int32_t PRVIEW_WIDTH_480 = 480; 157 static const int32_t PRVIEW_HEIGHT_480 = 480; 158 static const int32_t PRVIEW_WIDTH_640 = 640; 159 static const int32_t PRVIEW_HEIGHT_640 = 640; 160 static const int32_t PRVIEW_WIDTH_4096 = 4096; 161 static const int32_t PRVIEW_HEIGHT_3072 = 3072; 162 static const int32_t PRVIEW_WIDTH_4160 = 4160; 163 static const int32_t PRVIEW_HEIGHT_3120 = 3120; 164 static const int32_t PRVIEW_WIDTH_8192 = 8192; 165 static const int32_t PRVIEW_HEIGHT_6144 = 6144; 166 static const int32_t VEDIO_FRAMERATES_120 = 120; 167 static const int32_t VEDIO_FRAMERATES_240 = 240; 168 static const int32_t VEDIO_FRAMERATES_SIZE = 2; 169 170 class CameraBaseFunctionModuleTest : public testing::Test { 171 public: 172 static const int32_t deviceBackIndex = 0; 173 static const int32_t deviceFrontIndex = 1; 174 175 /* SetUpTestCase: The preset action of the test suite is executed before the first test case */ 176 static void SetUpTestCase(void); 177 178 /* TearDownTestCase: The cleanup action of the test suite is executed after the last test case */ 179 static void TearDownTestCase(void); 180 181 /* SetUp: Execute before each test case */ 182 void SetUp(); 183 184 /* TearDown: Execute after each test case */ 185 void TearDown(); 186 187 void UpdateCameraOutputCapability(int32_t index = 0, int32_t modeName = 0); 188 void UpdateCameraOutputCapabilityForSys(int32_t index = 0, int32_t modeName = 0); 189 void FilterPreviewProfiles(std::vector<Profile>& previewProfiles); 190 191 sptr<PreviewOutput> CreatePreviewOutput(Profile &previewProfile); 192 sptr<PhotoOutput> CreatePhotoOutput(Profile &photoProfile); 193 sptr<VideoOutput> CreateVideoOutput(VideoProfile &videoProfile); 194 195 void CreateAndConfigureDefaultCaptureOutput(sptr<PhotoOutput> &photoOutput, sptr<VideoOutput> &videoOutput); 196 void CreateAndConfigureDefaultCaptureOutputForSys(sptr<PhotoOutput> &photoOutput, sptr<VideoOutput> &videoOutput); 197 void CreateAndConfigureDefaultCaptureOutput(sptr<PhotoOutput> &photoOutput); 198 void StartDefaultCaptureOutput(sptr<PhotoOutput> photoOutput, sptr<VideoOutput> videoOutput); 199 void StartDefaultCaptureOutputForSys(sptr<PhotoOutput> photoOutput, sptr<VideoOutput> videoOutput); 200 void StartDefaultCaptureOutput(sptr<PhotoOutput> photoOutput); 201 202 void CreateNormalSession(); 203 void CreateSystemSession(); 204 205 protected: 206 int32_t previewFd_ = -1; 207 int32_t videoFd_ = -1; 208 int32_t sketchFd_ = -1; 209 210 sptr<CameraInput> cameraInput_ = nullptr; 211 sptr<CameraManager> cameraManager_ = nullptr; 212 sptr<CameraManagerForSys> cameraManagerForSys_ = nullptr; 213 sptr<CaptureSession> captureSession_ = nullptr; 214 sptr<CaptureSessionForSys> captureSessionForSys_ = nullptr; 215 std::vector<sptr<CameraDevice>> cameraDevices_ = {}; 216 217 std::vector<Profile> photoProfiles_ = {}; 218 std::vector<Profile> previewProfiles_ = {}; 219 std::vector<VideoProfile> videoProfiles_ = {}; 220 std::vector<Profile> photoProfilesForSys_ = {}; 221 std::vector<Profile> previewProfilesForSys_ = {}; 222 std::vector<VideoProfile> videoProfilesForSys_ = {}; 223 std::vector<DepthProfile> depthProfiles_ = {}; 224 std::vector<MetadataObjectType> metadataObjectTypes_ = {}; 225 }; 226 } // CameraStandard 227 } // OHOS 228 #endif // CAMERA_BASE_FUNCTION_MODULETEST_H