1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "filehelper.h"
#include "mousesimulator.h"
#include "processhandler.h"
#include "windowhelper.h"
#include "testenglishletters.h"
namespace {
const QString KTest_Name = "Test %1 key operations.";
const quint32 KTime_Wait_To_Start_Process = 350000;
const quint32 KTime_Wait_To_Close_Process = 100000;
const QString KTest_File_Name = "test_letters.txt";
const QString KTest_String = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv\n";
const quint16 KMax_Key_Operations = 100;
}
TestEnglishLetters::TestEnglishLetters(QObject *parent, WindowHelper &windowHelper, quint32 numberOfTests, qint64 x11vkbProcId) :
TestBase(parent, KTest_Name, numberOfTests, x11vkbProcId),
m_windowHelper(windowHelper),
m_otherProcHandler(nullptr),
m_letters(QString())
{
this->setTestRepeats(KMax_Key_Operations);
this->setTestName();
this->setTestingString();
}
void TestEnglishLetters::startTest()
{
m_testTimer.start();
this->deleteTestFile();
QString geditProcessName = QString("gedit -s %1").arg(KTest_File_Name);
m_otherProcHandler = new ProcessHandler(this, geditProcessName, KTime_Wait_To_Start_Process);
QObject::connect(m_otherProcHandler, &ProcessHandler::procReady, this, &TestEnglishLetters::doTestLettersInGedit);
m_otherProcHandler->startProc();
}
void TestEnglishLetters::doTestLettersInGedit()
{
auto x11vkbWin = m_windowHelper.findWindowByPid(m_x11vkbProcId);
auto otherWinId = m_windowHelper.findWindowByPid(m_otherProcHandler->getProcId());
auto bigDimension = m_windowHelper.getWindowDimension(x11vkbWin);
auto mouseSimulator = new MouseSimulator(this, x11vkbWin, bigDimension.first, bigDimension.second);
QStringList lines = m_letters.split(QLatin1Char('\n'));
QChar enterChar = QChar::CarriageReturn;
// first click shiftKey to get it Down
if (!TestBase::shiftIsDown) {
mouseSimulator->mouseLeftClickOnVkb(mouseSimulator->getPosition(3,1));
TestBase::shiftIsDown = true;
}
for (auto line : lines)
{
for (auto letter : line)
{
mouseSimulator->clickEnglishLetter(letter);
}
if (line != lines.at(lines.size()-1)) {
mouseSimulator->clickEnglishLetter(enterChar);
}
}
// close gedit process starts
usleep(KTime_Wait_To_Close_Process);
mouseSimulator->clickCtrlPlusSToSave(otherWinId);
usleep(KTime_Wait_To_Close_Process);
m_otherProcHandler->closeProcess();
this->verifyResult();
this->deleteTestFile();
m_timeElapsed = m_testTimer.elapsed();
emit endTest();
}
void TestEnglishLetters::verifyResult()
{
auto resultStr = FileHelper::getFileContext(KTest_File_Name);
if (QString::compare(m_letters, resultStr.trimmed() ) == 0) {
m_passed = true;
} else {
m_testResult =
QString("key operation amount expected: %1\nkey operation amount result: : %2")
.arg(m_letters.size()).arg(resultStr.size());
}
}
void TestEnglishLetters::deleteTestFile() const
{
if (FileHelper::fileExists(KTest_File_Name)) {
std::remove(KTest_File_Name.toLatin1());
}
}
void TestEnglishLetters::setTestingString()
{
QString testString = "";
while (testString.trimmed().size() < static_cast<int>(m_numberOfTests)) {
testString = testString + KTest_String;
}
m_letters = testString.mid(0, static_cast<int>(m_numberOfTests));
}
|