1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
/*
Copyright 2013 Albert Astals Cid <aacid@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kcolorbuttontest.h"
#include "qtest_kde.h"
#include <kcolorbutton.h>
#include <kcolordialog.h>
#include <QComboBox>
#include <QDialogButtonBox>
QTEST_KDEMAIN(KColorButtonTest, GUI)
#include "kcolorbuttontest.moc"
void KColorButtonTest::initTestCase()
{
black40Colors.setHsv(-1, 0, 0);
}
void KColorButtonTest::testChangeAndCancel()
{
KColorButton colorButton(Qt::red);
colorButton.show();
QVERIFY(QTest::qWaitForWindowShown(&colorButton));
QTest::mouseClick(&colorButton, Qt::LeftButton);
KColorDialog *dialog = colorButton.findChild<KColorDialog*>();
QVERIFY(dialog != NULL);
QVERIFY(QTest::qWaitForWindowShown(dialog));
KColorCells *cells = dialog->findChild<KColorCells*>();
QVERIFY(cells != NULL);
QTest::mouseClick(cells->viewport(), Qt::LeftButton, 0, QPoint(1, 1));
QCOMPARE(dialog->color(), black40Colors);
dialog->reject();
QCOMPARE(colorButton.color(), QColor(Qt::red));
}
void KColorButtonTest::testDoubleClickChange()
{
KColorButton colorButton(Qt::red);
colorButton.show();
QVERIFY(QTest::qWaitForWindowShown(&colorButton));
QTest::mouseClick(&colorButton, Qt::LeftButton);
KColorDialog *dialog = colorButton.findChild<KColorDialog*>();
QVERIFY(dialog != NULL);
QVERIFY(QTest::qWaitForWindowShown(dialog));
KColorCells *cells = dialog->findChild<KColorCells*>();
QVERIFY(cells != NULL);
QTest::mouseDClick(cells->viewport(), Qt::LeftButton, 0, QPoint(1, 1));
QCOMPARE(colorButton.color(), black40Colors);
}
void KColorButtonTest::testOkChange()
{
KColorButton colorButton(Qt::red);
colorButton.show();
QVERIFY(QTest::qWaitForWindowShown(&colorButton));
QTest::mouseClick(&colorButton, Qt::LeftButton);
KColorDialog *dialog = colorButton.findChild<KColorDialog*>();
QVERIFY(dialog != NULL);
QVERIFY(QTest::qWaitForWindowShown(dialog));
KColorCells *cells = dialog->findChild<KColorCells*>();
QVERIFY(cells != NULL);
QTest::mouseClick(cells->viewport(), Qt::LeftButton, 0, QPoint(1, 1));
QCOMPARE(dialog->color(), black40Colors);
QSignalSpy okClickedSpy(dialog, SIGNAL(okClicked()));
const QDialogButtonBox *buttonBox = dialog->findChild<QDialogButtonBox*>();
const QList<QAbstractButton *> buttons = buttonBox->buttons();
foreach(QAbstractButton *button, buttons) {
if (buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
QTest::mouseClick(button, Qt::LeftButton);
break;
}
}
QCOMPARE(okClickedSpy.count(), 1);
QCOMPARE(colorButton.color(), black40Colors);
}
void KColorButtonTest::testRecentColorsPick()
{
KColorButton colorButton(Qt::red);
colorButton.show();
QVERIFY(QTest::qWaitForWindowShown(&colorButton));
QTest::mouseClick(&colorButton, Qt::LeftButton);
KColorDialog *dialog = colorButton.findChild<KColorDialog*>();
QVERIFY(dialog != NULL);
QVERIFY(QTest::qWaitForWindowShown(dialog));
QComboBox *combo = dialog->findChild<QComboBox*>();
combo->setFocus();
QTest::keyPress(combo, Qt::Key_Up);
QTest::keyPress(combo, Qt::Key_Up);
KColorCells *cells = dialog->findChild<KColorCells*>();
QVERIFY(cells != NULL);
QTest::mouseMove(cells->viewport(), QPoint(1, 1));
QTest::mouseClick(cells->viewport(), Qt::LeftButton, 0, QPoint(30, 1));
const QColor color = dialog->color();
dialog->accept();
QCOMPARE(colorButton.color(), color);
}
|