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 #include "camera_moving_photo_moduletest.h"
17
18 #include "accesstoken_kit.h"
19 #include "camera_error_code.h"
20 #include "camera_log.h"
21 #include "camera_util.h"
22 #include "camera_photo_proxy.h"
23 #include "hap_token_info.h"
24 #include "ipc_skeleton.h"
25 #include "media_asset_capi.h"
26 #include "media_asset_helper.h"
27 #include "media_access_helper_capi.h"
28 #include "media_asset_change_request_capi.h"
29 #include "media_photo_asset_proxy.h"
30 #include "native_image.h"
31 #include "nativetoken_kit.h"
32 #include "securec.h"
33 #include "system_ability_definition.h"
34 #include "test_common.h"
35 #include "token_setproc.h"
36 #include "os_account_manager.h"
37 #include "video_key_info.h"
38 #include "userfile_manager_types.h"
39
40 using namespace testing::ext;
41
42 namespace OHOS {
43 namespace CameraStandard {
44 static std::mutex g_mutex;
45 const char* DEFAULT_SURFACEID = "photoOutput";
46
47 OH_MediaAsset *CameraMovingPhotoModuleTest::mediaAsset_ = nullptr;
48 OH_MovingPhoto *CameraMovingPhotoModuleTest::movingPhoto_ = nullptr;
49 OH_MediaAssetManager *CameraMovingPhotoModuleTest::mediaAssetManager_ = nullptr;
50
PhotoListenerTest(PhotoOutput * photoOutput,sptr<Surface> surface)51 PhotoListenerTest::PhotoListenerTest(PhotoOutput* photoOutput, sptr<Surface> surface)
52 : photoOutput_(photoOutput), photoSurface_(surface)
53 {
54 MEDIA_DEBUG_LOG("movingp photo module test photoListenerTest structure");
55 }
56
~PhotoListenerTest()57 PhotoListenerTest::~PhotoListenerTest()
58 {
59 photoSurface_ = nullptr;
60 }
61
OnBufferAvailable()62 void PhotoListenerTest::OnBufferAvailable()
63 {
64 MEDIA_INFO_LOG("PhotoListenerTest::OnBufferAvailable");
65 std::lock_guard<std::mutex> lock(g_mutex);
66 CAMERA_SYNC_TRACE;
67 MEDIA_INFO_LOG("PhotoListenerTest::OnBufferAvailable is called");
68 CHECK_ERROR_RETURN_LOG(photoSurface_ == nullptr, "photoSurface_ is null");
69
70 int64_t timestamp;
71 OHOS::Rect damage;
72 sptr<SurfaceBuffer> surfaceBuffer = nullptr;
73 int32_t fence = -1;
74 SurfaceError surfaceRet = photoSurface_->AcquireBuffer(surfaceBuffer, fence, timestamp, damage);
75 CHECK_ERROR_RETURN_LOG(surfaceRet != SURFACE_ERROR_OK, "Failed to acquire surface buffer");
76
77 CameraBufferExtraData extraData = GetCameraBufferExtraData(surfaceBuffer);
78
79 if ((callbackFlag_ & CAPTURE_PHOTO_ASSET) != 0) {
80 MEDIA_DEBUG_LOG("PhotoListenerTest on capture photo asset callback");
81 sptr<SurfaceBuffer> newSurfaceBuffer = SurfaceBuffer::Create();
82 DeepCopyBuffer(newSurfaceBuffer, surfaceBuffer);
83 photoSurface_->ReleaseBuffer(surfaceBuffer, -1);
84 CHECK_ERROR_RETURN_LOG(newSurfaceBuffer == nullptr, "deep copy buffer failed");
85
86 ExecutePhotoAsset(newSurfaceBuffer, extraData, extraData.isDegradedImage == 0, timestamp);
87 MEDIA_DEBUG_LOG("PhotoListenerTest on capture photo asset callback end");
88 } else if (extraData.isDegradedImage == 0 && (callbackFlag_ & CAPTURE_PHOTO) != 0) {
89 MEDIA_DEBUG_LOG("PhotoListenerTest on capture photo callback");
90 photoSurface_->ReleaseBuffer(surfaceBuffer, -1);
91 } else {
92 MEDIA_INFO_LOG("PhotoListenerTest on error callback");
93 photoSurface_->ReleaseBuffer(surfaceBuffer, -1);
94 }
95 }
96
SetCallbackFlag(uint8_t callbackFlag)97 void PhotoListenerTest::SetCallbackFlag(uint8_t callbackFlag)
98 {
99 callbackFlag_ = callbackFlag;
100 }
101
SetPhotoAssetAvailableCallback(PhotoOutputTest_PhotoAssetAvailable callback)102 void PhotoListenerTest::SetPhotoAssetAvailableCallback(PhotoOutputTest_PhotoAssetAvailable callback)
103 {
104 std::lock_guard<std::mutex> lock(g_mutex);
105 MEDIA_INFO_LOG("PhotoListenerTest::SetPhotoAssetAvailableCallback is called");
106 if (callback != nullptr) {
107 photoAssetCallback_ = callback;
108 }
109 }
110
UnregisterPhotoAssetAvailableCallback(PhotoOutputTest_PhotoAssetAvailable callback)111 void PhotoListenerTest::UnregisterPhotoAssetAvailableCallback(PhotoOutputTest_PhotoAssetAvailable callback)
112 {
113 std::lock_guard<std::mutex> lock(g_mutex);
114 MEDIA_INFO_LOG("PhotoListenerTest::UnregisterPhotoAssetAvailableCallback is called");
115 if (photoAssetCallback_ != nullptr && callback != nullptr) {
116 photoAssetCallback_ = nullptr;
117 }
118 }
119
ExecutePhotoAsset(sptr<SurfaceBuffer> surfaceBuffer,CameraBufferExtraData extraData,bool isHighQuality,int64_t timestamp)120 void PhotoListenerTest::ExecutePhotoAsset(sptr<SurfaceBuffer> surfaceBuffer, CameraBufferExtraData extraData,
121 bool isHighQuality, int64_t timestamp)
122 {
123 CAMERA_SYNC_TRACE;
124 BufferHandle* bufferHandle = surfaceBuffer->GetBufferHandle();
125 CHECK_ERROR_RETURN_LOG(bufferHandle == nullptr, "invalid bufferHandle");
126
127 surfaceBuffer->Map();
128 std::string uri = "";
129 int32_t cameraShotType = 0;
130 std::string burstKey = "";
131 CreateMediaLibrary(surfaceBuffer, bufferHandle, extraData, isHighQuality,
132 uri, cameraShotType, burstKey, timestamp);
133 CHECK_ERROR_RETURN_LOG(uri.empty(), "uri is empty");
134
135 auto mediaAssetHelper = Media::MediaAssetHelperFactory::CreateMediaAssetHelper();
136 CHECK_ERROR_RETURN_LOG(mediaAssetHelper == nullptr, "create media asset helper failed");
137
138 auto mediaAsset = mediaAssetHelper->GetMediaAsset(uri, cameraShotType, burstKey);
139 CHECK_ERROR_RETURN_LOG(mediaAsset == nullptr, "Create photo asset failed");
140
141 if (photoAssetCallback_ != nullptr && photoOutput_ != nullptr) {
142 photoAssetCallback_(photoOutput_, mediaAsset);
143 }
144 }
145
DeepCopyBuffer(sptr<SurfaceBuffer> newSurfaceBuffer,sptr<SurfaceBuffer> surfaceBuffer)146 void PhotoListenerTest::DeepCopyBuffer(sptr<SurfaceBuffer> newSurfaceBuffer, sptr<SurfaceBuffer> surfaceBuffer)
147 {
148 CAMERA_SYNC_TRACE;
149 BufferRequestConfig requestConfig = {
150 .width = surfaceBuffer->GetWidth(),
151 .height = surfaceBuffer->GetHeight(),
152 .strideAlignment = 0x8, // default stride is 8 Bytes.
153 .format = surfaceBuffer->GetFormat(),
154 .usage = surfaceBuffer->GetUsage(),
155 .timeout = 0,
156 .colorGamut = surfaceBuffer->GetSurfaceBufferColorGamut(),
157 .transform = surfaceBuffer->GetSurfaceBufferTransform(),
158 };
159 auto allocErrorCode = newSurfaceBuffer->Alloc(requestConfig);
160 MEDIA_INFO_LOG("SurfaceBuffer alloc ret: %d", allocErrorCode);
161 if (memcpy_s(newSurfaceBuffer->GetVirAddr(), newSurfaceBuffer->GetSize(),
162 surfaceBuffer->GetVirAddr(), surfaceBuffer->GetSize()) != EOK) {
163 MEDIA_ERR_LOG("PhotoListener memcpy_s failed");
164 }
165 }
166
CreateMediaLibrary(sptr<SurfaceBuffer> surfaceBuffer,BufferHandle * bufferHandle,CameraBufferExtraData extraData,bool isHighQuality,std::string & uri,int32_t & cameraShotType,std::string & burstKey,int64_t timestamp)167 void PhotoListenerTest::CreateMediaLibrary(sptr<SurfaceBuffer> surfaceBuffer, BufferHandle *bufferHandle,
168 CameraBufferExtraData extraData, bool isHighQuality, std::string &uri,
169 int32_t &cameraShotType, std::string &burstKey, int64_t timestamp)
170 {
171 CAMERA_SYNC_TRACE;
172 CHECK_ERROR_RETURN_LOG(bufferHandle == nullptr, "bufferHandle is nullptr");
173
174 int32_t format = bufferHandle->format;
175 sptr<CameraPhotoProxy> photoProxy;
176 std::string imageIdStr = std::to_string(extraData.imageId);
177 photoProxy = new(std::nothrow) CameraPhotoProxy(bufferHandle, format, extraData.photoWidth, extraData.photoHeight,
178 isHighQuality, extraData.captureId);
179 CHECK_ERROR_RETURN_LOG(photoProxy == nullptr, "Failed to new photoProxy");
180
181 photoProxy->SetDeferredAttrs(imageIdStr, extraData.deferredProcessingType, extraData.size,
182 extraData.deferredImageFormat);
183 if (photoOutput_ && photoOutput_->GetSession()) {
184 auto settings = photoOutput_->GetDefaultCaptureSetting();
185 if (settings) {
186 auto location = std::make_shared<Location>();
187 settings->GetLocation(location);
188 photoProxy->SetLocation(location->latitude, location->longitude);
189 }
190 photoOutput_->CreateMediaLibrary(photoProxy, uri, cameraShotType, burstKey, timestamp);
191 }
192 }
193
GetCameraBufferExtraData(const sptr<SurfaceBuffer> & surfaceBuffer)194 CameraBufferExtraData PhotoListenerTest::GetCameraBufferExtraData(const sptr<SurfaceBuffer> &surfaceBuffer)
195 {
196 CameraBufferExtraData extraData;
197 surfaceBuffer->GetExtraData()->ExtraGet(OHOS::Camera::captureId, extraData.captureId);
198 surfaceBuffer->GetExtraData()->ExtraGet(OHOS::Camera::imageId, extraData.imageId);
199 surfaceBuffer->GetExtraData()->ExtraGet(OHOS::Camera::deferredProcessingType, extraData.deferredProcessingType);
200 MEDIA_INFO_LOG("imageId:%{public}" PRId64
201 ", deferredProcessingType:%{public}d",
202 extraData.imageId,
203 extraData.deferredProcessingType);
204
205 surfaceBuffer->GetExtraData()->ExtraGet(OHOS::Camera::dataWidth, extraData.photoWidth);
206 surfaceBuffer->GetExtraData()->ExtraGet(OHOS::Camera::dataHeight, extraData.photoHeight);
207 uint64_t size = static_cast<uint64_t>(surfaceBuffer->GetSize());
208
209 auto res = surfaceBuffer->GetExtraData()->ExtraGet(OHOS::Camera::dataSize, extraData.extraDataSize);
210 if (res != 0) {
211 MEDIA_INFO_LOG("ExtraGet dataSize error %{public}d", res);
212 } else if (extraData.extraDataSize <= 0) {
213 MEDIA_INFO_LOG("ExtraGet dataSize OK, but size <= 0");
214 } else if (static_cast<uint64_t>(extraData.extraDataSize) > size) {
215 MEDIA_INFO_LOG("ExtraGet dataSize OK, but dataSize %{public}d is bigger "
216 "than bufferSize %{public}" PRIu64,
217 extraData.extraDataSize,
218 size);
219 } else {
220 MEDIA_INFO_LOG("ExtraGet dataSize %{public}d", extraData.extraDataSize);
221 size = static_cast<uint64_t>(extraData.extraDataSize);
222 }
223 extraData.size = size;
224
225 res = surfaceBuffer->GetExtraData()->ExtraGet(OHOS::Camera::deferredImageFormat, extraData.deferredImageFormat);
226 MEDIA_INFO_LOG("deferredImageFormat:%{public}d, width:%{public}d, "
227 "height:%{public}d, size:%{public}" PRId64,
228 extraData.deferredImageFormat,
229 extraData.photoWidth,
230 extraData.photoHeight,
231 size);
232
233 surfaceBuffer->GetExtraData()->ExtraGet(OHOS::Camera::isDegradedImage, extraData.isDegradedImage);
234 MEDIA_INFO_LOG("isDegradedImage:%{public}d", extraData.isDegradedImage);
235
236 return extraData;
237 }
238
SetUpTestCase(void)239 void CameraMovingPhotoModuleTest::SetUpTestCase(void)
240 {
241 MEDIA_DEBUG_LOG("CameraMovingPhotoModuleTest::SetUpTestCase started!");
242 }
243
TearDownTestCase(void)244 void CameraMovingPhotoModuleTest::TearDownTestCase(void)
245 {
246 MEDIA_DEBUG_LOG("CameraMovingPhotoModuleTest::TearDownTestCase started!");
247 }
248
SetUp()249 void CameraMovingPhotoModuleTest::SetUp()
250 {
251 MEDIA_INFO_LOG("CameraMovingPhotoModuleTest::SetUp start!");
252 NativeAuthorization();
253
254 manager_ = CameraManager::GetInstance();
255 ASSERT_NE(manager_, nullptr);
256 cameras_ = manager_->GetSupportedCameras();
257 ASSERT_FALSE(cameras_.empty());
258 session_ = manager_->CreateCaptureSession(SceneMode::CAPTURE);
259 ASSERT_NE(session_, nullptr);
260 input_ = manager_->CreateCameraInput(cameras_[0]);
261 ASSERT_NE(input_, nullptr);
262 EXPECT_EQ(input_->Open(), SUCCESS);
263
264 UpdataCameraOutputCapability();
265 EXPECT_EQ(CreatePreviewOutput(previewProfile_[0], previewOutput_), SUCCESS);
266 EXPECT_EQ(CreatePhotoOutputWithoutSurface(photoProfile_[0], photoOutput_), SUCCESS);
267
268 MEDIA_INFO_LOG("CameraMovingPhotoModuleTest::SetUp end!");
269 }
270
TearDown()271 void CameraMovingPhotoModuleTest::TearDown()
272 {
273 MEDIA_INFO_LOG("CameraMovingPhotoModuleTest::TearDown start!");
274
275 cameras_.clear();
276 photoProfile_.clear();
277 previewProfile_.clear();
278
279 photoOutput_->Release();
280 previewOutput_->Release();
281
282 manager_ = nullptr;
283 input_->Release();
284 session_->Release();
285
286 if (photoSurface_) {
287 photoSurface_ = nullptr;
288 }
289 if (photoListener_) {
290 photoListener_ =nullptr;
291 }
292 ReleaseMediaAsset();
293
294 MEDIA_INFO_LOG("CameraMovingPhotoModuleTest::TearDown end!");
295 }
296
NativeAuthorization()297 void CameraMovingPhotoModuleTest::NativeAuthorization()
298 {
299 const char *perms[6];
300 perms[0] = "ohos.permission.CAMERA";
301 perms[1] = "ohos.permission.MICROPHONE";
302 perms[2] = "ohos.permission.READ_MEDIA";
303 perms[3] = "ohos.permission.WRITE_MEDIA";
304 perms[4] = "ohos.permission.READ_IMAGEVIDEO";
305 perms[5] = "ohos.permission.WRITE_IMAGEVIDEO";
306 NativeTokenInfoParams infoInstance = {
307 .dcapsNum = 0,
308 .permsNum = 6,
309 .aclsNum = 0,
310 .dcaps = NULL,
311 .perms = perms,
312 .acls = NULL,
313 .processName = "native_camera_tdd",
314 .aplStr = "system_basic",
315 };
316 tokenId_ = GetAccessTokenId(&infoInstance);
317 uid_ = IPCSkeleton::GetCallingUid();
318 AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid_, userId_);
319 MEDIA_DEBUG_LOG("CameraMovingPhotoModuleTest::NativeAuthorization uid:%{public}d", uid_);
320 SetSelfTokenID(tokenId_);
321 OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
322 }
323
UpdataCameraOutputCapability(int32_t modeName)324 void CameraMovingPhotoModuleTest::UpdataCameraOutputCapability(int32_t modeName)
325 {
326 if (!manager_ || cameras_.empty()) {
327 return;
328 }
329 auto outputCapability = manager_->GetSupportedOutputCapability(cameras_[0], modeName);
330 ASSERT_NE(outputCapability, nullptr);
331
332 previewProfile_ = outputCapability->GetPreviewProfiles();
333 ASSERT_FALSE(previewProfile_.empty());
334
335 photoProfile_ = outputCapability->GetPhotoProfiles();
336 ASSERT_FALSE(photoProfile_.empty());
337 }
338
RegisterPhotoAssetAvailableCallback(PhotoOutputTest_PhotoAssetAvailable callback)339 int32_t CameraMovingPhotoModuleTest::RegisterPhotoAssetAvailableCallback(
340 PhotoOutputTest_PhotoAssetAvailable callback)
341 {
342 CHECK_ERROR_RETURN_RET_LOG(photoSurface_ == nullptr, INVALID_ARGUMENT,
343 "Photo surface is invalid");
344 if (photoListener_ == nullptr) {
345 photoListener_ = new (std::nothrow) PhotoListenerTest(photoOutput_, photoSurface_);
346 CHECK_ERROR_RETURN_RET_LOG(photoListener_ == nullptr, SERVICE_FATL_ERROR,
347 "Create photo listener failed");
348
349 SurfaceError ret = photoSurface_->RegisterConsumerListener((sptr<IBufferConsumerListener>&)photoListener_);
350 CHECK_ERROR_RETURN_RET_LOG(ret != SURFACE_ERROR_OK, SERVICE_FATL_ERROR,
351 "Register surface consumer listener failed");
352 }
353 photoListener_->SetPhotoAssetAvailableCallback(callback);
354 callbackFlag_ |= CAPTURE_PHOTO_ASSET;
355 photoListener_->SetCallbackFlag(callbackFlag_);
356 photoOutput_->SetCallbackFlag(callbackFlag_);
357 return SUCCESS;
358 }
359
UnregisterPhotoAssetAvailableCallback(PhotoOutputTest_PhotoAssetAvailable callback)360 int32_t CameraMovingPhotoModuleTest::UnregisterPhotoAssetAvailableCallback(
361 PhotoOutputTest_PhotoAssetAvailable callback)
362 {
363 if (callback != nullptr) {
364 if (photoListener_ != nullptr) {
365 callbackFlag_ &= ~CAPTURE_PHOTO_ASSET;
366 photoListener_->SetCallbackFlag(callbackFlag_);
367 photoListener_->UnregisterPhotoAssetAvailableCallback(callback);
368 }
369 }
370 return SUCCESS;
371 }
372
CreatePreviewOutput(Profile & profile,sptr<PreviewOutput> & previewOutput)373 int32_t CameraMovingPhotoModuleTest::CreatePreviewOutput(Profile &profile, sptr<PreviewOutput> &previewOutput)
374 {
375 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
376 if (surface == nullptr) {
377 MEDIA_ERR_LOG("Failed to get previewOutput surface");
378 return INVALID_ARGUMENT;
379 }
380 surface->SetUserData(CameraManager::surfaceFormat, std::to_string(profile.GetCameraFormat()));
381 int32_t retCode = manager_->CreatePreviewOutput(profile, surface, &previewOutput);
382 if (retCode != CameraErrorCode::SUCCESS) {
383 return SERVICE_FATL_ERROR;
384 }
385 return SUCCESS;
386 }
387
CreatePhotoOutputWithoutSurface(Profile & profile,sptr<PhotoOutput> & photoOutput)388 int32_t CameraMovingPhotoModuleTest::CreatePhotoOutputWithoutSurface(Profile &profile,
389 sptr<PhotoOutput> &photoOutput)
390 {
391 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer(DEFAULT_SURFACEID);
392 CHECK_ERROR_RETURN_RET_LOG(surface == nullptr, INVALID_ARGUMENT,
393 "Failed to get photoOutput surface");
394
395 photoSurface_ = surface;
396 surface->SetUserData(CameraManager::surfaceFormat, std::to_string(profile.GetCameraFormat()));
397 sptr<IBufferProducer> surfaceProducer = surface->GetProducer();
398 CHECK_ERROR_RETURN_RET_LOG(surfaceProducer == nullptr, SERVICE_FATL_ERROR, "Get producer failed");
399
400 int32_t retCode = manager_->CreatePhotoOutput(profile, surfaceProducer, &photoOutput_);
401 CHECK_ERROR_RETURN_RET_LOG((retCode != CameraErrorCode::SUCCESS || photoOutput_ == nullptr),
402 SERVICE_FATL_ERROR, "Create photo output failed");
403
404 photoOutput_->SetNativeSurface(true);
405 return SUCCESS;
406 }
407
onPhotoAssetAvailable(PhotoOutput * photoOutput,OH_MediaAsset * mediaAsset)408 void CameraMovingPhotoModuleTest::onPhotoAssetAvailable(PhotoOutput *photoOutput, OH_MediaAsset *mediaAsset)
409 {
410 MEDIA_INFO_LOG("CameraMovingPhotoModuleTest::onPhotoAssetAvailable");
411 mediaAsset_ = mediaAsset;
412 }
413
onMovingPhotoDataPrepared(MediaLibrary_ErrorCode result,MediaLibrary_RequestId requestId,MediaLibrary_MediaQuality mediaQuality,MediaLibrary_MediaContentType type,OH_MovingPhoto * movingPhoto)414 void CameraMovingPhotoModuleTest::onMovingPhotoDataPrepared(MediaLibrary_ErrorCode result,
415 MediaLibrary_RequestId requestId, MediaLibrary_MediaQuality mediaQuality,
416 MediaLibrary_MediaContentType type, OH_MovingPhoto* movingPhoto)
417 {
418 MEDIA_INFO_LOG("CameraMovingPhotoModuleTest::onMovingPhotoDataPrepared");
419 if (!movingPhoto) {
420 MEDIA_ERR_LOG("CameraMovingPhotoModuleTest::onMovingPhotoDataPrepared moving photo is nullptr");
421 return;
422 }
423 movingPhoto_ = movingPhoto;
424
425 OH_MediaAssetChangeRequest *changeRequest_ = OH_MediaAssetChangeRequest_Create(mediaAsset_);
426 if (!changeRequest_) {
427 MEDIA_ERR_LOG("CameraMovingPhotoModuleTest::onMovingPhotoDataPrepared create media asset change request fail");
428 return;
429 }
430
431 MediaLibrary_ErrorCode errCode = OH_MediaAssetChangeRequest_SaveCameraPhoto(changeRequest_,
432 MediaLibrary_ImageFileType::MEDIA_LIBRARY_IMAGE_JPEG);
433 if (errCode != MEDIA_LIBRARY_OK) {
434 MEDIA_ERR_LOG("CameraMovingPhotoModuleTest::onMovingPhotoDataPrepared save camera photo fail");
435 return;
436 }
437
438 errCode = OH_MediaAccessHelper_ApplyChanges(changeRequest_);
439 if (errCode != MEDIA_LIBRARY_OK) {
440 MEDIA_ERR_LOG("CameraMovingPhotoModuleTest::onMovingPhotoDataPrepared apply changes fail");
441 return;
442 }
443
444 const char *uri = nullptr;
445 errCode = OH_MovingPhoto_GetUri(movingPhoto_, &uri);
446 if (errCode != MEDIA_LIBRARY_OK || uri == nullptr) {
447 MEDIA_ERR_LOG("CameraMovingPhotoModuleTest::onMovingPhotoDataPrepared get uri fail");
448 return;
449 }
450 MEDIA_INFO_LOG("CameraMovingPhotoModuleTest::onMovingPhotoDataPrepared get uri is %{public}s", uri);
451
452 errCode = OH_MediaAssetChangeRequest_Release(changeRequest_);
453 if (errCode != MEDIA_LIBRARY_OK) {
454 MEDIA_ERR_LOG("CameraMovingPhotoModuleTest::onMovingPhotoDataPrepared release change request fail");
455 return;
456 }
457 }
458
MediaAssetManagerRequestMovingPhoto(OH_MediaLibrary_OnMovingPhotoDataPrepared callback)459 int32_t CameraMovingPhotoModuleTest::MediaAssetManagerRequestMovingPhoto(
460 OH_MediaLibrary_OnMovingPhotoDataPrepared callback)
461 {
462 mediaAssetManager_ = OH_MediaAssetManager_Create();
463 CHECK_ERROR_RETURN_RET_LOG(mediaAssetManager_ == nullptr, SERVICE_FATL_ERROR,
464 "Create media asset manager failed");
465
466 MediaLibrary_RequestId requestId;
467 MediaLibrary_RequestOptions requestOptions;
468 requestOptions.deliveryMode = MEDIA_LIBRARY_HIGH_QUALITY_MODE;
469 int32_t result = OH_MediaAssetManager_RequestMovingPhoto(mediaAssetManager_, mediaAsset_, requestOptions,
470 &requestId, callback);
471 CHECK_ERROR_RETURN_RET_LOG(result != MEDIA_LIBRARY_OK, SERVICE_FATL_ERROR,
472 "media asset manager request moving photo failed");
473 return SUCCESS;
474 }
475
ReleaseMediaAsset()476 void CameraMovingPhotoModuleTest::ReleaseMediaAsset()
477 {
478 if (mediaAsset_) {
479 OH_MediaAsset_Release(mediaAsset_);
480 mediaAsset_ = nullptr;
481 }
482 if (movingPhoto_) {
483 OH_MovingPhoto_Release(movingPhoto_);
484 movingPhoto_ = nullptr;
485 }
486 if (mediaAssetManager_) {
487 OH_MediaAssetManager_Release(mediaAssetManager_);
488 mediaAssetManager_ = nullptr;
489 }
490 }
491
492 /*
493 * Feature: Framework
494 * Function: Test the normal scenario of movingphoto.
495 * SubFunction: NA
496 * FunctionPoints: NA
497 * EnvConditions: NA
498 * CaseDescription: Test the normal scenario of movingphoto,Call the EnableMovingPhoto function
499 * after submitting the camera settings,and expect the movingphoto feature can be turned on successfully.
500 */
501 HWTEST_F(CameraMovingPhotoModuleTest, camera_moving_photo_moduletest_001, TestSize.Level0)
502 {
503 EXPECT_EQ(session_->BeginConfig(), SUCCESS);
504 EXPECT_EQ(session_->AddInput((sptr<CaptureInput>&)input_), SUCCESS);
505 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)previewOutput_), SUCCESS);
506 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)photoOutput_), SUCCESS);
507 EXPECT_EQ(session_->CommitConfig(), SUCCESS);
508
509 if (session_->IsMovingPhotoSupported()) {
510 session_->LockForControl();
511 EXPECT_EQ(session_->EnableMovingPhoto(true), CameraErrorCode::SUCCESS);
512 session_->UnlockForControl();
513 }
514
515 EXPECT_EQ(session_->Start(), SUCCESS);
516 sleep(WAIT_TIME_AFTER_START);
517
518 EXPECT_EQ(photoOutput_->Capture(), SUCCESS);
519 sleep(WAIT_TIME_AFTER_CAPTURE);
520
521 EXPECT_EQ(session_->Stop(), SUCCESS);
522 }
523
524 /*
525 * Feature: Framework
526 * Function: Test the abnormal scenario of movingphoto.
527 * SubFunction: NA
528 * FunctionPoints: NA
529 * EnvConditions: NA
530 * CaseDescription: Test the abnormal scenario of movingphoto,Call the EnableMovingPhoto function then tunrn off
531 * after submitting the camera settings,and expect the movingphoto feature can not be turned on successfully.
532 */
533 HWTEST_F(CameraMovingPhotoModuleTest, camera_moving_photo_moduletest_002, TestSize.Level0)
534 {
535 EXPECT_EQ(session_->BeginConfig(), SUCCESS);
536 EXPECT_EQ(session_->AddInput((sptr<CaptureInput>&)input_), SUCCESS);
537 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)previewOutput_), SUCCESS);
538 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)photoOutput_), SUCCESS);
539 EXPECT_EQ(session_->CommitConfig(), SUCCESS);
540
541 if (session_->IsMovingPhotoSupported()) {
542 session_->LockForControl();
543 EXPECT_EQ(session_->EnableMovingPhoto(true), CameraErrorCode::SUCCESS);
544 session_->UnlockForControl();
545 EXPECT_EQ(session_->IsMovingPhotoEnabled(), true);
546 session_->LockForControl();
547 EXPECT_EQ(session_->EnableMovingPhoto(false), CameraErrorCode::SUCCESS);
548 session_->UnlockForControl();
549 EXPECT_EQ(session_->IsMovingPhotoEnabled(), false);
550 }
551
552 EXPECT_EQ(session_->Start(), SUCCESS);
553 sleep(WAIT_TIME_AFTER_START);
554
555 EXPECT_EQ(photoOutput_->Capture(), SUCCESS);
556 sleep(WAIT_TIME_AFTER_CAPTURE);
557
558 EXPECT_EQ(session_->Stop(), SUCCESS);
559 }
560
561 /*
562 * Feature: Framework
563 * Function: Test the normal scenario of movingphoto.
564 * SubFunction: NA
565 * FunctionPoints: NA
566 * EnvConditions: NA
567 * CaseDescription: Test the normal scenario of movingphoto,Call the EnableMovingPhotoMirror function
568 * after submitting the camera settings,and expect the movingphotomirror feature can be turned on successfully.
569 */
570 HWTEST_F(CameraMovingPhotoModuleTest, camera_moving_photo_moduletest_003, TestSize.Level0)
571 {
572 EXPECT_EQ(session_->BeginConfig(), SUCCESS);
573 EXPECT_EQ(session_->AddInput((sptr<CaptureInput>&)input_), SUCCESS);
574 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)previewOutput_), SUCCESS);
575 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)photoOutput_), SUCCESS);
576 EXPECT_EQ(session_->CommitConfig(), SUCCESS);
577
578 if (session_->IsMovingPhotoSupported()) {
579 session_->LockForControl();
580 EXPECT_EQ(session_->EnableMovingPhoto(true), CameraErrorCode::SUCCESS);
581 session_->UnlockForControl();
582 EXPECT_EQ(session_->EnableMovingPhotoMirror(true, true), CameraErrorCode::SUCCESS);
583 }
584
585 EXPECT_EQ(session_->Start(), SUCCESS);
586 sleep(WAIT_TIME_AFTER_START);
587
588 EXPECT_EQ(photoOutput_->Capture(), SUCCESS);
589 sleep(WAIT_TIME_AFTER_CAPTURE);
590
591 EXPECT_EQ(session_->Stop(), SUCCESS);
592 }
593
594 /*
595 * Feature: Framework
596 * Function: Test the normal scenario of movingphoto.
597 * SubFunction: NA
598 * FunctionPoints: NA
599 * EnvConditions: NA
600 * CaseDescription: Test the normal scenario of movingphoto,Call the EnableMovingPhotoMirror function then tunrn off
601 * after submitting the camera settings,and expect the movingphotomirror feature can be turned on successfully.
602 */
603 HWTEST_F(CameraMovingPhotoModuleTest, camera_moving_photo_moduletest_004, TestSize.Level0)
604 {
605 EXPECT_EQ(session_->BeginConfig(), SUCCESS);
606 EXPECT_EQ(session_->AddInput((sptr<CaptureInput>&)input_), SUCCESS);
607 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)previewOutput_), SUCCESS);
608 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)photoOutput_), SUCCESS);
609 EXPECT_EQ(session_->CommitConfig(), SUCCESS);
610
611 if (session_->IsMovingPhotoSupported()) {
612 session_->LockForControl();
613 EXPECT_EQ(session_->EnableMovingPhoto(true), CameraErrorCode::SUCCESS);
614 session_->UnlockForControl();
615 EXPECT_EQ(session_->EnableMovingPhotoMirror(true, true), CameraErrorCode::SUCCESS);
616 EXPECT_EQ(session_->EnableMovingPhotoMirror(false, true), CameraErrorCode::SUCCESS);
617 }
618
619 EXPECT_EQ(session_->Start(), SUCCESS);
620 sleep(WAIT_TIME_AFTER_START);
621
622 EXPECT_EQ(photoOutput_->Capture(), SUCCESS);
623 sleep(WAIT_TIME_AFTER_CAPTURE);
624
625 EXPECT_EQ(session_->Stop(), SUCCESS);
626 }
627
628 /*
629 * Feature: Framework
630 * Function: Test the abnormal scenario of movingphoto.
631 * SubFunction: NA
632 * FunctionPoints: NA
633 * EnvConditions: NA
634 * CaseDescription: Test the abnormal scenario of movingphoto,Call the EnableMovingPhoto function
635 * before starting the camera settings,and expect the movingphoto feature can not be turned on successfully.
636 */
637 HWTEST_F(CameraMovingPhotoModuleTest, camera_moving_photo_moduletest_005, TestSize.Level0)
638 {
639 if (session_->IsMovingPhotoSupported()) {
640 session_->LockForControl();
641 EXPECT_EQ(session_->EnableMovingPhoto(true), CameraErrorCode::SERVICE_FATL_ERROR);
642 session_->UnlockForControl();
643 }
644
645 EXPECT_EQ(session_->BeginConfig(), SUCCESS);
646 EXPECT_EQ(session_->AddInput((sptr<CaptureInput>&)input_), SUCCESS);
647 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)previewOutput_), SUCCESS);
648 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)photoOutput_), SUCCESS);
649 EXPECT_EQ(session_->CommitConfig(), SUCCESS);
650
651 EXPECT_EQ(session_->Start(), SUCCESS);
652 sleep(WAIT_TIME_AFTER_START);
653
654 EXPECT_EQ(photoOutput_->Capture(), SUCCESS);
655 sleep(WAIT_TIME_AFTER_CAPTURE);
656
657 EXPECT_EQ(session_->Stop(), SUCCESS);
658 }
659
660 /*
661 * Feature: Framework
662 * Function: Test the abnormal scenario of movingphoto.
663 * SubFunction: NA
664 * FunctionPoints: NA
665 * EnvConditions: NA
666 * CaseDescription: Test the abnormal scenario of movingphoto,Call the EnableMovingPhoto function
667 * before submitting the camera settings,and expect the movingphoto feature can not be turned on successfully.
668 */
669 HWTEST_F(CameraMovingPhotoModuleTest, camera_moving_photo_moduletest_006, TestSize.Level0)
670 {
671 EXPECT_EQ(session_->BeginConfig(), SUCCESS);
672 EXPECT_EQ(session_->AddInput((sptr<CaptureInput>&)input_), SUCCESS);
673 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)previewOutput_), SUCCESS);
674 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)photoOutput_), SUCCESS);
675 if (session_->IsMovingPhotoSupported()) {
676 session_->LockForControl();
677 EXPECT_EQ(session_->EnableMovingPhoto(true), CameraErrorCode::SUCCESS);
678 session_->UnlockForControl();
679 }
680 EXPECT_EQ(session_->CommitConfig(), SUCCESS);
681
682 EXPECT_EQ(session_->Start(), SUCCESS);
683 sleep(WAIT_TIME_AFTER_START);
684
685 EXPECT_EQ(photoOutput_->Capture(), SUCCESS);
686 sleep(WAIT_TIME_AFTER_CAPTURE);
687
688 EXPECT_EQ(session_->Stop(), SUCCESS);
689 }
690
691 /*
692 * Feature: Framework
693 * Function: Test the normal scenario of movingphoto.
694 * SubFunction: NA
695 * FunctionPoints: NA
696 * EnvConditions: NA
697 * CaseDescription: Test the normal scenario of movingphoto.
698 */
699 HWTEST_F(CameraMovingPhotoModuleTest, camera_moving_photo_moduletest_007, TestSize.Level0)
700 {
701 EXPECT_EQ(session_->BeginConfig(), SUCCESS);
702 EXPECT_EQ(session_->AddInput((sptr<CaptureInput>&)input_), SUCCESS);
703 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)previewOutput_), SUCCESS);
704 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)photoOutput_), SUCCESS);
705 PhotoOutputTest_PhotoAssetAvailable photoAssetCallback = onPhotoAssetAvailable;
706 EXPECT_EQ(RegisterPhotoAssetAvailableCallback(photoAssetCallback), SUCCESS);
707 EXPECT_EQ(session_->CommitConfig(), SUCCESS);
708
709 if (!session_->IsMovingPhotoSupported()) {
710 MEDIA_ERR_LOG("Camera device not support moving photo");
711 return;
712 }
713 session_->LockForControl();
714 EXPECT_EQ(session_->EnableMovingPhoto(true), SUCCESS);
715 session_->UnlockForControl();
716
717 EXPECT_EQ(session_->Start(), SUCCESS);
718 sleep(WAIT_TIME_AFTER_START);
719
720 EXPECT_EQ(photoOutput_->Capture(), SUCCESS);
721 sleep(WAIT_TIME_AFTER_CAPTURE);
722
723 if (!mediaAsset_) {
724 MEDIA_ERR_LOG("Midia asset is null after register photo asset available callback");
725 return;
726 }
727
728 MediaLibrary_MediaSubType mediaSubType = MEDIA_LIBRARY_DEFAULT;
729 EXPECT_EQ(OH_MediaAsset_GetMediaSubType(mediaAsset_, &mediaSubType), MEDIA_LIBRARY_OK);
730 EXPECT_EQ(mediaSubType, MediaLibrary_MediaSubType::MEDIA_LIBRARY_MOVING_PHOTO);
731
732 EXPECT_EQ(session_->Stop(), SUCCESS);
733 }
734
735 /*
736 * Feature: Framework
737 * Function: Test the normal scenario of movingphoto.
738 * SubFunction: NA
739 * FunctionPoints: NA
740 * EnvConditions: NA
741 * CaseDescription: Test the normal scenario of movingphoto with enable moving photo mirror.
742 */
743 HWTEST_F(CameraMovingPhotoModuleTest, camera_moving_photo_moduletest_008, TestSize.Level0)
744 {
745 EXPECT_EQ(session_->BeginConfig(), SUCCESS);
746 EXPECT_EQ(session_->AddInput((sptr<CaptureInput>&)input_), SUCCESS);
747 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)previewOutput_), SUCCESS);
748 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)photoOutput_), SUCCESS);
749 PhotoOutputTest_PhotoAssetAvailable photoAssetCallback = onPhotoAssetAvailable;
750 EXPECT_EQ(RegisterPhotoAssetAvailableCallback(photoAssetCallback), SUCCESS);
751 EXPECT_EQ(session_->CommitConfig(), SUCCESS);
752
753 if (!session_->IsMovingPhotoSupported()) {
754 MEDIA_ERR_LOG("Camera device not support moving photo");
755 return;
756 }
757 session_->LockForControl();
758 EXPECT_EQ(session_->EnableMovingPhoto(true), SUCCESS);
759 EXPECT_EQ(session_->EnableMovingPhotoMirror(true, true), SUCCESS);
760 session_->UnlockForControl();
761
762 EXPECT_EQ(session_->Start(), SUCCESS);
763 sleep(WAIT_TIME_AFTER_START);
764
765 EXPECT_EQ(photoOutput_->Capture(), SUCCESS);
766 sleep(WAIT_TIME_AFTER_CAPTURE);
767
768 if (!mediaAsset_) {
769 MEDIA_ERR_LOG("Midia asset is null after register photo asset available callback");
770 return;
771 }
772
773 MediaLibrary_MediaSubType mediaSubType = MEDIA_LIBRARY_DEFAULT;
774 EXPECT_EQ(OH_MediaAsset_GetMediaSubType(mediaAsset_, &mediaSubType), MEDIA_LIBRARY_OK);
775 EXPECT_EQ(mediaSubType, MediaLibrary_MediaSubType::MEDIA_LIBRARY_MOVING_PHOTO);
776
777 EXPECT_EQ(session_->Stop(), SUCCESS);
778 }
779
780 /*
781 * Feature: Framework
782 * Function: Test the abnormal scenario of movingphoto.
783 * SubFunction: NA
784 * FunctionPoints: NA
785 * EnvConditions: NA
786 * CaseDescription: Test the abnormal scenario of movingphoto with PhotoAssetAvailableCallback is null.
787 */
788 HWTEST_F(CameraMovingPhotoModuleTest, camera_moving_photo_moduletest_009, TestSize.Level0)
789 {
790 EXPECT_EQ(session_->BeginConfig(), SUCCESS);
791 EXPECT_EQ(session_->AddInput((sptr<CaptureInput>&)input_), SUCCESS);
792 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)previewOutput_), SUCCESS);
793 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)photoOutput_), SUCCESS);
794 PhotoOutputTest_PhotoAssetAvailable callback = nullptr;
795 EXPECT_EQ(RegisterPhotoAssetAvailableCallback(callback), SUCCESS);
796 EXPECT_EQ(session_->CommitConfig(), SUCCESS);
797
798 if (!session_->IsMovingPhotoSupported()) {
799 MEDIA_ERR_LOG("Camera device not support moving photo");
800 return;
801 }
802 session_->LockForControl();
803 EXPECT_EQ(session_->EnableMovingPhoto(true), SUCCESS);
804 session_->UnlockForControl();
805
806 EXPECT_EQ(session_->Start(), SUCCESS);
807 sleep(WAIT_TIME_AFTER_START);
808
809 EXPECT_EQ(photoOutput_->Capture(), SUCCESS);
810 sleep(WAIT_TIME_AFTER_CAPTURE);
811
812 EXPECT_EQ(mediaAsset_, nullptr);
813
814 EXPECT_EQ(session_->Stop(), SUCCESS);
815 }
816
817 /*
818 * Feature: Framework
819 * Function: Test the abnormal scenario of movingphoto.
820 * SubFunction: NA
821 * FunctionPoints: NA
822 * EnvConditions: NA
823 * CaseDescription: Test the abnormal scenario of movingphoto with MovingPhotoDataPrepared is null.
824 */
825 HWTEST_F(CameraMovingPhotoModuleTest, camera_moving_photo_moduletest_010, TestSize.Level0)
826 {
827 EXPECT_EQ(session_->BeginConfig(), SUCCESS);
828 EXPECT_EQ(session_->AddInput((sptr<CaptureInput>&)input_), SUCCESS);
829 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)previewOutput_), SUCCESS);
830 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)photoOutput_), SUCCESS);
831 PhotoOutputTest_PhotoAssetAvailable photoAssetCallback = onPhotoAssetAvailable;
832 EXPECT_EQ(RegisterPhotoAssetAvailableCallback(photoAssetCallback), SUCCESS);
833 EXPECT_EQ(session_->CommitConfig(), SUCCESS);
834
835 if (!session_->IsMovingPhotoSupported()) {
836 MEDIA_ERR_LOG("Camera device not support moving photo");
837 return;
838 }
839 session_->LockForControl();
840 EXPECT_EQ(session_->EnableMovingPhoto(true), SUCCESS);
841 session_->UnlockForControl();
842
843 EXPECT_EQ(session_->Start(), SUCCESS);
844 sleep(WAIT_TIME_AFTER_START);
845
846 EXPECT_EQ(photoOutput_->Capture(), SUCCESS);
847 sleep(WAIT_TIME_AFTER_CAPTURE);
848
849 if (!mediaAsset_) {
850 MEDIA_ERR_LOG("Midia asset is null after register photo asset available callback");
851 return;
852 }
853
854 OH_MediaLibrary_OnMovingPhotoDataPrepared movingPhotoCallback = nullptr;
855 EXPECT_EQ(MediaAssetManagerRequestMovingPhoto(movingPhotoCallback), SERVICE_FATL_ERROR);
856 sleep(WAIT_TIME_CALLBACK);
857
858 EXPECT_EQ(movingPhoto_, nullptr);
859
860 EXPECT_EQ(session_->Stop(), SUCCESS);
861 }
862
863 /*
864 * Feature: Framework
865 * Function: Test the abnormal scenario of movingphoto.
866 * SubFunction: NA
867 * FunctionPoints: NA
868 * EnvConditions: NA
869 * CaseDescription: Test the abnormal scenario of movingphoto with disable moving photo.
870 */
871 HWTEST_F(CameraMovingPhotoModuleTest, camera_moving_photo_moduletest_011, TestSize.Level0)
872 {
873 EXPECT_EQ(session_->BeginConfig(), SUCCESS);
874 EXPECT_EQ(session_->AddInput((sptr<CaptureInput>&)input_), SUCCESS);
875 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)previewOutput_), SUCCESS);
876 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)photoOutput_), SUCCESS);
877 PhotoOutputTest_PhotoAssetAvailable photoAssetCallback = onPhotoAssetAvailable;
878 EXPECT_EQ(RegisterPhotoAssetAvailableCallback(photoAssetCallback), SUCCESS);
879 EXPECT_EQ(session_->CommitConfig(), SUCCESS);
880
881 if (!session_->IsMovingPhotoSupported()) {
882 MEDIA_ERR_LOG("Camera device not support moving photo");
883 return;
884 }
885 session_->LockForControl();
886 EXPECT_EQ(session_->EnableMovingPhoto(false), SUCCESS);
887 session_->UnlockForControl();
888
889 EXPECT_EQ(session_->Start(), SUCCESS);
890 sleep(WAIT_TIME_AFTER_START);
891
892 EXPECT_EQ(photoOutput_->Capture(), SUCCESS);
893 sleep(WAIT_TIME_AFTER_CAPTURE);
894
895 if (!mediaAsset_) {
896 MEDIA_ERR_LOG("Midia asset is null after register photo asset available callback");
897 return;
898 }
899
900 MediaLibrary_MediaSubType mediaSubType = MEDIA_LIBRARY_DEFAULT;
901 EXPECT_EQ(OH_MediaAsset_GetMediaSubType(mediaAsset_, &mediaSubType), MEDIA_LIBRARY_OK);
902 EXPECT_NE(mediaSubType, MediaLibrary_MediaSubType::MEDIA_LIBRARY_MOVING_PHOTO);
903
904 EXPECT_EQ(session_->Stop(), SUCCESS);
905 }
906
907 /*
908 * Feature: Framework
909 * Function: Test the abnormal scenario of movingphoto.
910 * SubFunction: NA
911 * FunctionPoints: NA
912 * EnvConditions: NA
913 * CaseDescription: Test the abnormal scenario of movingphoto with UnregisterPhotoAssetAvailableCallback.
914 */
915 HWTEST_F(CameraMovingPhotoModuleTest, camera_moving_photo_moduletest_012, TestSize.Level0)
916 {
917 EXPECT_EQ(session_->BeginConfig(), SUCCESS);
918 EXPECT_EQ(session_->AddInput((sptr<CaptureInput>&)input_), SUCCESS);
919 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)previewOutput_), SUCCESS);
920 EXPECT_EQ(session_->AddOutput((sptr<CaptureOutput>&)photoOutput_), SUCCESS);
921 PhotoOutputTest_PhotoAssetAvailable photoAssetCallback = onPhotoAssetAvailable;
922 EXPECT_EQ(RegisterPhotoAssetAvailableCallback(photoAssetCallback), SUCCESS);
923 EXPECT_EQ(session_->CommitConfig(), SUCCESS);
924
925 if (!session_->IsMovingPhotoSupported()) {
926 MEDIA_ERR_LOG("Camera device not support moving photo");
927 return;
928 }
929 session_->LockForControl();
930 EXPECT_EQ(session_->EnableMovingPhoto(true), SUCCESS);
931 session_->UnlockForControl();
932
933 EXPECT_EQ(session_->Start(), SUCCESS);
934 sleep(WAIT_TIME_AFTER_START);
935
936 ReleaseMediaAsset();
937 UnregisterPhotoAssetAvailableCallback(photoAssetCallback);
938
939 EXPECT_EQ(photoOutput_->Capture(), SUCCESS);
940 sleep(WAIT_TIME_AFTER_CAPTURE);
941 ASSERT_EQ(mediaAsset_, nullptr);
942
943 EXPECT_EQ(session_->Stop(), SUCCESS);
944 }
945
946 } // namespace CameraStandard
947 } // namespace OHOS