1 /*
2  * Copyright (c) 2021-2024 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_FRAMEWORK_MODULETEST_H
17 #define CAMERA_FRAMEWORK_MODULETEST_H
18 
19 #include "gtest/gtest.h"
20 #include "input/camera_device.h"
21 #include "input/camera_input.h"
22 #include "input/camera_manager.h"
23 #include "session/capture_session.h"
24 #include "session/portrait_session.h"
25 #include "hcamera_service_callback_proxy.h"
26 #include "hstream_repeat_proxy.h"
27 #include "hstream_capture_callback_proxy.h"
28 #include "hstream_repeat_callback_proxy.h"
29 #include "hcapture_session_callback_proxy.h"
30 #include "session/slow_motion_session.h"
31 
32 namespace OHOS {
33 namespace CameraStandard {
34 typedef struct {
35     Profile preview;
36     Profile photo;
37     VideoProfile video;
38 } SelectProfiles;
39 
40 class CameraFrameworkModuleTest : public testing::Test {
41 public:
42     static const int32_t PHOTO_DEFAULT_WIDTH = 1280;
43     static const int32_t PHOTO_DEFAULT_HEIGHT = 960;
44     static const int32_t PREVIEW_DEFAULT_WIDTH = 640;
45     static const int32_t PREVIEW_DEFAULT_HEIGHT = 480;
46     static const int32_t VIDEO_DEFAULT_WIDTH = 640;
47     static const int32_t VIDEO_DEFAULT_HEIGHT = 360;
48     CameraFormat previewFormat_;
49     CameraFormat photoFormat_;
50     CameraFormat videoFormat_;
51     int32_t previewWidth_;
52     int32_t previewHeight_;
53     int32_t photoWidth_;
54     int32_t photoHeight_;
55     int32_t videoWidth_;
56     int32_t videoHeight_;
57     sptr<CameraManager> manager_;
58     sptr<PortraitSession> portraitSession_;
59     sptr<CaptureSession> session_;
60     sptr<CaptureSession> scanSession_;
61     sptr<SlowMotionSession> slowMotionSession_;
62     sptr<CaptureSession> highResSession_;
63     sptr<CaptureSession> videoSession_;
64     sptr<CaptureInput> input_;
65     std::vector<sptr<CameraDevice>> cameras_;
66     std::vector<CameraFormat> previewFormats_;
67     std::vector<CameraFormat> photoFormats_;
68     std::vector<CameraFormat> videoFormats_;
69     std::vector<Size> previewSizes_;
70     std::vector<Size> photoSizes_;
71     std::vector<Size> videoSizes_;
72     std::vector<int32_t> videoFrameRates_;
73 
74     std::vector<Profile> previewProfiles;
75     std::vector<Profile> photoProfiles;
76     std::vector<VideoProfile> videoProfiles;
77     /* SetUpTestCase:The preset action of the test suite is executed before the first TestCase */
78     static void SetUpTestCase(void);
79 
80     /* TearDownTestCase:The test suite cleanup action is executed after the last TestCase */
81     static void TearDownTestCase(void);
82 
83     /* SetUp:Execute before each test case */
84     void SetUpInit();
85     void SetUp();
86 
87     /* TearDown:Execute after each test case */
88     void TearDown();
89 
90     sptr<CaptureOutput> CreatePreviewOutput(Profile& profile);
91     sptr<CaptureOutput> CreatePreviewOutput(int32_t width, int32_t height);
92     sptr<CaptureOutput> CreatePreviewOutput();
93     sptr<Surface> CreateSketchSurface(CameraFormat cameraFormat);
94     sptr<CaptureOutput> CreatePhotoOutput(int32_t width, int32_t height);
95     sptr<CaptureOutput> CreatePhotoOutput();
96     sptr<CaptureOutput> CreateVideoOutput(int32_t width, int32_t height);
97     sptr<CaptureOutput> CreateVideoOutput();
98     sptr<CaptureOutput> CreateVideoOutput(VideoProfile& profile);
99     sptr<CaptureOutput> CreatePhotoOutput(Profile profile);
100     void GetSupportedOutputCapability();
101     Profile SelectProfileByRatioAndFormat(sptr<CameraOutputCapability>& modeAbility,
102                                           float ratio, CameraFormat format);
103     void ConfigScanSession(sptr<CaptureOutput> &previewOutput_1, sptr<CaptureOutput> &previewOutput_2);
104     void ConfigHighResSession(sptr<CaptureOutput> &previewOutput_1, sptr<CaptureOutput> &previewOutput_2);
105     void ConfigSlowMotionSession(sptr<CaptureOutput> &previewOutput, sptr<CaptureOutput> &videoOutput);
106     void CreateHighResPhotoOutput(sptr<CaptureOutput> &previewOutput, sptr<CaptureOutput> &photoOutput,
107                                   Profile previewProfile, Profile photoProfile);
108     void ConfigVideoSession(sptr<CaptureOutput> &previewOutput, sptr<CaptureOutput> &videoOutput);
109     void ReleaseInput();
110 
111     void SetCameraParameters(sptr<CaptureSession> &session, bool video);
112     void TestCallbacksSession(sptr<CaptureOutput> photoOutput,
113 		    sptr<CaptureOutput> videoOutput);
114     void TestCallbacks(sptr<CameraDevice> &cameraInfo, bool video);
115     void TestSupportedResolution(int32_t previewWidth, int32_t previewHeight, int32_t photoWidth,
116                                  int32_t photoHeight, int32_t videoWidth, int32_t videoHeight);
117     void TestUnSupportedResolution(int32_t previewWidth, int32_t previewHeight, int32_t photoWidth,
118                                    int32_t photoHeight, int32_t videoWidth, int32_t videoHeight);
119     bool IsSupportNow();
120     bool IsSupportMode(SceneMode mode);
121 
122     std::shared_ptr<Profile> GetSketchPreviewProfile();
123 
124 private:
125     void RegisterErrorCallback();
126     static void SetNativeToken();
127     void SetHapToken();
128     void ProcessPreviewProfiles(sptr<CameraOutputCapability>& outputcapability);
129     void ProcessSize();
130     void ProcessPortraitSession(sptr<PortraitSession>& portraitSession, sptr<CaptureOutput>& previewOutput);
131 };
132 } // CameraStandard
133 } // OHOS
134 #endif // CAMERA_FRAMEWORK_MODULETEST_H
135