keepassxc

Форк
0
/
modeltest.cpp 
640 строк · 24.2 Кб
1
/****************************************************************************
2
**
3
** Copyright (C) 2015 The Qt Company Ltd.
4
** Contact: http://www.qt.io/licensing/
5
**
6
** This file is part of the test suite of the Qt Toolkit.
7
**
8
** $QT_BEGIN_LICENSE:LGPL21$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and The Qt Company. For licensing terms
14
** and conditions see http://www.qt.io/terms-conditions. For further
15
** information use the contact form at http://www.qt.io/contact-us.
16
**
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 or version 3 as published by the Free
20
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22
** following information to ensure the GNU Lesser General Public License
23
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
**
26
** As a special exception, The Qt Company gives you certain additional
27
** rights. These rights are described in The Qt Company LGPL Exception
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
**
30
** $QT_END_LICENSE$
31
**
32
****************************************************************************/
33

34
#include "modeltest.h"
35

36
#include <QtTest>
37

38
/*!
39
    Connect to all of the models signals.  Whenever anything happens recheck everything.
40
*/
41
ModelTest::ModelTest ( QAbstractItemModel *_model, QObject *parent ) : QObject ( parent ), model ( _model ), fetchingMore ( false )
42
{
43
    if (!model)
44
        qFatal("%s: model must not be null", Q_FUNC_INFO);
45

46
    connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)),
47
            this, SLOT(runAllTests()) );
48
    connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)),
49
            this, SLOT(runAllTests()) );
50
    connect(model, SIGNAL(columnsInserted(QModelIndex,int,int)),
51
            this, SLOT(runAllTests()) );
52
    connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
53
            this, SLOT(runAllTests()) );
54
    connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
55
            this, SLOT(runAllTests()) );
56
    connect(model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
57
            this, SLOT(runAllTests()) );
58
    connect(model, SIGNAL(layoutAboutToBeChanged()), this, SLOT(runAllTests()) );
59
    connect(model, SIGNAL(layoutChanged()), this, SLOT(runAllTests()) );
60
    connect(model, SIGNAL(modelReset()), this, SLOT(runAllTests()) );
61
    connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
62
            this, SLOT(runAllTests()) );
63
    connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
64
            this, SLOT(runAllTests()) );
65
    connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
66
            this, SLOT(runAllTests()) );
67
    connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
68
            this, SLOT(runAllTests()) );
69

70
    // Special checks for changes
71
    connect(model, SIGNAL(layoutAboutToBeChanged()),
72
            this, SLOT(layoutAboutToBeChanged()) );
73
    connect(model, SIGNAL(layoutChanged()),
74
            this, SLOT(layoutChanged()) );
75

76
    connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
77
            this, SLOT(rowsAboutToBeInserted(QModelIndex,int,int)) );
78
    connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
79
            this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)) );
80
    connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
81
            this, SLOT(rowsInserted(QModelIndex,int,int)) );
82
    connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
83
            this, SLOT(rowsRemoved(QModelIndex,int,int)) );
84
    connect(model, SIGNAL (rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
85
            this, SLOT (rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)) );
86
    connect(model, SIGNAL (rowsMoved(QModelIndex,int,int,QModelIndex,int)),
87
            this, SLOT (rowsMoved(QModelIndex,int,int,QModelIndex,int)) );
88
    connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
89
            this, SLOT(dataChanged(QModelIndex,QModelIndex)) );
90
    connect(model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
91
            this, SLOT(headerDataChanged(Qt::Orientation,int,int)) );
92

93
    runAllTests();
94
}
95

96
void ModelTest::runAllTests()
97
{
98
    if ( fetchingMore )
99
        return;
100
    nonDestructiveBasicTest();
101
    rowCount();
102
    columnCount();
103
    hasIndex();
104
    index();
105
    parent();
106
    data();
107
}
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
    QVERIFY( model->buddy ( QModelIndex() ) == QModelIndex() );
116
    model->canFetchMore ( QModelIndex() );
117
    QVERIFY( model->columnCount ( QModelIndex() ) >= 0 );
118
    QVERIFY( model->data ( QModelIndex() ) == QVariant() );
119
    fetchingMore = true;
120
    model->fetchMore ( QModelIndex() );
121
    fetchingMore = false;
122
    Qt::ItemFlags flags = model->flags ( QModelIndex() );
123
    QVERIFY( 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
    QVERIFY( model->parent ( QModelIndex() ) == QModelIndex() );
133
    QVERIFY( 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
/*!
145
    Tests model's implementation of QAbstractItemModel::rowCount() and hasChildren()
146

147
    Models that are dynamically populated are not as fully tested here.
148
 */
149
void ModelTest::rowCount()
150
{
151
//     qDebug() << "rc";
152
    // check top row
153
    QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
154
    int rows = model->rowCount ( topIndex );
155
    QVERIFY( rows >= 0 );
156
    if ( rows > 0 )
157
        QVERIFY( model->hasChildren ( topIndex ) );
158

159
    QModelIndex secondLevelIndex = model->index ( 0, 0, topIndex );
160
    if ( secondLevelIndex.isValid() ) { // not the top level
161
        // check a row count where parent is valid
162
        rows = model->rowCount ( secondLevelIndex );
163
        QVERIFY( rows >= 0 );
164
        if ( rows > 0 )
165
            QVERIFY( model->hasChildren ( secondLevelIndex ) );
166
    }
167

168
    // The models rowCount() is tested more extensively in checkChildren(),
169
    // but this catches the big mistakes
170
}
171

172
/*!
173
    Tests model's implementation of QAbstractItemModel::columnCount() and hasChildren()
174
 */
175
void ModelTest::columnCount()
176
{
177
    // check top row
178
    QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
179
    QVERIFY( model->columnCount ( topIndex ) >= 0 );
180

181
    // check a column count where parent is valid
182
    QModelIndex childIndex = model->index ( 0, 0, topIndex );
183
    if ( childIndex.isValid() )
184
        QVERIFY( model->columnCount ( childIndex ) >= 0 );
185

186
    // columnCount() is tested more extensively in checkChildren(),
187
    // but this catches the big mistakes
188
}
189

190
/*!
191
    Tests model's implementation of QAbstractItemModel::hasIndex()
192
 */
193
void ModelTest::hasIndex()
194
{
195
//     qDebug() << "hi";
196
    // Make sure that invalid values returns an invalid index
197
    QVERIFY( !model->hasIndex ( -2, -2 ) );
198
    QVERIFY( !model->hasIndex ( -2, 0 ) );
199
    QVERIFY( !model->hasIndex ( 0, -2 ) );
200

201
    int rows = model->rowCount();
202
    int columns = model->columnCount();
203

204
    // check out of bounds
205
    QVERIFY( !model->hasIndex ( rows, columns ) );
206
    QVERIFY( !model->hasIndex ( rows + 1, columns + 1 ) );
207

208
    if ( rows > 0 )
209
        QVERIFY( model->hasIndex ( 0, 0 ) );
210

211
    // hasIndex() is tested more extensively in checkChildren(),
212
    // but this catches the big mistakes
213
}
214

215
/*!
216
    Tests model's implementation of QAbstractItemModel::index()
217
 */
218
void ModelTest::index()
219
{
220
//     qDebug() << "i";
221
    // Make sure that invalid values returns an invalid index
222
    QVERIFY( model->index ( -2, -2 ) == QModelIndex() );
223
    QVERIFY( model->index ( -2, 0 ) == QModelIndex() );
224
    QVERIFY( model->index ( 0, -2 ) == QModelIndex() );
225

226
    int rows = model->rowCount();
227
    int columns = model->columnCount();
228

229
    if ( rows == 0 )
230
        return;
231

232
    // Catch off by one errors
233
    QVERIFY( model->index ( rows, columns ) == QModelIndex() );
234
    QVERIFY( model->index ( 0, 0 ).isValid() );
235

236
    // Make sure that the same index is *always* returned
237
    QModelIndex a = model->index ( 0, 0 );
238
    QModelIndex b = model->index ( 0, 0 );
239
    QVERIFY( a == b );
240

241
    // index() is tested more extensively in checkChildren(),
242
    // but this catches the big mistakes
243
}
244

245
/*!
246
    Tests model's implementation of QAbstractItemModel::parent()
247
 */
248
void ModelTest::parent()
249
{
250
//     qDebug() << "p";
251
    // Make sure the model won't crash and will return an invalid QModelIndex
252
    // when asked for the parent of an invalid index.
253
    QVERIFY( model->parent ( QModelIndex() ) == QModelIndex() );
254

255
    if ( model->rowCount() == 0 )
256
        return;
257

258
    // Column 0                | Column 1    |
259
    // QModelIndex()           |             |
260
    //    \- topIndex          | topIndex1   |
261
    //         \- childIndex   | childIndex1 |
262

263
    // Common error test #1, make sure that a top level index has a parent
264
    // that is a invalid QModelIndex.
265
    QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
266
    QVERIFY( model->parent ( topIndex ) == QModelIndex() );
267

268
    // Common error test #2, make sure that a second level index has a parent
269
    // that is the first level index.
270
    if ( model->rowCount ( topIndex ) > 0 ) {
271
        QModelIndex childIndex = model->index ( 0, 0, topIndex );
272
        QVERIFY( model->parent ( childIndex ) == topIndex );
273
    }
274

275
    // Common error test #3, the second column should NOT have the same children
276
    // as the first column in a row.
277
    // Usually the second column shouldn't have children.
278
    QModelIndex topIndex1 = model->index ( 0, 1, QModelIndex() );
279
    if ( model->rowCount ( topIndex1 ) > 0 ) {
280
        QModelIndex childIndex = model->index ( 0, 0, topIndex );
281
        QModelIndex childIndex1 = model->index ( 0, 0, topIndex1 );
282
        QVERIFY( childIndex != childIndex1 );
283
    }
284

285
    // Full test, walk n levels deep through the model making sure that all
286
    // parent's children correctly specify their parent.
287
    checkChildren ( QModelIndex() );
288
}
289

290
/*!
291
    Called from the parent() test.
292

293
    A model that returns an index of parent X should also return X when asking
294
    for the parent of the index.
295

296
    This recursive function does pretty extensive testing on the whole model in an
297
    effort to catch edge cases.
298

299
    This function assumes that rowCount(), columnCount() and index() already work.
300
    If they have a bug it will point it out, but the above tests should have already
301
    found the basic bugs because it is easier to figure out the problem in
302
    those tests then this one.
303
 */
304
void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
305
{
306
    // First just try walking back up the tree.
307
    QModelIndex p = parent;
308
    while ( p.isValid() )
309
        p = p.parent();
310

311
    // For models that are dynamically populated
312
    if ( model->canFetchMore ( parent ) ) {
313
        fetchingMore = true;
314
        model->fetchMore ( parent );
315
        fetchingMore = false;
316
    }
317

318
    int rows = model->rowCount ( parent );
319
    int columns = model->columnCount ( parent );
320

321
    if ( rows > 0 )
322
        QVERIFY( model->hasChildren ( parent ) );
323

324
    // Some further testing against rows(), columns(), and hasChildren()
325
    QVERIFY( rows >= 0 );
326
    QVERIFY( columns >= 0 );
327
    if ( rows > 0 )
328
        QVERIFY( model->hasChildren ( parent ) );
329

330
    //qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows
331
    //         << "columns:" << columns << "parent column:" << parent.column();
332

333
    const QModelIndex topLeftChild = model->index( 0, 0, parent );
334

335
    QVERIFY( !model->hasIndex ( rows + 1, 0, parent ) );
336
    for ( int r = 0; r < rows; ++r ) {
337
        if ( model->canFetchMore ( parent ) ) {
338
            fetchingMore = true;
339
            model->fetchMore ( parent );
340
            fetchingMore = false;
341
        }
342
        QVERIFY( !model->hasIndex ( r, columns + 1, parent ) );
343
        for ( int c = 0; c < columns; ++c ) {
344
            QVERIFY( model->hasIndex ( r, c, parent ) );
345
            QModelIndex index = model->index ( r, c, parent );
346
            // rowCount() and columnCount() said that it existed...
347
            QVERIFY( index.isValid() );
348

349
            // index() should always return the same index when called twice in a row
350
            QModelIndex modifiedIndex = model->index ( r, c, parent );
351
            QVERIFY( index == modifiedIndex );
352

353
            // Make sure we get the same index if we request it twice in a row
354
            QModelIndex a = model->index ( r, c, parent );
355
            QModelIndex b = model->index ( r, c, parent );
356
            QVERIFY( a == b );
357

358
            {
359
                const QModelIndex sibling = model->sibling( r, c, topLeftChild );
360
                QVERIFY( index == sibling );
361
            }
362
            {
363
                const QModelIndex sibling = topLeftChild.sibling( r, c );
364
                QVERIFY( index == sibling );
365
            }
366

367
            // Some basic checking on the index that is returned
368
            QVERIFY( index.model() == model );
369
            QCOMPARE( index.row(), r );
370
            QCOMPARE( index.column(), c );
371
            // While you can technically return a QVariant usually this is a sign
372
            // of a bug in data().  Disable if this really is ok in your model.
373
//            QVERIFY( model->data ( index, Qt::DisplayRole ).isValid() );
374

375
            // If the next test fails here is some somewhat useful debug you play with.
376

377
            if (model->parent(index) != parent) {
378
                qDebug() << r << c << currentDepth << model->data(index).toString()
379
                         << model->data(parent).toString();
380
                qDebug() << index << parent << model->parent(index);
381
//                 And a view that you can even use to show the model.
382
//                 QTreeView view;
383
//                 view.setModel(model);
384
//                 view.show();
385
            }
386

387
            // Check that we can get back our real parent.
388
            QCOMPARE( model->parent ( index ), parent );
389

390
            // recursively go down the children
391
            if ( model->hasChildren ( index ) && currentDepth < 10 ) {
392
                //qDebug() << r << c << "has children" << model->rowCount(index);
393
                checkChildren ( index, ++currentDepth );
394
            }/* else { if (currentDepth >= 10) qDebug() << "checked 10 deep"; };*/
395

396
            // make sure that after testing the children that the index doesn't change.
397
            QModelIndex newerIndex = model->index ( r, c, parent );
398
            QVERIFY( index == newerIndex );
399
        }
400
    }
401
}
402

403
/*!
404
    Tests model's implementation of QAbstractItemModel::data()
405
 */
406
void ModelTest::data()
407
{
408
    // Invalid index should return an invalid qvariant
409
    QVERIFY( !model->data ( QModelIndex() ).isValid() );
410

411
    if ( model->rowCount() == 0 )
412
        return;
413

414
    // A valid index should have a valid QVariant data
415
    QVERIFY( model->index ( 0, 0 ).isValid() );
416

417
    // shouldn't be able to set data on an invalid index
418
    QVERIFY( !model->setData ( QModelIndex(), QLatin1String ( "foo" ), Qt::DisplayRole ) );
419

420
    // General Purpose roles that should return a QString
421
    QVariant variant = model->data ( model->index ( 0, 0 ), Qt::ToolTipRole );
422
    if ( variant.isValid() ) {
423
        QVERIFY( variant.canConvert<QString>() );
424
    }
425
    variant = model->data ( model->index ( 0, 0 ), Qt::StatusTipRole );
426
    if ( variant.isValid() ) {
427
        QVERIFY( variant.canConvert<QString>() );
428
    }
429
    variant = model->data ( model->index ( 0, 0 ), Qt::WhatsThisRole );
430
    if ( variant.isValid() ) {
431
        QVERIFY( variant.canConvert<QString>() );
432
    }
433

434
    // General Purpose roles that should return a QSize
435
    variant = model->data ( model->index ( 0, 0 ), Qt::SizeHintRole );
436
    if ( variant.isValid() ) {
437
        QVERIFY( variant.canConvert<QSize>() );
438
    }
439

440
    // General Purpose roles that should return a QFont
441
    QVariant fontVariant = model->data ( model->index ( 0, 0 ), Qt::FontRole );
442
    if ( fontVariant.isValid() ) {
443
        QVERIFY( fontVariant.canConvert<QFont>() );
444
    }
445

446
    // Check that the alignment is one we know about
447
    QVariant textAlignmentVariant = model->data ( model->index ( 0, 0 ), Qt::TextAlignmentRole );
448
    if ( textAlignmentVariant.isValid() ) {
449
        int alignment = textAlignmentVariant.toInt();
450
        QCOMPARE( alignment, static_cast<int>( alignment & ( Qt::AlignHorizontal_Mask
451
                                                           | Qt::AlignVertical_Mask ) ) );
452
    }
453

454
    // General Purpose roles that should return a QColor
455
    QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundColorRole );
456
    if ( colorVariant.isValid() ) {
457
        QVERIFY( colorVariant.canConvert<QColor>() );
458
    }
459

460
    colorVariant = model->data ( model->index ( 0, 0 ), Qt::TextColorRole );
461
    if ( colorVariant.isValid() ) {
462
        QVERIFY( colorVariant.canConvert<QColor>() );
463
    }
464

465
    // Check that the "check state" is one we know about.
466
    QVariant checkStateVariant = model->data ( model->index ( 0, 0 ), Qt::CheckStateRole );
467
    if ( checkStateVariant.isValid() ) {
468
        int state = checkStateVariant.toInt();
469
        QVERIFY( state == Qt::Unchecked ||
470
                 state == Qt::PartiallyChecked ||
471
                 state == Qt::Checked );
472
    }
473
}
474

475
/*!
476
    Store what is about to be inserted to make sure it actually happens
477

478
    \sa rowsInserted()
479
 */
480
void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, int /* end */)
481
{
482
//     Q_UNUSED(end);
483
//    qDebug() << "rowsAboutToBeInserted" << "start=" << start << "end=" << end << "parent=" << model->data ( parent ).toString()
484
//    << "current count of parent=" << model->rowCount ( parent ); // << "display of last=" << model->data( model->index(start-1, 0, parent) );
485
//     qDebug() << model->index(start-1, 0, parent) << model->data( model->index(start-1, 0, parent) );
486
    Changing c;
487
    c.parent = parent;
488
    c.oldSize = model->rowCount ( parent );
489
    c.last = model->data ( model->index ( start - 1, 0, parent ) );
490
    c.next = model->data ( model->index ( start, 0, parent ) );
491
    insert.push ( c );
492
}
493

494
/*!
495
    Confirm that what was said was going to happen actually did
496

497
    \sa rowsAboutToBeInserted()
498
 */
499
void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
500
{
501
    Changing c = insert.pop();
502
    QVERIFY( c.parent == parent );
503
//    qDebug() << "rowsInserted"  << "start=" << start << "end=" << end << "oldsize=" << c.oldSize
504
//    << "parent=" << model->data ( parent ).toString() << "current rowcount of parent=" << model->rowCount ( parent );
505

506
//    for (int ii=start; ii <= end; ii++)
507
//    {
508
//      qDebug() << "itemWasInserted:" << ii << model->data ( model->index ( ii, 0, parent ));
509
//    }
510
//    qDebug();
511

512
    QVERIFY( c.oldSize + ( end - start + 1 ) == model->rowCount ( parent ) );
513
    QVERIFY( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) );
514

515
    if (c.next != model->data(model->index(end + 1, 0, c.parent))) {
516
        qDebug() << start << end;
517
        for (int i=0; i < model->rowCount(); ++i)
518
            qDebug() << model->index(i, 0).data().toString();
519
        qDebug() << c.next << model->data(model->index(end + 1, 0, c.parent));
520
    }
521

522
    QVERIFY( c.next == model->data ( model->index ( end + 1, 0, c.parent ) ) );
523
}
524

525
void ModelTest::layoutAboutToBeChanged()
526
{
527
    for ( int i = 0; i < qBound ( 0, model->rowCount(), 100 ); ++i )
528
        changing.append ( QPersistentModelIndex ( model->index ( i, 0 ) ) );
529
}
530

531
void ModelTest::layoutChanged()
532
{
533
    for ( int i = 0; i < changing.count(); ++i ) {
534
        QPersistentModelIndex p = changing[i];
535
        QVERIFY( p == model->index ( p.row(), p.column(), p.parent() ) );
536
    }
537
    changing.clear();
538
}
539

540
/*!
541
    Store what is about to be inserted to make sure it actually happens
542

543
    \sa rowsRemoved()
544
 */
545
void ModelTest::rowsAboutToBeRemoved ( const QModelIndex &parent, int start, int end )
546
{
547
//qDebug() << "ratbr" << parent << start << end;
548
    Changing c;
549
    c.parent = parent;
550
    c.oldSize = model->rowCount ( parent );
551
    c.last = model->data ( model->index ( start - 1, 0, parent ) );
552
    c.next = model->data ( model->index ( end + 1, 0, parent ) );
553
    remove.push ( c );
554
}
555

556
/*!
557
    Confirm that what was said was going to happen actually did
558

559
    \sa rowsAboutToBeRemoved()
560
 */
561
void ModelTest::rowsRemoved ( const QModelIndex & parent, int start, int end )
562
{
563
//  qDebug() << "rr" << parent << start << end;
564
    Changing c = remove.pop();
565
    QVERIFY( c.parent == parent );
566
    QVERIFY( c.oldSize - ( end - start + 1 ) == model->rowCount ( parent ) );
567
    QVERIFY( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) );
568
    QVERIFY( c.next == model->data ( model->index ( start, 0, c.parent ) ) );
569
}
570

571
void ModelTest::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
572
{
573
    QVERIFY(topLeft.isValid());
574
    QVERIFY(bottomRight.isValid());
575
    QModelIndex commonParent = bottomRight.parent();
576
    QVERIFY(topLeft.parent() == commonParent);
577
    QVERIFY(topLeft.row() <= bottomRight.row());
578
    QVERIFY(topLeft.column() <= bottomRight.column());
579
    int rowCount = model->rowCount(commonParent);
580
    int columnCount = model->columnCount(commonParent);
581
    QVERIFY(bottomRight.row() < rowCount);
582
    QVERIFY(bottomRight.column() < columnCount);
583
}
584

585
void ModelTest::headerDataChanged(Qt::Orientation orientation, int start, int end)
586
{
587
    QVERIFY(start >= 0);
588
    QVERIFY(end >= 0);
589
    QVERIFY(start <= end);
590
    int itemCount = orientation == Qt::Vertical ? model->rowCount() : model->columnCount();
591
    QVERIFY(start < itemCount);
592
    QVERIFY(end < itemCount);
593
}
594

595
void ModelTest::rowsAboutToBeMoved( const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destinationRow )
596
{
597
    Changing cs;
598
    cs.parent = srcParent;
599
    cs.oldSize = model->rowCount ( srcParent );
600
    cs.last = model->data ( model->index ( start - 1, 0, srcParent ) );
601
    cs.next = model->data ( model->index ( end + 1, 0, srcParent ) );
602
    remove.push ( cs );
603
    Changing cd;
604
    cd.parent = destParent;
605
    cd.oldSize = model->rowCount ( destParent );
606
    cd.last = model->data ( model->index ( destinationRow - 1, 0, destParent ) );
607
    cd.next = model->data ( model->index ( destinationRow, 0, destParent ) );
608
    insert.push ( cd );
609
}
610

611
void ModelTest::rowsMoved( const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destinationRow )
612
{
613
    Changing cd = insert.pop();
614
    QVERIFY ( cd.parent == destParent );
615
    if (srcParent == destParent) {
616
        QVERIFY ( cd.oldSize == model->rowCount ( destParent ) );
617

618
        // TODO: Find out what I can assert here about last and next.
619
        // Q_ASSERT ( cd.last == model->data ( model->index ( destinationRow - 1, 0, cd.parent ) ) );
620
        // Q_ASSERT ( cd.next == model->data ( model->index ( destinationRow + (end - start + 1), 0, cd.parent ) ) );
621
    }
622
    else {
623
        QVERIFY ( cd.oldSize + ( end - start + 1 ) == model->rowCount ( destParent ) );
624

625
        QVERIFY ( cd.last == model->data ( model->index ( destinationRow - 1, 0, cd.parent ) ) );
626
        QVERIFY ( cd.next == model->data ( model->index ( destinationRow + (end - start + 1), 0, cd.parent ) ) );
627
    }
628

629
    Changing cs = remove.pop();
630
    QVERIFY ( cs.parent == srcParent );
631
    if (srcParent == destParent) {
632
        QVERIFY ( cs.oldSize == model->rowCount ( srcParent ) );
633
    }
634
    else {
635
        QVERIFY ( cs.oldSize - ( end - start + 1 ) == model->rowCount ( srcParent ) );
636

637
        QVERIFY ( cs.last == model->data ( model->index ( start - 1, 0, srcParent ) ) );
638
        QVERIFY ( cs.next == model->data ( model->index ( start, 0, srcParent ) ) );
639
    }
640
}
641

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.