Hi!

I'm supposed to test an application with QTest. Now I would like to test a login function, which is void, but returns (I suppose) QMessages (I'm not sure though). Ok, I call the function from my test class:

Qt Code:
  1. TheClassToTest * test = new TheClassToTest();
  2.  
  3. QMetaObject::invokeMethod(test, "login", Qt::DirectConnection, Q_ARG(QString, username) , Q_ARG(QString, password));
To copy to clipboard, switch view to plain text mode 

This works, but obviously I am not comparing anything yet. If the login attempt is successful, the ClassToTest shows a Message (and this message in fact appears when i call my test class):

Qt Code:
  1. statusBar()->showMessage("You're logged in now!", 4000);
To copy to clipboard, switch view to plain text mode 

Since this function is void, this is the only reaction.

Now I would like to somehow get the content of this message an compare it to a predefined string, to see, if the login was indeed successful. In a very naive attempt I tried it this way:

Qt Code:
  1. TheClassToTest * test = new TheClassToTest();
  2. QMessageBox returnVal;
  3. QString result = "You're logged in now!"
  4.  
  5. QMetaObject::invokeMethod(test, "login", Qt::DirectConnection, Q_RETURN_ARG(QMessageBox, returnVal), Q_ARG(QString, username) , Q_ARG(QString, password));
  6.  
  7. QCOMPARE(returnVal.text(), result);
To copy to clipboard, switch view to plain text mode 

The MessageBox no longer appears if I now run the test, but the test still fails since the string I try to retrieve from my returnVal is empty:

Qt Code:
  1. Actual (returnVal.text()):
  2. Expected (result): You're logged in now!
To copy to clipboard, switch view to plain text mode 

I could not find how QStatusBar::showMessage() is implemented, maybe the error is that showMessage does not use a QMessageBox?

I would really appreciate some help.

Thank you.