87 lines
3.9 KiB
C++
87 lines
3.9 KiB
C++
/*
|
|
* 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 HAL_TEST_TOOL_H
|
|
#define HAL_TEST_TOOL_H
|
|
#include "GtestUsing.h"
|
|
#include "IHalCpp.h"
|
|
#include "LedControl.h"
|
|
#include "LinuxApiMock.h"
|
|
class HalTestTool
|
|
{
|
|
public:
|
|
HalTestTool() = default;
|
|
virtual ~HalTestTool() = default;
|
|
void Init(void);
|
|
void InitSdCardHal(std::shared_ptr<LinuxTest> &mock);
|
|
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 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 CameraType &cameraType);
|
|
|
|
protected:
|
|
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: // 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);
|
|
|
|
protected: // About sd card hal
|
|
void MockSdCardRemove(std::shared_ptr<LinuxTest> &mock);
|
|
void MockSdCardInsert(std::shared_ptr<LinuxTest> &mock);
|
|
|
|
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;
|
|
std::shared_ptr<VSdCardHal> mSdCardHal;
|
|
};
|
|
#endif |