| 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 |
** $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 |
|
| 46 |
#include <qapplication.h> |
| 47 |
#include <q3listbox.h> |
| 48 |
#include <qvariant.h> |
| 49 |
|
| 50 |
//TESTED_CLASS= |
| 51 |
//TESTED_FILES= |
| 52 |
|
| 53 |
class tst_Q3ListBox : public QObject |
| 54 |
{ |
| 55 |
Q_OBJECT |
| 56 |
|
| 57 |
public: |
| 58 |
tst_Q3ListBox(); |
| 59 |
virtual ~tst_Q3ListBox(); |
| 60 |
|
| 61 |
|
| 62 |
protected slots: |
| 63 |
void selectionChanged_helper(); |
| 64 |
void currentChanged_helper(Q3ListBoxItem *); |
| 65 |
void highlighted_helper(Q3ListBoxItem *); |
| 66 |
|
| 67 |
public slots: |
| 68 |
void initTestCase(); |
| 69 |
void cleanupTestCase(); |
| 70 |
void init(); |
| 71 |
void cleanup(); |
| 72 |
private slots: |
| 73 |
void count(); |
| 74 |
void itemAt(); |
| 75 |
void selectionChangedSingleSelection(); |
| 76 |
void selectionChangedExtendedSelection(); |
| 77 |
void selectionChangedMultiSelection(); |
| 78 |
void currentChangedSingleSelection(); |
| 79 |
void currentChangedExtendedSelection(); |
| 80 |
void currentChangedMultiSelection(); |
| 81 |
void highlightedChangedSingleSelection(); |
| 82 |
void highlightedChangedExtendedSelection(); |
| 83 |
void highlightedChangedMultiSelection(); |
| 84 |
private: |
| 85 |
Q3ListBox *testWidget; |
| 86 |
Q3ListBoxItem *selectedItem; |
| 87 |
bool selectionChangedSignal; |
| 88 |
Q3ListBoxItem *currentItem; |
| 89 |
bool currentChangedSignal; |
| 90 |
Q3ListBoxItem *highlightedItem; |
| 91 |
bool highlightedSignal; |
| 92 |
int currentChangedCount, selectionChangedCount, highlightedCount, itemHeight; |
| 93 |
}; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
tst_Q3ListBox::tst_Q3ListBox() |
| 99 |
{ |
| 100 |
} |
| 101 |
|
| 102 |
tst_Q3ListBox::~tst_Q3ListBox() |
| 103 |
{ |
| 104 |
} |
| 105 |
|
| 106 |
void tst_Q3ListBox::initTestCase() |
| 107 |
{ |
| 108 |
// Create the test class |
| 109 |
testWidget = new Q3ListBox(0,"testObject"); |
| 110 |
testWidget->resize(200,200); |
| 111 |
qApp->setMainWidget(testWidget); |
| 112 |
testWidget->show(); |
| 113 |
|
| 114 |
// Connect things here, so they aren't done more than once |
| 115 |
connect(testWidget, SIGNAL(currentChanged(Q3ListBoxItem *)), this, SLOT(currentChanged_helper(Q3ListBoxItem *))); |
| 116 |
connect(testWidget, SIGNAL(selectionChanged()), this, SLOT(selectionChanged_helper())); |
| 117 |
connect(testWidget, SIGNAL(highlighted(Q3ListBoxItem *)), this, SLOT(highlighted_helper(Q3ListBoxItem *))); |
| 118 |
} |
| 119 |
|
| 120 |
void tst_Q3ListBox::cleanupTestCase() |
| 121 |
{ |
| 122 |
delete testWidget; |
| 123 |
} |
| 124 |
|
| 125 |
void tst_Q3ListBox::init() |
| 126 |
{ |
| 127 |
testWidget->insertItem("This is a test"); |
| 128 |
testWidget->insertItem("And this is another"); |
| 129 |
testWidget->insertItem("Radiohead kicks ass!"); |
| 130 |
testWidget->insertItem("As do Sigur Ros!"); |
| 131 |
|
| 132 |
itemHeight = testWidget->itemHeight(0); // Safe to assume its the same for the standard tests |
| 133 |
|
| 134 |
selectionChangedCount = 0; |
| 135 |
selectionChangedSignal = false; |
| 136 |
selectedItem = 0; |
| 137 |
currentChangedCount = 0; |
| 138 |
currentChangedSignal = false; |
| 139 |
currentItem = 0; |
| 140 |
highlightedCount = 0; |
| 141 |
highlightedSignal = false; |
| 142 |
highlightedItem = 0; |
| 143 |
} |
| 144 |
|
| 145 |
void tst_Q3ListBox::cleanup() |
| 146 |
{ |
| 147 |
testWidget->clear(); |
| 148 |
} |
| 149 |
|
| 150 |
void tst_Q3ListBox::count() |
| 151 |
{ |
| 152 |
testWidget->clear(); |
| 153 |
QCOMPARE( testWidget->count(), (uint)0); |
| 154 |
testWidget->insertItem("1"); |
| 155 |
QCOMPARE( testWidget->count(), (uint)1); |
| 156 |
testWidget->insertItem("2"); |
| 157 |
QCOMPARE( testWidget->count(), (uint)2); |
| 158 |
} |
| 159 |
|
| 160 |
void tst_Q3ListBox::itemAt() |
| 161 |
{ |
| 162 |
QStringList itemText; |
| 163 |
itemText << "This is a test" |
| 164 |
<< "And this is another" |
| 165 |
<< "Radiohead kicks ass!" |
| 166 |
<< "As do Sigur Ros!"; |
| 167 |
|
| 168 |
// insert items |
| 169 |
for (int i=0; i<(int)itemText.count(); ++i) |
| 170 |
testWidget->insertItem(itemText[i]); |
| 171 |
|
| 172 |
QPoint itemPos = testWidget->viewport()->pos(); |
| 173 |
// test itemAt |
| 174 |
for (int i=0; i<(int)itemText.count(); ++i) { |
| 175 |
QCOMPARE(testWidget->item(i)->text(), itemText[i]); |
| 176 |
Q3ListBoxItem *item = 0; |
| 177 |
item = testWidget->itemAt(itemPos); |
| 178 |
if (item) { |
| 179 |
QCOMPARE(testWidget->itemAt(itemPos)->text(), itemText[i]); |
| 180 |
} else { |
| 181 |
QFAIL(QString("No item at QPoint(%1, %2)"). |
| 182 |
arg(itemPos.x()). |
| 183 |
arg(itemPos.y())); |
| 184 |
} |
| 185 |
itemPos += QPoint(0, testWidget->itemHeight(i)); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
void tst_Q3ListBox::selectionChanged_helper() |
| 190 |
{ |
| 191 |
selectionChangedCount++; |
| 192 |
selectionChangedSignal = true; |
| 193 |
selectedItem = testWidget->selectedItem(); |
| 194 |
} |
| 195 |
|
| 196 |
void tst_Q3ListBox::selectionChangedSingleSelection() |
| 197 |
{ |
| 198 |
testWidget->setSelectionMode(Q3ListBox::Single); |
| 199 |
testWidget->setSelected(testWidget->item(0), true); |
| 200 |
|
| 201 |
QVERIFY(selectionChangedSignal); |
| 202 |
QVERIFY(selectionChangedCount == 1); |
| 203 |
QVERIFY(testWidget->index(selectedItem) == 0); |
| 204 |
|
| 205 |
selectionChangedSignal = false; |
| 206 |
selectionChangedCount = 0; |
| 207 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ControlModifier, QPoint(5, itemHeight*2-5)); |
| 208 |
|
| 209 |
QVERIFY(selectionChangedSignal); |
| 210 |
QVERIFY(selectionChangedCount == 1); |
| 211 |
QVERIFY(testWidget->index(selectedItem) == 1); |
| 212 |
QCOMPARE(selectedItem->text(), QString::fromLatin1("And this is another")); |
| 213 |
|
| 214 |
selectionChangedSignal = false; |
| 215 |
selectionChangedCount = 0; |
| 216 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ShiftModifier, QPoint(5,itemHeight*3-5)); |
| 217 |
|
| 218 |
QVERIFY(selectionChangedSignal); |
| 219 |
QVERIFY(selectionChangedCount == 1); |
| 220 |
QVERIFY(testWidget->index(selectedItem) == 2); |
| 221 |
QCOMPARE(selectedItem->text(), QString::fromLatin1("Radiohead kicks ass!")); |
| 222 |
} |
| 223 |
|
| 224 |
void tst_Q3ListBox::selectionChangedExtendedSelection() |
| 225 |
{ |
| 226 |
testWidget->setSelectionMode(Q3ListBox::Extended); |
| 227 |
testWidget->setSelected(testWidget->item(0), true); |
| 228 |
|
| 229 |
QVERIFY(selectionChangedSignal); |
| 230 |
QVERIFY(selectionChangedCount == 1); |
| 231 |
QVERIFY(!selectedItem); // In this selection mode, it should be 0 |
| 232 |
|
| 233 |
selectionChangedSignal = false; |
| 234 |
selectionChangedCount = 0; |
| 235 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ControlModifier, QPoint(5,itemHeight*2-5)); |
| 236 |
|
| 237 |
QVERIFY(selectionChangedSignal); |
| 238 |
QVERIFY(selectionChangedCount == 1); |
| 239 |
QVERIFY(!selectedItem); |
| 240 |
|
| 241 |
selectionChangedSignal = false; |
| 242 |
selectionChangedCount = 0; |
| 243 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ShiftModifier, QPoint(5,itemHeight*3-5)); |
| 244 |
|
| 245 |
QVERIFY(selectionChangedSignal); |
| 246 |
QVERIFY(selectionChangedCount == 1); |
| 247 |
QVERIFY(!selectedItem); |
| 248 |
} |
| 249 |
|
| 250 |
void tst_Q3ListBox::selectionChangedMultiSelection() |
| 251 |
{ |
| 252 |
testWidget->setSelectionMode(Q3ListBox::Multi); |
| 253 |
testWidget->setSelected(testWidget->item(0), true); |
| 254 |
|
| 255 |
QVERIFY(selectionChangedSignal); |
| 256 |
QVERIFY(selectionChangedCount == 1); |
| 257 |
QVERIFY(!selectedItem); // In this selection mode, it should be 0 |
| 258 |
|
| 259 |
selectionChangedSignal = false; |
| 260 |
selectionChangedCount = 0; |
| 261 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ControlModifier, QPoint(5,itemHeight*2-5)); |
| 262 |
|
| 263 |
QVERIFY(selectionChangedSignal); |
| 264 |
QVERIFY(selectionChangedCount == 1); |
| 265 |
QVERIFY(!selectedItem); |
| 266 |
|
| 267 |
selectionChangedSignal = false; |
| 268 |
selectionChangedCount = 0; |
| 269 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ShiftModifier, QPoint(5,itemHeight*3-5)); |
| 270 |
|
| 271 |
QVERIFY(selectionChangedSignal); |
| 272 |
QVERIFY(selectionChangedCount == 1); |
| 273 |
QVERIFY(!selectedItem); |
| 274 |
} |
| 275 |
|
| 276 |
void tst_Q3ListBox::currentChanged_helper(Q3ListBoxItem *item) |
| 277 |
{ |
| 278 |
currentChangedCount++; |
| 279 |
currentChangedSignal = true; |
| 280 |
currentItem = item; |
| 281 |
} |
| 282 |
|
| 283 |
void tst_Q3ListBox::currentChangedSingleSelection() |
| 284 |
{ |
| 285 |
testWidget->setSelectionMode(Q3ListBox::Single); |
| 286 |
|
| 287 |
testWidget->setSelected(3, true); |
| 288 |
|
| 289 |
QVERIFY(currentChangedSignal); |
| 290 |
QVERIFY(currentChangedCount == 1); |
| 291 |
QVERIFY(currentItem); |
| 292 |
QCOMPARE(currentItem->text(), QString::fromLatin1("As do Sigur Ros!")); |
| 293 |
|
| 294 |
currentChangedSignal = false; |
| 295 |
currentChangedCount = 0; |
| 296 |
testWidget->setCurrentItem(2); |
| 297 |
|
| 298 |
QVERIFY(currentChangedSignal); |
| 299 |
QVERIFY(currentChangedCount == 1); |
| 300 |
QVERIFY(currentItem); |
| 301 |
QCOMPARE(currentItem->text(), QString::fromLatin1("Radiohead kicks ass!")); |
| 302 |
|
| 303 |
currentChangedSignal = false; |
| 304 |
currentChangedCount = 0; |
| 305 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5,itemHeight-5)); |
| 306 |
|
| 307 |
QVERIFY(currentChangedSignal); |
| 308 |
QVERIFY(currentChangedCount == 1); |
| 309 |
QVERIFY(currentItem); |
| 310 |
QCOMPARE(currentItem->text(), QString::fromLatin1("This is a test")); |
| 311 |
|
| 312 |
currentChangedSignal = false; |
| 313 |
currentChangedCount = 0; |
| 314 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ControlModifier, QPoint(5,itemHeight*2-5)); |
| 315 |
|
| 316 |
QVERIFY(currentChangedSignal); |
| 317 |
QVERIFY(currentChangedCount == 1); |
| 318 |
QVERIFY(currentItem); |
| 319 |
QCOMPARE(currentItem->text(), QString::fromLatin1("And this is another")); |
| 320 |
|
| 321 |
currentChangedSignal = false; |
| 322 |
currentChangedCount = 0; |
| 323 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ShiftModifier, QPoint(5,itemHeight*3-5)); |
| 324 |
|
| 325 |
QVERIFY(currentChangedSignal); |
| 326 |
QVERIFY(currentChangedCount == 1); |
| 327 |
QVERIFY(currentItem); |
| 328 |
QCOMPARE(currentItem->text(), QString::fromLatin1("Radiohead kicks ass!")); |
| 329 |
} |
| 330 |
|
| 331 |
void tst_Q3ListBox::currentChangedExtendedSelection() |
| 332 |
{ |
| 333 |
testWidget->setSelectionMode(Q3ListBox::Extended); |
| 334 |
testWidget->setSelected(3, true); |
| 335 |
|
| 336 |
QVERIFY(currentChangedSignal); |
| 337 |
QVERIFY(currentChangedCount == 1); |
| 338 |
QVERIFY(currentItem); |
| 339 |
QCOMPARE(currentItem->text(), QString::fromLatin1("As do Sigur Ros!")); |
| 340 |
|
| 341 |
currentChangedSignal = false; |
| 342 |
currentChangedCount = 0; |
| 343 |
testWidget->setCurrentItem(2); |
| 344 |
|
| 345 |
QVERIFY(currentChangedSignal); |
| 346 |
QVERIFY(currentChangedCount == 1); |
| 347 |
QVERIFY(currentItem); |
| 348 |
QCOMPARE(currentItem->text(), QString::fromLatin1("Radiohead kicks ass!")); |
| 349 |
|
| 350 |
currentChangedSignal = false; |
| 351 |
currentChangedCount = 0; |
| 352 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5,itemHeight-5)); |
| 353 |
|
| 354 |
QVERIFY(currentChangedSignal); |
| 355 |
QVERIFY(currentChangedCount == 1); |
| 356 |
QVERIFY(currentItem); |
| 357 |
QCOMPARE(currentItem->text(), QString::fromLatin1("This is a test")); |
| 358 |
|
| 359 |
currentChangedSignal = false; |
| 360 |
currentChangedCount = 0; |
| 361 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ControlModifier, QPoint(5,itemHeight*2-5)); |
| 362 |
|
| 363 |
QVERIFY(currentChangedSignal); |
| 364 |
QVERIFY(currentChangedCount == 1); |
| 365 |
QVERIFY(currentItem); |
| 366 |
QCOMPARE(currentItem->text(), QString::fromLatin1("And this is another")); |
| 367 |
|
| 368 |
currentChangedSignal = false; |
| 369 |
currentChangedCount = 0; |
| 370 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ShiftModifier, QPoint(5,itemHeight*3-5)); |
| 371 |
|
| 372 |
QVERIFY(currentChangedSignal); |
| 373 |
QVERIFY(currentChangedCount == 1); |
| 374 |
QVERIFY(currentItem); |
| 375 |
QCOMPARE(currentItem->text(), QString::fromLatin1("Radiohead kicks ass!")); |
| 376 |
} |
| 377 |
|
| 378 |
void tst_Q3ListBox::currentChangedMultiSelection() |
| 379 |
{ |
| 380 |
testWidget->setSelectionMode(Q3ListBox::Multi); |
| 381 |
testWidget->setSelected(3, true); |
| 382 |
|
| 383 |
QVERIFY(currentChangedSignal); |
| 384 |
QVERIFY(currentChangedCount == 1); |
| 385 |
QVERIFY(currentItem); |
| 386 |
QCOMPARE(currentItem->text(), QString::fromLatin1("As do Sigur Ros!")); |
| 387 |
|
| 388 |
currentChangedSignal = false; |
| 389 |
currentChangedCount = 0; |
| 390 |
testWidget->setCurrentItem(2); |
| 391 |
|
| 392 |
QVERIFY(currentChangedSignal); |
| 393 |
QVERIFY(currentChangedCount == 1); |
| 394 |
QVERIFY(currentItem); |
| 395 |
QCOMPARE(currentItem->text(), QString::fromLatin1("Radiohead kicks ass!")); |
| 396 |
|
| 397 |
currentChangedSignal = false; |
| 398 |
currentChangedCount = 0; |
| 399 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5,itemHeight-5)); |
| 400 |
|
| 401 |
QVERIFY(currentChangedSignal); |
| 402 |
QVERIFY(currentChangedCount == 1); |
| 403 |
QVERIFY(currentItem); |
| 404 |
QCOMPARE(currentItem->text(), QString::fromLatin1("This is a test")); |
| 405 |
|
| 406 |
currentChangedSignal = false; |
| 407 |
currentChangedCount = 0; |
| 408 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ControlModifier, QPoint(5,itemHeight*2-5)); |
| 409 |
|
| 410 |
QVERIFY(currentChangedSignal); |
| 411 |
QVERIFY(currentChangedCount == 1); |
| 412 |
QVERIFY(currentItem); |
| 413 |
QCOMPARE(currentItem->text(), QString::fromLatin1("And this is another")); |
| 414 |
|
| 415 |
currentChangedSignal = false; |
| 416 |
currentChangedCount = 0; |
| 417 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ShiftModifier, QPoint(5,itemHeight*3-5)); |
| 418 |
|
| 419 |
QVERIFY(currentChangedSignal); |
| 420 |
QVERIFY(currentChangedCount == 1); |
| 421 |
QVERIFY(currentItem); |
| 422 |
QCOMPARE(currentItem->text(), QString::fromLatin1("Radiohead kicks ass!")); |
| 423 |
} |
| 424 |
|
| 425 |
void tst_Q3ListBox::highlighted_helper(Q3ListBoxItem *item) |
| 426 |
{ |
| 427 |
highlightedCount++; |
| 428 |
highlightedSignal = true; |
| 429 |
highlightedItem = item; |
| 430 |
} |
| 431 |
|
| 432 |
void tst_Q3ListBox::highlightedChangedSingleSelection() |
| 433 |
{ |
| 434 |
QVERIFY(highlightedCount == 0); |
| 435 |
testWidget->setSelectionMode(Q3ListBox::Single); |
| 436 |
QSignalSpy highlightedIndexSpy(testWidget, SIGNAL(highlighted(int))); |
| 437 |
QSignalSpy highlightedTextSpy(testWidget, SIGNAL(highlighted(const QString &))); |
| 438 |
|
| 439 |
testWidget->setSelected(3, true); |
| 440 |
|
| 441 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 442 |
QList<QVariant> list = highlightedIndexSpy.takeFirst(); |
| 443 |
QCOMPARE(list.at(0).toInt(), 3); |
| 444 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 445 |
list = highlightedTextSpy.takeFirst(); |
| 446 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("As do Sigur Ros!")); |
| 447 |
QVERIFY(highlightedSignal); |
| 448 |
QVERIFY(highlightedCount == 1); |
| 449 |
QVERIFY(highlightedItem); |
| 450 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("As do Sigur Ros!")); |
| 451 |
|
| 452 |
highlightedSignal = false; |
| 453 |
highlightedCount = 0; |
| 454 |
testWidget->setCurrentItem(2); |
| 455 |
|
| 456 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 457 |
list = highlightedIndexSpy.takeFirst(); |
| 458 |
QCOMPARE(list.at(0).toInt(), 2); |
| 459 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 460 |
list = highlightedTextSpy.takeFirst(); |
| 461 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("Radiohead kicks ass!")); |
| 462 |
QVERIFY(highlightedSignal); |
| 463 |
QVERIFY(highlightedCount == 1); |
| 464 |
QVERIFY(highlightedItem); |
| 465 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("Radiohead kicks ass!")); |
| 466 |
|
| 467 |
highlightedSignal = false; |
| 468 |
highlightedCount = 0; |
| 469 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5,itemHeight-5)); |
| 470 |
|
| 471 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 472 |
list = highlightedIndexSpy.takeFirst(); |
| 473 |
QCOMPARE(list.at(0).toInt(), 0); |
| 474 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 475 |
list = highlightedTextSpy.takeFirst(); |
| 476 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("This is a test")); |
| 477 |
QVERIFY(highlightedSignal); |
| 478 |
QVERIFY(highlightedCount == 1); |
| 479 |
QVERIFY(highlightedItem); |
| 480 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("This is a test")); |
| 481 |
|
| 482 |
highlightedSignal = false; |
| 483 |
highlightedCount = 0; |
| 484 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ControlModifier, QPoint(5,itemHeight*2-5)); |
| 485 |
|
| 486 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 487 |
list = highlightedIndexSpy.takeFirst(); |
| 488 |
QCOMPARE(list.at(0).toInt(), 1); |
| 489 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 490 |
list = highlightedTextSpy.takeFirst(); |
| 491 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("And this is another")); |
| 492 |
QVERIFY(highlightedSignal); |
| 493 |
QVERIFY(highlightedCount == 1); |
| 494 |
QVERIFY(highlightedItem); |
| 495 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("And this is another")); |
| 496 |
|
| 497 |
highlightedSignal = false; |
| 498 |
highlightedCount = 0; |
| 499 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ShiftModifier, QPoint(5,itemHeight*3-5)); |
| 500 |
|
| 501 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 502 |
list = highlightedIndexSpy.takeFirst(); |
| 503 |
QCOMPARE(list.at(0).toInt(), 2); |
| 504 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 505 |
list = highlightedTextSpy.takeFirst(); |
| 506 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("Radiohead kicks ass!")); |
| 507 |
QVERIFY(highlightedSignal); |
| 508 |
QVERIFY(highlightedCount == 1); |
| 509 |
QVERIFY(highlightedItem); |
| 510 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("Radiohead kicks ass!")); |
| 511 |
} |
| 512 |
|
| 513 |
void tst_Q3ListBox::highlightedChangedExtendedSelection() |
| 514 |
{ |
| 515 |
QVERIFY(highlightedCount == 0); |
| 516 |
testWidget->setSelectionMode(Q3ListBox::Extended); |
| 517 |
QSignalSpy highlightedIndexSpy(testWidget, SIGNAL(highlighted(int))); |
| 518 |
QSignalSpy highlightedTextSpy(testWidget, SIGNAL(highlighted(const QString &))); |
| 519 |
|
| 520 |
testWidget->setSelected(3, true); |
| 521 |
|
| 522 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 523 |
QList<QVariant> list = highlightedIndexSpy.takeFirst(); |
| 524 |
QCOMPARE(list.at(0).toInt(), 3); |
| 525 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 526 |
list = highlightedTextSpy.takeFirst(); |
| 527 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("As do Sigur Ros!")); |
| 528 |
QVERIFY(highlightedSignal); |
| 529 |
QVERIFY(highlightedCount == 1); |
| 530 |
QVERIFY(highlightedItem); |
| 531 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("As do Sigur Ros!")); |
| 532 |
|
| 533 |
highlightedSignal = false; |
| 534 |
highlightedCount = 0; |
| 535 |
testWidget->setCurrentItem(2); |
| 536 |
|
| 537 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 538 |
list = highlightedIndexSpy.takeFirst(); |
| 539 |
QCOMPARE(list.at(0).toInt(), 2); |
| 540 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 541 |
list = highlightedTextSpy.takeFirst(); |
| 542 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("Radiohead kicks ass!")); |
| 543 |
QVERIFY(highlightedSignal); |
| 544 |
QVERIFY(highlightedCount == 1); |
| 545 |
QVERIFY(highlightedItem); |
| 546 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("Radiohead kicks ass!")); |
| 547 |
|
| 548 |
highlightedSignal = false; |
| 549 |
highlightedCount = 0; |
| 550 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5,itemHeight-5)); |
| 551 |
|
| 552 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 553 |
list = highlightedIndexSpy.takeFirst(); |
| 554 |
QCOMPARE(list.at(0).toInt(), 0); |
| 555 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 556 |
list = highlightedTextSpy.takeFirst(); |
| 557 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("This is a test")); |
| 558 |
QVERIFY(highlightedSignal); |
| 559 |
QVERIFY(highlightedCount == 1); |
| 560 |
QVERIFY(highlightedItem); |
| 561 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("This is a test")); |
| 562 |
|
| 563 |
highlightedSignal = false; |
| 564 |
highlightedCount = 0; |
| 565 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ControlModifier, QPoint(5,itemHeight*2-5)); |
| 566 |
|
| 567 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 568 |
list = highlightedIndexSpy.takeFirst(); |
| 569 |
QCOMPARE(list.at(0).toInt(), 1); |
| 570 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 571 |
list = highlightedTextSpy.takeFirst(); |
| 572 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("And this is another")); |
| 573 |
QVERIFY(highlightedSignal); |
| 574 |
QVERIFY(highlightedCount == 1); |
| 575 |
QVERIFY(highlightedItem); |
| 576 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("And this is another")); |
| 577 |
|
| 578 |
highlightedSignal = false; |
| 579 |
highlightedCount = 0; |
| 580 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ShiftModifier, QPoint(5,itemHeight*3-5)); |
| 581 |
|
| 582 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 583 |
list = highlightedIndexSpy.takeFirst(); |
| 584 |
QCOMPARE(list.at(0).toInt(), 2); |
| 585 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 586 |
list = highlightedTextSpy.takeFirst(); |
| 587 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("Radiohead kicks ass!")); |
| 588 |
QVERIFY(highlightedSignal); |
| 589 |
QVERIFY(highlightedCount == 1); |
| 590 |
QVERIFY(highlightedItem); |
| 591 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("Radiohead kicks ass!")); |
| 592 |
} |
| 593 |
|
| 594 |
void tst_Q3ListBox::highlightedChangedMultiSelection() |
| 595 |
{ |
| 596 |
QVERIFY(highlightedCount == 0); |
| 597 |
testWidget->setSelectionMode(Q3ListBox::Multi); |
| 598 |
QSignalSpy highlightedIndexSpy(testWidget, SIGNAL(highlighted(int))); |
| 599 |
QSignalSpy highlightedTextSpy(testWidget, SIGNAL(highlighted(const QString &))); |
| 600 |
|
| 601 |
testWidget->setSelected(3, true); |
| 602 |
|
| 603 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 604 |
QList<QVariant> list = highlightedIndexSpy.takeFirst(); |
| 605 |
QCOMPARE(list.at(0).toInt(), 3); |
| 606 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 607 |
list = highlightedTextSpy.takeFirst(); |
| 608 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("As do Sigur Ros!")); |
| 609 |
QVERIFY(highlightedSignal); |
| 610 |
QVERIFY(highlightedCount == 1); |
| 611 |
QVERIFY(highlightedItem); |
| 612 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("As do Sigur Ros!")); |
| 613 |
|
| 614 |
highlightedSignal = false; |
| 615 |
highlightedCount = 0; |
| 616 |
testWidget->setCurrentItem(2); |
| 617 |
|
| 618 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 619 |
list = highlightedIndexSpy.takeFirst(); |
| 620 |
QCOMPARE(list.at(0).toInt(), 2); |
| 621 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 622 |
list = highlightedTextSpy.takeFirst(); |
| 623 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("Radiohead kicks ass!")); |
| 624 |
QVERIFY(highlightedSignal); |
| 625 |
QVERIFY(highlightedCount == 1); |
| 626 |
QVERIFY(highlightedItem); |
| 627 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("Radiohead kicks ass!")); |
| 628 |
|
| 629 |
highlightedSignal = false; |
| 630 |
highlightedCount = 0; |
| 631 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5,itemHeight-5)); |
| 632 |
|
| 633 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 634 |
list = highlightedIndexSpy.takeFirst(); |
| 635 |
QCOMPARE(list.at(0).toInt(), 0); |
| 636 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 637 |
list = highlightedTextSpy.takeFirst(); |
| 638 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("This is a test")); |
| 639 |
QVERIFY(highlightedSignal); |
| 640 |
QVERIFY(highlightedCount == 1); |
| 641 |
QVERIFY(highlightedItem); |
| 642 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("This is a test")); |
| 643 |
|
| 644 |
highlightedSignal = false; |
| 645 |
highlightedCount = 0; |
| 646 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ControlModifier, QPoint(5,itemHeight*2-5)); |
| 647 |
|
| 648 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 649 |
list = highlightedIndexSpy.takeFirst(); |
| 650 |
QCOMPARE(list.at(0).toInt(), 1); |
| 651 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 652 |
list = highlightedTextSpy.takeFirst(); |
| 653 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("And this is another")); |
| 654 |
QVERIFY(highlightedSignal); |
| 655 |
QVERIFY(highlightedCount == 1); |
| 656 |
QVERIFY(highlightedItem); |
| 657 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("And this is another")); |
| 658 |
|
| 659 |
highlightedSignal = false; |
| 660 |
highlightedCount = 0; |
| 661 |
QTest::mouseClick(testWidget->viewport(), Qt::LeftButton, Qt::ShiftModifier, QPoint(5,itemHeight*3-5)); |
| 662 |
|
| 663 |
QCOMPARE(highlightedIndexSpy.count(), 1); |
| 664 |
list = highlightedIndexSpy.takeFirst(); |
| 665 |
QCOMPARE(list.at(0).toInt(), 2); |
| 666 |
QCOMPARE(highlightedTextSpy.count(), 1); |
| 667 |
list = highlightedTextSpy.takeFirst(); |
| 668 |
QCOMPARE(list.at(0).toString(), QString::fromLatin1("Radiohead kicks ass!")); |
| 669 |
QVERIFY(highlightedSignal); |
| 670 |
QVERIFY(highlightedCount == 1); |
| 671 |
QVERIFY(highlightedItem); |
| 672 |
QCOMPARE(highlightedItem->text(), QString::fromLatin1("Radiohead kicks ass!")); |
| 673 |
} |
| 674 |
|
| 675 |
QTEST_MAIN(tst_Q3ListBox) |
| 676 |
#include "tst_qlistbox.moc" |