From df19bffbd9a3a8bd69acf1ff6f3ba9c4649d13be Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Fri, 9 Mar 2012 18:28:12 -0800 Subject: Move tst_qshortcut.cpp to QtWidgets QShortcut belongs to QtWidgets instead of QtGui. Change-Id: I9715399bb372a6ea4bd76109f87ba31a1e30a7e6 Reviewed-by: Gunnar Sletta Reviewed-by: Friedemann Kleint --- tests/auto/gui/kernel/kernel.pro | 1 - tests/auto/gui/kernel/qshortcut/.gitignore | 1 - tests/auto/gui/kernel/qshortcut/qshortcut.pro | 12 - tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp | 1259 -------------------- tests/auto/widgets/kernel/kernel.pro | 1 + tests/auto/widgets/kernel/qshortcut/.gitignore | 1 + tests/auto/widgets/kernel/qshortcut/qshortcut.pro | 12 + .../widgets/kernel/qshortcut/tst_qshortcut.cpp | 1259 ++++++++++++++++++++ 8 files changed, 1273 insertions(+), 1273 deletions(-) delete mode 100644 tests/auto/gui/kernel/qshortcut/.gitignore delete mode 100644 tests/auto/gui/kernel/qshortcut/qshortcut.pro delete mode 100644 tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp create mode 100644 tests/auto/widgets/kernel/qshortcut/.gitignore create mode 100644 tests/auto/widgets/kernel/qshortcut/qshortcut.pro create mode 100644 tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp (limited to 'tests/auto') diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro index 116e9dd1f1..48d94b9bf8 100644 --- a/tests/auto/gui/kernel/kernel.pro +++ b/tests/auto/gui/kernel/kernel.pro @@ -13,7 +13,6 @@ SUBDIRS=\ qmouseevent_modal \ qpalette \ qscreen \ - qshortcut \ qtouchevent \ qwindow \ qguiapplication \ diff --git a/tests/auto/gui/kernel/qshortcut/.gitignore b/tests/auto/gui/kernel/qshortcut/.gitignore deleted file mode 100644 index 3a17eb18e3..0000000000 --- a/tests/auto/gui/kernel/qshortcut/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tst_qshortcut diff --git a/tests/auto/gui/kernel/qshortcut/qshortcut.pro b/tests/auto/gui/kernel/qshortcut/qshortcut.pro deleted file mode 100644 index 7ac1dd2c9d..0000000000 --- a/tests/auto/gui/kernel/qshortcut/qshortcut.pro +++ /dev/null @@ -1,12 +0,0 @@ -CONFIG += testcase -TARGET = tst_qshortcut - -# Project Configuration ---------------------------------------------- -INCLUDEPATH += ../ - -# Normal Test Files -------------------------------------------------- -QT += widgets testlib -HEADERS += -SOURCES += tst_qshortcut.cpp - - diff --git a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp deleted file mode 100644 index 61efb6e3f3..0000000000 --- a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp +++ /dev/null @@ -1,1259 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class AccelForm; -QT_BEGIN_NAMESPACE -class QMainWindow; -class QTextEdit; -QT_END_NAMESPACE - -class tst_QShortcut : public QObject -{ - Q_OBJECT -public: - tst_QShortcut(); - virtual ~tst_QShortcut(); - - - enum Action { - SetupAccel, - TestAccel, - ClearAll - } currentAction; - - enum Widget { - NoWidget, - TriggerSlot1, - TriggerSlot2, - TriggerSlot3, - TriggerSlot4, - TriggerSlot5, - TriggerSlot6, - TriggerSlot7 - }; - - enum Result { - NoResult, - Slot1Triggered, - Slot2Triggered, - Slot3Triggered, - Slot4Triggered, - Slot5Triggered, - Slot6Triggered, - Slot7Triggered, - Ambiguous - } currentResult; - -public slots: - void slotTrig1() { currentResult = Slot1Triggered; } - void slotTrig2() { currentResult = Slot2Triggered; } - void slotTrig3() { currentResult = Slot3Triggered; } - void slotTrig4() { currentResult = Slot4Triggered; } - void slotTrig5() { currentResult = Slot5Triggered; } - void slotTrig6() { currentResult = Slot6Triggered; } - void slotTrig7() { currentResult = Slot7Triggered; } - void ambigSlot1() { currentResult = Ambiguous; ambigResult = Slot1Triggered; } - void ambigSlot2() { currentResult = Ambiguous; ambigResult = Slot2Triggered; } - void ambigSlot3() { currentResult = Ambiguous; ambigResult = Slot3Triggered; } - void ambigSlot4() { currentResult = Ambiguous; ambigResult = Slot4Triggered; } - void ambigSlot5() { currentResult = Ambiguous; ambigResult = Slot5Triggered; } - void ambigSlot6() { currentResult = Ambiguous; ambigResult = Slot6Triggered; } - void ambigSlot7() { currentResult = Ambiguous; ambigResult = Slot7Triggered; } - void statusMessage( const QString& message ) { sbText = message; } - void shortcutDestroyed(QObject* obj); - -public slots: - void initTestCase(); - void cleanupTestCase(); - -private slots: - void number_data(); - void number(); - void text_data(); - void text(); - void disabledItems(); - void ambiguousItems(); - void ambiguousRotation(); - void keypressConsumption(); - void unicodeCompare(); - void context(); - -protected: - static Qt::KeyboardModifiers toButtons( int key ); - void defElements(); - - void clearAllShortcuts(); - QShortcut *setupShortcut(int testWidget, const QKeySequence &ks); - QShortcut *setupShortcut(int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0); - - QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0); - QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QKeySequence &ks, Qt::ShortcutContext context = Qt::WindowShortcut); - - void sendKeyEvents(QWidget *w, int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0); - void sendKeyEvents(int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0); - - void testElement(); - - QMainWindow *mainW; - QList shortcuts; - QTextEdit *edit; - QString sbText; - Result ambigResult; -}; - -Q_DECLARE_METATYPE(tst_QShortcut::Widget); -Q_DECLARE_METATYPE(tst_QShortcut::Result); -Q_DECLARE_METATYPE(tst_QShortcut::Action); - -class TestEdit : public QTextEdit -{ - Q_OBJECT -public: - TestEdit(QWidget *parent, const char *name) - : QTextEdit(parent) - { - setObjectName(name); - } - -protected: - bool event(QEvent *e) { - // Make testedit allow any Ctrl+Key as shortcut - if (e->type() == QEvent::ShortcutOverride) { - QKeyEvent *ke = static_cast(e); - if (ke->modifiers() == Qt::ControlModifier - && ke->key() > Qt::Key_Any - && ke->key() < Qt::Key_ydiaeresis) { - ke->ignore(); - return true; - } - } - - // If keypress not processed as normal, check for - // Ctrl+Key event, and input custom string for - // result comparison. - if (e->type() == QEvent::KeyPress) { - QKeyEvent *ke = static_cast(e); - if (ke->modifiers() && ke->key() > Qt::Key_Any - && ke->key() < Qt::Key_ydiaeresis) { - if (ke->modifiers() == Qt::ControlModifier) - insertPlainText(QString("").arg(char(ke->key()))); - else if (ke->modifiers() == Qt::AltModifier) - insertPlainText(QString("").arg(char(ke->key()))); - else if (ke->modifiers() == Qt::ShiftModifier) - insertPlainText(QString("").arg(char(ke->key()))); - return true; - } - } - return QTextEdit::event(e); - } -}; - -tst_QShortcut::tst_QShortcut(): mainW( 0 ) -{ -} - -tst_QShortcut::~tst_QShortcut() -{ - clearAllShortcuts(); -} - -void tst_QShortcut::initTestCase() -{ - currentResult = NoResult; - mainW = new QMainWindow(0); - mainW->setWindowFlags(Qt::X11BypassWindowManagerHint); - edit = new TestEdit(mainW, "test_edit"); - mainW->setFixedSize( 100, 100 ); - mainW->setCentralWidget( edit ); - mainW->show(); - QTest::qWaitForWindowShown(mainW); - mainW->activateWindow(); - QTest::qWait(100); - connect( mainW->statusBar(), SIGNAL(messageChanged(const QString&)), - this, SLOT(statusMessage(const QString&)) ); -} - -void tst_QShortcut::cleanupTestCase() -{ - delete mainW; -} - -Qt::KeyboardModifiers tst_QShortcut::toButtons( int key ) -{ - Qt::KeyboardModifiers result = Qt::NoModifier; - if ( key & Qt::SHIFT ) - result |= Qt::ShiftModifier; - if ( key & Qt::CTRL ) - result |= Qt::ControlModifier; - if ( key & Qt::META ) - result |= Qt::MetaModifier; - if ( key & Qt::ALT ) - result |= Qt::AltModifier; - return result; -} - -void tst_QShortcut::defElements() -{ - QTest::addColumn("action"); - QTest::addColumn("testWidget"); - QTest::addColumn("txt"); - QTest::addColumn("k1"); - QTest::addColumn("c1"); - QTest::addColumn("k2"); - QTest::addColumn("c2"); - QTest::addColumn("k3"); - QTest::addColumn("c3"); - QTest::addColumn("k4"); - QTest::addColumn("c4"); - QTest::addColumn("result"); -} - -void tst_QShortcut::number() -{ - // We expect a failure on these tests, until QtTestKeyboard is - // fixed to do real platform dependent keyboard simulations - if (QTest::currentDataTag() == QString("N006a:Shift+Tab - [BackTab]") - || QTest::currentDataTag() == QString("N006b:Shift+Tab - [Shift+BackTab]")) - QEXPECT_FAIL("", "FLAW IN QTESTKEYBOARD: Keyboard events not passed through " - "platform dependent key handling code", Continue); - testElement(); -} -void tst_QShortcut::text() -{ - testElement(); -} -// ------------------------------------------------------------------ -// Number Elements -------------------------------------------------- -// ------------------------------------------------------------------ -void tst_QShortcut::number_data() -{ - defElements(); - - // Clear all - QTest::newRow("N00 - clear") << ClearAll << NoWidget <activateWindow(); - qApp->syncX(); - QTest::qWait(100); - - /* Testing Disabled Shortcuts - Qt::Key_M on slot1 - Shift + Qt::Key_M on slot1 - Qt::Key_M on slot2 (disabled) - Shift + Qt::Key_M on slot2 (disabled) - */ - - // Setup two identical shortcuts on different pushbuttons - QPushButton pb1(mainW); - QPushButton pb2(mainW); - pb1.setObjectName("pushbutton-1"); - pb2.setObjectName("pushbutton-2"); - pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger - pb2.show(); - - QShortcut *cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M"); - QShortcut *cut2 = setupShortcut(&pb1, "shortcut2-pb1", TriggerSlot1, "Shift+M"); - QShortcut *cut3 = setupShortcut(&pb2, "shortcut3-pb2", TriggerSlot2, "M"); - QShortcut *cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+M"); - - cut3->setEnabled(false); - cut4->setEnabled(false); - - currentResult = NoResult; - sendKeyEvents(Qt::Key_M, 'm'); - QCOMPARE(currentResult, Slot1Triggered); - - currentResult = NoResult; - sendKeyEvents(Qt::SHIFT+Qt::Key_M, 'M'); - QCOMPARE(currentResult, Slot1Triggered); - - cut2->setEnabled(false); - cut4->setEnabled(true); - - /* Testing Disabled Shortcuts - Qt::Key_M on slot1 - Shift + Qt::Key_M on slot1 (disabled) - Qt::Key_M on slot2 (disabled) - Shift + Qt::Key_M on slot2 - */ - currentResult = NoResult; - sendKeyEvents( Qt::Key_M, 'm' ); - QCOMPARE( currentResult, Slot1Triggered ); - - currentResult = NoResult; - sendKeyEvents( Qt::SHIFT+Qt::Key_M, 'M' ); - QCOMPARE( currentResult, Slot2Triggered ); - - - /* Testing Disabled Accel - Qt::Key_F5 on slot1 - Shift + Qt::Key_F5 on slot2 (disabled) - */ - clearAllShortcuts(); - cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "F5"); - cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+F5"); - - cut1->setKey(QKeySequence("F5")); - cut4->setKey(QKeySequence("Shift+F5")); - - cut1->setEnabled(true); - cut4->setEnabled(false); - - currentResult = NoResult; - sendKeyEvents( Qt::Key_F5, 0 ); - QCOMPARE( currentResult, Slot1Triggered ); - - currentResult = NoResult; - sendKeyEvents( Qt::SHIFT+Qt::Key_F5, 0 ); - QCOMPARE( currentResult, NoResult ); - -#if 0 - qFatal("Not testing statusbar text feedback yet, since not implemented"); - /* Testing Disabled Accel, and the corresponding statusbar feedback - Ctrl + Qt::Key_K, Ctrl + Qt::Key_L on slot1 - Ctrl + Qt::Key_K, Ctrl + Qt::Key_M on slot2 (disabled) - */ - cut1->setKey(QKeySequence("Ctrl+K, Ctrl+L")); - cut4->setKey(QKeySequence("Ctrl+K, Ctrl+M")); - - cut1->setEnabled(true); - cut4->setEnabled(false); - - currentResult = NoResult; - sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); - sendKeyEvents( Qt::CTRL+Qt::Key_Q, 0 ); - QCOMPARE( currentResult, NoResult ); - if (over_330) - QCOMPARE( sbText, QString("Ctrl+K, Ctrl+Q not defined") ); - - currentResult = NoResult; - sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); - sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 ); - QCOMPARE( currentResult, NoResult ); - if (over_330) - QCOMPARE( sbText, QString::null ); - - currentResult = NoResult; - sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); - sendKeyEvents( Qt::CTRL+Qt::Key_L, 0 ); - QCOMPARE( currentResult, Slot1Triggered ); - if (over_330) - QCOMPARE( sbText, QString::null ); -#endif - clearAllShortcuts(); - cut1 = 0; - cut4 = 0; -} -// ------------------------------------------------------------------ -// Ambiguous Elements ----------------------------------------------- -// ------------------------------------------------------------------ -void tst_QShortcut::ambiguousRotation() -{ - clearAllShortcuts(); - /* Testing Shortcut rotation scheme - Ctrl + Qt::Key_A on slot1 (disabled) - Ctrl + Qt::Key_A on slot2 (disabled) - Ctrl + Qt::Key_A on slot3 - Ctrl + Qt::Key_A on slot4 - Ctrl + Qt::Key_A on slot5 (disabled) - Ctrl + Qt::Key_A on slot6 - Ctrl + Qt::Key_A on slot7 (disabled) - */ - QShortcut *cut1 = setupShortcut(TriggerSlot1, "Ctrl+A"); - QShortcut *cut2 = setupShortcut(TriggerSlot2, "Ctrl+A"); - QShortcut *cut3 = setupShortcut(TriggerSlot3, "Ctrl+A"); - QShortcut *cut4 = setupShortcut(TriggerSlot4, "Ctrl+A"); - QShortcut *cut5 = setupShortcut(TriggerSlot5, "Ctrl+A"); - QShortcut *cut6 = setupShortcut(TriggerSlot6, "Ctrl+A"); - QShortcut *cut7 = setupShortcut(TriggerSlot7, "Ctrl+A"); - - cut1->setEnabled(false); - cut2->setEnabled(false); - cut5->setEnabled(false); - cut7->setEnabled(false); - - // Test proper rotation - // Start on first - // Go to last - // Go back to first - // Continue... - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot3Triggered); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot4Triggered); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot6Triggered); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot3Triggered); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot4Triggered); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot6Triggered); - - /* Testing Shortcut rotation scheme - Ctrl + Qt::Key_A on slot1 - Ctrl + Qt::Key_A on slot2 - Ctrl + Qt::Key_A on slot3 (disabled) - Ctrl + Qt::Key_A on slot4 (disabled) - Ctrl + Qt::Key_A on slot5 - Ctrl + Qt::Key_A on slot6 (disabled) - Ctrl + Qt::Key_A on slot7 - */ - - cut1->setEnabled(true); - cut2->setEnabled(true); - cut5->setEnabled(true); - cut7->setEnabled(true); - - cut3->setEnabled(false); - cut4->setEnabled(false); - cut6->setEnabled(false); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot1Triggered); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot2Triggered); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot5Triggered); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot7Triggered); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot1Triggered); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot2Triggered); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot5Triggered); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); - QCOMPARE(currentResult, Ambiguous); - QCOMPARE(ambigResult, Slot7Triggered); - - clearAllShortcuts(); - cut1 = 0; cut2 = 0; - cut3 = 0; cut4 = 0; - cut5 = 0; cut6 = 0; - cut7 = 0; -} - -void tst_QShortcut::ambiguousItems() -{ - clearAllShortcuts(); - /* Testing Ambiguous Shortcuts - Qt::Key_M on Pushbutton 1 - Qt::Key_M on Pushbutton 2 - */ - - // Setup two identical shortcuts on different pushbuttons - QPushButton pb1(mainW); - QPushButton pb2(mainW); - pb1.setObjectName("pushbutton-1"); - pb2.setObjectName("pushbutton-2"); - pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger - pb2.show(); - - setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M"); - setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, "M"); - - currentResult = NoResult; - sendKeyEvents( Qt::Key_M, 'm' ); - QCOMPARE( currentResult, Ambiguous ); - QCOMPARE( ambigResult, Slot1Triggered ); - - currentResult = NoResult; - sendKeyEvents( Qt::Key_M, 'm' ); - QCOMPARE( currentResult, Ambiguous ); - QCOMPARE( ambigResult, Slot2Triggered ); - - currentResult = NoResult; - sendKeyEvents( Qt::Key_M, 'm' ); - QCOMPARE( currentResult, Ambiguous ); - QCOMPARE( ambigResult, Slot1Triggered ); - - clearAllShortcuts(); -} - - -// ------------------------------------------------------------------ -// Unicode and non-unicode Elements --------------------------------- -// ------------------------------------------------------------------ -void tst_QShortcut::unicodeCompare() -{ - clearAllShortcuts(); - /* Testing Unicode/non-Unicode Shortcuts - Qt::Key_M on Pushbutton 1 - Qt::Key_M on Pushbutton 2 - */ - QPushButton pb1(mainW); - QPushButton pb2(mainW); - pb1.setObjectName("pushbutton-1"); - pb2.setObjectName("pushbutton-2"); - pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger - pb2.show(); - - QKeySequence ks1("Ctrl+M"); // Unicode - QKeySequence ks2(Qt::CTRL+Qt::Key_M); // non-Unicode - setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, ks1); - setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, ks2); - - currentResult = NoResult; - sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 ); - QCOMPARE( currentResult, Ambiguous ); - // They _are_ ambiguous, so the QKeySequence operator== - // should indicate the same - QVERIFY( ks1 == ks2 ); - QVERIFY( !(ks1 != ks2) ); - - clearAllShortcuts(); -} - -// ------------------------------------------------------------------ -// Keypress consumption verification -------------------------------- -// ------------------------------------------------------------------ -void tst_QShortcut::keypressConsumption() -{ - clearAllShortcuts(); - edit->clear(); - QCOMPARE(edit->toPlainText().size(), 0); - - QShortcut *cut1 = setupShortcut(edit, "shortcut1-line", TriggerSlot1, "Ctrl+I, A"); - QShortcut *cut2 = setupShortcut(edit, "shortcut1-line", TriggerSlot2, "Ctrl+I, B"); - - currentResult = NoResult; - ambigResult = NoResult; - sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0); // Send key to edit - QCOMPARE( currentResult, NoResult ); - QCOMPARE( ambigResult, NoResult ); - QCOMPARE(edit->toPlainText(), QString("")); - - // Make sure next keypress is eaten (failing multiple keysequence) - sendKeyEvents(edit, Qt::Key_C, 'c'); // Send key to edit - QCOMPARE( currentResult, NoResult ); - QCOMPARE( ambigResult, NoResult ); - QCOMPARE(edit->toPlainText(), QString("")); - - // Next keypress should be normal - sendKeyEvents(edit, Qt::Key_C, 'c'); // Send key to edit - QCOMPARE( currentResult, NoResult ); - QCOMPARE( ambigResult, NoResult ); - QCOMPARE(edit->toPlainText(), QString("c")); - - currentResult = NoResult; - ambigResult = NoResult; - edit->clear(); - QCOMPARE(edit->toPlainText().size(), 0); - - cut1->setEnabled(false); - cut2->setEnabled(false); - - // Make sure keypresses is passed on, since all multiple keysequences - // with Ctrl+I are disabled - sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0); // Send key to edit - QCOMPARE( currentResult, NoResult ); - QCOMPARE( ambigResult, NoResult ); - QVERIFY(edit->toPlainText().endsWith("")); - - sendKeyEvents(edit, Qt::Key_A, 'a'); // Send key to edit - QCOMPARE( currentResult, NoResult ); - QCOMPARE( ambigResult, NoResult ); - QVERIFY(edit->toPlainText().endsWith("a")); - - clearAllShortcuts(); -} - -// ------------------------------------------------------------------ -// Context Validation ----------------------------------------------- -// ------------------------------------------------------------------ -void tst_QShortcut::context() -{ - clearAllShortcuts(); - - QWidget myBox; - TestEdit *other1 = new TestEdit(&myBox, "test_edit_other1"); - TestEdit *other2 = new TestEdit(&myBox, "test_edit_other2"); - QHBoxLayout *layout = new QHBoxLayout(&myBox); - layout->addWidget(other1); - layout->addWidget(other2); - myBox.show(); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&myBox); -#endif - - setupShortcut(other1, "ActiveWindow", TriggerSlot1, QKeySequence("Alt+1"), Qt::WindowShortcut); - setupShortcut(other2, "Focus", TriggerSlot2, QKeySequence("Alt+2"), Qt::WidgetShortcut); - setupShortcut(edit, "Application", TriggerSlot3, QKeySequence("Alt+3"), Qt::ApplicationShortcut); - - currentResult = NoResult; - ambigResult = NoResult; - edit->clear(); - other1->clear(); - other2->clear(); - - // edit doesn't have focus, so ActiveWindow context should work - // ..but Focus context shouldn't.. - // Changing focus to edit should make focus context work - // Application context should always work - - - // Focus on 'other1' edit, so Active Window context should trigger - other1->activateWindow(); // <--- - QApplication::setActiveWindow(other1); - QCOMPARE(qApp->activeWindow(), other1->window()); - QCOMPARE(qApp->focusWidget(), (QWidget *)other1); - - currentResult = NoResult; - ambigResult = NoResult; - edit->clear(); - other1->clear(); - other2->clear(); - - QCOMPARE(qApp->focusWidget(), (QWidget *)other1); - sendKeyEvents(other1, Qt::ALT+Qt::Key_1); - QCOMPARE(currentResult, Slot1Triggered); - QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString("")); - QCOMPARE(other1->toPlainText(), QString("")); - QCOMPARE(other2->toPlainText(), QString("")); - - // ..but not Focus context on 'other2'.. - currentResult = NoResult; - ambigResult = NoResult; - edit->clear(); - other1->clear(); - other2->clear(); - - sendKeyEvents(other1, Qt::ALT+Qt::Key_2); - QCOMPARE(currentResult, NoResult); - QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString("")); - QCOMPARE(other1->toPlainText(), QString("")); - QCOMPARE(other2->toPlainText(), QString("")); - - // ..however, application global context on 'edit' should.. - currentResult = NoResult; - ambigResult = NoResult; - edit->clear(); - other1->clear(); - other2->clear(); - - sendKeyEvents(other1, Qt::ALT+Qt::Key_3); - QCOMPARE(currentResult, Slot3Triggered); - QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString("")); - QCOMPARE(other1->toPlainText(), QString("")); - QCOMPARE(other2->toPlainText(), QString("")); - - // Changing focus to 'other2' should make the Focus context there work - other2->activateWindow(); - other2->setFocus(); // ### - qApp->syncX(); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(other2); -#endif - QTest::qWait(100); - QCOMPARE(qApp->activeWindow(), other2->window()); - QCOMPARE(qApp->focusWidget(), (QWidget *)other2); - - currentResult = NoResult; - ambigResult = NoResult; - edit->clear(); - other1->clear(); - other2->clear(); - - sendKeyEvents(other2, Qt::ALT+Qt::Key_2); - QCOMPARE(currentResult, Slot2Triggered); - QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString("")); - QCOMPARE(other1->toPlainText(), QString("")); - QCOMPARE(other2->toPlainText(), QString("")); - - clearAllShortcuts(); - delete other1; - delete other2; - edit->activateWindow(); - qApp->syncX(); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(edit); -#endif - QTest::qWait(100); -} - -// ------------------------------------------------------------------ -// Element Testing helper functions --------------------------------- -// ------------------------------------------------------------------ -void tst_QShortcut::clearAllShortcuts() -{ - QList shortcutsCpy = shortcuts; - qDeleteAll(shortcutsCpy); - shortcuts.clear(); -} - -QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QKeySequence &ks) -{ - return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget, ks); -} - -QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QString &txt, int k1, int k2, int k3, int k4) -{ - return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget, - (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt))); -} - -QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1, int k2, int k3, int k4) -{ - return setupShortcut(parent, name, testWidget, - (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt))); -} - -QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget, - const QKeySequence &ks, Qt::ShortcutContext context) -{ - // Set up shortcut for next test - QShortcut *cut = new QShortcut(QKeySequence(), parent, 0, 0, context); - cut->setObjectName(name); - cut->setKey(ks); - - const char *normal = 0; - const char *ambig = 0; - switch(testWidget) - { - case TriggerSlot1: - normal = SLOT(slotTrig1()); - ambig = SLOT(ambigSlot1()); - break; - case TriggerSlot2: - normal = SLOT(slotTrig2()); - ambig = SLOT(ambigSlot2()); - break; - case TriggerSlot3: - normal = SLOT(slotTrig3()); - ambig = SLOT(ambigSlot3()); - break; - case TriggerSlot4: - normal = SLOT(slotTrig4()); - ambig = SLOT(ambigSlot4()); - break; - case TriggerSlot5: - normal = SLOT(slotTrig5()); - ambig = SLOT(ambigSlot5()); - break; - case TriggerSlot6: - normal = SLOT(slotTrig6()); - ambig = SLOT(ambigSlot6()); - break; - case TriggerSlot7: - normal = SLOT(slotTrig7()); - ambig = SLOT(ambigSlot7()); - break; - } - connect(cut, SIGNAL(activated()), this, normal); - connect(cut, SIGNAL(activatedAmbiguously()), this, ambig); - connect(cut, SIGNAL(destroyed(QObject*)), this, SLOT(shortcutDestroyed(QObject*))); - shortcuts.append(cut); - return cut; -} - -void tst_QShortcut::shortcutDestroyed(QObject* obj) -{ - shortcuts.removeAll(static_cast(obj)); -} - -void tst_QShortcut::sendKeyEvents(int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4) -{ - sendKeyEvents(mainW, k1, c1, k2, c2, k3, c3, k4, c4); -} - -void tst_QShortcut::sendKeyEvents(QWidget *w, int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4) -{ - Qt::KeyboardModifiers b1 = toButtons( k1 ); - Qt::KeyboardModifiers b2 = toButtons( k2 ); - Qt::KeyboardModifiers b3 = toButtons( k3 ); - Qt::KeyboardModifiers b4 = toButtons( k4 ); - k1 &= ~Qt::MODIFIER_MASK; - k2 &= ~Qt::MODIFIER_MASK; - k3 &= ~Qt::MODIFIER_MASK; - k4 &= ~Qt::MODIFIER_MASK; - - - if (k1 || c1.toAscii()) { - QString c(c1.unicode() == QChar::Null ? QString() : QString(c1)); - QTest::sendKeyEvent(QTest::Press, w, static_cast(k1), c, b1); - QTest::sendKeyEvent(QTest::Release, w, static_cast(k1), c, b1); - } - - if (k2 || c2.toAscii()) { - QString c(c2.unicode() == QChar::Null ? QString() : QString(c2)); - QTest::sendKeyEvent(QTest::Press, w, static_cast(k2), c, b2); - QTest::sendKeyEvent(QTest::Release, w, static_cast(k2), c, b2); - } - - if (k3 || c3.toAscii()) { - QString c(c3.unicode() == QChar::Null ? QString() : QString(c3)); - QTest::sendKeyEvent(QTest::Press, w, static_cast(k3), c, b3); - QTest::sendKeyEvent(QTest::Release, w, static_cast(k3), c, b3); - } - - if (k4 || c4.toAscii()) { - QString c(c4.unicode() == QChar::Null ? QString() : QString(c4)); - QTest::sendKeyEvent(QTest::Press, w, static_cast(k4), c, b4); - QTest::sendKeyEvent(QTest::Release, w, static_cast(k4), c, b4); - } -} - -void tst_QShortcut::testElement() -{ - currentResult = NoResult; - QFETCH(tst_QShortcut::Action, action); - QFETCH(tst_QShortcut::Widget, testWidget); - QFETCH(QString, txt); - QFETCH(int, k1); - QFETCH(int, c1); - QFETCH(int, k2); - QFETCH(int, c2); - QFETCH(int, k3); - QFETCH(int, c3); - QFETCH(int, k4); - QFETCH(int, c4); - QFETCH(tst_QShortcut::Result, result); - - if (action == ClearAll) { - clearAllShortcuts(); - } else if (action == SetupAccel) { - setupShortcut(testWidget, txt, k1, k2, k3, k4); - } else { - sendKeyEvents(k1, c1, k2, c2, k3, c3, k4, c4); - QCOMPARE(currentResult, result); - } -} - -QTEST_MAIN(tst_QShortcut) -#include "tst_qshortcut.moc" diff --git a/tests/auto/widgets/kernel/kernel.pro b/tests/auto/widgets/kernel/kernel.pro index 3a00300ac3..cf909b7e87 100644 --- a/tests/auto/widgets/kernel/kernel.pro +++ b/tests/auto/widgets/kernel/kernel.pro @@ -14,6 +14,7 @@ SUBDIRS=\ qwidget_window \ qwidgetaction \ qicon \ + qshortcut \ SUBDIRS -= qsound diff --git a/tests/auto/widgets/kernel/qshortcut/.gitignore b/tests/auto/widgets/kernel/qshortcut/.gitignore new file mode 100644 index 0000000000..3a17eb18e3 --- /dev/null +++ b/tests/auto/widgets/kernel/qshortcut/.gitignore @@ -0,0 +1 @@ +tst_qshortcut diff --git a/tests/auto/widgets/kernel/qshortcut/qshortcut.pro b/tests/auto/widgets/kernel/qshortcut/qshortcut.pro new file mode 100644 index 0000000000..7ac1dd2c9d --- /dev/null +++ b/tests/auto/widgets/kernel/qshortcut/qshortcut.pro @@ -0,0 +1,12 @@ +CONFIG += testcase +TARGET = tst_qshortcut + +# Project Configuration ---------------------------------------------- +INCLUDEPATH += ../ + +# Normal Test Files -------------------------------------------------- +QT += widgets testlib +HEADERS += +SOURCES += tst_qshortcut.cpp + + diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp new file mode 100644 index 0000000000..61efb6e3f3 --- /dev/null +++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp @@ -0,0 +1,1259 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class AccelForm; +QT_BEGIN_NAMESPACE +class QMainWindow; +class QTextEdit; +QT_END_NAMESPACE + +class tst_QShortcut : public QObject +{ + Q_OBJECT +public: + tst_QShortcut(); + virtual ~tst_QShortcut(); + + + enum Action { + SetupAccel, + TestAccel, + ClearAll + } currentAction; + + enum Widget { + NoWidget, + TriggerSlot1, + TriggerSlot2, + TriggerSlot3, + TriggerSlot4, + TriggerSlot5, + TriggerSlot6, + TriggerSlot7 + }; + + enum Result { + NoResult, + Slot1Triggered, + Slot2Triggered, + Slot3Triggered, + Slot4Triggered, + Slot5Triggered, + Slot6Triggered, + Slot7Triggered, + Ambiguous + } currentResult; + +public slots: + void slotTrig1() { currentResult = Slot1Triggered; } + void slotTrig2() { currentResult = Slot2Triggered; } + void slotTrig3() { currentResult = Slot3Triggered; } + void slotTrig4() { currentResult = Slot4Triggered; } + void slotTrig5() { currentResult = Slot5Triggered; } + void slotTrig6() { currentResult = Slot6Triggered; } + void slotTrig7() { currentResult = Slot7Triggered; } + void ambigSlot1() { currentResult = Ambiguous; ambigResult = Slot1Triggered; } + void ambigSlot2() { currentResult = Ambiguous; ambigResult = Slot2Triggered; } + void ambigSlot3() { currentResult = Ambiguous; ambigResult = Slot3Triggered; } + void ambigSlot4() { currentResult = Ambiguous; ambigResult = Slot4Triggered; } + void ambigSlot5() { currentResult = Ambiguous; ambigResult = Slot5Triggered; } + void ambigSlot6() { currentResult = Ambiguous; ambigResult = Slot6Triggered; } + void ambigSlot7() { currentResult = Ambiguous; ambigResult = Slot7Triggered; } + void statusMessage( const QString& message ) { sbText = message; } + void shortcutDestroyed(QObject* obj); + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void number_data(); + void number(); + void text_data(); + void text(); + void disabledItems(); + void ambiguousItems(); + void ambiguousRotation(); + void keypressConsumption(); + void unicodeCompare(); + void context(); + +protected: + static Qt::KeyboardModifiers toButtons( int key ); + void defElements(); + + void clearAllShortcuts(); + QShortcut *setupShortcut(int testWidget, const QKeySequence &ks); + QShortcut *setupShortcut(int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0); + + QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0); + QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QKeySequence &ks, Qt::ShortcutContext context = Qt::WindowShortcut); + + void sendKeyEvents(QWidget *w, int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0); + void sendKeyEvents(int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0); + + void testElement(); + + QMainWindow *mainW; + QList shortcuts; + QTextEdit *edit; + QString sbText; + Result ambigResult; +}; + +Q_DECLARE_METATYPE(tst_QShortcut::Widget); +Q_DECLARE_METATYPE(tst_QShortcut::Result); +Q_DECLARE_METATYPE(tst_QShortcut::Action); + +class TestEdit : public QTextEdit +{ + Q_OBJECT +public: + TestEdit(QWidget *parent, const char *name) + : QTextEdit(parent) + { + setObjectName(name); + } + +protected: + bool event(QEvent *e) { + // Make testedit allow any Ctrl+Key as shortcut + if (e->type() == QEvent::ShortcutOverride) { + QKeyEvent *ke = static_cast(e); + if (ke->modifiers() == Qt::ControlModifier + && ke->key() > Qt::Key_Any + && ke->key() < Qt::Key_ydiaeresis) { + ke->ignore(); + return true; + } + } + + // If keypress not processed as normal, check for + // Ctrl+Key event, and input custom string for + // result comparison. + if (e->type() == QEvent::KeyPress) { + QKeyEvent *ke = static_cast(e); + if (ke->modifiers() && ke->key() > Qt::Key_Any + && ke->key() < Qt::Key_ydiaeresis) { + if (ke->modifiers() == Qt::ControlModifier) + insertPlainText(QString("").arg(char(ke->key()))); + else if (ke->modifiers() == Qt::AltModifier) + insertPlainText(QString("").arg(char(ke->key()))); + else if (ke->modifiers() == Qt::ShiftModifier) + insertPlainText(QString("").arg(char(ke->key()))); + return true; + } + } + return QTextEdit::event(e); + } +}; + +tst_QShortcut::tst_QShortcut(): mainW( 0 ) +{ +} + +tst_QShortcut::~tst_QShortcut() +{ + clearAllShortcuts(); +} + +void tst_QShortcut::initTestCase() +{ + currentResult = NoResult; + mainW = new QMainWindow(0); + mainW->setWindowFlags(Qt::X11BypassWindowManagerHint); + edit = new TestEdit(mainW, "test_edit"); + mainW->setFixedSize( 100, 100 ); + mainW->setCentralWidget( edit ); + mainW->show(); + QTest::qWaitForWindowShown(mainW); + mainW->activateWindow(); + QTest::qWait(100); + connect( mainW->statusBar(), SIGNAL(messageChanged(const QString&)), + this, SLOT(statusMessage(const QString&)) ); +} + +void tst_QShortcut::cleanupTestCase() +{ + delete mainW; +} + +Qt::KeyboardModifiers tst_QShortcut::toButtons( int key ) +{ + Qt::KeyboardModifiers result = Qt::NoModifier; + if ( key & Qt::SHIFT ) + result |= Qt::ShiftModifier; + if ( key & Qt::CTRL ) + result |= Qt::ControlModifier; + if ( key & Qt::META ) + result |= Qt::MetaModifier; + if ( key & Qt::ALT ) + result |= Qt::AltModifier; + return result; +} + +void tst_QShortcut::defElements() +{ + QTest::addColumn("action"); + QTest::addColumn("testWidget"); + QTest::addColumn("txt"); + QTest::addColumn("k1"); + QTest::addColumn("c1"); + QTest::addColumn("k2"); + QTest::addColumn("c2"); + QTest::addColumn("k3"); + QTest::addColumn("c3"); + QTest::addColumn("k4"); + QTest::addColumn("c4"); + QTest::addColumn("result"); +} + +void tst_QShortcut::number() +{ + // We expect a failure on these tests, until QtTestKeyboard is + // fixed to do real platform dependent keyboard simulations + if (QTest::currentDataTag() == QString("N006a:Shift+Tab - [BackTab]") + || QTest::currentDataTag() == QString("N006b:Shift+Tab - [Shift+BackTab]")) + QEXPECT_FAIL("", "FLAW IN QTESTKEYBOARD: Keyboard events not passed through " + "platform dependent key handling code", Continue); + testElement(); +} +void tst_QShortcut::text() +{ + testElement(); +} +// ------------------------------------------------------------------ +// Number Elements -------------------------------------------------- +// ------------------------------------------------------------------ +void tst_QShortcut::number_data() +{ + defElements(); + + // Clear all + QTest::newRow("N00 - clear") << ClearAll << NoWidget <activateWindow(); + qApp->syncX(); + QTest::qWait(100); + + /* Testing Disabled Shortcuts + Qt::Key_M on slot1 + Shift + Qt::Key_M on slot1 + Qt::Key_M on slot2 (disabled) + Shift + Qt::Key_M on slot2 (disabled) + */ + + // Setup two identical shortcuts on different pushbuttons + QPushButton pb1(mainW); + QPushButton pb2(mainW); + pb1.setObjectName("pushbutton-1"); + pb2.setObjectName("pushbutton-2"); + pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger + pb2.show(); + + QShortcut *cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M"); + QShortcut *cut2 = setupShortcut(&pb1, "shortcut2-pb1", TriggerSlot1, "Shift+M"); + QShortcut *cut3 = setupShortcut(&pb2, "shortcut3-pb2", TriggerSlot2, "M"); + QShortcut *cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+M"); + + cut3->setEnabled(false); + cut4->setEnabled(false); + + currentResult = NoResult; + sendKeyEvents(Qt::Key_M, 'm'); + QCOMPARE(currentResult, Slot1Triggered); + + currentResult = NoResult; + sendKeyEvents(Qt::SHIFT+Qt::Key_M, 'M'); + QCOMPARE(currentResult, Slot1Triggered); + + cut2->setEnabled(false); + cut4->setEnabled(true); + + /* Testing Disabled Shortcuts + Qt::Key_M on slot1 + Shift + Qt::Key_M on slot1 (disabled) + Qt::Key_M on slot2 (disabled) + Shift + Qt::Key_M on slot2 + */ + currentResult = NoResult; + sendKeyEvents( Qt::Key_M, 'm' ); + QCOMPARE( currentResult, Slot1Triggered ); + + currentResult = NoResult; + sendKeyEvents( Qt::SHIFT+Qt::Key_M, 'M' ); + QCOMPARE( currentResult, Slot2Triggered ); + + + /* Testing Disabled Accel + Qt::Key_F5 on slot1 + Shift + Qt::Key_F5 on slot2 (disabled) + */ + clearAllShortcuts(); + cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "F5"); + cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+F5"); + + cut1->setKey(QKeySequence("F5")); + cut4->setKey(QKeySequence("Shift+F5")); + + cut1->setEnabled(true); + cut4->setEnabled(false); + + currentResult = NoResult; + sendKeyEvents( Qt::Key_F5, 0 ); + QCOMPARE( currentResult, Slot1Triggered ); + + currentResult = NoResult; + sendKeyEvents( Qt::SHIFT+Qt::Key_F5, 0 ); + QCOMPARE( currentResult, NoResult ); + +#if 0 + qFatal("Not testing statusbar text feedback yet, since not implemented"); + /* Testing Disabled Accel, and the corresponding statusbar feedback + Ctrl + Qt::Key_K, Ctrl + Qt::Key_L on slot1 + Ctrl + Qt::Key_K, Ctrl + Qt::Key_M on slot2 (disabled) + */ + cut1->setKey(QKeySequence("Ctrl+K, Ctrl+L")); + cut4->setKey(QKeySequence("Ctrl+K, Ctrl+M")); + + cut1->setEnabled(true); + cut4->setEnabled(false); + + currentResult = NoResult; + sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); + sendKeyEvents( Qt::CTRL+Qt::Key_Q, 0 ); + QCOMPARE( currentResult, NoResult ); + if (over_330) + QCOMPARE( sbText, QString("Ctrl+K, Ctrl+Q not defined") ); + + currentResult = NoResult; + sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); + sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 ); + QCOMPARE( currentResult, NoResult ); + if (over_330) + QCOMPARE( sbText, QString::null ); + + currentResult = NoResult; + sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); + sendKeyEvents( Qt::CTRL+Qt::Key_L, 0 ); + QCOMPARE( currentResult, Slot1Triggered ); + if (over_330) + QCOMPARE( sbText, QString::null ); +#endif + clearAllShortcuts(); + cut1 = 0; + cut4 = 0; +} +// ------------------------------------------------------------------ +// Ambiguous Elements ----------------------------------------------- +// ------------------------------------------------------------------ +void tst_QShortcut::ambiguousRotation() +{ + clearAllShortcuts(); + /* Testing Shortcut rotation scheme + Ctrl + Qt::Key_A on slot1 (disabled) + Ctrl + Qt::Key_A on slot2 (disabled) + Ctrl + Qt::Key_A on slot3 + Ctrl + Qt::Key_A on slot4 + Ctrl + Qt::Key_A on slot5 (disabled) + Ctrl + Qt::Key_A on slot6 + Ctrl + Qt::Key_A on slot7 (disabled) + */ + QShortcut *cut1 = setupShortcut(TriggerSlot1, "Ctrl+A"); + QShortcut *cut2 = setupShortcut(TriggerSlot2, "Ctrl+A"); + QShortcut *cut3 = setupShortcut(TriggerSlot3, "Ctrl+A"); + QShortcut *cut4 = setupShortcut(TriggerSlot4, "Ctrl+A"); + QShortcut *cut5 = setupShortcut(TriggerSlot5, "Ctrl+A"); + QShortcut *cut6 = setupShortcut(TriggerSlot6, "Ctrl+A"); + QShortcut *cut7 = setupShortcut(TriggerSlot7, "Ctrl+A"); + + cut1->setEnabled(false); + cut2->setEnabled(false); + cut5->setEnabled(false); + cut7->setEnabled(false); + + // Test proper rotation + // Start on first + // Go to last + // Go back to first + // Continue... + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot3Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot4Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot6Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot3Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot4Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot6Triggered); + + /* Testing Shortcut rotation scheme + Ctrl + Qt::Key_A on slot1 + Ctrl + Qt::Key_A on slot2 + Ctrl + Qt::Key_A on slot3 (disabled) + Ctrl + Qt::Key_A on slot4 (disabled) + Ctrl + Qt::Key_A on slot5 + Ctrl + Qt::Key_A on slot6 (disabled) + Ctrl + Qt::Key_A on slot7 + */ + + cut1->setEnabled(true); + cut2->setEnabled(true); + cut5->setEnabled(true); + cut7->setEnabled(true); + + cut3->setEnabled(false); + cut4->setEnabled(false); + cut6->setEnabled(false); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot1Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot2Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot5Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot7Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot1Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot2Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot5Triggered); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(Qt::CTRL+Qt::Key_A); + QCOMPARE(currentResult, Ambiguous); + QCOMPARE(ambigResult, Slot7Triggered); + + clearAllShortcuts(); + cut1 = 0; cut2 = 0; + cut3 = 0; cut4 = 0; + cut5 = 0; cut6 = 0; + cut7 = 0; +} + +void tst_QShortcut::ambiguousItems() +{ + clearAllShortcuts(); + /* Testing Ambiguous Shortcuts + Qt::Key_M on Pushbutton 1 + Qt::Key_M on Pushbutton 2 + */ + + // Setup two identical shortcuts on different pushbuttons + QPushButton pb1(mainW); + QPushButton pb2(mainW); + pb1.setObjectName("pushbutton-1"); + pb2.setObjectName("pushbutton-2"); + pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger + pb2.show(); + + setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M"); + setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, "M"); + + currentResult = NoResult; + sendKeyEvents( Qt::Key_M, 'm' ); + QCOMPARE( currentResult, Ambiguous ); + QCOMPARE( ambigResult, Slot1Triggered ); + + currentResult = NoResult; + sendKeyEvents( Qt::Key_M, 'm' ); + QCOMPARE( currentResult, Ambiguous ); + QCOMPARE( ambigResult, Slot2Triggered ); + + currentResult = NoResult; + sendKeyEvents( Qt::Key_M, 'm' ); + QCOMPARE( currentResult, Ambiguous ); + QCOMPARE( ambigResult, Slot1Triggered ); + + clearAllShortcuts(); +} + + +// ------------------------------------------------------------------ +// Unicode and non-unicode Elements --------------------------------- +// ------------------------------------------------------------------ +void tst_QShortcut::unicodeCompare() +{ + clearAllShortcuts(); + /* Testing Unicode/non-Unicode Shortcuts + Qt::Key_M on Pushbutton 1 + Qt::Key_M on Pushbutton 2 + */ + QPushButton pb1(mainW); + QPushButton pb2(mainW); + pb1.setObjectName("pushbutton-1"); + pb2.setObjectName("pushbutton-2"); + pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger + pb2.show(); + + QKeySequence ks1("Ctrl+M"); // Unicode + QKeySequence ks2(Qt::CTRL+Qt::Key_M); // non-Unicode + setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, ks1); + setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, ks2); + + currentResult = NoResult; + sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 ); + QCOMPARE( currentResult, Ambiguous ); + // They _are_ ambiguous, so the QKeySequence operator== + // should indicate the same + QVERIFY( ks1 == ks2 ); + QVERIFY( !(ks1 != ks2) ); + + clearAllShortcuts(); +} + +// ------------------------------------------------------------------ +// Keypress consumption verification -------------------------------- +// ------------------------------------------------------------------ +void tst_QShortcut::keypressConsumption() +{ + clearAllShortcuts(); + edit->clear(); + QCOMPARE(edit->toPlainText().size(), 0); + + QShortcut *cut1 = setupShortcut(edit, "shortcut1-line", TriggerSlot1, "Ctrl+I, A"); + QShortcut *cut2 = setupShortcut(edit, "shortcut1-line", TriggerSlot2, "Ctrl+I, B"); + + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0); // Send key to edit + QCOMPARE( currentResult, NoResult ); + QCOMPARE( ambigResult, NoResult ); + QCOMPARE(edit->toPlainText(), QString("")); + + // Make sure next keypress is eaten (failing multiple keysequence) + sendKeyEvents(edit, Qt::Key_C, 'c'); // Send key to edit + QCOMPARE( currentResult, NoResult ); + QCOMPARE( ambigResult, NoResult ); + QCOMPARE(edit->toPlainText(), QString("")); + + // Next keypress should be normal + sendKeyEvents(edit, Qt::Key_C, 'c'); // Send key to edit + QCOMPARE( currentResult, NoResult ); + QCOMPARE( ambigResult, NoResult ); + QCOMPARE(edit->toPlainText(), QString("c")); + + currentResult = NoResult; + ambigResult = NoResult; + edit->clear(); + QCOMPARE(edit->toPlainText().size(), 0); + + cut1->setEnabled(false); + cut2->setEnabled(false); + + // Make sure keypresses is passed on, since all multiple keysequences + // with Ctrl+I are disabled + sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0); // Send key to edit + QCOMPARE( currentResult, NoResult ); + QCOMPARE( ambigResult, NoResult ); + QVERIFY(edit->toPlainText().endsWith("")); + + sendKeyEvents(edit, Qt::Key_A, 'a'); // Send key to edit + QCOMPARE( currentResult, NoResult ); + QCOMPARE( ambigResult, NoResult ); + QVERIFY(edit->toPlainText().endsWith("a")); + + clearAllShortcuts(); +} + +// ------------------------------------------------------------------ +// Context Validation ----------------------------------------------- +// ------------------------------------------------------------------ +void tst_QShortcut::context() +{ + clearAllShortcuts(); + + QWidget myBox; + TestEdit *other1 = new TestEdit(&myBox, "test_edit_other1"); + TestEdit *other2 = new TestEdit(&myBox, "test_edit_other2"); + QHBoxLayout *layout = new QHBoxLayout(&myBox); + layout->addWidget(other1); + layout->addWidget(other2); + myBox.show(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&myBox); +#endif + + setupShortcut(other1, "ActiveWindow", TriggerSlot1, QKeySequence("Alt+1"), Qt::WindowShortcut); + setupShortcut(other2, "Focus", TriggerSlot2, QKeySequence("Alt+2"), Qt::WidgetShortcut); + setupShortcut(edit, "Application", TriggerSlot3, QKeySequence("Alt+3"), Qt::ApplicationShortcut); + + currentResult = NoResult; + ambigResult = NoResult; + edit->clear(); + other1->clear(); + other2->clear(); + + // edit doesn't have focus, so ActiveWindow context should work + // ..but Focus context shouldn't.. + // Changing focus to edit should make focus context work + // Application context should always work + + + // Focus on 'other1' edit, so Active Window context should trigger + other1->activateWindow(); // <--- + QApplication::setActiveWindow(other1); + QCOMPARE(qApp->activeWindow(), other1->window()); + QCOMPARE(qApp->focusWidget(), (QWidget *)other1); + + currentResult = NoResult; + ambigResult = NoResult; + edit->clear(); + other1->clear(); + other2->clear(); + + QCOMPARE(qApp->focusWidget(), (QWidget *)other1); + sendKeyEvents(other1, Qt::ALT+Qt::Key_1); + QCOMPARE(currentResult, Slot1Triggered); + QCOMPARE(ambigResult, NoResult); + QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(other1->toPlainText(), QString("")); + QCOMPARE(other2->toPlainText(), QString("")); + + // ..but not Focus context on 'other2'.. + currentResult = NoResult; + ambigResult = NoResult; + edit->clear(); + other1->clear(); + other2->clear(); + + sendKeyEvents(other1, Qt::ALT+Qt::Key_2); + QCOMPARE(currentResult, NoResult); + QCOMPARE(ambigResult, NoResult); + QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(other1->toPlainText(), QString("")); + QCOMPARE(other2->toPlainText(), QString("")); + + // ..however, application global context on 'edit' should.. + currentResult = NoResult; + ambigResult = NoResult; + edit->clear(); + other1->clear(); + other2->clear(); + + sendKeyEvents(other1, Qt::ALT+Qt::Key_3); + QCOMPARE(currentResult, Slot3Triggered); + QCOMPARE(ambigResult, NoResult); + QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(other1->toPlainText(), QString("")); + QCOMPARE(other2->toPlainText(), QString("")); + + // Changing focus to 'other2' should make the Focus context there work + other2->activateWindow(); + other2->setFocus(); // ### + qApp->syncX(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(other2); +#endif + QTest::qWait(100); + QCOMPARE(qApp->activeWindow(), other2->window()); + QCOMPARE(qApp->focusWidget(), (QWidget *)other2); + + currentResult = NoResult; + ambigResult = NoResult; + edit->clear(); + other1->clear(); + other2->clear(); + + sendKeyEvents(other2, Qt::ALT+Qt::Key_2); + QCOMPARE(currentResult, Slot2Triggered); + QCOMPARE(ambigResult, NoResult); + QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(other1->toPlainText(), QString("")); + QCOMPARE(other2->toPlainText(), QString("")); + + clearAllShortcuts(); + delete other1; + delete other2; + edit->activateWindow(); + qApp->syncX(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(edit); +#endif + QTest::qWait(100); +} + +// ------------------------------------------------------------------ +// Element Testing helper functions --------------------------------- +// ------------------------------------------------------------------ +void tst_QShortcut::clearAllShortcuts() +{ + QList shortcutsCpy = shortcuts; + qDeleteAll(shortcutsCpy); + shortcuts.clear(); +} + +QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QKeySequence &ks) +{ + return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget, ks); +} + +QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QString &txt, int k1, int k2, int k3, int k4) +{ + return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget, + (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt))); +} + +QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1, int k2, int k3, int k4) +{ + return setupShortcut(parent, name, testWidget, + (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt))); +} + +QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget, + const QKeySequence &ks, Qt::ShortcutContext context) +{ + // Set up shortcut for next test + QShortcut *cut = new QShortcut(QKeySequence(), parent, 0, 0, context); + cut->setObjectName(name); + cut->setKey(ks); + + const char *normal = 0; + const char *ambig = 0; + switch(testWidget) + { + case TriggerSlot1: + normal = SLOT(slotTrig1()); + ambig = SLOT(ambigSlot1()); + break; + case TriggerSlot2: + normal = SLOT(slotTrig2()); + ambig = SLOT(ambigSlot2()); + break; + case TriggerSlot3: + normal = SLOT(slotTrig3()); + ambig = SLOT(ambigSlot3()); + break; + case TriggerSlot4: + normal = SLOT(slotTrig4()); + ambig = SLOT(ambigSlot4()); + break; + case TriggerSlot5: + normal = SLOT(slotTrig5()); + ambig = SLOT(ambigSlot5()); + break; + case TriggerSlot6: + normal = SLOT(slotTrig6()); + ambig = SLOT(ambigSlot6()); + break; + case TriggerSlot7: + normal = SLOT(slotTrig7()); + ambig = SLOT(ambigSlot7()); + break; + } + connect(cut, SIGNAL(activated()), this, normal); + connect(cut, SIGNAL(activatedAmbiguously()), this, ambig); + connect(cut, SIGNAL(destroyed(QObject*)), this, SLOT(shortcutDestroyed(QObject*))); + shortcuts.append(cut); + return cut; +} + +void tst_QShortcut::shortcutDestroyed(QObject* obj) +{ + shortcuts.removeAll(static_cast(obj)); +} + +void tst_QShortcut::sendKeyEvents(int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4) +{ + sendKeyEvents(mainW, k1, c1, k2, c2, k3, c3, k4, c4); +} + +void tst_QShortcut::sendKeyEvents(QWidget *w, int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4) +{ + Qt::KeyboardModifiers b1 = toButtons( k1 ); + Qt::KeyboardModifiers b2 = toButtons( k2 ); + Qt::KeyboardModifiers b3 = toButtons( k3 ); + Qt::KeyboardModifiers b4 = toButtons( k4 ); + k1 &= ~Qt::MODIFIER_MASK; + k2 &= ~Qt::MODIFIER_MASK; + k3 &= ~Qt::MODIFIER_MASK; + k4 &= ~Qt::MODIFIER_MASK; + + + if (k1 || c1.toAscii()) { + QString c(c1.unicode() == QChar::Null ? QString() : QString(c1)); + QTest::sendKeyEvent(QTest::Press, w, static_cast(k1), c, b1); + QTest::sendKeyEvent(QTest::Release, w, static_cast(k1), c, b1); + } + + if (k2 || c2.toAscii()) { + QString c(c2.unicode() == QChar::Null ? QString() : QString(c2)); + QTest::sendKeyEvent(QTest::Press, w, static_cast(k2), c, b2); + QTest::sendKeyEvent(QTest::Release, w, static_cast(k2), c, b2); + } + + if (k3 || c3.toAscii()) { + QString c(c3.unicode() == QChar::Null ? QString() : QString(c3)); + QTest::sendKeyEvent(QTest::Press, w, static_cast(k3), c, b3); + QTest::sendKeyEvent(QTest::Release, w, static_cast(k3), c, b3); + } + + if (k4 || c4.toAscii()) { + QString c(c4.unicode() == QChar::Null ? QString() : QString(c4)); + QTest::sendKeyEvent(QTest::Press, w, static_cast(k4), c, b4); + QTest::sendKeyEvent(QTest::Release, w, static_cast(k4), c, b4); + } +} + +void tst_QShortcut::testElement() +{ + currentResult = NoResult; + QFETCH(tst_QShortcut::Action, action); + QFETCH(tst_QShortcut::Widget, testWidget); + QFETCH(QString, txt); + QFETCH(int, k1); + QFETCH(int, c1); + QFETCH(int, k2); + QFETCH(int, c2); + QFETCH(int, k3); + QFETCH(int, c3); + QFETCH(int, k4); + QFETCH(int, c4); + QFETCH(tst_QShortcut::Result, result); + + if (action == ClearAll) { + clearAllShortcuts(); + } else if (action == SetupAccel) { + setupShortcut(testWidget, txt, k1, k2, k3, k4); + } else { + sendKeyEvents(k1, c1, k2, c2, k3, c3, k4, c4); + QCOMPARE(currentResult, result); + } +} + +QTEST_MAIN(tst_QShortcut) +#include "tst_qshortcut.moc" -- cgit v1.2.3 From 612040a0cd702e4c764e5cbb5d0c091497650c6a Mon Sep 17 00:00:00 2001 From: Alexei Rousskikh Date: Mon, 12 Mar 2012 14:33:39 -0400 Subject: Trailing comma should result in an error during JSON parsing 1. QJsonParseError::MissingObject defined 2. QJsonDocument::fromJson() will result in defined error after parsing of something like "{ 'key':1 , }" or "[ {'key':1}, ]" Change-Id: I8e6234a03b8aca4e5ad6180f273f91066b86d7a1 Reviewed-by: Lars Knoll --- tests/auto/corelib/json/tst_qtjson.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index 079ff6e76b..87820d2e78 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -120,6 +120,8 @@ private Q_SLOTS: void assignObjects(); void assignArrays(); + + void testTrailingComma(); private: QString testDataDir; }; @@ -1807,5 +1809,16 @@ void TestQtJson::assignArrays() QCOMPARE(inner.at(0).toDouble(), 2.); } +void TestQtJson::testTrailingComma() +{ + const char *jsons[] = { "{ \"Key\": 1, }", "[ { \"Key\": 1 }, ]" }; + + for (unsigned i = 0; i < sizeof(jsons)/sizeof(jsons[0]); ++i) { + QJsonParseError error; + QJsonDocument doc = QJsonDocument::fromJson(jsons[i], &error); + QCOMPARE(error.error, QJsonParseError::MissingObject); + } +} + QTEST_MAIN(TestQtJson) #include "tst_qtjson.moc" -- cgit v1.2.3 From 13c57d0f68cffb139311e8e22a074099eb28a88f Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Tue, 28 Feb 2012 22:42:02 +0100 Subject: QSqlTableModel::isDirty(): new overloaded method Checks if model has any changes to submit. Includes new test covering isDirty(index) as well the new overloaded function. Task-number: QTBUG-3108 Change-Id: I0ccbda45d5d9f06434cf1e1c037a9efb76d0cc37 Reviewed-by: Honglei Zhang --- .../models/qsqltablemodel/tst_qsqltablemodel.cpp | 162 +++++++++++++++++++++ 1 file changed, 162 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp index 448111cd9f..7dcc109cdc 100644 --- a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp @@ -95,6 +95,8 @@ private slots: void removeInsertedRow(); void removeInsertedRows_data() { generic_data(); } void removeInsertedRows(); + void isDirty_data() { generic_data_with_strategies(); } + void isDirty(); void setFilter_data() { generic_data(); } void setFilter(); void setInvalidFilter_data() { generic_data(); } @@ -956,6 +958,166 @@ void tst_QSqlTableModel::removeInsertedRows() QCOMPARE(model.data(model.index(1, 1)).toString(), QString("vohi")); } +void tst_QSqlTableModel::isDirty() +{ + QFETCH(QString, dbName); + QFETCH(int, submitpolicy_i); + QSqlTableModel::EditStrategy submitpolicy = (QSqlTableModel::EditStrategy) submitpolicy_i; + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + QSqlTableModel model(0, db); + model.setEditStrategy(submitpolicy); + model.setTable(test); + QFAIL_SQL(model, isDirty()); + + model.setSort(0, Qt::AscendingOrder); + QVERIFY_SQL(model, select()); + QFAIL_SQL(model, isDirty()); + + if (submitpolicy != QSqlTableModel::OnFieldChange) { + // setData() followed by revertAll() + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QVERIFY_SQL(model, setData(model.index(0, 1), QString("sam i am"))); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("sam i am")); + QVERIFY_SQL(model, isDirty()); + QVERIFY_SQL(model, isDirty(model.index(0, 1))); + model.revertAll(); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + + // setData() followed by select(), which clears changes + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QVERIFY_SQL(model, setData(model.index(0, 1), QString("sam i am"))); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("sam i am")); + QVERIFY_SQL(model, isDirty()); + QVERIFY_SQL(model, isDirty(model.index(0, 1))); + QVERIFY_SQL(model, select()); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + } + + // setData() followed by submitAll() + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QVERIFY_SQL(model, setData(model.index(0, 1), QString("sam i am"))); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("sam i am")); + if (submitpolicy != QSqlTableModel::OnFieldChange) { + QVERIFY_SQL(model, isDirty()); + QVERIFY_SQL(model, isDirty(model.index(0, 1))); + } + QVERIFY_SQL(model, submitAll()); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("sam i am")); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + // check status after refreshing underlying query + QVERIFY_SQL(model, select()); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("sam i am")); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + //restore original state + QVERIFY_SQL(model, setData(model.index(0, 1), QString("harry"))); + QVERIFY_SQL(model, submitAll()); + QVERIFY_SQL(model, select()); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + + QSqlRecord newvals = model.record(0); + newvals.setValue(1, QString("sam i am")); + newvals.setGenerated(1, true); + if (submitpolicy != QSqlTableModel::OnFieldChange) { + // setRecord() followed by revertAll() + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QVERIFY_SQL(model, setRecord(0, newvals)); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("sam i am")); + QVERIFY_SQL(model, isDirty()); + QVERIFY_SQL(model, isDirty(model.index(0, 1))); + model.revertAll(); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + + // setRecord() followed by select(), which clears changes + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QVERIFY_SQL(model, setRecord(0, newvals)); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("sam i am")); + QVERIFY_SQL(model, isDirty()); + QVERIFY_SQL(model, isDirty(model.index(0, 1))); + QVERIFY_SQL(model, select()); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + } + + // setRecord() followed by submitAll() + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QVERIFY_SQL(model, setRecord(0, newvals)); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("sam i am")); + if (submitpolicy != QSqlTableModel::OnFieldChange) { + QVERIFY_SQL(model, isDirty()); + QVERIFY_SQL(model, isDirty(model.index(0, 1))); + } + QVERIFY_SQL(model, submitAll()); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("sam i am")); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + // check status after refreshing underlying query + QVERIFY_SQL(model, select()); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("sam i am")); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + //restore original state + QVERIFY_SQL(model, setData(model.index(0, 1), QString("harry"))); + QVERIFY_SQL(model, submitAll()); + QVERIFY_SQL(model, select()); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + + // insertRow() + QVERIFY_SQL(model, insertRow(0)); + QVERIFY_SQL(model, isDirty()); + QVERIFY_SQL(model, isDirty(model.index(0, 1))); + model.revertAll(); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + QVERIFY_SQL(model, select()); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + + // removeRow() + QSqlRecord saved_rec = model.record(0); + QVERIFY_SQL(model, removeRow(0)); + if (submitpolicy == QSqlTableModel::OnManualSubmit) { + QVERIFY_SQL(model, isDirty()); + QVERIFY_SQL(model, isDirty(model.index(0, 1))); + } + QVERIFY_SQL(model, submitAll()); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + QVERIFY_SQL(model, select()); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("trond")); + + // insertRecord(), put back the removed row + for (int i = saved_rec.count() - 1; i >= 0; --i) + saved_rec.setGenerated(i, true); + QVERIFY_SQL(model, insertRecord(0, saved_rec)); + if (submitpolicy == QSqlTableModel::OnManualSubmit) { + QVERIFY_SQL(model, isDirty()); + QVERIFY_SQL(model, isDirty(model.index(0, 1))); + } + QVERIFY_SQL(model, submitAll()); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + QVERIFY_SQL(model, select()); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); +} + void tst_QSqlTableModel::emptyTable() { QFETCH(QString, dbName); -- cgit v1.2.3 From 76ddc9bc0c14b01e2e3c760cade5265da4f4a5c1 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Wed, 7 Mar 2012 19:09:33 +0100 Subject: Autotest details of QAccessibleEvent. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ieec33c23e7b18cfedf061088d6561203a5e7ac39 Reviewed-by: Jan-Arve Sæther --- .../other/qaccessibility/tst_qaccessibility.cpp | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 0edda96f2a..24469c74d0 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -403,8 +403,8 @@ void tst_QAccessibility::cleanup() qWarning("%d accessibility event(s) were not handled in testfunction '%s':", list.count(), QString(QTest::currentTestFunction()).toAscii().constData()); for (int i = 0; i < list.count(); ++i) - qWarning(" %d: Object: %p Event: '%s' Child: %d", i + 1, list.at(i).object(), - eventName(list.at(i).type()).toAscii().constData(), list.at(i).child()); + qWarning(" %d: Object: %p Event: '%s' Child: %d", i + 1, list.at(i)->object(), + eventName(list.at(i)->type()).toAscii().constData(), list.at(i)->child()); } QTestAccessibility::clearEvents(); } @@ -730,16 +730,16 @@ void tst_QAccessibility::hideShowTest() window->show(); QVERIFY(!state(window).invisible); QVERIFY(!state(child).invisible); - QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectShow, window))); - QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectShow, child))); + QVERIFY(QTestAccessibility::containsEvent(QAccessibleEvent(QAccessible::ObjectShow, window))); + QVERIFY(QTestAccessibility::containsEvent(QAccessibleEvent(QAccessible::ObjectShow, child))); QTestAccessibility::clearEvents(); // hide() and veryfy that both window and child are invisible and get ObjectHide events. window->hide(); QVERIFY(state(window).invisible); QVERIFY(state(child).invisible); - QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectHide, window))); - QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectHide, child))); + QVERIFY(QTestAccessibility::containsEvent(QAccessibleEvent(QAccessible::ObjectHide, window))); + QVERIFY(QTestAccessibility::containsEvent(QAccessibleEvent(QAccessible::ObjectHide, child))); QTestAccessibility::clearEvents(); delete window; @@ -963,6 +963,9 @@ void tst_QAccessibility::buttonTest() delete menu; } + + QTestAccessibility::clearEvents(); + { // test check box interface = QAccessible::queryAccessibleInterface(&checkBox); actionInterface = interface->actionInterface(); @@ -970,11 +973,16 @@ void tst_QAccessibility::buttonTest() QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::checkAction() << QAccessibleActionInterface::setFocusAction()); QVERIFY(!interface->state().checked); actionInterface->doAction(QAccessibleActionInterface::checkAction()); + QTest::qWait(500); QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::uncheckAction() << QAccessibleActionInterface::setFocusAction()); QVERIFY(interface->state().checked); QVERIFY(checkBox.isChecked()); + QAccessible::State st; + st.checked = true; + QVERIFY_EVENT(QAccessibleStateChangeEvent(st, &checkBox)); delete interface; + } // test radiobutton interface = QAccessible::queryAccessibleInterface(&radio); @@ -1050,12 +1058,12 @@ void tst_QAccessibility::scrollBarTest() scrollBar->resize(200, 50); scrollBar->show(); QVERIFY(!scrollBarInterface->state().invisible); - QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectShow, scrollBar))); + QVERIFY(QTestAccessibility::containsEvent(QAccessibleEvent(QAccessible::ObjectShow, scrollBar))); QTestAccessibility::clearEvents(); scrollBar->hide(); QVERIFY(scrollBarInterface->state().invisible); - QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::ObjectHide, scrollBar))); + QVERIFY(QTestAccessibility::containsEvent(QAccessibleEvent(QAccessible::ObjectHide, scrollBar))); QTestAccessibility::clearEvents(); // Test that the left/right subcontrols are set to unavailable when the scrollBar is at the minimum/maximum. @@ -1495,9 +1503,8 @@ void tst_QAccessibility::spinBoxTest() QTestAccessibility::clearEvents(); QTest::keyPress(spinBox, Qt::Key_Up); QTest::qWait(200); - EventList events = QTestAccessibility::events(); QAccessibleEvent expectedEvent(QAccessible::ValueChanged, spinBox); - QVERIFY(events.contains(expectedEvent)); + QVERIFY(QTestAccessibility::containsEvent(expectedEvent)); delete spinBox; QTestAccessibility::clearEvents(); } @@ -1767,7 +1774,7 @@ void tst_QAccessibility::lineEditTest() le->setFocus(Qt::TabFocusReason); QTestAccessibility::clearEvents(); le2->setFocus(Qt::TabFocusReason); - QTRY_VERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Focus, le2))); + QTRY_VERIFY(QTestAccessibility::containsEvent(QAccessibleEvent(QAccessible::Focus, le2))); le->setText(QLatin1String("500")); le->setValidator(new QIntValidator()); @@ -1787,7 +1794,7 @@ void tst_QAccessibility::lineEditTest() le3->deselect(); le3->setCursorPosition(3); QCOMPARE(textIface->cursorPosition(), 3); - QTRY_VERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::TextCaretMoved, le3))); + QTRY_VERIFY(QTestAccessibility::containsEvent(QAccessibleEvent(QAccessible::TextCaretMoved, le3))); QCOMPARE(textIface->selectionCount(), 0); QTestAccessibility::clearEvents(); @@ -2158,11 +2165,11 @@ void tst_QAccessibility::listTest() // Check for events QTest::mouseClick(listView->viewport(), Qt::LeftButton, 0, listView->visualItemRect(listView->item(1)).center()); - QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Selection, listView, 2))); - QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Focus, listView, 2))); + QVERIFY(QTestAccessibility::containsEvent(QAccessibleEvent(QAccessible::Selection, listView, 2))); + QVERIFY(QTestAccessibility::containsEvent(QAccessibleEvent(QAccessible::Focus, listView, 2))); QTest::mouseClick(listView->viewport(), Qt::LeftButton, 0, listView->visualItemRect(listView->item(2)).center()); - QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Selection, listView, 3))); - QVERIFY(QTestAccessibility::events().contains(QAccessibleEvent(QAccessible::Focus, listView, 3))); + QVERIFY(QTestAccessibility::containsEvent(QAccessibleEvent(QAccessible::Selection, listView, 3))); + QVERIFY(QTestAccessibility::containsEvent(QAccessibleEvent(QAccessible::Focus, listView, 3))); listView->addItem("Munich"); QCOMPARE(iface->childCount(), 4); -- cgit v1.2.3 From 6d85d77a5def22ef8a50505f3c7634146db73421 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Wed, 7 Mar 2012 19:38:39 +0100 Subject: Clean up test, check radio button and checkbox. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I4dcfa2014256aee10feb08146ae6fc3f402ac8fb Reviewed-by: Jan-Arve Sæther --- tests/auto/other/qaccessibility/tst_qaccessibility.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 24469c74d0..3cd7d7c211 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -981,9 +981,12 @@ void tst_QAccessibility::buttonTest() QAccessible::State st; st.checked = true; QVERIFY_EVENT(QAccessibleStateChangeEvent(st, &checkBox)); + checkBox.setChecked(false); + QVERIFY_EVENT(QAccessibleStateChangeEvent(st, &checkBox)); delete interface; } + { // test radiobutton interface = QAccessible::queryAccessibleInterface(&radio); actionInterface = interface->actionInterface(); @@ -994,8 +997,12 @@ void tst_QAccessibility::buttonTest() QTest::qWait(500); QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::checkAction() << QAccessibleActionInterface::setFocusAction()); QVERIFY(interface->state().checked); - QVERIFY(checkBox.isChecked()); + QVERIFY(radio.isChecked()); + QAccessible::State st; + st.checked = true; + QVERIFY_EVENT(QAccessibleStateChangeEvent(st, &radio)); delete interface; + } // // test standard toolbutton // QVERIFY(QAccessible::queryAccessibleInterface(&toolbutton, &test)); @@ -1045,8 +1052,6 @@ void tst_QAccessibility::buttonTest() // QCOMPARE(test->actionText(test->defaultAction(2), QAccessible::Name, 2), QString("Open")); // QCOMPARE(test->state(2), (int)QAccessible::HasPopup); // test->release(); - - QTestAccessibility::clearEvents(); } void tst_QAccessibility::scrollBarTest() -- cgit v1.2.3 From 2c515ea42c3d2270b3c8f059bbdbe255cb5be77e Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Tue, 13 Mar 2012 14:11:51 +0100 Subject: Print all accessibility event strings. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2488fe86fb2c154a8b7d91c6e4f2cd9c9e7b9ecb Reviewed-by: Jan-Arve Sæther --- .../other/qaccessibility/tst_qaccessibility.cpp | 48 +--------------------- 1 file changed, 1 insertion(+), 47 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 3cd7d7c211..c984fedc86 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -278,52 +278,6 @@ private: const double Q_PI = 3.14159265358979323846; -QString eventName(const int ev) -{ - switch(ev) { - case 0x0001: return "SoundPlayed"; - case 0x0002: return "Alert"; - case 0x0003: return "ForegroundChanged"; - case 0x0004: return "MenuStart"; - case 0x0005: return "MenuEnd"; - case 0x0006: return "PopupMenuStart"; - case 0x0007: return "PopupMenuEnd"; - case 0x000C: return "ContextHelpStart"; - case 0x000D: return "ContextHelpEnd"; - case 0x000E: return "DragDropStart"; - case 0x000F: return "DragDropEnd"; - case 0x0010: return "DialogStart"; - case 0x0011: return "DialogEnd"; - case 0x0012: return "ScrollingStart"; - case 0x0013: return "ScrollingEnd"; - case 0x0018: return "MenuCommand"; - - case 0x0116: return "TableModelChanged"; - case 0x011B: return "TextCaretMoved"; - - case 0x8000: return "ObjectCreated"; - case 0x8001: return "ObjectDestroyed"; - case 0x8002: return "ObjectShow"; - case 0x8003: return "ObjectHide"; - case 0x8004: return "ObjectReorder"; - case 0x8005: return "Focus"; - case 0x8006: return "Selection"; - case 0x8007: return "SelectionAdd"; - case 0x8008: return "SelectionRemove"; - case 0x8009: return "SelectionWithin"; - case 0x800A: return "StateChanged"; - case 0x800B: return "LocationChanged"; - case 0x800C: return "NameChanged"; - case 0x800D: return "DescriptionChanged"; - case 0x800E: return "ValueChanged"; - case 0x800F: return "ParentChanged"; - case 0x80A0: return "HelpChanged"; - case 0x80B0: return "DefaultActionChanged"; - case 0x80C0: return "AcceleratorChanged"; - default: return "Unknown Event"; - } -} - QAccessible::State state(QWidget * const widget) { QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget); @@ -404,7 +358,7 @@ void tst_QAccessibility::cleanup() QString(QTest::currentTestFunction()).toAscii().constData()); for (int i = 0; i < list.count(); ++i) qWarning(" %d: Object: %p Event: '%s' Child: %d", i + 1, list.at(i)->object(), - eventName(list.at(i)->type()).toAscii().constData(), list.at(i)->child()); + qAccessibleEventString(list.at(i)->type()), list.at(i)->child()); } QTestAccessibility::clearEvents(); } -- cgit v1.2.3 From 360e5e0c0821f247eb182eb70cbea83503c42077 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 13 Mar 2012 14:33:14 +1000 Subject: Remove commented code from qtconcurrentmap autotest. The removed code was already commented out when the test was added to the Qt repository and does not compile when uncommented as it calls non-existant overloads of QtConcurrent::FunctionWrapper1::operator(). Change-Id: I5a02efae4b89e2815b077474aa7cd0192dcb2730 Reviewed-by: Rohan McGovern --- tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp | 9 --------- 1 file changed, 9 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp index 35ee0be326..d0609d00ef 100644 --- a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp +++ b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp @@ -2115,15 +2115,6 @@ void tst_QtConcurrentMap::functionOverloads() QtConcurrent::blockingMapped >(constIntList, changeTypeConst); QtConcurrent::blockingMapped >(classList, &MemFnTester::changeTypeConst); QtConcurrent::blockingMapped >(constMemFnTesterList, &MemFnTester::changeTypeConst); - - QStringList stringList; - const QStringList constStringList; - // QtConcurrent::map(stringList, changeTypeQStringListConst); - // QtConcurrent::map(intList, changeTypeNonConst); - // QList(QtConcurrent::map(constStringList, changeTypeQStringList)); - // QtConcurrent::map(classList, &MemFnTester::changeType); - // QtConcurrent::map(classList, &MemFnTester::changeTypeConst); - // QtConcurrent::map(constMemFnTesterList, &MemFnTester::changeTypeConst); } QAtomicInt currentInstanceCount; -- cgit v1.2.3 From 16045184e34b54111fc817feb8bd13cd5a536bce Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 13 Mar 2012 15:12:54 +1000 Subject: Tidy the QSettings autotest. - remove unnecessary includes - remove undefined private functions - remove commented-out test function - fix indentation - clarify why part of tst_QSettings::setValue() is commented-out Change-Id: I09e1a33896536e702f7ba65f266415536b4f9e0b Reviewed-by: Rohan McGovern --- tests/auto/corelib/io/qsettings/tst_qsettings.cpp | 148 +++++++++------------- 1 file changed, 62 insertions(+), 86 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index df8e97ab9c..b9ade8e7c8 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ -#include #include #include @@ -48,11 +47,13 @@ #include #include #include -#include #include +#include +#include #include #include +#include #if defined(Q_OS_WIN) && defined(Q_CC_GNU) // need for unlink on mingw #include @@ -60,13 +61,16 @@ #if defined(Q_OS_WIN) #include +#else +#include #endif +Q_DECLARE_METATYPE(QSettings::Format) + #ifndef QSETTINGS_P_H_VERSION #define QSETTINGS_P_H_VERSION 1 #endif -QT_FORWARD_DECLARE_CLASS(QSettings) QT_FORWARD_DECLARE_CLASS(QSettings) class tst_QSettings : public QObject @@ -136,12 +140,6 @@ private slots: void testByteArray_data(); void testByteArray(); - -private: - void oldWriteEntry_data(); - void oldReadEntry_data(); - void oldWriteEntryHelper(QSettings &settings); - void oldReadEntryHelper(QSettings &settings); }; // Testing get/set functions @@ -156,20 +154,6 @@ void tst_QSettings::getSetCheck() QCOMPARE(true, obj1.fallbacksEnabled()); } -//using namespace std; - -//#include -#include -#include -#include -#include -#include -#ifndef Q_OS_WIN -#include -#endif - -Q_DECLARE_METATYPE(QSettings::Format) - #if defined(Q_OS_WINCE) static void removePath(const QString& _path) { @@ -194,7 +178,7 @@ static void removePath(const QString& _path) static QString settingsPath(const char *path = "") { - // Temporary path for files that are specified explictly in the constructor. + // Temporary path for files that are specified explicitly in the constructor. QString tempPath = QDir::tempPath(); if (tempPath.endsWith("/")) tempPath.truncate(tempPath.size() - 1); @@ -971,6 +955,8 @@ void tst_QSettings::setValue() QCOMPARE(settings.value("key 2").toBool(), true); settings.setValue("key 2", QString("false")); QCOMPARE(settings.value("key 2", true).toBool(), false); + + // The following block should not compile. /* settings.setValue("key 2", "true"); QCOMPARE(settings.value("key 2").toBool(), true); @@ -984,8 +970,8 @@ void tst_QSettings::setValue() QCOMPARE(settings.value("key 2", true).toBool(), true); settings.setValue("key 2", "0.000e-00"); QCOMPARE(settings.value("key 2", false).toBool(), false); - */ + settings.setValue("key 2", QStringList()); QCOMPARE(settings.value("key 2").toStringList(), QStringList()); settings.setValue("key 2", QStringList("")); @@ -1963,43 +1949,43 @@ void tst_QSettings::setIniCodec() QByteArray actualContents4, actualContents5; { - QFile inFile(":/resourcefile4.ini"); - inFile.open(QIODevice::ReadOnly); - expeContents4 = inFile.readAll(); - inFile.close(); + QFile inFile(":/resourcefile4.ini"); + inFile.open(QIODevice::ReadOnly); + expeContents4 = inFile.readAll(); + inFile.close(); } { - QFile inFile(":/resourcefile5.ini"); - inFile.open(QIODevice::ReadOnly); - expeContents5 = inFile.readAll(); - inFile.close(); + QFile inFile(":/resourcefile5.ini"); + inFile.open(QIODevice::ReadOnly); + expeContents5 = inFile.readAll(); + inFile.close(); } { - QSettings settings4(QSettings::IniFormat, QSettings::UserScope, "software.org", "KillerAPP"); - settings4.setIniCodec("UTF-8"); - settings4.setValue(QLatin1String("Fa\xe7" "ade/QU\xc9" "BEC"), QLatin1String("Fa\xe7" "ade/QU\xc9" "BEC")); - settings4.sync(); - - QSettings settings5(QSettings::IniFormat, QSettings::UserScope, "other.software.org", "KillerAPP"); - settings5.setIniCodec("ISO 8859-1"); - settings5.setValue(QLatin1String("Fa\xe7" "ade/QU\xc9" "BEC"), QLatin1String("Fa\xe7" "ade/QU\xc9" "BEC")); - settings5.sync(); - - { - QFile inFile(settings4.fileName()); - inFile.open(QIODevice::ReadOnly); - actualContents4 = inFile.readAll(); - inFile.close(); - } + QSettings settings4(QSettings::IniFormat, QSettings::UserScope, "software.org", "KillerAPP"); + settings4.setIniCodec("UTF-8"); + settings4.setValue(QLatin1String("Fa\xe7" "ade/QU\xc9" "BEC"), QLatin1String("Fa\xe7" "ade/QU\xc9" "BEC")); + settings4.sync(); + + QSettings settings5(QSettings::IniFormat, QSettings::UserScope, "other.software.org", "KillerAPP"); + settings5.setIniCodec("ISO 8859-1"); + settings5.setValue(QLatin1String("Fa\xe7" "ade/QU\xc9" "BEC"), QLatin1String("Fa\xe7" "ade/QU\xc9" "BEC")); + settings5.sync(); + + { + QFile inFile(settings4.fileName()); + inFile.open(QIODevice::ReadOnly); + actualContents4 = inFile.readAll(); + inFile.close(); + } - { - QFile inFile(settings5.fileName()); - inFile.open(QIODevice::ReadOnly); - actualContents5 = inFile.readAll(); - inFile.close(); - } + { + QFile inFile(settings5.fileName()); + inFile.open(QIODevice::ReadOnly); + actualContents5 = inFile.readAll(); + inFile.close(); + } } QConfFile::clearCache(); @@ -2901,10 +2887,10 @@ void tst_QSettings::registerFormat() f.close(); { - QSettings settings(settingsPath("someDir/someSettings.custom3"), QSettings::CustomFormat3); - QCOMPARE(settings.status(), QSettings::NoError); - QCOMPARE(settings.value("retval").toString(), QString("OK")); - QVERIFY(settings.isWritable()); + QSettings settings(settingsPath("someDir/someSettings.custom3"), QSettings::CustomFormat3); + QCOMPARE(settings.status(), QSettings::NoError); + QCOMPARE(settings.value("retval").toString(), QString("OK")); + QVERIFY(settings.isWritable()); } QVERIFY(f.open(QFile::WriteOnly)); @@ -2912,10 +2898,10 @@ void tst_QSettings::registerFormat() f.close(); { - QSettings settings(settingsPath("someDir/someSettings.custom3"), QSettings::CustomFormat3); - QCOMPARE(settings.status(), QSettings::FormatError); - QCOMPARE(settings.value("retval").toString(), QString()); - QVERIFY(settings.isWritable()); + QSettings settings(settingsPath("someDir/someSettings.custom3"), QSettings::CustomFormat3); + QCOMPARE(settings.status(), QSettings::FormatError); + QCOMPARE(settings.value("retval").toString(), QString()); + QVERIFY(settings.isWritable()); } QVERIFY(f.open(QFile::WriteOnly)); @@ -2923,24 +2909,24 @@ void tst_QSettings::registerFormat() f.close(); { - QSettings settings(settingsPath("someDir/someSettings.custom3"), QSettings::CustomFormat3); - QCOMPARE(settings.status(), QSettings::NoError); - settings.setValue("zzz", "bar"); - settings.sync(); - QCOMPARE(settings.status(), QSettings::NoError); + QSettings settings(settingsPath("someDir/someSettings.custom3"), QSettings::CustomFormat3); + QCOMPARE(settings.status(), QSettings::NoError); + settings.setValue("zzz", "bar"); + settings.sync(); + QCOMPARE(settings.status(), QSettings::NoError); - settings.setValue("retval", "NotOK"); - settings.sync(); - QCOMPARE(settings.status(), QSettings::AccessError); + settings.setValue("retval", "NotOK"); + settings.sync(); + QCOMPARE(settings.status(), QSettings::AccessError); - QCOMPARE(settings.value("retval").toString(), QString("NotOK")); - QVERIFY(settings.isWritable()); + QCOMPARE(settings.value("retval").toString(), QString("NotOK")); + QVERIFY(settings.isWritable()); } { - QSettings settings(settingsPath("someDir/someSettings.custom3"), QSettings::CustomFormat4); - QCOMPARE(settings.status(), QSettings::AccessError); - QVERIFY(!settings.isWritable()); + QSettings settings(settingsPath("someDir/someSettings.custom3"), QSettings::CustomFormat4); + QCOMPARE(settings.status(), QSettings::AccessError); + QVERIFY(!settings.isWritable()); } } @@ -3168,16 +3154,6 @@ void tst_QSettings::consistentRegistryStorage() } } #endif -/* -// Not tested at the moment. -void tst_QSettings::oldSubkeyList() -{ - QVERIFY( true ); -} -*/ QTEST_MAIN(tst_QSettings) #include "tst_qsettings.moc" - - -// foo -- cgit v1.2.3 From f4dfb55243cccf8bbf4176fee856f945f8564171 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 13 Mar 2012 17:06:09 +1000 Subject: Uncomment disabled code in QResourceEngine autotest. Resource files are expected to be readable. Change-Id: Ife2b624e69b58e2fb996bc3e210a6e6c5c6852fe Reviewed-by: Rohan McGovern --- tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index 796282d6d8..990841dc87 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -311,7 +311,7 @@ void tst_QResourceEngine::checkStructure() QVERIFY(fileInfo.exists()); QCOMPARE(fileInfo.isDir(), directory); QCOMPARE(fileInfo.size(), contentsSize); - //QVERIFY(fileInfo.isReadable()); + QVERIFY(fileInfo.isReadable()); QVERIFY(!fileInfo.isWritable()); QVERIFY(!fileInfo.isExecutable()); -- cgit v1.2.3 From 22494ea8e82d5d5588e67e8067f0273687ed9098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Tue, 13 Mar 2012 14:15:53 +0100 Subject: Unify QMetaType::TypeFlags detection. Duplicated code was removed. As an side effect: - one runtime flag check was replaced by a compile time check. - is enum flag can be used together with built-in types. Change-Id: I54173e7b07ce7e487d3cc21ba24dcccd28b5d049 Reviewed-by: Olivier Goffart --- .../corelib/kernel/qmetatype/tst_qmetatype.cpp | 48 +++++++++++++--------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index bc5fa2716b..a3959f6d33 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -717,39 +717,47 @@ Q_DECLARE_METATYPE(QPairPC) Q_DECLARE_METATYPE(QPairPM) Q_DECLARE_METATYPE(QPairPP) +enum FlagsDataEnum {}; +Q_DECLARE_METATYPE(FlagsDataEnum); + void tst_QMetaType::flags_data() { QTest::addColumn("type"); QTest::addColumn("isMovable"); QTest::addColumn("isComplex"); QTest::addColumn("isPointerToQObject"); + QTest::addColumn("isEnum"); #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \ - QTest::newRow(#RealType) << MetaTypeId << bool(!QTypeInfo::isStatic) << bool(QTypeInfo::isComplex) << bool(QtPrivate::IsPointerToTypeDerivedFromQObject::Value); + QTest::newRow(#RealType) << MetaTypeId \ + << bool(!QTypeInfo::isStatic) \ + << bool(QTypeInfo::isComplex) \ + << bool(QtPrivate::IsPointerToTypeDerivedFromQObject::Value) \ + << bool(Q_IS_ENUM(RealType)); QT_FOR_EACH_STATIC_CORE_CLASS(ADD_METATYPE_TEST_ROW) QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(ADD_METATYPE_TEST_ROW) QT_FOR_EACH_STATIC_CORE_POINTER(ADD_METATYPE_TEST_ROW) #undef ADD_METATYPE_TEST_ROW - QTest::newRow("TestSpace::Foo") << ::qMetaTypeId() << false << true << false; - QTest::newRow("Whity") << ::qMetaTypeId >() << false << true << false; - QTest::newRow("CustomMovable") << ::qMetaTypeId() << true << true << false; - QTest::newRow("CustomObject*") << ::qMetaTypeId() << true << false << true; - QTest::newRow("CustomMultiInheritanceObject*") << ::qMetaTypeId() << true << false << true; - QTest::newRow("QPair") << ::qMetaTypeId >() << false << true << false; - QTest::newRow("QPair") << ::qMetaTypeId >() << false << true << false; - QTest::newRow("QPair") << ::qMetaTypeId >() << false << true << false; - QTest::newRow("QPair") << ::qMetaTypeId >() << false << true << false; - QTest::newRow("QPair") << ::qMetaTypeId >() << true << true << false; - QTest::newRow("QPair") << ::qMetaTypeId >() << true << true << false; - QTest::newRow("QPair") << ::qMetaTypeId >() << false << true << false; - QTest::newRow("QPair") << ::qMetaTypeId >() << true << true << false; - QTest::newRow("QPair") << ::qMetaTypeId >() << true << false << false; + QTest::newRow("TestSpace::Foo") << ::qMetaTypeId() << false << true << false << false; + QTest::newRow("Whity") << ::qMetaTypeId >() << false << true << false << false; + QTest::newRow("CustomMovable") << ::qMetaTypeId() << true << true << false << false; + QTest::newRow("CustomObject*") << ::qMetaTypeId() << true << false << true << false; + QTest::newRow("CustomMultiInheritanceObject*") << ::qMetaTypeId() << true << false << true << false; + QTest::newRow("QPair") << ::qMetaTypeId >() << false << true << false << false; + QTest::newRow("QPair") << ::qMetaTypeId >() << false << true << false << false; + QTest::newRow("QPair") << ::qMetaTypeId >() << false << true << false << false; + QTest::newRow("QPair") << ::qMetaTypeId >() << false << true << false << false; + QTest::newRow("QPair") << ::qMetaTypeId >() << true << true << false << false; + QTest::newRow("QPair") << ::qMetaTypeId >() << true << true << false << false; + QTest::newRow("QPair") << ::qMetaTypeId >() << false << true << false << false; + QTest::newRow("QPair") << ::qMetaTypeId >() << true << true << false << false; + QTest::newRow("QPair") << ::qMetaTypeId >() << true << false << false << false; + QTest::newRow("FlagsDataEnum") << ::qMetaTypeId() << false << true << false << true; // invalid ids. - QTest::newRow("-1") << -1 << false << false << false; - QTest::newRow("-124125534") << -124125534 << false << false << false; - QTest::newRow("124125534") << 124125534 << false << false << false; - + QTest::newRow("-1") << -1 << false << false << false << false; + QTest::newRow("-124125534") << -124125534 << false << false << false << false; + QTest::newRow("124125534") << 124125534 << false << false << false << false; } void tst_QMetaType::flags() @@ -758,11 +766,13 @@ void tst_QMetaType::flags() QFETCH(bool, isMovable); QFETCH(bool, isComplex); QFETCH(bool, isPointerToQObject); + QFETCH(bool, isEnum); QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::NeedsConstruction), isComplex); QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::NeedsDestruction), isComplex); QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::MovableType), isMovable); QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::PointerToQObject), isPointerToQObject); + QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::IsEnumeration), isEnum); } void tst_QMetaType::flagsStaticLess_data() -- cgit v1.2.3 From b64426248d2212eb59535b2ca383d30fdb5e1c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Sat, 3 Mar 2012 06:05:54 +0100 Subject: QHeaderView - renaming functions in Qt5 This patch renames the functions in Qt5 according to the notes. It also renames resizeMode to be consistent. The old functions are both marked with both QT_DEPRECATED and '### Qt 6 - remove' All usage of the function within the qtbase are also changed to use the new functions. Change-Id: I9e05fa41d232e9ca43b945fcc949987017f3aedd Reviewed-by: Stephen Kelly --- .../qfilesystemmodel/tst_qfilesystemmodel.cpp | 2 +- .../itemviews/qheaderview/tst_qheaderview.cpp | 60 +++++++++++----------- 2 files changed, 31 insertions(+), 31 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index fe374b1e8d..1a3d083864 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -847,7 +847,7 @@ void tst_QFileSystemModel::sort() tree->resize(800, 800); QTest::qWait(500); tree->header()->setSortIndicator(1,Qt::DescendingOrder); - tree->header()->setResizeMode(0, QHeaderView::ResizeToContents); + tree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); QStringList dirsToOpen; do { diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 3edc125b5a..9ad71771c5 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -502,20 +502,20 @@ void tst_QHeaderView::removeCols() void tst_QHeaderView::movable() { - QCOMPARE(view->isMovable(), false); - view->setMovable(false); - QCOMPARE(view->isMovable(), false); - view->setMovable(true); - QCOMPARE(view->isMovable(), true); + QCOMPARE(view->sectionsMovable(), false); + view->setSectionsMovable(false); + QCOMPARE(view->sectionsMovable(), false); + view->setSectionsMovable(true); + QCOMPARE(view->sectionsMovable(), true); } void tst_QHeaderView::clickable() { - QCOMPARE(view->isClickable(), false); - view->setClickable(false); - QCOMPARE(view->isClickable(), false); - view->setClickable(true); - QCOMPARE(view->isClickable(), true); + QCOMPARE(view->sectionsClickable(), false); + view->setSectionsClickable(false); + QCOMPARE(view->sectionsClickable(), false); + view->setSectionsClickable(true); + QCOMPARE(view->sectionsClickable(), true); } void tst_QHeaderView::hidden() @@ -1108,7 +1108,7 @@ void tst_QHeaderView::resizeWithResizeModes() view->setStretchLastSection(false); for (int i = 0; i < sections.count(); ++i) { view->resizeSection(i, sections.at(i)); - view->setResizeMode(i, (QHeaderView::ResizeMode)modes.at(i)); + view->setSectionResizeMode(i, (QHeaderView::ResizeMode)modes.at(i)); } topLevel->show(); view->resize(size, size); @@ -1150,27 +1150,27 @@ void tst_QHeaderView::resizeMode() // resizeMode must not be called with an invalid index int last = view->count() - 1; view->setResizeMode(QHeaderView::Interactive); - QCOMPARE(view->resizeMode(last), QHeaderView::Interactive); - QCOMPARE(view->resizeMode(1), QHeaderView::Interactive); + QCOMPARE(view->sectionResizeMode(last), QHeaderView::Interactive); + QCOMPARE(view->sectionResizeMode(1), QHeaderView::Interactive); view->setResizeMode(QHeaderView::Stretch); - QCOMPARE(view->resizeMode(last), QHeaderView::Stretch); - QCOMPARE(view->resizeMode(1), QHeaderView::Stretch); + QCOMPARE(view->sectionResizeMode(last), QHeaderView::Stretch); + QCOMPARE(view->sectionResizeMode(1), QHeaderView::Stretch); view->setResizeMode(QHeaderView::Custom); - QCOMPARE(view->resizeMode(last), QHeaderView::Custom); - QCOMPARE(view->resizeMode(1), QHeaderView::Custom); + QCOMPARE(view->sectionResizeMode(last), QHeaderView::Custom); + QCOMPARE(view->sectionResizeMode(1), QHeaderView::Custom); // test when sections have been moved view->setStretchLastSection(false); for (int i=0; i < (view->count() - 1); ++i) - view->setResizeMode(i, QHeaderView::Interactive); + view->setSectionResizeMode(i, QHeaderView::Interactive); int logicalIndex = view->count() / 2; - view->setResizeMode(logicalIndex, QHeaderView::Stretch); + view->setSectionResizeMode(logicalIndex, QHeaderView::Stretch); view->moveSection(view->visualIndex(logicalIndex), 0); for (int i=0; i < (view->count() - 1); ++i) { if (i == logicalIndex) - QCOMPARE(view->resizeMode(i), QHeaderView::Stretch); + QCOMPARE(view->sectionResizeMode(i), QHeaderView::Stretch); else - QCOMPARE(view->resizeMode(i), QHeaderView::Interactive); + QCOMPARE(view->sectionResizeMode(i), QHeaderView::Interactive); } } @@ -1209,12 +1209,12 @@ void tst_QHeaderView::resizeSection() view->resize(400, 400); topLevel->show(); - view->setMovable(true); + view->setSectionsMovable(true); view->setStretchLastSection(false); for (int i = 0; i < logical.count(); ++i) if (logical.at(i) > -1 && logical.at(i) < view->count()) // for now - view->setResizeMode(logical.at(i), (QHeaderView::ResizeMode)mode.at(i)); + view->setSectionResizeMode(logical.at(i), (QHeaderView::ResizeMode)mode.at(i)); for (int j = 0; j < logical.count(); ++j) view->resizeSection(logical.at(j), initial); @@ -1447,7 +1447,7 @@ void tst_QHeaderView::stretchSectionCount() view->setStretchLastSection(true); QCOMPARE(view->stretchSectionCount(), 0); - view->setResizeMode(0, QHeaderView::Stretch); + view->setSectionResizeMode(0, QHeaderView::Stretch); QCOMPARE(view->stretchSectionCount(), 1); } @@ -1693,7 +1693,7 @@ void tst_QHeaderView::globalResizeMode() h.setResizeMode((QHeaderView::ResizeMode)mode); m.insertRow(insert); for (int i = 0; i < h.count(); ++i) - QCOMPARE(h.resizeMode(i), (QHeaderView::ResizeMode)mode); + QCOMPARE(h.sectionResizeMode(i), (QHeaderView::ResizeMode)mode); } @@ -1725,7 +1725,7 @@ void tst_QHeaderView::sectionPressedSignal() h.setModel(&m); h.show(); - h.setClickable(clickable); + h.setSectionsClickable(clickable); QSignalSpy spy(&h, SIGNAL(sectionPressed(int))); @@ -1745,7 +1745,7 @@ void tst_QHeaderView::sectionClickedSignal() h.setModel(&m); h.show(); - h.setClickable(clickable); + h.setSectionsClickable(clickable); h.setSortIndicatorShown(true); QSignalSpy spy(&h, SIGNAL(sectionClicked(int))); @@ -1869,7 +1869,7 @@ void tst_QHeaderView::preserveHiddenSectionWidth() view.resizeSection(0, 100); view.resizeSection(1, 10); view.resizeSection(2, 50); - view.setResizeMode(3, QHeaderView::Stretch); + view.setSectionResizeMode(3, QHeaderView::Stretch); view.show(); view.hideSection(2); @@ -2066,7 +2066,7 @@ void tst_QHeaderView::QTBUG7833_sectionClicked() tv.setSortingEnabled(true); tv.horizontalHeader()->setSortIndicatorShown(true); - tv.horizontalHeader()->setClickable(true); + tv.horizontalHeader()->setSectionsClickable(true); tv.horizontalHeader()->setStretchLastSection(true); tv.horizontalHeader()->setResizeMode(QHeaderView::Interactive); @@ -2126,7 +2126,7 @@ void tst_QHeaderView::QTBUG12268_hiddenMovedSectionSorting() for (int j = 0; j< model->columnCount(); ++j) model->setData(model->index(i,j), QString("item [%1,%2]").arg(i).arg(j)); view.setModel(model); - view.horizontalHeader()->setMovable(true); + view.horizontalHeader()->setSectionsMovable(true); view.setSortingEnabled(true); view.sortByColumn(1, Qt::AscendingOrder); view.horizontalHeader()->moveSection(0,2); -- cgit v1.2.3 From d6311a06515221e41edb69722b571080c08d11ce Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Fri, 16 Dec 2011 13:12:39 +0100 Subject: Cocoa: Improve basic window handling. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor NSWindow creation into createNSWindow and setNSWindow. This is necessary to support QMacNativeWidget where we re-use an already created window. Implement popup window handling. Make sure the window is displayed correctly and closes when it should. Take control over window activation in order to prevent infinite loops involving the QtCreator "cmd-k" window. Activation events are for now not sent to popup-type windows. There is now a different set of test failures: add and remove some QEXPECT_FAILs. Change-Id: I229761b59f90c9815b968eacc2cbc9c20cc5047e Reviewed-by: Morten Johan Sørvig --- .../graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 3 --- .../qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp | 3 --- tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp | 17 ++--------------- tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp | 3 --- .../widgets/widgets/qdockwidget/tst_qdockwidget.cpp | 3 +++ 5 files changed, 5 insertions(+), 24 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 5c99e48388..98c3866dd2 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -1069,9 +1069,6 @@ void tst_QGraphicsItem::toolTip() foundTipLabel = true; } QVERIFY(foundView); -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-23707", Continue); -#endif QVERIFY(foundTipLabel); } diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 843b584ce5..fef21c19f7 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -2640,9 +2640,6 @@ void tst_QGraphicsProxyWidget::tooltip_basic() foundTipLabel = true; } QVERIFY(foundView); -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-23707", Continue); -#endif QVERIFY(foundTipLabel); } } diff --git a/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp b/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp index b47ef659be..e20111c652 100644 --- a/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp +++ b/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp @@ -90,12 +90,8 @@ void tst_QToolTip::task183679_data() { QTest::addColumn("key"); QTest::addColumn("visible"); -#ifdef Q_OS_MAC - const bool visibleAfterNonModifier = false; -#else - const bool visibleAfterNonModifier = true; -#endif - QTest::newRow("non-modifier") << Qt::Key_A << visibleAfterNonModifier; + + QTest::newRow("non-modifier") << Qt::Key_A << true; QTest::newRow("Shift") << Qt::Key_Shift << true; QTest::newRow("Control") << Qt::Key_Control << true; QTest::newRow("Alt") << Qt::Key_Alt << true; @@ -116,9 +112,6 @@ void tst_QToolTip::task183679() widget.showDelayedToolTip(100); QTest::qWait(300); -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-23707", Continue); -#endif QTRY_VERIFY(QToolTip::isVisible()); QTest::keyPress(&widget, key); @@ -128,12 +121,6 @@ void tst_QToolTip::task183679() // auto-close timeout (currently 10000 msecs) QTest::qWait(1500); -#ifdef Q_OS_MAC - QEXPECT_FAIL("Shift", "QTBUG-23707", Continue); - QEXPECT_FAIL("Control", "QTBUG-23707", Continue); - QEXPECT_FAIL("Alt", "QTBUG-23707", Continue); - QEXPECT_FAIL("Meta", "QTBUG-23707", Continue); -#endif QCOMPARE(QToolTip::isVisible(), visible); } diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index f9eb8b6159..4730d7d556 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -909,9 +909,6 @@ void tst_QComboBox::hide() QTRY_VERIFY(testWidget->view()->isVisible()); testWidget->hidePopup(); //allow combobox effect to complete -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-23678", Continue); -#endif QTRY_VERIFY(!testWidget->view()->isVisible()); testWidget->hide(); QVERIFY(!testWidget->isVisible()); diff --git a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp index 43c0022c25..7e7b049166 100644 --- a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp @@ -764,6 +764,9 @@ void tst_QDockWidget::task169808_setFloating() qt_x11_wait_for_window_manager(&mw); #endif +#ifdef Q_OS_MAC + QEXPECT_FAIL("", "Window handling: QTBUG-24774", Abort); +#endif QCOMPARE(dw->widget()->size(), dw->widget()->sizeHint()); //and now we try to test if the contents margin is taken into account -- cgit v1.2.3 From 9e87104295b019a1afa49f856ddcef07249d1afb Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Tue, 13 Mar 2012 11:40:25 +0100 Subject: QTableView: call model->submit() on row change QTreeView already does this in the exact same way. It's necessary to call submit() so edit strategy OnRowChange in QSqlTableModel will work as expected. Change-Id: Ib430143e8a71f3b0bcd842fcc772cc7ee4525f0a Reviewed-by: Olivier Goffart --- .../itemviews/qtableview/tst_qtableview.cpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index 9144a023d7..0c396aac60 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -175,6 +175,7 @@ private slots: void tabFocus(); void bigModel(); void selectionSignal(); + void setCurrentIndex(); // task-specific tests: void task173773_updateVerticalHeader(); @@ -254,11 +255,15 @@ class QtTestTableModel: public QAbstractTableModel signals: void invalidIndexEncountered() const; +public slots: + bool submit() { ++submit_count; return QAbstractTableModel::submit(); } + public: QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0) : QAbstractTableModel(parent), row_count(rows), column_count(columns), + submit_count(0), can_fetch_more(false), fetch_more_count(0), disabled_rows(), @@ -400,6 +405,7 @@ public: int row_count; int column_count; + int submit_count; bool can_fetch_more; int fetch_more_count; QSet disabled_rows; @@ -3480,6 +3486,27 @@ void tst_QTableView::selectionSignal() QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(2, 0)).center()); } +void tst_QTableView::setCurrentIndex() +{ + QtTestTableModel model(4, 4); + QtTestTableView view; + view.setModel(&model); + + // submit() slot should be called in model when current row changes + view.setCurrentIndex(model.index(0,0)); + QCOMPARE(model.submit_count, 1); + view.setCurrentIndex(model.index(0,2)); + QCOMPARE(model.submit_count, 1); + view.setCurrentIndex(model.index(1,0)); + QCOMPARE(model.submit_count, 2); + view.setCurrentIndex(model.index(3,3)); + QCOMPARE(model.submit_count, 3); + view.setCurrentIndex(model.index(0,1)); + QCOMPARE(model.submit_count, 4); + view.setCurrentIndex(model.index(0,0)); + QCOMPARE(model.submit_count, 4); +} + class task173773_EventFilter : public QObject { int paintEventCount_; -- cgit v1.2.3 From aac68052afb83ab6d33a1b874f1cf3192586afa4 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Thu, 15 Mar 2012 09:17:23 +1000 Subject: Mark tst_qtimeline as insignificant on Windows This test has been repeatedly unstable. Task-number: QTBUG-24796 Change-Id: I603965c0189ad6da0cdf48527c4919c55e1918b4 Reviewed-by: Toby Tomkins --- tests/auto/corelib/tools/qtimeline/qtimeline.pro | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/auto') diff --git a/tests/auto/corelib/tools/qtimeline/qtimeline.pro b/tests/auto/corelib/tools/qtimeline/qtimeline.pro index 3a6c120b5a..cac8074038 100644 --- a/tests/auto/corelib/tools/qtimeline/qtimeline.pro +++ b/tests/auto/corelib/tools/qtimeline/qtimeline.pro @@ -2,3 +2,4 @@ CONFIG += testcase parallel_test TARGET = tst_qtimeline QT = core testlib SOURCES = tst_qtimeline.cpp +win32:CONFIG+=insignificant_test # unstable, QTBUG-24796 -- cgit v1.2.3 From 329469d5a1c12e4bcc9b2a5ae283539e6ebfc34a Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Thu, 15 Mar 2012 08:29:17 +1000 Subject: headersclean: omit -Wcast-align also on MIPS These issues are permitted to go unfixed for ARM and MIPS, for the time being. Change-Id: Ibdf33dc42e3de19ef20e9dc50f12f451ea6dbf23 Reviewed-by: Thiago Macieira --- tests/auto/other/headersclean/headersclean.pri | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/other/headersclean/headersclean.pri b/tests/auto/other/headersclean/headersclean.pri index 163ef6d409..c95380e3b9 100644 --- a/tests/auto/other/headersclean/headersclean.pri +++ b/tests/auto/other/headersclean/headersclean.pri @@ -18,8 +18,10 @@ # Enable pedantic mode, but accept variadic macros and 'long long' usage. *-g++*: QMAKE_CXXFLAGS += -Wno-long-long -Wno-variadic-macros -pedantic-errors -# There are outstanding alignment issues on ARM in some container classes. -contains(QT_ARCH,arm):*-g++*:QMAKE_CXXFLAGS -= -Wcast-align +contains(QT_ARCH,arm)|contains(QT_ARCH,mips) { + # There are outstanding alignment issues in some container classes. + *-g++*:QMAKE_CXXFLAGS -= -Wcast-align +} QMAKE_CXXFLAGS += -DQT_NO_CAST_TO_ASCII \ -DQT_NO_CAST_FROM_ASCII \ -- cgit v1.2.3 From 8a79e8b645bfaa2f9ed00976466198223f6db6dd Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Tue, 6 Mar 2012 12:23:31 +0100 Subject: Remove unmaintained and broken VNC platform plugin Change-Id: Ie0a07c3a6822870b095a20d997b63fb1635f20be Reviewed-by: Oswald Buddenhagen Reviewed-by: Robert Griebl Reviewed-by: Girish Ramakrishnan --- tests/auto/other/other.pro | 4 +- tests/auto/other/qmultiscreen/.gitignore | 1 - tests/auto/other/qmultiscreen/qmultiscreen.pro | 7 - tests/auto/other/qmultiscreen/tst_qmultiscreen.cpp | 163 --------------------- 4 files changed, 1 insertion(+), 174 deletions(-) delete mode 100644 tests/auto/other/qmultiscreen/.gitignore delete mode 100644 tests/auto/other/qmultiscreen/qmultiscreen.pro delete mode 100644 tests/auto/other/qmultiscreen/tst_qmultiscreen.cpp (limited to 'tests/auto') diff --git a/tests/auto/other/other.pro b/tests/auto/other/other.pro index 6c708baa6b..2a6dc1d662 100644 --- a/tests/auto/other/other.pro +++ b/tests/auto/other/other.pro @@ -18,7 +18,6 @@ SUBDIRS=\ qaccessibility \ qcomplextext \ qfocusevent \ - qmultiscreen \ qnetworkaccessmanager_and_qprogressdialog \ qobjectperformance \ qobjectrace \ @@ -40,8 +39,7 @@ wince*|!contains(QT_CONFIG, accessibility):SUBDIRS -= qaccessibility macplist !embedded|wince*: SUBDIRS -= \ - qdirectpainter \ - qmultiscreen \ + qdirectpainter !linux*-g++*:SUBDIRS -= exceptionsafety_objects diff --git a/tests/auto/other/qmultiscreen/.gitignore b/tests/auto/other/qmultiscreen/.gitignore deleted file mode 100644 index 82e8d449ad..0000000000 --- a/tests/auto/other/qmultiscreen/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tst_qmultiscreen diff --git a/tests/auto/other/qmultiscreen/qmultiscreen.pro b/tests/auto/other/qmultiscreen/qmultiscreen.pro deleted file mode 100644 index 28373823bf..0000000000 --- a/tests/auto/other/qmultiscreen/qmultiscreen.pro +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG += testcase -TARGET = tst_qmultiscreen -QT += widgets testlib -SOURCES += tst_qmultiscreen.cpp - -requires(embedded) - diff --git a/tests/auto/other/qmultiscreen/tst_qmultiscreen.cpp b/tests/auto/other/qmultiscreen/tst_qmultiscreen.cpp deleted file mode 100644 index 9beb0666eb..0000000000 --- a/tests/auto/other/qmultiscreen/tst_qmultiscreen.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include - -#include -#include -#include -#include - -class tst_QMultiScreen : public QObject -{ - Q_OBJECT - -public: - tst_QMultiScreen() : screen(0), oldScreen(0) {} - ~tst_QMultiScreen() {} - -private slots: - void initTestCase(); - void cleanupTestCase(); - void widgetSetFixedSize(); - void grabWindow(); - -private: - QScreen *screen; - QScreen *oldScreen; -}; - -void tst_QMultiScreen::cleanupTestCase() -{ - screen->shutdownDevice(); - screen->disconnect(); - delete screen; - screen = 0; - - qt_screen = oldScreen; -} - -void tst_QMultiScreen::initTestCase() -{ - oldScreen = qt_screen; - - QVERIFY(QScreenDriverFactory::keys().contains(QLatin1String("Multi"))); - QVERIFY(QScreenDriverFactory::keys().contains(QLatin1String("VNC"))); - - const int id = 10; - screen = QScreenDriverFactory::create("Multi", id); - QVERIFY(screen); - QVERIFY(screen->connect(QString("Multi: " - "VNC:size=640x480:depth=32:offset=0,0:%1 " - "VNC:size=640x480:depth=32:offset=640,0:%2 " - "VNC:size=640x480:depth=16:offset=0,480:%3 " - ":%4") - .arg(id+1).arg(id+2).arg(id+3).arg(id))); - QVERIFY(screen->initDevice()); - - QDesktopWidget desktop; - QCOMPARE(desktop.numScreens(), 3); -} - -void tst_QMultiScreen::widgetSetFixedSize() -{ - QDesktopWidget desktop; - QRect maxRect; - for (int i = 0; i < desktop.numScreens(); ++i) - maxRect |= desktop.availableGeometry(i); - - maxRect = maxRect.adjusted(50, 50, -50, -50); - - // make sure we can set a size larger than a single screen (task 166368) - QWidget w; - w.setFixedSize(maxRect.size()); - w.show(); - QApplication::processEvents(); - QCOMPARE(w.geometry().size(), maxRect.size()); -} - -void tst_QMultiScreen::grabWindow() -{ - QDesktopWidget desktop; - - QVERIFY(desktop.numScreens() >= 2); - - const QRect r0 = desktop.availableGeometry(0).adjusted(50, 50, -50, -50); - const QRect r1 = desktop.availableGeometry(1).adjusted(60, 60, -60, -60); - - QWidget w; - w.setGeometry(r0); - w.show(); - - QLabel l("hi there"); - l.setGeometry(r1); - l.show(); - - QApplication::processEvents(); - QApplication::sendPostedEvents(); // workaround for glib event loop - QVERIFY(desktop.screenNumber(&w) == 0); - QVERIFY(desktop.screenNumber(&l) == 1); - - const QPixmap p0 = QPixmap::grabWindow(w.winId()); - const QPixmap p1 = QPixmap::grabWindow(l.winId()); - -// p0.save("w.png", "PNG"); -// p1.save("l.png", "PNG"); - QCOMPARE(p0.size(), w.size()); - QCOMPARE(p1.size(), l.size()); - - const QImage img0 = p0.toImage(); - const QImage img1 = p1.toImage(); - -// QPixmap::grabWidget(&w).toImage().convertToFormat(img0.format()).save("w_img.png", "PNG"); -// QPixmap::grabWidget(&l).toImage().convertToFormat(img1.format()).save("l_img.png", "PNG"); - - QImage::Format format = QImage::Format_RGB16; - QCOMPARE(img0.convertToFormat(format), - QPixmap::grabWidget(&w).toImage().convertToFormat(format)); - QCOMPARE(img1.convertToFormat(format), - QPixmap::grabWidget(&l).toImage().convertToFormat(format)); -} - -QTEST_MAIN(tst_QMultiScreen) - -#include "tst_qmultiscreen.moc" -- cgit v1.2.3 From 07764b9c15ff9be15730252c9f930cb0b2efe15a Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 13 Mar 2012 16:36:38 +1000 Subject: Verify expected warnings in QSettings autotest. Use QTest::ignoreMessage() so that the warnings don't appear in the test output and so that the test will fail if the warnings are not produced. Change-Id: I418d78819fc9dbfd7da2a8b6c0a1ebfa967347e2 Reviewed-by: Rohan McGovern --- tests/auto/corelib/io/qsettings/tst_qsettings.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index b9ade8e7c8..d294eec248 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -880,8 +880,10 @@ void tst_QSettings::beginGroup() QCOMPARE(settings1.value("geometry").toInt(), 777); // endGroup() should do nothing if group() is empty - for (int i = 0; i < 10; ++i) + for (int i = 0; i < 10; ++i) { + QTest::ignoreMessage(QtWarningMsg, "QSettings::endGroup: No matching beginGroup()"); settings2.endGroup(); + } QCOMPARE(settings2.value("geometry").toInt(), 5); QCOMPARE(settings2.value("alpha/geometry").toInt(), 66); QCOMPARE(settings2.value("alpha/beta/geometry").toInt(), 777); @@ -2167,6 +2169,16 @@ void tst_QSettings::testArrays() endArray() and vice versa. This is not documented, but this is the behavior that we have chosen. */ + QTest::ignoreMessage(QtWarningMsg, "QSettings::setArrayIndex: Missing beginArray()"); + QTest::ignoreMessage(QtWarningMsg, "QSettings::setArrayIndex: Missing beginArray()"); + QTest::ignoreMessage(QtWarningMsg, "QSettings::setArrayIndex: Missing beginArray()"); + QTest::ignoreMessage(QtWarningMsg, "QSettings::setArrayIndex: Missing beginArray()"); + QTest::ignoreMessage(QtWarningMsg, "QSettings::setArrayIndex: Missing beginArray()"); + QTest::ignoreMessage(QtWarningMsg, "QSettings::endArray: Expected endGroup() instead"); + QTest::ignoreMessage(QtWarningMsg, "QSettings::endGroup: Expected endArray() instead"); + QTest::ignoreMessage(QtWarningMsg, "QSettings::endArray: Expected endGroup() instead"); + QTest::ignoreMessage(QtWarningMsg, "QSettings::endGroup: No matching beginGroup()"); + QSettings settings1(format, QSettings::UserScope, "software.org", "KillerAPP"); settings1.clear(); settings1.beginGroup("/alpha"); @@ -2217,7 +2229,6 @@ void tst_QSettings::testArrays() QCOMPARE(settings1.group(), QString()); settings1.endGroup(); QCOMPARE(settings1.group(), QString()); - /* Now, let's make sure that things work well if an array is spread across multiple files. -- cgit v1.2.3 From 65a2613e3e4fd341c2be35cb4eaf03d0918c2661 Mon Sep 17 00:00:00 2001 From: Debao Zhang Date: Tue, 13 Mar 2012 10:46:39 -0700 Subject: tst_qsharedpointer: Fix auto test fail under Windows 7 The tst_QSharedPointer generate another Process to test some invalid codes, and it expect that the prcoess will crash and return a non-zero value. The process which is a console application was linked to windows subsystem, and QProcess seems can not get its return value. This cause the unit test fail. In addition, when the process crash under debug mode, a debug error report-dialog will appear, which is very annoying, so I suppress it too. Task-number: QTBUG-24160 Change-Id: Ia1c872d4515c83b0aa516bcfe3783f59797d2d49 Reviewed-by: Friedemann Kleint --- tests/auto/corelib/tools/qsharedpointer/externaltests.cpp | 13 ++++++++++++- tests/auto/corelib/tools/qsharedpointer/qsharedpointer.pro | 2 -- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp index fb946d9ca1..0e7e2fad70 100644 --- a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp @@ -353,15 +353,25 @@ namespace QTest { "\n" "#ifdef Q_OS_WIN\n" "#include \n" + "#if defined(Q_CC_MSVC) && !defined(Q_OS_WINCE)\n" + "#include \n" + "#endif\n" "static void q_test_setup()\n" "{\n" " SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);\n" "}\n" + "static int __cdecl CrtDbgHook(int /*reportType*/, char * /*message*/, int * /*returnValue*/)\n" + "{\n" + " return TRUE;\n" + "}\n" "#else\n" "static void q_test_setup() { }\n" "#endif\n" "int main(int argc, char **argv)\n" - "{\n"; + "{\n" + "#if defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) && !defined(Q_OS_WINCE)\n" + " _CrtSetReportHook2(_CRT_RPTHOOK_INSTALL, CrtDbgHook);\n" + "#endif\n"; switch (appType) { applicationless: @@ -456,6 +466,7 @@ namespace QTest { "TARGET = externaltest\n" "CONFIG -= app_bundle\n" // for the Mac "CONFIG -= debug_and_release\n" + "CONFIG += console\n" "DESTDIR = .\n" "OBJECTS_DIR = .\n" "UI_DIR = .\n" diff --git a/tests/auto/corelib/tools/qsharedpointer/qsharedpointer.pro b/tests/auto/corelib/tools/qsharedpointer/qsharedpointer.pro index 1b227109b3..b1cd309293 100644 --- a/tests/auto/corelib/tools/qsharedpointer/qsharedpointer.pro +++ b/tests/auto/corelib/tools/qsharedpointer/qsharedpointer.pro @@ -13,5 +13,3 @@ HEADERS = forwarddeclared.h \ TESTDATA += forwarddeclared.cpp forwarddeclared.h include(externaltests.pri) - -win32:CONFIG += insignificant_test # QTBUG-24160 -- cgit v1.2.3 From 1741f6890c9ad51c7541fff8fed450c8c4da9654 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 15 Mar 2012 14:08:54 +0100 Subject: UTF8-Codec test: Fix compilation with g++/C++0X. Change-Id: I704f8d1b07ca371c36e4eecc52c80ac783e3da3c Reviewed-by: Thiago Macieira --- tests/auto/corelib/codecs/utf8/tst_utf8.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/codecs/utf8/tst_utf8.cpp b/tests/auto/corelib/codecs/utf8/tst_utf8.cpp index e07b7cb239..dd6774e101 100644 --- a/tests/auto/corelib/codecs/utf8/tst_utf8.cpp +++ b/tests/auto/corelib/codecs/utf8/tst_utf8.cpp @@ -322,7 +322,7 @@ void tst_Utf8::nonCharacters_data() // U+FDD0 through U+FDEF for (int i = 0; i < 16; ++i) { - char utf8[] = { 0357, 0267, 0220 + i, 0 }; + char utf8[] = { char(0357), char(0267), char(0220 + i), 0 }; QString utf16 = QChar(0xfdd0 + i); QTest::newRow(qPrintable(QString::number(0xfdd0 + i, 16))) << QByteArray(utf8) << utf16; } @@ -331,10 +331,10 @@ void tst_Utf8::nonCharacters_data() for (uint plane = 1; plane <= 16; ++plane) { for (uint lower = 0xfffe; lower < 0x10000; ++lower) { uint ucs4 = (plane << 16) | lower; - char utf8[] = { 0xf0 | uchar(ucs4 >> 18), - 0x80 | (uchar(ucs4 >> 12) & 0x3f), - 0x80 | (uchar(ucs4 >> 6) & 0x3f), - 0x80 | (uchar(ucs4) & 0x3f), + char utf8[] = { char(0xf0 | uchar(ucs4 >> 18)), + char(0x80 | (uchar(ucs4 >> 12) & 0x3f)), + char(0x80 | (uchar(ucs4 >> 6) & 0x3f)), + char(0x80 | (uchar(ucs4) & 0x3f)), 0 }; ushort utf16[] = { QChar::highSurrogate(ucs4), QChar::lowSurrogate(ucs4), 0 }; -- cgit v1.2.3 From f6ca63f896b5f9a330ff497aebff6943653dc35d Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Tue, 28 Feb 2012 23:41:31 +0100 Subject: QSqlTableModel::setData()/setRecord(): fix incorrect row For OnFieldChange and OnRowChange, before submitting new changes, setData() and setRecord() attempt to submit pending changes and revert them upon failure. However, they fail to consider that reverting pending insertions removes rows from the model. As a result, the new change can be applied to a row higher than intended. One possible solution would be to adjust the targetted index for the removed rows, so that the intended row is affected by the new change. But this still causes the strange editing experience as rows jump up just as they are being edited. It does not seem right in the first place for the model to initiate reverting changes. It should be up to the application to decide what to do when data cannot be committed. In particular, setData() and setRecord() should not have the side effect of reverting already pending changes. The chosen solution is simply to refuse new changes that don't make sense for the edit strategy. For OnFieldChange, flag() will indicate read-only when editing is blocked by a pending change. Since setData() and setRecord() submit data immediately for OnFieldChange, it no longer makes sense to resubmit changes automatically before a new change. For OnRowChange, setData() keeps the behavior of automatically submitting a pending row before starting on a new row. This is historical behavior and is probably motivated by the fact that QTableView does not automatically call submit() when editing leaves a row. The obvious shortcoming of this is that the last row to be edited will not be submitted automatically. It also prevents us from flagging rows other than the pending row as read-only. For OnRowChange, setRecord(), being row-oriented by nature, should submit the change immediately rather than waiting for the next call to setRecord(). This makes setRecord() consistent with insertRecord(). Change-Id: Icb4019d8b7c53a7ee48f8121a7a525e8bc35d523 Reviewed-by: Honglei Zhang --- .../models/qsqltablemodel/tst_qsqltablemodel.cpp | 72 ++++++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp index 7dcc109cdc..bb1131655d 100644 --- a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp @@ -83,6 +83,8 @@ private slots: void setRecord(); void insertRow_data() { generic_data_with_strategies(); } void insertRow(); + void insertRowFailure_data() { generic_data_with_strategies(); } + void insertRowFailure(); void insertRecord_data() { generic_data(); } void insertRecord(); void insertMultiRecords_data() { generic_data(); } @@ -161,7 +163,8 @@ void tst_QSqlTableModel::dropTestTables() << qTableName("test4", __FILE__) << qTableName("emptytable", __FILE__) << qTableName("bigtable", __FILE__) - << qTableName("foo", __FILE__); + << qTableName("foo", __FILE__) + << qTableName("pktest", __FILE__); if (testWhiteSpaceNames(db.driverName())) tableNames << qTableName("qtestw hitespace", db.driver()); @@ -197,6 +200,8 @@ void tst_QSqlTableModel::createTestTables() QString qry = "create table " + qTableName("qtestw hitespace", db.driver()) + " ("+ db.driver()->escapeIdentifier("a field", QSqlDriver::FieldName) + " int)"; QVERIFY_SQL( q, exec(qry)); } + + QVERIFY_SQL( q, exec("create table "+qTableName("pktest", __FILE__)+"(id int not null primary key, a varchar(20))")); } } @@ -414,7 +419,7 @@ void tst_QSqlTableModel::setRecord() model.submit(); else { // dataChanged() emitted by selectRow() as well as setRecord() - if ((QSqlTableModel::EditStrategy)submitpolicy == QSqlTableModel::OnFieldChange) + if ((QSqlTableModel::EditStrategy)submitpolicy != QSqlTableModel::OnManualSubmit) QCOMPARE(spy.count(), 2); else QCOMPARE(spy.count(), 1); @@ -541,6 +546,65 @@ void tst_QSqlTableModel::insertRow() QCOMPARE(model.data(model.index(3, 2)).toInt(), 2); } +void tst_QSqlTableModel::insertRowFailure() +{ + QFETCH(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + QFETCH(int, submitpolicy_i); + QSqlTableModel::EditStrategy submitpolicy = (QSqlTableModel::EditStrategy) submitpolicy_i; + CHECK_DATABASE(db); + + QSqlTableModel model(0, db); + model.setTable(qTableName("pktest", __FILE__)); + model.setEditStrategy(submitpolicy); + + QSqlRecord values = model.record(); + values.setValue(0, 42); + values.setGenerated(0, true); + values.setValue(1, QString("blah")); + values.setGenerated(1, true); + + // populate 1 row + QVERIFY_SQL(model, insertRecord(0, values)); + QVERIFY_SQL(model, submitAll()); + QVERIFY_SQL(model, select()); + QCOMPARE(model.rowCount(), 1); + QCOMPARE(model.data(model.index(0, 0)).toInt(), 42); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("blah")); + + // primary key conflict will succeed in model but fail in database + QVERIFY_SQL(model, insertRow(0)); + QVERIFY_SQL(model, setData(model.index(0, 0), 42)); + QVERIFY_SQL(model, setData(model.index(0, 1), "conflict")); + QFAIL_SQL(model, submitAll()); + + // failed insert is still cached + QCOMPARE(model.rowCount(), 2); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("conflict")); + QCOMPARE(model.data(model.index(1, 1)).toString(), QString("blah")); + + // cached insert affects subsequent operations + values.setValue(1, QString("spam")); + if (submitpolicy != QSqlTableModel::OnManualSubmit) { + QFAIL_SQL(model, setData(model.index(1, 1), QString("eggs"))); + QCOMPARE(model.data(model.index(1, 1)).toString(), QString("blah")); + QFAIL_SQL(model, setRecord(1, values)); + QCOMPARE(model.data(model.index(1, 1)).toString(), QString("blah")); + } else { + QVERIFY_SQL(model, setData(model.index(1, 1), QString("eggs"))); + QCOMPARE(model.data(model.index(1, 1)).toString(), QString("eggs")); + QVERIFY_SQL(model, setRecord(1, values)); + QCOMPARE(model.data(model.index(1, 1)).toString(), QString("spam")); + } + + // restore empty table + model.revertAll(); + QVERIFY_SQL(model, removeRow(0)); + QVERIFY_SQL(model, submitAll()); + QVERIFY_SQL(model, select()); + QCOMPARE(model.rowCount(), 0); +} + void tst_QSqlTableModel::insertRecord() { QFETCH(QString, dbName); @@ -1026,7 +1090,7 @@ void tst_QSqlTableModel::isDirty() QSqlRecord newvals = model.record(0); newvals.setValue(1, QString("sam i am")); newvals.setGenerated(1, true); - if (submitpolicy != QSqlTableModel::OnFieldChange) { + if (submitpolicy == QSqlTableModel::OnManualSubmit) { // setRecord() followed by revertAll() QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); QVERIFY_SQL(model, setRecord(0, newvals)); @@ -1054,7 +1118,7 @@ void tst_QSqlTableModel::isDirty() QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); QVERIFY_SQL(model, setRecord(0, newvals)); QCOMPARE(model.data(model.index(0, 1)).toString(), QString("sam i am")); - if (submitpolicy != QSqlTableModel::OnFieldChange) { + if (submitpolicy == QSqlTableModel::OnManualSubmit) { QVERIFY_SQL(model, isDirty()); QVERIFY_SQL(model, isDirty(model.index(0, 1))); } -- cgit v1.2.3 From 3d7cec6577fa32fb6036b346db57c53e38ea2ffd Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Wed, 29 Feb 2012 01:51:23 +0100 Subject: QSqlTableModel: disallow insert if changes are pending For OnFieldChange and OnRowChange, inserting rows should not be allowed if there are pending changes in cache. Change-Id: Ia794332959a35a1de87e798ba1a74ace3dfae68f Reviewed-by: Honglei Zhang --- tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp index bb1131655d..0bdcb3bce6 100644 --- a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp @@ -590,11 +590,15 @@ void tst_QSqlTableModel::insertRowFailure() QCOMPARE(model.data(model.index(1, 1)).toString(), QString("blah")); QFAIL_SQL(model, setRecord(1, values)); QCOMPARE(model.data(model.index(1, 1)).toString(), QString("blah")); + QFAIL_SQL(model, insertRow(2)); + QCOMPARE(model.rowCount(), 2); } else { QVERIFY_SQL(model, setData(model.index(1, 1), QString("eggs"))); QCOMPARE(model.data(model.index(1, 1)).toString(), QString("eggs")); QVERIFY_SQL(model, setRecord(1, values)); QCOMPARE(model.data(model.index(1, 1)).toString(), QString("spam")); + QVERIFY_SQL(model, insertRow(2)); + QCOMPARE(model.rowCount(), 3); } // restore empty table -- cgit v1.2.3 From 108748404beb607538ea965a21fa932d275eecdd Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Tue, 13 Mar 2012 01:28:35 +0100 Subject: QSqlTableModel::setData(): no longer autosubmit for OnRowChange The model can never do a good job of knowing when user moves to a new row in the view. Faking it by detecting when another row is changed was not a good solution because it cannot detect when the last edited row is left. Either the view should automatically submit when the user leaves a row or the application should provide a way to submit. This change made it possible to reuse the logic of flags() in setData(). Change-Id: I2550e5b113bceba1a852fc21203babeca07c5748 Reviewed-by: Honglei Zhang --- .../tst_qsqlrelationaltablemodel.cpp | 2 ++ .../sql/models/qsqltablemodel/tst_qsqltablemodel.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/sql/models/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp b/tests/auto/sql/models/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp index ce0d8db1fd..05d84383ae 100644 --- a/tests/auto/sql/models/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp +++ b/tests/auto/sql/models/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp @@ -1537,7 +1537,9 @@ void tst_QSqlRelationalTableModel::relationOnFirstColumn() //modify the model data QVERIFY_SQL(model, setData(model.index(0, 0), 40)); + QVERIFY_SQL(model, submit()); QVERIFY_SQL(model, setData(model.index(1, 0), 50)); + QVERIFY_SQL(model, submit()); QVERIFY_SQL(model, setData(model.index(2, 0), 30)); //verify the data after modificaiton diff --git a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp index 0bdcb3bce6..8bc71257e3 100644 --- a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp @@ -1067,6 +1067,26 @@ void tst_QSqlTableModel::isDirty() QFAIL_SQL(model, isDirty(model.index(0, 1))); } + if (submitpolicy == QSqlTableModel::OnRowChange) { + // dirty row must block change on other rows + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QVERIFY(model.rowCount() > 1); + QVERIFY_SQL(model, setData(model.index(0, 1), QString("sam i am"))); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("sam i am")); + QVERIFY_SQL(model, isDirty()); + QVERIFY_SQL(model, isDirty(model.index(0, 1))); + QVERIFY(!(model.flags(model.index(1, 1)) & Qt::ItemIsEditable)); + QFAIL_SQL(model, setData(model.index(1, 1), QString("sam i am"))); + QFAIL_SQL(model, setRecord(1, model.record(1))); + QFAIL_SQL(model, insertRow(1)); + QFAIL_SQL(model, isDirty(model.index(1, 1))); + + model.revertAll(); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QFAIL_SQL(model, isDirty()); + QFAIL_SQL(model, isDirty(model.index(0, 1))); + } + // setData() followed by submitAll() QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); QVERIFY_SQL(model, setData(model.index(0, 1), QString("sam i am"))); -- cgit v1.2.3 From 26450fe6a6340b09b1e3fa49c35028aa15ef223f Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Thu, 15 Mar 2012 11:23:27 +0100 Subject: QSqlTableModel::removeRows() enforce edit strategy For OnFieldChange and OnRowChange, we don't want more than one row in the cache with uncommitted changes. This could happen if deletion in the database fails while other changes are pending. Chosen solution is to return false if other rows have pending changes. Also, we only allow 1 row removed at a time. Updated test, changes and documentation. Change-Id: I68baf6d221789b4754e891535070011c759a2155 Reviewed-by: Honglei Zhang --- tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp index 8bc71257e3..afe2c59144 100644 --- a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp @@ -592,6 +592,8 @@ void tst_QSqlTableModel::insertRowFailure() QCOMPARE(model.data(model.index(1, 1)).toString(), QString("blah")); QFAIL_SQL(model, insertRow(2)); QCOMPARE(model.rowCount(), 2); + QFAIL_SQL(model, removeRow(1)); + QCOMPARE(model.rowCount(), 2); } else { QVERIFY_SQL(model, setData(model.index(1, 1), QString("eggs"))); QCOMPARE(model.data(model.index(1, 1)).toString(), QString("eggs")); @@ -599,6 +601,8 @@ void tst_QSqlTableModel::insertRowFailure() QCOMPARE(model.data(model.index(1, 1)).toString(), QString("spam")); QVERIFY_SQL(model, insertRow(2)); QCOMPARE(model.rowCount(), 3); + QVERIFY_SQL(model, removeRow(1)); + QCOMPARE(model.rowCount(), 3); } // restore empty table @@ -795,8 +799,10 @@ void tst_QSqlTableModel::removeRows() QVERIFY(!model.removeRows(1, 0)); // zero count QVERIFY(!model.removeRows(5, 1)); // past end (DOESN'T causes a beforeDelete to be emitted) QVERIFY(!model.removeRows(1, 0, model.index(2, 0))); // can't pass a valid modelindex + QFAIL_SQL(model, removeRows(0, 2)); // more than 1 row on OnFieldChange - QVERIFY_SQL(model, removeRows(0, 2)); + QVERIFY_SQL(model, removeRows(0, 1)); + QVERIFY_SQL(model, removeRows(1, 1)); QCOMPARE(beforeDeleteSpy.count(), 2); QVERIFY(beforeDeleteSpy.at(0).at(0).toInt() == 0); QVERIFY(beforeDeleteSpy.at(1).at(0).toInt() == 1); @@ -1079,6 +1085,7 @@ void tst_QSqlTableModel::isDirty() QFAIL_SQL(model, setData(model.index(1, 1), QString("sam i am"))); QFAIL_SQL(model, setRecord(1, model.record(1))); QFAIL_SQL(model, insertRow(1)); + QFAIL_SQL(model, removeRow(1)); QFAIL_SQL(model, isDirty(model.index(1, 1))); model.revertAll(); -- cgit v1.2.3 From 8a811865ab03bc7e30c8f6f52c0a61c5ae76191d Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Mon, 12 Mar 2012 18:46:21 +0000 Subject: Fix QDnsLookup autotest failure in CI environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The DNS server can legitimately include NS and A records for the authoritative name server in addition to the DNS records that were requested. These are now ignored when checking the reply (we only check results that match the query, rather than failing if a result is for a different host name than the query). Task-number: QTBUG-24698 Change-Id: I327f31d58cdca50c7df6b32b275d7f28b56405f0 Reviewed-by: Jeremy Lainé Reviewed-by: Robin Burchell --- tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp b/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp index 249ccd3d75..c1400b82af 100644 --- a/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp +++ b/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp @@ -159,8 +159,9 @@ void tst_QDnsLookup::lookup() const QString hostName = cname.isEmpty() ? domain : cname; QStringList addresses; foreach (const QDnsHostAddressRecord &record, lookup.hostAddressRecords()) { - QCOMPARE(record.name(), hostName); - addresses << record.value().toString().toLower(); + //reply may include A & AAAA records for nameservers, ignore them and only look at records matching the query + if (record.name() == hostName) + addresses << record.value().toString().toLower(); } addresses.sort(); QCOMPARE(addresses.join(" "), host); @@ -176,8 +177,9 @@ void tst_QDnsLookup::lookup() // name servers QStringList nameServers; foreach (const QDnsDomainNameRecord &record, lookup.nameServerRecords()) { - QCOMPARE(record.name(), domain); - nameServers << record.value(); + //reply may include NS records for authoritative nameservers, ignore them and only look at records matching the query + if (record.name() == domain) + nameServers << record.value(); } nameServers.sort(); QCOMPARE(nameServers.join(" "), ns); -- cgit v1.2.3 From 1e4f0351583ee9283d7cea4c4a00b8c5f60a98e9 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Fri, 2 Mar 2012 11:18:43 +0000 Subject: Revert "Disable 'check' target generation for network autotests for Windows." Too broad disabling, will disable more selectively This reverts commit 3efb0d50e590f6a1e8d67d0136a648cd3b97c37d. Change-Id: I29e25816646194b6a4b7d8ff69e0c0d074ac2a19 Reviewed-by: Sergio Ahumada Reviewed-by: Rohan McGovern --- tests/auto/auto.pro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 124af19799..a23c3d672a 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -19,8 +19,8 @@ cross_compile: SUBDIRS -= tools !contains(QT_CONFIG, opengl): SUBDIRS -= opengl !unix|embedded|!contains(QT_CONFIG, dbus): SUBDIRS -= dbus -# disable 'make check' on Mac OS X and Windows for the following subdirs for the time being -mac|win32 { +# disable 'make check' on Mac OS X for the following subdirs for the time being +mac { network.CONFIG += no_check_target } -- cgit v1.2.3