rust-qt-binding-generator/tests/test_object_types.cpp

54 lines
1.5 KiB
C++
Raw Normal View History

2017-08-11 14:47:56 -07:00
#include "test_object_types_rust.h"
2017-08-11 12:55:51 -07:00
#include <QTest>
#include <QSignalSpy>
2017-08-12 03:49:37 -07:00
#include <QDebug>
2017-08-11 12:55:51 -07:00
class TestRustObjectTypes : public QObject
2017-08-11 12:55:51 -07:00
{
Q_OBJECT
private slots:
2017-08-11 16:00:54 -07:00
void testSetter();
void testSetter_data();
2017-08-11 12:55:51 -07:00
};
2017-08-11 16:00:54 -07:00
void TestRustObjectTypes::testSetter()
2017-08-11 12:55:51 -07:00
{
// GIVEN
2017-08-12 03:49:37 -07:00
QFETCH(QVariant, value);
Object object;
QSignalSpy spy(&object, &Object::valueChanged);
// WHEN
2017-08-12 03:49:37 -07:00
object.setValue(value);
// THEN
QVERIFY(spy.isValid());
QCOMPARE(spy.count(), 1);
2017-08-12 03:49:37 -07:00
auto resultType = object.value().type();
QCOMPARE(resultType, value.type());
QCOMPARE(object.value(), value);
2017-08-11 12:55:51 -07:00
}
2017-08-11 16:00:54 -07:00
void TestRustObjectTypes::testSetter_data()
2017-08-11 12:55:51 -07:00
{
2017-08-11 16:00:54 -07:00
QTest::addColumn<QVariant>("value");
QTest::newRow("invalid") << QVariant();
QTest::newRow("true") << QVariant(true);
QTest::newRow("false") << QVariant(false);
QTest::newRow("0") << QVariant((int)0);
QTest::newRow("1") << QVariant((int)1);
int min_int = std::numeric_limits<int>::min();
QTest::newRow("min_int") << QVariant(min_int);
int max_int = std::numeric_limits<int>::max();
QTest::newRow("max_int") << QVariant(max_int);
2017-08-11 16:00:54 -07:00
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};
2017-08-11 16:00:54 -07:00
QTest::newRow("QByteArray(data)") << QVariant(QByteArray(data, 10));
}
QTEST_MAIN(TestRustObjectTypes)
2017-08-11 12:55:51 -07:00
#include "test_object_types.moc"