85 lines
2.2 KiB
C++
85 lines
2.2 KiB
C++
/**
|
|
* @file test_qt6_compatibility.cpp
|
|
* @brief Tests für Qt6-Kompatibilitätsfixes
|
|
*
|
|
* Tests verify that:
|
|
* 1. QRandomGenerator works correctly (replacing qrand())
|
|
* 2. QChar conversions work with static_cast<ushort>
|
|
* 3. Qt6 APIs function correctly
|
|
*/
|
|
|
|
#include <QtCore/QChar>
|
|
#include <QRandomGenerator>
|
|
#include <QtCore/QString>
|
|
#include <QStringView>
|
|
#include <QtCore/QVector>
|
|
#include <gtest/gtest.h>
|
|
|
|
// Test 1: QRandomGenerator basic functionality
|
|
TEST(Qt6Compatibility, QRandomGeneratorBasic)
|
|
{
|
|
// Test bounded random number generation (Qt6 replacement for qrand() % n)
|
|
auto* generator = QRandomGenerator::global();
|
|
ASSERT_NE(generator, nullptr);
|
|
|
|
int value = generator->bounded(100);
|
|
EXPECT_GE(value, 0);
|
|
EXPECT_LT(value, 100);
|
|
}
|
|
|
|
// Test 2: QRandomGenerator seeded generation
|
|
TEST(Qt6Compatibility, QRandomGeneratorSeeded)
|
|
{
|
|
QRandomGenerator generator(42); // Fixed seed for reproducibility
|
|
int value1 = generator.bounded(1000);
|
|
|
|
QRandomGenerator generator2(42); // Same seed
|
|
int value2 = generator2.bounded(1000);
|
|
|
|
EXPECT_EQ(value1, value2); // Should produce same sequence
|
|
}
|
|
|
|
// Test 3: QChar construction with static_cast<ushort>
|
|
TEST(Qt6Compatibility, QCharConstruction)
|
|
{
|
|
// Qt6 has stricter QChar constructors
|
|
char c = 'A';
|
|
QChar qchar = QChar(static_cast<ushort>(c));
|
|
EXPECT_EQ(qchar, QChar(u'A'));
|
|
}
|
|
|
|
// Test 4: QChar Unicode handling
|
|
TEST(Qt6Compatibility, QCharUnicode)
|
|
{
|
|
// Test Unicode character handling in Qt6
|
|
QChar unicodeChar(0x00E9); // é
|
|
EXPECT_EQ(unicodeChar.unicode(), 0x00E9);
|
|
|
|
QString str(unicodeChar);
|
|
EXPECT_EQ(str, QStringLiteral("é"));
|
|
}
|
|
|
|
// Test 5: QVector with Qt6
|
|
TEST(Qt6Compatibility, QVectorBasic)
|
|
{
|
|
QVector<int> vec;
|
|
vec.append(1);
|
|
vec.append(2);
|
|
vec.append(3);
|
|
|
|
EXPECT_EQ(vec.size(), 3);
|
|
EXPECT_EQ(vec[0], 1);
|
|
EXPECT_EQ(vec.contains(2), true);
|
|
}
|
|
|
|
// Test 6: QString Qt6 compatibility
|
|
TEST(Qt6Compatibility, QStringBasic)
|
|
{
|
|
QString str = QStringLiteral("Hello Qt6");
|
|
EXPECT_EQ(str.length(), 9);
|
|
EXPECT_TRUE(str.contains(QStringLiteral("Qt6")));
|
|
|
|
// Test Qt6 string methods - use QStringView instead of toStdStringView
|
|
QStringView view = str;
|
|
EXPECT_EQ(view.size(), 9);
|
|
} |