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 | [email protected] | Senior Software Engineer
KDAB (UK) Ltd., a KDAB Group company | Tel: UK +44-1625-809908
KDAB - Qt, C++ and OpenGL Experts

Attachment: smime.p7s
Description: Firma crittografica S/MIME

_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to