1 /*
2 * Copyright (c) 2022 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 #include <gtest/gtest.h>
17 #include "dcameraprovidercase.h"
18 #include "dcameratest.h"
19 #include "dcamera_provider_callback_impl.h"
20 #include "dcamera_provider.h"
21
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace DistributedHardware {
26 class DCameraProviderTest : public testing::Test {
27 public:
28 static void SetUpTestCase(void);
29 static void TearDownTestCase(void);
30 void SetUp();
31 void TearDown();
32
33 std::shared_ptr<DCameraSourceDev> camDev_;
34 std::shared_ptr<ICameraStateListener> stateListener_;
35 sptr<IDCameraProviderCallback> hdiCallback_;
36 };
37
38 namespace {
39 const std::string testDeviceId = "bb536a637105409e904d4da83790a4a7";
40 const std::string testCameraDh = "camera_0";
41 const std::string testReqId = "0xFFFF";
42 const std::string testParam = R"({"CodecType": ["avenc_mpeg4"],
43 "OutputFormat": {"Photo":[4], "Preview":[2, 3], "Video":[2, 3]},
44 "Position": "BACK",
45 "ProtocolVer": "1.0",
46 "MetaData": "",
47 "Resolution": {
48 "2": ["1920*1080", "1504*720", "1440*1080", "1280*960", "1280*720", "1232*768", "1152*720", "960*720", "960*544",
49 "880*720", "720*720", "720*480", "640*480", "352*288", "320*240"],
50 "3": ["1920*1080", "1504*720", "1440*1080", "1280*960", "1280*720", "1232*768", "1152*720", "960*720", "960*544",
51 "880*720", "720*720", "720*480", "640*480", "352*288", "320*240"],
52 "4": ["3840*2160", "3264*2448", "3264*1840", "2304*1728", "2048*1536", "1920*1440", "1920*1080", "1744*1088",
53 "1280*720", "1232*768", "1152*720", "640*480", "320*240"]}})";
54 const int32_t TEST_WIDTH = 1920;
55 const int32_t TEST_HEIGTH = 1080;
56 const int32_t TEST_STREAMID = 2;
57 }
58
59 std::vector<DCStreamInfo> streamInfos;
60 std::vector<DCCaptureInfo> captureInfos;
61 std::vector<DCameraSettings> settings;
62 std::vector<int> streamIds;
63 DCameraSettings result;
64 DHBase dhBase;
65 DCameraProvider cameraProvider;
66 DCameraBuffer buffer;
67 DCameraHDFEvent hdiEvent;
68
SetUpTestCase(void)69 void DCameraProviderTest::SetUpTestCase(void)
70 {
71 dhBase.deviceId_ = testDeviceId;
72 dhBase.dhId_ = testCameraDh;
73
74 hdiEvent.type_ = 0;
75 hdiEvent.result_ = 1;
76 hdiEvent.content_ = 9;
77
78 result.type_ = METADATA_RESULT;
79 result.value_ = "SettingValue";
80
81 DCStreamInfo streamInfo1;
82 streamInfo1.streamId_ = 1;
83 streamInfo1.width_ = TEST_WIDTH;
84 streamInfo1.height_ = TEST_HEIGTH;
85 streamInfo1.stride_ = 1;
86 streamInfo1.format_ = 1;
87 streamInfo1.dataspace_ = 1;
88 streamInfo1.encodeType_ = ENCODE_TYPE_JPEG;
89 streamInfo1.type_ = SNAPSHOT_FRAME;
90 streamInfos.push_back(streamInfo1);
91
92 streamIds.push_back(1);
93 streamIds.push_back(TEST_STREAMID);
94
95 DCCaptureInfo captureInfo1;
96 captureInfo1.streamIds_.push_back(1);
97 captureInfo1.width_ = TEST_WIDTH;
98 captureInfo1.height_ = TEST_HEIGTH;
99 captureInfo1.stride_ = 1;
100 captureInfo1.format_ = 1;
101 captureInfo1.dataspace_ = 1;
102 captureInfo1.encodeType_ = ENCODE_TYPE_H265;
103 captureInfo1.type_ = CONTINUOUS_FRAME;
104 captureInfos.push_back(captureInfo1);
105
106 settings.push_back(result);
107 }
108
TearDownTestCase(void)109 void DCameraProviderTest::TearDownTestCase(void) {}
110
SetUp(void)111 void DCameraProviderTest::SetUp(void)
112 {
113 stateListener_ = std::make_shared<HdiDCameraSourceStateListener>();
114 camDev_ = std::make_shared<HdiDCameraSourceDev>(testDeviceId, testCameraDh, stateListener_);
115 hdiCallback_ = new (std::nothrow)DCameraProviderCallbackImpl(testDeviceId, testCameraDh, camDev_);
116 }
117
TearDown(void)118 void DCameraProviderTest::TearDown(void)
119 {
120 hdiCallback_ = nullptr;
121 camDev_ = nullptr;
122 stateListener_ = nullptr;
123 }
124
125 HWTEST_F(DCameraProviderTest, DCameraCase_0010, TestSize.Level1)
126 {
127 int32_t ret = cameraProvider.EnableDCameraDevice(dhBase, testParam, hdiCallback_);
128 EXPECT_EQ(0, ret) << "EnableDCameraDevice fail";
129 }
130
131 HWTEST_F(DCameraProviderTest, DCameraCase_0020, TestSize.Level1)
132 {
133 int32_t ret = cameraProvider.OpenSession(dhBase);
134 EXPECT_NE(0, ret) << "OpenSession fail";
135 }
136
137 HWTEST_F(DCameraProviderTest, DCameraCase_0030, TestSize.Level1)
138 {
139 int32_t ret = cameraProvider.ConfigureStreams(dhBase, streamInfos);
140 EXPECT_NE(0, ret) << "ConfigureStreams fail";
141 }
142
143 HWTEST_F(DCameraProviderTest, DCameraCase_0040, TestSize.Level1)
144 {
145 int32_t ret = cameraProvider.StartCapture(dhBase, captureInfos);
146 EXPECT_NE(0, ret) << "StartCapture fail";
147 }
148
149 HWTEST_F(DCameraProviderTest, DCameraCase_0050, TestSize.Level1)
150 {
151 int32_t ret = cameraProvider.OnSettingsResult(dhBase, result);
152 EXPECT_NE(0, ret) << "OnSettingsResult fail";
153 }
154
155 HWTEST_F(DCameraProviderTest, DCameraCase_0060, TestSize.Level1)
156 {
157 int32_t ret = cameraProvider.UpdateSettings(dhBase, settings);
158 EXPECT_NE(0, ret) << "UpdateSettings fail";
159 }
160
161 HWTEST_F(DCameraProviderTest, DCameraCase_0070, TestSize.Level1)
162 {
163 int32_t ret = cameraProvider.AcquireBuffer(dhBase, TEST_STREAMID, buffer);
164 EXPECT_NE(0, ret) << "AcquireBuffer fail";
165 }
166
167 HWTEST_F(DCameraProviderTest, DCameraCase_0080, TestSize.Level1)
168 {
169 int32_t ret = cameraProvider.Notify(dhBase, hdiEvent);
170 EXPECT_EQ(0, ret) << "Notify fail";
171 }
172
173 HWTEST_F(DCameraProviderTest, DCameraCase_0090, TestSize.Level1)
174 {
175 int32_t ret = cameraProvider.ShutterBuffer(dhBase, TEST_STREAMID, buffer);
176 EXPECT_NE(0, ret) << "ShutterBuffer fail";
177 }
178
179 HWTEST_F(DCameraProviderTest, DCameraCase_0100, TestSize.Level1)
180 {
181 int32_t ret = cameraProvider.StopCapture(dhBase, streamIds);
182 EXPECT_NE(0, ret) << "StopCapture fail";
183 }
184
185 HWTEST_F(DCameraProviderTest, DCameraCase_0110, TestSize.Level1)
186 {
187 int32_t ret = cameraProvider.ReleaseStreams(dhBase, streamIds);
188 EXPECT_NE(0, ret) << "ReleaseStreams fail";
189 }
190
191
192 HWTEST_F(DCameraProviderTest, DCameraCase_0120, TestSize.Level1)
193 {
194 int32_t ret = cameraProvider.CloseSession(dhBase);
195 EXPECT_NE(0, ret) << "CloseSession fail";
196 }
197
198 HWTEST_F(DCameraProviderTest, DCameraCase_0130, TestSize.Level1)
199 {
200 int32_t ret = cameraProvider.DisableDCameraDevice(dhBase);
201 EXPECT_EQ(0, ret) << "DisableDCameraDevice fail";
202 }
203 }
204 }