!860 hdi test suites

Merge pull request !860 from wangchao/master
This commit is contained in:
openharmony_ci 2023-10-30 13:59:36 +00:00 committed by Gitee
commit e5560fdc96
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
35 changed files with 5165 additions and 0 deletions

View File

@ -25,6 +25,7 @@ group("HatsHdfCameraTest") {
deps = [
"cameraHdi:HatsHdfCameraHdiTest",
"cameraMg:HatsHdfCameraMgTest",
"cameraMg_additional:HatsHdfCameraMgTestAdditional",
#"cameraBenchmarkTest:HatsHdfCamerabenchmarkTest",
]

View File

@ -0,0 +1,27 @@
# Copyright (c) 2021-2022 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos_var.gni")
import("//test/xts/hats/build.gni")
import("//test/xts/tools/build/suite.gni")
#################################group#########################################
group("HatsHdfCameraMgTestAdditional") {
if (!defined(ohos_lite)) {
testonly = true
}
if (is_standard_system) {
deps = [ "v1_0:HatsHdfCameraMgTestv0Additional" ]
}
}
###############################################################################

View File

@ -0,0 +1,77 @@
# Copyright (c) 2022 - 2023 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
base_root = "../../../../../../../"
import("//build/ohos.gni")
import("//build/ohos_var.gni")
import("//build/test.gni")
import("//test/xts/tools/build/suite.gni")
import("$base_root/drivers/peripheral/camera/camera.gni")
import("$base_root/drivers/peripheral/display/display_config.gni")
module_output_path = "hats/camera"
ohos_moduletest_suite("HatsHdfCameraMgTestv0Additional") {
#testonly = true
defines = []
defines += display_defines
configs = [ ":hdf_cameramg_additional" ]
module_out_path = module_output_path
sources = [
"./src/camera_3a_uttest.cpp",
"./src/common.cpp",
"./src/hdi_device_uttest.cpp",
"./src/hdi_host_uttest.cpp",
"./src/hdi_stream_uttest.cpp",
]
deps = [
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest",
"//third_party/googletest:gtest_main",
]
if (is_standard_system) {
external_deps = [
"c_utils:utils",
"hdf_core:libhdf_host",
"hdf_core:libhdf_ipc_adapter",
"hdf_core:libhdf_utils",
"hdf_core:libhdi",
"hilog:libhilog",
"ipc:ipc_single",
]
} else {
external_deps = [ "hilog:libhilog" ]
}
external_deps += [
"drivers_interface_camera:libbuffer_producer_sequenceable_1.0",
"drivers_interface_camera:libcamera_proxy_1.0",
"drivers_interface_camera:metadata",
"drivers_interface_display:libdisplay_composer_proxy_1.0",
"graphic_chipsetsdk:surface",
"samgr:samgr_proxy",
]
# public_configs = [ ":cameraTest_config" ]
subsystem_name = "xts"
part_name = "hats"
}
config("hdf_cameramg_additional") {
include_dirs = [
# common includes
"./include",
"//third_party/googletest/googletest/include",
"$camera_path/../../interfaces/include",
"$camera_path/include",
]
}

View File

@ -0,0 +1,18 @@
{
"kits": [
{
"push": [
"HatsHdfCameraMgTestv0Additional->/data/local/tmp/HatsHdfCameraMgTestv0Additional"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "HatsHdfCameraMgTestv0Additional",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for HatsHdfCameraMgTestv0Additional Tests"
}

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file expected in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "common.h"
class Camera3AUtTestAdditional : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp(void);
void TearDown(void);
std::shared_ptr<OHOS::Camera::Test> cameraTest = nullptr;
};

View File

@ -0,0 +1,196 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file expected in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <thread>
#include <iostream>
#include <unistd.h>
#include <gtest/gtest.h>
#include <sys/time.h>
#include <map>
#include <vector>
#include <fcntl.h>
#include "camera.h"
#include "v1_0/types.h"
#include "metadata_utils.h"
#include "v1_0/icamera_host.h"
#include "v1_0/icamera_device.h"
#include "v1_0/istream_operator.h"
#include "v1_0/camera_host_proxy.h"
#include "v1_0/ioffline_stream_operator.h"
#include "v1_0/display_composer_type.h"
#include "iconsumer_surface.h"
namespace OHOS::Camera {
enum CameraUtConstants {
UT_SLEEP_TIME = 2,
UT_SECOND_TIMES,
UT_TUNNEL_MODE = 5,
UT_DATA_SIZE = 8,
};
enum ImageDataSaveSwitch {
SWITCH_OFF,
SWITCH_ON,
};
using namespace OHOS::HDI::Camera::V1_0;
using namespace OHOS::HDI::Display::Composer::V1_0;
class Test {
public:
void Init();
void Open();
void Close();
void GetCameraMetadata();
void StartStream(std::vector<StreamIntent> intents);
uint64_t GetCurrentLocalTimeStamp();
int32_t DumpImageFile(int streamId, std::string suffix, const void* buffer, int32_t size);
void StartCapture(int streamId, int captureId, bool shutterCallback, bool isStreaming);
void StopStream(std::vector<int>& captureIds, std::vector<int>& streamIds);
OHOS::sptr<OHOS::Camera::ICameraHost> service = nullptr;
OHOS::sptr<ICameraDevice> cameraDevice = nullptr;
OHOS::sptr<IStreamOperatorCallback> streamOperatorCallback = nullptr;
OHOS::sptr<ICameraHostCallback> hostCallback = nullptr;
OHOS::sptr<IStreamOperator> streamOperator = nullptr;
OHOS::sptr<ICameraDeviceCallback> deviceCallback = nullptr;
std::vector<StreamInfo> streamInfos;
std::shared_ptr<StreamInfo> streamInfo = nullptr;
std::shared_ptr<StreamInfo> streamInfoSnapshot = nullptr;
std::shared_ptr<StreamInfo> streamInfoCapture = nullptr;
std::shared_ptr<StreamInfo> streamInfoAnalyze = nullptr;
std::shared_ptr<StreamInfo> streamInfoPre = nullptr;
std::shared_ptr<StreamInfo> streamInfoVideo = nullptr;
std::shared_ptr<CaptureInfo> captureInfo = nullptr;
int previewFormat = PIXEL_FMT_YCRCB_420_SP;
int videoFormat = PIXEL_FMT_YCRCB_420_SP;
int snapshotFormat = PIXEL_FMT_YCRCB_420_SP;
int analyzeFormat = PIXEL_FMT_YCRCB_420_SP;
int streamIdPreview = 100;
int streamIdCapture = 101;
int captureIdPreview = 2000;
int previewWidth = 1920;
int previewHeight = 1080;
int captureIdCapture = 2010;
int captureIdVideo = 2020;
int streamIdVideo = 102;
int videoHeight = 1080;
int videoWidth = 1920;
int analyzeWidth = 1920;
int analyzeHeight = 1080;
int snapshotWidth = 4160;
int snapshotHeight = 3120;
int streamIdAnalyze = 103;
std::vector<int> captureIds;
std::vector<int> streamIds;
int32_t imageDataSaveSwitch = SWITCH_OFF;
int32_t rc;
bool status;
std::vector<std::string> cameraIds;
std::vector<uint8_t> abilityVec = {};
std::shared_ptr<CameraMetadata> ability = nullptr;
std::vector<StreamIntent> intents;
class StreamConsumer;
std::map<OHOS::Camera::StreamIntent, std::shared_ptr<StreamConsumer>> consumerMap_ = {};
class TestBufferConsumerListener : public OHOS::IBufferConsumerListener {
public:
TestBufferConsumerListener() {}
~TestBufferConsumerListener() {}
void OnBufferAvailable()
{
hasAvailablebuffer = true;
}
bool checkBufferAvailable()
{
if (hasAvailablebuffer) {
hasAvailablebuffer = false;
return true;
}
return false;
}
private:
bool hasAvailablebuffer = false;
};
class StreamConsumer {
public:
void CalculateFps(int64_t timestamp, int32_t streamId);
OHOS::sptr<OHOS::IBufferProducer> CreateProducer(std::function<void(void*, uint32_t)> callback);
OHOS::sptr<BufferProducerSequenceable> CreateProducerSeq(std::function<void(void*, uint32_t)> callback);
void TakeSnapshoe()
{
shotCount_++;
}
void WaitSnapshotEnd()
{
std::cout << "ready to wait" << std::endl;
std::unique_lock<std::mutex> l(l_);
cv_.wait(l, [this]() {return shotCount_ == 0; });
}
~StreamConsumer()
{
running_ = false;
if (consumerThread_ != nullptr) {
consumerThread_->join();
delete consumerThread_;
}
}
public:
std::atomic<uint64_t> shotCount_ = 0;
std::mutex l_;
std::condition_variable cv_;
bool running_ = true;
OHOS::sptr<OHOS::IConsumerSurface> consumer_ = nullptr;
std::thread* consumerThread_ = nullptr;
std::function<void(void*, uint32_t)> callback_ = nullptr;
bool isFirstCalculateFps_ = false;
int timestampCount_ = 0;
int64_t intervalTimestamp_ = 0;
const int64_t ONESECOND_OF_MICROSECOND_UNIT = 1000000000;
int64_t interval_ = ONESECOND_OF_MICROSECOND_UNIT;
};
class DemoCameraDeviceCallback : public ICameraDeviceCallback {
public:
DemoCameraDeviceCallback() = default;
virtual ~DemoCameraDeviceCallback() = default;
int32_t OnError(ErrorType type, int32_t errorMsg) override;
int32_t OnResult(uint64_t timestamp, const std::vector<uint8_t> &result) override;
};
using ResultCallback = std::function<void (uint64_t, const std::shared_ptr<CameraMetadata>)>;
static ResultCallback resultCallback_;
class TestStreamOperatorCallback : public IStreamOperatorCallback {
public:
TestStreamOperatorCallback() = default;
virtual ~TestStreamOperatorCallback() = default;
int32_t OnCaptureStarted(int32_t captureId, const std::vector<int32_t> &streamId) override;
int32_t OnCaptureEnded(int32_t captureId, const std::vector<CaptureEndedInfo> &infos) override;
int32_t OnCaptureError(int32_t captureId, const std::vector<CaptureErrorInfo> &infos) override;
int32_t OnFrameShutter(int32_t captureId, const std::vector<int32_t> &streamIds, uint64_t timestamp) override;
};
class TestCameraHostCallback : public ICameraHostCallback {
public:
TestCameraHostCallback() = default;
virtual ~TestCameraHostCallback() = default;
int32_t OnCameraStatus(const std::string& cameraId, CameraStatus status) override;
int32_t OnFlashlightStatus(const std::string& cameraId, FlashlightStatus status) override;
int32_t OnCameraEvent(const std::string& cameraId, CameraEvent event) override;
};
};
}

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file expected in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "common.h"
class HdiDeviceUtTestAdditional : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp(void);
void TearDown(void);
std::shared_ptr<OHOS::Camera::Test> cameraTest = nullptr;
};

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file expected in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "common.h"
class HdiHostUtTestAdditional : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp(void);
void TearDown(void);
std::shared_ptr<OHOS::Camera::Test> cameraTest = nullptr;
};

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file expected in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "common.h"
class HdiStreamUtTestAdditional : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp(void);
void TearDown(void);
std::shared_ptr<OHOS::Camera::Test> cameraTest = nullptr;
};

View File

@ -0,0 +1,351 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file expected in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "camera_3a_uttest.h"
using namespace OHOS;
using namespace std;
using namespace testing::ext;
using namespace OHOS::Camera;
void Camera3AUtTestAdditional::SetUpTestCase(void) {}
void Camera3AUtTestAdditional::TearDownTestCase(void) {}
void Camera3AUtTestAdditional::SetUp(void)
{
cameraTest = std::make_shared<OHOS::Camera::Test>();
cameraTest->Init();
cameraTest->Open();
}
void Camera3AUtTestAdditional::TearDown(void)
{
cameraTest->Close();
}
/**
* @tc.number: SUB_Driver_Camera_UpdateSettings_0100
* @tc.name: testUpdateSettings001
* @tc.desc: UpdateSettings, OHOS_CONTROL_AE_EXPOSURE_COMPENSATION
*/
HWTEST_F(Camera3AUtTestAdditional, testUpdateSettings001, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraSetting>(100, 200);
int32_t expo = 0xa0;
meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
std::vector<uint8_t> metaVec;
MetadataUtils::ConvertMetadataToVec(meta, metaVec);
cameraTest->rc = cameraTest->cameraDevice->UpdateSettings(metaVec);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number: SUB_Driver_Camera_UpdateSettings_0200
* @tc.name: testUpdateSettings002
* @tc.desc: UpdateSettings, OHOS_CONTROL_FPS_RANGES
*/
HWTEST_F(Camera3AUtTestAdditional, testUpdateSettings002, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
const int32_t FPS_VALUE = 10;
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraSetting>(100, 200);
std::vector<int32_t> fpsRange;
fpsRange.push_back(FPS_VALUE);
fpsRange.push_back(FPS_VALUE);
meta->addEntry(OHOS_CONTROL_FPS_RANGES, fpsRange.data(), fpsRange.size());
std::vector<uint8_t> metaVec;
MetadataUtils::ConvertMetadataToVec(meta, metaVec);
cameraTest->rc = cameraTest->cameraDevice->UpdateSettings(metaVec);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number: SUB_Driver_Camera_UpdateSettings_0300
* @tc.name: testUpdateSettings003
* @tc.desc: UpdateSettings, OHOS_CAMERA_STREAM_ID
*/
HWTEST_F(Camera3AUtTestAdditional, testUpdateSettings003, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraSetting>(100, 200);
const int32_t deviceStreamId = 0;
meta->addEntry(OHOS_CAMERA_STREAM_ID, &deviceStreamId, 1);
std::vector<uint8_t> metaVec;
MetadataUtils::ConvertMetadataToVec(meta, metaVec);
cameraTest->rc = cameraTest->cameraDevice->UpdateSettings(metaVec);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number: SUB_Driver_Camera_UpdateSettings_0400
* @tc.name: testUpdateSettings004
* @tc.desc: UpdateSettings, OHOS_SENSOR_COLOR_CORRECTION_GAINS
*/
HWTEST_F(Camera3AUtTestAdditional, testUpdateSettings004, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraSetting>(100, 200);
int64_t colorGains[4] = {0};
meta->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
std::vector<uint8_t> metaVec;
MetadataUtils::ConvertMetadataToVec(meta, metaVec);
cameraTest->rc = cameraTest->cameraDevice->UpdateSettings(metaVec);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number: SUB_Driver_Camera_UpdateSettings_0500
* @tc.name: testUpdateSettings005
* @tc.desc: UpdateSettings, OHOS_SENSOR_COLOR_CORRECTION_GAINS
*/
HWTEST_F(Camera3AUtTestAdditional, testUpdateSettings005, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraSetting>(100, 200);
int64_t expoTime = 0;
meta->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
std::vector<uint8_t> metaVec;
MetadataUtils::ConvertMetadataToVec(meta, metaVec);
cameraTest->rc = cameraTest->cameraDevice->UpdateSettings(metaVec);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number: SUB_Driver_Camera_UpdateSettings_0600
* @tc.name: testUpdateSettings006
* @tc.desc: UpdateSettings, OHOS_CONTROL_AE_MODE
*/
HWTEST_F(Camera3AUtTestAdditional, testUpdateSettings006, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraSetting>(100, 200);
uint8_t aeMode = OHOS_CAMERA_AE_MODE_ON;
meta->addEntry(OHOS_CONTROL_AE_MODE, &aeMode, 1);
std::vector<uint8_t> metaVec;
MetadataUtils::ConvertMetadataToVec(meta, metaVec);
cameraTest->rc = cameraTest->cameraDevice->UpdateSettings(metaVec);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number: SUB_Driver_Camera_UpdateSettings_0700
* @tc.name: testUpdateSettings007
* @tc.desc: UpdateSettings, OHOS_CONTROL_AWB_MODE
*/
HWTEST_F(Camera3AUtTestAdditional, testUpdateSettings007, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraSetting>(100, 200);
uint8_t awbMode = OHOS_CAMERA_AWB_MODE_AUTO;
meta->addEntry(OHOS_CONTROL_AWB_MODE, &awbMode, 1);
std::vector<uint8_t> metaVec;
MetadataUtils::ConvertMetadataToVec(meta, metaVec);
cameraTest->rc = cameraTest->cameraDevice->UpdateSettings(metaVec);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number: SUB_Driver_Camera_UpdateSettings_0800
* @tc.name: testUpdateSettings008
* @tc.desc: UpdateSettings, OHOS_CONTROL_AE_MODE
*/
HWTEST_F(Camera3AUtTestAdditional, testUpdateSettings008, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraSetting>(100, 200);
uint8_t aeMode = OHOS_CAMERA_AE_MODE_OFF;
meta->addEntry(OHOS_CONTROL_AE_MODE, &aeMode, 1);
std::vector<uint8_t> metaVec;
MetadataUtils::ConvertMetadataToVec(meta, metaVec);
cameraTest->rc = cameraTest->cameraDevice->UpdateSettings(metaVec);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number: SUB_Driver_Camera_UpdateSettings_0900
* @tc.name: testUpdateSettings009
* @tc.desc: UpdateSettings, stability test
*/
HWTEST_F(Camera3AUtTestAdditional, testUpdateSettings009, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraSetting>(100, 200);
int32_t expo = 0xa0;
meta->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &expo, 1);
std::vector<uint8_t> metaVec;
MetadataUtils::ConvertMetadataToVec(meta, metaVec);
for (int i = 0; i < 100; i++) {
cameraTest->rc = cameraTest->cameraDevice->UpdateSettings(metaVec);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number: SUB_Driver_Camera_UpdateSettings_1000
* @tc.name: testUpdateSettings010
* @tc.desc: UpdateSettings, OHOS_CONTROL_AE_MODE
*/
HWTEST_F(Camera3AUtTestAdditional, testUpdateSettings010, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraSetting>(100, 200);
uint8_t aeMode = OHOS_CAMERA_AE_MODE_ON_AUTO_FLASH;
meta->addEntry(OHOS_CONTROL_AE_MODE, &aeMode, 1);
std::vector<uint8_t> metaVec;
MetadataUtils::ConvertMetadataToVec(meta, metaVec);
cameraTest->rc = cameraTest->cameraDevice->UpdateSettings(metaVec);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number: SUB_Driver_Camera_UpdateSettings_1100
* @tc.name: testUpdateSettings011
* @tc.desc: UpdateSettings, OHOS_CONTROL_AE_MODE
*/
HWTEST_F(Camera3AUtTestAdditional, testUpdateSettings011, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraSetting>(100, 200);
uint8_t aeMode = OHOS_CAMERA_AE_MODE_ON_ALWAYS_FLASH;
meta->addEntry(OHOS_CONTROL_AE_MODE, &aeMode, 1);
std::vector<uint8_t> metaVec;
MetadataUtils::ConvertMetadataToVec(meta, metaVec);
cameraTest->rc = cameraTest->cameraDevice->UpdateSettings(metaVec);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number: SUB_Driver_Camera_UpdateSettings_1200
* @tc.name: testUpdateSettings012
* @tc.desc: UpdateSettings, OHOS_CONTROL_AE_MODE
*/
HWTEST_F(Camera3AUtTestAdditional, testUpdateSettings012, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraSetting>(100, 200);
uint8_t aeMode = OHOS_CAMERA_AE_MODE_ON_AUTO_FLASH_REDEYE;
meta->addEntry(OHOS_CONTROL_AE_MODE, &aeMode, 1);
std::vector<uint8_t> metaVec;
MetadataUtils::ConvertMetadataToVec(meta, metaVec);
cameraTest->rc = cameraTest->cameraDevice->UpdateSettings(metaVec);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number: SUB_Driver_Camera_UpdateSettings_1300
* @tc.name: testUpdateSettings013
* @tc.desc: UpdateSettings, OHOS_CONTROL_AE_MODE
*/
HWTEST_F(Camera3AUtTestAdditional, testUpdateSettings013, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, false, true);
std::shared_ptr<CameraMetadata> meta = std::make_shared<CameraSetting>(100, 200);
uint8_t aeMode = OHOS_CAMERA_AE_MODE_ON_EXTERNAL_FLASH;
meta->addEntry(OHOS_CONTROL_AE_MODE, &aeMode, 1);
std::vector<uint8_t> metaVec;
MetadataUtils::ConvertMetadataToVec(meta, metaVec);
cameraTest->rc = cameraTest->cameraDevice->UpdateSettings(metaVec);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}

View File

@ -0,0 +1,441 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file expected in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "common.h"
#include "camera.h"
#include "video_key_info.h"
namespace OHOS::Camera {
Test::ResultCallback Test::resultCallback_ = 0;
uint64_t Test::GetCurrentLocalTimeStamp()
{
std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds> tp =
std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
auto tmp = std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch());
return static_cast<uint64_t>(tmp.count());
}
int32_t Test::DumpImageFile(int streamId, std::string suffix, const void* buffer, int32_t size)
{
if (imageDataSaveSwitch == SWITCH_OFF) {
return 0;
}
if (streamId < 0) {
CAMERA_LOGE("ivalid stream id: %{public}d", streamId);
return -1;
}
char mkdirCmd[PATH_MAX] = {0};
char path[PATH_MAX] = {0};
int ret = sprintf_s(mkdirCmd, sizeof(mkdirCmd) / sizeof(mkdirCmd[0]),
"mkdir -p /data/stream-%d", streamId);
if (ret < 0) {
return -1;
}
system(mkdirCmd);
ret = sprintf_s(path, sizeof(path) / sizeof(path[0]), "data/stream-%d/%lld.%s",
streamId, GetCurrentLocalTimeStamp(), suffix.c_str());
if (ret < 0) {
return -1;
}
int imgFd = open(path, O_RDWR | O_CREAT, 00766);
if (imgFd == -1) {
CAMERA_LOGE("open file failed, errno: %{public}s", strerror(errno));
return -1;
}
ret = write(imgFd, buffer, size);
if (ret == -1) {
CAMERA_LOGE("write file failed, error: %{public}s", strerror(errno));
close(imgFd);
return -1;
}
close(imgFd);
return 0;
}
void Test::Init()
{
if (service == nullptr) {
service = ICameraHost::Get("camera_service", false);
if (service == nullptr) {
CAMERA_LOGI("ICameraHost get failed");
} else {
CAMERA_LOGE("ICameraHost get success");
}
ASSERT_TRUE(service != nullptr);
}
hostCallback = new TestCameraHostCallback();
service->SetCallback(hostCallback);
}
void Test::GetCameraMetadata()
{
rc = service->GetCameraAbility(cameraIds.front(), abilityVec);
if (rc != HDI::Camera::V1_0::NO_ERROR) {
CAMERA_LOGE("GetCameraAbility failed, rc = %{public}d", rc);
}
MetadataUtils::ConvertVecToMetadata(abilityVec, ability);
common_metadata_header_t* data = ability->get();
camera_metadata_item_t entry;
int ret = FindCameraMetadataItem(data, OHOS_CONTROL_AE_AVAILABLE_MODES, &entry);
if (ret == 0) {
CAMERA_LOGI("get OHOS_CONTROL_AE_AVAILABLE_MODES success");
}
}
void Test::Open()
{
if (cameraDevice == nullptr) {
service->GetCameraIds(cameraIds);
if (cameraIds.size() == 0) {
CAMERA_LOGE("camera device list empty");
return;
}
GetCameraMetadata();
deviceCallback = new OHOS::Camera::Test::DemoCameraDeviceCallback();
rc = service->OpenCamera(cameraIds.front(), deviceCallback, cameraDevice);
if (rc != HDI::Camera::V1_0::NO_ERROR || cameraDevice == nullptr) {
CAMERA_LOGE("openCamera failed, rc = %{public}d", rc);
return;
}
CAMERA_LOGI("OpenCamera success");
}
}
void Test::Close()
{
if (cameraDevice != nullptr) {
cameraDevice->Close();
cameraDevice = nullptr;
}
}
void Test::StartStream(std::vector<StreamIntent> intents)
{
streamOperatorCallback = new TestStreamOperatorCallback();
rc = cameraDevice->GetStreamOperator(streamOperatorCallback, streamOperator);
if (rc == HDI::Camera::V1_0::NO_ERROR) {
CAMERA_LOGI("GetStreamOperator success");
} else {
CAMERA_LOGE("GetStreamOperator fail, rc = %{public}d", rc);
}
streamInfoPre = std::make_shared<StreamInfo>();
streamInfoVideo = std::make_shared<StreamInfo>();
streamInfoCapture = std::make_shared<StreamInfo>();
streamInfoAnalyze = std::make_shared<StreamInfo>();
for (auto& intent : intents) {
if (intent == StreamIntent::PREVIEW) {
streamInfoPre->streamId_ = streamIdPreview;
streamInfoPre->width_ = previewWidth;
streamInfoPre->height_ = previewHeight;
streamInfoPre->format_ = previewFormat;
streamInfoPre->dataspace_ = UT_DATA_SIZE;
streamInfoPre->intent_ = intent;
streamInfoPre->tunneledMode_ = UT_TUNNEL_MODE;
std::shared_ptr<StreamConsumer> consumer_pre = std::make_shared<StreamConsumer>();
streamInfoPre->bufferQueue_ = consumer_pre->CreateProducerSeq([this](void* addr, uint32_t size) {
DumpImageFile(streamIdPreview, "yuv", addr, size);
});
streamInfoPre->bufferQueue_->producer_->SetQueueSize(UT_DATA_SIZE);
consumerMap_[intent] = consumer_pre;
streamInfos.push_back(*streamInfoPre);
} else if (intent == StreamIntent::VIDEO) {
streamInfoVideo->streamId_ = streamIdVideo;
streamInfoVideo->width_ = videoWidth;
streamInfoVideo->height_ = videoHeight;
streamInfoVideo->format_ = videoFormat;
streamInfoVideo->dataspace_ = UT_DATA_SIZE;
streamInfoVideo->intent_ = intent;
streamInfoVideo->encodeType_ = ENCODE_TYPE_H265;
streamInfoVideo->tunneledMode_ = UT_TUNNEL_MODE;
std::shared_ptr<StreamConsumer> consumer_video = std::make_shared<StreamConsumer>();
streamInfoVideo->bufferQueue_ = consumer_video->CreateProducerSeq([this](void* addr, uint32_t size) {
DumpImageFile(streamIdPreview, "yuv", addr, size);
});
streamInfoVideo->bufferQueue_->producer_->SetQueueSize(UT_DATA_SIZE);
consumerMap_[intent] = consumer_video;
streamInfos.push_back(*streamInfoVideo);
} else if (intent == StreamIntent::ANALYZE) {
streamInfoAnalyze->streamId_ = streamIdAnalyze;
streamInfoAnalyze->width_ = analyzeWidth;
streamInfoAnalyze->height_ = analyzeHeight;
streamInfoAnalyze->format_ = analyzeFormat;
streamInfoAnalyze->dataspace_ = UT_DATA_SIZE;
streamInfoAnalyze->intent_ = intent;
streamInfoAnalyze->tunneledMode_ = UT_TUNNEL_MODE;
std::shared_ptr<StreamConsumer> consumer_analyze = std::make_shared<StreamConsumer>();
streamInfoAnalyze->bufferQueue_ = consumer_analyze->CreateProducerSeq([this](void* addr, uint32_t size) {
common_metadata_header_t *data = static_cast<common_metadata_header_t *>(addr);
camera_metadata_item_t entry = {};
int ret = FindCameraMetadataItem(data, OHOS_STATISTICS_FACE_IDS, &entry);
if (ret == 0) {
for (size_t i = 0; i < entry.count; i++) {
int id = entry.data.i32[i];
CAMERA_LOGI("Face ids : %{public}d", id);
}
}
ret = FindCameraMetadataItem(data, OHOS_STATISTICS_FACE_RECTANGLES, &entry);
if (ret == 0) {
for (size_t i = 0; i < entry.count; i++) {
int id = entry.data.i32[i];
CAMERA_LOGI("Face rectangles : %{public}d", id);
}
}
});
streamInfoAnalyze->bufferQueue_->producer_->SetQueueSize(UT_DATA_SIZE);
consumerMap_[intent] = consumer_analyze;
streamInfos.push_back(*streamInfoAnalyze);
} else {
streamInfoCapture->streamId_ = streamIdAnalyze;
streamInfoCapture->width_ = analyzeWidth;
streamInfoCapture->height_ = analyzeHeight;
streamInfoCapture->format_ = analyzeFormat;
streamInfoCapture->dataspace_ = UT_DATA_SIZE;
streamInfoCapture->intent_ = intent;
streamInfoCapture->tunneledMode_ = UT_TUNNEL_MODE;
std::shared_ptr<StreamConsumer> consumer_capture = std::make_shared<StreamConsumer>();
streamInfoCapture->bufferQueue_ = consumer_capture->CreateProducerSeq([this](void* addr, uint32_t size) {
DumpImageFile(streamIdPreview, "yuv", addr, size);
});
streamInfoCapture->bufferQueue_->producer_->SetQueueSize(UT_DATA_SIZE);
consumerMap_[intent] = consumer_capture;
streamInfos.push_back(*streamInfoCapture);
}
}
rc = streamOperator->CreateStreams(streamInfos);
EXPECT_EQ(false, rc != HDI::Camera::V1_0::NO_ERROR);
rc = streamOperator->CommitStreams(OperationMode::NORMAL, abilityVec);
EXPECT_EQ(false, rc != HDI::Camera::V1_0::NO_ERROR);
sleep(1);
std::vector<StreamInfo>().swap(streamInfos);
}
void Test::StartCapture(int streamId, int captureId, bool shutterCallback, bool isStreaming)
{
captureInfo = std::make_shared<CaptureInfo>();
captureInfo->streamIds_ = {streamId};
captureInfo->captureSetting_ = abilityVec;
captureInfo->enableShutterCallback_ = shutterCallback;
rc = (CamRetCode)streamOperator->Capture(captureId, *captureInfo, isStreaming);
EXPECT_EQ(true, rc == HDI::Camera::V1_0::NO_ERROR);
if (rc == HDI::Camera::V1_0::NO_ERROR) {
CAMERA_LOGI("check Capture: Capture success, %{public}d", captureId);
} else {
std::cout << "rc = " << rc << std::endl;
CAMERA_LOGE("check Capture: Capture fail, rc = %{public}d", rc);
}
sleep(UT_SLEEP_TIME);
}
void Test::StopStream(std::vector<int>& captureIds, std::vector<int>& streamIds)
{
if (sizeof(captureIds) > 0) {
for (auto &captureId : captureIds) {
rc = streamOperator->CancelCapture(captureId);
EXPECT_EQ(true, rc == HDI::Camera::V1_0::NO_ERROR);
if (rc == HDI::Camera::V1_0::NO_ERROR) {
CAMERA_LOGI("check Capture: CancelCapture success, %{public}d", captureId);
} else {
CAMERA_LOGE("check Capture: CancelCapture fail, rc = %{public}d, captureId = %{public}d",
rc, captureId);
}
}
}
if (sizeof(streamIds) > 0) {
rc = streamOperator->ReleaseStreams(streamIds);
EXPECT_EQ(true, rc == HDI::Camera::V1_0::NO_ERROR);
if (rc == HDI::Camera::V1_0::NO_ERROR) {
CAMERA_LOGI("check Capture: ReleaseStream success");
} else {
CAMERA_LOGE("check Capture: ReleaseStreams fail, rc = %{public}d", rc);
}
}
}
void Test::StreamConsumer::CalculateFps(int64_t timestamp, int32_t streamId)
{
if (isFirstCalculateFps_) {
if ((timestamp - intervalTimestamp_) >= interval_) {
int64_t timeInterval = timestamp - intervalTimestamp_;
if (timeInterval != 0) {
float fps = (int64_t)(100000000000 * timestampCount_ / timeInterval) / 100.0;
CAMERA_LOGI("Calculate FPS success, streamId: %{public}d, Fps:%{public}f", streamId, fps);
interval_ = ONESECOND_OF_MICROSECOND_UNIT;
} else {
CAMERA_LOGE("Calculate FPS error timeInerval is 0");
}
}
} else {
intervalTimestamp_ = timestamp;
isFirstCalculateFps_ = true;
}
if ((timestamp - intervalTimestamp_) >= ONESECOND_OF_MICROSECOND_UNIT * UT_SECOND_TIMES) {
intervalTimestamp_ = timestamp;
timestampCount_ = 0;
interval_ = ONESECOND_OF_MICROSECOND_UNIT;
}
timestampCount_++;
}
OHOS::sptr<OHOS::IBufferProducer> Test::StreamConsumer::CreateProducer(std::function<void(void*, uint32_t)> callback)
{
consumer_ = OHOS::IConsumerSurface::Create();
if (consumer_ == nullptr) {
return nullptr;
}
sptr<IBufferConsumerListener> listener = new TestBufferConsumerListener();
consumer_->RegisterConsumerListener(listener);
auto producer = consumer_->GetProducer();
if (producer == nullptr) {
return nullptr;
}
callback_ = callback;
consumerThread_ = new std::thread([this, listener] {
int32_t flushFence = 0;
int64_t timestamp = 0;
OHOS::Rect damage;
TestBufferConsumerListener* checker = static_cast<TestBufferConsumerListener*>(listener.GetRefPtr());
while (running_ == true) {
OHOS::sptr<OHOS::SurfaceBuffer> buffer = nullptr;
if (checker->checkBufferAvailable()) {
consumer_->AcquireBuffer(buffer, flushFence, timestamp, damage);
if (buffer != nullptr) {
void* addr = buffer->GetVirAddr();
uint32_t size = buffer->GetSize();
int32_t gotSize = 0;
int32_t isKey = 0;
int32_t streamId = 0;
int32_t captureId = 0;
buffer->GetExtraData()->ExtraGet(OHOS::Camera::dataSize, gotSize);
buffer->GetExtraData()->ExtraGet(OHOS::Camera::isKeyFrame, isKey);
buffer->GetExtraData()->ExtraGet(OHOS::Camera::timeStamp, timestamp);
buffer->GetExtraData()->ExtraGet(OHOS::Camera::streamId, streamId);
buffer->GetExtraData()->ExtraGet(OHOS::Camera::captureId, captureId);
if (gotSize) {
CalculateFps(timestamp, streamId);
callback_(addr, gotSize);
} else {
callback_(addr, size);
}
consumer_->ReleaseBuffer(buffer, -1);
shotCount_--;
if (shotCount_ == 0) {
std::unique_lock<std::mutex> l(l_);
cv_.notify_one();
}
}
}
if (running_ == false) {
break;
}
usleep(1);
}
});
return producer;
}
OHOS::sptr<BufferProducerSequenceable> Test::StreamConsumer::CreateProducerSeq(
std::function<void(void*, uint32_t)> callback)
{
OHOS::sptr<OHOS::IBufferProducer> producer = CreateProducer(callback);
if (producer == nullptr) {
return nullptr;
}
return new BufferProducerSequenceable(producer);
}
int32_t Test::TestStreamOperatorCallback::OnCaptureStarted(int32_t captureId, const std::vector<int32_t> &streamId)
{
for (auto it : streamId) {
CAMERA_LOGE("captureId: %{public}d, streamId: %{public}d", captureId, it);
}
return HDI::Camera::V1_0::NO_ERROR;
}
int32_t Test::TestStreamOperatorCallback::OnCaptureEnded(int32_t captureId, const std::vector<CaptureEndedInfo> &infos)
{
for (auto it : infos) {
CAMERA_LOGE("captureId: %{public}d, streamId: %{public}d, count: %{public}d", captureId, it.streamId_,
it.frameCount_);
}
return HDI::Camera::V1_0::NO_ERROR;
}
int32_t Test::TestStreamOperatorCallback::OnCaptureError(int32_t captureId, const std::vector<CaptureErrorInfo> &infos)
{
for (auto it : infos) {
CAMERA_LOGE("captureId: %{public}d, streamId: %{public}d, error: %{public}d", captureId, it.streamId_,
it.error_);
}
return HDI::Camera::V1_0::NO_ERROR;
}
int32_t Test::TestStreamOperatorCallback::OnFrameShutter(int32_t captureId,
const std::vector<int32_t> &streamIds, uint64_t timestamp)
{
(void)timestamp;
for (auto it : streamIds) {
CAMERA_LOGE("captureId: %{public}d, streamId: %{public}d", captureId, it);
}
return HDI::Camera::V1_0::NO_ERROR;
}
int32_t Test::DemoCameraDeviceCallback::OnError(ErrorType type, int32_t errorMsg)
{
CAMERA_LOGE("type: %{public}d, errorMsg: %{public}d", type, errorMsg);
return HDI::Camera::V1_0::NO_ERROR;
}
int32_t Test::DemoCameraDeviceCallback::OnResult(uint64_t timestamp, const std::vector<uint8_t> &result)
{
if (Test::resultCallback_) {
std::shared_ptr<CameraMetadata> resultMeta;
MetadataUtils::ConvertVecToMetadata(result, resultMeta);
Test::resultCallback_(timestamp, resultMeta);
}
return HDI::Camera::V1_0::NO_ERROR;
}
int32_t Test::TestCameraHostCallback::OnCameraStatus(const std::string& cameraId, CameraStatus status)
{
CAMERA_LOGE("cameraId: %{public}s, status: %{public}d", cameraId.c_str(), status);
return HDI::Camera::V1_0::NO_ERROR;
}
int32_t Test::TestCameraHostCallback::OnFlashlightStatus(const std::string& cameraId, FlashlightStatus status)
{
CAMERA_LOGE("cameraId: %{public}s, status: %{public}d", cameraId.c_str(), status);
return HDI::Camera::V1_0::NO_ERROR;
}
int32_t Test::TestCameraHostCallback::OnCameraEvent(const std::string& cameraId, CameraEvent event)
{
CAMERA_LOGE("cameraId: %{public}s, status: %{public}d", cameraId.c_str(), event);
return HDI::Camera::V1_0::NO_ERROR;
}
}

View File

@ -0,0 +1,133 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file expected in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "hdi_device_uttest.h"
using namespace OHOS;
using namespace std;
using namespace testing::ext;
using namespace OHOS::Camera;
void HdiDeviceUtTestAdditional::SetUpTestCase(void) {}
void HdiDeviceUtTestAdditional::TearDownTestCase(void) {}
void HdiDeviceUtTestAdditional::SetUp(void)
{
cameraTest = std::make_shared<OHOS::Camera::Test>();
cameraTest->Init();
}
void HdiDeviceUtTestAdditional::TearDown(void)
{
cameraTest->Close();
}
/**
* @tc.number: SUB_Driver_Camera_GetStreamOperator_0100
* @tc.name: testGetStreamOperator001
* @tc.desc: GetStreamOperator, stability test
*/
HWTEST_F(HdiDeviceUtTestAdditional, testGetStreamOperator001, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
for (int i = 0; i < 100; i++) {
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
}
/**
* @tc.number: SUB_Driver_Camera_SetResultMode_0100
* @tc.name: testSetResultMode001
* @tc.desc: SetResultMode stability test
*/
HWTEST_F(HdiDeviceUtTestAdditional, testSetResultMode001, Function | MediumTest | Level1)
{
cameraTest->Open();
EXPECT_EQ(true, cameraTest->cameraDevice != nullptr);
std::vector<MetaType> enableTypes;
cameraTest->rc = cameraTest->cameraDevice->GetEnabledResults(enableTypes);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
for (auto &type : enableTypes) {
CAMERA_LOGE("check hdi_device: type = %{public}d", type);
}
for (int i = 0; i < 100; i++) {
cameraTest->rc = cameraTest->cameraDevice->SetResultMode(PER_FRAME);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
}
/**
* @tc.number: SUB_Driver_Camera_GetEnabledResults_0100
* @tc.name: testGetEnabledResults001
* @tc.desc: GetEnabledResults return NO_ERROR
*/
HWTEST_F(HdiDeviceUtTestAdditional, testGetEnabledResults001, Function | MediumTest | Level1)
{
cameraTest->Open();
EXPECT_EQ(true, cameraTest->cameraDevice != nullptr);
std::vector<MetaType> enableTypes;
cameraTest->rc = cameraTest->cameraDevice->GetEnabledResults(enableTypes);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
/**
* @tc.number: SUB_Driver_Camera_GetEnabledResults_0200
* @tc.name: testGetEnabledResults002
* @tc.desc: GetEnabledResults stability test
*/
HWTEST_F(HdiDeviceUtTestAdditional, testGetEnabledResults002, Function | MediumTest | Level1)
{
cameraTest->Open();
EXPECT_EQ(true, cameraTest->cameraDevice != nullptr);
std::vector<MetaType> enableTypes;
for (int i = 0; i < 100; i++) {
cameraTest->rc = cameraTest->cameraDevice->GetEnabledResults(enableTypes);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
}
/**
* @tc.number: SUB_Driver_Camera_EnableResult_0100
* @tc.name: testEnableResult001
* @tc.desc: EnableResult, stability test
*/
HWTEST_F(HdiDeviceUtTestAdditional, testEnableResult001, Function | MediumTest | Level1)
{
cameraTest->Open();
std::vector<int32_t> resultsList;
resultsList.push_back(OHOS_CAMERA_STREAM_ID);
resultsList.push_back(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION);
for (int i = 0; i < 100; i++) {
cameraTest->rc = cameraTest->cameraDevice->EnableResult(resultsList);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
}
/**
* @tc.number: SUB_Driver_Camera_DisableResult_0100
* @tc.name: testDisableResult001
* @tc.desc: DisableResult, stability test
*/
HWTEST_F(HdiDeviceUtTestAdditional, testDisableResult001, Function | MediumTest | Level1)
{
cameraTest->Open();
std::vector<OHOS::Camera::MetaType> resultsOriginal;
for (int i = 0; i < 100; i++) {
cameraTest->cameraDevice->DisableResult(resultsOriginal);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
}

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file expected in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "hdi_host_uttest.h"
using namespace OHOS;
using namespace std;
using namespace testing::ext;
using namespace OHOS::Camera;
void HdiHostUtTestAdditional::SetUpTestCase(void) {}
void HdiHostUtTestAdditional::TearDownTestCase(void) {}
void HdiHostUtTestAdditional::SetUp(void)
{
cameraTest = std::make_shared<OHOS::Camera::Test>();
cameraTest->Init();
}
void HdiHostUtTestAdditional::TearDown(void)
{
cameraTest->Close();
}
/**
* @tc.number: SUB_Driver_Camera_GetCameraIds_0100
* @tc.name: testGetCameraIds001
* @tc.desc: GetCameraIds stability test
*/
HWTEST_F(HdiHostUtTestAdditional, testGetCameraIds001, Function | MediumTest | Level1)
{
EXPECT_EQ(true, cameraTest->cameraDevice == nullptr);
if (cameraTest->cameraDevice == nullptr) {
for (int i = 0; i < 100; i++) {
cameraTest->rc = cameraTest->service->GetCameraIds(cameraTest->cameraIds);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
EXPECT_LT(0, cameraTest->cameraIds.size());
CAMERA_LOGE("check hdi_host: cameraIds.size() = %{public}zu", cameraTest->cameraIds.size());
}
}
}

View File

@ -0,0 +1,785 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file expected in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "hdi_stream_uttest.h"
using namespace OHOS;
using namespace std;
using namespace testing::ext;
using namespace OHOS::Camera;
void HdiStreamUtTestAdditional::SetUpTestCase(void) {}
void HdiStreamUtTestAdditional::TearDownTestCase(void) {}
void HdiStreamUtTestAdditional::SetUp(void)
{
cameraTest = std::make_shared<OHOS::Camera::Test>();
cameraTest->Init();
}
void HdiStreamUtTestAdditional::TearDown(void)
{
cameraTest->Close();
}
/**
* @tc.number : SUB_Driver_Camera_CancelCapture_0100
* @tc.name : testCancelCapture001
* @tc.desc : CancelCapture captureId = 0, return error
*/
HWTEST_F(HdiStreamUtTestAdditional, testCancelCapture001, Function | MediumTest | Level2)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, true, true);
cameraTest->rc = cameraTest->streamOperator->CancelCapture(0);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::INVALID_ARGUMENT);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number : SUB_Driver_Camera_CancelCapture_0200
* @tc.name : testCancelCapture002
* @tc.desc : CancelCapture captureId = 2147483647, return error
*/
HWTEST_F(HdiStreamUtTestAdditional, testCancelCapture002, Function | MediumTest | Level2)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, true, true);
cameraTest->rc = cameraTest->streamOperator->CancelCapture(2147483647);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::INVALID_ARGUMENT);
cameraTest->captureIds = {cameraTest->captureIdPreview};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number : SUB_Driver_Camera_CancelCapture_0300
* @tc.name : testCancelCapture003
* @tc.desc : Do not create stream, call the CancelCapture function directly, return error
*/
HWTEST_F(HdiStreamUtTestAdditional, testCancelCapture003, Function | MediumTest | Level2)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
int captureId = 10;
cameraTest->rc = cameraTest->streamOperator->CancelCapture(captureId);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::INVALID_ARGUMENT);
cameraTest->captureIds = {};
cameraTest->streamIds = {cameraTest->streamIdPreview};
cameraTest->StopStream(cameraTest->captureIds, cameraTest->streamIds);
}
/**
* @tc.number : SUB_Driver_Camera_CancelCapture_0400
* @tc.name : testCancelCapture004
* @tc.desc : CancelCapture stability test, return success
*/
HWTEST_F(HdiStreamUtTestAdditional, testCancelCapture004, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
cameraTest->StartStream(cameraTest->intents);
for (int i = 0; i < 10; i++) {
cameraTest->StartCapture(cameraTest->streamIdPreview, cameraTest->captureIdPreview, true, true);
cameraTest->rc = cameraTest->streamOperator->CancelCapture(cameraTest->captureIdPreview);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
cameraTest->rc = cameraTest->streamOperator->ReleaseStreams({cameraTest->streamIdPreview});
}
/**
* @tc.number : SUB_Driver_Camera_ReleaseStreams_0100
* @tc.name : testReleaseStreams001
* @tc.desc : Do not create stream, call the ReleaseStreams function directly, return success
*/
HWTEST_F(HdiStreamUtTestAdditional, testReleaseStreams001, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(false, cameraTest->rc != HDI::Camera::V1_0::NO_ERROR || cameraTest->streamOperator == nullptr);
cameraTest->rc = cameraTest->streamOperator->ReleaseStreams({100});
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
/**
* @tc.number : SUB_Driver_Camera_ReleaseStreams_0200
* @tc.name : testReleaseStreams002
* @tc.desc : ReleaseStreams stability test, return success
*/
HWTEST_F(HdiStreamUtTestAdditional, testReleaseStreams002, Function | MediumTest | Level1)
{
cameraTest->Open();
cameraTest->intents = {PREVIEW};
for (int i = 0; i < 10; i++) {
cameraTest->StartStream(cameraTest->intents);
cameraTest->rc = cameraTest->streamOperator->ReleaseStreams({cameraTest->streamIdPreview});
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_0100
* @tc.name : testIsStreamsSupported001
* @tc.desc : IsStreamsSupported, StreamInfo->streamId = -1, return error
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported001, Function | MediumTest | Level2)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(2, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = -1;
cameraTest->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
cameraTest->streamInfo->height_ = 480;
cameraTest->streamInfo->width_ = 640;
cameraTest->streamInfo->dataspace_ = 8;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = PREVIEW;
cameraTest->streamInfo->tunneledMode_ = 5;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::INVALID_ARGUMENT);
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_0200
* @tc.name : testIsStreamsSupported002
* @tc.desc : IsStreamsSupported, StreamInfo->streamId = 2147483647, return success
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported002, Function | MediumTest | Level1)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(2, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = 2147483647;
cameraTest->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
cameraTest->streamInfo->height_ = 480;
cameraTest->streamInfo->width_ = 640;
cameraTest->streamInfo->dataspace_ = 8;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = PREVIEW;
cameraTest->streamInfo->tunneledMode_ = 5;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_0300
* @tc.name : testIsStreamsSupported003
* @tc.desc : IsStreamsSupported, StreamInfo->format = -1, return error
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported003, Function | MediumTest | Level2)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(2, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = 101;
cameraTest->streamInfo->format_ = -1;
cameraTest->streamInfo->height_ = 480;
cameraTest->streamInfo->width_ = 640;
cameraTest->streamInfo->dataspace_ = 8;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = PREVIEW;
cameraTest->streamInfo->tunneledMode_ = 5;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::INVALID_ARGUMENT);
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_0400
* @tc.name : testIsStreamsSupported004
* @tc.desc : IsStreamsSupported, StreamInfo->format = 2147483647, return success
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported004, Function | MediumTest | Level1)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(2, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = 101;
cameraTest->streamInfo->format_ = 2147483647;
cameraTest->streamInfo->height_ = 480;
cameraTest->streamInfo->width_ = 640;
cameraTest->streamInfo->dataspace_ = 8;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = PREVIEW;
cameraTest->streamInfo->tunneledMode_ = 5;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_0500
* @tc.name : testIsStreamsSupported005
* @tc.desc : IsStreamsSupported, StreamInfo->width = -1, return error
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported005, Function | MediumTest | Level2)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(2, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = 101;
cameraTest->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
cameraTest->streamInfo->height_ = 480;
cameraTest->streamInfo->width_ = -1;
cameraTest->streamInfo->dataspace_ = 8;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = PREVIEW;
cameraTest->streamInfo->tunneledMode_ = 5;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::INVALID_ARGUMENT);
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_0600
* @tc.name : testIsStreamsSupported006
* @tc.desc : IsStreamsSupported, StreamInfo->width = 2147483647, return success
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported006, Function | MediumTest | Level1)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(2, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = 101;
cameraTest->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
cameraTest->streamInfo->height_ = 480;
cameraTest->streamInfo->width_ = 2147483647;
cameraTest->streamInfo->dataspace_ = 8;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = PREVIEW;
cameraTest->streamInfo->tunneledMode_ = 5;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_0700
* @tc.name : testIsStreamsSupported007
* @tc.desc : IsStreamsSupported, StreamInfo->height = -1, return error
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported007, Function | MediumTest | Level2)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(2, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = 101;
cameraTest->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
cameraTest->streamInfo->height_ = -1;
cameraTest->streamInfo->width_ = 640;
cameraTest->streamInfo->dataspace_ = 8;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = PREVIEW;
cameraTest->streamInfo->tunneledMode_ = 5;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::INVALID_ARGUMENT);
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_0800
* @tc.name : testIsStreamsSupported008
* @tc.desc : IsStreamsSupported, StreamInfo->height = 2147483647, return success
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported008, Function | MediumTest | Level1)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(2, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = 101;
cameraTest->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
cameraTest->streamInfo->height_ = 2147483647;
cameraTest->streamInfo->width_ = 640;
cameraTest->streamInfo->dataspace_ = 8;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = PREVIEW;
cameraTest->streamInfo->tunneledMode_ = 5;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_0900
* @tc.name : testIsStreamsSupported009
* @tc.desc : IsStreamsSupported, Add AWB in modeSetting, return success
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported009, Function | MediumTest | Level1)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(100, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
uint8_t awbMode = OHOS_CAMERA_AWB_MODE_AUTO;
modeSetting->addEntry(OHOS_CONTROL_AWB_MODE, &awbMode, 1);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = 101;
cameraTest->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
cameraTest->streamInfo->height_ = 2147483647;
cameraTest->streamInfo->width_ = 640;
cameraTest->streamInfo->dataspace_ = 8;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = PREVIEW;
cameraTest->streamInfo->tunneledMode_ = 5;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_1000
* @tc.name : testIsStreamsSupported010
* @tc.desc : IsStreamsSupported, StreamInfo->dataspace = -1, return error
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported010, Function | MediumTest | Level2)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(2, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = 101;
cameraTest->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
cameraTest->streamInfo->height_ = 480;
cameraTest->streamInfo->width_ = 640;
cameraTest->streamInfo->dataspace_ = -1;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = PREVIEW;
cameraTest->streamInfo->tunneledMode_ = 5;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::INVALID_ARGUMENT);
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_1100
* @tc.name : testIsStreamsSupported011
* @tc.desc : IsStreamsSupported, StreamInfo->dataspace = 2147483647, return success
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported011, Function | MediumTest | Level1)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(2, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = 101;
cameraTest->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
cameraTest->streamInfo->height_ = 480;
cameraTest->streamInfo->width_ = 640;
cameraTest->streamInfo->dataspace_ = 2147483647;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = PREVIEW;
cameraTest->streamInfo->tunneledMode_ = 5;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_1200
* @tc.name : testIsStreamsSupported012
* @tc.desc : IsStreamsSupported, StreamInfo->intent = VIDEO, return success
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported012, Function | MediumTest | Level1)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(2, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = 101;
cameraTest->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
cameraTest->streamInfo->height_ = 480;
cameraTest->streamInfo->width_ = 640;
cameraTest->streamInfo->dataspace_ = 8;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = VIDEO;
cameraTest->streamInfo->tunneledMode_ = 5;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_1300
* @tc.name : testIsStreamsSupported013
* @tc.desc : IsStreamsSupported, stability test, return success
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported013, Function | MediumTest | Level1)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(2, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = 101;
cameraTest->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
cameraTest->streamInfo->height_ = 480;
cameraTest->streamInfo->width_ = 640;
cameraTest->streamInfo->dataspace_ = 8;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = PREVIEW;
cameraTest->streamInfo->tunneledMode_ = 5;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
for (int i = 0; i < 1000; i++) {
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}
}
/**
* @tc.number : SUB_Driver_Camera_IsStreamsSupported_1400
* @tc.name : testIsStreamsSupported014
* @tc.desc : IsStreamsSupported, StreamInfo->tunneledMode = 0, return success
*/
HWTEST_F(HdiStreamUtTestAdditional, testIsStreamsSupported014, Function | MediumTest | Level1)
{
cameraTest->Open();
EXPECT_EQ(false, cameraTest->cameraDevice == nullptr);
cameraTest->streamOperatorCallback = new OHOS::Camera::Test::TestStreamOperatorCallback();
cameraTest->rc = cameraTest->cameraDevice->GetStreamOperator(cameraTest->streamOperatorCallback,
cameraTest->streamOperator);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
std::shared_ptr<CameraMetadata> modeSetting = std::make_shared<CameraMetadata>(2, 128);
int64_t expoTime = 0;
modeSetting->addEntry(OHOS_SENSOR_EXPOSURE_TIME, &expoTime, 1);
int64_t colorGains[4] = {0};
modeSetting->addEntry(OHOS_SENSOR_COLOR_CORRECTION_GAINS, &colorGains, 4);
cameraTest->streamInfo = std::make_shared<StreamInfo>();
cameraTest->streamInfo->streamId_ = 101;
cameraTest->streamInfo->format_ = PIXEL_FMT_YCRCB_420_SP;
cameraTest->streamInfo->height_ = 480;
cameraTest->streamInfo->width_ = 640;
cameraTest->streamInfo->dataspace_ = 8;
std::shared_ptr<OHOS::Camera::Test::StreamConsumer> consumer =
std::make_shared<OHOS::Camera::Test::StreamConsumer>();
cameraTest->streamInfo->bufferQueue_ = consumer->CreateProducerSeq([this](void* addr, uint32_t size) {
cameraTest->DumpImageFile(cameraTest->streamIdPreview, "yuv", addr, size);
});
cameraTest->streamInfo->bufferQueue_->producer_->SetQueueSize(8);
cameraTest->consumerMap_[cameraTest->streamInfo->intent_] = consumer;
cameraTest->streamInfo->intent_ = PREVIEW;
cameraTest->streamInfo->tunneledMode_ = 0;
StreamSupportType pType;
std::vector<StreamInfo> streams;
streams.push_back(*cameraTest->streamInfo);
std::vector<uint8_t> modeSettingVec;
MetadataUtils::ConvertMetadataToVec(modeSetting, modeSettingVec);
cameraTest->rc = cameraTest->streamOperator->IsStreamsSupported(OperationMode::NORMAL, modeSettingVec,
streams, pType);
EXPECT_EQ(cameraTest->rc, HDI::Camera::V1_0::NO_ERROR);
}

View File

@ -22,8 +22,11 @@ group("HatsHdfCodecTest") {
deps = [
#"benchmarktest:HatsHdfCodecBenchmarkTest",
"hdi_adapter:HatsHdfAdapterCodecTest",
"hdi_adapter_additional:HatsHdfAdapterCodecTestAdditional",
"hdi_image:HatsHdfImageCodecTest",
"hdi_image_additional:HatsHdfImageCodecTestAdditional",
"hdi_omx:HatsHdfOmxCodecTest",
"hdi_omx_additional:HatsHdfOmxCodecTestAdditional",
"hdi_v1.0:HatsHdfV1CodecTest",
]
} else {

View File

@ -0,0 +1,43 @@
# Copyright (c) 2022 - 2023 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
import("//test/xts/tools/build/suite.gni")
module_output_path = "hats/codec"
ohos_moduletest_suite("HatsHdfAdapterCodecTestAdditional") {
module_out_path = module_output_path
configs = [ ":hdc_codec_adapter_additional" ]
sources = [ "codec_hdi_adapter_test.cpp" ]
deps = [ "//third_party/googletest:gtest_main" ]
if (is_standard_system) {
external_deps = [
"c_utils:utils",
"drivers_peripheral_codec:libcodec_hdi_passthrough_impl",
"hdf_core:libhdf_utils",
"hdf_core:libhdi",
"hilog:libhilog",
]
} else {
external_deps = [ "hilog:libhilog" ]
}
subsystem_name = "xts"
part_name = "hats"
}
config("hdc_codec_adapter_additional") {
include_dirs = [ "//third_party/openmax/api/1.1.2" ]
}

View File

@ -0,0 +1,18 @@
{
"kits": [
{
"push": [
"HatsHdfAdapterCodecTestAdditional->/data/local/tmp/HatsHdfAdapterCodecTestAdditional"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "HatsHdfAdapterCodecTestAdditional",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for HatsHdfAdapterCodecTestAdditional Tests"
}

View File

@ -0,0 +1,519 @@
/*
* Copyright (c) 2022-2023 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <OMX_Component.h>
#include <OMX_Core.h>
#include <OMX_Video.h>
#include <OMX_VideoExt.h>
#include <ashmem.h>
#include <gtest/gtest.h>
#include <hdf_log.h>
#include <osal_mem.h>
#include <securec.h>
#include <servmgr_hdi.h>
#include "codec_component_manager.h"
#include "codec_component_type.h"
#include "hdf_io_service_if.h"
#include "codec_omx_ext.h"
#define HDF_LOG_TAG codec_hdi_test
using namespace std;
using namespace testing::ext;
namespace {
struct CodecComponentManager *g_manager = nullptr;
struct CodecComponentType *g_component = nullptr;
struct CodecCallbackType *g_callback = nullptr;
static inline std::string g_compName = "";
uint32_t g_componentId = 0;
union OMX_VERSIONTYPE g_version;
template <typename T>
void InitParam(T &param)
{
memset_s(&param, sizeof(param), 0x0, sizeof(param));
param.nSize = sizeof(param);
param.nVersion = g_version;
}
class CodecHdiAdapterTestAdditional : public testing::Test {
public:
static void SetUpTestCase()
{
g_manager = GetCodecComponentManager();
if (g_manager == nullptr) {
std::cout<<"GetCodecComponentManager ret nullptr"<<std::endl;
return;
}
auto count = g_manager->GetComponentNum();
if (count > 0) {
CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count);
ASSERT_TRUE(capList != nullptr);
auto err = g_manager->GetComponentCapabilityList(capList, count);
ASSERT_TRUE(err == HDF_SUCCESS);
g_compName = capList[0].compName;
OsalMemFree(capList);
capList = nullptr;
}
}
static void TearDownTestCase()
{
CodecComponentManagerRelease();
g_manager = nullptr;
}
void SetUp()
{
if (g_manager == nullptr) {
return;
}
g_callback = CodecCallbackTypeGet(nullptr);
if (g_callback == nullptr) {
return;
}
if (g_compName.empty()) {
return;
}
auto ret = g_manager->CreateComponent(&g_component, &g_componentId, g_compName.data(),
reinterpret_cast<int64_t>(this), g_callback);
if (ret != HDF_SUCCESS) {
return;
}
struct CompVerInfo verInfo;
ret = g_component->GetComponentVersion(g_component, &verInfo);
if (ret != HDF_SUCCESS) {
return;
}
g_version = verInfo.compVersion;
}
void TearDown()
{
if (g_manager != nullptr && g_component != nullptr) {
g_manager->DestroyComponent(g_componentId);
}
if (g_callback != nullptr) {
CodecCallbackTypeRelease(g_callback);
g_callback = nullptr;
}
}
};
/**
* @tc.number SUB_Driver_Codec_Adapter_6400
* @tc.name testAdapter001
* @tc.desc The first input parameter is empty. GetComponentVersion is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter001, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
struct CompVerInfo verInfo;
auto ret = g_component->GetComponentVersion(nullptr, &verInfo);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_6500
* @tc.name testAdapter002
* @tc.desc The second input parameter is empty. GetComponentVersion is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter002, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
auto ret = g_component->GetComponentVersion(g_component, nullptr);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_6600
* @tc.name testAdapter003
* @tc.desc The second and third parameters are OMX_CommandStateSet and OMX_StateInvalid. SendCommand is successful.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter003, Function | MediumTest | Level1)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateInvalid, nullptr, 0);
ASSERT_EQ(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_6700
* @tc.name testAdapter004
* @tc.desc The second and third parameters are OMX_CommandStateSet and OMX_StateLoaded. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter004, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateLoaded, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_6800
* @tc.name testAdapter005
* @tc.desc The second and third parameters are OMX_CommandStateSet and OMX_StateWaitForResources.
* SendCommand is successful.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter005, Function | MediumTest | Level1)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateWaitForResources, nullptr, 0);
ASSERT_EQ(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_6900
* @tc.name testAdapter006
* @tc.desc The second and third parameters are OMX_CommandStateSet and OMX_StateKhronosExtensions.
* SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter006, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateKhronosExtensions, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_7000
* @tc.name testAdapter007
* @tc.desc The second and third parameters are OMX_CommandStateSet and OMX_StateVendorStartUnused.
* SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter007, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateVendorStartUnused, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_7100
* @tc.name testAdapter008
* @tc.desc The second and third parameters are OMX_CommandStateSet and -1. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter008, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, -1, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_7200
* @tc.name testAdapter009
* @tc.desc The second and third parameters are OMX_CommandStateSet and OMX_StateMax. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter009, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateMax, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_7300
* @tc.name testAdapter010
* @tc.desc The second and third parameters are OMX_CommandPortEnable and OMX_StateInvalid. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter010, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortEnable, OMX_StateInvalid, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_7400
* @tc.name testAdapter011
* @tc.desc The second and third parameters are OMX_CommandPortEnable and OMX_StateLoaded. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter011, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortEnable, OMX_StateLoaded, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_7500
* @tc.name testAdapter012
* @tc.desc The second and third parameters are OMX_CommandPortEnable and OMX_StateIdle. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter012, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortEnable, OMX_StateIdle, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_7600
* @tc.name testAdapter013
* @tc.desc The second and third parameters are OMX_CommandFlush and OMX_StateExecuting. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter013, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandFlush, OMX_StateExecuting, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_7700
* @tc.name testAdapter014
* @tc.desc The second and third parameters are OMX_CommandFlush and OMX_StateWaitForResources. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter014, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandFlush, OMX_StateWaitForResources, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_7800
* @tc.name testAdapter015
* @tc.desc The second and third parameters are OMX_CommandFlush and OMX_StateKhronosExtensions. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter015, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandFlush, OMX_StateKhronosExtensions, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_7900
* @tc.name testAdapter016
* @tc.desc The second and third parameters are OMX_CommandFlush and OMX_StateVendorStartUnused. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter016, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandFlush, OMX_StateVendorStartUnused, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_8000
* @tc.name testAdapter017
* @tc.desc The second and third parameters are OMX_CommandFlush and -1. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter017, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandFlush, -1, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_8100
* @tc.name testAdapter018
* @tc.desc The second and third parameters are OMX_CommandFlush and OMX_StateMax. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter018, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandFlush, OMX_StateMax, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_8200
* @tc.name testAdapter019
* @tc.desc The second and third parameters are OMX_CommandPortDisable and OMX_StateInvalid. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter019, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortDisable, OMX_StateInvalid, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_8300
* @tc.name testAdapter020
* @tc.desc The second and third parameters are OMX_CommandPortDisable and OMX_StateLoaded. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter020, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortDisable, OMX_StateLoaded, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_8400
* @tc.name testAdapter021
* @tc.desc The second and third parameters are OMX_CommandPortDisable and OMX_StateIdle. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter021, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortDisable, OMX_StateIdle, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_8500
* @tc.name testAdapter022
* @tc.desc The second and third parameters are OMX_CommandPortDisable and OMX_StateExecuting. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter022, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortDisable, OMX_StateExecuting, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_8600
* @tc.name testAdapter023
* @tc.desc The second and third parameters are OMX_CommandPortDisable and OMX_StateWaitForResources.
* SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter023, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortDisable, OMX_StateWaitForResources, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_8700
* @tc.name testAdapter024
* @tc.desc The second and third parameters are OMX_CommandPortDisable and OMX_StateKhronosExtensions.
* SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter024, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortDisable, OMX_StateKhronosExtensions, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_8800
* @tc.name testAdapter025
* @tc.desc The second and third parameters are OMX_CommandPortDisable and OMX_StateVendorStartUnused.
* SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter025, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortDisable, OMX_StateVendorStartUnused, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_8900
* @tc.name testAdapter026
* @tc.desc The second and third parameters are OMX_CommandPortDisable and -1. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter026, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortDisable, -1, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_9000
* @tc.name testAdapter027
* @tc.desc The second and third parameters are OMX_CommandPortDisable and OMX_StateMax. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter027, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandPortDisable, OMX_StateMax, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_9100
* @tc.name testAdapter028
* @tc.desc The second and third parameters are OMX_CommandMax and OMX_StateInvalid. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter028, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandMax, OMX_StateInvalid, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_9200
* @tc.name testAdapter029
* @tc.desc The second and third parameters are OMX_CommandMax and OMX_StateLoaded. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter029, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandMax, OMX_StateLoaded, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_9300
* @tc.name testAdapter030
* @tc.desc The second and third parameters are OMX_CommandMax and OMX_StateIdle. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter030, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandMax, OMX_StateIdle, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_9400
* @tc.name testAdapter031
* @tc.desc The second and third parameters are OMX_CommandMax and OMX_StateExecuting. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter031, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandMax, OMX_StateExecuting, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_9500
* @tc.name testAdapter032
* @tc.desc The second and third parameters are OMX_CommandMax and OMX_StateWaitForResources. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter032, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandMax, OMX_StateWaitForResources, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_9600
* @tc.name testAdapter033
* @tc.desc The second and third parameters are OMX_CommandMax and OMX_StateKhronosExtensions. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter033, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandMax, OMX_StateKhronosExtensions, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_9700
* @tc.name testAdapter034
* @tc.desc The second and third parameters are OMX_CommandMax and OMX_StateVendorStartUnused. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter034, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandMax, OMX_StateVendorStartUnused, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_9800
* @tc.name testAdapter035
* @tc.desc The second and third parameters are OMX_CommandMax and -1. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter035, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandMax, -1, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_Adapter_9900
* @tc.name testAdapter036
* @tc.desc The second and third parameters are OMX_CommandMax and OMX_StateMax. SendCommand is error.
*/
HWTEST_F(CodecHdiAdapterTestAdditional, testAdapter036, Function | MediumTest | Level2)
{
ASSERT_TRUE(g_component != nullptr);
int32_t ret = g_component->SendCommand(g_component, OMX_CommandMax, OMX_StateMax, nullptr, 0);
ASSERT_NE(ret, HDF_SUCCESS);
}
} // namespace

View File

@ -0,0 +1,48 @@
# Copyright (c) 2023 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/test.gni")
import("//test/xts/tools/build/suite.gni")
module_output_path = "hats/codec"
ohos_moduletest_suite("HatsHdfImageCodecTestAdditional") {
module_out_path = module_output_path
deps = [ "//third_party/googletest:gtest_main" ]
sources = [ "codec_hdi_jpeg_test.cpp" ]
if (is_standard_system) {
external_deps = [
"c_utils:utils",
"drivers_interface_codec:image_idl_headers",
"drivers_interface_codec:libcodec_proxy_1.0",
"drivers_interface_codec:libimage_proxy_1.0",
"drivers_interface_display:display_buffer_idl_headers",
"drivers_interface_display:display_composer_idl_headers",
"drivers_interface_display:libdisplay_buffer_hdi_impl",
"drivers_interface_display:libdisplay_composer_hdi_impl",
"graphic_chipsetsdk:buffer_handle",
"hdf_core:libhdf_host",
"hdf_core:libhdf_ipc_adapter",
"hdf_core:libhdf_utils",
"hdf_core:libhdi",
"hilog:libhilog",
"ipc:ipc_single",
]
} else {
external_deps = [ "hilog:libhilog" ]
}
subsystem_name = "xts"
part_name = "hats"
}

View File

@ -0,0 +1,18 @@
{
"kits": [
{
"push": [
"HatsHdfImageCodecTestAdditional->/data/local/tmp/HatsHdfImageCodecTestAdditional"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "HatsHdfImageCodecTestAdditional",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for HatsHdfImageCodecTestAdditional Tests"
}

View File

@ -0,0 +1,515 @@
/*
* Copyright (c) 2023 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <buffer_handle.h>
#include <gtest/gtest.h>
#include "hdf_log.h"
#include "v1_0/include/idisplay_buffer.h"
#include "v1_0/display_composer_type.h"
#include "v1_0/display_buffer_type.h"
#include "v1_0/codec_types.h"
#include "v1_0/codec_image_type.h"
#include "v1_0/icodec_image.h"
#define HDF_LOG_TAG codec_jpeg_test
using namespace std;
using namespace testing::ext;
using namespace OHOS::HDI::Display::Buffer::V1_0;
using namespace OHOS::HDI::Display::Composer::V1_0;
using namespace OHOS::HDI::Codec::V1_0;
using namespace OHOS::HDI::Codec::Image::V1_0;
namespace {
constexpr int32_t WIDTH = 640;
constexpr int32_t HEIGHT = 480;
constexpr uint32_t NORMAL_BUFFER_SIZE = 1000;
static OHOS::sptr<ICodecImage> hdiJpeg_;
static IDisplayBuffer *hdiBuffer_;
class CodecHdiJpegTestAdditional : public testing::Test {
public:
void InitOutBuffer(CodecImageBuffer &outBuffer)
{
AllocInfo alloc = {
.width = WIDTH,
.height = HEIGHT,
.usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA,
.format = PIXEL_FMT_YCBCR_420_SP};
BufferHandle *bufferHandle = nullptr;
auto err = hdiBuffer_->AllocMem(alloc, bufferHandle);
if (err != HDF_SUCCESS) {
return;
}
outBuffer.buffer = new NativeBuffer(bufferHandle);
}
static void SetUpTestCase()
{
hdiJpeg_ = ICodecImage::Get();
hdiBuffer_ = IDisplayBuffer::Get();
}
static void TearDownTestCase()
{
hdiJpeg_ = nullptr;
hdiBuffer_ = nullptr;
}
void SetUp()
{
if (hdiJpeg_ != nullptr) {
hdiJpeg_->Init(CODEC_IMAGE_JPEG);
}
}
void TearDown()
{
if (hdiJpeg_ != nullptr) {
hdiJpeg_->DeInit(CODEC_IMAGE_JPEG);
}
}
};
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_0900
* @tc.name : testCodecDoJpegDecode001
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecDoJpegDecode001, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
struct CodecImageBuffer outBuffer;
struct CodecJpegDecInfo decInfo;
inBuffer.size = -1;
auto ret = hdiJpeg_->DoJpegDecode(inBuffer, outBuffer, decInfo);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_1000
* @tc.name : testCodecDoJpegDecode002
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecDoJpegDecode002, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
struct CodecImageBuffer outBuffer;
struct CodecJpegDecInfo decInfo;
inBuffer.buffer = 0;
auto ret = hdiJpeg_->DoJpegDecode(inBuffer, outBuffer, decInfo);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_1100
* @tc.name : testCodecDoJpegDecode003
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecDoJpegDecode003, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
struct CodecImageBuffer outBuffer;
struct CodecJpegDecInfo decInfo;
inBuffer.fenceFd = -1;
auto ret = hdiJpeg_->DoJpegDecode(inBuffer, outBuffer, decInfo);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_1200
* @tc.name : testCodecDoJpegDecode004
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecDoJpegDecode004, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
struct CodecImageBuffer outBuffer;
struct CodecJpegDecInfo decInfo;
outBuffer.id = -1;
auto ret = hdiJpeg_->DoJpegDecode(inBuffer, outBuffer, decInfo);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_1300
* @tc.name : testCodecDoJpegDecode005
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecDoJpegDecode005, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
struct CodecImageBuffer outBuffer;
struct CodecJpegDecInfo decInfo;
outBuffer.size = -1;
auto ret = hdiJpeg_->DoJpegDecode(inBuffer, outBuffer, decInfo);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_1400
* @tc.name : testCodecDoJpegDecode006
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecDoJpegDecode006, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
struct CodecImageBuffer outBuffer;
struct CodecJpegDecInfo decInfo;
outBuffer.buffer = 0;
auto ret = hdiJpeg_->DoJpegDecode(inBuffer, outBuffer, decInfo);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_1500
* @tc.name : testCodecDoJpegDecode007
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecDoJpegDecode007, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
struct CodecImageBuffer outBuffer;
struct CodecJpegDecInfo decInfo;
outBuffer.fenceFd = -1;
auto ret = hdiJpeg_->DoJpegDecode(inBuffer, outBuffer, decInfo);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_1600
* @tc.name : testCodecDoJpegDecode008
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecDoJpegDecode008, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
struct CodecImageBuffer outBuffer;
struct CodecJpegDecInfo decInfo;
decInfo.imageWidth = -1;
auto ret = hdiJpeg_->DoJpegDecode(inBuffer, outBuffer, decInfo);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_1700
* @tc.name : testCodecDoJpegDecode009
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecDoJpegDecode0009, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
struct CodecImageBuffer outBuffer;
struct CodecJpegDecInfo decInfo;
decInfo.imageHeight = -1;
auto ret = hdiJpeg_->DoJpegDecode(inBuffer, outBuffer, decInfo);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_1800
* @tc.name : testCodecDoJpegDecode010
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecDoJpegDecode0010, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
struct CodecImageBuffer outBuffer;
struct CodecJpegDecInfo decInfo;
decInfo.dataPrecision = -1;
auto ret = hdiJpeg_->DoJpegDecode(inBuffer, outBuffer, decInfo);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_1900
* @tc.name : testCodecDoJpegDecode011
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecDoJpegDecode0011, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
struct CodecImageBuffer outBuffer;
struct CodecJpegDecInfo decInfo;
decInfo.numComponents = -1;
auto ret = hdiJpeg_->DoJpegDecode(inBuffer, outBuffer, decInfo);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_2000
* @tc.name : testCodecDoJpegDecode012
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecDoJpegDecode0012, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
struct CodecImageBuffer outBuffer;
struct CodecJpegDecInfo decInfo;
decInfo.restartInterval = -1;
auto ret = hdiJpeg_->DoJpegDecode(inBuffer, outBuffer, decInfo);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_2100
* @tc.name : testCodecFreeInBuffer001
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecFreeInBuffer001, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
inBuffer.size = -1;
auto ret = hdiJpeg_->FreeInBuffer(inBuffer);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_2200
* @tc.name : testCodecFreeInBuffer002
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecFreeInBuffer002, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
inBuffer.buffer = 0;
auto ret = hdiJpeg_->FreeInBuffer(inBuffer);
ASSERT_EQ(ret, HDF_FAILURE);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_2300
* @tc.name : testCodecFreeInBuffer003
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecFreeInBuffer003, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
inBuffer.fenceFd = -1;
auto ret = hdiJpeg_->FreeInBuffer(inBuffer);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_2400
* @tc.name : testCodecGetImageCapability001
* @tc.desc : Determine whether existing values of parameter structures affect function results
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecGetImageCapability001, TestSize.Level1)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
std::vector<CodecImageCapability> capList(1);
capList[0].role = CODEC_IMAGE_INVALID;
auto ret = hdiJpeg_->GetImageCapability(capList);
ASSERT_EQ(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_2500
* @tc.name : testCodecGetImageCapability002
* @tc.desc : Determine whether existing values of parameter structures affect function results
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecGetImageCapability002, TestSize.Level1)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
std::vector<CodecImageCapability> capList(1);
capList[0].type = CODEC_IMAGE_TYPE_INVALID;
auto ret = hdiJpeg_->GetImageCapability(capList);
ASSERT_EQ(ret, HDF_SUCCESS);
ASSERT_TRUE(!capList[0].name.empty());
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_2600
* @tc.name : testCodecGetImageCapability003
* @tc.desc : Determine whether existing values of parameter structures affect function results
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecGetImageCapability003, TestSize.Level1)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
std::vector<CodecImageCapability> capList(1);
capList[0].widthAlignment = -1;
auto ret = hdiJpeg_->GetImageCapability(capList);
ASSERT_TRUE(capList[0].widthAlignment >= 0);
ASSERT_EQ(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_2700
* @tc.name : testCodecGetImageCapability004
* @tc.desc : Determine whether existing values of parameter structures affect function results
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecGetImageCapability004, TestSize.Level1)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
std::vector<CodecImageCapability> capList(1);
capList[0].heightAlignment = -1;
auto ret = hdiJpeg_->GetImageCapability(capList);
ASSERT_TRUE(capList[0].heightAlignment >= 0);
ASSERT_EQ(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_2800
* @tc.name : testCodecGetImageCapability005
* @tc.desc : Determine whether existing values of parameter structures affect function results
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecGetImageCapability005, TestSize.Level1)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
std::vector<CodecImageCapability> capList(1);
capList[0].maxSample = -1;
auto ret = hdiJpeg_->GetImageCapability(capList);
ASSERT_TRUE(capList[0].maxSample >= 0);
ASSERT_EQ(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_2900
* @tc.name : testCodecGetImageCapability006
* @tc.desc : Determine whether existing values of parameter structures affect function results
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecGetImageCapability006, TestSize.Level1)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
std::vector<CodecImageCapability> capList(1);
capList[0].maxWidth = -1;
auto ret = hdiJpeg_->GetImageCapability(capList);
ASSERT_TRUE(capList[0].maxWidth >= 0);
ASSERT_EQ(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_3000
* @tc.name : testCodecGetImageCapability007
* @tc.desc : Determine whether existing values of parameter structures affect function results
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecGetImageCapability007, TestSize.Level1)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
std::vector<CodecImageCapability> capList(1);
capList[0].maxHeight = -1;
auto ret = hdiJpeg_->GetImageCapability(capList);
ASSERT_TRUE(capList[0].maxHeight >= 0);
ASSERT_EQ(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_3100
* @tc.name : testCodecGetImageCapability008
* @tc.desc : Determine whether existing values of parameter structures affect function results
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecGetImageCapability008, TestSize.Level1)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
std::vector<CodecImageCapability> capList(1);
capList[0].maxInst = -1;
auto ret = hdiJpeg_->GetImageCapability(capList);
ASSERT_TRUE(capList[0].maxInst >= 0);
ASSERT_EQ(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_3200
* @tc.name : testCodecAllocateInBuffer001
* @tc.desc : Determine whether existing values of parameter structures affect function results
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecAllocateInBuffer001, TestSize.Level1)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
inBuffer.id = -1;
auto ret = hdiJpeg_->AllocateInBuffer(inBuffer, NORMAL_BUFFER_SIZE, CODEC_IMAGE_JPEG);
ASSERT_EQ(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_3300
* @tc.name : testCodecAllocateInBuffer002
* @tc.desc : Determine whether existing values of parameter structures affect function results
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecAllocateInBuffer002, TestSize.Level1)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
inBuffer.size = -1;
auto ret = hdiJpeg_->AllocateInBuffer(inBuffer, NORMAL_BUFFER_SIZE, CODEC_IMAGE_JPEG);
ASSERT_EQ(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_3400
* @tc.name : testCodecAllocateInBuffer003
* @tc.desc : Determine whether existing values of parameter structures affect function results
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecAllocateInBuffer003, TestSize.Level1)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
inBuffer.buffer = 0;
auto ret = hdiJpeg_->AllocateInBuffer(inBuffer, NORMAL_BUFFER_SIZE, CODEC_IMAGE_JPEG);
ASSERT_EQ(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_3500
* @tc.name : testCodecAllocateInBuffer004
* @tc.desc : Determine whether existing values of parameter structures affect function results
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecAllocateInBuffer004, TestSize.Level1)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
inBuffer.fenceFd = -1;
auto ret = hdiJpeg_->AllocateInBuffer(inBuffer, NORMAL_BUFFER_SIZE, CODEC_IMAGE_JPEG);
ASSERT_EQ(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_3600
* @tc.name : testCodecAllocateInBuffer005
* @tc.desc : Determines the result of the function when the wrong argument is passed
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecAllocateInBuffer005, TestSize.Level2)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
auto ret = hdiJpeg_->AllocateInBuffer(inBuffer, -1, CODEC_IMAGE_JPEG);
ASSERT_NE(ret, HDF_SUCCESS);
}
/**
* @tc.number : SUB_Driver_Codec_ImageCodecHDI_3700
* @tc.name : testCodecAllocateInBuffer006
* @tc.desc : Determines the result of the function when the correct argument is passed in
*/
HWTEST_F(CodecHdiJpegTestAdditional, testCodecAllocateInBuffer006, TestSize.Level1)
{
ASSERT_TRUE(hdiJpeg_ != nullptr);
struct CodecImageBuffer inBuffer;
auto ret = hdiJpeg_->AllocateInBuffer(inBuffer, 200, CODEC_IMAGE_JPEG);
ASSERT_EQ(ret, HDF_SUCCESS);
}
} // namespace

View File

@ -0,0 +1,68 @@
# Copyright (c) 2021-2023 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//build/test.gni")
import("//test/xts/hats/build.gni")
import("//test/xts/tools/build/suite.gni")
module_output_path = "hats/codec"
ohos_moduletest_suite("HatsHdfOmxCodecTestAdditional") {
module_out_path = module_output_path
configs = [ ":hdf_codec_omx" ]
sources = [ "codec_hdi_manager_test.cpp" ]
deps = [ "//third_party/googletest:gtest_main" ]
if (is_standard_system) {
external_deps = [
"c_utils:utils",
"drivers_interface_display:display_buffer_idl_headers",
"drivers_interface_display:display_composer_idl_headers",
"drivers_interface_display:libdisplay_buffer_hdi_impl",
"drivers_interface_display:libdisplay_composer_hdi_impl",
"drivers_peripheral_codec:libcodec_hdi_omx_client",
"graphic_chipsetsdk:buffer_handle",
"hdf_core:libhdf_host",
"hdf_core:libhdf_ipc_adapter",
"hdf_core:libhdf_utils",
"hdf_core:libhdi",
"hilog:libhilog",
"ipc:ipc_single",
]
} else {
external_deps = [ "hilog:libhilog" ]
}
defines = []
if (hats_rich) {
defines += [ "SUPPORT_OMX" ]
}
subsystem_name = "xts"
part_name = "hats"
}
config("hdf_codec_omx") {
include_dirs = [ "//third_party/openmax/api/1.1.2" ]
cflags = [
"-Wall",
"-Wextra",
"-Werror",
"-fsigned-char",
"-fno-common",
"-fno-strict-aliasing",
]
if (hats_rich == false) {
cflags += [ "-DSUPPORT_OMX" ]
}
}

View File

@ -0,0 +1,18 @@
{
"kits": [
{
"push": [
"HatsHdfOmxCodecTestAdditional->/data/local/tmp/HatsHdfOmxCodecTestAdditional"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "HatsHdfOmxCodecTestAdditional",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for HatsHdfOmxCodecTestAdditional Tests"
}

View File

@ -0,0 +1,314 @@
/*
* Copyright (c) 2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <osal_mem.h>
#include "codec_callback_if.h"
#include "codec_component_manager.h"
using namespace std;
using namespace testing::ext;
namespace {
class CodecHdiManagerTestAdditional : public testing::Test {
public:
static void SetUpTestCase()
{}
static void TearDownTestCase()
{}
void SetUp()
{
manager_ = GetCodecComponentManager();
}
void TearDown()
{
CodecComponentManagerRelease();
manager_ = nullptr;
}
public:
struct CodecComponentManager *manager_ = nullptr;
};
/**
* @tc.number SUB_Driver_Codec_CodecHdi_0600
* @tc.name testCodecGetComponentNum001
* @tc.desc Determines whether the function gets the param correctly
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentNum001, Function | MediumTest | Level1)
{
ASSERT_TRUE(manager_ != nullptr);
auto count = -1;
count = manager_->GetComponentNum();
EXPECT_TRUE(count >= 0);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_0700
* @tc.name testCodecGetComponentCapabilityList001
* @tc.desc Determine whether the function can obtain the correct value if there are existing values in the structure
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList001, Function | MediumTest | Level1)
{
ASSERT_TRUE(manager_ != nullptr);
auto count = manager_->GetComponentNum();
CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count);
ASSERT_TRUE(capList != nullptr);
capList->role = MEDIA_ROLETYPE_INVALID;
auto err = manager_->GetComponentCapabilityList(capList, count);
EXPECT_EQ(err, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_0800
* @tc.name testCodecGetComponentCapabilityList002
* @tc.desc Determine whether the function can obtain the correct value if there are existing values in the structure
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList002, Function | MediumTest | Level1)
{
ASSERT_TRUE(manager_ != nullptr);
auto count = manager_->GetComponentNum();
ASSERT_TRUE(count > 0);
CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count);
ASSERT_TRUE(capList != nullptr);
capList->role = MEDIA_ROLETYPE_IMAGE_JPEG;
auto err = manager_->GetComponentCapabilityList(capList, count);
EXPECT_EQ(err, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_0900
* @tc.name testCodecGetComponentCapabilityList003
* @tc.desc Determine whether the function can obtain the correct value if there are existing values in the structure
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList003, Function | MediumTest | Level1)
{
ASSERT_TRUE(manager_ != nullptr);
auto count = manager_->GetComponentNum();
CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count);
ASSERT_TRUE(capList != nullptr);
capList->type = INVALID_TYPE;
auto err = manager_->GetComponentCapabilityList(capList, count);
EXPECT_EQ(err, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_1000
* @tc.name testCodecGetComponentCapabilityList004
* @tc.desc Determine whether the function can obtain the correct value if there are existing values in the structure
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList004, Function | MediumTest | Level1)
{
ASSERT_TRUE(manager_ != nullptr);
auto count = manager_->GetComponentNum();
CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count);
ASSERT_TRUE(capList != nullptr);
capList->maxInst = -1;
auto err = manager_->GetComponentCapabilityList(capList, count);
EXPECT_EQ(err, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_1100
* @tc.name testCodecGetComponentCapabilityList005
* @tc.desc Determine whether the function can obtain the correct value if there are existing values in the structure
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList005, Function | MediumTest | Level1)
{
ASSERT_TRUE(manager_ != nullptr);
auto count = manager_->GetComponentNum();
CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count);
ASSERT_TRUE(capList != nullptr);
capList->capsMask = -1;
auto err = manager_->GetComponentCapabilityList(capList, count);
EXPECT_EQ(err, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_1200
* @tc.name testCodecGetComponentCapabilityList006
* @tc.desc When the number of codec components is negative, the validity of the function is judged
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecGetComponentCapabilityList006, Function | MediumTest | Level2)
{
ASSERT_TRUE(manager_ != nullptr);
int count = -1;
CodecCompCapability *capList = (CodecCompCapability *)
OsalMemAlloc(sizeof(CodecCompCapability) * (manager_->GetComponentNum()));
ASSERT_TRUE(capList != nullptr);
auto err = manager_->GetComponentCapabilityList(capList, count);
EXPECT_NE(err, HDF_SUCCESS);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_1300
* @tc.name testCodecCreateComponent001
* @tc.desc When the parameter passed by the function already has a value, determine whether it will have an effect
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent001, Function | MediumTest | Level1)
{
ASSERT_TRUE(manager_ != nullptr);
std::string compName("");
auto count = manager_->GetComponentNum();
ASSERT_TRUE(count > 0);
CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count);
ASSERT_TRUE(capList != nullptr);
auto err = manager_->GetComponentCapabilityList(capList, count);
ASSERT_TRUE(err == HDF_SUCCESS);
compName = capList[0].compName;
OsalMemFree(capList);
capList = nullptr;
ASSERT_FALSE(compName.empty());
struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
struct CodecComponentType *component = nullptr;
uint32_t componentId = -1;
ASSERT_TRUE(callback != nullptr);
int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback);
EXPECT_EQ(ret, HDF_SUCCESS);
CodecCallbackTypeRelease(callback);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_1400
* @tc.name testCodecCreateComponent002
* @tc.desc Open the OpenMax component based on a non-existent compName
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent002, Function | MediumTest | Level2)
{
struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
ASSERT_TRUE(callback != nullptr);
ASSERT_TRUE(manager_ != nullptr);
std::string compName(" ");
struct CodecComponentType *component = nullptr;
uint32_t componentId = 0;
int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback);
EXPECT_NE(ret, HDF_SUCCESS);
EXPECT_EQ(component, nullptr);
CodecCallbackTypeRelease(callback);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_1500
* @tc.name testCodecCreateComponent003
* @tc.desc Open the OpenMax component based on a non-existent compName
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent003, Function | MediumTest | Level2)
{
struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
ASSERT_TRUE(callback != nullptr);
ASSERT_TRUE(manager_ != nullptr);
std::string compName("//\a");
struct CodecComponentType *component = nullptr;
uint32_t componentId = 0;
int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback);
EXPECT_NE(ret, HDF_SUCCESS);
EXPECT_EQ(component, nullptr);
CodecCallbackTypeRelease(callback);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_1600
* @tc.name testCodecCreateComponent004
* @tc.desc Open the OpenMax component based on a non-existent compName
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent004, Function | MediumTest | Level2)
{
struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
ASSERT_TRUE(callback != nullptr);
ASSERT_TRUE(manager_ != nullptr);
std::string compName("a,");
struct CodecComponentType *component = nullptr;
uint32_t componentId = 0;
int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback);
EXPECT_NE(ret, HDF_SUCCESS);
EXPECT_EQ(component, nullptr);
CodecCallbackTypeRelease(callback);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_1700
* @tc.name testCodecCreateComponent005
* @tc.desc Open the OpenMax component based on a non-existent compName
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent005, Function | MediumTest | Level2)
{
struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
ASSERT_TRUE(callback != nullptr);
ASSERT_TRUE(manager_ != nullptr);
std::string compName("12344");
struct CodecComponentType *component = nullptr;
uint32_t componentId = 0;
int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback);
EXPECT_NE(ret, HDF_SUCCESS);
EXPECT_EQ(component, nullptr);
CodecCallbackTypeRelease(callback);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_1800
* @tc.name testCodecCreateComponent006
* @tc.desc Open the OpenMax component based on a non-existent compName
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent006, Function | MediumTest | Level1)
{
struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
ASSERT_TRUE(callback != nullptr);
ASSERT_TRUE(manager_ != nullptr);
std::string compName("a@%");
struct CodecComponentType *component = nullptr;
uint32_t componentId = 0;
int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback);
EXPECT_NE(ret, HDF_SUCCESS);
EXPECT_EQ(component, nullptr);
CodecCallbackTypeRelease(callback);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_1900
* @tc.name testCodecCreateComponent007
* @tc.desc Open the OpenMax component based on a non-existent compName
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent007, Function | MediumTest | Level2)
{
struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
ASSERT_TRUE(callback != nullptr);
ASSERT_TRUE(manager_ != nullptr);
std::string compName("a~~~");
struct CodecComponentType *component = nullptr;
uint32_t componentId = 0;
int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback);
EXPECT_NE(ret, HDF_SUCCESS);
EXPECT_EQ(component, nullptr);
CodecCallbackTypeRelease(callback);
}
/**
* @tc.number SUB_Driver_Codec_CodecHdi_2000
* @tc.name testCodecCreateComponent008
* @tc.desc Open the OpenMax component based on a non-existent compName
*/
HWTEST_F(CodecHdiManagerTestAdditional, testCodecCreateComponent008, Function | MediumTest | Level2)
{
struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
ASSERT_TRUE(callback != nullptr);
ASSERT_TRUE(manager_ != nullptr);
std::string compName("a");
struct CodecComponentType *component = nullptr;
uint32_t componentId = 0;
int32_t ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback);
EXPECT_NE(ret, HDF_SUCCESS);
EXPECT_EQ(component, nullptr);
CodecCallbackTypeRelease(callback);
}
} // namespace

View File

@ -24,6 +24,7 @@ group("HatsHdfDisplayTest") {
"composer/death:HatsHdfDisplayComposerDeathTest",
"composer/moduletest:HatszHdfDisplayComposerMtTest",
"composer/unittest:HatszHdfDisplayComposerUtTest",
"composer/unittest_additional:HatsHdfDisplayComposerUtTestAdditional",
]
} else {
deps = [
@ -33,6 +34,7 @@ group("HatsHdfDisplayTest") {
"composer/death:HatsHdfDisplayComposerDeathTest",
"composer/moduletest:HatszHdfDisplayComposerMtTest",
"composer/unittest:HatszHdfDisplayComposerUtTest",
"composer/unittest_additional:HatsHdfDisplayComposerUtTestAdditional",
]
}
}

View File

@ -0,0 +1,43 @@
# Copyright (c) 2023 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos_var.gni")
import("//test/xts/tools/build/suite.gni")
module_output_path = "hats/display"
config("module_private_config") {
visibility = [ ":*" ]
}
ohos_moduletest_suite("HatsHdfDisplayComposerUtTestAdditional") {
module_out_path = module_output_path
sources = [ "hdi_composer_ut.cpp" ]
deps = [ "../common:disp_dev_hdi_test" ]
include_dirs = [ "../common" ]
external_deps = [
"c_utils:utils",
"drivers_interface_display:display_buffer_idl_headers",
"drivers_interface_display:display_composer_idl_headers",
"drivers_interface_display:libdisplay_buffer_hdi_impl",
"drivers_interface_display:libdisplay_composer_hdi_impl",
"googletest:gtest",
"graphic_chipsetsdk:buffer_handle",
"hdf_core:libhdf_utils",
"hilog:libhilog",
"ipc:ipc_core",
]
cflags = [ "-Wno-unused-function" ]
subsystem_name = "xts"
part_name = "hats"
}

View File

@ -0,0 +1,18 @@
{
"kits": [
{
"push": [
"HatsHdfDisplayComposerUtTestAdditional->/data/local/tmp/HatsHdfDisplayComposerUtTestAdditional"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "HatsHdfDisplayComposerUtTestAdditional",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for HatsHdfDisplayComposerUtTestAdditional Tests"
}

View File

@ -0,0 +1,251 @@
/*
* Copyright (c) 2023 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "hdi_composer_ut.h"
#include <chrono>
#include <cinttypes>
#include <algorithm>
#include "v1_0/include/idisplay_composer_interface.h"
#include "v1_0/display_composer_type.h"
#include "v1_0/display_buffer_type.h"
#include "display_test.h"
#include "display_test_utils.h"
#include "hdi_composition_check.h"
#include "hdi_test_device.h"
#include "hdi_test_device_common.h"
#include "hdi_test_display.h"
#include "hdi_test_render_utils.h"
using namespace OHOS::HDI::Display::Buffer::V1_0;
using namespace OHOS::HDI::Display::Composer::V1_0;
using namespace OHOS::HDI::Display::TEST;
using namespace testing::ext;
static sptr<IDisplayComposerInterface> g_composerDevice = nullptr;
static std::shared_ptr<IDisplayBuffer> g_gralloc = nullptr;
static std::vector<uint32_t> g_displayIds;
void DeviceTestAdditional::SetUpTestCase()
{
int ret = HdiTestDevice::GetInstance().InitDevice();
ASSERT_TRUE(ret == DISPLAY_SUCCESS);
g_composerDevice = HdiTestDevice::GetInstance().GetDeviceInterface();
ASSERT_TRUE(g_composerDevice != nullptr);
g_gralloc.reset(IDisplayBuffer::Get());
ASSERT_TRUE(g_gralloc != nullptr);
g_displayIds = HdiTestDevice::GetInstance().GetDevIds();
ASSERT_TRUE(g_displayIds.size() > 0);
}
void DeviceTestAdditional::TearDownTestCase()
{
HdiTestDevice::GetInstance().Clear();
HdiTestDevice::GetInstance().GetFirstDisplay()->ResetClientLayer();
}
/**
* @tc.number : SUB_Driver_Display_ClientBufferCount_0100
* @tc.name : testClientBufferCount001
* @tc.desc : test cache count Max
*/
HWTEST_F(DeviceTestAdditional, testClientBufferCount001, Function | MediumTest | Level1)
{
const uint32_t cacheCount = 20;
auto ret = g_composerDevice->SetClientBufferCacheCount(g_displayIds[0], cacheCount);
EXPECT_EQ(DISPLAY_SUCCESS, ret);
}
/**
* @tc.number : SUB_Driver_Display_ClientBufferCount_0200
* @tc.name : testClientBufferCount002
* @tc.desc : test cache count Min
*/
HWTEST_F(DeviceTestAdditional, testClientBufferCount002, Function | MediumTest | Level1)
{
const uint32_t cacheCount = 0;
auto ret = g_composerDevice->SetClientBufferCacheCount(g_displayIds[0], cacheCount);
EXPECT_EQ(DISPLAY_SUCCESS, ret);
}
/**
* @tc.number : SUB_Driver_Display_ClientBufferCount_0300
* @tc.name : testClientBufferCount003
* @tc.desc : test cache count Random
*/
HWTEST_F(DeviceTestAdditional, testClientBufferCount003, Function | MediumTest | Level1)
{
const uint32_t cacheCount = 15;
auto ret = g_composerDevice->SetClientBufferCacheCount(g_displayIds[0], cacheCount);
EXPECT_EQ(DISPLAY_SUCCESS, ret);
}
/**
* @tc.number : SUB_Driver_Display_ClientBufferCount_0400
* @tc.name : testClientBufferCount004
* @tc.desc : test devId Max
*/
HWTEST_F(DeviceTestAdditional, testClientBufferCount004, Function | MediumTest | Level1)
{
const uint32_t cacheCount = 5;
auto ret = g_composerDevice->SetClientBufferCacheCount(20, cacheCount);
EXPECT_EQ(DISPLAY_FAILURE, ret);
}
/**
* @tc.number : SUB_Driver_Display_ClientBufferCount_0500
* @tc.name : testClientBufferCount005
* @tc.desc : test devId Min
*/
HWTEST_F(DeviceTestAdditional, testClientBufferCount005, Function | MediumTest | Level1)
{
const uint32_t cacheCount = 5;
auto ret = g_composerDevice->SetClientBufferCacheCount(0, cacheCount);
EXPECT_EQ(DISPLAY_SUCCESS, ret);
}
/**
* @tc.number : SUB_Driver_Display_ClientBufferCount_0600
* @tc.name : testClientBufferCount006
* @tc.desc : test devId Random
*/
HWTEST_F(DeviceTestAdditional, testClientBufferCount006, Function | MediumTest | Level1)
{
const uint32_t cacheCount = 5;
auto ret = g_composerDevice->SetClientBufferCacheCount(15, cacheCount);
EXPECT_EQ(DISPLAY_FAILURE, ret);
}
/**
* @tc.number : SUB_Driver_Display_ClientBufferCount_0700
* @tc.name : testClientBufferCount007
* @tc.desc : test devId Negative Number
*/
HWTEST_F(DeviceTestAdditional, testClientBufferCount007, Function | MediumTest | Level2)
{
const uint32_t cacheCount = 5;
auto ret = g_composerDevice->SetClientBufferCacheCount(-1, cacheCount);
EXPECT_EQ(DISPLAY_FAILURE, ret);
}
/**
* @tc.number : SUB_Driver_Display_ClientBufferCount_0800
* @tc.name : testClientBufferCount008
* @tc.desc : test devId Negative Number
*/
HWTEST_F(DeviceTestAdditional, testClientBufferCount008, Function | MediumTest | Level1)
{
const uint32_t cacheCount = -1;
auto ret = g_composerDevice->SetClientBufferCacheCount(g_displayIds[0], cacheCount);
EXPECT_EQ(DISPLAY_SUCCESS, ret);
}
/**
* @tc.number : SUB_Driver_Display_Capability_0200
* @tc.name : testCapability002
* @tc.desc : test devId Min
*/
HWTEST_F(DeviceTestAdditional, testCapability002, Function | MediumTest | Level1)
{
DisplayCapability info;
auto ret = g_composerDevice->GetDisplayCapability(0, info);
EXPECT_EQ(DISPLAY_SUCCESS, ret);
}
/**
* @tc.number : SUB_Driver_Display_SupportedModes_0100
* @tc.name : testSupportedModes001
* @tc.desc : test devId Max
*/
HWTEST_F(DeviceTestAdditional, testSupportedModes001, Function | MediumTest | Level1)
{
std::vector<DisplayModeInfo> modes;
auto ret = g_composerDevice->GetDisplaySupportedModes(20, modes);
EXPECT_EQ(DISPLAY_FAILURE, ret);
}
/**
* @tc.number : SUB_Driver_Display_SupportedModes_0200
* @tc.name : testSupportedModes002
* @tc.desc : test devId Min
*/
HWTEST_F(DeviceTestAdditional, testSupportedModes002, Function | MediumTest | Level1)
{
std::vector<DisplayModeInfo> modes;
auto ret = g_composerDevice->GetDisplaySupportedModes(0, modes);
EXPECT_EQ(DISPLAY_SUCCESS, ret);
}
/**
* @tc.number : SUB_Driver_Display_SupportedModes_0400
* @tc.name : testSupportedModes004
* @tc.desc : test devId Negative Number
*/
HWTEST_F(DeviceTestAdditional, testSupportedModes004, Function | MediumTest | Level2)
{
std::vector<DisplayModeInfo> modes;
auto ret = g_composerDevice->GetDisplaySupportedModes(-1, modes);
EXPECT_EQ(DISPLAY_FAILURE, ret);
}
/**
* @tc.number : SUB_Driver_Display_DisplayMode_0100
* @tc.name : testDisplayMode001
* @tc.desc : test devId Max
*/
HWTEST_F(DeviceTestAdditional, testDisplayMode001, Function | MediumTest | Level1)
{
uint32_t mode = 0;
auto ret = g_composerDevice->GetDisplayMode(20, mode);
EXPECT_EQ(DISPLAY_FAILURE, ret);
}
/**
* @tc.number : SUB_Driver_Display_DisplayMode_0200
* @tc.name : testDisplayMode002
* @tc.desc : test devId Min
*/
HWTEST_F(DeviceTestAdditional, testDisplayMode002, Function | MediumTest | Level1)
{
uint32_t mode = 0;
auto ret = g_composerDevice->GetDisplayMode(0, mode);
EXPECT_EQ(DISPLAY_SUCCESS, ret);
}
/**
* @tc.number : SUB_Driver_Display_DisplayMode_0300
* @tc.name : testDisplayMode003
* @tc.desc : test devId Random
*/
HWTEST_F(DeviceTestAdditional, testDisplayMode003, Function | MediumTest | Level1)
{
uint32_t mode = 0;
auto ret = g_composerDevice->GetDisplayMode(15, mode);
EXPECT_EQ(DISPLAY_FAILURE, ret);
}
/**
* @tc.number : SUB_Driver_Display_DisplayMode_0400
* @tc.name : testDisplayMode004
* @tc.desc : test devId Negative Number
*/
HWTEST_F(DeviceTestAdditional, testDisplayMode004, Function | MediumTest | Level1)
{
uint32_t mode = 0;
auto ret = g_composerDevice->GetDisplayMode(-1, mode);
EXPECT_EQ(DISPLAY_FAILURE, ret);
}

View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2023 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HDI_COMPOSER_UT_H
#define HDI_COMPOSER_UT_H
#include "v1_0/display_composer_type.h"
#include "v1_0/display_buffer_type.h"
#include "display_test_utils.h"
#include "gtest/gtest.h"
#include <condition_variable>
#include <mutex>
#include <vector>
namespace OHOS {
namespace HDI {
namespace Display {
namespace TEST {
using namespace OHOS::HDI::Display::Buffer::V1_0;
using namespace OHOS::HDI::Display::Composer::V1_0;
class DeviceTestAdditional : public ::testing::Test {
protected:
static void SetUpTestCase();
static void TearDownTestCase();
};
class VblankCtr {
public:
static VblankCtr& GetInstance()
{
static VblankCtr instance;
return instance;
}
void NotifyVblank(unsigned int sequence, uint64_t ns, const void* data);
int32_t WaitVblank(uint32_t ms);
private:
std::mutex vblankMutex_;
std::condition_variable vblankCondition_;
VblankCtr() {}
~VblankCtr();
bool hasVblank_ = false;
};
} // namespace SYSTEMTEST
} // namespace Display
} // namespace HDI
} // namespace OHOS
#endif // HDI_DEVICE_SYSTEM_TEST_H

View File

@ -20,6 +20,8 @@ group("HatsHdfSensorTest") {
deps = [
#":HatsHdfSensorHdiTest",
"hdiService:HatsHdfSensorServiceTest",
"hdiService_additional:HatsHdfSensorServiceTestAdditional",
#"sensorBenchmarkTest:HatsHdfSensorbenchmarkTest",
]
}

View File

@ -0,0 +1,58 @@
# Copyright (c) 2021-2022 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
base_root = "../../../../../.."
import("//build/ohos_var.gni")
import("//test/xts/tools/build/suite.gni")
import("$base_root/drivers/hdf_core/adapter/uhdf2/uhdf.gni")
module_output_path = "hats/sensor"
ohos_moduletest_suite("HatsHdfSensorServiceTestAdditional") {
module_out_path = module_output_path
configs = [ ":hdf_sensor_hdiservice_additional" ]
sources = [
"hdf_sensor_hdiService_test.cpp",
"sensor_callback_impl.cpp",
]
cflags = [
"-Wall",
"-Wextra",
"-Werror",
"-fsigned-char",
"-fno-common",
"-fno-strict-aliasing",
]
if (is_standard_system) {
external_deps = [
"c_utils:utils",
"drivers_interface_sensor:libsensor_proxy_1.1",
"hdf_core:libhdf_utils",
"hilog:libhilog",
"ipc:ipc_single",
]
} else {
external_deps = [ "hilog:libhilog" ]
}
external_deps += [ "ipc:ipc_single" ]
}
config("hdf_sensor_hdiservice_additional") {
include_dirs = [
"$base_root/drivers/peripheral/sensor/interfaces",
"$base_root/drivers/peripheral/sensor/interfaces/include",
]
}

View File

@ -0,0 +1,18 @@
{
"kits": [
{
"push": [
"HatsHdfSensorServiceTestAdditional->/data/local/tmp/HatsHdfSensorServiceTestAdditional"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "HatsHdfSensorServiceTestAdditional",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for HatsHdfSensorServiceTestAdditional Tests"
}

View File

@ -0,0 +1,821 @@
/*
* Copyright (c) 2021-2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cmath>
#include <cstdio>
#include <unistd.h>
#include <gtest/gtest.h>
#include <securec.h>
#include "hdf_base.h"
#include "osal_time.h"
#include "v1_1/isensor_interface.h"
#include "sensor_type.h"
#include "sensor_callback_impl.h"
#include "hdf_base.h"
#include "hdf_log.h"
#include "sensor_if.h"
using namespace OHOS::HDI::Sensor::V1_1;
using namespace testing::ext;
namespace {
sptr<ISensorInterface> g_sensorInterface = nullptr;
sptr<ISensorCallback> g_traditionalCallback = new SensorCallbackImpl();
sptr<ISensorCallback> g_medicalCallback = new SensorCallbackImpl();
std::vector<HdfSensorInformation> g_info;
constexpr int32_t SENSOR_INTERVAL2 = 20000000;
constexpr int32_t SENSOR_POLL_TIME = 1;
class HatsHdfSensorServiceTestAdditional : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void HatsHdfSensorServiceTestAdditional::SetUpTestCase()
{
g_sensorInterface = ISensorInterface::Get();
}
void HatsHdfSensorServiceTestAdditional::TearDownTestCase()
{
}
void HatsHdfSensorServiceTestAdditional::SetUp()
{
}
void HatsHdfSensorServiceTestAdditional::TearDown()
{
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_7100
* @tc.name: testHdiSensorSetBatch001
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorSetBatch001, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->SetBatch(HDF_SENSOR_TYPE_ACCELEROMETER, SENSOR_INTERVAL2, SENSOR_POLL_TIME);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_7200
* @tc.name: testHdiSensorSetBatch002
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorSetBatch002, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->GetAllSensorInfo(g_info);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
for (auto iter : g_info) {
int i = 0;
ret = g_sensorInterface->SetBatch(iter.sensorId, i, SENSOR_POLL_TIME);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_7300
* @tc.name: testHdiSensorSetBatch003
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorSetBatch003, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->GetAllSensorInfo(g_info);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
for (int a = 0; a <= 50; a++) {
for (auto iter : g_info) {
int i = 0;
ret = g_sensorInterface->SetBatch(iter.sensorId, i, SENSOR_POLL_TIME);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_7400
* @tc.name: testHdiSetBatchSensor004
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorSetBatch004, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->SetBatch(-1, SENSOR_INTERVAL2, SENSOR_POLL_TIME);
EXPECT_EQ(SENSOR_NOT_SUPPORT, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_7500
* @tc.name: testHdiSensorSetBatch005
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorSetBatch005, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
for (int i = 0; i <= 50; i++) {
ret = g_sensorInterface->SetBatch(-1, SENSOR_INTERVAL2, SENSOR_POLL_TIME);
EXPECT_EQ(SENSOR_NOT_SUPPORT, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_7600
* @tc.name: testHdiSensorSetBatch006
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorSetBatch006, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->GetAllSensorInfo(g_info);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
for (auto iter : g_info) {
int i = -1;
ret = g_sensorInterface->SetBatch(iter.sensorId, i, SENSOR_POLL_TIME);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_7700
* @tc.name: testHdiSensorSetBatch007
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorSetBatch007, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->GetAllSensorInfo(g_info);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
for (int a = 0; a <= 50; a++) {
for (auto iter : g_info) {
int i = -1;
ret = g_sensorInterface->SetBatch(iter.sensorId, i, SENSOR_POLL_TIME);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_7800
* @tc.name: testHdiSensorSetBatch008
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorSetBatch008, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->GetAllSensorInfo(g_info);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
for (auto iter : g_info) {
int i = 1;
ret = g_sensorInterface->SetBatch(iter.sensorId, i, SENSOR_POLL_TIME);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_7900
* @tc.name: testHdiSensorSetBatch009
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorSetBatch009, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->GetAllSensorInfo(g_info);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
for (auto iter : g_info) {
int i = 0;
ret = g_sensorInterface->SetBatch(iter.sensorId, SENSOR_INTERVAL2, i);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_8000
* @tc.name: testHdiSensorSetBatch010
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorSetBatch010, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->GetAllSensorInfo(g_info);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
for (int a = 0; a <= 50; a++) {
for (auto iter : g_info) {
int i = 0;
ret = g_sensorInterface->SetBatch(iter.sensorId, SENSOR_INTERVAL2, i);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_8100
* @tc.name: testHdiSensorSetBatch011
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorSetBatch011, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->GetAllSensorInfo(g_info);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
for (auto iter : g_info) {
int i = -1;
ret = g_sensorInterface->SetBatch(iter.sensorId, SENSOR_INTERVAL2, i);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_8200
* @tc.name: testHdiSensorSetBatch012
* @tc.desc: Sets the sampling time and data report interval for sensors in batches.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorSetBatch012, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->GetAllSensorInfo(g_info);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
for (int a = 0; a <= 50; a++) {
for (auto iter : g_info) {
int i = -1;
ret = g_sensorInterface->SetBatch(iter.sensorId, SENSOR_INTERVAL2, i);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_8300
* @tc.name: testHdiSensorRegister001
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorRegister001, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(HDF_MEDICAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Unregister(HDF_MEDICAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_8400
* @tc.name: testHdiSensorRegister002
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorRegister002, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(HDF_MEDICAL_SENSOR_TYPE, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_8500
* @tc.name: testHdiSensorRegister003
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorRegister003, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
for (int i = 0; i <= 50; i++) {
int32_t ret = g_sensorInterface->Register(HDF_MEDICAL_SENSOR_TYPE, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_8600
* @tc.name: testHdiSensorRegister004
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorRegister004, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(HDF_SENSOR_TYPE_ACCELEROMETER, g_medicalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Unregister(HDF_SENSOR_TYPE_ACCELEROMETER, g_medicalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_8700
* @tc.name: testHdiSensorRegister005
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorRegister005, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
for (int i = 0; i <= 50; i++) {
int32_t ret = g_sensorInterface->Register(HDF_MEDICAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Unregister(HDF_MEDICAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_8800
* @tc.name: testHdiSensorRegister006
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorRegister006, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(HDF_MEDICAL_SENSOR_TYPE, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
ret = g_sensorInterface->Unregister(HDF_MEDICAL_SENSOR_TYPE, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_8900
* @tc.name: testHdiSensorRegister007
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorRegister007, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
for (int i = 0; i <= 50; i++) {
int32_t ret = g_sensorInterface->Register(HDF_MEDICAL_SENSOR_TYPE, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
ret = g_sensorInterface->Unregister(HDF_MEDICAL_SENSOR_TYPE, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_9000
* @tc.name: testHdiSensorRegister008
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorRegister008, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(HDF_TRADITIONAL_SENSOR_TYPE, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
ret = g_sensorInterface->Unregister(HDF_TRADITIONAL_SENSOR_TYPE, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_9100
* @tc.name: testHdiSensorRegister009
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorRegister009, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
for (int i = 0; i <= 50; i++) {
int32_t ret = g_sensorInterface->Register(HDF_TRADITIONAL_SENSOR_TYPE, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
ret = g_sensorInterface->Unregister(HDF_TRADITIONAL_SENSOR_TYPE, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_9200
* @tc.name: testHdiSensorRegister010
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorRegister010, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(HDF_SENSOR_GROUP_TYPE_MAX, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
ret = g_sensorInterface->Unregister(HDF_SENSOR_GROUP_TYPE_MAX, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_9300
* @tc.name: testHdiSensorRegister011
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorRegister011, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
for (int i = 0; i <= 50; i++) {
int32_t ret = g_sensorInterface->Register(HDF_SENSOR_GROUP_TYPE_MAX, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
ret = g_sensorInterface->Unregister(HDF_SENSOR_GROUP_TYPE_MAX, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_9400
* @tc.name: testHdiSensorUnregister001
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorUnregister001, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(HDF_SENSOR_TYPE_MAGNETIC_FIELD, g_traditionalCallback);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
ret = g_sensorInterface->Unregister(-1, g_traditionalCallback);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_9500
* @tc.name: testHdiSensorUnregister002
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorUnregister002, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
for (int i = 0; i <= 50; i++) {
int32_t ret = g_sensorInterface->Register(HDF_SENSOR_TYPE_MAGNETIC_FIELD, g_traditionalCallback);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
ret = g_sensorInterface->Unregister(-1, g_traditionalCallback);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_9600
* @tc.name: testHdiSensorUnregister003
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorUnregister003, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(HDF_SENSOR_TYPE_CAPACITIVE, g_traditionalCallback);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
for (int i = 0; i <= 50; i++) {
ret = g_sensorInterface->Unregister(-1, g_traditionalCallback);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_9700
* @tc.name: testHdiSensorUnregister004
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorUnregister004, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(SENSOR_GROUP_TYPE_MAX, g_medicalCallback);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
ret = g_sensorInterface->Unregister(SENSOR_GROUP_TYPE_MAX, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_9800
* @tc.name: testHdiSensorUnregister005
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorUnregister005, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
for (int i = 0; i <= 50; i++) {
int32_t ret = g_sensorInterface->Register(SENSOR_GROUP_TYPE_MAX, g_medicalCallback);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
ret = g_sensorInterface->Unregister(SENSOR_GROUP_TYPE_MAX, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_9900
* @tc.name: testHdiSensorUnregister006
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorUnregister006, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(SENSOR_GROUP_TYPE_MAX, g_traditionalCallback);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
ret = g_sensorInterface->Unregister(SENSOR_GROUP_TYPE_MAX, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_0010
* @tc.name: testHdiSensorUnregister007
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorUnregister007, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
for (int i = 0; i <= 50; i++) {
int32_t ret = g_sensorInterface->Register(SENSOR_GROUP_TYPE_MAX, g_traditionalCallback);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
ret = g_sensorInterface->Unregister(SENSOR_GROUP_TYPE_MAX, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_0020
* @tc.name: testHdiSensorUnregister008
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorUnregister008, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->GetAllSensorInfo(g_info);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Unregister(TRADITIONAL_SENSOR_TYPE, g_medicalCallback);
EXPECT_EQ(SENSOR_FAILURE, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_0030
* @tc.name: testHdiSensorUnregister009
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorUnregister009, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
for (int i = 0; i <= 50; i++) {
int32_t ret = g_sensorInterface->GetAllSensorInfo(g_info);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Unregister(TRADITIONAL_SENSOR_TYPE, g_medicalCallback);
EXPECT_EQ(SENSOR_FAILURE, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_0040
* @tc.name: testHdiSensorUnregister010
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorUnregister010, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Unregister(TRADITIONAL_SENSOR_TYPE, nullptr);
EXPECT_EQ(SENSOR_INVALID_PARAM, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_0050
* @tc.name: testHdiSensorUnregister011
* @tc.desc: Returns 0 if the callback is successfully registered; returns a negative value otherwise.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorUnregister011, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(MEDICAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Unregister(MEDICAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_0060
* @tc.name: testHdiSensorEnable001
* @tc.desc: Enables the sensor available in the sensor list based on the specified sensor ID.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorEnable001, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Enable(HDF_SENSOR_TYPE_ACCELEROMETER);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_0070
* @tc.name: testHdiSensorEnable002
* @tc.desc: Enables the sensor available in the sensor list based on the specified sensor ID.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorEnable002, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Enable(-1);
EXPECT_EQ(SENSOR_NOT_SUPPORT, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_0080
* @tc.name: testHdiSensorEnable003
* @tc.desc: Enables the sensor available in the sensor list based on the specified sensor ID.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorEnable003, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
for (int i = 0; i <= 50; i++) {
ret = g_sensorInterface->Enable(-1);
EXPECT_EQ(SENSOR_NOT_SUPPORT, ret);
}
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_0090
* @tc.name: testHdiSensorDisable001
* @tc.desc: Enables the sensor available in the sensor list based on the specified sensor ID.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorDisable001, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->Disable(HDF_SENSOR_TYPE_ACCELEROMETER);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_0110
* @tc.name: testHdiSensorSetMode001
* @tc.desc: Sets the data reporting mode for the specified sensor.The current real-time polling mode is valid.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorSetMode001, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
int32_t ret = g_sensorInterface->Register(TRADITIONAL_SENSOR_TYPE, g_traditionalCallback);
EXPECT_EQ(SENSOR_SUCCESS, ret);
ret = g_sensorInterface->SetMode(HDF_SENSOR_TYPE_ACCELEROMETER, SENSOR_MODE_ONE_SHOT);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
/**
* @tc.number: SUB_Driver_Sensor_HdiSensor_0120
* @tc.name: testHdiSensorGetAllSensorInfo001
* @tc.desc: Obtains information about all sensors in the system.
*/
HWTEST_F(HatsHdfSensorServiceTestAdditional, testHdiSensorGetAllSensorInfo001, TestSize.Level1)
{
if (g_sensorInterface == nullptr) {
ASSERT_NE(nullptr, g_sensorInterface);
return;
}
for (int i = 0; i <= 50; i++) {
int32_t ret = g_sensorInterface->GetAllSensorInfo(g_info);
EXPECT_EQ(SENSOR_SUCCESS, ret);
}
}
}

View File

@ -0,0 +1,115 @@
/*
* Copyright (c) 2021-2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "sensor_callback_impl.h"
#include "sensor_type.h"
#include "osal_mem.h"
namespace OHOS {
namespace HDI {
namespace Sensor {
namespace V1_1 {
uint32_t SensorCallbackImpl::sensorDataFlag = 1;
namespace {
struct SensorValueRange {
float highThreshold;
float lowThreshold;
};
struct SensorDevelopmentList {
int32_t sensorTypeId;
char sensorName[SENSOR_NAME_MAX_LEN];
int32_t dataForm; // 0: fixed, 1: range
int32_t dataDimension;
struct SensorValueRange *valueRange;
};
struct SensorValueRange g_testRange[] = {{1e5, 0.0}};
struct SensorValueRange g_accelRange[] = {{78.0, -78.0}, {78.0, -78.0}, {78.0, -78.0}};
struct SensorValueRange g_alsRange[] = {{10000.0, 0.0}};
struct SensorValueRange g_pedometerRange[] = {{10000.0, 0.0}};
struct SensorValueRange g_proximityRange[] = {{5.0, 0.0}};
struct SensorValueRange g_hallRange[] = {{1.0, 0.0}};
struct SensorValueRange g_barometerRange[] = {{1100.0, -1100.0}, {1100.0, -1100.0}};
struct SensorValueRange g_magneticRange[] = {{2000.0, -2000.0}, {2000.0, -2000.0}, {2000.0, -2000.0}};
struct SensorValueRange g_gyroscopeRange[] = {{35.0, -35.0}, {35.0, -35.0}, {35.0, -35.0}};
struct SensorValueRange g_gravityRange[] = {{78.0, -78.0}, {78.0, -78.0}, {78.0, -78.0}};
struct SensorDevelopmentList g_sensorList[] = {
{SENSOR_TYPE_NONE, "sensor_test", 1, 1, g_testRange},
{SENSOR_TYPE_ACCELEROMETER, "accelerometer", 1, 3, g_accelRange},
{SENSOR_TYPE_PEDOMETER, "pedometer", 1, 1, g_pedometerRange},
{SENSOR_TYPE_PROXIMITY, "proximity", 0, 1, g_proximityRange},
{SENSOR_TYPE_HALL, "hallrometer", 0, 1, g_hallRange},
{SENSOR_TYPE_BAROMETER, "barometer", 1, 2, g_barometerRange},
{SENSOR_TYPE_AMBIENT_LIGHT, "als", 1, 1, g_alsRange},
{SENSOR_TYPE_MAGNETIC_FIELD, "magnetometer", 1, 3, g_magneticRange},
{SENSOR_TYPE_GYROSCOPE, "gyroscope", 1, 3, g_gyroscopeRange},
{SENSOR_TYPE_GRAVITY, "gravity", 1, 3, g_gravityRange}
};
constexpr int LIST_NUM = sizeof(g_sensorList) / sizeof(g_sensorList[0]);
constexpr float EPSINON = 1e-6;
void SensorDataVerification(const float &data, const struct SensorDevelopmentList &sensorNode)
{
for (int32_t j = 0; j < sensorNode.dataDimension; ++j) {
printf("sensor id :[%d], data[%d]: %f\n\r", sensorNode.sensorTypeId, j + 1, *(&data + j));
if (sensorNode.dataForm == 0) {
if (abs(*(&data + j) - sensorNode.valueRange[j].highThreshold) < EPSINON ||
abs(*(&data + j) - sensorNode.valueRange[j].lowThreshold) < EPSINON) {
SensorCallbackImpl::sensorDataFlag &= 1;
} else {
SensorCallbackImpl::sensorDataFlag = 0;
printf("%s: %s Not expected\n\r", __func__, sensorNode.sensorName);
}
}
if (sensorNode.dataForm == 1) {
if (*(&data + j) >= sensorNode.valueRange[j].lowThreshold &&
*(&data + j) <= sensorNode.valueRange[j].highThreshold) {
SensorCallbackImpl::sensorDataFlag &= 1;
printf("sensorDataFlag = 1;");
} else {
SensorCallbackImpl::sensorDataFlag = 0;
printf("%s: %s Not expected\n\r", __func__, sensorNode.sensorName);
}
}
}
}
}
int32_t SensorCallbackImpl::OnDataEvent(const HdfSensorEvents& event)
{
void *origin = OsalMemCalloc(sizeof(uint8_t) * (event.dataLen));
uint8_t *tmp = static_cast<uint8_t*>(origin);
uint8_t *eventData = tmp;
for (auto value : event.data) {
*tmp++ = value;
}
for (int i = 0; i < LIST_NUM; ++i) {
if (event.sensorId == g_sensorList[i].sensorTypeId) {
float *data = (float*)eventData;
SensorDataVerification(*data, g_sensorList[i]);
}
}
OsalMemFree(origin);
return HDF_SUCCESS;
}
} // V1_1
} // Sensor
} // HDI
} // OHOS

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2021-2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_HDI_SENSOR_V1_1_SENSORCALLBACKIMPL_H
#define OHOS_HDI_SENSOR_V1_1_SENSORCALLBACKIMPL_H
#include <hdf_base.h>
#include "v1_1/isensor_callback.h"
namespace OHOS {
namespace HDI {
namespace Sensor {
namespace V1_1 {
class SensorCallbackImpl : public ISensorCallback {
public:
virtual ~SensorCallbackImpl() {}
int32_t OnDataEvent(const HdfSensorEvents& event) override;
static uint32_t sensorDataFlag;
};
} // V1_1
} // Sensor
} // HDI
} // OHOS
#endif // OHOS_HDI_SENSOR_V1_1_SENSORCALLBACKIMPL_H