Why doesn't QTest allow const char* as a test data format?

Martin Herrmann

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?

ahmed

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why C doesn't allow implicit conversion from char ** to const char *const * (and C++ does)?

From Dev

Why doesn't Windows 7 allow me to format?

From Dev

Why doesn't elasticsearch allow changes to an indexed data?

From Dev

Why doesn't the compiler allow this?

From Dev

Why Doesn't string::data() Provide a Mutable char*?

From Dev

Why char[] work,but char * doesn't

From Dev

C complains about passing char** value to function taking char const*const*const but C++ doesn't

From Dev

c++: why can't we convert char ** to const char **

From Dev

Why doesn't jooq allow a Record in whenNotMatchedInsert?

From Dev

Why doesn't AngularJS allow for xor operations?

From Dev

Why doesn't jooq allow a Record in whenNotMatchedInsert?

From Dev

Why doesn't GLib use 'const' in these functions?

From Dev

Why doesn't MSVC initialize this const struct?

From Dev

Why doesn't const range based for use const_iterator?

From Dev

A const string constructor that doesn't allocate any char memory?

From Dev

Why doesn't char = (char) System.in.read(); work in java?

From Dev

Why doesn't this Jest test fail?

From Dev

Why doesn't chkrootkit test syslogd?

From Dev

Why doesn't VS 2013 Express allow inspection of AggregateException?

From Dev

Why doesn't D allow overload of nested functions?

From Java

Why doesn't Java allow overriding of static methods?

From Dev

Why doesn't Python allow to put a for followed by an if on the same line?

From Dev

Why C++ doesn't allow template overloading?

From Java

Why doesn't Dhall allow returning types from if expressions?

From Java

Why doesn't useState() allow for concatenation of Boolean values?

From Java

Why doesn't std::deque allow specifying the bucket size?

From Dev

Why doesn't numpy allow array multiplication by scalars?

From Dev

Why doesn't Ruby 'require' allow relative paths?

From Dev

Why doesn't Java 8 allow interface members to be private?

Related Related

  1. 1

    Why C doesn't allow implicit conversion from char ** to const char *const * (and C++ does)?

  2. 2

    Why doesn't Windows 7 allow me to format?

  3. 3

    Why doesn't elasticsearch allow changes to an indexed data?

  4. 4

    Why doesn't the compiler allow this?

  5. 5

    Why Doesn't string::data() Provide a Mutable char*?

  6. 6

    Why char[] work,but char * doesn't

  7. 7

    C complains about passing char** value to function taking char const*const*const but C++ doesn't

  8. 8

    c++: why can't we convert char ** to const char **

  9. 9

    Why doesn't jooq allow a Record in whenNotMatchedInsert?

  10. 10

    Why doesn't AngularJS allow for xor operations?

  11. 11

    Why doesn't jooq allow a Record in whenNotMatchedInsert?

  12. 12

    Why doesn't GLib use 'const' in these functions?

  13. 13

    Why doesn't MSVC initialize this const struct?

  14. 14

    Why doesn't const range based for use const_iterator?

  15. 15

    A const string constructor that doesn't allocate any char memory?

  16. 16

    Why doesn't char = (char) System.in.read(); work in java?

  17. 17

    Why doesn't this Jest test fail?

  18. 18

    Why doesn't chkrootkit test syslogd?

  19. 19

    Why doesn't VS 2013 Express allow inspection of AggregateException?

  20. 20

    Why doesn't D allow overload of nested functions?

  21. 21

    Why doesn't Java allow overriding of static methods?

  22. 22

    Why doesn't Python allow to put a for followed by an if on the same line?

  23. 23

    Why C++ doesn't allow template overloading?

  24. 24

    Why doesn't Dhall allow returning types from if expressions?

  25. 25

    Why doesn't useState() allow for concatenation of Boolean values?

  26. 26

    Why doesn't std::deque allow specifying the bucket size?

  27. 27

    Why doesn't numpy allow array multiplication by scalars?

  28. 28

    Why doesn't Ruby 'require' allow relative paths?

  29. 29

    Why doesn't Java 8 allow interface members to be private?

HotTag

Archive