提交 e56f3a64 编写于 作者: A apperception 提交者: Gitee

Signed-off-by: zhaochen <zhaochen69@huawei.com>

上级 e969a100
......@@ -23,6 +23,9 @@ hcpptest_suite("ActsMediaCameraTest") {
include_dirs = [
"src",
"//test/xts/acts/multimedia_lite/utils_posix/common/include",
"//foundation/multimedia/camera_lite/interfaces/kits",
"//foundation/multimedia/media_lite/interfaces/kits/recorder_lite",
"//foundation/multimedia/camera_lite/test/unittest",
]
ldflags = [ "-lstdc++" ]
ldflags += [ "-lm" ]
......@@ -32,6 +35,8 @@ hcpptest_suite("ActsMediaCameraTest") {
ldflags += [ "-Wl,-rpath-link=$ohos_root_path/$root_out_dir" ]
deps = [
"//foundation/graphic/surface:lite_surface",
"//foundation/graphic/ui:lite_ui",
"//foundation/multimedia/camera_lite/frameworks:camera_lite",
"//foundation/multimedia/media_lite/frameworks/recorder_lite:recorder_lite",
]
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2020-2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -14,58 +14,123 @@
*/
#include "ActsMediaCameraTest.h"
#include "ActsTestMediaUtils.h"
#include <components/ui_surface_view.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include "camera_kit.h"
using namespace std;
using namespace OHOS;
using namespace OHOS::Media;
using namespace testing::ext;
namespace OHOS {
/* *
* get current dir
* @return string current file path of the test suits
*/
string GetCurDir()
{
string filePath = "";
char *buffer;
if ((buffer = getcwd(NULL, 0)) == NULL) {
perror("get file path error");
} else {
printf("Current Dir: %s\r\n", buffer);
filePath = buffer;
free(buffer);
}
return filePath + "/";
}
// SetUpTestCase
void ActsMediaCameraTest::SetUpTestCase(void)
void CameraLiteTest::SetUpTestCase(void)
{
g_testPath = GetCurDir();
cout << "SetUpTestCase" << endl;
}
// TearDownTestCase
void ActsMediaCameraTest::TearDownTestCase(void)
void CameraLiteTest::TearDownTestCase(void)
{
g_testPath = "";
cout << "TearDownTestCase" << endl;
}
void ActsMediaCameraTest::SetUp(void)
void CameraLiteTest::SetUp(void)
{
// CameraSetUp
CameraFlag::g_onGetCameraAbilityFlag = FLAG0;
CameraFlag::g_onConfigureFlag = FLAG0;
CameraFlag::g_onGetSupportedSizesFlag = FLAG0;
g_onGetCameraAbilityFlag = false;
g_onConfigureFlag = false;
g_onGetSupportedSizesFlag = false;
// CameraDeviceCallBack
CameraFlag::g_onCameraAvailableFlag = FLAG0;
CameraFlag::g_onCameraUnavailableFlag = FLAG0;
g_onCameraAvailableFlag = false;
g_onCameraUnavailableFlag = false;
// CameraStateCallback
CameraFlag::g_onCreatedFlag = FLAG0;
CameraFlag::g_onCreateFailedFlag = FLAG0;
CameraFlag::g_onConfiguredFlag = FLAG0;
CameraFlag::g_onConfigureFailedFlag = FLAG0;
CameraFlag::g_onReleasedFlag = FLAG0;
g_onCreatedFlag = false;
g_onCreateFailedFlag = false;
g_onConfiguredFlag = false;
g_onConfigureFailedFlag = false;
g_onReleasedFlag = false;
// FrameStateCallback
CameraFlag::g_onCaptureTriggerAbortedFlag = FLAG0;
CameraFlag::g_onCaptureTriggerCompletedFlag = FLAG0;
CameraFlag::g_onCaptureTriggerStartedFlag = FLAG0;
CameraFlag::g_onFrameFinishedFlag = FLAG0;
CameraFlag::g_onGetFrameConfigureType = FLAG0;
CameraFlag::g_onFrameErrorFlag = FLAG0;
CameraFlag::g_onFrameProgressedFlag = FLAG0;
CameraFlag::g_onFrameStartedFlag = FLAG0;
g_onCaptureTriggerAbortedFlag = false;
g_onCaptureTriggerCompletedFlag = false;
g_onCaptureTriggerStartedFlag = false;
g_onFrameFinishedFlag = false;
g_onGetFrameConfigureType = false;
g_onFrameErrorFlag = false;
g_onFrameProgressedFlag = false;
g_onFrameStartedFlag = false;
g_onRecorderFlag = false;
cout << "SetUp" << endl;
}
// Tear down
void ActsMediaCameraTest::TearDown(void)
void CameraLiteTest::TearDown(void) { cout << "TearDown." << endl; }
int32_t SetupAudioSource(const Recorder &rec)
{
cout << "TearDown." << endl;
Recorder *recorder = (Recorder *)&rec;
int32_t ret = SUCCESS;
int32_t audioSourceId = 0;
AudioCodecFormat audioFormat = AAC_LC;
AudioSourceType inputSource = AUDIO_MIC;
int32_t sampleRate = 48000;
int32_t channelCount = 1;
int32_t audioEncodingBitRate = sampleRate;
if ((ret = recorder->SetAudioSource(inputSource, audioSourceId)) != SUCCESS) {
cout << "SetAudioSource failed." << ret << endl;
return FAIL;
}
if ((ret = recorder->SetAudioEncoder(audioSourceId, audioFormat)) != SUCCESS) {
cout << "SetAudioEncoder failed." << ret << endl;
return FAIL;
}
if ((ret = recorder->SetAudioSampleRate(audioSourceId, sampleRate)) != SUCCESS) {
cout << "SetAudioSampleRate failed." << ret << endl;
return FAIL;
}
if ((ret = recorder->SetAudioChannels(audioSourceId, channelCount)) != SUCCESS) {
cout << "SetAudioChannels failed." << ret << endl;
return FAIL;
}
if ((ret = recorder->SetAudioEncodingBitRate(audioSourceId, audioEncodingBitRate)) != SUCCESS) {
cout << "SetAudioEncodingBitRate failed." << ret << endl;
return FAIL;
}
return SUCCESS;
}
/* *
......@@ -74,25 +139,17 @@ void ActsMediaCameraTest::TearDown(void)
Recorder *SampleCreateRecorder()
{
int ret = 0;
int32_t sampleRate = 48000;
int32_t channelCount = 1;
AudioCodecFormat audioFormat = AAC_LC;
AudioSourceType inputSource = AUDIO_MIC;
int32_t audioEncodingBitRate = sampleRate;
VideoSourceType source = VIDEO_SOURCE_SURFACE_ES;
int32_t frameRate = 30;
double fps = 30;
int32_t rate = 4096;
int32_t sourceId = 0;
int32_t audioSourceId = 0;
int32_t width = 1920;
int32_t height = 1080;
VideoCodecFormat encoder;
encoder = HEVC;
VideoCodecFormat encoder = HEVC;
Recorder *recorder = new Recorder();
if ((ret = recorder->SetVideoSource(source, sourceId)) != SUCCESS) {
cout << "SetVideoSource failed." << ret << endl;
delete recorder;
return nullptr;
}
if ((ret = recorder->SetVideoEncoder(sourceId, encoder)) != SUCCESS) {
......@@ -120,28 +177,7 @@ Recorder *SampleCreateRecorder()
delete recorder;
return nullptr;
}
if ((ret = recorder->SetAudioSource(inputSource, audioSourceId)) != SUCCESS) {
cout << "SetAudioSource failed." << ret << endl;
delete recorder;
return nullptr;
}
if ((ret = recorder->SetAudioEncoder(audioSourceId, audioFormat)) != SUCCESS) {
cout << "SetAudioEncoder failed." << ret << endl;
delete recorder;
return nullptr;
}
if ((ret = recorder->SetAudioSampleRate(audioSourceId, sampleRate)) != SUCCESS) {
cout << "SetAudioSampleRate failed." << ret << endl;
delete recorder;
return nullptr;
}
if ((ret = recorder->SetAudioChannels(audioSourceId, channelCount)) != SUCCESS) {
cout << "SetAudioChannels failed." << ret << endl;
delete recorder;
return nullptr;
}
if ((ret = recorder->SetAudioEncodingBitRate(audioSourceId, audioEncodingBitRate)) != SUCCESS) {
cout << "SetAudioEncodingBitRate failed." << ret << endl;
if ((ret = SetupAudioSource(*recorder) != SUCCESS)) {
delete recorder;
return nullptr;
}
......@@ -152,13 +188,63 @@ Recorder *SampleCreateRecorder()
* Create Frame StateCallback
*/
class SampleFrameStateCallback : public FrameStateCallback {
void OnFrameFinished(Camera &camera, FrameConfig &fc, FrameResult &result) override
/* *
* check file exist
*
* @param filename the filename
* @return check result
*/
int32_t FileCheck(const string &filename)
{
CameraFlag::g_onFrameStartedFlag = FLAG1;
CameraFlag::g_onFrameProgressedFlag = FLAG1;
fstream fileTmp;
fileTmp.open(filename);
if (!fileTmp) {
cout << "file is not exist!" << endl;
return RET_ERR;
} else {
cout << "file is exist!" << endl;
fileTmp.close();
return RET_OK;
}
}
/* *
* Save Capture
*
* @param testPath the file path
* @param buffer the buffer
* @param size the size
* @return save result
*/
int32_t SampleSaveCapture(string testPath, char *buffer, uint32_t size)
{
cout << "Start saving picture" << endl;
string filePath = "";
struct timeval tv = {0};
gettimeofday(&tv, NULL);
struct tm *ltm = localtime(&tv.tv_sec);
if (ltm != nullptr) {
ostringstream ss("Capture_");
ss << "Capture" << ltm->tm_hour << "_" << ltm->tm_min << "_" << ltm->tm_sec << ".jpg";
filePath = testPath + ss.str();
ofstream pic(testPath + ss.str(), ofstream::out | ofstream::trunc);
cout << "write " << size << " bytes" << endl;
pic.write(buffer, size);
cout << "Saving picture end" << endl;
}
const char *filename = filePath.data();
int32_t ret = FileCheck(string(filename));
return ret;
}
void OnFrameFinished(Camera &cam, FrameConfig &fc, FrameResult &res) override
{
g_onFrameStartedFlag = true;
g_onFrameProgressedFlag = true;
cout << "Receive frame complete inform." << endl;
if (fc.GetFrameConfigType() == FRAME_CONFIG_CAPTURE) {
CameraFlag::g_onGetFrameConfigureType = FLAG1;
g_onGetFrameConfigureType = true;
cout << "Capture frame received." << endl;
list<Surface *> surfaceList = fc.GetSurfaces();
for (Surface *surface : surfaceList) {
......@@ -168,19 +254,19 @@ class SampleFrameStateCallback : public FrameStateCallback {
if (virtAddr != nullptr) {
SampleSaveCapture(g_testPath, virtAddr, buffer->GetSize());
} else {
CameraFlag::g_onFrameErrorFlag = FLAG1;
g_onFrameErrorFlag = true;
}
surface->ReleaseBuffer(buffer);
} else {
CameraFlag::g_onFrameErrorFlag = FLAG1;
g_onFrameErrorFlag = true;
}
delete surface;
}
delete &fc;
} else {
CameraFlag::g_onFrameErrorFlag = FLAG1;
g_onFrameErrorFlag = true;
}
CameraFlag::g_onFrameFinishedFlag = FLAG1;
g_onFrameFinishedFlag = true;
}
};
......@@ -197,7 +283,6 @@ public:
{
if (recorder_ != nullptr) {
recorder_->Release();
delete recorder_;
}
if (cam_ != nullptr) {
cam_->Release();
......@@ -206,24 +291,25 @@ public:
void OnCreated(Camera &c) override
{
CameraFlag::g_onCreatedFlag = FLAG1;
g_onCreatedFlag = true;
cout << "Sample recv OnCreate camera." << endl;
auto config = CameraConfig::CreateCameraConfig();
config->SetFrameStateCallback(&fsCb_, &eventHandler_);
config->SetFrameStateCallback(&fsCb, &eventHandler_);
c.Configure(*config);
CameraFlag::g_onConfigureFlag = FLAG1;
g_onConfigureFlag = true;
cam_ = &c;
}
void OnCreateFailed(const std::string cameraId, int32_t errorCode) override
{
CameraFlag::g_onCreateFailedFlag = FLAG1;
cout << "Sample recv OnCreateFailed camera." << endl;
g_onCreateFailedFlag = true;
cout << "Camera ID: " << cameraId << endl;
cout << "Sample recv OnCreateFailed camera.: " << errorCode << endl;
}
void OnReleased(Camera &c) override
{
CameraFlag::g_onReleasedFlag = FLAG1;
g_onReleasedFlag = true;
cout << "Sample recv OnReleased camera." << endl;
}
......@@ -234,9 +320,10 @@ public:
cout << "Camera is already recording." << endl;
return;
}
if (recorder_ == nullptr) {
recorder_ = SampleCreateRecorder();
if (recorder_ != nullptr) {
cout << "Recorder is not null" << endl;
}
recorder_ = SampleCreateRecorder();
if (recorder_ == nullptr) {
cout << "Recorder not available" << endl;
return;
......@@ -253,7 +340,7 @@ public:
cout << "Prepare failed.=" << ret << endl;
return;
}
Surface *surface = (recorder_->GetSurface(0)).get();
auto surface = recorder_->GetSurface(0);
surface->SetWidthAndHeight(WIDTH, HEIGHT);
surface->SetQueueSize(QUEUE_SIZE);
surface->SetSize(BUFFER_SIZE * BUFFER_SIZE);
......@@ -261,8 +348,8 @@ public:
fc->AddSurface(*surface);
ret = recorder_->Start();
if (ret != SUCCESS) {
delete fc;
cout << "recorder start failed. ret=" << ret << endl;
delete fc;
return;
}
static int cnt = 3;
......@@ -275,11 +362,11 @@ public:
ret = cam_->TriggerLoopingCapture(*fc);
if (ret != 0) {
delete fc;
cout << "camera start recording failed. ret=" << ret << endl;
return;
}
isRecording_ = true;
g_onRecorderFlag = true;
cout << "camera start recording succeed." << endl;
}
......@@ -290,18 +377,17 @@ public:
return;
}
FrameConfig *fc = new FrameConfig(FRAME_CONFIG_PREVIEW);
Surface *surface = Surface::CreateSurface();
UISurfaceView *surface = new UISurfaceView();
int width = 960;
int height = 480;
surface->SetPosition(0, 0, width, height);
surface->GetSurface()->SetWidthAndHeight(WIDTH, HEIGHT);
if (surface == nullptr) {
delete fc;
cout << "CreateSurface failed" << endl;
delete fc;
return;
}
surface->SetWidthAndHeight(WIDTH, HEIGHT);
surface->SetUserData("region_position_x", "0");
surface->SetUserData("region_position_y", "0");
surface->SetUserData("region_width", "480");
surface->SetUserData("region_height", "480");
fc->AddSurface(*surface);
fc->AddSurface(*(surface->GetSurface()));
static int cnt = 3;
while (cam_ == nullptr) {
if (cnt-- < 0)
......@@ -311,26 +397,25 @@ public:
}
int32_t ret = cam_->TriggerLoopingCapture(*fc);
if (ret != 0) {
delete fc;
cout << "camera start preview failed. ret=" << ret << endl;
delete fc;
return;
}
CameraFlag::g_onCaptureTriggerCompletedFlag = FLAG1;
delete surface;
isPreviewing_ = true;
g_onPreviewFlag = true;
cout << "camera start preview succeed." << endl;
}
void Capture()
void Capture(void)
{
FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
Surface *surface = Surface::CreateSurface();
if (surface == nullptr) {
delete fc;
cout << "CreateSurface failed" << endl;
delete fc;
return;
}
surface->SetWidthAndHeight(1920, 1080); /* 1920:width,1080:height */
surface->SetWidthAndHeight(WIDTH, HEIGHT);
fc->AddSurface(*surface);
static int cnt = 3;
while (cam_ == nullptr) {
......@@ -339,15 +424,18 @@ public:
cout << "Wait camera created success" << endl;
sleep(1);
}
CameraFlag::g_onCaptureTriggerStartedFlag = FLAG1;
g_onCaptureTriggerStartedFlag = true;
cam_->TriggerSingleCapture(*fc);
CameraFlag::g_onCaptureTriggerCompletedFlag = FLAG1;
g_onCaptureTriggerCompletedFlag = true;
}
void Stop()
{
if (recorder_ != nullptr) {
recorder_->Stop(false);
int32_t ret = recorder_->Stop(true);
if (ret != 0) {
cout << "recorder_ stop failed. ret=" << ret << endl;
}
}
while (cam_ == nullptr) {
......@@ -357,6 +445,8 @@ public:
cam_->StopLoopingCapture();
isPreviewing_ = false;
isRecording_ = false;
g_onRecorderFlag = false;
g_onPreviewFlag = false;
}
bool isPreviewing_ = false;
......@@ -364,7 +454,7 @@ public:
EventHandler &eventHandler_;
Camera *cam_ = nullptr;
Recorder *recorder_ = nullptr;
SampleFrameStateCallback fsCb_;
SampleFrameStateCallback fsCb;
};
/* *
......@@ -385,41 +475,43 @@ public:
void OnCreated(Camera &c) override
{
CameraFlag::g_onCreatedFlag = FLAG1;
g_onCreatedFlag = true;
cout << "camera Create success." << endl;
auto config = CameraConfig::CreateCameraConfig();
config->SetFrameStateCallback(&fsCb_, &eventHandler_);
config->SetFrameStateCallback(&fsCb, &eventHandler_);
c.Configure(*config);
cam_ = &c;
}
void OnCreateFailed(const std::string cameraId, int32_t errorCode) override
{
CameraFlag::g_onCreateFailedFlag = FLAG1;
cout << "Camera Create Failed." << endl;
g_onCreateFailedFlag = true;
cout << "Camera ID: " << cameraId << endl;
cout << "Camera Create Failed: " << errorCode << endl;
}
void OnReleased(Camera &c) override
{
CameraFlag::g_onReleasedFlag = FLAG1;
g_onReleasedFlag = true;
cout << "camera Releasedsuccess." << endl;
}
void OnConfigured(Camera &c) override
{
CameraFlag::g_onConfiguredFlag = FLAG1;
g_onConfiguredFlag = true;
cout << "Camera Configured success." << endl;
}
void OnConfigureFailed(const std::string cameraId, int32_t errorCode) override
{
CameraFlag::g_onConfigureFailedFlag = FLAG1;
cout << "Camera Configured failed." << endl;
g_onConfigureFailedFlag = true;
cout << "Camera ID: " << cameraId << endl;
cout << "Camera Configured failed: " << errorCode << endl;
}
EventHandler &eventHandler_;
Camera *cam_ = nullptr;
SampleFrameStateCallback fsCb_;
SampleFrameStateCallback fsCb;
};
/* *
......@@ -434,12 +526,12 @@ public:
// camera device status changed
void OnCameraStatus(std::string cameraId, int32_t status) override
{
cout << "SampleCameraDeviceCallback OnCameraStatus\n" << endl;
cout << "SampleCameraDeviceCallback OnCameraStatus cam Id: \n" << cameraId << endl;
if (status == CAMERA_DEVICE_STATE_AVAILABLE) {
CameraFlag::g_onCameraAvailableFlag = FLAG1;
g_onCameraAvailableFlag = true;
cout << "SampleCameraDeviceCallback onCameraAvailable\n" << endl;
} else if (status == CAMERA_DEVICE_STATE_UNAVAILABLE) {
CameraFlag::g_onCameraUnavailableFlag = FLAG1;
g_onCameraUnavailableFlag = true;
cout << "SampleCameraDeviceCallback onCameraUnavailable\n" << endl;
}
}
......@@ -448,498 +540,1656 @@ public:
/* *
* Get camera Id
*/
void GetCameraId(CameraKit *cameraKit, list<string> &camList, string &camId)
void GetCameraId(CameraKit *cameraKit, list<string> &cameraList, string &cameraId)
{
cameraKit = CameraKit::GetInstance();
camList = cameraKit->GetCameraIds();
for (auto &cam : camList) {
cameraList = cameraKit->GetCameraIds();
for (auto &cam : cameraList) {
cout << "camera name:" << cam << endl;
const CameraAbility *ability = cameraKit->GetCameraAbility(cam);
ASSERT_NE(ability, nullptr);
CameraFlag::g_onGetCameraAbilityFlag = FLAG1;
g_onGetCameraAbilityFlag = true;
/* find camera which fits user's ability */
list<CameraPicSize> sizeList = ability->GetSupportedSizes(0);
if (sizeList.size() != 0) {
CameraFlag::g_onGetSupportedSizesFlag = FLAG1;
g_onGetSupportedSizesFlag = true;
}
for (auto &pic : sizeList) {
cout << "Pic size: " << pic.width << "x" << pic.height << endl;
if (pic.width == WIDTH && pic.height == HEIGHT) {
/* 1920:width,1080:height */
camId = cam;
cameraId = cam;
break;
}
}
}
if (camId.empty()) {
if (cameraId.empty()) {
cout << "No available camera.(1080p wanted)" << endl;
return;
}
}
using namespace OHOS;
using namespace std;
/* start camera kit interface test */
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_0100
* @tc.name : Get cameraIDs
* @tc.name : Get Instance
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, Test_GetCameraIDs, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_GetInstance_001, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
EXPECT_NE(cameraKit, nullptr);
}
HWTEST_F(CameraLiteTest, PrfTest_GetInstance_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
EXPECT_FALSE(camId.empty());
EXPECT_EQ("main", camId);
cameraKit = NULL;
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
cameraKit = CameraKit::GetInstance();
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_0200
* @tc.name : Get cameraAbility
* @tc.name : Get cameraIDs
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, Test_GetCameraAbility, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_GetCameraIds_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
SampleCameraStateMng camStateMng(eventHdlr);
EXPECT_EQ(CameraFlag::g_onGetCameraAbilityFlag, FLAG1);
cameraKit = NULL;
CameraKit *cameraKit = CameraKit::GetInstance();
list<string> cameraList = cameraKit->GetCameraIds();
EXPECT_TRUE(cameraList.size() > 0);
}
HWTEST_F(CameraLiteTest, PrfTest_GetCameraIds_001, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
list<string> cameraList;
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
cameraList = cameraKit->GetCameraIds();
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_0300
* @tc.name : CameraKit get instance
* @tc.name : Get cameraAbility
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestCreatCamerakit, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_GetCameraAbility_001, Level1)
{
CameraKit *cameraKit = nullptr;
cameraKit = CameraKit::GetInstance();
EXPECT_NE(nullptr, cameraKit);
cameraKit = NULL;
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
EXPECT_NE(ability, nullptr);
}
HWTEST_F(CameraLiteTest, Test_GetCameraAbility_002, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string errorCameraId = "-1";
const CameraAbility *ability = cameraKit->GetCameraAbility(errorCameraId);
EXPECT_EQ(ability, nullptr);
}
HWTEST_F(CameraLiteTest, Test_GetCameraAbility_003, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string errorCameraId = "main";
const CameraAbility *ability = cameraKit->GetCameraAbility(errorCameraId);
EXPECT_EQ(ability, nullptr);
}
HWTEST_F(CameraLiteTest, PrfTest_GetCameraAbility_001, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
const CameraAbility *ability = nullptr;
string cameraId = "0";
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
ability = cameraKit->GetCameraAbility(cameraId);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_0400
* @tc.name : Get cameraKit deviceCallback
* @tc.name : CameraKit get Info
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestNewDeviceCallback, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_GetCameraInfo_001, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
list<string> cameraList = cameraKit->GetCameraIds();
for (auto &cameraId : cameraList) {
const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(cameraId);
EXPECT_NE(cameraInfo, nullptr);
}
}
HWTEST_F(CameraLiteTest, Test_GetCameraInfo_002, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string errorCameraId = "-1";
const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(errorCameraId);
EXPECT_EQ(cameraInfo, nullptr);
}
HWTEST_F(CameraLiteTest, Test_GetCameraInfo_003, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string errorCameraId = "main";
const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(errorCameraId);
EXPECT_EQ(cameraInfo, nullptr);
}
HWTEST_F(CameraLiteTest, PrfTest_GetCameraInfo_001, Level1)
{
SampleCameraDeviceCallback *deviceCallback = nullptr;
deviceCallback = new SampleCameraDeviceCallback();
EXPECT_NE(nullptr, deviceCallback);
delete deviceCallback;
deviceCallback = nullptr;
struct timespec tv1 = {0};
struct timespec tv2 = {0};
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
cameraKit->GetCameraInfo(cameraId);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_0500
* @tc.name : Get cameraKit supported Size
* @tc.name : Register Camera device callback
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestGetSupportedSizes, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_RegisterCameraDeviceCallback_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
EXPECT_EQ(CameraFlag::g_onGetSupportedSizesFlag, FLAG1);
cameraKit = NULL;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
SampleCameraDeviceCallback deviceCallback = SampleCameraDeviceCallback();
g_onCameraAvailableFlag = false;
cameraKit->RegisterCameraDeviceCallback(deviceCallback, eventHdlr);
sleep(2);
EXPECT_TRUE(g_onCameraAvailableFlag);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_0600
* @tc.name : Register Camera device callback
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, Test_RegisterCameraDeviceCallback, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, PrfTest_RegisterCameraDeviceCallback_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
SampleCameraDeviceCallback *deviceCallback = nullptr;
deviceCallback = new SampleCameraDeviceCallback();
ASSERT_NE(nullptr, deviceCallback);
cameraKit->RegisterCameraDeviceCallback(*deviceCallback, eventHdlr);
sleep(1);
EXPECT_EQ(CameraFlag::g_onCameraAvailableFlag, FLAG1);
delete deviceCallback;
deviceCallback = nullptr;
cameraKit = NULL;
SampleCameraDeviceCallback deviceCallback = SampleCameraDeviceCallback();
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
cameraKit->RegisterCameraDeviceCallback(deviceCallback, eventHdlr);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_0700
* @tc.number : SUB_MEDIA_CAMERA_DEV_0600
* @tc.name : Unregister Camera Device Callback
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, Test_UnregisterCameraDeviceCallback, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_UnregisterCameraDeviceCallback_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
SampleCameraDeviceCallback *deviceCallback = nullptr;
deviceCallback = new SampleCameraDeviceCallback();
ASSERT_NE(nullptr, deviceCallback);
cameraKit->RegisterCameraDeviceCallback(*deviceCallback, eventHdlr);
sleep(1);
EXPECT_EQ(CameraFlag::g_onCameraAvailableFlag, FLAG1);
cameraKit->UnregisterCameraDeviceCallback(*deviceCallback);
sleep(1);
EXPECT_EQ(CameraFlag::g_onCameraUnavailableFlag, FLAG0);
delete deviceCallback;
deviceCallback = nullptr;
cameraKit = NULL;
SampleCameraDeviceCallback deviceCallback = SampleCameraDeviceCallback();
g_onCameraAvailableFlag = false;
cameraKit->RegisterCameraDeviceCallback(deviceCallback, eventHdlr);
sleep(2);
g_onCameraAvailableFlag = false;
cameraKit->UnregisterCameraDeviceCallback(deviceCallback);
sleep(2);
EXPECT_EQ(g_onCameraAvailableFlag, false);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_0800
* @tc.name : Capture On Configure
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestCaptureOnConfigure, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, PrfTest_UnregisterCameraDeviceCallback_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
sleep(1);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(1);
EXPECT_EQ(CameraFlag::g_onConfigureFlag, FLAG1);
EXPECT_NE(camStateMng.cam_, nullptr);
cameraKit = NULL;
SampleCameraDeviceCallback deviceCallback = SampleCameraDeviceCallback();
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
cameraKit->RegisterCameraDeviceCallback(deviceCallback, eventHdlr);
clock_gettime(CLOCK_REALTIME, &tv1);
cameraKit->UnregisterCameraDeviceCallback(deviceCallback);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_0900
* @tc.number : SUB_MEDIA_CAMERA_DEV_0700
* @tc.name : Create Camera
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestCreateCamera, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_CreateCamera_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
SampleCameraStateMng camStateMng(eventHdlr);
sleep(3);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(3);
EXPECT_EQ(CameraFlag::g_onCreatedFlag, FLAG1);
EXPECT_NE(CameraFlag::g_onCreateFailedFlag, FLAG1);
EXPECT_NE(camStateMng.cam_, nullptr);
cameraKit = NULL;
g_onCreatedFlag = false;
g_onCreateFailedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
EXPECT_EQ(g_onCreatedFlag, true);
EXPECT_EQ(g_onCreateFailedFlag, false);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1000
* @tc.name : Create Camera with error camera id
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestCapture_Create_Camera_ERROR_cameraId, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_CreateCamera_002, Level1)
{
CameraKit *cameraKit = nullptr;
cameraKit = CameraKit::GetInstance();
string camId = "0";
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "main";
EventHandler eventHdlr;
SampleCameraStateMng camStateMng(eventHdlr);
sleep(3);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(3);
EXPECT_EQ(CameraFlag::g_onCreatedFlag, FLAG0);
EXPECT_EQ(CameraFlag::g_onCreateFailedFlag, FLAG1);
cameraKit = NULL;
g_onCreatedFlag = false;
g_onCreateFailedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
EXPECT_EQ(g_onCreatedFlag, false);
EXPECT_EQ(g_onCreateFailedFlag, true);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1100
* @tc.name : Test Capture Frame config
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestCapture_Frame_config, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_CreateCamera_003, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
CameraKit *cameraKit = CameraKit::GetInstance();
list<string> cameraList;
string cameraId = "0";
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
g_onCreatedFlag = false;
g_onCreateFailedFlag = false;
SampleCameraStateMng camStateMng(eventHdlr);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(3);
FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
EXPECT_NE(fc, nullptr);
delete fc;
cameraKit = NULL;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
EXPECT_EQ(g_onCreatedFlag, true);
}
HWTEST_F(CameraLiteTest, Test_CreateCamera_004, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
EventHandler eventHdlr;
g_onCreatedFlag = false;
g_onCreateFailedFlag = false;
SampleCameraStateMng camStateMng(eventHdlr);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
cameraId = "-1";
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
EXPECT_EQ(g_onCreatedFlag, true);
EXPECT_EQ(g_onCreateFailedFlag, true);
}
HWTEST_F(CameraLiteTest, PrfTest_CreateCamera_001, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
EventHandler eventHdlr;
SampleCameraStateMng camStateMng(eventHdlr);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t totalTime = 0;
int64_t usecTimes = 1000000;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 500000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
} /* end camera kit interface test */
/* start camera ability interface test */
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1200
* @tc.name : Test Create Surface
* @tc.number : SUB_MEDIA_CAMERA_DEV_0800
* @tc.name : Get cameraKit supported Size
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestCapture_Create_Surface, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_GetSupportedSizes_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
SampleCameraStateMng camStateMng(eventHdlr);
sleep(3);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(3);
FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
Surface *surface = Surface::CreateSurface();
if (surface == nullptr) {
delete fc;
cout << "CreateSurface failed" << endl;
CameraKit *cameraKit = CameraKit::GetInstance();
list<string> cameraList = cameraKit->GetCameraIds();
for (auto &cameraId : cameraList) {
const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
list<CameraPicSize> cameraPicSizes = ability->GetSupportedSizes(0);
EXPECT_TRUE(cameraPicSizes.size() > 0);
}
EXPECT_NE(surface, nullptr);
delete surface;
delete fc;
cameraKit = NULL;
}
HWTEST_F(CameraLiteTest, PrfTest_GetSupportedSizes_001, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
ability->GetSupportedSizes(0);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1300
* @tc.name : Get Surface Size
* @tc.number : SUB_MEDIA_CAMERA_DEV_0900
* @tc.name : Get supported AfModes
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestCapture_GetSurfaceSize, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_GetSupportedAfModes_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
SampleCameraStateMng camStateMng(eventHdlr);
sleep(3);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(3);
FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
Surface *surface = Surface::CreateSurface();
if (surface == nullptr) {
delete fc;
cout << "CreateSurface failed" << endl;
CameraKit *cameraKit = CameraKit::GetInstance();
list<string> cameraList = cameraKit->GetCameraIds();
for (auto &cameraId : cameraList) {
const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
list<int32_t> afModes = ability->GetSupportedAfModes();
EXPECT_TRUE(afModes.size() >= 0);
}
surface->SetWidthAndHeight(1920, 1080); /* 1920:width,1080:height */
EXPECT_EQ(1920, surface->GetWidth());
EXPECT_EQ(1080, surface->GetHeight());
delete surface;
delete fc;
cameraKit = NULL;
}
HWTEST_F(CameraLiteTest, PrfTest_GetSupportedAfModes_001, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
ability->GetSupportedAfModes();
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1400
* @tc.name : Get FrameConfig size
* @tc.number : SUB_MEDIA_CAMERA_DEV_1000
* @tc.name : Get supported AeModes
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestCapture_frameConfig_getsize, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_GetSupportedAeModes_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
SampleCameraStateMng camStateMng(eventHdlr);
sleep(3);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(3);
FrameConfig *fc = new FrameConfig(FRAME_CONFIG_CAPTURE);
Surface *surface = Surface::CreateSurface();
if (surface == nullptr) {
delete fc;
cout << "CreateSurface failed" << endl;
CameraKit *cameraKit = CameraKit::GetInstance();
list<string> cameraList = cameraKit->GetCameraIds();
for (auto &cameraId : cameraList) {
const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
list<int32_t> aeModes = ability->GetSupportedAeModes();
EXPECT_TRUE(aeModes.size() >= 0);
}
surface->SetWidthAndHeight(1920, 1080); /* 1920:width,1080:height */
fc->AddSurface(*surface);
EXPECT_NE(0, fc->GetSurfaces().size());
delete surface;
delete fc;
cameraKit = NULL;
}
HWTEST_F(CameraLiteTest, PrfTest_GetSupportedAeModes_001, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
const CameraAbility *ability = cameraKit->GetCameraAbility(cameraId);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t totalTime = 0;
int64_t usecTimes = 1000000;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
ability->GetSupportedAeModes();
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
} /* end camera ability interface test*/
/* start camera state callback test */
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1500
* @tc.name : Test Get Frame
* @tc.number : SUB_MEDIA_CAMERA_DEV_1100
* @tc.name : On Create
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestOnFrameProgressed, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_OnCreate_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
SampleCameraStateMng camStateMng(eventHdlr);
sleep(3);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(3);
camStateMng.Capture();
sleep(1);
EXPECT_EQ(CameraFlag::g_onFrameStartedFlag, FLAG1);
EXPECT_EQ(CameraFlag::g_onFrameProgressedFlag, FLAG1);
cameraKit = NULL;
g_onCreatedFlag = false;
g_onCreateFailedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
EXPECT_EQ(g_onCreatedFlag, true);
EXPECT_EQ(g_onCreateFailedFlag, false);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1600
* @tc.name : Get FrameConfig onConfig
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestGetFrameConfigureType, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_OnCreate_002, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
SampleCameraStateMng camStateMng(eventHdlr);
sleep(3);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(3);
camStateMng.Capture();
sleep(1);
EXPECT_EQ(CameraFlag::g_onGetFrameConfigureType, FLAG1);
cameraKit = NULL;
g_onCreatedFlag = false;
g_onCreateFailedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.Stop();
EXPECT_EQ(g_onCreatedFlag, true);
EXPECT_NE(g_onCreateFailedFlag, true);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1700
* @tc.name : Test Get Frame finished
* @tc.number : SUB_MEDIA_CAMERA_DEV_1200
* @tc.name : On Create Failed
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestFrameCompletedFlag, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_OnCreateFailed_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "-1";
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
SampleCameraStateMng camStateMng(eventHdlr);
sleep(3);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(3);
camStateMng.Capture();
sleep(1);
EXPECT_EQ(CameraFlag::g_onFrameFinishedFlag, FLAG1);
cameraKit = NULL;
g_onCreateFailedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
EXPECT_EQ(g_onCreateFailedFlag, true);
}
HWTEST_F(CameraLiteTest, Test_OnCreateFailed_002, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "main";
EventHandler eventHdlr;
SampleCameraStateMng camStateMng(eventHdlr);
g_onCreateFailedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
EXPECT_EQ(g_onCreateFailedFlag, true);
} /* end camera state callback test */
/* start frame config & frame state call back interface test */
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1300
* @tc.name : Frame Config
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(CameraLiteTest, Test_FrameConfig_001, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
EXPECT_NE(frameConfig.get(), nullptr);
}
HWTEST_F(CameraLiteTest, Test_FrameConfig_002, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
EXPECT_NE(frameConfig.get(), nullptr);
}
HWTEST_F(CameraLiteTest, Test_FrameConfig_003, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
EXPECT_NE(frameConfig.get(), nullptr);
}
HWTEST_F(CameraLiteTest, Test_FrameConfig_004, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
EXPECT_NE(frameConfig.get(), nullptr);
}
HWTEST_F(CameraLiteTest, PrfTest_Frameconfig_001, Level1)
{
shared_ptr<FrameConfig> frameConfig = nullptr;
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
HWTEST_F(CameraLiteTest, PrfTest_Frameconfig_002, Level1)
{
shared_ptr<FrameConfig> frameConfig = nullptr;
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
HWTEST_F(CameraLiteTest, PrfTest_Frameconfig_003, Level1)
{
shared_ptr<FrameConfig> frameConfig = nullptr;
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
HWTEST_F(CameraLiteTest, PrfTest_Frameconfig_004, Level1)
{
shared_ptr<FrameConfig> frameConfig = nullptr;
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1400
* @tc.name : Get Frame Configure Type
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(CameraLiteTest, Test_GetFrameConfigureType_001, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
EventHandler eventHdlr;
SampleCameraStateMng camStateMng(eventHdlr);
g_onGetFrameConfigureType = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.Capture();
sleep(2);
EXPECT_EQ(g_onGetFrameConfigureType, true);
}
HWTEST_F(CameraLiteTest, Test_GetFrameConfigureType_002, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
EventHandler eventHdlr;
SampleCameraStateMng camStateMng(eventHdlr);
g_onGetFrameConfigureType = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.Capture();
sleep(2);
camStateMng.Stop();
EXPECT_EQ(g_onGetFrameConfigureType, true);
}
HWTEST_F(CameraLiteTest, Test_GetFrameConfigureType_003, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
EventHandler eventHdlr;
SampleCameraStateMng camStateMng(eventHdlr);
g_onGetFrameConfigureType = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.StartPreview();
sleep(2);
camStateMng.Stop();
EXPECT_EQ(g_onGetFrameConfigureType, false);
}
HWTEST_F(CameraLiteTest, Test_GetFrameConfigureType_004, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
EventHandler eventHdlr;
SampleCameraStateMng camStateMng(eventHdlr);
g_onGetFrameConfigureType = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.Capture();
sleep(2);
camStateMng.StartPreview();
sleep(2);
camStateMng.Stop();
EXPECT_EQ(g_onGetFrameConfigureType, true);
}
HWTEST_F(CameraLiteTest, Test_GetFrameConfigureType_005, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
EventHandler eventHdlr;
SampleCameraStateMng camStateMng(eventHdlr);
g_onGetFrameConfigureType = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.StartPreview();
sleep(2);
camStateMng.Capture();
sleep(2);
camStateMng.Stop();
EXPECT_EQ(g_onGetFrameConfigureType, true);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1500
* @tc.name : Set Vendor Parameter
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(CameraLiteTest, Test_SetVendorParameter_001, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
privateTag[4] = 5;
frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
uint8_t *privateTagTemp = new uint8_t[10];
frameConfig->GetVendorParameter(privateTagTemp, 10);
EXPECT_TRUE(privateTagTemp[4] == 5);
delete[] privateTag;
delete[] privateTagTemp;
}
HWTEST_F(CameraLiteTest, Test_SetVendorParameter_002, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
privateTag[10] = 10;
frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
EXPECT_TRUE(privateTagTemp[10] == 10);
delete[] privateTag;
delete[] privateTagTemp;
}
HWTEST_F(CameraLiteTest, Test_SetVendorParameter_003, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
privateTag[0] = 1;
frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
EXPECT_TRUE(privateTagTemp[0] == 1);
delete[] privateTag;
delete[] privateTagTemp;
}
HWTEST_F(CameraLiteTest, Test_SetVendorParameter_004, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
privateTag[31] = 31;
frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
EXPECT_TRUE(privateTagTemp[31] == 31);
delete[] privateTag;
delete[] privateTagTemp;
}
HWTEST_F(CameraLiteTest, PrfTest_SetVendorParameter_001, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
privateTag[1] = 1;
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
delete[] privateTag;
}
HWTEST_F(CameraLiteTest, PrfTest_SetVendorParameter_002, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
privateTag[2] = 2;
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
delete[] privateTag;
}
HWTEST_F(CameraLiteTest, PrfTest_SetVendorParameter_003, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
privateTag[3] = 3;
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
delete[] privateTag;
}
HWTEST_F(CameraLiteTest, PrfTest_SetVendorParameter_004, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
privateTag[4] = 4;
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
delete[] privateTag;
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1600
* @tc.name : Get Vendor Parameter
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(CameraLiteTest, PrfTest_GetVendorParameter_001, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
privateTag[1] = 1;
frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
delete[] privateTag;
delete[] privateTagTemp;
}
HWTEST_F(CameraLiteTest, PrfTest_GetVendorParameter_002, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
privateTag[2] = 2;
frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
delete[] privateTag;
delete[] privateTagTemp;
}
HWTEST_F(CameraLiteTest, PrfTest_GetVendorParameter_003, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
privateTag[3] = 3;
frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
delete[] privateTag;
delete[] privateTagTemp;
}
HWTEST_F(CameraLiteTest, PrfTest_GetVendorParameter_004, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
uint8_t *privateTag = new uint8_t[PRIVATE_TAG_LEN];
privateTag[4] = 4;
frameConfig->SetVendorParameter(privateTag, PRIVATE_TAG_LEN);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
uint8_t *privateTagTemp = new uint8_t[PRIVATE_TAG_LEN];
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->GetVendorParameter(privateTagTemp, PRIVATE_TAG_LEN);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
delete[] privateTag;
delete[] privateTagTemp;
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1700
* @tc.name : Get Surface
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(CameraLiteTest, Test_GetSurface_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
Surface *surface = Surface::CreateSurface();
surface->SetWidthAndHeight(1920, 1080);
EXPECT_EQ(1920, surface->GetWidth());
EXPECT_EQ(1080, surface->GetHeight());
}
HWTEST_F(CameraLiteTest, Test_GetSurface_002, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
Surface *surface = Surface::CreateSurface();
surface->SetWidthAndHeight(480, 360);
EXPECT_EQ(480, surface->GetWidth());
EXPECT_EQ(360, surface->GetHeight());
}
HWTEST_F(CameraLiteTest, Test_GetSurface_003, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
Surface *surface = Surface::CreateSurface();
surface->SetWidthAndHeight(1920, 1080);
frameConfig->AddSurface(*surface);
EXPECT_FALSE(frameConfig->GetSurfaces().size() == 0);
}
HWTEST_F(CameraLiteTest, Test_GetSurface_004, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
Surface *surface = Surface::CreateSurface();
frameConfig->AddSurface(*surface);
frameConfig->RemoveSurface(*surface);
list<Surface *> list = frameConfig->GetSurfaces();
EXPECT_TRUE(list.size() == 0);
}
HWTEST_F(CameraLiteTest, Test_GetSurface_005, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
Surface *surface = Surface::CreateSurface();
frameConfig->AddSurface(*surface);
list<Surface *> list = frameConfig->GetSurfaces();
EXPECT_TRUE(list.size() == 1);
}
HWTEST_F(CameraLiteTest, Test_GetSurface_006, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
Surface *surface = Surface::CreateSurface();
frameConfig->AddSurface(*surface);
list<Surface *> list = frameConfig->GetSurfaces();
EXPECT_TRUE(list.size() == 1);
}
HWTEST_F(CameraLiteTest, PrfTest_GetSurfaces_001, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
Surface *surface = Surface::CreateSurface();
frameConfig->AddSurface(*surface);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->GetSurfaces();
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
HWTEST_F(CameraLiteTest, PrfTest_GetSurfaces_002, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CAPTURE);
Surface *surface = Surface::CreateSurface();
frameConfig->AddSurface(*surface);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->GetSurfaces();
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
HWTEST_F(CameraLiteTest, PrfTest_GetSurfaces_003, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_RECORD);
Surface *surface = Surface::CreateSurface();
frameConfig->AddSurface(*surface);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->GetSurfaces();
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
HWTEST_F(CameraLiteTest, PrfTest_GetSurfaces_004, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_CALLBACK);
Surface *surface = Surface::CreateSurface();
frameConfig->AddSurface(*surface);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->GetSurfaces();
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1800
* @tc.name : Test GetFrame Error
* @tc.name : On Frame Progressed
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestonFrameErrorFlag, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_OnFrameProgressed_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
sleep(3);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(3);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.Capture();
sleep(1);
EXPECT_NE(CameraFlag::g_onFrameErrorFlag, FLAG1);
cameraKit = NULL;
sleep(2);
EXPECT_EQ(g_onFrameStartedFlag, true);
EXPECT_EQ(g_onFrameProgressedFlag, true);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_1900
* @tc.name : Test Capture Success
* @tc.name : On Frame Completed
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestCapture01, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_OnFrameCompletedFlag_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
sleep(3);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(3);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.Capture();
sleep(1);
EXPECT_EQ(CameraFlag::g_onCaptureTriggerStartedFlag, FLAG1);
EXPECT_EQ(CameraFlag::g_onCaptureTriggerCompletedFlag, FLAG1);
cameraKit = NULL;
sleep(2);
EXPECT_EQ(g_onFrameFinishedFlag, true);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_2000
* @tc.name : Test capture and record
* @tc.name : On Frame Error
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestRecord01, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_OnFrameErrorFlag_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
sleep(3);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(3);
EXPECT_EQ(CameraFlag::g_onCreatedFlag, FLAG1);
EXPECT_EQ(CameraFlag::g_onConfigureFlag, FLAG1);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.Capture();
sleep(3);
camStateMng.StartRecord();
sleep(3);
camStateMng.Stop();
cameraKit = NULL;
sleep(2);
EXPECT_NE(g_onFrameErrorFlag, true);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_2100
* @tc.name : Test get event handler
* @tc.name : Add Surface
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(CameraLiteTest, Test_AddSurface_001, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
Surface *surface = Surface::CreateSurface();
frameConfig->AddSurface(*surface);
list<Surface *> list = frameConfig->GetSurfaces();
EXPECT_TRUE(list.size() == 1);
}
HWTEST_F(CameraLiteTest, Test_AddSurface_002, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
Surface *surface = Surface::CreateSurface();
frameConfig->AddSurface(*surface);
frameConfig->AddSurface(*surface);
list<Surface *> list = frameConfig->GetSurfaces();
EXPECT_TRUE(list.size() == 2);
}
HWTEST_F(CameraLiteTest, Test_AddSurface_003, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
Surface *surface = Surface::CreateSurface();
frameConfig->AddSurface(*surface);
frameConfig->AddSurface(*surface);
frameConfig->AddSurface(*surface);
list<Surface *> list = frameConfig->GetSurfaces();
EXPECT_TRUE(list.size() == 3);
}
HWTEST_F(CameraLiteTest, PrfTest_AddSurface_001, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
Surface *surface = Surface::CreateSurface();
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->AddSurface(*surface);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_2200
* @tc.name : Remove Surface
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(ActsMediaCameraTest, TestGetEventHandler, Function | MediumTest | Level1)
HWTEST_F(CameraLiteTest, Test_RemoveSurface_001, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
Surface *surface = Surface::CreateSurface();
frameConfig->AddSurface(*surface);
frameConfig->RemoveSurface(*surface);
list<Surface *> list = frameConfig->GetSurfaces();
EXPECT_TRUE(list.size() == 0);
}
HWTEST_F(CameraLiteTest, Test_RemoveSurface_002, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
Surface *surface = Surface::CreateSurface();
Surface *surface1 = Surface::CreateSurface();
frameConfig->AddSurface(*surface);
frameConfig->AddSurface(*surface1);
frameConfig->RemoveSurface(*surface1);
list<Surface *> list = frameConfig->GetSurfaces();
EXPECT_TRUE(list.size() == 1);
}
HWTEST_F(CameraLiteTest, Test_RemoveSurface_003, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
Surface *surface = Surface::CreateSurface();
Surface *surface1 = Surface::CreateSurface();
frameConfig->AddSurface(*surface);
frameConfig->AddSurface(*surface1);
frameConfig->RemoveSurface(*surface);
frameConfig->RemoveSurface(*surface1);
list<Surface *> list = frameConfig->GetSurfaces();
EXPECT_TRUE(list.size() == 0);
}
HWTEST_F(CameraLiteTest, PrfTest_RemoveSurface_001, Level1)
{
shared_ptr<FrameConfig> frameConfig = make_shared<FrameConfig>(FRAME_CONFIG_PREVIEW);
Surface *surface = Surface::CreateSurface();
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
frameConfig->AddSurface(*surface);
clock_gettime(CLOCK_REALTIME, &tv1);
frameConfig->RemoveSurface(*surface);
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_2300
* @tc.name : Capture
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(CameraLiteTest, Test_Capture_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> camList;
string camId;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, camList, camId);
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
sleep(3);
cameraKit->CreateCamera(camId, camStateMng, eventHdlr);
sleep(3);
EXPECT_EQ(CameraFlag::g_onCreatedFlag, FLAG1);
EXPECT_EQ(CameraFlag::g_onConfigureFlag, FLAG1);
g_onCaptureTriggerStartedFlag = false;
g_onCaptureTriggerCompletedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.Capture();
sleep(3);
camStateMng.StartRecord();
sleep(3);
sleep(2);
EXPECT_EQ(g_onCaptureTriggerStartedFlag, true);
EXPECT_EQ(g_onCaptureTriggerCompletedFlag, true);
}
HWTEST_F(CameraLiteTest, Test_Capture_002, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
EventHandler eventHdlr;
SampleCameraStateMng camStateMng(eventHdlr);
g_onCaptureTriggerStartedFlag = false;
g_onCaptureTriggerCompletedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.StartPreview();
sleep(2);
camStateMng.Capture();
sleep(2);
camStateMng.Stop();
cameraKit = NULL;
sleep(2);
EXPECT_EQ(g_onCaptureTriggerStartedFlag, true);
EXPECT_EQ(g_onCaptureTriggerCompletedFlag, true);
}
HWTEST_F(CameraLiteTest, Test_Capture_003, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
EventHandler eventHdlr;
SampleCameraStateMng camStateMng(eventHdlr);
g_onCaptureTriggerStartedFlag = false;
g_onCaptureTriggerCompletedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.StartPreview();
sleep(2);
camStateMng.Stop();
sleep(2);
EXPECT_EQ(g_onCaptureTriggerStartedFlag, false);
EXPECT_EQ(g_onCaptureTriggerCompletedFlag, false);
}
HWTEST_F(CameraLiteTest, Test_Capture_004, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
g_onCaptureTriggerStartedFlag = false;
g_onCaptureTriggerCompletedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.Capture();
sleep(2);
camStateMng.Stop();
sleep(2);
EXPECT_EQ(g_onCaptureTriggerStartedFlag, true);
EXPECT_EQ(g_onCaptureTriggerCompletedFlag, true);
}
HWTEST_F(CameraLiteTest, Test_Capture_005, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
g_onCaptureTriggerStartedFlag = false;
g_onCaptureTriggerCompletedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.Capture();
sleep(2);
camStateMng.Capture();
sleep(2);
EXPECT_EQ(g_onCaptureTriggerStartedFlag, true);
EXPECT_EQ(g_onCaptureTriggerCompletedFlag, true);
}
HWTEST_F(CameraLiteTest, Test_Capture_006, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
g_onCaptureTriggerStartedFlag = false;
g_onCaptureTriggerCompletedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.Capture();
sleep(2);
EXPECT_TRUE(g_onCaptureTriggerStartedFlag);
EXPECT_TRUE(g_onCaptureTriggerCompletedFlag);
}
HWTEST_F(CameraLiteTest, Test_Capture_007, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
g_onCaptureTriggerStartedFlag = false;
g_onCaptureTriggerCompletedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.Stop();
sleep(2);
camStateMng.Capture();
sleep(2);
EXPECT_TRUE(g_onCaptureTriggerStartedFlag);
EXPECT_TRUE(g_onCaptureTriggerCompletedFlag);
}
HWTEST_F(CameraLiteTest, Test_Capture_008, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
g_onCaptureTriggerStartedFlag = false;
g_onCaptureTriggerCompletedFlag = false;
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
sleep(2);
camStateMng.StartPreview();
sleep(2);
camStateMng.Stop();
sleep(2);
camStateMng.Capture();
sleep(2);
EXPECT_EQ(g_onCaptureTriggerStartedFlag, true);
EXPECT_EQ(g_onCaptureTriggerCompletedFlag, true);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_2400
* @tc.name : Preview
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(CameraLiteTest, Test_Preview_001, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
g_onPreviewFlag = false;
camStateMng.StartPreview();
sleep(2);
EXPECT_TRUE(g_onPreviewFlag);
camStateMng.Stop();
}
HWTEST_F(CameraLiteTest, Test_Preview_002, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
g_onPreviewFlag = false;
camStateMng.StartPreview();
sleep(2);
camStateMng.Stop();
EXPECT_FALSE(g_onPreviewFlag);
}
HWTEST_F(CameraLiteTest, Test_Preview_003, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
g_onPreviewFlag = false;
camStateMng.StartPreview();
sleep(2);
camStateMng.Stop();
camStateMng.StartPreview();
sleep(2);
EXPECT_TRUE(g_onPreviewFlag);
}
HWTEST_F(CameraLiteTest, Test_Preview_004, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
g_onPreviewFlag = false;
camStateMng.StartPreview();
sleep(2);
camStateMng.Stop();
camStateMng.StartPreview();
sleep(2);
camStateMng.Stop();
EXPECT_FALSE(g_onPreviewFlag);
}
HWTEST_F(CameraLiteTest, Test_Preview_005, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
g_onPreviewFlag = false;
camStateMng.Capture();
sleep(2);
camStateMng.Stop();
sleep(2);
camStateMng.StartPreview();
sleep(2);
EXPECT_TRUE(g_onPreviewFlag);
camStateMng.Stop();
}
HWTEST_F(CameraLiteTest, Test_Preview_006, Level1)
{
CameraKit *cameraKit = nullptr;
list<string> cameraList;
string cameraId;
EventHandler eventHdlr;
GetCameraId(cameraKit, cameraList, cameraId);
SampleCameraStateMng camStateMng(eventHdlr);
cameraKit->CreateCamera(cameraId, camStateMng, eventHdlr);
g_onPreviewFlag = false;
camStateMng.Capture();
sleep(2);
camStateMng.StartPreview();
sleep(2);
camStateMng.Stop();
EXPECT_FALSE(g_onPreviewFlag);
} /* end frame config & frame state call back interface test */
/* start camera info interface test */
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_2500
* @tc.name : Get Camera Type
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(CameraLiteTest, Test_GetCameraType_001, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(cameraId);
int32_t cameraType = cameraInfo->GetCameraType();
EXPECT_TRUE(cameraType <= 3);
EXPECT_TRUE(cameraType >= 0);
}
HWTEST_F(CameraLiteTest, PrfTest_GetCameraType_001, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(cameraId);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
cameraInfo->GetCameraType();
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
}
/* *
* @tc.number : SUB_MEDIA_CAMERA_DEV_2600
* @tc.name : Get Camera Facing Type
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F(CameraLiteTest, Test_GetCameraFacingType_001, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(cameraId);
int32_t cameraFacingType = cameraInfo->GetCameraFacingType();
EXPECT_TRUE(cameraFacingType <= 2);
EXPECT_TRUE(cameraFacingType >= 0);
}
HWTEST_F(CameraLiteTest, PrfTest_GetCameraFacingType_001, Level1)
{
CameraKit *cameraKit = CameraKit::GetInstance();
string cameraId = "0";
const CameraInfo *cameraInfo = cameraKit->GetCameraInfo(cameraId);
struct timespec tv1 = {0};
struct timespec tv2 = {0};
int64_t performanceTestTimes = 10;
int64_t usecTimes = 1000000;
int64_t totalTime = 0;
for (int32_t i = 0; i < performanceTestTimes; i++) {
clock_gettime(CLOCK_REALTIME, &tv1);
cameraInfo->GetCameraFacingType();
clock_gettime(CLOCK_REALTIME, &tv2);
totalTime += tv2.tv_sec * usecTimes + tv2.tv_nsec - (tv1.tv_sec * usecTimes + tv1.tv_nsec);
}
int64_t expectTime = 1000000;
EXPECT_TRUE(totalTime <= expectTime * performanceTestTimes);
} /* end camera info interface test */
} // namespace OHOS
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2020-2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -13,19 +13,15 @@
* limitations under the License.
*/
#ifndef CAMERA_DEMO_TEST_H
#define CAMERA_DEMO_TEST_H
#ifndef CAMERA_LITE_TEST_H
#define CAMERA_LITE_TEST_H
#include "gtest/gtest.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <sys/time.h>
#include "camera_kit.h"
#include "recorder.h"
namespace OHOS {
const int32_t RET_OK = 0;
const int32_t RET_ERR = -1;
const int32_t FRAME_RATE_DEFAULT = 30;
const int32_t OK = 0;
const int32_t FAIL = -1;
......@@ -34,11 +30,29 @@ const int32_t BUFFER_SIZE = 1024;
static std::string g_filePath = "/test_root/multimedia/";
std::string g_testPath;
// CallBack Flag
enum TestCallBackFlag {
FLAG0 = 0,
FLAG1 = 1,
};
bool g_onGetCameraAbilityFlag;
bool g_onConfigureFlag;
bool g_onGetSupportedSizesFlag;
// CameraDeviceCallBack Flag
bool g_onCameraAvailableFlag;
bool g_onCameraUnavailableFlag;
// CameraStateCallback
bool g_onCreatedFlag;
bool g_onCreateFailedFlag;
bool g_onReleasedFlag;
bool g_onConfiguredFlag;
bool g_onConfigureFailedFlag;
// FrameStateCallback
bool g_onCaptureTriggerAbortedFlag;
bool g_onCaptureTriggerCompletedFlag;
bool g_onCaptureTriggerStartedFlag;
bool g_onGetFrameConfigureType;
bool g_onFrameFinishedFlag;
bool g_onFrameErrorFlag;
bool g_onFrameProgressedFlag;
bool g_onFrameStartedFlag;
bool g_onRecorderFlag;
bool g_onPreviewFlag;
// VideoSize
enum TestVideoSize {
......@@ -46,7 +60,7 @@ enum TestVideoSize {
HEIGHT = 1080,
};
class ActsMediaCameraTest : public testing::Test {
class CameraLiteTest : public testing::Test {
public:
// SetUpTestCase: before all testcasee
static void SetUpTestCase(void);
......@@ -57,53 +71,5 @@ public:
// TearDown
void TearDown(void);
};
class CameraFlag {
public:
// CameraSetupFlag
static int32_t g_onGetCameraAbilityFlag;
static int32_t g_onConfigureFlag;
static int32_t g_onGetSupportedSizesFlag;
// CameraDeviceCallBack Flag
static int32_t g_onCameraAvailableFlag;
static int32_t g_onCameraUnavailableFlag;
// CameraStateCallback
static int32_t g_onCreatedFlag;
static int32_t g_onCreateFailedFlag;
static int32_t g_onReleasedFlag;
static int32_t g_onConfiguredFlag;
static int32_t g_onConfigureFailedFlag;
// FrameStateCallback
static int32_t g_onCaptureTriggerAbortedFlag;
static int32_t g_onCaptureTriggerCompletedFlag;
static int32_t g_onCaptureTriggerStartedFlag;
static int32_t g_onGetFrameConfigureType;
static int32_t g_onFrameFinishedFlag;
static int32_t g_onFrameErrorFlag;
static int32_t g_onFrameProgressedFlag;
static int32_t g_onFrameStartedFlag;
};
// CameraSetup
int32_t CameraFlag::g_onGetCameraAbilityFlag = FLAG0;
int32_t CameraFlag::g_onConfigureFlag = FLAG0;
int32_t CameraFlag::g_onGetSupportedSizesFlag = FLAG0;
// CameraDeviceCallBack
int32_t CameraFlag::g_onCameraAvailableFlag = FLAG0;
int32_t CameraFlag::g_onCameraUnavailableFlag = FLAG0;
// CameraStateCallback
int32_t CameraFlag::g_onCreatedFlag = FLAG0;
int32_t CameraFlag::g_onCreateFailedFlag = FLAG0;
int32_t CameraFlag::g_onConfiguredFlag = FLAG0;
int32_t CameraFlag::g_onConfigureFailedFlag = FLAG0;
int32_t CameraFlag::g_onReleasedFlag = FLAG0;
// FrameStateCallback
int32_t CameraFlag::g_onCaptureTriggerAbortedFlag = FLAG0;
int32_t CameraFlag::g_onCaptureTriggerCompletedFlag = FLAG0;
int32_t CameraFlag::g_onCaptureTriggerStartedFlag = FLAG0;
int32_t CameraFlag::g_onGetFrameConfigureType = FLAG0;
int32_t CameraFlag::g_onFrameFinishedFlag = FLAG0;
int32_t CameraFlag::g_onFrameErrorFlag = FLAG0;
int32_t CameraFlag::g_onFrameProgressedFlag = FLAG0;
int32_t CameraFlag::g_onFrameStartedFlag = FLAG0;
#endif
\ No newline at end of file
} // namespace OHOS
#endif // CAMERA_LITE_TEST_H
\ No newline at end of file
......@@ -1006,7 +1006,7 @@ HWTEST_F(ActsMediaRecorderNDKTest, Test_SetMaxFileSize2, Function | MediumTest |
HWTEST_F(ActsMediaRecorderNDKTest, Test_SetOutputFile1, Function | MediumTest | Level0)
{
Recorder *recorder = new Recorder();
int32_t ret = recorder->SetOutputFile(-1);
int32_t ret = recorder->SetOutputFile(1);
EXPECT_EQ(ERR_INVALID_PARAM, ret);
delete recorder;
recorder = NULL;
......@@ -1020,7 +1020,7 @@ HWTEST_F(ActsMediaRecorderNDKTest, Test_SetOutputFile1, Function | MediumTest |
HWTEST_F(ActsMediaRecorderNDKTest, Test_SetNextOutputFile1, Function | MediumTest | Level0)
{
Recorder *recorder = new Recorder();
int32_t ret = recorder->SetNextOutputFile(-1);
int32_t ret = recorder->SetNextOutputFile(1);
EXPECT_EQ(ERR_INVALID_PARAM, ret);
delete recorder;
recorder = NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册