Using QTestLib in S60

From Qt Wiki
Jump to navigation Jump to search


Template:ArticleMetaData

Overview[edit | edit source]

Template:Abstract

In general passing console parameters for application can be considered inconvenient in S60 especially when testing on device. This snippet demonstrates how to modify QTEST_MAIN macro so that application ignores command line parameters and saves test results to "c:\data" + [application name] +."log" file. This speeds testing process because user can start tests simply clicking on the application icon and tests results will be available under data folder.

Example[edit | edit source]

Header that defines new macro[edit | edit source]

  1. include <QtTest/QtTest>
  1. ifndef S60UNITTEST_H_
  2. define S60UNITTEST_H_
  1. define QTEST_MAIN_S60(TestObject) \

int main(int argc, char *argv[]) \ { \ char *new_argv[3]; \ QApplication app(argc, argv); \ \ QString str = "C:\\data\\" + QFileInfo(QCoreApplication::applicationFilePath()).baseName() + ".log"; \ QByteArray bytes = str.toAscii(); \ \ char arg1[] = "-o"; \ \ new_argv[0] = argv[0]; \ new_argv[1] = arg1; \ new_argv[2] = bytes.data(); \ \ TestObject tc; \ return QTest::qExec(&tc, 3, new_argv); \ }

  1. endif /* S60UNITTEST_H_ */

In cpp file instead of using QTEST_MAIN macro use QTEST_MAIN_S60. Unit test examples for QTestLib can be found under qt\examples\qtestlib folder at Qt SDK.

See also[edit | edit source]