fix source ut bug

Signed-off-by: zhuxu <zhuxu29@huawei.com>
This commit is contained in:
zhuxu
2022-03-21 15:48:40 +08:00
parent 62cfd64dd7
commit d0e4b1adb6
3 changed files with 52 additions and 3 deletions
@@ -27,6 +27,7 @@
#include "dcamera_source_state_factory.h"
#include "dcamera_source_state_machine.h"
#include "mock_dcamera_source_dev.h"
#include "mock_dcamera_source_state_listener.h"
#include "anonymous_string.h"
#include "distributed_camera_constants.h"
@@ -45,6 +46,7 @@ public:
void TearDown();
std::shared_ptr<DCameraSourceDev> camDev_;
std::shared_ptr<ICameraStateListener> stateListener_;
std::shared_ptr<DCameraSourceStateMachine> stateMachine_;
private:
@@ -150,7 +152,8 @@ void DCameraSourceStateMachineTest::TearDownTestCase(void)
void DCameraSourceStateMachineTest::SetUp(void)
{
camDev_ = std::make_shared<MockDCameraSourceDev>(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0);
stateListener_ = std::make_shared<MockDCameraSourceStateListener>();
camDev_ = std::make_shared<MockDCameraSourceDev>(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, stateListener_);
stateMachine_ = std::make_shared<DCameraSourceStateMachine>(camDev_);
}
@@ -158,6 +161,7 @@ void DCameraSourceStateMachineTest::TearDown(void)
{
stateMachine_ = nullptr;
camDev_ = nullptr;
stateListener_ = nullptr;
}
/**
@@ -25,7 +25,8 @@ namespace OHOS {
namespace DistributedHardware {
class MockDCameraSourceDev : public DCameraSourceDev {
public:
MockDCameraSourceDev(std::string devId, std::string dhId) : DCameraSourceDev(devId, dhId, stateLisener_) {};
MockDCameraSourceDev(std::string devId, std::string dhId, std::shared_ptr<ICameraStateListener>& stateLisener)
: DCameraSourceDev(devId, dhId, stateLisener) {};
~MockDCameraSourceDev() = default;
int32_t ExecuteRegister(std::shared_ptr<DCameraRegistParam>& param)
@@ -76,7 +77,7 @@ public:
private:
std::string devId_;
std::string dhId_;
std::shared_ptr<ICameraStateListener> stateLisener_ = nullptr;
std::shared_ptr<ICameraStateListener> stateLisener_;
};
} // namespace DistributedHardware
} // namespace OHOS
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* 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_DISTRIBUTED_CAMERA_MOCKSOURCE_STATE_LISTENER_H
#define OHOS_DISTRIBUTED_CAMERA_MOCKSOURCE_STATE_LISTENER_H
#include "icamera_state_listener.h"
#include "distributed_camera_errno.h"
namespace OHOS {
namespace DistributedHardware {
class MockDCameraSourceStateListener : public ICameraStateListener {
public:
MockDCameraSourceStateListener() {};
~MockDCameraSourceStateListener() = default;
int32_t OnRegisterNotify(const std::string& devId, const std::string& dhId, const std::string& reqId,
int32_t status, std::string& data)
{
return DCAMERA_OK;
}
int32_t OnUnregisterNotify(const std::string& devId, const std::string& dhId, const std::string& reqId,
int32_t status, std::string& data)
{
return DCAMERA_OK;
}
};
}
}
#endif