1/* 2 * Copyright (c) 2023 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 "dcamera_client_demo.h" 18#include "distributed_hardware_log.h" 19 20#include "access_token.h" 21#include "accesstoken_kit.h" 22#include "hap_token_info.h" 23#include "ipc_skeleton.h" 24#include "nativetoken_kit.h" 25#include "token_setproc.h" 26 27using namespace testing::ext; 28using namespace OHOS::DistributedHardware; 29 30namespace OHOS { 31namespace DistributedHardware { 32constexpr int32_t CAMERA_OK = 0; 33constexpr int32_t SLEEP_OK_SECOND = 2; 34constexpr int32_t SLEEP_FIVE_SECOND = 5; 35 36class DCameraClientAutomaticTest : public testing::Test { 37public: 38 static void SetUpTestCase(void); 39 static void TearDownTestCase(void); 40 void SetUp(); 41 void TearDown(); 42 DCameraClientAutomaticTest(); 43}; 44 45void DCameraClientAutomaticTest::SetUpTestCase(void) 46{ 47 uint64_t tokenId; 48 const char *perms[2]; 49 perms[0] = "ohos.permission.DISTRIBUTED_DATASYNC"; 50 perms[1] = "ohos.permission.CAMERA"; 51 NativeTokenInfoParams infoInstance = { 52 .dcapsNum = 0, 53 .permsNum = 2, 54 .aclsNum = 0, 55 .dcaps = NULL, 56 .perms = perms, 57 .acls = NULL, 58 .processName = "dcamera_client_demo", 59 .aplStr = "system_basic", 60 }; 61 tokenId = GetAccessTokenId(&infoInstance); 62 SetSelfTokenID(tokenId); 63 OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); 64 sleep(SLEEP_OK_SECOND); 65} 66 67void DCameraClientAutomaticTest::TearDownTestCase(void) {} 68void DCameraClientAutomaticTest::SetUp(void) {} 69void DCameraClientAutomaticTest::TearDown(void) 70{ 71 ReleaseResource(); 72 sleep(SLEEP_OK_SECOND); 73} 74DCameraClientAutomaticTest::DCameraClientAutomaticTest(void) {} 75 76/** 77 * @tc.number : DCameraTest_0100 78 * @tc.name :InitCameraStandard() 79 * @tc.desc : rear camera acquisition 80 * @tc.desc : swicth distributed cmera 81 * @tc.type : FUNC 82 * @tc.size : Medium test 83 */ 84HWTEST_F(DCameraClientAutomaticTest, DCameraTest_0100, TestSize.Level1) 85{ 86 int32_t ret = InitCameraStandard(OHOS::CameraStandard::CameraPosition::CAMERA_POSITION_BACK); 87 EXPECT_EQ(CAMERA_OK, ret) << "InitCameraStandard fail"; 88} 89 90/** 91 * @tc.number : DCameraTest_0200 92 * @tc.name :InitCameraStandard() 93 * @tc.desc : rear camera preview 94 * @tc.desc : swicth distributed cmera 95 * @tc.type : FUNC 96 * @tc.size : Medium test 97 */ 98HWTEST_F(DCameraClientAutomaticTest, DCameraTest_0200, TestSize.Level1) 99{ 100 int32_t ret = InitCameraStandard(OHOS::CameraStandard::CameraPosition::CAMERA_POSITION_BACK); 101 EXPECT_EQ(CAMERA_OK, ret) << "InitCameraStandard fail"; 102 InitCaptureInfo(0, 0); 103 InitPhotoOutput(); 104 InitPreviewOutput(); 105 ConfigCaptureSession(); 106 sleep(SLEEP_FIVE_SECOND); 107} 108 109/** 110 * @tc.number : DCameraTest_0300 111 * @tc.name :InitCameraStandard() 112 * @tc.desc : front camera acquisition 113 * @tc.desc : swicth distributed cmera 114 * @tc.type : FUNC 115 * @tc.size : Medium test 116 */ 117HWTEST_F(DCameraClientAutomaticTest, DCameraTest_0300, TestSize.Level1) 118{ 119 int32_t ret = InitCameraStandard(OHOS::CameraStandard::CameraPosition::CAMERA_POSITION_FRONT); 120 EXPECT_EQ(CAMERA_OK, ret) << "InitCameraStandard fail"; 121} 122 123/** 124 * @tc.number : DCameraTest_0400 125 * @tc.name :InitCameraStandard() 126 * @tc.desc : front camera preview 127 * @tc.desc : swicth distributed cmera 128 * @tc.type : FUNC 129 * @tc.size : Medium test 130 */ 131HWTEST_F(DCameraClientAutomaticTest, DCameraTest_0400, TestSize.Level1) 132{ 133 int32_t ret = InitCameraStandard(OHOS::CameraStandard::CameraPosition::CAMERA_POSITION_FRONT); 134 EXPECT_EQ(CAMERA_OK, ret) << "InitCameraStandard fail"; 135 InitCaptureInfo(0, 0); 136 InitPhotoOutput(); 137 InitPreviewOutput(); 138 ConfigCaptureSession(); 139 sleep(SLEEP_FIVE_SECOND); 140} 141 142/** 143 * @tc.number : DCameraTest_0500 144 * @tc.name :InitCameraStandard() 145 * @tc.desc : front and rear camera switching preview 146 * @tc.desc : swicth distributed cmera 147 * @tc.type : FUNC 148 * @tc.size : Medium test 149 */ 150HWTEST_F(DCameraClientAutomaticTest, DCameraTest_0500, TestSize.Level1) 151{ 152 int32_t ret = InitCameraStandard(OHOS::CameraStandard::CameraPosition::CAMERA_POSITION_FRONT); 153 EXPECT_EQ(CAMERA_OK, ret) << "InitCameraStandard fail"; 154 InitCaptureInfo(0, 0); 155 InitPhotoOutput(); 156 InitPreviewOutput(); 157 ConfigCaptureSession(); 158 sleep(SLEEP_FIVE_SECOND); 159 ReleaseResource(); 160 sleep(SLEEP_OK_SECOND); 161 162 ret = InitCameraStandard(OHOS::CameraStandard::CameraPosition::CAMERA_POSITION_BACK); 163 EXPECT_EQ(CAMERA_OK, ret) << "InitCameraStandard fail"; 164 InitCaptureInfo(0, 0); 165 InitPhotoOutput(); 166 InitPreviewOutput(); 167 ConfigCaptureSession(); 168 sleep(SLEEP_FIVE_SECOND); 169 ReleaseResource(); 170 sleep(SLEEP_OK_SECOND); 171 172 ret = InitCameraStandard(OHOS::CameraStandard::CameraPosition::CAMERA_POSITION_FRONT); 173 EXPECT_EQ(CAMERA_OK, ret) << "InitCameraStandard fail"; 174 InitCaptureInfo(0, 0); 175 InitPhotoOutput(); 176 InitPreviewOutput(); 177 ConfigCaptureSession(); 178 sleep(SLEEP_FIVE_SECOND); 179} 180 181/** 182 * @tc.number : DCameraTest_0600 183 * @tc.name :Capture() 184 * @tc.desc : rear camera taking photos 185 * @tc.desc : swicth distributed cmera 186 * @tc.type : FUNC 187 * @tc.size : Medium test 188 */ 189HWTEST_F(DCameraClientAutomaticTest, DCameraTest_0600, TestSize.Level1) 190{ 191 int32_t ret = InitCameraStandard(OHOS::CameraStandard::CameraPosition::CAMERA_POSITION_BACK); 192 EXPECT_EQ(CAMERA_OK, ret) << "InitCameraStandard fail"; 193 InitCaptureInfo(0, 0); 194 InitPhotoOutput(); 195 InitPreviewOutput(); 196 ConfigCaptureSession(); 197 ret = Capture(); 198 EXPECT_EQ(CAMERA_OK, ret) << "Capture fail"; 199 sleep(SLEEP_FIVE_SECOND); 200} 201 202/** 203 * @tc.number : DCameraTest_0700 204 * @tc.name :Capture() 205 * @tc.desc : front camera taking photos 206 * @tc.desc : swicth distributed cmera 207 * @tc.type : FUNC 208 * @tc.size : Medium test 209 */ 210HWTEST_F(DCameraClientAutomaticTest, DCameraTest_0700, TestSize.Level1) 211{ 212 int32_t ret = InitCameraStandard(OHOS::CameraStandard::CameraPosition::CAMERA_POSITION_FRONT); 213 EXPECT_EQ(CAMERA_OK, ret) << "InitCameraStandard fail"; 214 InitCaptureInfo(0, 0); 215 InitPhotoOutput(); 216 InitPreviewOutput(); 217 ConfigCaptureSession(); 218 ret = Capture(); 219 EXPECT_EQ(CAMERA_OK, ret) << "Capture fail"; 220 sleep(SLEEP_FIVE_SECOND); 221} 222 223/** 224 * @tc.number : DCameraTest_0800 225 * @tc.name :Capture() 226 * @tc.desc : flash photography 227 * @tc.desc : swicth distributed cmera 228 * @tc.type : FUNC 229 * @tc.size : Medium test 230 */ 231HWTEST_F(DCameraClientAutomaticTest, DCameraTest_0800, TestSize.Level1) 232{ 233 int32_t ret = InitCameraStandard(OHOS::CameraStandard::CameraPosition::CAMERA_POSITION_BACK); 234 EXPECT_EQ(CAMERA_OK, ret) << "InitCameraStandard fail"; 235 InitCaptureInfo(0, 0); 236 InitPhotoOutput(); 237 InitPreviewOutput(); 238 ConfigCaptureSession(); 239 ConfigFocusFlashAndExposure(false); 240 ret = Capture(); 241 EXPECT_EQ(CAMERA_OK, ret) << "Capture fail"; 242 sleep(SLEEP_FIVE_SECOND); 243} 244 245/** 246 * @tc.number : DCameraTest_0900 247 * @tc.name :Capture() 248 * @tc.desc : preview using resolution 249 * @tc.desc : swicth distributed cmera 250 * @tc.type : FUNC 251 * @tc.size : Medium test 252 */ 253HWTEST_F(DCameraClientAutomaticTest, DCameraTest_0900, TestSize.Level1) 254{ 255 int32_t ret = InitCameraStandard(OHOS::CameraStandard::CameraPosition::CAMERA_POSITION_BACK); 256 EXPECT_EQ(CAMERA_OK, ret) << "InitCameraStandard fail"; 257 std::vector<CameraStandard::Size> previewResolution = {}; 258 ret = GetPreviewProfiles(previewResolution); 259 EXPECT_EQ(CAMERA_OK, ret) << "GetPreviewProfiles fail"; 260 CameraStandard::Size size = previewResolution.back(); 261 InitCaptureInfo(size.width, size.height); 262 InitPhotoOutput(); 263 InitPreviewOutput(); 264 ConfigCaptureSession(); 265 ConfigFocusFlashAndExposure(false); 266 ret = Capture(); 267 EXPECT_EQ(CAMERA_OK, ret) << "Capture fail"; 268 sleep(SLEEP_FIVE_SECOND); 269} 270 271/** 272 * @tc.number : DCameraTest_1000 273 * @tc.name :Capture() 274 * @tc.desc : front and rear camera switching preview 50 times 275 * @tc.desc : swicth distributed cmera 276 * @tc.type : FUNC 277 * @tc.size : Medium test 278 */ 279HWTEST_F(DCameraClientAutomaticTest, DCameraTest_1000, TestSize.Level1) 280{ 281 int32_t i = 50; 282 while (i > 0) { 283 int32_t ret = InitCameraStandard(OHOS::CameraStandard::CameraPosition::CAMERA_POSITION_BACK); 284 EXPECT_EQ(CAMERA_OK, ret) << "InitCameraStandard fail"; 285 InitCaptureInfo(0, 0); 286 InitPhotoOutput(); 287 InitPreviewOutput(); 288 ConfigCaptureSession(); 289 sleep(SLEEP_FIVE_SECOND); 290 ReleaseResource(); 291 sleep(SLEEP_OK_SECOND); 292 293 ret = InitCameraStandard(OHOS::CameraStandard::CameraPosition::CAMERA_POSITION_FRONT); 294 EXPECT_EQ(CAMERA_OK, ret) << "InitCameraStandard fail"; 295 InitCaptureInfo(0, 0); 296 InitPhotoOutput(); 297 InitPreviewOutput(); 298 ConfigCaptureSession(); 299 sleep(SLEEP_FIVE_SECOND); 300 ReleaseResource(); 301 sleep(SLEEP_OK_SECOND); 302 i--; 303 } 304} 305} // namespace DistributedHardware 306} // namespace OHOS 307