| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2012 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 |
** $QT_BEGIN_LICENSE:LGPL$ |
| 10 |
** GNU Lesser General Public License Usage |
| 11 |
** This file may be used under the terms of the GNU Lesser General Public |
| 12 |
** License version 2.1 as published by the Free Software Foundation and |
| 13 |
** appearing in the file LICENSE.LGPL included in the packaging of this |
| 14 |
** file. Please review the following information to ensure the GNU Lesser |
| 15 |
** General Public License version 2.1 requirements will be met: |
| 16 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 17 |
** |
| 18 |
** In addition, as a special exception, Nokia gives you certain additional |
| 19 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 20 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 21 |
** |
| 22 |
** GNU General Public License Usage |
| 23 |
** Alternatively, this file may be used under the terms of the GNU General |
| 24 |
** Public License version 3.0 as published by the Free Software Foundation |
| 25 |
** and appearing in the file LICENSE.GPL included in the packaging of this |
| 26 |
** file. Please review the following information to ensure the GNU General |
| 27 |
** Public License version 3.0 requirements will be met: |
| 28 |
** http://www.gnu.org/copyleft/gpl.html. |
| 29 |
** |
| 30 |
** Other Usage |
| 31 |
** Alternatively, this file may be used in accordance with the terms and |
| 32 |
** conditions contained in a signed written agreement between you and Nokia. |
| 33 |
** |
| 34 |
** |
| 35 |
** |
| 36 |
** |
| 37 |
** |
| 38 |
** $QT_END_LICENSE$ |
| 39 |
** |
| 40 |
****************************************************************************/ |
| 41 |
|
| 42 |
|
| 43 |
#include <QtTest/QtTest> |
| 44 |
|
| 45 |
#include <qapplication.h> |
| 46 |
#include <q3listview.h> |
| 47 |
|
| 48 |
//TESTED_CLASS= |
| 49 |
//TESTED_FILES= |
| 50 |
|
| 51 |
class tst_Q3ListViewItemIterator : public QObject |
| 52 |
{ |
| 53 |
Q_OBJECT |
| 54 |
|
| 55 |
public: |
| 56 |
tst_Q3ListViewItemIterator(); |
| 57 |
virtual ~tst_Q3ListViewItemIterator(); |
| 58 |
|
| 59 |
|
| 60 |
public slots: |
| 61 |
void init(); |
| 62 |
void cleanup(); |
| 63 |
private slots: |
| 64 |
void copy_and_assignment(); |
| 65 |
void operator_plus_plus_data(); |
| 66 |
void operator_plus_plus(); |
| 67 |
void operator_minus_minus_data(); |
| 68 |
void operator_minus_minus(); |
| 69 |
void operator_plus_equals_data(); |
| 70 |
void operator_plus_equals(); |
| 71 |
void operator_minus_equals_data(); |
| 72 |
void operator_minus_equals(); |
| 73 |
|
| 74 |
private: |
| 75 |
Q3ListView *testWidget; |
| 76 |
QList<Q3CheckListItem*> testItems; |
| 77 |
|
| 78 |
void prepareItem( Q3CheckListItem *item, int flags ); |
| 79 |
}; |
| 80 |
|
| 81 |
typedef QList<int> IntList; |
| 82 |
Q_DECLARE_METATYPE(IntList) |
| 83 |
|
| 84 |
tst_Q3ListViewItemIterator::tst_Q3ListViewItemIterator() |
| 85 |
{ |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
tst_Q3ListViewItemIterator::~tst_Q3ListViewItemIterator() |
| 90 |
{ |
| 91 |
|
| 92 |
} |
| 93 |
|
| 94 |
void tst_Q3ListViewItemIterator::copy_and_assignment() |
| 95 |
{ |
| 96 |
// sets up every second item to be selected (item 1, 3, 5 etc.) |
| 97 |
for (int i=0; i<testItems.count(); ++i ) { |
| 98 |
if (i%2) { |
| 99 |
prepareItem(testItems.at( i ), Q3ListViewItemIterator::Selected); |
| 100 |
} else { |
| 101 |
prepareItem(testItems.at( i ), 0); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
// create iterator, copy it with copy constructor and assignment operator |
| 106 |
Q3ListViewItemIterator it(testWidget, Q3ListViewItemIterator::Selected); |
| 107 |
Q3ListViewItemIterator copied(it); |
| 108 |
Q3ListViewItemIterator assigned = it; |
| 109 |
|
| 110 |
// we expect at least one valid current item |
| 111 |
QVERIFY(it.current()); |
| 112 |
QVERIFY(copied.current()); |
| 113 |
QVERIFY(assigned.current()); |
| 114 |
|
| 115 |
// check that all iterators point to the same current item |
| 116 |
while (it.current()) { |
| 117 |
QVERIFY(it.current() == copied.current()); |
| 118 |
QVERIFY(it.current() == assigned.current()); |
| 119 |
++it; |
| 120 |
++copied; |
| 121 |
++assigned; |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
void tst_Q3ListViewItemIterator::operator_plus_plus_data() |
| 126 |
{ |
| 127 |
QTest::addColumn<IntList>("itemFlags"); |
| 128 |
QTest::addColumn<int>("iteratorFlags"); |
| 129 |
QTest::addColumn<QStringList>("expectedItems"); |
| 130 |
{ |
| 131 |
IntList itemFlags; |
| 132 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 133 |
itemFlags.append( 0 ); |
| 134 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 135 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 136 |
|
| 137 |
int flags = Q3ListViewItemIterator::Selected; |
| 138 |
|
| 139 |
QStringList expectedItems; |
| 140 |
expectedItems.append( "item1" ); |
| 141 |
expectedItems.append( "item3" ); |
| 142 |
expectedItems.append( "item4" ); |
| 143 |
|
| 144 |
QTest::newRow( "Selected 01" ) << itemFlags << flags << expectedItems; |
| 145 |
} |
| 146 |
{ |
| 147 |
IntList itemFlags; |
| 148 |
itemFlags.append( 0 ); |
| 149 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 150 |
itemFlags.append( 0 ); |
| 151 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 152 |
|
| 153 |
int flags = Q3ListViewItemIterator::Selected; |
| 154 |
|
| 155 |
QStringList expectedItems; |
| 156 |
expectedItems.append( "item2" ); |
| 157 |
expectedItems.append( "item4" ); |
| 158 |
|
| 159 |
QTest::newRow( "Selected 02" ) << itemFlags << flags << expectedItems; |
| 160 |
} |
| 161 |
{ |
| 162 |
IntList itemFlags; |
| 163 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 164 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 165 |
itemFlags.append( 0 ); |
| 166 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 167 |
|
| 168 |
int flags = Q3ListViewItemIterator::Unselected; |
| 169 |
|
| 170 |
QStringList expectedItems; |
| 171 |
expectedItems.append( "item3" ); |
| 172 |
expectedItems.append( "item5" ); |
| 173 |
expectedItems.append( "item6" ); |
| 174 |
expectedItems.append( "item7" ); |
| 175 |
expectedItems.append( "item8" ); |
| 176 |
expectedItems.append( "item9" ); |
| 177 |
expectedItems.append( "item10" ); |
| 178 |
QTest::newRow( "Unselected" ) << itemFlags << flags << expectedItems; |
| 179 |
} |
| 180 |
{ |
| 181 |
IntList itemFlags; |
| 182 |
|
| 183 |
int flags = Q3ListViewItemIterator::Visible | |
| 184 |
Q3ListViewItemIterator::Unselected | |
| 185 |
Q3ListViewItemIterator::Selectable | |
| 186 |
Q3ListViewItemIterator::DragDisabled | |
| 187 |
Q3ListViewItemIterator::DropDisabled | |
| 188 |
Q3ListViewItemIterator::NotExpandable | |
| 189 |
Q3ListViewItemIterator::NotChecked; |
| 190 |
|
| 191 |
QStringList expectedItems; |
| 192 |
expectedItems.append( "item1" ); |
| 193 |
expectedItems.append( "item2" ); |
| 194 |
expectedItems.append( "item3" ); |
| 195 |
expectedItems.append( "item4" ); |
| 196 |
expectedItems.append( "item5" ); |
| 197 |
expectedItems.append( "item6" ); |
| 198 |
expectedItems.append( "item7" ); |
| 199 |
expectedItems.append( "item8" ); |
| 200 |
expectedItems.append( "item9" ); |
| 201 |
expectedItems.append( "item10" ); |
| 202 |
QTest::newRow( "All default settings" ) << itemFlags << flags << expectedItems; |
| 203 |
} |
| 204 |
{ |
| 205 |
IntList itemFlags; |
| 206 |
|
| 207 |
int flags = 0; |
| 208 |
|
| 209 |
QStringList expectedItems; |
| 210 |
expectedItems.append( "item1" ); |
| 211 |
expectedItems.append( "item2" ); |
| 212 |
expectedItems.append( "item3" ); |
| 213 |
expectedItems.append( "item4" ); |
| 214 |
expectedItems.append( "item5" ); |
| 215 |
expectedItems.append( "item6" ); |
| 216 |
expectedItems.append( "item7" ); |
| 217 |
expectedItems.append( "item8" ); |
| 218 |
expectedItems.append( "item9" ); |
| 219 |
expectedItems.append( "item10" ); |
| 220 |
QTest::newRow( "Normal iterator (no flags)" ) << itemFlags << flags << expectedItems; |
| 221 |
} |
| 222 |
{ |
| 223 |
int flags = Q3ListViewItemIterator::Selected | |
| 224 |
Q3ListViewItemIterator::Checked; |
| 225 |
|
| 226 |
IntList itemFlags; |
| 227 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 228 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 229 |
itemFlags.append( flags ); |
| 230 |
itemFlags.append( flags ); |
| 231 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 232 |
|
| 233 |
QStringList expectedItems; |
| 234 |
expectedItems.append( "item3" ); |
| 235 |
expectedItems.append( "item4" ); |
| 236 |
QTest::newRow( "Selected | Checked" ) << itemFlags << flags << expectedItems; |
| 237 |
} |
| 238 |
{ |
| 239 |
int flags = Q3ListViewItemIterator::Selected | |
| 240 |
Q3ListViewItemIterator::Unselected; |
| 241 |
|
| 242 |
IntList itemFlags; |
| 243 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 244 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 245 |
itemFlags.append( flags ); |
| 246 |
itemFlags.append( flags ); |
| 247 |
itemFlags.append( Q3ListViewItemIterator::Unselected ); |
| 248 |
itemFlags.append( Q3ListViewItemIterator::Unselected ); |
| 249 |
itemFlags.append( flags ); |
| 250 |
|
| 251 |
QStringList expectedItems; |
| 252 |
QTest::newRow( "Selected | Unselected" ) << itemFlags << flags << expectedItems; |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
void tst_Q3ListViewItemIterator::operator_minus_minus_data() |
| 257 |
{ |
| 258 |
QTest::addColumn<IntList>("itemFlags"); |
| 259 |
QTest::addColumn<int>("iteratorFlags"); |
| 260 |
QTest::addColumn<QStringList>("expectedItems"); |
| 261 |
{ |
| 262 |
IntList itemFlags; |
| 263 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 264 |
itemFlags.append( 0 ); |
| 265 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 266 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 267 |
|
| 268 |
int flags = Q3ListViewItemIterator::Selected; |
| 269 |
|
| 270 |
QStringList expectedItems; |
| 271 |
expectedItems.append( "item4" ); |
| 272 |
expectedItems.append( "item3" ); |
| 273 |
expectedItems.append( "item1" ); |
| 274 |
|
| 275 |
QTest::newRow( "Selected 01" ) << itemFlags << flags << expectedItems; |
| 276 |
} |
| 277 |
{ |
| 278 |
IntList itemFlags; |
| 279 |
itemFlags.append( Q3ListViewItemIterator::Checked ); |
| 280 |
itemFlags.append( 0 ); |
| 281 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 282 |
itemFlags.append( Q3ListViewItemIterator::Selected | Q3ListViewItemIterator::NotChecked ); |
| 283 |
|
| 284 |
int flags = Q3ListViewItemIterator::Selected | |
| 285 |
Q3ListViewItemIterator::Checked; |
| 286 |
|
| 287 |
QStringList expectedItems; |
| 288 |
QTest::newRow( "Selected | Checked" ) << itemFlags << flags << expectedItems; |
| 289 |
} |
| 290 |
{ |
| 291 |
IntList itemFlags; |
| 292 |
|
| 293 |
int flags = 0; |
| 294 |
|
| 295 |
QStringList expectedItems; |
| 296 |
expectedItems.append( "item10" ); |
| 297 |
expectedItems.append( "item9" ); |
| 298 |
expectedItems.append( "item8" ); |
| 299 |
expectedItems.append( "item7" ); |
| 300 |
expectedItems.append( "item6" ); |
| 301 |
expectedItems.append( "item5" ); |
| 302 |
expectedItems.append( "item4" ); |
| 303 |
expectedItems.append( "item3" ); |
| 304 |
expectedItems.append( "item2" ); |
| 305 |
expectedItems.append( "item1" ); |
| 306 |
QTest::newRow( "Normal iterator (no flags)" ) << itemFlags << flags << expectedItems; |
| 307 |
} |
| 308 |
} |
| 309 |
|
| 310 |
void tst_Q3ListViewItemIterator::operator_plus_equals_data() |
| 311 |
{ |
| 312 |
QTest::addColumn<IntList>("itemFlags"); |
| 313 |
QTest::addColumn<int>("iteratorFlags"); |
| 314 |
QTest::addColumn<QStringList>("expectedItems"); |
| 315 |
QTest::addColumn<int>("stepSize"); |
| 316 |
{ |
| 317 |
IntList itemFlags; |
| 318 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 319 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 320 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 321 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 322 |
|
| 323 |
int flags = Q3ListViewItemIterator::Selected; |
| 324 |
|
| 325 |
QStringList expectedItems; |
| 326 |
expectedItems.append( "item1" ); |
| 327 |
expectedItems.append( "item3" ); |
| 328 |
|
| 329 |
QTest::newRow( "Selected 01" ) << itemFlags << flags << expectedItems << 2; |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
void tst_Q3ListViewItemIterator::operator_minus_equals_data() |
| 334 |
{ |
| 335 |
QTest::addColumn<IntList>("itemFlags"); |
| 336 |
QTest::addColumn<int>("iteratorFlags"); |
| 337 |
QTest::addColumn<QStringList>("expectedItems"); |
| 338 |
QTest::addColumn<int>("stepSize"); |
| 339 |
{ |
| 340 |
IntList itemFlags; |
| 341 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 342 |
itemFlags.append( 0 ); |
| 343 |
itemFlags.append( 0 ); |
| 344 |
itemFlags.append( 0 ); |
| 345 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 346 |
itemFlags.append( 0 ); |
| 347 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 348 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 349 |
itemFlags.append( 0 ); |
| 350 |
itemFlags.append( Q3ListViewItemIterator::Selected ); |
| 351 |
|
| 352 |
int flags = Q3ListViewItemIterator::Selected; |
| 353 |
|
| 354 |
QStringList expectedItems; |
| 355 |
expectedItems.append( "item10" ); |
| 356 |
expectedItems.append( "item7" ); |
| 357 |
expectedItems.append( "item1" ); |
| 358 |
|
| 359 |
QTest::newRow( "Selected 01" ) << itemFlags << flags << expectedItems << 2; |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
void tst_Q3ListViewItemIterator::init() |
| 364 |
{ |
| 365 |
testWidget = new Q3ListView(); |
| 366 |
testWidget->addColumn( "Testing" ); |
| 367 |
testWidget->setRootIsDecorated( TRUE ); |
| 368 |
testWidget->setSorting( -1 ); |
| 369 |
|
| 370 |
testItems.clear(); |
| 371 |
|
| 372 |
// this listviewitem tree should become more complex in later tests |
| 373 |
for ( int i =10; i>0; --i) { |
| 374 |
Q3CheckListItem *item = new Q3CheckListItem( testWidget, "item" + QString::number( i ), Q3CheckListItem::CheckBox ); |
| 375 |
testItems.insert( 0, item ); |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
void tst_Q3ListViewItemIterator::cleanup() |
| 380 |
{ |
| 381 |
if ( testWidget ) |
| 382 |
delete testWidget; |
| 383 |
testWidget = 0; |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
void tst_Q3ListViewItemIterator::operator_plus_plus() |
| 388 |
{ |
| 389 |
QFETCH( IntList, itemFlags ); |
| 390 |
QFETCH( int, iteratorFlags ); |
| 391 |
QFETCH( QStringList, expectedItems ); |
| 392 |
|
| 393 |
// sets up the items |
| 394 |
for (int i=0; i<testItems.count(); ++i ) { |
| 395 |
if ( itemFlags.count() > i ) |
| 396 |
prepareItem( testItems.at( i ), itemFlags[ i ] ); |
| 397 |
} |
| 398 |
|
| 399 |
// gets the iterator |
| 400 |
Q3ListViewItemIterator it( testWidget ); |
| 401 |
if ( iteratorFlags != 0 ) |
| 402 |
it = Q3ListViewItemIterator( testWidget, iteratorFlags ); |
| 403 |
|
| 404 |
// iterates over them and compares with expectedItems |
| 405 |
QStringList::iterator expected = expectedItems.begin(); |
| 406 |
if ( it.current() == 0 ) { |
| 407 |
QVERIFY( expectedItems.empty() ); |
| 408 |
} else { |
| 409 |
while ( it.current() ) { |
| 410 |
QCOMPARE( it.current()->text( 0 ), *expected ); |
| 411 |
it++; |
| 412 |
expected++; |
| 413 |
} |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
void tst_Q3ListViewItemIterator::operator_minus_minus() |
| 418 |
{ |
| 419 |
QFETCH( IntList, itemFlags ); |
| 420 |
QFETCH( int, iteratorFlags ); |
| 421 |
QFETCH( QStringList, expectedItems ); |
| 422 |
|
| 423 |
// sets up the items |
| 424 |
for (int i=0; i<testItems.count(); ++i ) { |
| 425 |
if ( itemFlags.count() > i ) |
| 426 |
prepareItem( testItems.at( i ), itemFlags[ i ] ); |
| 427 |
} |
| 428 |
|
| 429 |
// gets the iterator |
| 430 |
Q3ListViewItemIterator it( testWidget ); |
| 431 |
if ( iteratorFlags != 0 ) |
| 432 |
it = Q3ListViewItemIterator( testWidget, iteratorFlags ); |
| 433 |
|
| 434 |
// traverse to the last valid item |
| 435 |
Q3ListViewItem *item = 0; |
| 436 |
while ( it.current() ) { |
| 437 |
item = it.current(); |
| 438 |
++it; |
| 439 |
} |
| 440 |
if ( iteratorFlags != 0 ) |
| 441 |
it = Q3ListViewItemIterator( item, iteratorFlags ); |
| 442 |
else |
| 443 |
it = Q3ListViewItemIterator( item ); |
| 444 |
|
| 445 |
// iterates over them and compares with expectedItems |
| 446 |
QStringList::iterator expected = expectedItems.begin(); |
| 447 |
if ( it.current() == 0 ) { |
| 448 |
QVERIFY( expectedItems.empty() ); |
| 449 |
} else { |
| 450 |
while ( it.current() ) { |
| 451 |
QCOMPARE( it.current()->text( 0 ), *expected ); |
| 452 |
it--; |
| 453 |
expected++; |
| 454 |
} |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
void tst_Q3ListViewItemIterator::operator_plus_equals() |
| 459 |
{ |
| 460 |
QFETCH( IntList, itemFlags ); |
| 461 |
QFETCH( int, iteratorFlags ); |
| 462 |
QFETCH( QStringList, expectedItems ); |
| 463 |
QFETCH( int, stepSize ); |
| 464 |
|
| 465 |
// sets up the items |
| 466 |
for (int i=0; i<testItems.count(); ++i ) { |
| 467 |
if ( itemFlags.count() > i ) |
| 468 |
prepareItem( testItems.at( i ), itemFlags[ i ] ); |
| 469 |
} |
| 470 |
|
| 471 |
// gets the iterator |
| 472 |
Q3ListViewItemIterator it( testWidget ); |
| 473 |
if ( iteratorFlags != 0 ) |
| 474 |
it = Q3ListViewItemIterator( testWidget, iteratorFlags ); |
| 475 |
|
| 476 |
// iterates over them and compares with expectedItems |
| 477 |
QStringList::iterator expected = expectedItems.begin(); |
| 478 |
if ( it.current() == 0 ) { |
| 479 |
QVERIFY( expectedItems.empty() ); |
| 480 |
} else { |
| 481 |
while ( it.current() ) { |
| 482 |
QCOMPARE( it.current()->text( 0 ), *expected ); |
| 483 |
it += stepSize; |
| 484 |
expected++; |
| 485 |
} |
| 486 |
} |
| 487 |
} |
| 488 |
|
| 489 |
void tst_Q3ListViewItemIterator::operator_minus_equals() |
| 490 |
{ |
| 491 |
QFETCH( IntList, itemFlags ); |
| 492 |
QFETCH( int, iteratorFlags ); |
| 493 |
QFETCH( QStringList, expectedItems ); |
| 494 |
QFETCH( int, stepSize ); |
| 495 |
|
| 496 |
// sets up the items |
| 497 |
for (int i=0; i<testItems.count(); ++i ) { |
| 498 |
if ( itemFlags.count() > i ) |
| 499 |
prepareItem( testItems.at( i ), itemFlags[ i ] ); |
| 500 |
} |
| 501 |
|
| 502 |
// gets the iterator |
| 503 |
Q3ListViewItemIterator it( testWidget ); |
| 504 |
if ( iteratorFlags != 0 ) |
| 505 |
it = Q3ListViewItemIterator( testWidget, iteratorFlags ); |
| 506 |
|
| 507 |
// traverse to the last valid item |
| 508 |
Q3ListViewItem *item = 0; |
| 509 |
while ( it.current() ) { |
| 510 |
item = it.current(); |
| 511 |
++it; |
| 512 |
} |
| 513 |
if ( iteratorFlags != 0 ) |
| 514 |
it = Q3ListViewItemIterator( item, iteratorFlags ); |
| 515 |
else |
| 516 |
it = Q3ListViewItemIterator( item ); |
| 517 |
|
| 518 |
// iterates over them and compares with expectedItems |
| 519 |
QStringList::iterator expected = expectedItems.begin(); |
| 520 |
if ( it.current() == 0 ) { |
| 521 |
QVERIFY( expectedItems.empty() ); |
| 522 |
} else { |
| 523 |
while ( it.current() ) { |
| 524 |
QCOMPARE( it.current()->text( 0 ), *expected ); |
| 525 |
it -= stepSize; |
| 526 |
expected++; |
| 527 |
} |
| 528 |
} |
| 529 |
} |
| 530 |
|
| 531 |
void tst_Q3ListViewItemIterator::prepareItem( Q3CheckListItem *item, int flags ) |
| 532 |
{ |
| 533 |
if ( flags & Q3ListViewItemIterator::Visible ) |
| 534 |
item->setVisible( TRUE ); |
| 535 |
if ( flags & Q3ListViewItemIterator::Invisible ) |
| 536 |
item->setVisible( FALSE ); |
| 537 |
if ( flags & Q3ListViewItemIterator::Selected ) |
| 538 |
item->setSelected( TRUE ); |
| 539 |
if ( flags & Q3ListViewItemIterator::Unselected ) |
| 540 |
item->setSelected( FALSE ); |
| 541 |
if ( flags & Q3ListViewItemIterator::Selectable ) |
| 542 |
item->setSelectable( TRUE ); |
| 543 |
if ( flags & Q3ListViewItemIterator::NotSelectable ) |
| 544 |
item->setSelectable( FALSE ); |
| 545 |
if ( flags & Q3ListViewItemIterator::DragEnabled ) |
| 546 |
item->setDragEnabled( TRUE ); |
| 547 |
if ( flags & Q3ListViewItemIterator::DragDisabled ) |
| 548 |
item->setDragEnabled( FALSE ); |
| 549 |
if ( flags & Q3ListViewItemIterator::DropEnabled ) |
| 550 |
item->setDropEnabled( TRUE ); |
| 551 |
if ( flags & Q3ListViewItemIterator::DropDisabled ) |
| 552 |
item->setDropEnabled( FALSE ); |
| 553 |
if ( flags & Q3ListViewItemIterator::Expandable ) |
| 554 |
item->setExpandable( TRUE ); |
| 555 |
if ( flags & Q3ListViewItemIterator::NotExpandable ) |
| 556 |
item->setExpandable( FALSE ); |
| 557 |
if ( flags & Q3ListViewItemIterator::Checked ) |
| 558 |
item->setOn( TRUE ); |
| 559 |
if ( flags & Q3ListViewItemIterator::NotChecked ) |
| 560 |
item->setOn( FALSE ); |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
QTEST_MAIN(tst_Q3ListViewItemIterator) |
| 566 |
#include "tst_q3listviewitemiterator.moc" |