Backup:MediaManager module.
This commit is contained in:
parent
ed9771b5b5
commit
9351b0611e
|
@ -16,8 +16,8 @@
|
|||
#include "ILog.h"
|
||||
#include <memory>
|
||||
camera_report_event::camera_report_event(const std::string &fileName, const std::string &filePath,
|
||||
const CameraEventType &type)
|
||||
: mFileName(fileName), mFilePath(filePath), mType(type)
|
||||
const CameraEvent &eventType, const CameraType &cameraType)
|
||||
: mFileName(fileName), mFilePath(filePath), mEventType(eventType), mCameraType(cameraType)
|
||||
{
|
||||
}
|
||||
void VKeyHalMonitor::KeyEventHappened(const std::string &keyName, const VirtualKeyEvent &event,
|
||||
|
@ -40,6 +40,10 @@ StatusCode VWifiHal::OpenApMode(void)
|
|||
void VCameraHalMonitor::ReportEvent(const CameraReportEvent &event)
|
||||
{
|
||||
}
|
||||
void VCameraHal::SetCameraMonitor(std::shared_ptr<VCameraHalMonitor> &monitor)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
}
|
||||
std::shared_ptr<IHalCpp> &IHalCpp::GetInstance(std::shared_ptr<IHalCpp> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<IHalCpp>();
|
||||
|
@ -76,5 +80,6 @@ StatusCode IHalCpp::GetWifiHal(std::shared_ptr<VWifiHal> &wifi)
|
|||
}
|
||||
StatusCode IHalCpp::GetCameraHal(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras)
|
||||
{
|
||||
LogWarning("STATUS_CODE_VIRTUAL_FUNCTION.\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
|
@ -29,7 +29,7 @@ enum class CameraType
|
|||
MAIN_CAMERA = 0,
|
||||
END
|
||||
};
|
||||
enum class CameraEventType
|
||||
enum class CameraEvent
|
||||
{
|
||||
PICTIRUE = 0,
|
||||
VIDEO,
|
||||
|
@ -38,10 +38,12 @@ enum class CameraEventType
|
|||
};
|
||||
typedef struct camera_report_event
|
||||
{
|
||||
camera_report_event(const std::string &fileName, const std::string &filePath, const CameraEventType &type);
|
||||
camera_report_event(const std::string &fileName, const std::string &filePath, const CameraEvent &eventType,
|
||||
const CameraType &cameraType);
|
||||
const std::string mFileName;
|
||||
const std::string mFilePath;
|
||||
const CameraEventType mType;
|
||||
const CameraEvent mEventType;
|
||||
const CameraType mCameraType;
|
||||
} CameraReportEvent;
|
||||
void CreateHalCppModule(void);
|
||||
void DestroyHalCppModule(void);
|
||||
|
@ -86,6 +88,7 @@ class VCameraHal
|
|||
public:
|
||||
VCameraHal() = default;
|
||||
virtual ~VCameraHal() = default;
|
||||
virtual void SetCameraMonitor(std::shared_ptr<VCameraHalMonitor> &monitor);
|
||||
};
|
||||
class IHalCpp
|
||||
{
|
||||
|
|
|
@ -27,7 +27,7 @@ aux_source_directory(./src SRC_FILES)
|
|||
set(TARGET_NAME MediaManager)
|
||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||
|
||||
target_link_libraries(${TARGET_NAME} StatusCode Log)
|
||||
target_link_libraries(${TARGET_NAME} Hal StatusCode Log)
|
||||
|
||||
if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true")
|
||||
add_custom_target(
|
||||
|
|
|
@ -70,6 +70,6 @@ public:
|
|||
static std::shared_ptr<IMediaManager> &GetInstance(std::shared_ptr<IMediaManager> *impl = nullptr);
|
||||
virtual const StatusCode Init(void);
|
||||
virtual const StatusCode UnInit(void);
|
||||
virtual StatusCode SetMeidaMonitor(std::shared_ptr<VMediaMonitor> &monitor);
|
||||
virtual StatusCode SetMediaMonitor(std::shared_ptr<VMediaMonitor> &monitor);
|
||||
};
|
||||
#endif
|
|
@ -55,7 +55,7 @@ const StatusCode IMediaManager::UnInit(void)
|
|||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode IMediaManager::SetMeidaMonitor(std::shared_ptr<VMediaMonitor> &monitor)
|
||||
StatusCode IMediaManager::SetMediaMonitor(std::shared_ptr<VMediaMonitor> &monitor)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
|
@ -13,15 +13,27 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#include "MediaManagerImpl.h"
|
||||
#include "ILog.h"
|
||||
const StatusCode MediaManagerImpl::Init(void)
|
||||
{
|
||||
IHalCpp::GetInstance()->GetCameraHal(mAllCameras);
|
||||
SetCamerasMonitor();
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
const StatusCode MediaManagerImpl::UnInit(void)
|
||||
{
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
StatusCode MediaManagerImpl::SetMeidaMonitor(std::shared_ptr<VMediaMonitor> &monitor)
|
||||
StatusCode MediaManagerImpl::SetMediaMonitor(std::shared_ptr<VMediaMonitor> &monitor)
|
||||
{
|
||||
mMediaMonitor = monitor;
|
||||
return CreateStatusCode(STATUS_CODE_OK);
|
||||
}
|
||||
void MediaManagerImpl::SetCamerasMonitor(void)
|
||||
{
|
||||
std::shared_ptr<VCameraHalMonitor> moniter = shared_from_this();
|
||||
for (const auto &camera : mAllCameras) {
|
||||
LogInfo("SetCameraMonitor.\n");
|
||||
camera.second->SetCameraMonitor(moniter);
|
||||
}
|
||||
}
|
|
@ -17,16 +17,22 @@
|
|||
#include "IHalCpp.h"
|
||||
#include "IMediaManager.h"
|
||||
#include <map>
|
||||
class MediaManagerImpl : public IMediaManager
|
||||
class MediaManagerImpl : public IMediaManager,
|
||||
public VCameraHalMonitor,
|
||||
public std::enable_shared_from_this<MediaManagerImpl>
|
||||
{
|
||||
public:
|
||||
MediaManagerImpl() = default;
|
||||
virtual ~MediaManagerImpl() = default;
|
||||
const StatusCode Init(void) override;
|
||||
const StatusCode UnInit(void) override;
|
||||
StatusCode SetMeidaMonitor(std::shared_ptr<VMediaMonitor> &monitor) override;
|
||||
StatusCode SetMediaMonitor(std::shared_ptr<VMediaMonitor> &monitor) override;
|
||||
|
||||
private:
|
||||
void SetCamerasMonitor(void);
|
||||
|
||||
private:
|
||||
std::map<CameraType, std::shared_ptr<VCameraHal>> mAllCameras;
|
||||
std::shared_ptr<VMediaMonitor> mMediaMonitor;
|
||||
};
|
||||
#endif
|
|
@ -24,41 +24,58 @@ public:
|
|||
virtual ~HalTestTool() = default;
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
/**
|
||||
* @brief Set the All Keys Result object
|
||||
* Due to the abstract design of the HAL for the number and type of buttons, it is necessary to externally
|
||||
* determine the instances of the buttons.
|
||||
* @param allKeys The instances of the buttons.
|
||||
*/
|
||||
void SetAllKeysResult(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
|
||||
void SetAllLedsResult(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds);
|
||||
// void SetKeyEvent(const std::string keyName, const KeyHalEvent &event); // TODO: unused function?
|
||||
void SetKeyClick(const std::string &keyName, const unsigned int &pressingTimeMs = 200);
|
||||
void SetAllCamerasResult(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras);
|
||||
void MockKeyClick(const std::string &keyName, const unsigned int &pressingTimeMs = 200);
|
||||
void SetLedStateExpectations(const std::string &ledName, const LedState &state, const unsigned int &aliveTimeMs,
|
||||
const unsigned int &blinkTimeMs);
|
||||
void MockReportCameraEvent(const std::string &fileName, const std::string &filePath, const CameraEvent &eventType,
|
||||
const CameraType &cameraType);
|
||||
|
||||
protected:
|
||||
virtual void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs)
|
||||
{
|
||||
}
|
||||
virtual void DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs);
|
||||
|
||||
private:
|
||||
void KeyEventHappendOnce(std::shared_ptr<VKeyHal> &vMock, const unsigned int &pressingTimeMs);
|
||||
|
||||
private:
|
||||
void HalMockInit(std::shared_ptr<IHalCpp> &vMock);
|
||||
|
||||
private: // About key hal
|
||||
void SetAllKeysResult(std::shared_ptr<IHalCpp> &vMock, std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
|
||||
std::shared_ptr<VKeyHal> SearchKey(const std::string &keyName);
|
||||
void InitAllKeysMock(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
|
||||
void InitKeysMock(std::shared_ptr<VKeyHal> &vMock);
|
||||
|
||||
private:
|
||||
private: // About led hal
|
||||
void SetAllLedsResult(std::shared_ptr<IHalCpp> &vMock, std::map<std::string, std::shared_ptr<VLedHal>> &allLeds);
|
||||
std::shared_ptr<VLedHal> &SearchLed(const std::string &ledName);
|
||||
void InitAllLedsMock(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds);
|
||||
void InitLedsMock(std::shared_ptr<VLedHal> &vMock);
|
||||
|
||||
private: // About camera hal
|
||||
void SetAllCamerasResult(std::shared_ptr<IHalCpp> &vMock,
|
||||
std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras);
|
||||
std::shared_ptr<VCameraHal> SearchCamera(const CameraType &cameraType);
|
||||
void InitAllCamerasMock(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras);
|
||||
void InitCamerasMock(std::shared_ptr<VCameraHal> &vMock);
|
||||
|
||||
public:
|
||||
static std::shared_ptr<VKeyHal> MakeKeyHalTest(const std::string &keyName);
|
||||
static std::shared_ptr<VLedHal> MakeLedHalTest(const std::string &ledName);
|
||||
static std::shared_ptr<VCameraHal> MakeCameraHalTest(const CameraType &type);
|
||||
|
||||
private:
|
||||
std::shared_ptr<IHalCpp> mHalMock;
|
||||
std::map<std::string, std::shared_ptr<VKeyHal>> mAllKeys;
|
||||
std::map<std::string, std::shared_ptr<VLedHal>> mAllLeds;
|
||||
std::map<CameraType, std::shared_ptr<VCameraHal>> mAllCameras;
|
||||
};
|
||||
#endif
|
42
test/hal/tool/src/CameraHalMock.cpp
Normal file
42
test/hal/tool/src/CameraHalMock.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* 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 "CameraHalMock.h"
|
||||
#include "HalCppMock.h"
|
||||
#include "ILog.h"
|
||||
CameraHalTest::CameraHalTest(const CameraType &cameraType) : mCameraType(cameraType)
|
||||
{
|
||||
}
|
||||
void CameraHalTest::SetCameraMonitor(std::shared_ptr<VCameraHalMonitor> &monitor)
|
||||
{
|
||||
LogInfo("CameraHalTest::SetCameraMonitor.\n");
|
||||
mMonitor = monitor;
|
||||
SetCameraMonitorTrace(monitor);
|
||||
}
|
||||
void CameraHalTest::SetCameraMonitorTrace(std::shared_ptr<VCameraHalMonitor> &monitor)
|
||||
{
|
||||
LogWarning("SetCameraMonitorTrace.\n");
|
||||
}
|
||||
CameraHalMock::CameraHalMock(const CameraType &cameraType) : CameraHalTest(cameraType)
|
||||
{
|
||||
}
|
||||
void CameraHalMock::MockReportCameraEvent(const CameraReportEvent &event)
|
||||
{
|
||||
auto monitor = mMonitor.lock();
|
||||
if (mMonitor.expired()) {
|
||||
LogError("monitor is nullptr.\n");
|
||||
return;
|
||||
}
|
||||
monitor->ReportEvent(event);
|
||||
}
|
41
test/hal/tool/src/CameraHalMock.h
Normal file
41
test/hal/tool/src/CameraHalMock.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Fancy Code.
|
||||
* 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 CAMERA_HAL_MOCK_H
|
||||
#define CAMERA_HAL_MOCK_H
|
||||
#include "HalCpp.h"
|
||||
#include "HalTestTool.h"
|
||||
class CameraHalTest : public VCameraHal
|
||||
{
|
||||
public:
|
||||
CameraHalTest(const CameraType &cameraType);
|
||||
virtual ~CameraHalTest() = default;
|
||||
void SetCameraMonitor(std::shared_ptr<VCameraHalMonitor> &monitor) override;
|
||||
|
||||
private:
|
||||
virtual void SetCameraMonitorTrace(std::shared_ptr<VCameraHalMonitor> &monitor);
|
||||
|
||||
protected:
|
||||
const CameraType mCameraType;
|
||||
std::weak_ptr<VCameraHalMonitor> mMonitor;
|
||||
};
|
||||
class CameraHalMock : public CameraHalTest
|
||||
{
|
||||
public:
|
||||
CameraHalMock(const CameraType &cameraType);
|
||||
virtual ~CameraHalMock() = default;
|
||||
void MockReportCameraEvent(const CameraReportEvent &event);
|
||||
MOCK_METHOD1(SetCameraMonitorTrace, void(std::shared_ptr<VCameraHalMonitor> &));
|
||||
};
|
||||
#endif
|
|
@ -51,8 +51,22 @@ StatusCode HalCppTest::GetWifiHal(std::shared_ptr<VWifiHal> &wifi)
|
|||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode HalCppTest::GetCameraHal(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras)
|
||||
{
|
||||
LogInfo("HalCppTest::GetCameraHal\n");
|
||||
StatusCode code = GetCameraHalTrace(allCameras);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return HalCpp::GetCameraHal(allCameras);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
StatusCode HalCppTest::GetWifiHalTrace(std::shared_ptr<VWifiHal> &wifi)
|
||||
{
|
||||
LogInfo("HalCppTest::GetWifiHalTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
StatusCode HalCppTest::GetCameraHalTrace(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras)
|
||||
{
|
||||
LogInfo("HalCppTest::GetCameraHalTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
|
@ -24,11 +24,13 @@ public:
|
|||
StatusCode GetAllLeds(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds) override;
|
||||
StatusCode GetAllKeys(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys) override;
|
||||
StatusCode GetWifiHal(std::shared_ptr<VWifiHal> &wifi) override;
|
||||
StatusCode GetCameraHal(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras) override;
|
||||
|
||||
protected:
|
||||
virtual StatusCode GetAllLedsTrace(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds);
|
||||
virtual StatusCode GetAllKeysTrace(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
|
||||
virtual StatusCode GetWifiHalTrace(std::shared_ptr<VWifiHal> &wifi);
|
||||
virtual StatusCode GetCameraHalTrace(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras);
|
||||
};
|
||||
class HalCppMock : public HalCppTest
|
||||
{
|
||||
|
@ -38,5 +40,6 @@ public:
|
|||
MOCK_METHOD1(GetAllLedsTrace, StatusCode(std::map<std::string, std::shared_ptr<VLedHal>> &));
|
||||
MOCK_METHOD1(GetAllKeysTrace, StatusCode(std::map<std::string, std::shared_ptr<VKeyHal>> &));
|
||||
MOCK_METHOD1(GetWifiHalTrace, StatusCode(std::shared_ptr<VWifiHal> &));
|
||||
MOCK_METHOD1(GetCameraHalTrace, StatusCode(std::map<CameraType, std::shared_ptr<VCameraHal>> &));
|
||||
};
|
||||
#endif
|
|
@ -13,6 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#include "HalTestTool.h"
|
||||
#include "CameraHalMock.h"
|
||||
#include "HalCppMock.h"
|
||||
#include "HalMakePtrTest.h"
|
||||
#include "ILog.h"
|
||||
|
@ -47,31 +48,22 @@ void HalTestTool::SetAllLedsResult(std::map<std::string, std::shared_ptr<VLedHal
|
|||
SetAllLedsResult(halMock, allLeds);
|
||||
mAllLeds = allLeds;
|
||||
}
|
||||
// void HalTestTool::SetKeyEvent(const std::string keyName, const KeyHalEvent &event)
|
||||
// {
|
||||
// std::shared_ptr<VKeyHal> key = SearchKey(keyName);
|
||||
// if (!key) {
|
||||
// LogError("Can't set key event, key not found.\n");
|
||||
// return;
|
||||
// }
|
||||
// std::shared_ptr<KeyControlMock> keyMock = std::dynamic_pointer_cast<KeyControlMock>(key);
|
||||
// if (keyMock) {
|
||||
// keyMock->SetKeyEvent(event);
|
||||
// }
|
||||
// else {
|
||||
// LogWarning("Key mock error.\n");
|
||||
// }
|
||||
// }
|
||||
void HalTestTool::SetKeyClick(const std::string &keyName, const unsigned int &pressingTimeMs)
|
||||
void HalTestTool::SetAllCamerasResult(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras)
|
||||
{
|
||||
std::shared_ptr<IHalCpp> halMock = mHalMock;
|
||||
SetAllCamerasResult(halMock, allCameras);
|
||||
mAllCameras = allCameras;
|
||||
}
|
||||
void HalTestTool::MockKeyClick(const std::string &keyName, const unsigned int &pressingTimeMs)
|
||||
{
|
||||
std::shared_ptr<VKeyHal> key = SearchKey(keyName);
|
||||
if (!key) {
|
||||
LogError("Can't set key event, key not found.\n");
|
||||
LogError("Can't mock key event, key not found.\n");
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<KeyControlMock> keyMock = std::dynamic_pointer_cast<KeyControlMock>(key);
|
||||
if (keyMock) {
|
||||
if (keyMock->SetKeyClick(pressingTimeMs)) {
|
||||
if (keyMock->MockKeyClick(pressingTimeMs)) {
|
||||
DeviceManagerNotice(keyName, pressingTimeMs);
|
||||
}
|
||||
}
|
||||
|
@ -96,6 +88,26 @@ void HalTestTool::SetLedStateExpectations(const std::string &ledName, const LedS
|
|||
// }
|
||||
LedControlMock::SetLedStateMock(led, state, aliveTimeMs, blinkTimeMs);
|
||||
}
|
||||
void HalTestTool::MockReportCameraEvent(const std::string &fileName, const std::string &filePath,
|
||||
const CameraEvent &eventType, const CameraType &cameraType)
|
||||
{
|
||||
std::shared_ptr<VCameraHal> camera = SearchCamera(cameraType);
|
||||
if (!camera) {
|
||||
LogError("Can't mock camera event, key not found.\n");
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<CameraHalMock> cameraMock = std::dynamic_pointer_cast<CameraHalMock>(camera);
|
||||
if (cameraMock) {
|
||||
CameraReportEvent report(fileName, filePath, eventType, cameraType);
|
||||
cameraMock->MockReportCameraEvent(report);
|
||||
}
|
||||
else {
|
||||
LogWarning("camera mock error.\n");
|
||||
}
|
||||
}
|
||||
void HalTestTool::DeviceManagerNotice(const std::string &keyName, const unsigned int &pressingTimeMs)
|
||||
{
|
||||
}
|
||||
void HalTestTool::KeyEventHappendOnce(std::shared_ptr<VKeyHal> &vMock, const unsigned int &pressingTimeMs)
|
||||
{
|
||||
std::shared_ptr<KeyControlMock> mock = std::dynamic_pointer_cast<KeyControlMock>(vMock);
|
||||
|
@ -162,6 +174,8 @@ void HalTestTool::HalMockInit(std::shared_ptr<IHalCpp> &vMock)
|
|||
std::shared_ptr<VWifiHal> wifiHal = std::make_shared<WifiHalMock>();
|
||||
EXPECT_CALL(*mock.get(), GetWifiHalTrace(_))
|
||||
.WillRepeatedly(DoAll(SetArgReferee<0>(wifiHal), Return(CreateStatusCode(STATUS_CODE_OK))));
|
||||
EXPECT_CALL(*mock.get(), GetCameraHalTrace(_))
|
||||
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
}
|
||||
void HalTestTool::SetAllKeysResult(std::shared_ptr<IHalCpp> &vMock,
|
||||
std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys)
|
||||
|
@ -230,6 +244,60 @@ void HalTestTool::InitLedsMock(std::shared_ptr<VLedHal> &vMock)
|
|||
constexpr int LED_SHOULD_NOT_BE_CONTROLED_WHEN_NOBODY_CONTROL_IT = 0;
|
||||
EXPECT_CALL(*mock.get(), SetLedStateTrace(_)).Times(LED_SHOULD_NOT_BE_CONTROLED_WHEN_NOBODY_CONTROL_IT);
|
||||
}
|
||||
void HalTestTool::SetAllCamerasResult(std::shared_ptr<IHalCpp> &vMock,
|
||||
std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras)
|
||||
{
|
||||
std::shared_ptr<HalCppMock> mock = std::dynamic_pointer_cast<HalCppMock>(vMock);
|
||||
if (!mock) {
|
||||
LogError("vMock error.\n");
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* Note: The SetArgReference function cannot be used here, as it will prevent the smart pointer from being released
|
||||
* within the TEST range, resulting in an error only being reported after all test cases have finished running.
|
||||
* Can't use:
|
||||
* EXPECT_CALL(*mock.get(), GetCameraHalTrace(_))
|
||||
* .WillRepeatedly(DoAll(SetArgReferee<0>(allCameras), Return(CreateStatusCode(STATUS_CODE_OK))));
|
||||
*/
|
||||
auto getAllCameras = [=, &allCameras](std::map<CameraType, std::shared_ptr<VCameraHal>> &setAllCameras) {
|
||||
setAllCameras = allCameras;
|
||||
};
|
||||
EXPECT_CALL(*mock.get(), GetCameraHalTrace(_))
|
||||
.WillRepeatedly(DoAll(WithArgs<0>(Invoke(getAllCameras)), Return(CreateStatusCode(STATUS_CODE_OK))));
|
||||
InitAllCamerasMock(allCameras);
|
||||
}
|
||||
std::shared_ptr<VCameraHal> HalTestTool::SearchCamera(const CameraType &cameraType)
|
||||
{
|
||||
std::shared_ptr<CameraHalMock> mock;
|
||||
std::map<CameraType, std::shared_ptr<VCameraHal>>::iterator iter;
|
||||
iter = mAllCameras.find(cameraType);
|
||||
if (iter != mAllCameras.end()) {
|
||||
mock = std::dynamic_pointer_cast<CameraHalMock>(mAllCameras[cameraType]);
|
||||
}
|
||||
else {
|
||||
LogWarning("Can't found the camera control.\n");
|
||||
}
|
||||
return mock;
|
||||
}
|
||||
void HalTestTool::InitAllCamerasMock(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras)
|
||||
{
|
||||
std::map<CameraType, std::shared_ptr<VCameraHal>>::iterator iter;
|
||||
for (iter = allCameras.begin(); iter != allCameras.end(); ++iter) {
|
||||
std::shared_ptr<VCameraHal> cameraHal = iter->second;
|
||||
InitCamerasMock(cameraHal);
|
||||
}
|
||||
}
|
||||
void HalTestTool::InitCamerasMock(std::shared_ptr<VCameraHal> &vMock)
|
||||
{
|
||||
std::shared_ptr<CameraHalMock> mock = std::dynamic_pointer_cast<CameraHalMock>(vMock);
|
||||
if (!mock) {
|
||||
LogError("vMock error.\n");
|
||||
return;
|
||||
}
|
||||
constexpr int USER_SHOULD_SET_CAMERA_MONITER = 1;
|
||||
EXPECT_CALL(*mock.get(), SetCameraMonitorTrace(_)).Times(USER_SHOULD_SET_CAMERA_MONITER);
|
||||
}
|
||||
std::shared_ptr<VKeyHal> HalTestTool::MakeKeyHalTest(const std::string &keyName)
|
||||
{
|
||||
std::shared_ptr<VKeyHal> key = std::make_shared<KeyControlMock>(keyName);
|
||||
|
@ -239,4 +307,9 @@ std::shared_ptr<VLedHal> HalTestTool::MakeLedHalTest(const std::string &ledName)
|
|||
{
|
||||
std::shared_ptr<VLedHal> led = std::make_shared<LedControlMock>(ledName);
|
||||
return led;
|
||||
}
|
||||
std::shared_ptr<VCameraHal> HalTestTool::MakeCameraHalTest(const CameraType &type)
|
||||
{
|
||||
std::shared_ptr<VCameraHal> camera = std::make_shared<CameraHalMock>(type);
|
||||
return camera;
|
||||
}
|
|
@ -16,16 +16,13 @@
|
|||
#include "ILog.h"
|
||||
KeyControlTest::KeyControlTest(const std::string &keyName) : mKeyName(keyName)
|
||||
{
|
||||
//
|
||||
}
|
||||
void KeyControlTest::SetKeyMonitor(std::shared_ptr<VKeyHalMonitor> &monitor)
|
||||
{
|
||||
//
|
||||
mMonitor = monitor;
|
||||
}
|
||||
void KeyControlTest::CheckKeyStatus(void)
|
||||
{
|
||||
//
|
||||
TimerKeyEventTrigger(KeyHalEvent::PRESSING);
|
||||
}
|
||||
void KeyControlTest::KeyEventTrigger(const std::string &keyName, const KeyEvent &event, const unsigned int &timeMs)
|
||||
|
@ -41,14 +38,12 @@ void KeyControlTest::KeyEventTrigger(const std::string &keyName, const KeyEvent
|
|||
}
|
||||
KeyControlMock::KeyControlMock(const std::string &keyName) : KeyControlTest(keyName)
|
||||
{
|
||||
//
|
||||
}
|
||||
void KeyControlMock::SetKeyEvent(const KeyHalEvent &event)
|
||||
{
|
||||
//
|
||||
KeyHalEventTrigger(event);
|
||||
}
|
||||
bool KeyControlMock::SetKeyClick(const unsigned int &pressingTimeMs)
|
||||
bool KeyControlMock::MockKeyClick(const unsigned int &pressingTimeMs)
|
||||
{
|
||||
if (mMutex.try_lock()) {
|
||||
auto keyClickThread = [=](std::shared_ptr<KeyControlMock> key) {
|
||||
|
@ -64,7 +59,7 @@ bool KeyControlMock::SetKeyClick(const unsigned int &pressingTimeMs)
|
|||
clickThread.detach();
|
||||
return true;
|
||||
}
|
||||
LogWarning("SetKeyClick failed, becase key was lock.\n");
|
||||
LogWarning("MockKeyClick failed, becase key was lock.\n");
|
||||
return false;
|
||||
}
|
||||
void KeyControlMock::KeyEventHappendOnce(std::shared_ptr<KeyControlMock> &mock, const unsigned int &pressingTimeMs)
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
virtual ~KeyControlMock() = default;
|
||||
// void KeyEventTrigger(const std::string &keyName, const KeyEvent &event, const unsigned int &timeMs) override;
|
||||
void SetKeyEvent(const KeyHalEvent &event);
|
||||
bool SetKeyClick(const unsigned int &pressingTimeMs = 200);
|
||||
bool MockKeyClick(const unsigned int &pressingTimeMs = 200);
|
||||
MOCK_METHOD3(KeyEventTriggerTrace, StatusCode(const std::string &, const KeyEvent &, const unsigned int &));
|
||||
|
||||
private:
|
||||
|
|
|
@ -13,32 +13,4 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#include "HalCppMock.h"
|
||||
#include "ILog.h"
|
||||
// StatusCode WifiHalTest::GetAllLeds(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds)
|
||||
// {
|
||||
// LogInfo("WifiHalTest::GetAllLeds\n");
|
||||
// StatusCode code = GetAllLedsTrace(allLeds);
|
||||
// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
// return HalCpp::GetAllLeds(allLeds);
|
||||
// }
|
||||
// return code;
|
||||
// }
|
||||
// StatusCode WifiHalTest::GetAllKeys(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys)
|
||||
// {
|
||||
// LogInfo("WifiHalTest::GetAllKeys\n");
|
||||
// StatusCode code = GetAllKeysTrace(allKeys);
|
||||
// if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
// return HalCpp::GetAllKeys(allKeys);
|
||||
// }
|
||||
// return code;
|
||||
// }
|
||||
// StatusCode WifiHalTest::GetAllLedsTrace(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds)
|
||||
// {
|
||||
// LogInfo("WifiHalTest::GetAllLedsTrace\n");
|
||||
// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
// }
|
||||
// StatusCode WifiHalTest::GetAllKeysTrace(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys)
|
||||
// {
|
||||
// LogInfo("WifiHalTest::GetAllKeysTrace\n");
|
||||
// return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
// }
|
||||
#include "ILog.h"
|
|
@ -21,19 +21,11 @@ class WifiHalTest : public VWifiHal
|
|||
public:
|
||||
WifiHalTest() = default;
|
||||
virtual ~WifiHalTest() = default;
|
||||
// StatusCode GetAllLeds(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds) override;
|
||||
// StatusCode GetAllKeys(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys) override;
|
||||
|
||||
protected:
|
||||
// virtual StatusCode GetAllLedsTrace(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds);
|
||||
// virtual StatusCode GetAllKeysTrace(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
|
||||
};
|
||||
class WifiHalMock : public WifiHalTest
|
||||
{
|
||||
public:
|
||||
WifiHalMock() = default;
|
||||
virtual ~WifiHalMock() = default;
|
||||
// MOCK_METHOD1(GetAllLedsTrace, StatusCode(std::map<std::string, std::shared_ptr<VLedHal>> &));
|
||||
// MOCK_METHOD1(GetAllKeysTrace, StatusCode(std::map<std::string, std::shared_ptr<VKeyHal>> &));
|
||||
};
|
||||
#endif
|
|
@ -92,7 +92,7 @@ TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_KeyShortPress)
|
|||
IDeviceManager::GetInstance()->Init();
|
||||
std::shared_ptr<VKeyMonitor> monitor = std::make_shared<KeyMonitorMock>();
|
||||
IDeviceManager::GetInstance()->SetAllKeysMonitor(monitor);
|
||||
SetKeyClick(KEY_TEST); // Simulate pressing a button.
|
||||
MockKeyClick(KEY_TEST); // Simulate pressing a button.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IDeviceManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_KeyInvalidShort
|
|||
IDeviceManager::GetInstance()->Init();
|
||||
std::shared_ptr<VKeyMonitor> monitor = std::make_shared<KeyMonitorMock>();
|
||||
IDeviceManager::GetInstance()->SetAllKeysMonitor(monitor);
|
||||
SetKeyClick(KEY_TEST, 50); // Simulate pressing a button.
|
||||
MockKeyClick(KEY_TEST, 50); // Simulate pressing a button.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
IDeviceManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_KeyLongPress)
|
|||
IDeviceManager::GetInstance()->Init();
|
||||
std::shared_ptr<VKeyMonitor> monitor = std::make_shared<KeyMonitorMock>();
|
||||
IDeviceManager::GetInstance()->SetAllKeysMonitor(monitor);
|
||||
SetKeyClick(KEY_TEST, 1000); // Simulate pressing a button.
|
||||
MockKeyClick(KEY_TEST, 1000); // Simulate pressing a button.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
IDeviceManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
@ -138,9 +138,9 @@ TEST_F(DeviceManagerTest, INTEGRATION_DeviceManager_EXAMPLE_AUTO_SetKeyMonitor)
|
|||
IDeviceManager::GetInstance()->Init();
|
||||
std::shared_ptr<VKeyMonitor> monitor = std::make_shared<KeyMonitorMock>();
|
||||
IDeviceManager::GetInstance()->SetAllKeysMonitor(monitor);
|
||||
SetKeyClick(KEY_TEST, 1000); // Simulate pressing a button.
|
||||
MockKeyClick(KEY_TEST, 1000); // Simulate pressing a button.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
SetKeyClick(KEY_TEST, 1000); // Simulate pressing a button.
|
||||
MockKeyClick(KEY_TEST, 1000); // Simulate pressing a button.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
IDeviceManager::GetInstance()->UnInit();
|
||||
}
|
||||
|
|
|
@ -10,12 +10,12 @@ include_directories(
|
|||
${UTILS_SOURCE_PATH}/Log/include
|
||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||
# ${UTILS_SOURCE_PATH}/KeyControl/include
|
||||
# ${UTILS_SOURCE_PATH}/LedControl/include
|
||||
${UTILS_SOURCE_PATH}/LedControl/include
|
||||
# ${UTILS_SOURCE_PATH}/WebServer/include
|
||||
# ${HAL_SOURCE_PATH}/include
|
||||
${HAL_SOURCE_PATH}/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/MediaManager/include
|
||||
${TEST_SOURCE_PATH}
|
||||
# ${TEST_SOURCE_PATH}/hal/tool/include
|
||||
${TEST_SOURCE_PATH}/hal/tool/include
|
||||
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include
|
||||
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include
|
||||
)
|
||||
|
@ -33,7 +33,7 @@ endif()
|
|||
|
||||
set(TARGET_NAME MediaManagerTest)
|
||||
add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES})
|
||||
target_link_libraries(${TARGET_NAME} MediaManager MediaManagerTestTool gtest gmock pthread)
|
||||
target_link_libraries(${TARGET_NAME} MediaManager MediaManagerTestTool HalTestTool gtest gmock pthread)
|
||||
if(${TEST_COVERAGE} MATCHES "true")
|
||||
target_link_libraries(${TARGET_NAME} gcov)
|
||||
endif()
|
||||
|
|
|
@ -13,14 +13,16 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#include "GtestUsing.h"
|
||||
#include "HalTestTool.h"
|
||||
#include "ILog.h"
|
||||
#include "IMediaManager.h"
|
||||
#include "MediaManagerTestTool.h"
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <thread>
|
||||
namespace MediaManagerTest
|
||||
{
|
||||
class MediaManagerTest : public testing::Test
|
||||
class MediaManagerTest : public testing::Test, public MediaManagerTestTool, public HalTestTool
|
||||
{
|
||||
public:
|
||||
MediaManagerTest()
|
||||
|
@ -40,35 +42,50 @@ public:
|
|||
}
|
||||
virtual void SetUp()
|
||||
{
|
||||
// HalTestTool::Init();
|
||||
// AppManagerTestTool::Init();
|
||||
// CreateHalCppModule();
|
||||
CreateAllCamerasMcok();
|
||||
HalTestTool::Init();
|
||||
MediaManagerTestTool::Init();
|
||||
CreateHalCppModule();
|
||||
CreateMediaManagerModule();
|
||||
}
|
||||
virtual void TearDown()
|
||||
{
|
||||
// AppManagerTestTool::UnInit();
|
||||
// HalTestTool::UnInit();
|
||||
MediaManagerTestTool::UnInit();
|
||||
HalTestTool::UnInit();
|
||||
DestroyMediaManagerModule();
|
||||
// DestroyHalCppModule();
|
||||
DestroyHalCppModule();
|
||||
DestroyAllCamerasMock();
|
||||
}
|
||||
|
||||
private:
|
||||
void CreateAllCamerasMcok(void)
|
||||
{
|
||||
std::shared_ptr<VCameraHal> camera = HalTestTool::MakeCameraHalTest(CameraType::MAIN_CAMERA);
|
||||
mAllCamerasMock[CameraType::MAIN_CAMERA] = camera;
|
||||
}
|
||||
void DestroyAllCamerasMock(void)
|
||||
{
|
||||
mAllCamerasMock.clear();
|
||||
}
|
||||
|
||||
protected:
|
||||
// const AppParam mAppParam;
|
||||
std::map<CameraType, std::shared_ptr<VCameraHal>> mAllCamerasMock;
|
||||
};
|
||||
// ../output_files/test/bin/MediaManagerTest --gtest_filter=MediaManagerTest.INTEGRATION_MediaManager_EXAMPLE_Demo0
|
||||
TEST_F(MediaManagerTest, INTEGRATION_MediaManager_EXAMPLE_Demo0)
|
||||
{
|
||||
// std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
|
||||
// IAppManager::GetInstance()->Init(mAppParam);
|
||||
// IAppManager::GetInstance()->SetAppMonitor(monitor);
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
SetAllCamerasResult(mAllCamerasMock);
|
||||
std::shared_ptr<VMediaMonitor> monitor = MediaManagerTestTool::MakeMonitorMock();
|
||||
IMediaManager::GetInstance()->Init();
|
||||
IMediaManager::GetInstance()->SetMediaMonitor(monitor);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
MockReportCameraEvent("test name", "test path", CameraEvent::PICTIRUE, CameraType::MAIN_CAMERA);
|
||||
// MockAppClientConnect();
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
// MockSetRecordingStatus(RecordingStatus::RECORDING_START);
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||
// IAppManager::GetInstance()->UnInit();
|
||||
IMediaManager::GetInstance()->Init();
|
||||
IMediaManager::GetInstance()->UnInit();
|
||||
}
|
||||
} // namespace MediaManagerTest
|
|
@ -32,5 +32,8 @@ private:
|
|||
private:
|
||||
std::shared_ptr<IMediaManager> mMediaManagerMock;
|
||||
std::shared_ptr<VMediaMonitor> mMediaMonitorMock;
|
||||
|
||||
public:
|
||||
static std::shared_ptr<VMediaMonitor> MakeMonitorMock(void);
|
||||
};
|
||||
#endif
|
|
@ -37,11 +37,9 @@ void CancelOverrideMediaManagerMakePtrObject(void)
|
|||
}
|
||||
MediaManagerMakePtrTest::MediaManagerMakePtrTest()
|
||||
{
|
||||
//
|
||||
}
|
||||
MediaManagerMakePtrTest::~MediaManagerMakePtrTest()
|
||||
{
|
||||
//
|
||||
mMediaManagerMock.reset();
|
||||
}
|
||||
const StatusCode MediaManagerMakePtrTest::CreateMediaManagerModule(std::shared_ptr<IMediaManager> &impl)
|
||||
|
|
|
@ -14,17 +14,17 @@
|
|||
*/
|
||||
#include "MediaManagerMock.h"
|
||||
#include "ILog.h"
|
||||
StatusCode MediaManagerTest::SetMeidaMonitor(std::shared_ptr<VMediaMonitor> &monitor)
|
||||
StatusCode MediaManagerTest::SetMediaMonitor(std::shared_ptr<VMediaMonitor> &monitor)
|
||||
{
|
||||
LogInfo("MediaManagerTest::SetAppMonitor\n");
|
||||
LogInfo("MediaManagerTest::SetMediaMonitor\n");
|
||||
StatusCode code = SetMediaMonitorTrace(monitor);
|
||||
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||
return MediaManagerImpl::SetMeidaMonitor(monitor);
|
||||
return MediaManagerImpl::SetMediaMonitor(monitor);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
const StatusCode MediaManagerTest::SetMediaMonitorTrace(std::shared_ptr<VMediaMonitor> &monitor)
|
||||
{
|
||||
LogInfo("SetMediaMonitorTrace::SetAppMonitorTrace\n");
|
||||
LogInfo("SetMediaMonitorTrace::SetMediaMonitorTrace\n");
|
||||
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
|
@ -21,8 +21,8 @@ class MediaManagerTest : public MediaManagerImpl
|
|||
public:
|
||||
MediaManagerTest() = default;
|
||||
virtual ~MediaManagerTest() = default;
|
||||
// const StatusCode SetMeidaMonitor(std::shared_ptr<VMediaMonitor> &monitor) override;
|
||||
StatusCode SetMeidaMonitor(std::shared_ptr<VMediaMonitor> &monitor) override;
|
||||
// const StatusCode SetMediaMonitor(std::shared_ptr<VMediaMonitor> &monitor) override;
|
||||
StatusCode SetMediaMonitor(std::shared_ptr<VMediaMonitor> &monitor) override;
|
||||
|
||||
protected:
|
||||
virtual const StatusCode SetMediaMonitorTrace(std::shared_ptr<VMediaMonitor> &monitor);
|
||||
|
|
|
@ -88,4 +88,15 @@ void MediaManagerTestTool::MediaMonitorInit(std::shared_ptr<VMediaMonitor> &vMoc
|
|||
// EXPECT_CALL(*mock.get(), MediaClientConnectedTrace(_))
|
||||
// .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||
}
|
||||
}
|
||||
std::shared_ptr<VMediaMonitor> MediaManagerTestTool::MakeMonitorMock(void)
|
||||
{
|
||||
class Monitor : public MediaMonitorMock, public MediaMonitorTest
|
||||
{
|
||||
public:
|
||||
Monitor() = default;
|
||||
virtual ~Monitor() = default;
|
||||
};
|
||||
std::shared_ptr<VMediaMonitor> monitor = std::make_shared<Monitor>();
|
||||
return monitor;
|
||||
}
|
Loading…
Reference in New Issue
Block a user