/* * 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" constexpr int FORMAT_SD_CARD_SUCESS = 0; constexpr int FORMAT_SD_CARD_FAIL = -1; class HalTestTool { public: HalTestTool() = default; virtual ~HalTestTool() = default; void Init(void); void InitSdCardHal(std::shared_ptr &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> &allKeys); void SetAllLedsResult(std::map> &allLeds); void SetAllCamerasResult(std::map> &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 &vMock, const unsigned int &pressingTimeMs); private: void HalMockInit(std::shared_ptr &vMock); private: // About key hal void SetAllKeysResult(std::shared_ptr &vMock, std::map> &allKeys); std::shared_ptr SearchKey(const std::string &keyName); void InitAllKeysMock(std::map> &allKeys); void InitKeysMock(std::shared_ptr &vMock); private: // About led hal void SetAllLedsResult(std::shared_ptr &vMock, std::map> &allLeds); std::shared_ptr &SearchLed(const std::string &ledName); void InitAllLedsMock(std::map> &allLeds); void InitLedsMock(std::shared_ptr &vMock); private: // About camera hal void SetAllCamerasResult(std::shared_ptr &vMock, std::map> &allCameras); std::shared_ptr SearchCamera(const CameraType &cameraType); void InitAllCamerasMock(std::map> &allCameras); void InitCamerasMock(std::shared_ptr &vMock); protected: // About sd card hal void MockSdCardRemove(std::shared_ptr &mock); void MockSdCardInsert(std::shared_ptr &mock); void MockSdCardFormatReturn(std::shared_ptr &mock, const int &systemResult); // TODO: delete void MockSdCardAbnormal(std::shared_ptr &mock); public: static std::shared_ptr MakeKeyHalTest(const std::string &keyName); static std::shared_ptr MakeLedHalTest(const std::string &ledName); static std::shared_ptr MakeCameraHalTest(const CameraType &type); static void DestroyCameraHalTest(std::map> &allCamerasMock); private: std::shared_ptr mHalMock; std::map> mAllKeys; std::map> mAllLeds; std::map> mAllCameras; std::shared_ptr mSdCardHal; }; #endif