Model Test

From Qt Wiki
Revision as of 16:08, 14 January 2015 by Maintenance script (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

English Spanish

Model Test

ModelTest provides a way to check for common errors in implementations of QAbstractItemModel [doc.qt.nokia.com].

ModelTest continuously checks a model as it changes, helping to verify the state and catching many common errors the moment they show up.

Modeltest.png

Some of the conditions caught include:

  • Verifying X number of rows have been inserted in the correct place after the signal rowsAboutToBeInserted() says X rows will be inserted.
  • The parent of the first index of the first row is a QModelIndex()
  • Calling index() twice in a row with the same values will return the same QModelIndex
  • If rowCount() says there are X number of rows, model test will verify that is true.
  • Many possible off by one bugs
  • hasChildren() returns true if rowCount() is greater then zero.
  • and many more…

To use the model test do the following:

  1. Include the pri file at the end of your project pro file using the include() command like so:
    include(../path/to/dir/modeltest.pri)
  1. Then in your source include “modeltest.h” and instantiate ModelTest with your model so the test can live for the lifetime of your model. For example:
  1. That is it. When the test finds a problem it will assert. modeltest.cpp contains some hints on how to fix problems that the test finds.

The source can be found here [qt.gitorious.org]

Categories: