hunting/test/hal/tool/include/HalTestTool.h
2024-02-19 10:14:51 -08:00

102 lines
3.6 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 "HalCpp.h"
#include "KeyControl.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
using ::testing::_;
using ::testing::Action;
using ::testing::ActionInterface;
using ::testing::AnyNumber;
using ::testing::Assign;
using ::testing::AtLeast;
using ::testing::ByMove;
using ::testing::ByRef;
using ::testing::DefaultValue;
using ::testing::DoAll;
using ::testing::DoDefault;
using ::testing::IgnoreResult;
using ::testing::Invoke;
using ::testing::InvokeWithoutArgs;
using ::testing::MakePolymorphicAction;
using ::testing::PolymorphicAction;
using ::testing::Return;
using ::testing::ReturnNew;
using ::testing::ReturnNull;
using ::testing::ReturnPointee;
using ::testing::ReturnRef;
using ::testing::ReturnRefOfCopy;
using ::testing::ReturnRoundRobin;
using ::testing::SaveArg;
using ::testing::SetArgPointee;
using ::testing::SetArgReferee;
using ::testing::SetArgumentPointee;
using ::testing::Unused;
using ::testing::WithArgs;
using ::testing::internal::BuiltInDefaultValue;
class HalCppTest : public HalCpp
{
public:
HalCppTest() = default;
virtual ~HalCppTest() = 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 HalCppMock : public HalCppTest
{
public:
HalCppMock() = default;
virtual ~HalCppMock() = 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>> &));
};
class HalTestTool
{
public:
HalTestTool() = default;
virtual ~HalTestTool() = default;
void Init(void);
void UnInit(void);
void SetAllKeysResult(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
void SetKeyEvent(const std::string keyName, const KeyHalEvent &event);
void SetKeyClick(const std::string &keyName, const unsigned int &pressingTimeMs = 200);
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<HalCppMock> &mock);
void SetAllKeysResult(std::shared_ptr<HalCppMock> &mock, 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);
public:
static std::shared_ptr<VKeyHal> MakeKeyHalTest(const std::string &keyName);
private:
std::shared_ptr<HalCppMock> mHalMock;
std::map<std::string, std::shared_ptr<VKeyHal>> mAllKeys;
};
#endif