Model Test: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
'''English''' [[ | '''English''' [[Model_Test_Spanish|Spanish]] | ||
=Model Test= | = Model Test = | ||
ModelTest provides a way to check for common errors in implementations of | ModelTest provides a way to check for common errors in implementations of "QAbstractItemModel":http://doc.qt.nokia.com/qabstractitemmodel.html. | ||
ModelTest continuously checks a model as it changes, helping to verify the state and catching many common errors the moment they show up. | ModelTest continuously checks a model as it changes, helping to verify the state and catching many common errors the moment they show up. | ||
[[Image:Modeltest.png]] | [[Image:http://developer.qt.nokia.com/uploads/image_upload/Modeltest.png|http://developer.qt.nokia.com/uploads/image_upload/Modeltest.png]] | ||
Some of the conditions caught include: | Some of the conditions caught include: | ||
Line 14: | Line 14: | ||
* The parent of the first index of the first row is a QModelIndex() | * 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 | * 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. | * If rowCount() says there are X number of rows, model test will verify that is true. | ||
* Many possible off by one bugs | * Many possible off by one bugs | ||
* hasChildren() returns true if rowCount() is greater then zero. | * hasChildren() returns true if rowCount() is greater then zero. | ||
Line 23: | Line 23: | ||
# Include the pri file at the end of your project pro file using the include() command like so:<br />''include(../path/to/dir/modeltest.pri)'' | # Include the pri file at the end of your project pro file using the include() command like so:<br />''include(../path/to/dir/modeltest.pri)'' | ||
# Then in your source include | # Then in your source include "modeltest.h&quot; and instantiate ModelTest with your model so the test can live for the lifetime of your model. For example:<br /><code>#include <modeltest.h&gt; | ||
QDirModel *model = new QDirModel(this);<br />new ModelTest(model, this);</code> | |||
# 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. | # 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 | The source can be found "here&quot;:http://qt.gitorious.org/qt/qt/trees/4.7/tests/auto/modeltest | ||
Revision as of 14:45, 23 February 2015
English Spanish
Model Test
ModelTest provides a way to check for common errors in implementations of "QAbstractItemModel":http://doc.qt.nokia.com/qabstractitemmodel.html.
ModelTest continuously checks a model as it changes, helping to verify the state and catching many common errors the moment they show up.
http://developer.qt.nokia.com/uploads/image_upload/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:
- Include the pri file at the end of your project pro file using the include() command like so:
include(../path/to/dir/modeltest.pri)
- 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:
#include <modeltest.h&gt; QDirModel *model = new QDirModel(this);<br />new ModelTest(model, this);
- 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":http://qt.gitorious.org/qt/qt/trees/4.7/tests/auto/modeltest