modeltest.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
  4. ** All rights reserved.
  5. ** Contact: Nokia Corporation (qt-info@nokia.com)
  6. **
  7. ** This file is part of the test suite of the Qt Toolkit.
  8. **
  9. ** This file is free software: you can redistribute it and/or modify
  10. ** it under the terms of the GNU General Public License as published by
  11. ** the Free Software Foundation, either version 3 of the License, or
  12. ** (at your option) any later version.
  13. **
  14. ** $QT_BEGIN_LICENSE:LGPL$
  15. ** GNU Lesser General Public License Usage
  16. ** This file may be used under the terms of the GNU Lesser General Public
  17. ** License version 2.1 as published by the Free Software Foundation and
  18. ** appearing in the file LICENSE.LGPL included in the packaging of this
  19. ** file. Please review the following information to ensure the GNU Lesser
  20. ** General Public License version 2.1 requirements will be met:
  21. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  22. **
  23. ** In addition, as a special exception, Nokia gives you certain additional
  24. ** rights. These rights are described in the Nokia Qt LGPL Exception
  25. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  26. **
  27. ** GNU General Public License Usage
  28. ** Alternatively, this file may be used under the terms of the GNU General
  29. ** Public License version 3.0 as published by the Free Software Foundation
  30. ** and appearing in the file LICENSE.GPL included in the packaging of this
  31. ** file. Please review the following information to ensure the GNU General
  32. ** Public License version 3.0 requirements will be met:
  33. ** http://www.gnu.org/copyleft/gpl.html.
  34. **
  35. ** Other Usage
  36. ** Alternatively, this file may be used in accordance with the terms and
  37. ** conditions contained in a signed written agreement between you and Nokia.
  38. **
  39. **
  40. **
  41. **
  42. **
  43. ** $QT_END_LICENSE$
  44. **
  45. ****************************************************************************/
  46. #include "modeltest.h"
  47. #include <QtGui/QtGui>
  48. #include <QtTest/QtTest>
  49. #undef Q_ASSERT
  50. #define Q_ASSERT QVERIFY
  51. Q_DECLARE_METATYPE( QModelIndex )
  52. /*!
  53. Connect to all of the models signals. Whenever anything happens recheck everything.
  54. */
  55. ModelTest::ModelTest( QAbstractItemModel *_model, QObject *parent )
  56. : QObject( parent ), model( _model ), fetchingMore( false )
  57. {
  58. Q_ASSERT( model );
  59. connect( model, SIGNAL( columnsAboutToBeInserted( const QModelIndex &, int, int ) ),
  60. this, SLOT( runAllTests() ) );
  61. connect( model, SIGNAL( columnsAboutToBeRemoved( const QModelIndex &, int, int ) ),
  62. this, SLOT( runAllTests() ) );
  63. connect( model, SIGNAL( columnsInserted( const QModelIndex &, int, int ) ),
  64. this, SLOT( runAllTests() ) );
  65. connect( model, SIGNAL( columnsRemoved( const QModelIndex &, int, int ) ),
  66. this, SLOT( runAllTests() ) );
  67. connect( model, SIGNAL( dataChanged( const QModelIndex &, const QModelIndex & ) ),
  68. this, SLOT( runAllTests() ) );
  69. connect( model, SIGNAL( headerDataChanged( Qt::Orientation, int, int ) ),
  70. this, SLOT( runAllTests() ) );
  71. connect( model, SIGNAL( layoutAboutToBeChanged() ), this, SLOT( runAllTests() ) );
  72. connect( model, SIGNAL( layoutChanged() ), this, SLOT( runAllTests() ) );
  73. connect( model, SIGNAL( modelReset() ), this, SLOT( runAllTests() ) );
  74. connect( model, SIGNAL( rowsAboutToBeInserted( const QModelIndex &, int, int ) ),
  75. this, SLOT( runAllTests() ) );
  76. connect( model, SIGNAL( rowsAboutToBeRemoved( const QModelIndex &, int, int ) ),
  77. this, SLOT( runAllTests() ) );
  78. connect( model, SIGNAL( rowsInserted( const QModelIndex &, int, int ) ),
  79. this, SLOT( runAllTests() ) );
  80. connect( model, SIGNAL( rowsRemoved( const QModelIndex &, int, int ) ),
  81. this, SLOT( runAllTests() ) );
  82. // Special checks for inserting/removing
  83. connect( model, SIGNAL( layoutAboutToBeChanged() ),
  84. this, SLOT( layoutAboutToBeChanged() ) );
  85. connect( model, SIGNAL( layoutChanged() ),
  86. this, SLOT( layoutChanged() ) );
  87. connect( model, SIGNAL( rowsAboutToBeInserted( const QModelIndex &, int, int ) ),
  88. this, SLOT( rowsAboutToBeInserted( const QModelIndex &, int, int ) ) );
  89. connect( model, SIGNAL( rowsAboutToBeRemoved( const QModelIndex &, int, int ) ),
  90. this, SLOT( rowsAboutToBeRemoved( const QModelIndex &, int, int ) ) );
  91. connect( model, SIGNAL( rowsInserted( const QModelIndex &, int, int ) ),
  92. this, SLOT( rowsInserted( const QModelIndex &, int, int ) ) );
  93. connect( model, SIGNAL( rowsRemoved( const QModelIndex &, int, int ) ),
  94. this, SLOT( rowsRemoved( const QModelIndex &, int, int ) ) );
  95. runAllTests();
  96. }
  97. void ModelTest::runAllTests()
  98. {
  99. if ( fetchingMore )
  100. return;
  101. nonDestructiveBasicTest();
  102. rowCount();
  103. columnCount();
  104. hasIndex();
  105. index();
  106. parent();
  107. data();
  108. }
  109. /*!
  110. nonDestructiveBasicTest tries to call a number of the basic functions (not all)
  111. to make sure the model doesn't outright segfault, testing the functions that makes sense.
  112. */
  113. void ModelTest::nonDestructiveBasicTest()
  114. {
  115. Q_ASSERT( model->buddy( QModelIndex() ) == QModelIndex() );
  116. model->canFetchMore( QModelIndex() );
  117. Q_ASSERT( model->columnCount( QModelIndex() ) >= 0 );
  118. Q_ASSERT( model->data( QModelIndex() ) == QVariant() );
  119. fetchingMore = true;
  120. model->fetchMore( QModelIndex() );
  121. fetchingMore = false;
  122. Qt::ItemFlags flags = model->flags( QModelIndex() );
  123. Q_ASSERT( flags == Qt::ItemIsDropEnabled || flags == 0 );
  124. model->hasChildren( QModelIndex() );
  125. model->hasIndex( 0, 0 );
  126. model->headerData( 0, Qt::Horizontal );
  127. model->index( 0, 0 );
  128. model->itemData( QModelIndex() );
  129. QVariant cache;
  130. model->match( QModelIndex(), -1, cache );
  131. model->mimeTypes();
  132. Q_ASSERT( model->parent( QModelIndex() ) == QModelIndex() );
  133. Q_ASSERT( model->rowCount() >= 0 );
  134. QVariant variant;
  135. model->setData( QModelIndex(), variant, -1 );
  136. model->setHeaderData( -1, Qt::Horizontal, QVariant() );
  137. model->setHeaderData( 999999, Qt::Horizontal, QVariant() );
  138. QMap<int, QVariant> roles;
  139. model->sibling( 0, 0, QModelIndex() );
  140. model->span( QModelIndex() );
  141. model->supportedDropActions();
  142. }
  143. /*!
  144. Tests model's implementation of QAbstractItemModel::rowCount() and hasChildren()
  145. Models that are dynamically populated are not as fully tested here.
  146. */
  147. void ModelTest::rowCount()
  148. {
  149. // qDebug() << "rc";
  150. // check top row
  151. QModelIndex topIndex = model->index( 0, 0, QModelIndex() );
  152. int rows = model->rowCount( topIndex );
  153. Q_ASSERT( rows >= 0 );
  154. if ( rows > 0 )
  155. Q_ASSERT( model->hasChildren( topIndex ) );
  156. QModelIndex secondLevelIndex = model->index( 0, 0, topIndex );
  157. if ( secondLevelIndex.isValid() ) // not the top level
  158. {
  159. // check a row count where parent is valid
  160. rows = model->rowCount( secondLevelIndex );
  161. Q_ASSERT( rows >= 0 );
  162. if ( rows > 0 )
  163. Q_ASSERT( model->hasChildren( secondLevelIndex ) );
  164. }
  165. // The models rowCount() is tested more extensively in checkChildren(),
  166. // but this catches the big mistakes
  167. }
  168. /*!
  169. Tests model's implementation of QAbstractItemModel::columnCount() and hasChildren()
  170. */
  171. void ModelTest::columnCount()
  172. {
  173. // check top row
  174. QModelIndex topIndex = model->index( 0, 0, QModelIndex() );
  175. Q_ASSERT( model->columnCount( topIndex ) >= 0 );
  176. // check a column count where parent is valid
  177. QModelIndex childIndex = model->index( 0, 0, topIndex );
  178. if ( childIndex.isValid() )
  179. Q_ASSERT( model->columnCount( childIndex ) >= 0 );
  180. // columnCount() is tested more extensively in checkChildren(),
  181. // but this catches the big mistakes
  182. }
  183. /*!
  184. Tests model's implementation of QAbstractItemModel::hasIndex()
  185. */
  186. void ModelTest::hasIndex()
  187. {
  188. // qDebug() << "hi";
  189. // Make sure that invalid values returns an invalid index
  190. Q_ASSERT( !model->hasIndex( -2, -2 ) );
  191. Q_ASSERT( !model->hasIndex( -2, 0 ) );
  192. Q_ASSERT( !model->hasIndex( 0, -2 ) );
  193. int rows = model->rowCount();
  194. int columns = model->columnCount();
  195. // check out of bounds
  196. Q_ASSERT( !model->hasIndex( rows, columns ) );
  197. Q_ASSERT( !model->hasIndex( rows + 1, columns + 1 ) );
  198. if ( rows > 0 )
  199. Q_ASSERT( model->hasIndex( 0, 0 ) );
  200. // hasIndex() is tested more extensively in checkChildren(),
  201. // but this catches the big mistakes
  202. }
  203. /*!
  204. Tests model's implementation of QAbstractItemModel::index()
  205. */
  206. void ModelTest::index()
  207. {
  208. // qDebug() << "i";
  209. // Make sure that invalid values returns an invalid index
  210. Q_ASSERT( model->index( -2, -2 ) == QModelIndex() );
  211. Q_ASSERT( model->index( -2, 0 ) == QModelIndex() );
  212. Q_ASSERT( model->index( 0, -2 ) == QModelIndex() );
  213. int rows = model->rowCount();
  214. int columns = model->columnCount();
  215. if ( rows == 0 )
  216. return;
  217. // Catch off by one errors
  218. Q_ASSERT( model->index( rows, columns ) == QModelIndex() );
  219. Q_ASSERT( model->index( 0, 0 ).isValid() );
  220. // Make sure that the same index is *always* returned
  221. QModelIndex a = model->index( 0, 0 );
  222. QModelIndex b = model->index( 0, 0 );
  223. Q_ASSERT( a == b );
  224. // index() is tested more extensively in checkChildren(),
  225. // but this catches the big mistakes
  226. }
  227. /*!
  228. Tests model's implementation of QAbstractItemModel::parent()
  229. */
  230. void ModelTest::parent()
  231. {
  232. // qDebug() << "p";
  233. // Make sure the model wont crash and will return an invalid QModelIndex
  234. // when asked for the parent of an invalid index.
  235. Q_ASSERT( model->parent( QModelIndex() ) == QModelIndex() );
  236. if ( model->rowCount() == 0 )
  237. return;
  238. // Column 0 | Column 1 |
  239. // QModelIndex() | |
  240. // \- topIndex | topIndex1 |
  241. // \- childIndex | childIndex1 |
  242. // Common error test #1, make sure that a top level index has a parent
  243. // that is a invalid QModelIndex.
  244. QModelIndex topIndex = model->index( 0, 0, QModelIndex() );
  245. Q_ASSERT( model->parent( topIndex ) == QModelIndex() );
  246. // Common error test #2, make sure that a second level index has a parent
  247. // that is the first level index.
  248. if ( model->rowCount( topIndex ) > 0 )
  249. {
  250. QModelIndex childIndex = model->index( 0, 0, topIndex );
  251. Q_ASSERT( model->parent( childIndex ) == topIndex );
  252. }
  253. // Common error test #3, the second column should NOT have the same children
  254. // as the first column in a row.
  255. // Usually the second column shouldn't have children.
  256. QModelIndex topIndex1 = model->index( 0, 1, QModelIndex() );
  257. if ( model->rowCount( topIndex1 ) > 0 && model->columnCount( QModelIndex() ) > 1 )
  258. {
  259. QModelIndex childIndex = model->index( 0, 0, topIndex );
  260. QModelIndex childIndex1 = model->index( 0, 0, topIndex1 );
  261. Q_ASSERT( childIndex != childIndex1 );
  262. }
  263. // Full test, walk n levels deep through the model making sure that all
  264. // parent's children correctly specify their parent.
  265. checkChildren( QModelIndex() );
  266. }
  267. /*!
  268. Called from the parent() test.
  269. A model that returns an index of parent X should also return X when asking
  270. for the parent of the index.
  271. This recursive function does pretty extensive testing on the whole model in an
  272. effort to catch edge cases.
  273. This function assumes that rowCount(), columnCount() and index() already work.
  274. If they have a bug it will point it out, but the above tests should have already
  275. found the basic bugs because it is easier to figure out the problem in
  276. those tests then this one.
  277. */
  278. void ModelTest::checkChildren( const QModelIndex &parent, int currentDepth )
  279. {
  280. // First just try walking back up the tree.
  281. QModelIndex p = parent;
  282. while ( p.isValid() )
  283. p = p.parent();
  284. // For models that are dynamically populated
  285. if ( model->canFetchMore( parent ) )
  286. {
  287. fetchingMore = true;
  288. model->fetchMore( parent );
  289. fetchingMore = false;
  290. }
  291. int rows = model->rowCount( parent );
  292. int columns = model->columnCount( parent );
  293. if ( rows > 0 )
  294. Q_ASSERT( model->hasChildren( parent ) );
  295. // Some further testing against rows(), columns(), and hasChildren()
  296. Q_ASSERT( rows >= 0 );
  297. Q_ASSERT( columns >= 0 );
  298. if ( rows > 0 )
  299. Q_ASSERT( model->hasChildren( parent ) );
  300. //qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows
  301. // << "columns:" << columns << "parent column:" << parent.column();
  302. Q_ASSERT( !model->hasIndex( rows + 1, 0, parent ) );
  303. for ( int r = 0; r < rows; ++r )
  304. {
  305. if ( model->canFetchMore( parent ) )
  306. {
  307. fetchingMore = true;
  308. model->fetchMore( parent );
  309. fetchingMore = false;
  310. }
  311. Q_ASSERT( !model->hasIndex( r, columns + 1, parent ) );
  312. for ( int c = 0; c < columns; ++c )
  313. {
  314. Q_ASSERT( model->hasIndex( r, c, parent ) );
  315. QModelIndex index = model->index( r, c, parent );
  316. // rowCount() and columnCount() said that it existed...
  317. Q_ASSERT( index.isValid() );
  318. // index() should always return the same index when called twice in a row
  319. QModelIndex modifiedIndex = model->index( r, c, parent );
  320. Q_ASSERT( index == modifiedIndex );
  321. // Make sure we get the same index if we request it twice in a row
  322. QModelIndex a = model->index( r, c, parent );
  323. QModelIndex b = model->index( r, c, parent );
  324. Q_ASSERT( a == b );
  325. // Some basic checking on the index that is returned
  326. Q_ASSERT( index.model() == model );
  327. Q_ASSERT( index.row() == r );
  328. Q_ASSERT( index.column() == c );
  329. // While you can technically return a QVariant usually this is a sign
  330. // of an bug in data() Disable if this really is ok in your model.
  331. // Q_ASSERT ( model->data ( index, Qt::DisplayRole ).isValid() );
  332. // If the next test fails here is some somewhat useful debug you play with.
  333. if ( model->parent( index ) != parent )
  334. {
  335. qDebug() << r << c << currentDepth << model->data( index ).toString()
  336. << model->data( parent ).toString();
  337. qDebug() << index << parent << model->parent( index );
  338. // And a view that you can even use to show the model.
  339. // QTreeView view;
  340. // view.setModel(model);
  341. // view.show();
  342. }
  343. // Check that we can get back our real parent.
  344. // qDebug() << model->parent ( index ) << parent;
  345. Q_ASSERT( model->parent( index ) == parent );
  346. // recursively go down the children
  347. if ( model->hasChildren( index ) && currentDepth < 10 )
  348. {
  349. //qDebug() << r << c << "has children" << model->rowCount(index);
  350. checkChildren( index, ++currentDepth );
  351. } /* else { if (currentDepth >= 10) qDebug() << "checked 10 deep"; };*/
  352. // make sure that after testing the children that the index doesn't change.
  353. QModelIndex newerIndex = model->index( r, c, parent );
  354. Q_ASSERT( index == newerIndex );
  355. }
  356. }
  357. }
  358. /*!
  359. Tests model's implementation of QAbstractItemModel::data()
  360. */
  361. void ModelTest::data()
  362. {
  363. // Invalid index should return an invalid qvariant
  364. Q_ASSERT( !model->data( QModelIndex() ).isValid() );
  365. if ( model->rowCount() == 0 )
  366. return;
  367. // A valid index should have a valid QVariant data
  368. Q_ASSERT( model->index( 0, 0 ).isValid() );
  369. // shouldn't be able to set data on an invalid index
  370. Q_ASSERT( !model->setData( QModelIndex(), QLatin1String( "foo" ), Qt::DisplayRole ) );
  371. // General Purpose roles that should return a QString
  372. QVariant variant = model->data( model->index( 0, 0 ), Qt::ToolTipRole );
  373. if ( variant.isValid() )
  374. {
  375. Q_ASSERT( variant.canConvert( QMetaType::QString ) );
  376. }
  377. variant = model->data( model->index( 0, 0 ), Qt::StatusTipRole );
  378. if ( variant.isValid() )
  379. {
  380. Q_ASSERT( variant.canConvert( QMetaType::QString ) );
  381. }
  382. variant = model->data( model->index( 0, 0 ), Qt::WhatsThisRole );
  383. if ( variant.isValid() )
  384. {
  385. Q_ASSERT( variant.canConvert( QMetaType::QString ) );
  386. }
  387. // General Purpose roles that should return a QSize
  388. variant = model->data( model->index( 0, 0 ), Qt::SizeHintRole );
  389. if ( variant.isValid() )
  390. {
  391. Q_ASSERT( variant.canConvert( QMetaType::QSize ) );
  392. }
  393. // General Purpose roles that should return a QFont
  394. QVariant fontVariant = model->data( model->index( 0, 0 ), Qt::FontRole );
  395. if ( fontVariant.isValid() )
  396. {
  397. Q_ASSERT( variant.canConvert( QMetaType::QFont ) );
  398. }
  399. // Check that the alignment is one we know about
  400. QVariant textAlignmentVariant = model->data( model->index( 0, 0 ), Qt::TextAlignmentRole );
  401. if ( textAlignmentVariant.isValid() )
  402. {
  403. int alignment = textAlignmentVariant.toInt();
  404. Q_ASSERT( alignment == ( alignment & ( Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask ) ) );
  405. }
  406. // General Purpose roles that should return a QColor
  407. QVariant colorVariant = model->data( model->index( 0, 0 ), Qt::BackgroundColorRole );
  408. if ( colorVariant.isValid() )
  409. {
  410. Q_ASSERT( variant.canConvert( QMetaType::QColor ) );
  411. }
  412. colorVariant = model->data( model->index( 0, 0 ), Qt::TextColorRole );
  413. if ( colorVariant.isValid() )
  414. {
  415. Q_ASSERT( variant.canConvert( QMetaType::QColor ) );
  416. }
  417. // Check that the "check state" is one we know about.
  418. QVariant checkStateVariant = model->data( model->index( 0, 0 ), Qt::CheckStateRole );
  419. if ( checkStateVariant.isValid() )
  420. {
  421. int state = checkStateVariant.toInt();
  422. Q_ASSERT( state == Qt::Unchecked || state == Qt::PartiallyChecked || state == Qt::Checked );
  423. }
  424. }
  425. /*!
  426. Store what is about to be inserted to make sure it actually happens
  427. \sa rowsInserted()
  428. */
  429. void ModelTest::rowsAboutToBeInserted( const QModelIndex &parent, int start, int end )
  430. {
  431. Q_UNUSED( end );
  432. // qDebug() << "rowsAboutToBeInserted" << "start=" << start << "end=" << end << "parent=" << model->data ( parent ).toString()
  433. // << "current count of parent=" << model->rowCount ( parent ); // << "display of last=" << model->data( model->index(start-1, 0, parent) );
  434. // qDebug() << model->index(start-1, 0, parent) << model->data( model->index(start-1, 0, parent) );
  435. Changing c;
  436. c.parent = parent;
  437. c.oldSize = model->rowCount( parent );
  438. c.last = model->data( model->index( start - 1, 0, parent ) );
  439. c.next = model->data( model->index( start, 0, parent ) );
  440. insert.push( c );
  441. }
  442. /*!
  443. Confirm that what was said was going to happen actually did
  444. \sa rowsAboutToBeInserted()
  445. */
  446. void ModelTest::rowsInserted( const QModelIndex &parent, int start, int end )
  447. {
  448. Changing c = insert.pop();
  449. Q_ASSERT( c.parent == parent );
  450. // qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize
  451. // << "parent=" << model->data ( parent ).toString() << "current rowcount of parent=" << model->rowCount ( parent );
  452. // for (int ii=start; ii <= end; ii++)
  453. // {
  454. // qDebug() << "itemWasInserted:" << ii << model->data ( model->index ( ii, 0, parent ));
  455. // }
  456. // qDebug();
  457. Q_ASSERT( c.oldSize + ( end - start + 1 ) == model->rowCount( parent ) );
  458. Q_ASSERT( c.last == model->data( model->index( start - 1, 0, c.parent ) ) );
  459. if ( c.next != model->data( model->index( end + 1, 0, c.parent ) ) )
  460. {
  461. qDebug() << start << end;
  462. for ( int i = 0; i < model->rowCount(); ++i )
  463. qDebug() << model->index( i, 0 ).data().toString();
  464. qDebug() << c.next << model->data( model->index( end + 1, 0, c.parent ) );
  465. }
  466. Q_ASSERT( c.next == model->data( model->index( end + 1, 0, c.parent ) ) );
  467. }
  468. void ModelTest::layoutAboutToBeChanged()
  469. {
  470. for ( int i = 0; i < qBound( 0, model->rowCount(), 100 ); ++i )
  471. changing.append( QPersistentModelIndex( model->index( i, 0 ) ) );
  472. }
  473. void ModelTest::layoutChanged()
  474. {
  475. for ( int i = 0; i < changing.count(); ++i )
  476. {
  477. QPersistentModelIndex p = changing[i];
  478. Q_ASSERT( p == model->index( p.row(), p.column(), p.parent() ) );
  479. }
  480. changing.clear();
  481. }
  482. /*!
  483. Store what is about to be inserted to make sure it actually happens
  484. \sa rowsRemoved()
  485. */
  486. void ModelTest::rowsAboutToBeRemoved( const QModelIndex &parent, int start, int end )
  487. {
  488. qDebug() << "ratbr" << parent << start << end;
  489. Changing c;
  490. c.parent = parent;
  491. c.oldSize = model->rowCount( parent );
  492. c.last = model->data( model->index( start - 1, 0, parent ) );
  493. c.next = model->data( model->index( end + 1, 0, parent ) );
  494. remove.push( c );
  495. }
  496. /*!
  497. Confirm that what was said was going to happen actually did
  498. \sa rowsAboutToBeRemoved()
  499. */
  500. void ModelTest::rowsRemoved( const QModelIndex &parent, int start, int end )
  501. {
  502. qDebug() << "rr" << parent << start << end;
  503. Changing c = remove.pop();
  504. Q_ASSERT( c.parent == parent );
  505. Q_ASSERT( c.oldSize - ( end - start + 1 ) == model->rowCount( parent ) );
  506. Q_ASSERT( c.last == model->data( model->index( start - 1, 0, c.parent ) ) );
  507. Q_ASSERT( c.next == model->data( model->index( start, 0, c.parent ) ) );
  508. }