So I'm using Qt's QTest framework with the "data driven" approach. I can define the test data like so:
Q_DECLARE_METATYPE (const int*);
void MyTest::testSomething_data ()
{
QTest::addColumn<const int*> ("rawIntegerData");
// ...
}
Now I try do to the same thing with const char*
instead of const int*
...
Q_DECLARE_METATYPE (const char*);
void MyTest::testSomething_data ()
{
QTest::addColumn<const char*> ("rawTextData");
// ...
}
...and I get a failed static assertion:
const char* is not allowed as a test data format.
Turns out that QTest::addColumn explicitly rejects const char*
in qtestcase.h.
I realize that QByteArray
is probably a viable alternative, but I was wondering: what is the reason that const char *
is not allowed here?
This is the commit message for that change:
Clarify assert on use of const char* as TestData type in tests.
Currently all C-style strings used as data types in QTest::addColumn will assert at runtime with, e.g.: "expected data of type 'const char*', got 'QString' for element 0 of data with tab 'blah'". This patch makes it clear that C-style strings are disallowed.
There are some comments in the Code Review here
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments