PDA

View Full Version : Custom QT test macros



migel
25th January 2012, 23:59
Hi

I have to write few macros which I have, but are very simple, eg.


void Macros::Example( cond )
{
if ( cond )
QFAIL("some message");
}

This works fine but it does not show me a message line and file where it failed. It shows me a file and the line of QFAIL("some message");.

I would like to write a macro like QVERIFY to show me where it failed. I tried digging in libraries, all functions like QTestLog are not available from the include.

Possible?

wysota
26th January 2012, 00:35
How about using QVERIFY2() ?

migel
26th January 2012, 13:27
Its not the point of displaying message. It is a point of heaviest and diff job for the macro. One of them I need to verify number of records in database. This code I would need to repeat all over the places in function cases in all test classes.

eg.


CONFIRM_RECORDS(1)

Having a job inside the macro in static class function instead, like Macros::ConfirmRecords(1) and use QVERIFY2 for verification would give me a line and file name of QVERIFY2 failure inside the Macros::ConfirmRecords(1) function, and not actually of Macros::ConfirmRecords(1) function failure, and no way to find a place of failure if Macros::ConfirmRecords(1) is added in 10 other places in one case function.

That's why I need builds own macros, but so far they show me the same like using static function.

Thanks

wysota
26th January 2012, 13:44
To be honest I have no idea what you are saying. If you are building your custom reporting macros then why do you want to use the built-in ones? Can't you do it like so?


QVERIFY2(countRecords(obj) == 1), ...);

or if you want to keep your syntax:


QVERIFY2(Macros::ConfirmRecords(1) == true, ...);

migel
26th January 2012, 13:58
pff, that would work - thanks