migrate: Qt5/C++11 app to Qt6/C++23 with tests and modern Qt APIs
qt-migration-copilot-demo/pipeline/head There was a failure building this commit
qt-migration-copilot-demo/pipeline/head There was a failure building this commit
Entire-Checkpoint: c1ee98dc34a3
This commit is contained in:
78 files changed
+22627
-1
No files matched your search
@@ -0,0 +1,33 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(Qt6MigratedBenchmarkTests LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Test)
|
||||
|
||||
add_executable(main_test
|
||||
main_test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(main_test PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
Qt6::Test
|
||||
)
|
||||
|
||||
add_test(NAME main_test COMMAND main_test)
|
||||
|
||||
add_executable(MainWindow_test
|
||||
MainWindow_test.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(MainWindow_test PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
Qt6::Test
|
||||
)
|
||||
|
||||
add_test(NAME MainWindow_test COMMAND MainWindow_test)
|
||||
@@ -0,0 +1,75 @@
|
||||
#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"
|
||||
@@ -0,0 +1,63 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
#include <QTest>
|
||||
|
||||
class MainTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testRegularExpressionValidation_data();
|
||||
void testRegularExpressionValidation();
|
||||
void testQStringUtf8Conversion();
|
||||
void testRegularExpressionPattern();
|
||||
};
|
||||
|
||||
void MainTest::testRegularExpressionValidation_data()
|
||||
{
|
||||
QTest::addColumn<QString>("input");
|
||||
QTest::addColumn<bool>("expectedMatch");
|
||||
|
||||
QTest::newRow("valid_input_Test123") << QString::fromUtf8("Test123") << true;
|
||||
QTest::newRow("valid_input_ABC456") << QString::fromUtf8("ABC456") << true;
|
||||
QTest::newRow("valid_input_a1") << QString::fromUtf8("a1") << true;
|
||||
QTest::newRow("invalid_input_123Test") << QString::fromUtf8("123Test") << false;
|
||||
QTest::newRow("invalid_input_special") << QString::fromUtf8("Test@123") << false;
|
||||
QTest::newRow("invalid_input_empty") << QString::fromUtf8("") << false;
|
||||
}
|
||||
|
||||
void MainTest::testRegularExpressionValidation()
|
||||
{
|
||||
QFETCH(QString, input);
|
||||
QFETCH(bool, expectedMatch);
|
||||
|
||||
QRegularExpression pattern(R"(^[A-Za-z]+\d+$)");
|
||||
const bool matches = pattern.match(input).hasMatch();
|
||||
|
||||
QCOMPARE(matches, expectedMatch);
|
||||
}
|
||||
|
||||
void MainTest::testQStringUtf8Conversion()
|
||||
{
|
||||
const QString title = QString::fromUtf8("Qt6 Migrated Benchmark");
|
||||
QCOMPARE(title, QString::fromUtf8("Qt6 Migrated Benchmark"));
|
||||
|
||||
const QString label = QString::fromUtf8("Bitte Text wie Test123 eingeben.");
|
||||
QCOMPARE(label, QString::fromUtf8("Bitte Text wie Test123 eingeben."));
|
||||
}
|
||||
|
||||
void MainTest::testRegularExpressionPattern()
|
||||
{
|
||||
QRegularExpression pattern(R"(^[A-Za-z]+\d+$)");
|
||||
QVERIFY(pattern.isValid());
|
||||
|
||||
const QRegularExpressionMatch match = pattern.match(QString::fromUtf8("Test123"));
|
||||
QVERIFY(match.hasMatch());
|
||||
|
||||
const QRegularExpressionMatch noMatch = pattern.match(QString::fromUtf8("123Test"));
|
||||
QVERIFY(!noMatch.hasMatch());
|
||||
}
|
||||
|
||||
QTEST_MAIN(MainTest)
|
||||
|
||||
#include "main_test.moc"
|
||||
Reference in new issue
Block a user