• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020-2021 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_lite_test.h"
17 
18 #include <components/ui_surface_view.h>
19 #include <sys/stat.h>
20 #include <sys/time.h>
21 #include <sys/types.h>
22 
23 #include <algorithm>
24 #include <cstdlib>
25 #include <fstream>
26 #include <iostream>
27 #include <memory>
28 #include <sstream>
29 #include <string>
30 
31 #include "camera_kit.h"
32 
33 using namespace std;
34 using namespace OHOS;
35 using namespace OHOS::Media;
36 using namespace testing::ext;
37 
38 namespace OHOS {
39 /* *
40  * get current dir
41  * @return  string current file path of the test suits
42  */
GetCurDir()43 string GetCurDir()
44 {
45     string filePath = "";
46     char *buffer;
47     if ((buffer = getcwd(NULL, 0)) == NULL) {
48         perror("get file path error");
49     } else {
50         printf("Current Dir: %s\r\n", buffer);
51         filePath = buffer;
52         free(buffer);
53     }
54     return filePath + "/";
55 }
56 
57 // SetUpTestCase
SetUpTestCase(void)58 void CameraLiteTest::SetUpTestCase(void)
59 {
60     g_testPath = GetCurDir();
61     cout << "SetUpTestCase" << endl;
62 }
63 
64 // TearDownTestCase
TearDownTestCase(void)65 void CameraLiteTest::TearDownTestCase(void)
66 {
67     g_testPath = "";
68     cout << "TearDownTestCase" << endl;
69 }
70 
SetUp(void)71 void CameraLiteTest::SetUp(void)
72 {
73     // CameraSetUp
74     g_onGetCameraAbilityFlag = false;
75     g_onConfigureFlag = false;
76     g_onGetSupportedSizesFlag = false;
77 
78     // CameraDeviceCallBack
79     g_onCameraAvailableFlag = false;
80     g_onCameraUnavailableFlag = false;
81 
82     // CameraStateCallback
83     g_onCreatedFlag = false;
84     g_onCreateFailedFlag = false;
85     g_onConfiguredFlag = false;
86     g_onConfigureFailedFlag = false;
87     g_onReleasedFlag = false;
88 
89     // FrameStateCallback
90     g_onCaptureTriggerAbortedFlag = false;
91     g_onCaptureTriggerCompletedFlag = false;
92     g_onCaptureTriggerStartedFlag = false;
93     g_onFrameFinishedFlag = false;
94     g_onGetFrameConfigureType = false;
95     g_onFrameErrorFlag = false;
96     g_onFrameProgressedFlag = false;
97     g_onFrameStartedFlag = false;
98     g_onRecorderFlag = false;
99     cout << "SetUp" << endl;
100 }
101 
102 // Tear down
TearDown(void)103 void CameraLiteTest::TearDown(void)
104 {
105     cout << "TearDown." << endl;
106 }
107 
SetupAudioSource(const Recorder & rec)108 int32_t SetupAudioSource(const Recorder &rec)
109 {
110     Recorder *recorder = (Recorder *)&rec;
111     int32_t ret = SUCCESS;
112     int32_t audioSourceId = 0;
113     AudioCodecFormat audioFormat = AAC_LC;
114     AudioSourceType inputSource = AUDIO_MIC;
115     int32_t sampleRate = 48000;
116     int32_t channelCount = 1;
117     int32_t audioEncodingBitRate = sampleRate;
118     if ((ret = recorder->SetAudioSource(inputSource, audioSourceId)) != SUCCESS) {
119         cout << "SetAudioSource failed." << ret << endl;
120         return FAIL;
121     }
122     if ((ret = recorder->SetAudioEncoder(audioSourceId, audioFormat)) != SUCCESS) {
123         cout << "SetAudioEncoder failed." << ret << endl;
124         return FAIL;
125     }
126     if ((ret = recorder->SetAudioSampleRate(audioSourceId, sampleRate)) != SUCCESS) {
127         cout << "SetAudioSampleRate failed." << ret << endl;
128         return FAIL;
129     }
130     if ((ret = recorder->SetAudioChannels(audioSourceId, channelCount)) != SUCCESS) {
131         cout << "SetAudioChannels failed." << ret << endl;
132         return FAIL;
133     }
134     if ((ret = recorder->SetAudioEncodingBitRate(audioSourceId, audioEncodingBitRate)) != SUCCESS) {
135         cout << "SetAudioEncodingBitRate failed." << ret << endl;
136         return FAIL;
137     }
138     return SUCCESS;
139 }
140 
141 /* *
142  * creat Recorder
143  */
SampleCreateRecorder()144 Recorder *SampleCreateRecorder()
145 {
146     int ret = 0;
147     VideoSourceType source = VIDEO_SOURCE_SURFACE_ES;
148     int32_t frameRate = 30;
149     double fps = 30;
150     int32_t rate = 4096;
151     int32_t sourceId = 0;
152     int32_t width = 1920;
153     int32_t height = 1080;
154     VideoCodecFormat encoder = HEVC;
155     Recorder *recorder = new Recorder();
156     if ((ret = recorder->SetVideoSource(source, sourceId)) != SUCCESS) {
157         cout << "SetVideoSource failed." << ret << endl;
158         delete recorder;
159         return nullptr;
160     }
161     if ((ret = recorder->SetVideoEncoder(sourceId, encoder)) != SUCCESS) {
162         cout << "SetVideoEncoder failed." << ret << endl;
163         delete recorder;
164         return nullptr;
165     }
166     if ((ret = recorder->SetVideoSize(sourceId, width, height)) != SUCCESS) {
167         cout << "SetVideoSize failed." << ret << endl;
168         delete recorder;
169         return nullptr;
170     }
171     if ((ret = recorder->SetVideoFrameRate(sourceId, frameRate)) != SUCCESS) {
172         cout << "SetVideoFrameRate failed." << ret << endl;
173         delete recorder;
174         return nullptr;
175     }
176     if ((ret = recorder->SetVideoEncodingBitRate(sourceId, rate)) != SUCCESS) {
177         cout << "SetVideoEncodingBitRate failed." << ret << endl;
178         delete recorder;
179         return nullptr;
180     }
181     if ((ret = recorder->SetCaptureRate(sourceId, fps)) != SUCCESS) {
182         cout << "SetCaptureRate failed." << ret << endl;
183         delete recorder;
184         return nullptr;
185     }
186     if ((ret = SetupAudioSource(*recorder) != SUCCESS)) {
187         delete recorder;
188         return nullptr;
189     }
190     return recorder;
191 }
192 
193 /* *
194  * Create Frame StateCallback
195  */
196 class SampleFrameStateCallback : public FrameStateCallback {
197     /* *
198      * check file exist
199      *
200      * @param filename the filename
201      * @return  check result
202      */
FileCheck(const string & filename)203     int32_t FileCheck(const string &filename)
204     {
205         fstream fileTmp;
206         fileTmp.open(filename);
207         if (!fileTmp) {
208             cout << "file is not exist!" << endl;
209             return RET_ERR;
210         } else {
211             cout << "file is exist!" << endl;
212             fileTmp.close();
213             return RET_OK;
214         }
215     }
216 
217     /* *
218      * Save Capture
219      *
220      * @param testPath the file path
221      * @param buffer the buffer
222      * @param size the size
223      * @return save result
224      */
SampleSaveCapture(string testPath,const char * buffer,uint32_t size)225     int32_t SampleSaveCapture(string testPath, const char *buffer, uint32_t size)
226     {
227         cout << "Start saving picture" << endl;
228         string filePath = "";
229         struct timeval tv = {0};
230 
231         gettimeofday(&tv, NULL);
232         struct tm *ltm = localtime(&tv.tv_sec);
233         if (ltm != nullptr) {
234             ostringstream ss("Capture_");
235             ss << "Capture" << ltm->tm_hour << "_" << ltm->tm_min << "_" << ltm->tm_sec << ".jpg";
236             filePath = testPath + ss.str();
237             ofstream pic(testPath + ss.str(), ofstream::out | ofstream::trunc);
238             cout << "write " << size << " bytes" << endl;
239             pic.write(buffer, size);
240             cout << "Saving picture end" << endl;
241         }
242         const char *filename = filePath.data();
243         int32_t ret = FileCheck(string(filename));
244         return ret;
245     }
246 
OnFrameFinished(Camera & cam,FrameConfig & fc,FrameResult & res)247     void OnFrameFinished(Camera &cam, FrameConfig &fc, FrameResult &res) override
248     {
249         g_onFrameStartedFlag = true;
250         g_onFrameProgressedFlag = true;
251         cout << "Receive frame complete inform." << endl;
252         if (fc.GetFrameConfigType() == FRAME_CONFIG_CAPTURE) {
253             g_onGetFrameConfigureType = true;
254             cout << "Capture frame received." << endl;
255             list<Surface *> surfaceList = fc.GetSurfaces();
256             for (Surface *surface : surfaceList) {
257                 SurfaceBuffer *buffer = surface->AcquireBuffer();
258                 if (buffer != nullptr) {
259                     char *virtAddr = static_cast<char *>(buffer->GetVirAddr());
260                     if (virtAddr != nullptr) {
261                         SampleSaveCapture(g_testPath, virtAddr, buffer->GetSize());
262                     } else {
263                         g_onFrameErrorFlag = true;
264                     }
265                     surface->ReleaseBuffer(buffer);
266                 } else {
267                     g_onFrameErrorFlag = true;
268                 }
269                 delete surface;
270             }
271             delete &fc;
272         } else {
273             g_onFrameErrorFlag = true;
274         }
275         g_onFrameFinishedFlag = true;
276     }
277 };
278 
279 /* *
280  * create CameraStateCallback
281  */
282 class SampleCameraStateMng : public CameraStateCallback {
283 public:
284     SampleCameraStateMng() = delete;
285 
SampleCameraStateMng(EventHandler & eventHdlr)286     explicit SampleCameraStateMng(EventHandler &eventHdlr) : eventHandler_(eventHdlr) {}
287 
~SampleCameraStateMng()288     ~SampleCameraStateMng()
289     {
290         if (recorder_ != nullptr) {
291             recorder_->Release();
292         }
293         if (cam_ != nullptr) {
294             cam_->Release();
295         }
296     }
297 
OnCreated(Camera & c)298     void OnCreated(Camera &c) override
299     {
300         g_onCreatedFlag = true;
301         cout << "Sample recv OnCreate camera." << endl;
302         auto config = CameraConfig::CreateCameraConfig();
303         config->SetFrameStateCallback(&fsCb, &eventHandler_);
304         c.Configure(*config);
305         g_onConfigureFlag = true;
306         cam_ = &c;
307     }
308 
OnCreateFailed(const std::string cameraId,int32_t errorCode)309     void OnCreateFailed(const std::string cameraId, int32_t errorCode) override
310     {
311         g_onCreateFailedFlag = true;
312         cout << "Camera  ID: " << cameraId << endl;
313         cout << "Sample recv OnCreateFailed camera.: " << errorCode << endl;
314     }
315 
OnReleased(Camera & c)316     void OnReleased(Camera &c) override
317     {
318         g_onReleasedFlag = true;
319         cout << "Sample recv OnReleased camera." << endl;
320     }
321 
StartRecord()322     void StartRecord()
323     {
324         int ret;
325         if (isRecording_) {
326             cout << "Camera is already recording." << endl;
327             return;
328         }
329         if (recorder_ != nullptr) {
330             cout << "Recorder is not null" << endl;
331         }
332         recorder_ = SampleCreateRecorder();
333         if (recorder_ == nullptr) {
334             cout << "Recorder not available" << endl;
335             return;
336         }
337         string path = GetCurDir();
338         ret = recorder_->SetOutputPath(path);
339         if (ret != SUCCESS) {
340             cout << "SetOutputPath failed :" << ret << std::endl;
341             return;
342         }
343 
344         ret = recorder_->Prepare();
345         if (ret != SUCCESS) {
346             cout << "Prepare failed.=" << ret << endl;
347             return;
348         }
349         auto surface = recorder_->GetSurface(0);
350         surface->SetWidthAndHeight(WIDTH, HEIGHT);
351         surface->SetQueueSize(QUEUE_SIZE);
352         surface->SetSize(BUFFER_SIZE * BUFFER_SIZE);
353         FrameConfig *fc = new FrameConfig(FRAME_CONFIG_RECORD);
354         fc->AddSurface(*surface);
355         ret = recorder_->Start();
356         if (ret != SUCCESS) {
357             cout << "recorder start failed. ret=" << ret << endl;
358             delete fc;
359             return;
360         }
361         static int cnt = 3;
362         while (cam_ == nullptr) {
363             if (cnt-- < 0)
364                 break;
365             cout << "Wait camera created success" << endl;
366             sleep(1);
367         }
368 
369         ret = cam_->TriggerLoopingCapture(*fc);
370         if (ret != 0) {
371             cout << "camera start recording failed. ret=" << ret << endl;
372             return;
373         }
374         isRecording_ = true;
375         g_onRecorderFlag = true;
376         cout << "camera start recording succeed." << endl;
377     }
378 
StartPreview()379     void StartPreview()
380     {
381         if (isPreviewing_) {
382             cout << "Camera is already previewing." << endl;
383             return;
384         }
385         FrameConfig *fc = new FrameConfig(FRAME_CONFIG_PREVIEW);
386         UISurfaceView *surface = new UISurfaceView();
387         int width = 960;
388         int height = 480;
389         if (surface == nullptr) {
390             cout << "CreateSurface failed" << endl;
391             delete fc;
392             return;
393         }
394         surface->SetPosition(0, 0, width, height);
395         surface->GetSurface()->SetWidthAndHeight(WIDTH, HEIGHT);
396         fc->AddSurface(*(surface->GetSurface()));
397         static int cnt = 3;
398         while (cam_ == nullptr) {
399             if (cnt-- < 0)
400                 break;
401             cout << "Wait camera created success" << endl;
402             sleep(1);
403         }
404         int32_t ret = cam_->TriggerLoopingCapture(*fc);
405         if (ret != 0) {
406             cout << "camera start preview failed. ret=" << ret << endl;
407             delete fc;
408             return;
409         }
410         delete surface;
411         isPreviewing_ = true;
412         g_onPreviewFlag = true;
413         cout << "camera start preview succeed." << endl;
414     }
415 
Capture(void)416     void Capture(void)
417     {
418         FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
419         Surface *surface = Surface::CreateSurface();
420         if (surface == nullptr) {
421             cout << "CreateSurface failed" << endl;
422             delete fc;
423             return;
424         }
425         surface->SetWidthAndHeight(WIDTH, HEIGHT);
426         fc->AddSurface(*surface);
427         static int cnt = 3;
428         while (cam_ == nullptr) {
429             if (cnt-- < 0)
430                 break;
431             cout << "Wait camera created success" << endl;
432             sleep(1);
433         }
434         g_onCaptureTriggerStartedFlag = true;
435         cam_->TriggerSingleCapture(*fc);
436         g_onCaptureTriggerCompletedFlag = true;
437     }
438 
Stop()439     void Stop()
440     {
441         if (recorder_ != nullptr) {
442             int32_t ret = recorder_->Stop(true);
443             if (ret != 0) {
444                 cout << "recorder_ stop failed. ret=" << ret << endl;
445             }
446         }
447 
448         while (cam_ == nullptr) {
449             cout << "Camera is not ready." << endl;
450             return;
451         }
452         cam_->StopLoopingCapture();
453         isPreviewing_ = false;
454         isRecording_ = false;
455         g_onRecorderFlag = false;
456         g_onPreviewFlag = false;
457     }
458 
459     bool isPreviewing_ = false;
460     bool isRecording_ = false;
461     EventHandler &eventHandler_;
462     Camera *cam_ = nullptr;
463     Recorder *recorder_ = nullptr;
464     SampleFrameStateCallback fsCb;
465 };
466 
467 /* *
468  * create CameraStateCallback for state test
469  */
470 class SampleCameraStateCallback : public CameraStateCallback {
471 public:
472     SampleCameraStateCallback() = delete;
473 
SampleCameraStateCallback(EventHandler & eventHdlr)474     explicit SampleCameraStateCallback(EventHandler &eventHdlr) : eventHandler_(eventHdlr) {}
475 
~SampleCameraStateCallback()476     ~SampleCameraStateCallback()
477     {
478         if (cam_ != nullptr) {
479             cam_->Release();
480         }
481     }
482 
OnCreated(Camera & c)483     void OnCreated(Camera &c) override
484     {
485         g_onCreatedFlag = true;
486         cout << "camera Create success." << endl;
487         auto config = CameraConfig::CreateCameraConfig();
488         config->SetFrameStateCallback(&fsCb, &eventHandler_);
489         c.Configure(*config);
490         cam_ = &c;
491     }
492 
OnCreateFailed(const std::string cameraId,int32_t errorCode)493     void OnCreateFailed(const std::string cameraId, int32_t errorCode) override
494     {
495         g_onCreateFailedFlag = true;
496         cout << "Camera  ID: " << cameraId << endl;
497         cout << "Camera Create Failed: " << errorCode << endl;
498     }
499 
OnReleased(Camera & c)500     void OnReleased(Camera &c) override
501     {
502         g_onReleasedFlag = true;
503         cout << "camera Releasedsuccess." << endl;
504     }
505 
OnConfigured(Camera & c)506     void OnConfigured(Camera &c) override
507     {
508         g_onConfiguredFlag = true;
509         cout << "Camera Configured success." << endl;
510     }
511 
OnConfigureFailed(const std::string cameraId,int32_t errorCode)512     void OnConfigureFailed(const std::string cameraId, int32_t errorCode) override
513     {
514         g_onConfigureFailedFlag = true;
515         cout << "Camera  ID: " << cameraId << endl;
516         cout << "Camera Configured failed: " << errorCode << endl;
517     }
518 
519     EventHandler &eventHandler_;
520     Camera *cam_ = nullptr;
521     SampleFrameStateCallback fsCb;
522 };
523 
524 /* *
525  * Creat camera device callback
526  */
527 class SampleCameraDeviceCallback : public CameraDeviceCallback {
528 public:
SampleCameraDeviceCallback()529     SampleCameraDeviceCallback() {}
530 
~SampleCameraDeviceCallback()531     ~SampleCameraDeviceCallback() {}
532 
OnCameraStatus(std::string cameraId,int32_t status)533     void OnCameraStatus(std::string cameraId, int32_t status) override
534     {
535         cout << "SampleCameraDeviceCallback OnCameraStatus cam Id: \n" << cameraId << endl;
536         if (status == CAMERA_DEVICE_STATE_AVAILABLE) {
537             g_onCameraAvailableFlag = true;
538             cout << "SampleCameraDeviceCallback onCameraAvailable\n" << endl;
539         } else if (status == CAMERA_DEVICE_STATE_UNAVAILABLE) {
540             g_onCameraUnavailableFlag = true;
541             cout << "SampleCameraDeviceCallback onCameraUnavailable\n" << endl;
542         }
543     }
544 };
545 
546 /* *
547  * Get camera Id
548  */
GetCameraId(CameraKit * cameraKit,list<string> & cameraList,string & cameraId)549 bool GetCameraId(CameraKit *cameraKit, list<string> &cameraList, string &cameraId)
550 {
551     cameraKit = CameraKit::GetInstance();
552     cameraList = cameraKit->GetCameraIds();
553     for (auto &cam : cameraList) {
554         cout << "camera name:" << cam << endl;
555         const CameraAbility *ability = cameraKit->GetCameraAbility(cam);
556         g_onGetCameraAbilityFlag = true;
557         /* find camera which fits user's ability */
558         list<CameraPicSize> sizeList = ability->GetSupportedSizes(0);
559         if (sizeList.size() != 0) {
560             g_onGetSupportedSizesFlag = true;
561         }
562         for (auto &pic : sizeList) {
563             cout << "Pic size: " << pic.width << "x" << pic.height << endl;
564             if (pic.width == WIDTH && pic.height == HEIGHT) {
565                 /* 1920:width,1080:height */
566                 cameraId = cam;
567                 break;
568             }
569         }
570     }
571 
572     if (cameraId.empty()) {
573         cout << "No available camera.(1080p wanted)" << endl;
574         return false;
575     } else
576         return true;
577 }
578 
579 /* start camera kit interface test */
HWTEST_F(CameraLiteTest,Test_GetInstance_001,Level1)580 HWTEST_F(CameraLiteTest, Test_GetInstance_001, Level1)
581 {
582     CameraKit *cameraKit = CameraKit::GetInstance();
583     EXPECT_NE(cameraKit, nullptr);
584 }
585 
HWTEST_F(CameraLiteTest,PrfTest_GetInstance_001,Level1)586 HWTEST_F(CameraLiteTest, PrfTest_GetInstance_001, Level1)
587 {
588     CameraKit *cameraKit = nullptr;
589     struct timespec tv1 = {0};
590     struct timespec tv2 = {0};
591     int64_t performanceTestTimes = 10;
592     int64_t usecTimes = 1000000;
593     int64_t totalTime = 0;
594     for (int32_t i = 0; i < performanceTestTimes; i++) {
595         clock_gettime(CLOCK_REALTIME, &tv1);
596         cameraKit = CameraKit::GetInstance();
597         clock_gettime(CLOCK_REALTIME, &tv2);
598         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
599     }
600     int64_t expectTime = 1000000;
601     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
602 }
603 
HWTEST_F(CameraLiteTest,Test_GetCameraIds_001,Level1)604 HWTEST_F(CameraLiteTest, Test_GetCameraIds_001, Level1)
605 {
606     CameraKit *cameraKit = CameraKit::GetInstance();
607     list<string> cameraList = cameraKit->GetCameraIds();
608     EXPECT_TRUE(cameraList.size() > 0);
609 }
610 
HWTEST_F(CameraLiteTest,PrfTest_GetCameraIds_001,Level1)611 HWTEST_F(CameraLiteTest, PrfTest_GetCameraIds_001, Level1)
612 {
613     CameraKit *cameraKit = CameraKit::GetInstance();
614     list<string> cameraList;
615     struct timespec tv1 = {0};
616     struct timespec tv2 = {0};
617     int64_t performanceTestTimes = 10;
618     int64_t usecTimes = 1000000;
619     int64_t totalTime = 0;
620     for (int32_t i = 0; i < performanceTestTimes; i++) {
621         clock_gettime(CLOCK_REALTIME, &tv1);
622         cameraList = cameraKit->GetCameraIds();
623         clock_gettime(CLOCK_REALTIME, &tv2);
624         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
625     }
626     int64_t expectTime = 1000000;
627     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
628 }
629 
HWTEST_F(CameraLiteTest,Test_GetCameraAbility_001,Level1)630 HWTEST_F(CameraLiteTest, Test_GetCameraAbility_001, Level1)
631 {
632     CameraKit *cameraKit = CameraKit::GetInstance();
633     string cameraId = "0";
634     const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
635     EXPECT_NE(ability, nullptr);
636 }
637 
HWTEST_F(CameraLiteTest,Test_GetCameraAbility_002,Level1)638 HWTEST_F(CameraLiteTest, Test_GetCameraAbility_002, Level1)
639 {
640     CameraKit *cameraKit = CameraKit::GetInstance();
641     string errorCameraId = "-1";
642     const CameraAbility *ability = cameraKit->GetCameraAbility(errorCameraId);
643     EXPECT_EQ(ability, nullptr);
644 }
645 
HWTEST_F(CameraLiteTest,Test_GetCameraAbility_003,Level1)646 HWTEST_F(CameraLiteTest, Test_GetCameraAbility_003, Level1)
647 {
648     CameraKit *cameraKit = CameraKit::GetInstance();
649     string errorCameraId = "main";
650     const CameraAbility *ability = cameraKit->GetCameraAbility(errorCameraId);
651     EXPECT_EQ(ability, nullptr);
652 }
653 
HWTEST_F(CameraLiteTest,PrfTest_GetCameraAbility_001,Level1)654 HWTEST_F(CameraLiteTest, PrfTest_GetCameraAbility_001, Level1)
655 {
656     CameraKit *cameraKit = CameraKit::GetInstance();
657     const CameraAbility *ability = nullptr;
658     string cameraId = "0";
659     struct timespec tv1 = {0};
660     struct timespec tv2 = {0};
661     int64_t performanceTestTimes = 10;
662     int64_t usecTimes = 1000000;
663     int64_t totalTime = 0;
664     for (int32_t i = 0; i < performanceTestTimes; i++) {
665         clock_gettime(CLOCK_REALTIME, &tv1);
666         ability = cameraKit->GetCameraAbility(cameraId);
667         clock_gettime(CLOCK_REALTIME, &tv2);
668         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
669     }
670     int64_t expectTime = 1000000;
671     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
672 }
673 
HWTEST_F(CameraLiteTest,Test_GetCameraInfo_001,Level1)674 HWTEST_F(CameraLiteTest, Test_GetCameraInfo_001, Level1)
675 {
676     CameraKit *cameraKit = CameraKit::GetInstance();
677     list<string> cameraList = cameraKit->GetCameraIds();
678     for (auto &cameraId : cameraList) {
679         const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(cameraId);
680         EXPECT_NE(cameraInfo, nullptr);
681     }
682 }
683 
HWTEST_F(CameraLiteTest,Test_GetCameraInfo_002,Level1)684 HWTEST_F(CameraLiteTest, Test_GetCameraInfo_002, Level1)
685 {
686     CameraKit *cameraKit = CameraKit::GetInstance();
687     string errorCameraId = "-1";
688     const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(errorCameraId);
689     EXPECT_EQ(cameraInfo, nullptr);
690 }
691 
HWTEST_F(CameraLiteTest,Test_GetCameraInfo_003,Level1)692 HWTEST_F(CameraLiteTest, Test_GetCameraInfo_003, Level1)
693 {
694     CameraKit *cameraKit = CameraKit::GetInstance();
695     string errorCameraId = "main";
696     const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(errorCameraId);
697     EXPECT_EQ(cameraInfo, nullptr);
698 }
699 
HWTEST_F(CameraLiteTest,PrfTest_GetCameraInfo_001,Level1)700 HWTEST_F(CameraLiteTest, PrfTest_GetCameraInfo_001, Level1)
701 {
702     struct timespec tv1 = {0};
703     struct timespec tv2 = {0};
704     CameraKit *cameraKit = CameraKit::GetInstance();
705     string cameraId = "0";
706     int64_t performanceTestTimes = 10;
707     int64_t usecTimes = 1000000;
708     int64_t totalTime = 0;
709     for (int32_t i = 0; i < performanceTestTimes; i++) {
710         clock_gettime(CLOCK_REALTIME, &tv1);
711         cameraKit->GetCameraInfo(cameraId);
712         clock_gettime(CLOCK_REALTIME, &tv2);
713         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
714     }
715     int64_t expectTime = 1000000;
716     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
717 }
718 
HWTEST_F(CameraLiteTest,Test_RegisterCameraDeviceCallback_001,Level1)719 HWTEST_F(CameraLiteTest, Test_RegisterCameraDeviceCallback_001, Level1)
720 {
721     CameraKit *cameraKit = nullptr;
722     list<string> cameraList;
723     string cameraId;
724     EventHandler eventHdlr;
725     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
726     SampleCameraStateMng camStateMng(eventHdlr);
727     SampleCameraDeviceCallback deviceCallback = SampleCameraDeviceCallback();
728     g_onCameraAvailableFlag = false;
729     cameraKit->RegisterCameraDeviceCallback(deviceCallback, eventHdlr);
730     sleep(2);
731     EXPECT_TRUE(g_onCameraAvailableFlag);
732 }
733 
HWTEST_F(CameraLiteTest,PrfTest_RegisterCameraDeviceCallback_001,Level1)734 HWTEST_F(CameraLiteTest, PrfTest_RegisterCameraDeviceCallback_001, Level1)
735 {
736     CameraKit *cameraKit = nullptr;
737     list<string> cameraList;
738     string cameraId;
739     EventHandler eventHdlr;
740     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
741     SampleCameraStateMng camStateMng(eventHdlr);
742     SampleCameraDeviceCallback deviceCallback = SampleCameraDeviceCallback();
743     struct timespec tv1 = {0};
744     struct timespec tv2 = {0};
745     int64_t performanceTestTimes = 10;
746     int64_t usecTimes = 1000000;
747     int64_t totalTime = 0;
748     for (int32_t i = 0; i < performanceTestTimes; i++) {
749         clock_gettime(CLOCK_REALTIME, &tv1);
750         cameraKit->RegisterCameraDeviceCallback(deviceCallback, eventHdlr);
751         clock_gettime(CLOCK_REALTIME, &tv2);
752         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
753     }
754     int64_t expectTime = 1000000;
755     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
756 }
757 
HWTEST_F(CameraLiteTest,Test_UnregisterCameraDeviceCallback_001,Level1)758 HWTEST_F(CameraLiteTest, Test_UnregisterCameraDeviceCallback_001, Level1)
759 {
760     CameraKit *cameraKit = nullptr;
761     list<string> cameraList;
762     string cameraId;
763     EventHandler eventHdlr;
764     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
765     SampleCameraStateMng camStateMng(eventHdlr);
766     SampleCameraDeviceCallback deviceCallback = SampleCameraDeviceCallback();
767     g_onCameraAvailableFlag = false;
768     cameraKit->RegisterCameraDeviceCallback(deviceCallback, eventHdlr);
769     sleep(2);
770     g_onCameraAvailableFlag = false;
771     cameraKit->UnregisterCameraDeviceCallback(deviceCallback);
772     sleep(2);
773     EXPECT_EQ(g_onCameraAvailableFlag, false);
774 }
775 
HWTEST_F(CameraLiteTest,PrfTest_UnregisterCameraDeviceCallback_001,Level1)776 HWTEST_F(CameraLiteTest, PrfTest_UnregisterCameraDeviceCallback_001, Level1)
777 {
778     CameraKit *cameraKit = nullptr;
779     list<string> cameraList;
780     string cameraId;
781     EventHandler eventHdlr;
782     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
783     SampleCameraStateMng camStateMng(eventHdlr);
784     SampleCameraDeviceCallback deviceCallback = SampleCameraDeviceCallback();
785     struct timespec tv1 = {0};
786     struct timespec tv2 = {0};
787     int64_t performanceTestTimes = 10;
788     int64_t usecTimes = 1000000;
789     int64_t totalTime = 0;
790     for (int32_t i = 0; i < performanceTestTimes; i++) {
791         cameraKit->RegisterCameraDeviceCallback(deviceCallback, eventHdlr);
792         clock_gettime(CLOCK_REALTIME, &tv1);
793         cameraKit->UnregisterCameraDeviceCallback(deviceCallback);
794         clock_gettime(CLOCK_REALTIME, &tv2);
795         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
796     }
797     int64_t expectTime = 1000000;
798     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
799 }
800 
HWTEST_F(CameraLiteTest,Test_CreateCamera_001,Level1)801 HWTEST_F(CameraLiteTest, Test_CreateCamera_001, Level1)
802 {
803     CameraKit *cameraKit = CameraKit::GetInstance();
804     string cameraId = "0";
805     EventHandler eventHdlr;
806     SampleCameraStateMng camStateMng(eventHdlr);
807     g_onCreatedFlag = false;
808     g_onCreateFailedFlag = false;
809     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
810     sleep(2);
811     EXPECT_EQ(g_onCreatedFlag, true);
812     EXPECT_EQ(g_onCreateFailedFlag, false);
813 }
814 
HWTEST_F(CameraLiteTest,Test_CreateCamera_002,Level1)815 HWTEST_F(CameraLiteTest, Test_CreateCamera_002, Level1)
816 {
817     CameraKit *cameraKit = CameraKit::GetInstance();
818     string cameraId = "main";
819     EventHandler eventHdlr;
820     SampleCameraStateMng camStateMng(eventHdlr);
821     g_onCreatedFlag = false;
822     g_onCreateFailedFlag = false;
823     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
824     sleep(2);
825     EXPECT_EQ(g_onCreatedFlag, false);
826     EXPECT_EQ(g_onCreateFailedFlag, true);
827 }
828 
HWTEST_F(CameraLiteTest,Test_CreateCamera_003,Level1)829 HWTEST_F(CameraLiteTest, Test_CreateCamera_003, Level1)
830 {
831     CameraKit *cameraKit = CameraKit::GetInstance();
832     list<string> cameraList;
833     string cameraId = "0";
834     EventHandler eventHdlr;
835     g_onCreatedFlag = false;
836     g_onCreateFailedFlag = false;
837     SampleCameraStateMng camStateMng(eventHdlr);
838     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
839     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
840     sleep(2);
841     EXPECT_EQ(g_onCreatedFlag, true);
842 }
843 
HWTEST_F(CameraLiteTest,Test_CreateCamera_004,Level1)844 HWTEST_F(CameraLiteTest, Test_CreateCamera_004, Level1)
845 {
846     CameraKit *cameraKit = CameraKit::GetInstance();
847     string cameraId = "0";
848     EventHandler eventHdlr;
849     g_onCreatedFlag = false;
850     g_onCreateFailedFlag = false;
851     SampleCameraStateMng camStateMng(eventHdlr);
852     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
853     sleep(2);
854     cameraId = "-1";
855     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
856     sleep(2);
857     EXPECT_EQ(g_onCreatedFlag, true);
858     EXPECT_EQ(g_onCreateFailedFlag, true);
859 }
860 
HWTEST_F(CameraLiteTest,PrfTest_CreateCamera_001,Level1)861 HWTEST_F(CameraLiteTest, PrfTest_CreateCamera_001, Level1)
862 {
863     CameraKit *cameraKit = CameraKit::GetInstance();
864     string cameraId = "0";
865     EventHandler eventHdlr;
866     SampleCameraStateMng camStateMng(eventHdlr);
867     struct timespec tv1 = {0};
868     struct timespec tv2 = {0};
869     int64_t performanceTestTimes = 10;
870     int64_t totalTime = 0;
871     int64_t usecTimes = 1000000;
872     for (int32_t i = 0; i < performanceTestTimes; i++) {
873         clock_gettime(CLOCK_REALTIME, &tv1);
874         cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
875         clock_gettime(CLOCK_REALTIME, &tv2);
876         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
877     }
878     int64_t expectTime = 500000000;
879     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
880 } /* end camera kit interface test */
881 
882 /* start camera ability interface test */
HWTEST_F(CameraLiteTest,Test_GetSupportedSizes_001,Level1)883 HWTEST_F(CameraLiteTest, Test_GetSupportedSizes_001, Level1)
884 {
885     CameraKit *cameraKit = CameraKit::GetInstance();
886     list<string> cameraList = cameraKit->GetCameraIds();
887     for (auto &cameraId : cameraList) {
888         const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
889         list<CameraPicSize> cameraPicSizes = ability->GetSupportedSizes(0);
890         EXPECT_TRUE(cameraPicSizes.size() > 0);
891     }
892 }
893 
HWTEST_F(CameraLiteTest,PrfTest_GetSupportedSizes_001,Level1)894 HWTEST_F(CameraLiteTest, PrfTest_GetSupportedSizes_001, Level1)
895 {
896     CameraKit *cameraKit = CameraKit::GetInstance();
897     string cameraId = "0";
898     const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
899     struct timespec tv1 = {0};
900     struct timespec tv2 = {0};
901     int64_t performanceTestTimes = 10;
902     int64_t usecTimes = 1000000;
903     int64_t totalTime = 0;
904     for (int32_t i = 0; i < performanceTestTimes; i++) {
905         clock_gettime(CLOCK_REALTIME, &tv1);
906         ability->GetSupportedSizes(0);
907         clock_gettime(CLOCK_REALTIME, &tv2);
908         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
909     }
910     int64_t expectTime = 1000000;
911     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
912 }
913 
HWTEST_F(CameraLiteTest,Test_GetSupportedAfModes_001,Level1)914 HWTEST_F(CameraLiteTest, Test_GetSupportedAfModes_001, Level1)
915 {
916     CameraKit *cameraKit = CameraKit::GetInstance();
917     list<string> cameraList = cameraKit->GetCameraIds();
918     for (auto &cameraId : cameraList) {
919         const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
920         list<int32_t> afModes = ability->GetSupportedAfModes();
921         EXPECT_TRUE(afModes.size() >= 0);
922     }
923 }
924 
HWTEST_F(CameraLiteTest,PrfTest_GetSupportedAfModes_001,Level1)925 HWTEST_F(CameraLiteTest, PrfTest_GetSupportedAfModes_001, Level1)
926 {
927     CameraKit *cameraKit = CameraKit::GetInstance();
928     string cameraId = "0";
929     const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
930     struct timespec tv1 = {0};
931     struct timespec tv2 = {0};
932     int64_t performanceTestTimes = 10;
933     int64_t usecTimes = 1000000;
934     int64_t totalTime = 0;
935     for (int32_t i = 0; i < performanceTestTimes; i++) {
936         clock_gettime(CLOCK_REALTIME, &tv1);
937         ability->GetSupportedAfModes();
938         clock_gettime(CLOCK_REALTIME, &tv2);
939         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
940     }
941     int64_t expectTime = 1000000;
942     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
943 }
944 
HWTEST_F(CameraLiteTest,Test_GetSupportedAeModes_001,Level1)945 HWTEST_F(CameraLiteTest, Test_GetSupportedAeModes_001, Level1)
946 {
947     CameraKit *cameraKit = CameraKit::GetInstance();
948     list<string> cameraList = cameraKit->GetCameraIds();
949     for (auto &cameraId : cameraList) {
950         const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
951         list<int32_t> aeModes = ability->GetSupportedAeModes();
952         EXPECT_TRUE(aeModes.size() >= 0);
953     }
954 }
955 
HWTEST_F(CameraLiteTest,PrfTest_GetSupportedAeModes_001,Level1)956 HWTEST_F(CameraLiteTest, PrfTest_GetSupportedAeModes_001, Level1)
957 {
958     CameraKit *cameraKit = CameraKit::GetInstance();
959     string cameraId = "0";
960     const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
961     struct timespec tv1 = {0};
962     struct timespec tv2 = {0};
963     int64_t performanceTestTimes = 10;
964     int64_t totalTime = 0;
965     int64_t usecTimes = 1000000;
966     for (int32_t i = 0; i < performanceTestTimes; i++) {
967         clock_gettime(CLOCK_REALTIME, &tv1);
968         ability->GetSupportedAeModes();
969         clock_gettime(CLOCK_REALTIME, &tv2);
970         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
971     }
972     int64_t expectTime = 1000000;
973     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
974 } /* end camera ability interface test*/
975 
976 /* start camera state callback test */
HWTEST_F(CameraLiteTest,Test_OnCreate_001,Level1)977 HWTEST_F(CameraLiteTest, Test_OnCreate_001, Level1)
978 {
979     CameraKit *cameraKit = CameraKit::GetInstance();
980     string cameraId = "0";
981     EventHandler eventHdlr;
982     SampleCameraStateMng camStateMng(eventHdlr);
983     g_onCreatedFlag = false;
984     g_onCreateFailedFlag = false;
985     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
986     sleep(2);
987     EXPECT_EQ(g_onCreatedFlag, true);
988     EXPECT_EQ(g_onCreateFailedFlag, false);
989 }
990 
HWTEST_F(CameraLiteTest,Test_OnCreate_002,Level1)991 HWTEST_F(CameraLiteTest, Test_OnCreate_002, Level1)
992 {
993     CameraKit *cameraKit = CameraKit::GetInstance();
994     string cameraId = "0";
995     EventHandler eventHdlr;
996     SampleCameraStateMng camStateMng(eventHdlr);
997     g_onCreatedFlag = false;
998     g_onCreateFailedFlag = false;
999     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1000     sleep(2);
1001     camStateMng.Stop();
1002     EXPECT_EQ(g_onCreatedFlag, true);
1003     EXPECT_NE(g_onCreateFailedFlag, true);
1004 }
1005 
HWTEST_F(CameraLiteTest,Test_OnCreateFailed_001,Level1)1006 HWTEST_F(CameraLiteTest, Test_OnCreateFailed_001, Level1)
1007 {
1008     CameraKit *cameraKit = CameraKit::GetInstance();
1009     string cameraId = "-1";
1010     EventHandler eventHdlr;
1011     SampleCameraStateMng camStateMng(eventHdlr);
1012     g_onCreateFailedFlag = false;
1013     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1014     sleep(2);
1015     EXPECT_EQ(g_onCreateFailedFlag, true);
1016 }
1017 
HWTEST_F(CameraLiteTest,Test_OnCreateFailed_002,Level1)1018 HWTEST_F(CameraLiteTest, Test_OnCreateFailed_002, Level1)
1019 {
1020     CameraKit *cameraKit = CameraKit::GetInstance();
1021     string cameraId = "main";
1022     EventHandler eventHdlr;
1023     SampleCameraStateMng camStateMng(eventHdlr);
1024     g_onCreateFailedFlag = false;
1025     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1026     sleep(2);
1027     EXPECT_EQ(g_onCreateFailedFlag, true);
1028 } /* end camera state callback test */
1029 
1030 /* start frame config & frame state call back interface test */
HWTEST_F(CameraLiteTest,Test_FrameConfig_001,Level1)1031 HWTEST_F(CameraLiteTest, Test_FrameConfig_001, Level1)
1032 {
1033     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1034     EXPECT_NE(frameConfig.get(), nullptr);
1035 }
1036 
HWTEST_F(CameraLiteTest,Test_FrameConfig_002,Level1)1037 HWTEST_F(CameraLiteTest, Test_FrameConfig_002, Level1)
1038 {
1039     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
1040     EXPECT_NE(frameConfig.get(), nullptr);
1041 }
1042 
HWTEST_F(CameraLiteTest,Test_FrameConfig_003,Level1)1043 HWTEST_F(CameraLiteTest, Test_FrameConfig_003, Level1)
1044 {
1045     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
1046     EXPECT_NE(frameConfig.get(), nullptr);
1047 }
1048 
HWTEST_F(CameraLiteTest,Test_FrameConfig_004,Level1)1049 HWTEST_F(CameraLiteTest, Test_FrameConfig_004, Level1)
1050 {
1051     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
1052     EXPECT_NE(frameConfig.get(), nullptr);
1053 }
1054 
HWTEST_F(CameraLiteTest,PrfTest_Frameconfig_001,Level1)1055 HWTEST_F(CameraLiteTest, PrfTest_Frameconfig_001, Level1)
1056 {
1057     shared_ptr<FrameConfig> frameConfig = nullptr;
1058     struct timespec tv1 = {0};
1059     struct timespec tv2 = {0};
1060     int64_t performanceTestTimes = 10;
1061     int64_t usecTimes = 1000000;
1062     int64_t totalTime = 0;
1063     for (int32_t i = 0; i < performanceTestTimes; i++) {
1064         clock_gettime(CLOCK_REALTIME, &tv1);
1065         frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1066         clock_gettime(CLOCK_REALTIME, &tv2);
1067         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1068     }
1069     int64_t expectTime = 1000000;
1070     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1071 }
1072 
HWTEST_F(CameraLiteTest,PrfTest_Frameconfig_002,Level1)1073 HWTEST_F(CameraLiteTest, PrfTest_Frameconfig_002, Level1)
1074 {
1075     shared_ptr<FrameConfig> frameConfig = nullptr;
1076     struct timespec tv1 = {0};
1077     struct timespec tv2 = {0};
1078     int64_t performanceTestTimes = 10;
1079     int64_t usecTimes = 1000000;
1080     int64_t totalTime = 0;
1081     for (int32_t i = 0; i < performanceTestTimes; i++) {
1082         clock_gettime(CLOCK_REALTIME, &tv1);
1083         frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
1084         clock_gettime(CLOCK_REALTIME, &tv2);
1085         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1086     }
1087     int64_t expectTime = 1000000;
1088     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1089 }
1090 
HWTEST_F(CameraLiteTest,PrfTest_Frameconfig_003,Level1)1091 HWTEST_F(CameraLiteTest, PrfTest_Frameconfig_003, Level1)
1092 {
1093     shared_ptr<FrameConfig> frameConfig = nullptr;
1094     struct timespec tv1 = {0};
1095     struct timespec tv2 = {0};
1096     int64_t performanceTestTimes = 10;
1097     int64_t usecTimes = 1000000;
1098     int64_t totalTime = 0;
1099     for (int32_t i = 0; i < performanceTestTimes; i++) {
1100         clock_gettime(CLOCK_REALTIME, &tv1);
1101         frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
1102         clock_gettime(CLOCK_REALTIME, &tv2);
1103         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1104     }
1105     int64_t expectTime = 1000000;
1106     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1107 }
1108 
HWTEST_F(CameraLiteTest,PrfTest_Frameconfig_004,Level1)1109 HWTEST_F(CameraLiteTest, PrfTest_Frameconfig_004, Level1)
1110 {
1111     shared_ptr<FrameConfig> frameConfig = nullptr;
1112     struct timespec tv1 = {0};
1113     struct timespec tv2 = {0};
1114     int64_t performanceTestTimes = 10;
1115     int64_t usecTimes = 1000000;
1116     int64_t totalTime = 0;
1117     for (int32_t i = 0; i < performanceTestTimes; i++) {
1118         clock_gettime(CLOCK_REALTIME, &tv1);
1119         frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
1120         clock_gettime(CLOCK_REALTIME, &tv2);
1121         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1122     }
1123     int64_t expectTime = 1000000;
1124     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1125 }
1126 
HWTEST_F(CameraLiteTest,Test_GetFrameConfigureType_001,Level1)1127 HWTEST_F(CameraLiteTest, Test_GetFrameConfigureType_001, Level1)
1128 {
1129     CameraKit *cameraKit = CameraKit::GetInstance();
1130     string cameraId = "0";
1131     EventHandler eventHdlr;
1132     SampleCameraStateMng camStateMng(eventHdlr);
1133     g_onGetFrameConfigureType = false;
1134     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1135     sleep(2);
1136     camStateMng.Capture();
1137     sleep(2);
1138     EXPECT_EQ(g_onGetFrameConfigureType, true);
1139 }
1140 
HWTEST_F(CameraLiteTest,Test_GetFrameConfigureType_002,Level1)1141 HWTEST_F(CameraLiteTest, Test_GetFrameConfigureType_002, Level1)
1142 {
1143     CameraKit *cameraKit = CameraKit::GetInstance();
1144     string cameraId = "0";
1145     EventHandler eventHdlr;
1146     SampleCameraStateMng camStateMng(eventHdlr);
1147     g_onGetFrameConfigureType = false;
1148     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1149     sleep(2);
1150     camStateMng.Capture();
1151     sleep(2);
1152     camStateMng.Stop();
1153     EXPECT_EQ(g_onGetFrameConfigureType, true);
1154 }
1155 
HWTEST_F(CameraLiteTest,Test_GetFrameConfigureType_003,Level1)1156 HWTEST_F(CameraLiteTest, Test_GetFrameConfigureType_003, Level1)
1157 {
1158     CameraKit *cameraKit = CameraKit::GetInstance();
1159     string cameraId = "0";
1160     EventHandler eventHdlr;
1161     SampleCameraStateMng camStateMng(eventHdlr);
1162     g_onGetFrameConfigureType = false;
1163     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1164     sleep(2);
1165     camStateMng.StartPreview();
1166     sleep(2);
1167     camStateMng.Stop();
1168     EXPECT_EQ(g_onGetFrameConfigureType, false);
1169 }
1170 
HWTEST_F(CameraLiteTest,Test_GetFrameConfigureType_004,Level1)1171 HWTEST_F(CameraLiteTest, Test_GetFrameConfigureType_004, Level1)
1172 {
1173     CameraKit *cameraKit = CameraKit::GetInstance();
1174     string cameraId = "0";
1175     EventHandler eventHdlr;
1176     SampleCameraStateMng camStateMng(eventHdlr);
1177     g_onGetFrameConfigureType = false;
1178     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1179     sleep(2);
1180     camStateMng.Capture();
1181     sleep(2);
1182     camStateMng.StartPreview();
1183     sleep(2);
1184     camStateMng.Stop();
1185     EXPECT_EQ(g_onGetFrameConfigureType, true);
1186 }
1187 
HWTEST_F(CameraLiteTest,Test_GetFrameConfigureType_005,Level1)1188 HWTEST_F(CameraLiteTest, Test_GetFrameConfigureType_005, Level1)
1189 {
1190     CameraKit *cameraKit = CameraKit::GetInstance();
1191     string cameraId = "0";
1192     EventHandler eventHdlr;
1193     SampleCameraStateMng camStateMng(eventHdlr);
1194     g_onGetFrameConfigureType = false;
1195     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1196     sleep(2);
1197     camStateMng.StartPreview();
1198     sleep(2);
1199     camStateMng.Capture();
1200     sleep(2);
1201     camStateMng.Stop();
1202     EXPECT_EQ(g_onGetFrameConfigureType, true);
1203 }
1204 
HWTEST_F(CameraLiteTest,Test_SetVendorParameter_001,Level1)1205 HWTEST_F(CameraLiteTest, Test_SetVendorParameter_001, Level1)
1206 {
1207     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1208     uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
1209     privateTag[4] = 5;
1210     frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
1211     uint8_t *privateTagTemp = new uint8_t[10];
1212     frameConfig->GetVendorParameter(privateTagTemp, 10);
1213     EXPECT_TRUE(privateTagTemp[4] == 5);
1214     delete[] privateTag;
1215     delete[] privateTagTemp;
1216 }
1217 
HWTEST_F(CameraLiteTest,Test_SetVendorParameter_002,Level1)1218 HWTEST_F(CameraLiteTest, Test_SetVendorParameter_002, Level1)
1219 {
1220     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
1221     uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
1222     privateTag[10] = 10;
1223     frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
1224     uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
1225     frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
1226     EXPECT_TRUE(privateTagTemp[10] == 10);
1227     delete[] privateTag;
1228     delete[] privateTagTemp;
1229 }
1230 
HWTEST_F(CameraLiteTest,Test_SetVendorParameter_003,Level1)1231 HWTEST_F(CameraLiteTest, Test_SetVendorParameter_003, Level1)
1232 {
1233     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
1234     uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
1235     privateTag[0] = 1;
1236     frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
1237     uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
1238     frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
1239     EXPECT_TRUE(privateTagTemp[0] == 1);
1240     delete[] privateTag;
1241     delete[] privateTagTemp;
1242 }
1243 
HWTEST_F(CameraLiteTest,Test_SetVendorParameter_004,Level1)1244 HWTEST_F(CameraLiteTest, Test_SetVendorParameter_004, Level1)
1245 {
1246     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
1247     uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
1248     privateTag[31] = 31;
1249     frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
1250     uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
1251     frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
1252     EXPECT_TRUE(privateTagTemp[31] == 31);
1253     delete[] privateTag;
1254     delete[] privateTagTemp;
1255 }
1256 
HWTEST_F(CameraLiteTest,PrfTest_SetVendorParameter_001,Level1)1257 HWTEST_F(CameraLiteTest, PrfTest_SetVendorParameter_001, Level1)
1258 {
1259     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1260     uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
1261     privateTag[1] = 1;
1262     struct timespec tv1 = {0};
1263     struct timespec tv2 = {0};
1264     int64_t performanceTestTimes = 10;
1265     int64_t usecTimes = 1000000;
1266     int64_t totalTime = 0;
1267     for (int32_t i = 0; i < performanceTestTimes; i++) {
1268         clock_gettime(CLOCK_REALTIME, &tv1);
1269         frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
1270         clock_gettime(CLOCK_REALTIME, &tv2);
1271         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1272     }
1273     int64_t expectTime = 1000000;
1274     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1275     delete[] privateTag;
1276 }
1277 
HWTEST_F(CameraLiteTest,PrfTest_SetVendorParameter_002,Level1)1278 HWTEST_F(CameraLiteTest, PrfTest_SetVendorParameter_002, Level1)
1279 {
1280     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
1281     uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
1282     privateTag[2] = 2;
1283     struct timespec tv1 = {0};
1284     struct timespec tv2 = {0};
1285     int64_t performanceTestTimes = 10;
1286     int64_t usecTimes = 1000000;
1287     int64_t totalTime = 0;
1288     for (int32_t i = 0; i < performanceTestTimes; i++) {
1289         clock_gettime(CLOCK_REALTIME, &tv1);
1290         frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
1291         clock_gettime(CLOCK_REALTIME, &tv2);
1292         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1293     }
1294     int64_t expectTime = 1000000;
1295     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1296     delete[] privateTag;
1297 }
1298 
HWTEST_F(CameraLiteTest,PrfTest_SetVendorParameter_003,Level1)1299 HWTEST_F(CameraLiteTest, PrfTest_SetVendorParameter_003, Level1)
1300 {
1301     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
1302     uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
1303     privateTag[3] = 3;
1304     struct timespec tv1 = {0};
1305     struct timespec tv2 = {0};
1306     int64_t performanceTestTimes = 10;
1307     int64_t usecTimes = 1000000;
1308     int64_t totalTime = 0;
1309     for (int32_t i = 0; i < performanceTestTimes; i++) {
1310         clock_gettime(CLOCK_REALTIME, &tv1);
1311         frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
1312         clock_gettime(CLOCK_REALTIME, &tv2);
1313         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1314     }
1315     int64_t expectTime = 1000000;
1316     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1317     delete[] privateTag;
1318 }
1319 
HWTEST_F(CameraLiteTest,PrfTest_SetVendorParameter_004,Level1)1320 HWTEST_F(CameraLiteTest, PrfTest_SetVendorParameter_004, Level1)
1321 {
1322     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
1323     uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
1324     privateTag[4] = 4;
1325     struct timespec tv1 = {0};
1326     struct timespec tv2 = {0};
1327     int64_t performanceTestTimes = 10;
1328     int64_t usecTimes = 1000000;
1329     int64_t totalTime = 0;
1330     for (int32_t i = 0; i < performanceTestTimes; i++) {
1331         clock_gettime(CLOCK_REALTIME, &tv1);
1332         frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
1333         clock_gettime(CLOCK_REALTIME, &tv2);
1334         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1335     }
1336     int64_t expectTime = 1000000;
1337     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1338     delete[] privateTag;
1339 }
1340 
HWTEST_F(CameraLiteTest,PrfTest_GetVendorParameter_001,Level1)1341 HWTEST_F(CameraLiteTest, PrfTest_GetVendorParameter_001, Level1)
1342 {
1343     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1344     uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
1345     privateTag[1] = 1;
1346     frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
1347     struct timespec tv1 = {0};
1348     struct timespec tv2 = {0};
1349     int64_t performanceTestTimes = 10;
1350     int64_t usecTimes = 1000000;
1351     int64_t totalTime = 0;
1352     uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
1353     for (int32_t i = 0; i < performanceTestTimes; i++) {
1354         clock_gettime(CLOCK_REALTIME, &tv1);
1355         frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
1356         clock_gettime(CLOCK_REALTIME, &tv2);
1357         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1358     }
1359     int64_t expectTime = 1000000;
1360     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1361     delete[] privateTag;
1362     delete[] privateTagTemp;
1363 }
1364 
HWTEST_F(CameraLiteTest,PrfTest_GetVendorParameter_002,Level1)1365 HWTEST_F(CameraLiteTest, PrfTest_GetVendorParameter_002, Level1)
1366 {
1367     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
1368     uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
1369     privateTag[2] = 2;
1370     frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
1371     struct timespec tv1 = {0};
1372     struct timespec tv2 = {0};
1373     int64_t performanceTestTimes = 10;
1374     int64_t usecTimes = 1000000;
1375     int64_t totalTime = 0;
1376     uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
1377     for (int32_t i = 0; i < performanceTestTimes; i++) {
1378         clock_gettime(CLOCK_REALTIME, &tv1);
1379         frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
1380         clock_gettime(CLOCK_REALTIME, &tv2);
1381         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1382     }
1383     int64_t expectTime = 1000000;
1384     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1385     delete[] privateTag;
1386     delete[] privateTagTemp;
1387 }
1388 
HWTEST_F(CameraLiteTest,PrfTest_GetVendorParameter_003,Level1)1389 HWTEST_F(CameraLiteTest, PrfTest_GetVendorParameter_003, Level1)
1390 {
1391     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
1392     uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
1393     privateTag[3] = 3;
1394     frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
1395     struct timespec tv1 = {0};
1396     struct timespec tv2 = {0};
1397     int64_t performanceTestTimes = 10;
1398     int64_t usecTimes = 1000000;
1399     int64_t totalTime = 0;
1400     uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
1401     for (int32_t i = 0; i < performanceTestTimes; i++) {
1402         clock_gettime(CLOCK_REALTIME, &tv1);
1403         frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
1404         clock_gettime(CLOCK_REALTIME, &tv2);
1405         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1406     }
1407     int64_t expectTime = 1000000;
1408     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1409     delete[] privateTag;
1410     delete[] privateTagTemp;
1411 }
1412 
HWTEST_F(CameraLiteTest,PrfTest_GetVendorParameter_004,Level1)1413 HWTEST_F(CameraLiteTest, PrfTest_GetVendorParameter_004, Level1)
1414 {
1415     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
1416     uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
1417     privateTag[4] = 4;
1418     frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
1419     struct timespec tv1 = {0};
1420     struct timespec tv2 = {0};
1421     int64_t performanceTestTimes = 10;
1422     int64_t usecTimes = 1000000;
1423     int64_t totalTime = 0;
1424     uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
1425     for (int32_t i = 0; i < performanceTestTimes; i++) {
1426         clock_gettime(CLOCK_REALTIME, &tv1);
1427         frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
1428         clock_gettime(CLOCK_REALTIME, &tv2);
1429         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1430     }
1431     int64_t expectTime = 1000000;
1432     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1433     delete[] privateTag;
1434     delete[] privateTagTemp;
1435 }
1436 
HWTEST_F(CameraLiteTest,Test_GetSurface_001,Level1)1437 HWTEST_F(CameraLiteTest, Test_GetSurface_001, Level1)
1438 {
1439     CameraKit *cameraKit = nullptr;
1440     list<string> cameraList;
1441     string cameraId;
1442     EventHandler eventHdlr;
1443     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1444     SampleCameraStateMng camStateMng(eventHdlr);
1445     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1446     sleep(2);
1447     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
1448     Surface *surface = Surface::CreateSurface();
1449     surface->SetWidthAndHeight(1920, 1080);
1450     EXPECT_EQ(1920, surface->GetWidth());
1451     EXPECT_EQ(1080, surface->GetHeight());
1452     delete surface;
1453 }
1454 
HWTEST_F(CameraLiteTest,Test_GetSurface_002,Level1)1455 HWTEST_F(CameraLiteTest, Test_GetSurface_002, Level1)
1456 {
1457     CameraKit *cameraKit = nullptr;
1458     list<string> cameraList;
1459     string cameraId;
1460     EventHandler eventHdlr;
1461     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1462     SampleCameraStateMng camStateMng(eventHdlr);
1463     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1464     sleep(2);
1465     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
1466     Surface *surface = Surface::CreateSurface();
1467     surface->SetWidthAndHeight(480, 360);
1468     EXPECT_EQ(480, surface->GetWidth());
1469     EXPECT_EQ(360, surface->GetHeight());
1470 }
1471 
HWTEST_F(CameraLiteTest,Test_GetSurface_003,Level1)1472 HWTEST_F(CameraLiteTest, Test_GetSurface_003, Level1)
1473 {
1474     CameraKit *cameraKit = nullptr;
1475     list<string> cameraList;
1476     string cameraId;
1477     EventHandler eventHdlr;
1478     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1479     SampleCameraStateMng camStateMng(eventHdlr);
1480     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1481     sleep(2);
1482     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
1483     Surface *surface = Surface::CreateSurface();
1484     surface->SetWidthAndHeight(1920, 1080);
1485     frameConfig->AddSurface(*surface);
1486     EXPECT_FALSE(frameConfig->GetSurfaces().size() == 0);
1487 }
1488 
HWTEST_F(CameraLiteTest,Test_GetSurface_004,Level1)1489 HWTEST_F(CameraLiteTest, Test_GetSurface_004, Level1)
1490 {
1491     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1492     Surface *surface = Surface::CreateSurface();
1493     frameConfig->AddSurface(*surface);
1494     frameConfig->RemoveSurface(*surface);
1495     list<Surface *> list = frameConfig->GetSurfaces();
1496     EXPECT_TRUE(list.size() == 0);
1497 }
1498 
HWTEST_F(CameraLiteTest,Test_GetSurface_005,Level1)1499 HWTEST_F(CameraLiteTest, Test_GetSurface_005, Level1)
1500 {
1501     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
1502     Surface *surface = Surface::CreateSurface();
1503     frameConfig->AddSurface(*surface);
1504     list<Surface *> list = frameConfig->GetSurfaces();
1505     EXPECT_TRUE(list.size() == 1);
1506 }
1507 
HWTEST_F(CameraLiteTest,Test_GetSurface_006,Level1)1508 HWTEST_F(CameraLiteTest, Test_GetSurface_006, Level1)
1509 {
1510     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
1511     Surface *surface = Surface::CreateSurface();
1512     frameConfig->AddSurface(*surface);
1513     list<Surface *> list = frameConfig->GetSurfaces();
1514     EXPECT_TRUE(list.size() == 1);
1515 }
1516 
HWTEST_F(CameraLiteTest,PrfTest_GetSurfaces_001,Level1)1517 HWTEST_F(CameraLiteTest, PrfTest_GetSurfaces_001, Level1)
1518 {
1519     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1520     Surface *surface = Surface::CreateSurface();
1521     frameConfig->AddSurface(*surface);
1522     struct timespec tv1 = {0};
1523     struct timespec tv2 = {0};
1524     int64_t performanceTestTimes = 10;
1525     int64_t usecTimes = 1000000;
1526     int64_t totalTime = 0;
1527     for (int32_t i = 0; i < performanceTestTimes; i++) {
1528         clock_gettime(CLOCK_REALTIME, &tv1);
1529         frameConfig->GetSurfaces();
1530         clock_gettime(CLOCK_REALTIME, &tv2);
1531         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1532     }
1533     int64_t expectTime = 1000000;
1534     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1535 }
1536 
HWTEST_F(CameraLiteTest,PrfTest_GetSurfaces_002,Level1)1537 HWTEST_F(CameraLiteTest, PrfTest_GetSurfaces_002, Level1)
1538 {
1539     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
1540     Surface *surface = Surface::CreateSurface();
1541     frameConfig->AddSurface(*surface);
1542     struct timespec tv1 = {0};
1543     struct timespec tv2 = {0};
1544     int64_t performanceTestTimes = 10;
1545     int64_t usecTimes = 1000000;
1546     int64_t totalTime = 0;
1547     for (int32_t i = 0; i < performanceTestTimes; i++) {
1548         clock_gettime(CLOCK_REALTIME, &tv1);
1549         frameConfig->GetSurfaces();
1550         clock_gettime(CLOCK_REALTIME, &tv2);
1551         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1552     }
1553     int64_t expectTime = 1000000;
1554     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1555     delete surface;
1556 }
1557 
HWTEST_F(CameraLiteTest,PrfTest_GetSurfaces_003,Level1)1558 HWTEST_F(CameraLiteTest, PrfTest_GetSurfaces_003, Level1)
1559 {
1560     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
1561     Surface *surface = Surface::CreateSurface();
1562     frameConfig->AddSurface(*surface);
1563     struct timespec tv1 = {0};
1564     struct timespec tv2 = {0};
1565     int64_t performanceTestTimes = 10;
1566     int64_t usecTimes = 1000000;
1567     int64_t totalTime = 0;
1568     for (int32_t i = 0; i < performanceTestTimes; i++) {
1569         clock_gettime(CLOCK_REALTIME, &tv1);
1570         frameConfig->GetSurfaces();
1571         clock_gettime(CLOCK_REALTIME, &tv2);
1572         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1573     }
1574     int64_t expectTime = 1000000;
1575     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1576 }
1577 
HWTEST_F(CameraLiteTest,PrfTest_GetSurfaces_004,Level1)1578 HWTEST_F(CameraLiteTest, PrfTest_GetSurfaces_004, Level1)
1579 {
1580     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
1581     Surface *surface = Surface::CreateSurface();
1582     frameConfig->AddSurface(*surface);
1583     struct timespec tv1 = {0};
1584     struct timespec tv2 = {0};
1585     int64_t performanceTestTimes = 10;
1586     int64_t usecTimes = 1000000;
1587     int64_t totalTime = 0;
1588     for (int32_t i = 0; i < performanceTestTimes; i++) {
1589         clock_gettime(CLOCK_REALTIME, &tv1);
1590         frameConfig->GetSurfaces();
1591         clock_gettime(CLOCK_REALTIME, &tv2);
1592         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1593     }
1594     int64_t expectTime = 1000000;
1595     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1596 }
1597 
HWTEST_F(CameraLiteTest,Test_OnFrameProgressed_001,Level1)1598 HWTEST_F(CameraLiteTest, Test_OnFrameProgressed_001, Level1)
1599 {
1600     CameraKit *cameraKit = nullptr;
1601     list<string> cameraList;
1602     string cameraId;
1603     EventHandler eventHdlr;
1604     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1605     SampleCameraStateMng camStateMng(eventHdlr);
1606     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1607     sleep(2);
1608     camStateMng.Capture();
1609     sleep(2);
1610     EXPECT_EQ(g_onFrameStartedFlag, true);
1611     EXPECT_EQ(g_onFrameProgressedFlag, true);
1612 }
1613 
HWTEST_F(CameraLiteTest,Test_OnFrameCompletedFlag_001,Level1)1614 HWTEST_F(CameraLiteTest, Test_OnFrameCompletedFlag_001, Level1)
1615 {
1616     CameraKit *cameraKit = nullptr;
1617     list<string> cameraList;
1618     string cameraId;
1619     EventHandler eventHdlr;
1620     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1621     SampleCameraStateMng camStateMng(eventHdlr);
1622     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1623     sleep(2);
1624     camStateMng.Capture();
1625     sleep(2);
1626     EXPECT_EQ(g_onFrameFinishedFlag, true);
1627 }
1628 
HWTEST_F(CameraLiteTest,Test_OnFrameErrorFlag_001,Level1)1629 HWTEST_F(CameraLiteTest, Test_OnFrameErrorFlag_001, Level1)
1630 {
1631     CameraKit *cameraKit = nullptr;
1632     list<string> cameraList;
1633     string cameraId;
1634     EventHandler eventHdlr;
1635     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1636     SampleCameraStateMng camStateMng(eventHdlr);
1637     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1638     sleep(2);
1639     camStateMng.Capture();
1640     sleep(2);
1641     EXPECT_NE(g_onFrameErrorFlag, true);
1642 }
1643 
HWTEST_F(CameraLiteTest,Test_AddSurface_001,Level1)1644 HWTEST_F(CameraLiteTest, Test_AddSurface_001, Level1)
1645 {
1646     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1647     Surface *surface = Surface::CreateSurface();
1648     frameConfig->AddSurface(*surface);
1649     list<Surface *> list = frameConfig->GetSurfaces();
1650     EXPECT_TRUE(list.size() == 1);
1651 }
1652 
HWTEST_F(CameraLiteTest,Test_AddSurface_002,Level1)1653 HWTEST_F(CameraLiteTest, Test_AddSurface_002, Level1)
1654 {
1655     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1656     Surface *surface = Surface::CreateSurface();
1657     frameConfig->AddSurface(*surface);
1658     frameConfig->AddSurface(*surface);
1659     list<Surface *> list = frameConfig->GetSurfaces();
1660     EXPECT_TRUE(list.size() == 1);
1661 }
1662 
HWTEST_F(CameraLiteTest,Test_AddSurface_003,Level1)1663 HWTEST_F(CameraLiteTest, Test_AddSurface_003, Level1)
1664 {
1665     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1666     Surface *surface = Surface::CreateSurface();
1667     frameConfig->AddSurface(*surface);
1668     frameConfig->AddSurface(*surface);
1669     frameConfig->AddSurface(*surface);
1670     list<Surface *> list = frameConfig->GetSurfaces();
1671     EXPECT_TRUE(list.size() == 1);
1672 }
1673 
HWTEST_F(CameraLiteTest,PrfTest_AddSurface_001,Level1)1674 HWTEST_F(CameraLiteTest, PrfTest_AddSurface_001, Level1)
1675 {
1676     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1677     Surface *surface = Surface::CreateSurface();
1678     struct timespec tv1 = {0};
1679     struct timespec tv2 = {0};
1680     int64_t performanceTestTimes = 10;
1681     int64_t usecTimes = 1000000;
1682     int64_t totalTime = 0;
1683     for (int32_t i = 0; i < performanceTestTimes; i++) {
1684         clock_gettime(CLOCK_REALTIME, &tv1);
1685         frameConfig->AddSurface(*surface);
1686         clock_gettime(CLOCK_REALTIME, &tv2);
1687         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1688     }
1689     int64_t expectTime = 1000000;
1690     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1691 }
1692 
HWTEST_F(CameraLiteTest,Test_RemoveSurface_001,Level1)1693 HWTEST_F(CameraLiteTest, Test_RemoveSurface_001, Level1)
1694 {
1695     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1696     Surface *surface = Surface::CreateSurface();
1697     frameConfig->AddSurface(*surface);
1698     frameConfig->RemoveSurface(*surface);
1699     list<Surface *> list = frameConfig->GetSurfaces();
1700     EXPECT_TRUE(list.size() == 0);
1701 }
1702 
HWTEST_F(CameraLiteTest,Test_RemoveSurface_002,Level1)1703 HWTEST_F(CameraLiteTest, Test_RemoveSurface_002, Level1)
1704 {
1705     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1706     Surface *surface = Surface::CreateSurface();
1707     Surface *surface1 = Surface::CreateSurface();
1708     frameConfig->AddSurface(*surface);
1709     frameConfig->AddSurface(*surface1);
1710     frameConfig->RemoveSurface(*surface1);
1711     list<Surface *> list = frameConfig->GetSurfaces();
1712     EXPECT_TRUE(list.size() == 1);
1713 }
1714 
HWTEST_F(CameraLiteTest,Test_RemoveSurface_003,Level1)1715 HWTEST_F(CameraLiteTest, Test_RemoveSurface_003, Level1)
1716 {
1717     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1718     Surface *surface = Surface::CreateSurface();
1719     Surface *surface1 = Surface::CreateSurface();
1720     frameConfig->AddSurface(*surface);
1721     frameConfig->AddSurface(*surface1);
1722     frameConfig->RemoveSurface(*surface);
1723     frameConfig->RemoveSurface(*surface1);
1724     list<Surface *> list = frameConfig->GetSurfaces();
1725     EXPECT_TRUE(list.size() == 0);
1726 }
1727 
HWTEST_F(CameraLiteTest,PrfTest_RemoveSurface_001,Level1)1728 HWTEST_F(CameraLiteTest, PrfTest_RemoveSurface_001, Level1)
1729 {
1730     shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
1731     Surface *surface = Surface::CreateSurface();
1732     struct timespec tv1 = {0};
1733     struct timespec tv2 = {0};
1734     int64_t performanceTestTimes = 10;
1735     int64_t usecTimes = 1000000;
1736     int64_t totalTime = 0;
1737     for (int32_t i = 0; i < performanceTestTimes; i++) {
1738         frameConfig->AddSurface(*surface);
1739         clock_gettime(CLOCK_REALTIME, &tv1);
1740         frameConfig->RemoveSurface(*surface);
1741         clock_gettime(CLOCK_REALTIME, &tv2);
1742         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
1743     }
1744     int64_t expectTime = 1000000;
1745     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
1746 }
1747 
HWTEST_F(CameraLiteTest,Test_Capture_001,Level1)1748 HWTEST_F(CameraLiteTest, Test_Capture_001, Level1)
1749 {
1750     CameraKit *cameraKit = nullptr;
1751     list<string> cameraList;
1752     string cameraId;
1753     EventHandler eventHdlr;
1754     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1755     SampleCameraStateMng camStateMng(eventHdlr);
1756     g_onCaptureTriggerStartedFlag = false;
1757     g_onCaptureTriggerCompletedFlag = false;
1758     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1759     sleep(2);
1760     camStateMng.Capture();
1761     sleep(2);
1762     EXPECT_EQ(g_onCaptureTriggerStartedFlag, true);
1763     EXPECT_EQ(g_onCaptureTriggerCompletedFlag, true);
1764 }
1765 
HWTEST_F(CameraLiteTest,Test_Capture_002,Level1)1766 HWTEST_F(CameraLiteTest, Test_Capture_002, Level1)
1767 {
1768     CameraKit *cameraKit = CameraKit::GetInstance();
1769     string cameraId = "0";
1770     EventHandler eventHdlr;
1771     SampleCameraStateMng camStateMng(eventHdlr);
1772     g_onCaptureTriggerStartedFlag = false;
1773     g_onCaptureTriggerCompletedFlag = false;
1774     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1775     sleep(2);
1776     camStateMng.StartPreview();
1777     sleep(2);
1778     camStateMng.Capture();
1779     sleep(2);
1780     camStateMng.Stop();
1781     sleep(2);
1782     EXPECT_EQ(g_onCaptureTriggerStartedFlag, true);
1783     EXPECT_EQ(g_onCaptureTriggerCompletedFlag, true);
1784 }
1785 
HWTEST_F(CameraLiteTest,Test_Capture_003,Level1)1786 HWTEST_F(CameraLiteTest, Test_Capture_003, Level1)
1787 {
1788     CameraKit *cameraKit = CameraKit::GetInstance();
1789     string cameraId = "0";
1790     EventHandler eventHdlr;
1791     SampleCameraStateMng camStateMng(eventHdlr);
1792     g_onCaptureTriggerStartedFlag = false;
1793     g_onCaptureTriggerCompletedFlag = false;
1794     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1795     sleep(2);
1796     camStateMng.StartPreview();
1797     sleep(2);
1798     camStateMng.Stop();
1799     sleep(2);
1800     EXPECT_EQ(g_onCaptureTriggerStartedFlag, false);
1801     EXPECT_EQ(g_onCaptureTriggerCompletedFlag, false);
1802 }
1803 
HWTEST_F(CameraLiteTest,Test_Capture_004,Level1)1804 HWTEST_F(CameraLiteTest, Test_Capture_004, Level1)
1805 {
1806     CameraKit *cameraKit = nullptr;
1807     list<string> cameraList;
1808     string cameraId;
1809     EventHandler eventHdlr;
1810     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1811     SampleCameraStateMng camStateMng(eventHdlr);
1812     g_onCaptureTriggerStartedFlag = false;
1813     g_onCaptureTriggerCompletedFlag = false;
1814     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1815     sleep(2);
1816     camStateMng.Capture();
1817     sleep(2);
1818     camStateMng.Stop();
1819     sleep(2);
1820     EXPECT_EQ(g_onCaptureTriggerStartedFlag, true);
1821     EXPECT_EQ(g_onCaptureTriggerCompletedFlag, true);
1822 }
1823 
HWTEST_F(CameraLiteTest,Test_Capture_005,Level1)1824 HWTEST_F(CameraLiteTest, Test_Capture_005, Level1)
1825 {
1826     CameraKit *cameraKit = nullptr;
1827     list<string> cameraList;
1828     string cameraId;
1829     EventHandler eventHdlr;
1830     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1831     SampleCameraStateMng camStateMng(eventHdlr);
1832     g_onCaptureTriggerStartedFlag = false;
1833     g_onCaptureTriggerCompletedFlag = false;
1834     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1835     sleep(2);
1836     camStateMng.Capture();
1837     sleep(2);
1838     camStateMng.Capture();
1839     sleep(2);
1840     EXPECT_EQ(g_onCaptureTriggerStartedFlag, true);
1841     EXPECT_EQ(g_onCaptureTriggerCompletedFlag, true);
1842 }
1843 
HWTEST_F(CameraLiteTest,Test_Capture_006,Level1)1844 HWTEST_F(CameraLiteTest, Test_Capture_006, Level1)
1845 {
1846     CameraKit *cameraKit = nullptr;
1847     list<string> cameraList;
1848     string cameraId;
1849     EventHandler eventHdlr;
1850     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1851     SampleCameraStateMng camStateMng(eventHdlr);
1852     g_onCaptureTriggerStartedFlag = false;
1853     g_onCaptureTriggerCompletedFlag = false;
1854     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1855     sleep(2);
1856     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1857     sleep(2);
1858     camStateMng.Capture();
1859     sleep(2);
1860     EXPECT_TRUE(g_onCaptureTriggerStartedFlag);
1861     EXPECT_TRUE(g_onCaptureTriggerCompletedFlag);
1862 }
1863 
HWTEST_F(CameraLiteTest,Test_Capture_007,Level1)1864 HWTEST_F(CameraLiteTest, Test_Capture_007, Level1)
1865 {
1866     CameraKit *cameraKit = nullptr;
1867     list<string> cameraList;
1868     string cameraId;
1869     EventHandler eventHdlr;
1870     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1871     SampleCameraStateMng camStateMng(eventHdlr);
1872     g_onCaptureTriggerStartedFlag = false;
1873     g_onCaptureTriggerCompletedFlag = false;
1874     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1875     sleep(2);
1876     camStateMng.Stop();
1877     sleep(2);
1878     camStateMng.Capture();
1879     sleep(2);
1880     EXPECT_TRUE(g_onCaptureTriggerStartedFlag);
1881     EXPECT_TRUE(g_onCaptureTriggerCompletedFlag);
1882 }
1883 
HWTEST_F(CameraLiteTest,Test_Capture_008,Level1)1884 HWTEST_F(CameraLiteTest, Test_Capture_008, Level1)
1885 {
1886     CameraKit *cameraKit = nullptr;
1887     list<string> cameraList;
1888     string cameraId;
1889     EventHandler eventHdlr;
1890     GetCameraId(cameraKit, cameraList, cameraId);
1891     SampleCameraStateMng camStateMng(eventHdlr);
1892     g_onCaptureTriggerStartedFlag = false;
1893     g_onCaptureTriggerCompletedFlag = false;
1894     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1895     sleep(2);
1896     camStateMng.StartPreview();
1897     sleep(2);
1898     camStateMng.Stop();
1899     sleep(2);
1900     camStateMng.Capture();
1901     sleep(2);
1902     EXPECT_EQ(g_onCaptureTriggerStartedFlag, true);
1903     EXPECT_EQ(g_onCaptureTriggerCompletedFlag, true);
1904 }
1905 
HWTEST_F(CameraLiteTest,Test_Preview_001,Level1)1906 HWTEST_F(CameraLiteTest, Test_Preview_001, Level1)
1907 {
1908     CameraKit *cameraKit = nullptr;
1909     list<string> cameraList;
1910     string cameraId;
1911     EventHandler eventHdlr;
1912     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1913     SampleCameraStateMng camStateMng(eventHdlr);
1914     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1915     g_onPreviewFlag = false;
1916     camStateMng.StartPreview();
1917     sleep(2);
1918     EXPECT_TRUE(g_onPreviewFlag);
1919     camStateMng.Stop();
1920 }
1921 
HWTEST_F(CameraLiteTest,Test_Preview_002,Level1)1922 HWTEST_F(CameraLiteTest, Test_Preview_002, Level1)
1923 {
1924     CameraKit *cameraKit = nullptr;
1925     list<string> cameraList;
1926     string cameraId;
1927     EventHandler eventHdlr;
1928     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1929     SampleCameraStateMng camStateMng(eventHdlr);
1930     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1931     g_onPreviewFlag = false;
1932     camStateMng.StartPreview();
1933     sleep(2);
1934     camStateMng.Stop();
1935     EXPECT_FALSE(g_onPreviewFlag);
1936 }
1937 
HWTEST_F(CameraLiteTest,Test_Preview_003,Level1)1938 HWTEST_F(CameraLiteTest, Test_Preview_003, Level1)
1939 {
1940     CameraKit *cameraKit = nullptr;
1941     list<string> cameraList;
1942     string cameraId;
1943     EventHandler eventHdlr;
1944     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1945     SampleCameraStateMng camStateMng(eventHdlr);
1946     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1947     g_onPreviewFlag = false;
1948     camStateMng.StartPreview();
1949     sleep(2);
1950     camStateMng.Stop();
1951     camStateMng.StartPreview();
1952     sleep(2);
1953     EXPECT_TRUE(g_onPreviewFlag);
1954 }
1955 
HWTEST_F(CameraLiteTest,Test_Preview_004,Level1)1956 HWTEST_F(CameraLiteTest, Test_Preview_004, Level1)
1957 {
1958     CameraKit *cameraKit = nullptr;
1959     list<string> cameraList;
1960     string cameraId;
1961     EventHandler eventHdlr;
1962     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1963     SampleCameraStateMng camStateMng(eventHdlr);
1964     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1965     g_onPreviewFlag = false;
1966     camStateMng.StartPreview();
1967     sleep(2);
1968     camStateMng.Stop();
1969     camStateMng.StartPreview();
1970     sleep(2);
1971     camStateMng.Stop();
1972     EXPECT_FALSE(g_onPreviewFlag);
1973 }
1974 
HWTEST_F(CameraLiteTest,Test_Preview_005,Level1)1975 HWTEST_F(CameraLiteTest, Test_Preview_005, Level1)
1976 {
1977     CameraKit *cameraKit = nullptr;
1978     list<string> cameraList;
1979     string cameraId;
1980     EventHandler eventHdlr;
1981     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
1982     SampleCameraStateMng camStateMng(eventHdlr);
1983     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
1984     g_onPreviewFlag = false;
1985     camStateMng.Capture();
1986     sleep(2);
1987     camStateMng.Stop();
1988     sleep(2);
1989     camStateMng.StartPreview();
1990     sleep(2);
1991     EXPECT_TRUE(g_onPreviewFlag);
1992     camStateMng.Stop();
1993 }
1994 
HWTEST_F(CameraLiteTest,Test_Preview_006,Level1)1995 HWTEST_F(CameraLiteTest, Test_Preview_006, Level1)
1996 {
1997     CameraKit *cameraKit = nullptr;
1998     list<string> cameraList;
1999     string cameraId;
2000     EventHandler eventHdlr;
2001     ASSERT_TRUE(GetCameraId(cameraKit, cameraList, cameraId));
2002     SampleCameraStateMng camStateMng(eventHdlr);
2003     cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
2004     g_onPreviewFlag = false;
2005     camStateMng.Capture();
2006     sleep(2);
2007     camStateMng.StartPreview();
2008     sleep(2);
2009     camStateMng.Stop();
2010     EXPECT_FALSE(g_onPreviewFlag);
2011 } /* end frame config & frame state call back interface test */
2012 
2013 /* start camera info interface test */
HWTEST_F(CameraLiteTest,Test_GetCameraType_001,Level1)2014 HWTEST_F(CameraLiteTest, Test_GetCameraType_001, Level1)
2015 {
2016     CameraKit *cameraKit = CameraKit::GetInstance();
2017     string cameraId = "0";
2018     const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(cameraId);
2019     int32_t cameraType = cameraInfo->GetCameraType();
2020     EXPECT_TRUE(cameraType <= 3);
2021     EXPECT_TRUE(cameraType >= 0);
2022 }
2023 
HWTEST_F(CameraLiteTest,PrfTest_GetCameraType_001,Level1)2024 HWTEST_F(CameraLiteTest, PrfTest_GetCameraType_001, Level1)
2025 {
2026     CameraKit *cameraKit = CameraKit::GetInstance();
2027     string cameraId = "0";
2028     const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(cameraId);
2029     struct timespec tv1 = {0};
2030     struct timespec tv2 = {0};
2031     int64_t performanceTestTimes = 10;
2032     int64_t usecTimes = 1000000;
2033     int64_t totalTime = 0;
2034     for (int32_t i = 0; i < performanceTestTimes; i++) {
2035         clock_gettime(CLOCK_REALTIME, &tv1);
2036         cameraInfo->GetCameraType();
2037         clock_gettime(CLOCK_REALTIME, &tv2);
2038         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
2039     }
2040     int64_t expectTime = 1000000;
2041     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
2042 }
2043 
HWTEST_F(CameraLiteTest,Test_GetCameraFacingType_001,Level1)2044 HWTEST_F(CameraLiteTest, Test_GetCameraFacingType_001, Level1)
2045 {
2046     CameraKit *cameraKit = CameraKit::GetInstance();
2047     string cameraId = "0";
2048     const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(cameraId);
2049     int32_t cameraFacingType = cameraInfo->GetCameraFacingType();
2050     EXPECT_TRUE(cameraFacingType <= 2);
2051     EXPECT_TRUE(cameraFacingType >= 0);
2052 }
2053 
HWTEST_F(CameraLiteTest,PrfTest_GetCameraFacingType_001,Level1)2054 HWTEST_F(CameraLiteTest, PrfTest_GetCameraFacingType_001, Level1)
2055 {
2056     CameraKit *cameraKit = CameraKit::GetInstance();
2057     string cameraId = "0";
2058     const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(cameraId);
2059     struct timespec tv1 = {0};
2060     struct timespec tv2 = {0};
2061     int64_t performanceTestTimes = 10;
2062     int64_t usecTimes = 1000000;
2063     int64_t totalTime = 0;
2064     for (int32_t i = 0; i < performanceTestTimes; i++) {
2065         clock_gettime(CLOCK_REALTIME, &tv1);
2066         cameraInfo->GetCameraFacingType();
2067         clock_gettime(CLOCK_REALTIME, &tv2);
2068         totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
2069     }
2070     int64_t expectTime = 1000000;
2071     EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
2072 } /* end camera info interface test */
2073 }  // namespace OHOS
2074