[Interest] Printing QObject-derived classes on QCOMPARE failure
Mitch Curtis
mitch.curtis at qt.io
Mon Jun 26 10:21:58 CEST 2017
Damn. Thanks. :)
> -----Original Message-----
> From: Interest [mailto:interest-bounces+mitch.curtis=qt.io at qt-project.org]
> On Behalf Of Giuseppe D'Angelo
> Sent: Saturday, 24 June 2017 5:55 PM
> To: interest at qt-project.org
> Subject: Re: [Interest] Printing QObject-derived classes on QCOMPARE
> failure
>
> Hi,
>
> Il 24/06/2017 15:54, Mitch Curtis ha scritto:
> > Is it possible to have QCOMPARE call the operator<< overload for my
> custom QObject-derived class upon failure?
> >
> > The following test only prints:
> >
> > FAIL! : Untitled1Test::testCase1() Compared pointers are not the same
> > Loc: [../untitled1/tst_untitled1test.cpp(44)]
>
> Not without modifying QtTestLib. QCOMPARE in that case calls the qCompare
> specialization for pointers:
>
> > template <typename T>
> > inline bool qCompare(const T *t1, const T *t2, const char *actual, const
> char *expected,
> > const char *file, int line)
> > {
> > return compare_ptr_helper(t1, t2, actual, expected, file, line);
> > }
>
> compare_ptr_helper loses information on T1/T2 and just uses comparison on
> void*:
>
> > inline bool compare_ptr_helper(const volatile void *t1, const volatile void
> *t2, const char *actual,
> > const char *expected, const char *file, int line)
> > {
> > return compare_helper(t1 == t2, "Compared pointers are not the
> same",
> > toString(t1), toString(t2), actual, expected, file, line);
> > }
> >
>
> Cheers,
>
> --
> Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software
> Engineer KDAB (UK) Ltd., a KDAB Group company | Tel: UK +44-1625-809908
> KDAB - Qt, C++ and OpenGL Experts
More information about the Interest
mailing list