Files
qt-migration-copilot-demo/qt6-after/qt6-migrated-benchmark/tests/main_test.cpp
T
torsten 3bdffc8a7f
qt-migration-copilot-demo/pipeline/head There was a failure building this commit
migrate: Qt5/C++11 app to Qt6/C++23 with tests and modern Qt APIs
Entire-Checkpoint: c1ee98dc34a3
2026-08-13 10:18:41 +02:00

63 lines
1.9 KiB
C++

#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"