[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdelibs/KDE/4.10] kdeui: Fix two bugs in kcolorbutton+tests
From:       Albert Astals Cid <aacid () kde ! org>
Date:       2013-02-06 23:09:35
Message-ID: 20130206230935.DD570A6091 () git ! kde ! org
[Download RAW message or body]

Git commit f3f6b9c7d533c3c03ceb47b9de753c74c4e082b9 by Albert Astals Cid.
Committed on 07/02/2013 at 00:08.
Pushed by aacid into branch 'KDE/4.10'.

Fix two bugs in kcolorbutton+tests

Selecting+cancel does not really cancel
Selecting in recent colors crashes
REVIEW: 108637
BUGS: 313984
FIXED-IN: 4.10.1

M  +1    -2    kdeui/colors/kcolorbutton.cpp
M  +1    -0    kdeui/tests/CMakeLists.txt
A  +119  -0    kdeui/tests/kcolorbuttontest.cpp     [License: LGPL (v2+)]
A  +40   -0    kdeui/tests/kcolorbuttontest.h     [License: LGPL (v2+)]

http://commits.kde.org/kdelibs/f3f6b9c7d533c3c03ceb47b9de753c74c4e082b9

diff --git a/kdeui/colors/kcolorbutton.cpp b/kdeui/colors/kcolorbutton.cpp
index 786cb9d..3c6a8f6 100644
--- a/kdeui/colors/kcolorbutton.cpp
+++ b/kdeui/colors/kcolorbutton.cpp
@@ -263,8 +263,7 @@ void KColorButton::KColorButtonPrivate::_k_chooseColor()
     dialog->setAttribute(Qt::WA_DeleteOnClose);
     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
     connect(dialog, SIGNAL(applyClicked()), q, SLOT(_k_colorChosen()));
-    connect(dialog, SIGNAL(okClicked()), q, SLOT(_k_colorChosen()));
-    connect(dialog, SIGNAL(colorSelected(QColor)), q, SLOT(_k_colorChosen()));
+    connect(dialog, SIGNAL(accepted()), q, SLOT(_k_colorChosen()));
     dialogPtr = dialog;
     dialog->show();
 }
diff --git a/kdeui/tests/CMakeLists.txt b/kdeui/tests/CMakeLists.txt
index 85f12ed..235e31e 100644
--- a/kdeui/tests/CMakeLists.txt
+++ b/kdeui/tests/CMakeLists.txt
@@ -73,6 +73,7 @@ KDEUI_UNIT_TESTS(
   kdatecomboboxtest
   kdatetimeedittest
   kconfigdialog_unittest
+  kcolorbuttontest
 )
 
 KDEUI_PROXYMODEL_TESTS(
diff --git a/kdeui/tests/kcolorbuttontest.cpp b/kdeui/tests/kcolorbuttontest.cpp
new file mode 100644
index 0000000..5a31b12
--- /dev/null
+++ b/kdeui/tests/kcolorbuttontest.cpp
@@ -0,0 +1,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);
+}
diff --git a/kdeui/tests/kcolorbuttontest.h b/kdeui/tests/kcolorbuttontest.h
new file mode 100644
index 0000000..6639709
--- /dev/null
+++ b/kdeui/tests/kcolorbuttontest.h
@@ -0,0 +1,40 @@
+/*
+    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.
+*/
+
+#ifndef KCOLORBUTTONTEST_H
+#define KCOLORBUTTONTEST_H
+
+#include <QtGui/QWidget>
+
+class KColorButtonTest : public QObject
+{
+  Q_OBJECT
+
+private Q_SLOTS:
+  void initTestCase();
+  void testChangeAndCancel();
+  void testDoubleClickChange();
+  void testOkChange();
+  void testRecentColorsPick();
+
+private:
+  QColor black40Colors;
+};
+
+#endif
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic