<commit_before>#include "gtest/gtest.h"
#include "MockupInputManager.hpp"
#include "MockupInputEventListener.hpp"
#include "MockupKey.hpp"

using namespace rd;

//-- Class for the setup of each test
//--------------------------------------------------------------------------------------
class MockupInputManagerTest : public testing::Test
{
    public:
        virtual void SetUp()
        {
            ASSERT_TRUE(MockupInputManager::RegisterManager());
            inputManager = (MockupInputManager *) MockupInputManager::getInputManager(MockupInputManager::id);
            ASSERT_TRUE(inputManager);
        }

        virtual void TearDown()
        {
            ASSERT_TRUE(MockupInputManager::destroyInputManager());
        }


    protected:
        MockupInputManager * inputManager;
};


//-- Things that are being tested
//-----------------------------------------------------------------------------------------------------
TEST_F(MockupInputManagerTest, SingleControlKeyPressSentAndReceivedCorrectly)
{
    MockupInputEventListener listener;
    RdInputEventListener * plistener = (RdInputEventListener *) &listener;
    ASSERT_TRUE(((RdInputManager*)inputManager)->addInputEventListener(plistener));
    ASSERT_EQ(1, inputManager->getNumListeners());

    ASSERT_TRUE(inputManager->start());
    ASSERT_FALSE(inputManager->isStopped());

    //-- Fake a control keypress
    MockupKey enter_key(RdKey::KEY_ENTER);
    ASSERT_TRUE(inputManager->sendKeyPress(enter_key));

    //-- Check if keypress was received
    ASSERT_EQ(1,listener.getNumKeyDownPresses());
    ASSERT_EQ(1,listener.getNumKeyUpPresses());

    //-- Check if keypress received is correct
    std::vector<RdKey> keys_down_received = listener.getStoredKeyDownPresses();
    std::vector<RdKey> keys_up_received = listener.getStoredKeyDownPresses();
    ASSERT_EQ(1,keys_down_received.size());
    ASSERT_EQ(1,keys_up_received.size());

    ASSERT_EQ(enter_key.getValue(), keys_down_received[0].getValue());
    ASSERT_EQ(enter_key.getValue(), keys_up_received[0].getValue());

    //-- Cleanup
    ASSERT_TRUE(inputManager->removeInputEventListeners());
    ASSERT_EQ(0, inputManager->getNumListeners());
    ASSERT_TRUE(inputManager->stop());
    ASSERT_TRUE(inputManager->isStopped());
}

TEST_F(MockupInputManagerTest, SinglePrintableKeyPressSentAndReceivedCorrectly)
{
    MockupInputEventListener listener;
    RdInputEventListener * plistener = (RdInputEventListener *) &listener;
    ASSERT_TRUE(((RdInputManager*)inputManager)->addInputEventListener(plistener));

    ASSERT_TRUE(inputManager->start());
    ASSERT_FALSE(inputManager->isStopped());

    //-- Fake a control keypress
    MockupKey d_key('d');
    ASSERT_TRUE(inputManager->sendKeyPress(d_key));

    //-- Check if keypress was received
    ASSERT_EQ(1,listener.getNumKeyDownPresses());
    ASSERT_EQ(1,listener.getNumKeyUpPresses());

    //-- Check if keypress received is correct
    std::vector<RdKey> keys_down_received = listener.getStoredKeyDownPresses();
    std::vector<RdKey> keys_up_received = listener.getStoredKeyDownPresses();
    ASSERT_EQ(1,keys_down_received.size());
    ASSERT_EQ(1,keys_up_received.size());

    ASSERT_EQ(d_key.getChar(), keys_down_received[0].getChar());
    ASSERT_EQ(d_key.getChar(), keys_up_received[0].getChar());

    //-- Cleanup
    ASSERT_TRUE(inputManager->removeInputEventListeners());
    ASSERT_TRUE(inputManager->stop());
    ASSERT_TRUE(inputManager->isStopped());
}

TEST_F(MockupInputManagerTest, SeveralControlKeyPressesSentAndReceivedCorrectly)
{
    MockupInputEventListener listener;
    RdInputEventListener * plistener = (RdInputEventListener *) &listener;
    ASSERT_TRUE(((RdInputManager*)inputManager)->addInputEventListener(plistener));

    ASSERT_TRUE(inputManager->start());
    ASSERT_FALSE(inputManager->isStopped());

    //-- Fake a control keypress
    MockupKey enter_key(RdKey::KEY_ENTER);
    MockupKey arrow_key(RdKey::KEY_ARROW_DOWN);
    ASSERT_TRUE(inputManager->sendKeyPress(enter_key));
    ASSERT_TRUE(inputManager->sendKeyPress(arrow_key));

    //-- Check if keypress was received
    ASSERT_EQ(2,listener.getNumKeyDownPresses());
    ASSERT_EQ(2,listener.getNumKeyUpPresses());

    //-- Check if keypress received is correct
    std::vector<RdKey> keys_down_received = listener.getStoredKeyDownPresses();
    std::vector<RdKey> keys_up_received = listener.getStoredKeyDownPresses();
    ASSERT_EQ(2,keys_down_received.size());
    ASSERT_EQ(2,keys_up_received.size());

    ASSERT_EQ(enter_key.getValue(), keys_down_received[0].getValue());
    ASSERT_EQ(enter_key.getValue(), keys_up_received[0].getValue());
    ASSERT_EQ(arrow_key.getValue(), keys_down_received[1].getValue());
    ASSERT_EQ(arrow_key.getValue(), keys_up_received[1].getValue());

    //-- Cleanup
    ASSERT_TRUE(inputManager->removeInputEventListeners());
    ASSERT_TRUE(inputManager->stop());
    ASSERT_TRUE(inputManager->isStopped());
}

TEST_F(MockupInputManagerTest, SeveralPrintableKeyPressesSentAndReceivedCorrectly)
{
    MockupInputEventListener listener;
    RdInputEventListener * plistener = (RdInputEventListener *) &listener;
    ASSERT_TRUE(((RdInputManager*)inputManager)->addInputEventListener(plistener));

    ASSERT_TRUE(inputManager->start());
    ASSERT_FALSE(inputManager->isStopped());

    //-- Fake a control keypress
    MockupKey r_key('r');
    MockupKey d_key('d');
    ASSERT_TRUE(inputManager->sendKeyPress(r_key));
    ASSERT_TRUE(inputManager->sendKeyPress(d_key));

    //-- Check if keypress was received
    ASSERT_EQ(2,listener.getNumKeyDownPresses());
    ASSERT_EQ(2,listener.getNumKeyUpPresses());

    //-- Check if keypress received is correct
    std::vector<RdKey> keys_down_received = listener.getStoredKeyDownPresses();
    std::vector<RdKey> keys_up_received = listener.getStoredKeyDownPresses();
    ASSERT_EQ(2,keys_down_received.size());
    ASSERT_EQ(2,keys_up_received.size());

    ASSERT_EQ(r_key.getChar(), keys_down_received[0].getChar());
    ASSERT_EQ(r_key.getChar(), keys_up_received[0].getChar());
    ASSERT_EQ(d_key.getChar(), keys_down_received[1].getChar());
    ASSERT_EQ(d_key.getChar(), keys_up_received[1].getChar());

    //-- Cleanup
    ASSERT_TRUE(inputManager->removeInputEventListeners());
    ASSERT_TRUE(inputManager->stop());
    ASSERT_TRUE(inputManager->isStopped());
}<commit_msg>Add failing test for new feature (KeyUp/KeyDown emulation) in MockupInputManager<commit_after>#include "gtest/gtest.h"
#include "MockupInputManager.hpp"
#include "MockupInputEventListener.hpp"
#include "MockupKey.hpp"

using namespace rd;

//-- Class for the setup of each test
//--------------------------------------------------------------------------------------
class MockupInputManagerTest : public testing::Test
{
    public:
        virtual void SetUp()
        {
            ASSERT_TRUE(MockupInputManager::RegisterManager());
            inputManager = (MockupInputManager *) MockupInputManager::getInputManager(MockupInputManager::id);
            ASSERT_TRUE(inputManager);
        }

        virtual void TearDown()
        {
            ASSERT_TRUE(MockupInputManager::destroyInputManager());
        }


    protected:
        MockupInputManager * inputManager;
};


//-- Things that are being tested
//-----------------------------------------------------------------------------------------------------
TEST_F(MockupInputManagerTest, SingleControlKeyPressSentAndReceivedCorrectly)
{
    MockupInputEventListener listener;
    RdInputEventListener * plistener = (RdInputEventListener *) &listener;
    ASSERT_TRUE(((RdInputManager*)inputManager)->addInputEventListener(plistener));
    ASSERT_EQ(1, inputManager->getNumListeners());

    ASSERT_TRUE(inputManager->start());
    ASSERT_FALSE(inputManager->isStopped());

    //-- Fake a control keypress
    MockupKey enter_key(RdKey::KEY_ENTER);
    ASSERT_TRUE(inputManager->sendKeyPress(enter_key));

    //-- Check if keypress was received
    ASSERT_EQ(1,listener.getNumKeyDownPresses());
    ASSERT_EQ(1,listener.getNumKeyUpPresses());

    //-- Check if keypress received is correct
    std::vector<RdKey> keys_down_received = listener.getStoredKeyDownPresses();
    std::vector<RdKey> keys_up_received = listener.getStoredKeyDownPresses();
    ASSERT_EQ(1,keys_down_received.size());
    ASSERT_EQ(1,keys_up_received.size());

    ASSERT_EQ(enter_key.getValue(), keys_down_received[0].getValue());
    ASSERT_EQ(enter_key.getValue(), keys_up_received[0].getValue());

    //-- Cleanup
    ASSERT_TRUE(inputManager->removeInputEventListeners());
    ASSERT_EQ(0, inputManager->getNumListeners());
    ASSERT_TRUE(inputManager->stop());
    ASSERT_TRUE(inputManager->isStopped());
}

TEST_F(MockupInputManagerTest, SinglePrintableKeyPressSentAndReceivedCorrectly)
{
    MockupInputEventListener listener;
    RdInputEventListener * plistener = (RdInputEventListener *) &listener;
    ASSERT_TRUE(((RdInputManager*)inputManager)->addInputEventListener(plistener));

    ASSERT_TRUE(inputManager->start());
    ASSERT_FALSE(inputManager->isStopped());

    //-- Fake a control keypress
    MockupKey d_key('d');
    ASSERT_TRUE(inputManager->sendKeyPress(d_key));

    //-- Check if keypress was received
    ASSERT_EQ(1,listener.getNumKeyDownPresses());
    ASSERT_EQ(1,listener.getNumKeyUpPresses());

    //-- Check if keypress received is correct
    std::vector<RdKey> keys_down_received = listener.getStoredKeyDownPresses();
    std::vector<RdKey> keys_up_received = listener.getStoredKeyDownPresses();
    ASSERT_EQ(1,keys_down_received.size());
    ASSERT_EQ(1,keys_up_received.size());

    ASSERT_EQ(d_key.getChar(), keys_down_received[0].getChar());
    ASSERT_EQ(d_key.getChar(), keys_up_received[0].getChar());

    //-- Cleanup
    ASSERT_TRUE(inputManager->removeInputEventListeners());
    ASSERT_TRUE(inputManager->stop());
    ASSERT_TRUE(inputManager->isStopped());
}

TEST_F(MockupInputManagerTest, SeveralControlKeyPressesSentAndReceivedCorrectly)
{
    MockupInputEventListener listener;
    RdInputEventListener * plistener = (RdInputEventListener *) &listener;
    ASSERT_TRUE(((RdInputManager*)inputManager)->addInputEventListener(plistener));

    ASSERT_TRUE(inputManager->start());
    ASSERT_FALSE(inputManager->isStopped());

    //-- Fake a control keypress
    MockupKey enter_key(RdKey::KEY_ENTER);
    MockupKey arrow_key(RdKey::KEY_ARROW_DOWN);
    ASSERT_TRUE(inputManager->sendKeyPress(enter_key));
    ASSERT_TRUE(inputManager->sendKeyPress(arrow_key));

    //-- Check if keypress was received
    ASSERT_EQ(2,listener.getNumKeyDownPresses());
    ASSERT_EQ(2,listener.getNumKeyUpPresses());

    //-- Check if keypress received is correct
    std::vector<RdKey> keys_down_received = listener.getStoredKeyDownPresses();
    std::vector<RdKey> keys_up_received = listener.getStoredKeyDownPresses();
    ASSERT_EQ(2,keys_down_received.size());
    ASSERT_EQ(2,keys_up_received.size());

    ASSERT_EQ(enter_key.getValue(), keys_down_received[0].getValue());
    ASSERT_EQ(enter_key.getValue(), keys_up_received[0].getValue());
    ASSERT_EQ(arrow_key.getValue(), keys_down_received[1].getValue());
    ASSERT_EQ(arrow_key.getValue(), keys_up_received[1].getValue());

    //-- Cleanup
    ASSERT_TRUE(inputManager->removeInputEventListeners());
    ASSERT_TRUE(inputManager->stop());
    ASSERT_TRUE(inputManager->isStopped());
}

TEST_F(MockupInputManagerTest, SeveralPrintableKeyPressesSentAndReceivedCorrectly)
{
    MockupInputEventListener listener;
    RdInputEventListener * plistener = (RdInputEventListener *) &listener;
    ASSERT_TRUE(((RdInputManager*)inputManager)->addInputEventListener(plistener));

    ASSERT_TRUE(inputManager->start());
    ASSERT_FALSE(inputManager->isStopped());

    //-- Fake a control keypress
    MockupKey r_key('r');
    MockupKey d_key('d');
    ASSERT_TRUE(inputManager->sendKeyPress(r_key));
    ASSERT_TRUE(inputManager->sendKeyPress(d_key));

    //-- Check if keypress was received
    ASSERT_EQ(2,listener.getNumKeyDownPresses());
    ASSERT_EQ(2,listener.getNumKeyUpPresses());

    //-- Check if keypress received is correct
    std::vector<RdKey> keys_down_received = listener.getStoredKeyDownPresses();
    std::vector<RdKey> keys_up_received = listener.getStoredKeyDownPresses();
    ASSERT_EQ(2,keys_down_received.size());
    ASSERT_EQ(2,keys_up_received.size());

    ASSERT_EQ(r_key.getChar(), keys_down_received[0].getChar());
    ASSERT_EQ(r_key.getChar(), keys_up_received[0].getChar());
    ASSERT_EQ(d_key.getChar(), keys_down_received[1].getChar());
    ASSERT_EQ(d_key.getChar(), keys_up_received[1].getChar());

    //-- Cleanup
    ASSERT_TRUE(inputManager->removeInputEventListeners());
    ASSERT_TRUE(inputManager->stop());
    ASSERT_TRUE(inputManager->isStopped());
}

TEST_F(MockupInputManagerTest, KeyUpAndKeyDownSentAndReceivedCorrectly)
{
    MockupInputEventListener listener;
    RdInputEventListener * plistener = (RdInputEventListener *) &listener;
    ASSERT_TRUE(((RdInputManager*)inputManager)->addInputEventListener(plistener));

    ASSERT_TRUE(inputManager->start());
    ASSERT_FALSE(inputManager->isStopped());

    //-- Fake a key down
    MockupKey enter_key(RdKey::KEY_ENTER);
    MockupKey d_key('d');
    ASSERT_TRUE(inputManager->sendKeyDown(enter_key));
    ASSERT_TRUE(inputManager->sendKeyDown(d_key));

    //-- Check if keypress was received
    ASSERT_EQ(2,listener.getNumKeyDownPresses());
    ASSERT_EQ(0,listener.getNumKeyUpPresses());

    //-- Fake a key up
    ASSERT_TRUE(inputManager->sendKeyUp(enter_key));
    ASSERT_TRUE(inputManager->sendKeyUp(d_key));

    //-- Check if keypress was received
    ASSERT_EQ(2,listener.getNumKeyDownPresses());
    ASSERT_EQ(2,listener.getNumKeyUpPresses());

    //-- Check if keypress received is correct
    std::vector<RdKey> keys_down_received = listener.getStoredKeyDownPresses();
    std::vector<RdKey> keys_up_received = listener.getStoredKeyDownPresses();
    ASSERT_EQ(2,keys_down_received.size());
    ASSERT_EQ(2,keys_up_received.size());

    ASSERT_EQ(enter_key.getValue(), keys_down_received[0].getValue());
    ASSERT_EQ(enter_key.getValue(), keys_up_received[0].getValue());
    ASSERT_EQ(d_key.getChar(), keys_down_received[1].getChar());
    ASSERT_EQ(d_key.getChar(), keys_up_received[1].getChar());

    //-- Cleanup
    ASSERT_TRUE(inputManager->removeInputEventListeners());
    ASSERT_TRUE(inputManager->stop());
    ASSERT_TRUE(inputManager->isStopped());
}
{'fraction_non_alphanumeric': 0.1519327499483222, 'fraction_numerical': 0.0048232619031213396, 'mean_word_length': 4.45229151014275, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 95, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3199628', 'n_tokens_mistral': 4451, 'n_tokens_neox': 4314, 'n_words': 574}