QEvent: document and check when registerEventTypes() returns -1

In tst_QEvent, add a check that exhausts the available event type ids and verifies
that registerEventTypes() returns -1 in that case, as documented.

I haven't found a way to test the other case in which -1 is returned.

Since this test operates on a global write-only registry the new test case needs
to keep track of whether the earlier test cases have run successfully. If they
didn't, skip this test case.

Change-Id: I68ea9d17d10dcec22175994aba269dd09c9adf43
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Marc Mutz 2014-03-04 15:20:07 +01:00 committed by The Qt Project
parent ecdeaa4369
commit de10bf4955
2 changed files with 29 additions and 0 deletions

View File

@ -406,6 +406,9 @@ Q_GLOBAL_STATIC(QEventUserEventRegistration, userEventRegistrationHelper)
between QEvent::User and QEvent::MaxUser that has not yet been
registered. The \a hint is ignored if its value is not between
QEvent::User and QEvent::MaxUser.
Returns -1 if all available values are already taken or the
program is shutting down.
*/
int QEvent::registerEventType(int hint)
{

View File

@ -55,9 +55,14 @@ public:
private slots:
void registerEventType_data();
void registerEventType();
void exhaustEventTypeRegistration(); // keep behind registerEventType() test
private:
bool registerEventTypeSucceeded; // track success of registerEventType for use by exhaustEventTypeRegistration()
};
tst_QEvent::tst_QEvent()
: registerEventTypeSucceeded(true)
{ }
tst_QEvent::~tst_QEvent()
@ -82,9 +87,30 @@ void tst_QEvent::registerEventType_data()
void tst_QEvent::registerEventType()
{
const bool oldRegisterEventTypeSucceeded = registerEventTypeSucceeded;
registerEventTypeSucceeded = false;
QFETCH(int, hint);
QFETCH(int, expected);
QCOMPARE(QEvent::registerEventType(hint), expected);
registerEventTypeSucceeded = oldRegisterEventTypeSucceeded;
}
void tst_QEvent::exhaustEventTypeRegistration()
{
if (!registerEventTypeSucceeded)
QSKIP("requires the previous test (registerEventType) to have finished successfully");
int i = QEvent::User;
int result;
while ((result = QEvent::registerEventType(i)) == i)
++i;
QCOMPARE(i, int(QEvent::User + 1000));
QCOMPARE(result, int(QEvent::MaxUser - 4));
i = QEvent::User + 1001;
while ((result = QEvent::registerEventType(i)) == i)
++i;
QCOMPARE(result, -1);
QCOMPARE(i, int(QEvent::MaxUser - 4));
}
QTEST_MAIN(tst_QEvent)