qt-migration-copilot-demo/pipeline/head There was a failure building this commit
Entire-Checkpoint: c1ee98dc34a3
75 lines
2.3 KiB
C++
75 lines
2.3 KiB
C++
#include <QRect>
|
|
#include <QRegularExpression>
|
|
#include <QScreen>
|
|
#include <QString>
|
|
#include <QTest>
|
|
|
|
class MainWindowPatternTest : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
private slots:
|
|
void testPatternValidLettersThenDigits();
|
|
void testPatternInvalidDigitsThenLetters();
|
|
void testPatternInvalidSpecialCharacters();
|
|
void testScreenGeometryExtraction();
|
|
void testRegularExpressionContainsMethod();
|
|
};
|
|
|
|
void MainWindowPatternTest::testPatternValidLettersThenDigits()
|
|
{
|
|
QRegularExpression pattern(R"(^[A-Za-z]+\d+$)");
|
|
|
|
QVERIFY(pattern.match(QString::fromUtf8("Test123")).hasMatch());
|
|
QVERIFY(pattern.match(QString::fromUtf8("ABC456")).hasMatch());
|
|
QVERIFY(pattern.match(QString::fromUtf8("a1")).hasMatch());
|
|
}
|
|
|
|
void MainWindowPatternTest::testPatternInvalidDigitsThenLetters()
|
|
{
|
|
QRegularExpression pattern(R"(^[A-Za-z]+\d+$)");
|
|
|
|
QVERIFY(!pattern.match(QString::fromUtf8("123Test")).hasMatch());
|
|
QVERIFY(!pattern.match(QString::fromUtf8("1a")).hasMatch());
|
|
}
|
|
|
|
void MainWindowPatternTest::testPatternInvalidSpecialCharacters()
|
|
{
|
|
QRegularExpression pattern(R"(^[A-Za-z]+\d+$)");
|
|
|
|
QVERIFY(!pattern.match(QString::fromUtf8("Test@123")).hasMatch());
|
|
QVERIFY(!pattern.match(QString::fromUtf8("Test_123")).hasMatch());
|
|
QVERIFY(!pattern.match(QString::fromUtf8("")).hasMatch());
|
|
}
|
|
|
|
void MainWindowPatternTest::testScreenGeometryExtraction()
|
|
{
|
|
const QScreen* screen = QGuiApplication::primaryScreen();
|
|
if (screen)
|
|
{
|
|
const QRect geometry = screen->geometry();
|
|
QVERIFY(geometry.width() > 0);
|
|
QVERIFY(geometry.height() > 0);
|
|
|
|
const QString info = QString::fromUtf8("Screen: %1x%2").arg(geometry.width()).arg(geometry.height());
|
|
QVERIFY(!info.isEmpty());
|
|
QVERIFY(info.contains(QString::fromUtf8("Screen:")));
|
|
}
|
|
}
|
|
|
|
void MainWindowPatternTest::testRegularExpressionContainsMethod()
|
|
{
|
|
QRegularExpression pattern(R"(^[A-Za-z]+\d+$)");
|
|
|
|
const QString validInput = QString::fromUtf8("Test123");
|
|
const QRegularExpressionMatch match = pattern.match(validInput);
|
|
QVERIFY(match.hasMatch());
|
|
|
|
const QString invalidInput = QString::fromUtf8("Invalid");
|
|
const QRegularExpressionMatch noMatch = pattern.match(invalidInput);
|
|
QVERIFY(!noMatch.hasMatch());
|
|
}
|
|
|
|
QTEST_MAIN(MainWindowPatternTest)
|
|
|
|
#include "MainWindow_test.moc" |