Do data driven testing
parent
e93cb80d26
commit
c1e982ec24
|
@ -6,13 +6,11 @@ class TestRustObjectTypes : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void testInvalid();
|
||||
void testBool();
|
||||
void testString();
|
||||
void testByteArray();
|
||||
void testSetter();
|
||||
void testSetter_data();
|
||||
};
|
||||
|
||||
void TestRustObjectTypes::testInvalid()
|
||||
void TestRustObjectTypes::testSetter()
|
||||
{
|
||||
// GIVEN
|
||||
Person person;
|
||||
|
@ -29,56 +27,18 @@ void TestRustObjectTypes::testInvalid()
|
|||
QCOMPARE(person.userName(), userName);
|
||||
}
|
||||
|
||||
void TestRustObjectTypes::testBool()
|
||||
void TestRustObjectTypes::testSetter_data()
|
||||
{
|
||||
// GIVEN
|
||||
Person person;
|
||||
const QVariant userName(true);
|
||||
QSignalSpy spy(&person, &Person::userNameChanged);
|
||||
|
||||
// WHEN
|
||||
person.setUserName(userName);
|
||||
|
||||
// THEN
|
||||
QVERIFY(spy.isValid());
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QCOMPARE(person.userName().type(), userName.type());
|
||||
QCOMPARE(person.userName(), userName);
|
||||
}
|
||||
|
||||
void TestRustObjectTypes::testString()
|
||||
{
|
||||
// GIVEN
|
||||
Person person;
|
||||
const QVariant userName(QString("Konqi"));
|
||||
QSignalSpy spy(&person, &Person::userNameChanged);
|
||||
|
||||
// WHEN
|
||||
person.setUserName(userName);
|
||||
|
||||
// THEN
|
||||
QVERIFY(spy.isValid());
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QCOMPARE(person.userName().type(), userName.type());
|
||||
QCOMPARE(person.userName(), userName);
|
||||
}
|
||||
|
||||
void TestRustObjectTypes::testByteArray()
|
||||
{
|
||||
// GIVEN
|
||||
Person person;
|
||||
QTest::addColumn<QVariant>("value");
|
||||
QTest::newRow("invalid") << QVariant();
|
||||
QTest::newRow("true") << QVariant(true);
|
||||
QTest::newRow("false") << QVariant(false);
|
||||
QTest::newRow("QString()") << QVariant(QString());
|
||||
QTest::newRow("QString(Konqi)") << QVariant("Konqi");
|
||||
QTest::newRow("QString($€𐐷𤭢)") << QVariant("$€𐐷𤭢");
|
||||
QTest::newRow("QByteArray()") << QVariant(QByteArray());
|
||||
const char data[10] = {0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9};
|
||||
const QVariant userName(QByteArray(data, 10));
|
||||
QSignalSpy spy(&person, &Person::userNameChanged);
|
||||
|
||||
// WHEN
|
||||
person.setUserName(userName);
|
||||
|
||||
// THEN
|
||||
QVERIFY(spy.isValid());
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QCOMPARE(person.userName().type(), userName.type());
|
||||
QCOMPARE(person.userName(), userName);
|
||||
QTest::newRow("QByteArray(data)") << QVariant(QByteArray(data, 10));
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestRustObjectTypes)
|
||||
|
|
Loading…
Reference in New Issue