mirror of
				https://gitee.com/jiuyilian/embedded-framework.git
				synced 2025-10-24 18:20:15 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			59 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			2.2 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 KEY_CONTROL_MOCK_H
 | 
						|
#define KEY_CONTROL_MOCK_H
 | 
						|
#include "HalTestTool.h"
 | 
						|
#include "IHalCpp.h"
 | 
						|
#include "KeyControl.h"
 | 
						|
#include <thread>
 | 
						|
class KeyControlTest : public KeyControl, public VKeyHal
 | 
						|
{
 | 
						|
public:
 | 
						|
    KeyControlTest(const std::string &keyName);
 | 
						|
    virtual ~KeyControlTest() = default;
 | 
						|
    unsigned int GetStatusCheckPeriodMs(void) override { return PERIPHERAL_CHECK_PERIOD_MS; }
 | 
						|
    void SetKeyMonitor(std::shared_ptr<VKeyHalMonitor> &monitor) override;
 | 
						|
    void CheckKeyStatus(void) override;
 | 
						|
    void KeyEventTrigger(const std::string &keyName, const KeyEvent &event, const unsigned int &timeMs) override;
 | 
						|
    const std::string GetKeyName(void) override { return mKeyName; }
 | 
						|
 | 
						|
private:
 | 
						|
    virtual StatusCode KeyEventTriggerTrace(const std::string &keyName, const KeyEvent &event,
 | 
						|
                                            const unsigned int &timeMs)
 | 
						|
    {
 | 
						|
        return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
 | 
						|
    }
 | 
						|
 | 
						|
private:
 | 
						|
    const std::string mKeyName;
 | 
						|
    std::weak_ptr<VKeyHalMonitor> mMonitor;
 | 
						|
};
 | 
						|
class KeyControlMock : public KeyControlTest
 | 
						|
{
 | 
						|
public:
 | 
						|
    KeyControlMock(const std::string &keyName);
 | 
						|
    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);
 | 
						|
    MOCK_METHOD3(KeyEventTriggerTrace, StatusCode(const std::string &, const KeyEvent &, const unsigned int &));
 | 
						|
 | 
						|
private:
 | 
						|
    void KeyEventHappendOnce(std::shared_ptr<KeyControlMock> &mock, const unsigned int &pressingTimeMs);
 | 
						|
 | 
						|
private:
 | 
						|
    std::mutex mMutex;
 | 
						|
};
 | 
						|
#endif |