[Qt-interest] QtTest data-driven approach with custom types

Kimmo Viitanen kviitanen at gmail.com
Fri Jul 30 10:30:01 CEST 2010


Hello,

I wrote a test for a class of mine using QtTest. After writing the
test I figured
the way I was testing would be ideal for the data-driven type of testing using
the _data() function. This will not work, however; I get an error
telling me that
qt_metatype_id is not a member of
QMetaTypeId<QVector<Sub_GameUtility::Identification> >.

Identification here is a class of my own. Now is this Qt's way of telling me
that I cannot use QVector in a _data() function and FETCH() it? Or that I
cannot use my custom type? Would I have to derive it from QObject?

The way I'm trying to use the _data function is probably silly too...
So is there a way to FETCH() data from the data function
without streaming it to the QTest::newRow() ?



Here is the code.

void Testmapcolumn::testConstructor_data()
{
    QTest::addColumn<unsigned int>("size");
    QTest::addColumn<QVector<Identification> >("data");

    Identification id1;
    Identification id2;
    Identification id3;
    Identification id4;
    Identification id5;
    Identification id6;

    QVector<Identification> data;
    data << id1 << id2 << id3 << id4 << id5 << id6;

    QTest::newRow("size smaller than data") << data.size() - 2 << data;
    QTest::newRow("size greater than data") << data.size() + 4 << data;
    QTest::newRow("size equal to data") << data.size() << data;
    QTest::newRow("empty data, size > 0") << 12 << QVector<Identification>();
}

void Testmapcolumn::testConstructor()
{
    QFETCH(unsigned int, size);
    QFETCH(QVector<Identification>, data);

    MapColumn column(size, data);

    QVERIFY(column.getColumnSize() == size);

    for (int i = 0; i < column.getColumnSize(); ++i)
    {
        if (i >= data.size())
            QVERIFY(column.getEntity(i) == Identification::invalidId());
        else
            QVERIFY(column.getEntity(i) == data.at(i));
    }
}



More information about the Qt-interest-old mailing list