diff options
Diffstat (limited to 'old/plugins/qtuitest_widgets/qtwidgets')
63 files changed, 8161 insertions, 0 deletions
diff --git a/old/plugins/qtuitest_widgets/qtwidgets/DESCRIPTION b/old/plugins/qtuitest_widgets/qtwidgets/DESCRIPTION new file mode 100644 index 0000000..5735373 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/DESCRIPTION @@ -0,0 +1 @@ +QtUitest plugin containing logic for interacting with Qt widgets. diff --git a/old/plugins/qtuitest_widgets/qtwidgets/qtwidgets.pro b/old/plugins/qtuitest_widgets/qtwidgets/qtwidgets.pro new file mode 100644 index 0000000..986f04e --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/qtwidgets.pro @@ -0,0 +1,95 @@ +SOURCES += \ + testabstractbutton.cpp \ + testabstractitemview.cpp \ + testabstractspinbox.cpp \ + testcalendarwidget.cpp \ + testcheckbox.cpp \ + testcombobox.cpp \ + testdateedit.cpp \ + testdatetimeedit.cpp \ + testdockwidget.cpp \ + testfactory.cpp \ + testgenericcheckwidget.cpp \ + testgenerictextwidget.cpp \ + testgroupbox.cpp \ + testheaderview.cpp \ + testignore.cpp \ + testlabel.cpp \ + testlineedit.cpp \ + testlistview.cpp \ + testmenu.cpp \ + testmenubar.cpp \ + testpushbutton.cpp \ + testtabbar.cpp \ + testtext.cpp \ + testtextedit.cpp \ + testtimeedit.cpp \ + testtoolbar.cpp \ + testtreeview.cpp \ + testtreewidget.cpp \ + testgenericinputmethod.cpp + +HEADERS += \ + testabstractbutton.h \ + testabstractitemview.h \ + testabstractspinbox.h \ + testcalendarwidget.h \ + testcheckbox.h \ + testcombobox.h \ + testdateedit.h \ + testdatetimeedit.h \ + testdockwidget.h \ + testfactory.h \ + testgenericcheckwidget.h \ + testgenerictextwidget.h \ + testgroupbox.h \ + testheaderview.h \ + testignore.h \ + testlabel.h \ + testlineedit.h \ + testlistview.h \ + testwidgetslog.h \ + testmenu.h \ + testmenubar.h \ + testpushbutton.h \ + testtabbar.h \ + testtext.h \ + testtextedit.h \ + testtimeedit.h \ + testtoolbar.h \ + testtreeview.h \ + testtreewidget.h \ + testgenericinputmethod.h + +TEMPLATE=lib +CONFIG+=plugin +VPATH+=$$PWD +INCLUDEPATH+=$$PWD +TARGET=qtwidgets +TARGET=$$qtLibraryTarget($$TARGET) + +include($$SRCROOT/libqtuitest/libqtuitest.pri) + + +target.path=$$[QT_INSTALL_PLUGINS]/qtuitest_widgets +unix:!symbian { + MOC_DIR=$$OUT_PWD/.moc + OBJECTS_DIR=$$OUT_PWD/.obj +} + +symbian { + TARGET.EPOCALLOWDLLDATA=1 + TARGET.CAPABILITY += AllFiles ReadDeviceData ReadUserData SwEvent WriteUserData NetworkServices + MOC_DIR=$$OUT_PWD/moc + OBJECTS_DIR=$$OUT_PWD/obj + LIBS+= -lws32 -leuser -lcone +} +INSTALLS += target + +contains(QT_CONFIG, webkit) { + QT+=webkit + SOURCES+=testwebview.cpp + HEADERS+=testwebview.h +} + + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testabstractbutton.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testabstractbutton.cpp new file mode 100644 index 0000000..379f92d --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testabstractbutton.cpp @@ -0,0 +1,195 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testabstractbutton.h" +#include "testwidgetslog.h" + +#include <QAbstractButton> +#include <QTimer> +#include <QTime> +#include <QPointer> +#include <QStyleOptionButton> + +namespace QtUiTest { + +TestAbstractButton::TestAbstractButton(QObject *_q) + : TestGenericTextWidget(_q), q(qobject_cast<QAbstractButton*>(_q)), + m_pressed(false) +{ + if (!QtUiTest::connectFirst(q, SIGNAL(pressed()), this, SIGNAL(activated()))) + Q_ASSERT(false); + if (!connect(q, SIGNAL(toggled(bool)), this, SLOT(on_toggled(bool)))) + Q_ASSERT(false); +} + +void TestAbstractButton::on_toggled(bool state) +{ emit stateChanged(state); } + +Qt::CheckState TestAbstractButton::checkState() const +{ return q->isChecked() ? Qt::Checked : Qt::Unchecked; } + +bool TestAbstractButton::setCheckState(Qt::CheckState state) +{ + if (state == checkState()) return true; + if (!q->isCheckable()) { + QtUiTest::setErrorString("This abstract button is not checkable."); + return false; + } + bool ret = activate(QtUiTest::NoOptions); + TestWidgetsLog() << "activated:" << ret; + if (ret && (state != checkState()) && !QtUiTest::waitForSignal(q, SIGNAL(toggled(bool)))) { + QtUiTest::setErrorString("Successfully activated button, but check state did not change " + "to expected value."); + return false; + } + TestWidgetsLog() << "state:" << ret; + return ret; +} + +bool TestAbstractButton::activate() +{ + return activate((QtUiTest::InputOption)0); +} + +bool TestAbstractButton::activate(QtUiTest::InputOption opt) +{ + if (QtUiTest::mousePreferred()) { + int t; + m_pressed = false; + + QPoint pos; + if (q->isCheckable()) { + QStyle const* style = q->style(); + QStyleOptionButton opt; + opt.initFrom(q); + QRect rect = style->subElementRect( QStyle::SE_CheckBoxIndicator, &opt, q); + pos = rect.center(); + } else { + pos = q->rect().center(); + } + + QRegion region = QRegion(pos.x()-1, pos.y()-1, 3, 3); + for (t = 0; t < 2; ++t) { + ensureVisibleRegion(region); + QtUiTest::mousePress(mapToGlobal(pos), Qt::LeftButton, opt); + QtUiTest::waitForSignal(q, SIGNAL(pressed())); + if (q->isDown()) + break; + } + if (!q->isDown()) { + qWarning("Button did not react to mouse press."); + QtUiTest::mouseRelease(mapToGlobal(pos), Qt::LeftButton, opt); + return false; + } + if (t > 0) + qWarning("Button did not react to mouse press on first try."); + + QtUiTest::mouseRelease(mapToGlobal(pos), Qt::LeftButton, opt); + return true; + } else { + Qt::Key key = Qt::Key(QtUiTest::Key_ActivateButton); + Qt::KeyboardModifiers mod = 0; + + if (q->focusPolicy() == Qt::NoFocus) { + /* Handle buttons which need to be activated by a shortcut */ + QKeySequence ks = q->shortcut(); + TestWidgetsLog() << "Can't give focus to button; need to use shortcut" + << ks.toString(); + if (ks.isEmpty()) { + QtUiTest::setErrorString("Button has NoFocus policy set and does not appear " + "to have any shortcut set. Therefore, it is impossible to activate " + "using only the keyboard."); + return false; + } + + int key_and_mod = ks[0]; + mod = QFlag(key_and_mod & (0xfe000000)); + key = Qt::Key(key_and_mod & (0x01ffffff)); + } + else { + if (!hasFocus()) setFocus(); + if (!hasFocus()) return false; + } + + QPointer<QObject> safeQ(q); + + if (!QtUiTest::keyClick(q, SIGNAL(pressed()), key, mod, opt)) + return false; + + if (safeQ && q->isDown() && !QtUiTest::waitForSignal(q, SIGNAL(released()))) { + QtUiTest::setErrorString("Button did not become released after key click"); + return false; + } + return true; + } + return false; +} + +QString TestAbstractButton::labelText() const +{ + QString ret = text(); + if (ret.isEmpty()) + return ret; + + QObject *w = parent(); + while (w) { + QtUiTest::Widget *qw = qtuitest_cast<QtUiTest::Widget*>(w); + QtUiTest::LabelWidget *lw = qtuitest_cast<QtUiTest::LabelWidget*>(w); + if (lw) { + if (!lw->labelText().isEmpty()) { + ret.prepend(lw->labelText() + "/"); + break; + } + } + w = qw->parent(); + } + return ret; +} + +QObject* TestAbstractButton::buddy() const +{ + return q; +} + +bool TestAbstractButton::canWrap(QObject *o) +{ return qobject_cast<QAbstractButton*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testabstractbutton.h b/old/plugins/qtuitest_widgets/qtwidgets/testabstractbutton.h new file mode 100644 index 0000000..687c56e --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testabstractbutton.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTABSTRACTBUTTON_H +#define TESTABSTRACTBUTTON_H + +#include "testgenerictextwidget.h" + +class QAbstractButton; + +namespace QtUiTest { + +class TestAbstractButton : public TestGenericTextWidget, + public QtUiTest::CheckWidget, + public QtUiTest::ActivateWidget, + public QtUiTest::LabelWidget +{ + Q_OBJECT + Q_INTERFACES( + QtUiTest::CheckWidget + QtUiTest::ActivateWidget + QtUiTest::LabelWidget) + +public: + TestAbstractButton(QObject*); + + virtual Qt::CheckState checkState() const; + virtual bool setCheckState(Qt::CheckState); + virtual bool activate(); + + virtual QString labelText() const; + virtual QObject* buddy() const; + + static bool canWrap(QObject*); + +protected: + bool activate(QtUiTest::InputOption); + +signals: + void stateChanged(int); + void activated(); + +private slots: + void on_toggled(bool); + +private: + QAbstractButton *q; + bool m_pressed; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testabstractitemview.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testabstractitemview.cpp new file mode 100644 index 0000000..ccb1371 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testabstractitemview.cpp @@ -0,0 +1,475 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testabstractitemview.h" +#include "testwidgetslog.h" + +#include <QListView> +#include <QTimer> +#include <QScrollBar> +#include <QComboBox> +#include <QGraphicsProxyWidget> +#include <QGraphicsView> + +#include <qtuitestnamespace.h> + +namespace QtUiTest { + +TestAbstractItemView::TestAbstractItemView(QObject *_q) + : TestWidget(_q), q(qobject_cast<QAbstractItemView*>(_q)) +{ + if (q && q->parent() && qobject_cast<QComboBox*>(q->parent()->parent())) { + // The test object of the combobox will handle recording + return; + } + + QtUiTest::connectFirst(q, SIGNAL(activated(QModelIndex)), + this, SLOT(on_activated(QModelIndex))); + QtUiTest::connectFirst(q, SIGNAL(pressed(QModelIndex)), + this, SLOT(on_activated(QModelIndex))); +} + +void TestAbstractItemView::on_activated(QModelIndex const& ind) +{ + // Timer discourages duplicate signal emission. + if (m_lastActivatedTimer.elapsed() > 500 || m_lastActivatedTimer.elapsed() < 0) { + TestWidgetsLog() << "emit selected" << ind.data().toString(); + emit selected(printable(ind.data().toString())); + m_lastActivatedTimer.start(); + } else { + TestWidgetsLog() << "Would emit selected" << ind.data().toString() + << "except we have already done that recently."; + } +} + +QString TestAbstractItemView::selectedText() const +{ + TestWidgetsLog(); + return printable(q->currentIndex().data().toString()); +} + +QString TestAbstractItemView::text() const +{ + TestWidgetsLog(); + return list().join("\n"); +} + +QStringList TestAbstractItemView::list() const +{ + class QModelListGetter : public QModelViewIterator<QAbstractItemView> + { + public: + QModelListGetter(QAbstractItemView *view) + : QModelViewIterator<QAbstractItemView>(view) {}; + + QStringList getList() { + list.clear(); + iterate(view()->rootIndex()); + return list; + } + protected: + virtual void visit(QModelIndex const &index) + { list << itemForIndex(index); } + + QStringList list; + }; + + return QModelListGetter(q).getList(); +} + +QModelIndex TestAbstractItemView::indexForItem(QString const &item) const +{ + QModelIndex ret; + + class QModelIndexGetter : public QModelViewIterator<QAbstractItemView> + { + public: + QModelIndexGetter(QAbstractItemView *view, QString const &item) + : QModelViewIterator<QAbstractItemView>(view), matches(0), m_item(item) {}; + QModelIndex index; + int matches; + + protected: + void visit(QModelIndex const &idx) { + + if (itemForIndex(idx) == m_item) { + ++matches; + index = idx; + } + } + private: + QString m_item; + }; + + QModelIndexGetter indexGetter(q, item); + indexGetter.iterate(q->rootIndex()); + + // No matching item + if (!indexGetter.matches) { + TestWidgetsLog() << "no matching item for" << item; + } + + // More than one matching item + else if (indexGetter.matches > 1) { + qWarning("QtUitest: more than one item matches '%s' in item view", qPrintable(item)); + TestWidgetsLog() << indexGetter.matches << "matches for" << item; + } + + else + ret = indexGetter.index; + + return ret; +} + +QModelIndex TestAbstractItemView::indexFromList(QVariantList const &list) const +{ + QVariantList indexList = list; + QModelIndex ret; + if (list.size() > 1) { + int column = indexList.takeLast().toInt(); + int row = indexList.takeLast().toInt(); + ret = q->model()->index(row, column, indexFromList(indexList)); + } + return ret; +} + + +QVariantList TestAbstractItemView::listFromIndex(QModelIndex const &index) const +{ + QVariantList ret; + if (index.parent().isValid()) { + ret << listFromIndex(index.parent()); + } + if (index.isValid()) { + ret << index.row() << index.column(); + } + + return ret; +} + +QRect TestAbstractItemView::visualRect(QString const &item) const +{ + QRect ret; + + QModelIndex index = indexForItem(item); + + if (index.isValid()) { + ret = q->visualRect(index); + ret.moveTopLeft(q->mapFromGlobal(q->viewport()->mapToGlobal(ret.topLeft()))); + } + + return ret; +} + +bool TestAbstractItemView::isMultiSelection() const +{ return (q->selectionMode() > QAbstractItemView::SingleSelection); } + +bool TestAbstractItemView::canSelect(QString const &item) const +{ + if (q->selectionMode() == QAbstractItemView::NoSelection) + return false; + + return list().contains(item); +} + +bool TestAbstractItemView::canSelectMulti(QStringList const &items) const +{ + if (!isMultiSelection()) + return false; + + QSet<QString> itemSet = items.toSet(); + return ((itemSet & list().toSet()) == itemSet); +} + +bool TestAbstractItemView::select(QString const &item) +{ + TestWidgetsLog() << item; + + if (!canSelect(item)) { + TestWidgetsLog() << "can't select" << item; + return false; + } + + if (!QtUiTest::mousePreferred() && (!setFocus() || !hasFocus())) { + QtUiTest::setErrorString("Couldn't give focus to item view"); + return false; + } + + return select(indexForItem(item)); +} + +bool TestAbstractItemView::select(QModelIndex const &index) +{ + if (QtUiTest::mousePreferred()) { + if (!ensureVisible(index)) { + TestWidgetsLog() << "couldn't make item visible"; + return false; + } + QPoint pos = q->visualRect(index).center(); + TestWidgetsLog() << "after ensureVisible, item is at" << pos; + + while (q->parentWidget()) { + // Workaround to allow selection from QComboBoxes embedded in a QGraphicsView + QGraphicsProxyWidget *gpw = q->parentWidget()->graphicsProxyWidget(); + if (!gpw) break; + QGraphicsScene *scene = gpw->scene(); + if (!scene) break; + QGraphicsView *view = scene->views().first(); + if (!view) break; + QtUiTest::mouseClick(view->mapToGlobal(view->mapFromScene(gpw->mapToScene(pos))), Qt::LeftButton); + return true; + } + + QtUiTest::mouseClick(q->viewport()->mapToGlobal(pos), Qt::LeftButton); + return true; + + } else { + // Consume pending key events, if any. + while (QtUiTest::waitForEvent(q, QEvent::KeyRelease, 200, Qt::QueuedConnection)) + {} + + const int maxtries = 100; + + // Move vertically + int desiredY = q->visualRect(index).center().y(); + int currentY = q->visualRect(q->currentIndex()).center().y(); + + for (int i = 0; i < maxtries && desiredY != currentY; ++i) { + Qt::Key key; + if (desiredY < currentY) { + key = Qt::Key_Up; + TestWidgetsLog() << "Up (desired=" << desiredY << ", current=" << currentY << ")"; + } else { + key = Qt::Key_Down; + TestWidgetsLog() << "Down (desired=" << desiredY << ", current=" << currentY << ")"; + } + if (!QtUiTest::keyClick(q, key)) return false; + desiredY = q->visualRect(index).center().y(); + currentY = q->visualRect(q->currentIndex()).center().y(); + } + if (desiredY != currentY) { + QtUiTest::setErrorString(QString( + "Up/down keys failed to move highlight vertically; desired position %1, " + "current position %2").arg(desiredY).arg(currentY)); + return false; + } + + // Move horizontally + int desiredX = q->visualRect(index).center().x(); + int currentX = q->visualRect(q->currentIndex()).center().x(); + + for (int i = 0; i < maxtries && desiredX != currentX; ++i) { + Qt::Key key; + if (desiredX < currentX) { + key = Qt::Key_Left; + TestWidgetsLog() << "Left (desired=" << desiredX << ", current=" << currentX << ")"; + } else { + key = Qt::Key_Right; + TestWidgetsLog() << "Right (desired=" << desiredX << ", current=" << currentX << ")"; + } + if (!QtUiTest::keyClick(q, key)) return false; + desiredX = q->visualRect(index).center().x(); + currentX = q->visualRect(q->currentIndex()).center().x(); + } + if (desiredX != currentX) { + QtUiTest::setErrorString(QString( + "Left/right keys failed to move highlight horizontally; desired position %1, " + "current position %2").arg(desiredX).arg(currentX)); + return false; + } + + TestWidgetsLog() << "hit activate key"; + if (!QtUiTest::keyClick(q, QtUiTest::Key_Activate)) return false; + return true; + } + + return false; +} + +bool TestAbstractItemView::selectMulti(QStringList const &items) +{ + if (!canSelectMulti(items)) return false; + + TestWidgetsLog() << items; + + return false; +} + +bool TestAbstractItemView::selectIndex(QVariantList const &indexList) +{ + QModelIndex idx = indexFromList(indexList); + if (idx.isValid()) { + return select(idx); + } + else { + QtUiTest::setErrorString("Invalid index"); + return false; + } +} + +QVariantList TestAbstractItemView::selectedIndex() const +{ + return listFromIndex(q->currentIndex()); +} + +bool TestAbstractItemView::ensureVisible(QString const &item) +{ + return ensureVisible(indexForItem(item)); +} + +bool TestAbstractItemView::ensureVisible(QModelIndex const &index) +{ + QPoint p = q->visualRect(index).center(); + + if (q->viewport()->rect().contains(p)) { + TestWidgetsLog() << "item is already visible"; + return true; + } + + if (!QtUiTest::mousePreferred()) + return false; + + /* Figure out the points to click for scrolling in each direction */ + QScrollBar *vbar = q->verticalScrollBar(); + QScrollBar *hbar = q->horizontalScrollBar(); + QPoint up = vbar->mapToGlobal(QPoint(vbar->width()/2,5)); + QPoint down = vbar->mapToGlobal(QPoint(vbar->width()/2,vbar->height()-5)); + QPoint left = hbar->mapToGlobal(QPoint(5, hbar->height()/2)); + QPoint right = hbar->mapToGlobal(QPoint(hbar->width()-5,hbar->height()/2)); + + // While p is above rect... + while (p.y() < q->viewport()->rect().top()) { + if (!vbar->isVisible()) return false; + TestWidgetsLog() << "up" << "\nrect:" << rect() << "p:" << p; + QtUiTest::mouseClick(up); + waitForSignal(vbar, SIGNAL(valueChanged(int))); + p = q->visualRect(index).center(); + } + // While p is below rect... + while (p.y() > q->viewport()->rect().bottom()) { + if (!vbar->isVisible()) return false; + TestWidgetsLog() << "down" << "\nrect:" << rect() << "p:" << p; + QtUiTest::mouseClick(down); + waitForSignal(vbar, SIGNAL(valueChanged(int))); + p = q->visualRect(index).center(); + } + // While p is left of rect... + while (p.x() < q->viewport()->rect().left()) { + if (!hbar->isVisible()) return false; + TestWidgetsLog() << "left" << "\nrect:" << rect() << "p:" << p; + QtUiTest::mouseClick(left); + waitForSignal(hbar, SIGNAL(valueChanged(int))); + p = q->visualRect(index).center(); + } + // While p is right of rect... + while (p.x() > q->viewport()->rect().right()) { + if (!hbar->isVisible()) return false; + TestWidgetsLog() << "right" << "\nrect:" << rect() << "p:" << p; + QtUiTest::mouseClick(right); + waitForSignal(hbar, SIGNAL(valueChanged(int))); + p = q->visualRect(index).center(); + } + + if (!q->viewport()->rect().contains(p)) { + TestWidgetsLog() << "failed" << "\nrect:" << q->viewport()->rect() << "p:" << p; + return false; + } + + return true; +} + +bool TestAbstractItemView::canEnter(QVariant const& item) const +{ + bool ret = false; + QModelIndex ci = q->currentIndex(); + if (ci.isValid() && q->selectionMode() != QAbstractItemView::NoSelection && ci.flags() & Qt::ItemIsEditable) { + QWidget *indexWidget = q->indexWidget(ci); + if (!indexWidget) { + // FIXME: Should simulate correct events to enter edit mode + q->edit(ci); + indexWidget = q->indexWidget(ci); + } + InputWidget* iw = qtuitest_cast<InputWidget*>(indexWidget); + if (iw) { + ret = iw->canEnter(item); + // FIXME: Should simulate correct events to leave edit mode + q->setFocus(); + } else { + SelectWidget* sw = qtuitest_cast<SelectWidget*>(indexWidget); + if (sw) { + ret = sw->canSelect(item.toString()); + q->setFocus(); + } + } + } + return ret; +} + +bool TestAbstractItemView::enter(QVariant const& item, bool noCommit) +{ + bool ret = false; + QModelIndex ci = q->currentIndex(); + if (ci.isValid() && q->selectionMode() != QAbstractItemView::NoSelection && ci.flags() & Qt::ItemIsEditable) { + QWidget *indexWidget = q->indexWidget(ci); + if (!indexWidget) { + // FIXME: Should simulate correct events to enter edit mode + q->edit(ci); + indexWidget = q->indexWidget(ci); + } + InputWidget* iw = qtuitest_cast<InputWidget*>(indexWidget); + if (iw) { + ret = iw->enter(item, noCommit); + // FIXME: Should simulate correct events to leave edit mode + q->setFocus(); + } else { + SelectWidget* sw = qtuitest_cast<SelectWidget*>(indexWidget); + ret = sw->select(item.toString()); + q->setFocus(); + } + } + + return ret; +} + +bool TestAbstractItemView::canWrap(QObject* o) +{ return qobject_cast<QAbstractItemView*>(o); } + +} diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testabstractitemview.h b/old/plugins/qtuitest_widgets/qtwidgets/testabstractitemview.h new file mode 100644 index 0000000..b6a5ddb --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testabstractitemview.h @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTABSTRACTITEMVIEW_H +#define TESTABSTRACTITEMVIEW_H + +#include <testwidget.h> +#include <QAbstractItemView> +#include <QTime> + +const int QTUITEST_MAX_LIST=15000; + +namespace QtUiTest { + +class TestAbstractItemView : public TestWidget, + public QtUiTest::TextWidget, + public QtUiTest::ListWidget, + public QtUiTest::SelectWidget, + public QtUiTest::IndexedWidget +{ + Q_OBJECT + Q_INTERFACES( + QtUiTest::TextWidget + QtUiTest::ListWidget + QtUiTest::SelectWidget + QtUiTest::IndexedWidget) + +public: + TestAbstractItemView(QObject*); + + virtual QString text() const; + virtual QString selectedText() const; + + virtual QStringList list() const; + virtual QRect visualRect(QString const&) const; + virtual bool ensureVisible(QString const&); + + virtual bool canEnter(QVariant const&) const; + virtual bool enter(QVariant const&,bool); + + virtual bool isMultiSelection() const; + virtual bool canSelect(QString const&) const; + virtual bool canSelectMulti(QStringList const&) const; + virtual bool select(QString const&); + virtual bool selectMulti(QStringList const&); + + virtual bool selectIndex(QVariantList const&); + virtual QVariantList selectedIndex() const; + + static bool canWrap(QObject*); + +protected: + virtual QModelIndex indexForItem(QString const&) const; + virtual QModelIndex indexFromList(QVariantList const&) const; + virtual QVariantList listFromIndex(QModelIndex const&) const; + virtual bool ensureVisible(QModelIndex const&); + virtual bool select(QModelIndex const&); + +signals: + void selected(const QString&); + +private slots: + void on_activated(QModelIndex const&); + +private: + QAbstractItemView *q; + QTime m_lastActivatedTimer; +}; + +template <typename T> +class QModelViewIterator +{ +public: + QModelViewIterator(T* view) + : m_view(view), count(0) + {} + + virtual ~QModelViewIterator() + {} + + virtual void iterate(QModelIndex rootIndex = QModelIndex(), bool recurse=true) + { + QModelIndexList seen; + iterate(rootIndex, &seen, recurse, true); + } + +protected: + T* view() const + { return m_view; } + QAbstractItemModel* model() const + { return m_view->model(); } + + virtual void visit(QModelIndex const&) = 0; + virtual void overFlow() + { + QtUiTest::setErrorString("Maximum number of items exceeded"); + } + virtual bool isRowHidden(int, const QModelIndex&) + { + return false; + } + virtual QString itemForIndex(QModelIndex const& idx) const + { + return TestWidget::printable(idx.data().toString()); + } + +private: + void iterate(QModelIndex const &index, QModelIndexList *seen, bool recurse, bool isRoot=false) + { + if (++count > QTUITEST_MAX_LIST) { + overFlow(); + return; + } + + if (index.isValid()) { + visit(index); + (*seen) << index; + } + + for (int i = 0, max_i = model()->rowCount(index); i < max_i && count <= QTUITEST_MAX_LIST; ++i) { + if (isRowHidden(i, index)) { + continue; + } + for (int j = 0, max_j = model()->columnCount(index); + j < max_j && count <= QTUITEST_MAX_LIST; ++j) { + QModelIndex child; + if (model()->hasIndex(i, j, index)) { + child = model()->index(i, j, index); + } + if (child.isValid() && !seen->contains(child) && (isRoot || recurse)) { +#if 0 + /* Very verbose! */ + qDebug() << "child at (" << i << "," << j << ")" << child.data(); +#endif + iterate(child, seen, recurse); + } + } + } + } + + T *m_view; + int count; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testabstractspinbox.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testabstractspinbox.cpp new file mode 100644 index 0000000..3469667 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testabstractspinbox.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testabstractspinbox.h" +#include "testwidgetslog.h" + +#include <QPointer> +#include <QSpinBox> +#include <QValidator> +#include <QVariant> + +namespace QtUiTest { + +TestAbstractSpinBox::TestAbstractSpinBox(QObject *_q) + : TestGenericTextWidget(_q), q(qobject_cast<QAbstractSpinBox*>(_q)) +{ +//TestWidgetsLog(); +} + +bool TestAbstractSpinBox::canEnter(QVariant const& item) const +{ + if (!item.canConvert<QString>()) return false; + + int dontcare = 0; + QString text = item.toString(); + return (QValidator::Acceptable==q->validate(text, dontcare)); +} + +bool TestAbstractSpinBox::enter(QVariant const& item, bool noCommit) +{ + if (!canEnter(item)) return false; + if (!hasFocus() && !setFocus()) return false; + + using namespace QtUiTest; + + QPointer<QObject> safeThis = this; + if (!safeThis) { + setErrorString("Widget was destroyed while entering text."); + return false; + } + + InputWidget* iw = qtuitest_cast<InputWidget*>(inputProxy()); + TestWidgetsLog() << iw; + + //FIXME: This shouldn't be necessary + bool kt = q->keyboardTracking(); + q->setKeyboardTracking(true); + + //FIXME: Doesn't use mouse events... + bool ret = true; + + /* Use input method if available... */ + if (iw) { + ret = iw->canEnter(item) && iw->enter(item, noCommit); + } else { + //FIXME: Should clear existing text using keyClicks, not API + q->clear(); + /* ...otherwise, generate key clicks ourself */ + foreach (QChar c, item.toString()) { + TestWidgetsLog() << asciiToModifiers(c.toLatin1()); + keyClick( asciiToKey(c.toLatin1()), asciiToModifiers(c.toLatin1()) ); + } + } + + waitForSignal(q, SIGNAL(valueChanged(int))); + q->setKeyboardTracking(kt); + + if (!safeThis) { + setErrorString("Widget was destroyed while entering text."); + return false; + } + + if (mousePreferred()) { + return ret; + } + + if (!noCommit) { + keyClick(QtUiTest::Key_Activate); + } + + return ret; +} + +bool TestAbstractSpinBox::canWrap(QObject *o) +{ return qobject_cast<QAbstractSpinBox*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testabstractspinbox.h b/old/plugins/qtuitest_widgets/qtwidgets/testabstractspinbox.h new file mode 100644 index 0000000..1f3444e --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testabstractspinbox.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTABSTRACTSPINBOX_H +#define TESTABSTRACTSPINBOX_H + +#include "testgenerictextwidget.h" + +class QAbstractSpinBox; + +namespace QtUiTest { + +class TestAbstractSpinBox : public TestGenericTextWidget +{ + Q_OBJECT + +public: + TestAbstractSpinBox(QObject*); + + virtual bool canEnter(QVariant const&) const; + virtual bool enter(QVariant const&,bool); + + static bool canWrap(QObject*); + +private: + QAbstractSpinBox *q; +}; + +} +#endif diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testcalendarwidget.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testcalendarwidget.cpp new file mode 100644 index 0000000..68897c6 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testcalendarwidget.cpp @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testcalendarwidget.h" +#include "testwidgetslog.h" + +#include <qtuitestnamespace.h> + +#include <QAbstractItemView> +#include <QCalendarWidget> +#include <QMenu> +#include <QSpinBox> +#include <QToolButton> + +namespace QtUiTest { + +/* FIXME replace this with canSelect */ +QString const GetListRegExp = QString("QTUITEST_REGEX_"); + +TestCalendarWidget::TestCalendarWidget(QObject *_q) + : TestWidget(_q), q(qobject_cast<QCalendarWidget*>(_q)) +{} + +QStringList TestCalendarWidget::list() const +{ + QStringList ret; + QtUiTest::ListWidget *calendarView + = qtuitest_cast<QtUiTest::ListWidget*>( + q->findChild<QAbstractItemView*>()); + + if (!calendarView) { + return ret; + } + + ret = calendarView->list(); + + /* Append months */ + QStringList months; + for (int i = 1; i <= 12; ++i) { + months << QDate::longMonthName(i); + } + ret << months; + + /* Append years */ + /* FIXME replace this with canSelect() */ + ret << (GetListRegExp + "[0-9]{4}"); + + return ret; +} + +/* FIXME make this less of a hack. */ +QRect TestCalendarWidget::visualRect(QString const &item) const +{ + TestWidgetsLog() << item << "my geometry is" << geometry(); + + QRect ret; + + QAbstractItemView *view = q->findChild<QAbstractItemView*>(); + QtUiTest::ListWidget *calendarView + = qtuitest_cast<QtUiTest::ListWidget*>(view); + + if (!calendarView) { + return ret; + } + + ret = calendarView->visualRect(item); + if (!ret.isNull()) { + ret.moveTopLeft( q->mapFromGlobal( view->mapToGlobal(ret.topLeft()) ) ); + TestWidgetsLog() << item << "is a visible day at" << ret; + return ret; + } + + QToolButton *yearButton = 0; + QToolButton *monthButton = 0; + QSpinBox *yearSpin = q->findChild<QSpinBox*>(); + QMenu *monthMenu = 0; + + QList<QToolButton*> blist = q->findChildren<QToolButton*>(); + foreach(QToolButton *b, blist) { + if (!monthButton && (monthMenu = b->menu())) { + monthButton = b; + } + if (!b->menu()) { + yearButton = b; + } + } + TestWidgetsLog() << "monthButton" << monthButton << "yearButton" << yearButton; + TestWidgetsLog() << "item" << item << "monthMenu" << monthMenu; + + if (yearButton && yearButton->isVisible() && yearButton->text() == item) { + QPoint p = q->mapFromGlobal( yearButton->mapToGlobal(QPoint(yearButton->width()+5, yearButton->height()/2)) ); + ret = QRect(p.x() - 2, p.y() - 2, 5, 5); + TestWidgetsLog() << "click near yearbutton"; + } else if (yearSpin && yearSpin->isVisible() && yearSpin->value() == item.toInt()) { + TestWidgetsLog() << "confirm spinbox"; + QPoint p = q->mapFromGlobal( yearSpin->mapToGlobal(QPoint(yearSpin->width()+5, yearSpin->height()/2)) ); + ret = QRect(p.x() - 2, p.y() - 2, 5, 5); + } else if (monthButton && monthButton->isVisible() && monthButton->text() == item) { + QPoint p = q->mapFromGlobal( monthButton->mapToGlobal(QPoint(-5, monthButton->height()/2)) ); + ret = QRect(p.x() - 2, p.y() - 2, 5, 5); + TestWidgetsLog() << "click near monthbutton"; + } else if (monthMenu && monthMenu->isVisible() + && qtuitest_cast<QtUiTest::ListWidget*>(monthMenu) + && qtuitest_cast<QtUiTest::ListWidget*>(monthMenu)->list().contains(item)) { + ret = qtuitest_cast<QtUiTest::ListWidget*>(monthMenu)->visualRect(item); + ret.moveTopLeft( q->mapFromGlobal( monthMenu->mapToGlobal(ret.topLeft()) ) ); + TestWidgetsLog() << "click on monthmenu"; + } else { + do { + QStringList items = list(); + if (items.contains(item)) { + ret = QRect(-1, -1, 1, 1); + ret.moveTopLeft( q->mapFromGlobal(QPoint(-1,-1)) ); + break; + } + foreach (QString s, items) { + if (!s.startsWith(GetListRegExp)) continue; + QRegExp re(s.mid(GetListRegExp.length())); + if (re.exactMatch(item)) { + ret = QRect(-1, -1, 1, 1); + ret.moveTopLeft( q->mapFromGlobal(QPoint(-1,-1)) ); + break; + } + } + if (!ret.isNull()) break; + } while(0); + } + + TestWidgetsLog() << "returning rect" << ret; + + return ret; +} + +/* FIXME implement these. */ +bool TestCalendarWidget::canSelect(QString const&) const +{ return false; } + +bool TestCalendarWidget::select(QString const&) +{ return false; } + +bool TestCalendarWidget::ensureVisible(QString const&) +{ return false; } + +bool TestCalendarWidget::canWrap(QObject *o) +{ return qobject_cast<QCalendarWidget*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testcalendarwidget.h b/old/plugins/qtuitest_widgets/qtwidgets/testcalendarwidget.h new file mode 100644 index 0000000..5846a95 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testcalendarwidget.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTCALENDARWIDGET_H +#define TESTCALENDARWIDGET_H + +#include <testwidget.h> + +class QCalendarWidget; + +namespace QtUiTest { + +class TestCalendarWidget : public TestWidget, public QtUiTest::ListWidget, + public QtUiTest::SelectWidget +{ + Q_OBJECT + Q_INTERFACES( + QtUiTest::ListWidget + QtUiTest::SelectWidget) + +public: + TestCalendarWidget(QObject*); + + virtual QStringList list() const; + virtual QRect visualRect(QString const&) const; + virtual bool ensureVisible(QString const&); + + virtual bool canSelect(QString const&) const; + virtual bool select(QString const&); + + static bool canWrap(QObject*); + +private: + QCalendarWidget *q; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testcheckbox.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testcheckbox.cpp new file mode 100644 index 0000000..cb7c5ee --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testcheckbox.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testcheckbox.h" +#include "testwidgetslog.h" + +#include <QCheckBox> + +namespace QtUiTest { + +TestCheckBox::TestCheckBox(QObject *_q) + : TestAbstractButton(_q), q(qobject_cast<QCheckBox*>(_q)) +{ TestWidgetsLog(); } + +bool TestCheckBox::isTristate() const +{ TestWidgetsLog(); return q->isTristate(); } + +Qt::CheckState TestCheckBox::checkState() const +{ TestWidgetsLog(); return q->checkState(); } + +bool TestCheckBox::setCheckState(Qt::CheckState state) +{ + Qt::CheckState initState = checkState(); + if (state == initState) return true; + + bool ret = activate(QtUiTest::NoOptions); + TestWidgetsLog() << "activated:" << ret; + + if (ret && (state == initState) && !QtUiTest::waitForSignal(q, SIGNAL(stateChanged(int)))) { + QtUiTest::setErrorString("Successfully activated button, but check state did not change " + "to expected value."); + return false; + } + + // Give application time to respond to first activation + QtUiTest::wait(20); + + if (state != checkState()) { + ret = activate(QtUiTest::NoOptions); + TestWidgetsLog() << "activated:" << ret; + } + + if (ret && (state != checkState()) && !QtUiTest::waitForSignal(q, SIGNAL(stateChanged(int)))) { + QtUiTest::setErrorString("Successfully activated button, but check state did not change " + "to expected value."); + return false; + } + TestWidgetsLog() << "state:" << ret; + return ret; +} + +bool TestCheckBox::canWrap(QObject *o) +{ return qobject_cast<QCheckBox*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testcheckbox.h b/old/plugins/qtuitest_widgets/qtwidgets/testcheckbox.h new file mode 100644 index 0000000..2698ce7 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testcheckbox.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTCHECKBOX_H +#define TESTCHECKBOX_H + +#include "testabstractbutton.h" + +class QCheckBox; + +namespace QtUiTest { + +class TestCheckBox : public TestAbstractButton +{ + Q_OBJECT +public: + TestCheckBox(QObject*); + + virtual bool isTristate() const; + virtual Qt::CheckState checkState() const; + virtual bool setCheckState(Qt::CheckState); + + static bool canWrap(QObject*); + +private: + QCheckBox *q; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testcombobox.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testcombobox.cpp new file mode 100644 index 0000000..0def518 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testcombobox.cpp @@ -0,0 +1,252 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testcombobox.h" +#include "testwidgetslog.h" + +#include <qtuitestnamespace.h> + +#include <QComboBox> +#include <QAbstractItemView> + +namespace QtUiTest { + +TestComboBox::TestComboBox(QObject *_q) + : TestWidget(_q), q(qobject_cast<QComboBox*>(_q)) +{ + TestWidgetsLog(); + connect(q, SIGNAL(activated(QString)), this, SIGNAL(selected(QString))); +} + +QString TestComboBox::text() const +{ TestWidgetsLog(); return list().join("\n"); } + +QString TestComboBox::selectedText() const +{ TestWidgetsLog(); return q->currentText(); } + +QStringList TestComboBox::list() const +{ + QStringList ret; + for (int i = 0, max = q->count(); i < max; ++i) { + ret << q->itemText(i); + } + TestWidgetsLog() << ret; + return ret; +} + +QRect TestComboBox::visualRect(QString const &item) const +{ + TestWidgetsLog(); + QRect ret; + QtUiTest::ListWidget *viewList + = qtuitest_cast<QtUiTest::ListWidget*>(q->view()); + if (viewList) { + ret = viewList->visualRect(item); + } + return ret; +} + +QString TestComboBox::labelText() const +{ + QString ret = selectedText(); + if (ret.isEmpty()) + return ret; + + QObject *w = parent(); + while (w) { + QtUiTest::Widget *qw = qtuitest_cast<QtUiTest::Widget*>(w); + QtUiTest::LabelWidget *lw = qtuitest_cast<QtUiTest::LabelWidget*>(w); + if (lw) { + if (!lw->labelText().isEmpty()) { + ret.prepend(lw->labelText() + "/"); + break; + } + } + w = qw->parent(); + } + return ret; +} + +QObject* TestComboBox::buddy() const +{ + return q; +} + +bool TestComboBox::canSelect(QString const &item) const +{ return list().contains(item); } + +bool TestComboBox::select(QString const &item) +{ + TestWidgetsLog() << item; + if (!canSelect(item)) return false; + if (selectedText() == item) return true; + + QtUiTest::Widget *wView + = qtuitest_cast<QtUiTest::Widget*>(q->view()); + QtUiTest::SelectWidget *sView + = qtuitest_cast<QtUiTest::SelectWidget*>(q->view()); + if (!wView || !sView) { + QtUiTest::setErrorString("Can't find a pointer to the item view for this combobox."); + return false; + } + + TestWidgetsLog() << "view isVisible()" << wView->isVisible(); + + /* Open the view if it is not currently open. */ + if (!wView->isVisible()) { + if (QtUiTest::mousePreferred()) { + QStyle const* style = q->style(); + QStyleOptionComboBox opt; + opt.initFrom(q); + QRect rect = style->subControlRect( QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxArrow, q); + QPoint pos = rect.center(); + TestWidgetsLog() << "local pos" << pos; + pos = mapToGlobal(pos); + /* May take more than one click. */ + for (int i = 0; i < 2 && !wView->isVisible(); ++i) { + TestWidgetsLog() << "global pos" << pos; + TestWidgetsLog() << "Going to click at" << pos << "to open the view"; + QtUiTest::mouseClick(pos, Qt::LeftButton); + QtUiTest::waitForSignal(q, SIGNAL(highlighted(int))); + } + // Combo box tries to detect and ignore "accidental" double clicks, + // so wait for a bit to ensure any subsequent clicks aren't + // ignored. + QtUiTest::wait( qApp->doubleClickInterval() ); + } else { + TestWidgetsLog() << "Going to give myself focus"; + if (!setFocus()) { + QtUiTest::setErrorString("Could not give focus to combobox"); + return false; + } + if (q->isEditable()) { + return selectWithKeys(item); + } else { + //FIXME: This doesn't work if the combobox is editable + QtUiTest::keyClick(QtUiTest::Key_Select); + if (!q->view()->hasFocus() && !QtUiTest::waitForEvent( q->view(), QEvent::FocusIn)) { + QtUiTest::setErrorString("Could not give focus to combobox popup."); + return false; + } + } + } + } + + /* Select the desired item from the view. */ + TestWidgetsLog() << "Calling select() on the view"; + bool ret = sView->select(item); + + // Wait up to 1 second for the view to disappear after selection. + for (int i = 0; i < 1000 && wView->isVisible(); i+=100, QtUiTest::wait(100)) + {} + + if (!ret && QtUiTest::errorString().isEmpty()) { + QtUiTest::setErrorString( + "Selecting from embedded item view in combo box failed for an unknown reason."); + } + + return ret; +} + +bool TestComboBox::selectWithKeys(QString const &item) +{ + QStringList allItems = list(); + + const int maxtries = 100; + int desiredIndex = allItems.indexOf(item); + + if (-1 == desiredIndex) + return false; + + int currentIndex = q->currentIndex(); + + // Move vertically + Qt::Key key; + if (desiredIndex > currentIndex) + key = Qt::Key_Down; + else + key = Qt::Key_Up; + + for (int i = 0; i < maxtries && selectedText() != item; ++i) { + TestWidgetsLog() << "keyClick" << (key==Qt::Key_Down ? "Down" : "Up"); + if (!QtUiTest::keyClick(q, key)) return false; + } + QString selected = selectedText(); + TestWidgetsLog() << "selectedText() now" << selected; + if (selected != item) { + QtUiTest::setErrorString(QString( + "Up/down keys should have caused item %1 to become selected, but item %2 " + "is selected instead.").arg(item).arg(selected)); + return false; + } + return true; +} + +bool TestComboBox::canEnter(QVariant const& item) const +{ + if (q->isEditable()) { + if (!item.canConvert<QString>()) return false; + int dontcare = 0; + QString text = item.toString(); + const QValidator *validator = q->validator(); + if (validator) { + return (QValidator::Acceptable==validator->validate(text, dontcare)); + } else { + return true; + } + } else { + return canSelect(item.toString()); + } +} + +bool TestComboBox::enter(QVariant const& item, bool noCommit) +{ + if (q->isEditable()) { + return TestWidget::enter(item, noCommit); + } else { + return select(item.toString()); + } +} + +bool TestComboBox::canWrap(QObject *o) +{ return qobject_cast<QComboBox*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testcombobox.h b/old/plugins/qtuitest_widgets/qtwidgets/testcombobox.h new file mode 100644 index 0000000..c8e72dd --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testcombobox.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTCOMBOBOX_H +#define TESTCOMBOBOX_H + +#include <testwidget.h> + +class QComboBox; + +namespace QtUiTest { + +class TestComboBox : public TestWidget, + public QtUiTest::TextWidget, + public QtUiTest::ListWidget, + public QtUiTest::LabelWidget, + public QtUiTest::SelectWidget +{ + Q_OBJECT + Q_INTERFACES( + QtUiTest::TextWidget + QtUiTest::ListWidget + QtUiTest::LabelWidget + QtUiTest::SelectWidget) +public: + TestComboBox(QObject*); + + virtual QString text() const; + virtual QString selectedText() const; + + virtual QStringList list() const; + virtual QRect visualRect(QString const&) const; + + virtual QString labelText() const; + virtual QObject* buddy() const; + + virtual bool canSelect(QString const&) const; + virtual bool select(QString const&); + + virtual bool canEnter(QVariant const&) const; + virtual bool enter(QVariant const&,bool); + + static bool canWrap(QObject*); + +signals: + void selected(QString const&); + +private: + bool selectWithKeys(QString const&); + + QComboBox *q; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testdateedit.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testdateedit.cpp new file mode 100644 index 0000000..a14622f --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testdateedit.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testdateedit.h" +#include "testwidgetslog.h" + +#include <QDateEdit> + +namespace QtUiTest { + +TestDateEdit::TestDateEdit(QObject* _q) + : TestDateTimeEdit(_q), q(qobject_cast<QDateEdit*>(_q)) +{ + TestWidgetsLog(); + + disconnect(q, SIGNAL(dateTimeChanged(QDateTime)), this, 0); + connect(q, SIGNAL(dateTimeChanged(QDateTime)), + this, SLOT(onDateTimeChanged(QDateTime))); +} + +void TestDateEdit::onDateTimeChanged(QDateTime const& dt) +{ + emit entered(dt.date()); +} + +QString TestDateEdit::text() const +{ + TestWidgetsLog(); + return q->date().toString(q->displayFormat()); +} + +QVariant TestDateEdit::value() const +{ + return q->date(); +} + +bool TestDateEdit::canWrap(QObject *o) +{ return qobject_cast<QDateEdit*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testdateedit.h b/old/plugins/qtuitest_widgets/qtwidgets/testdateedit.h new file mode 100644 index 0000000..3494e14 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testdateedit.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTDATEEDIT_H +#define TESTDATEEDIT_H + +#include "testdatetimeedit.h" + +class QDateEdit; + +namespace QtUiTest { + +class TestDateEdit : public TestDateTimeEdit +{ + Q_OBJECT +public: + TestDateEdit(QObject*); + + virtual QString text() const; + virtual QVariant value() const; + + static bool canWrap(QObject*); + +private slots: + void onDateTimeChanged(QDateTime const&); + +private: + QDateEdit *q; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testdatetimeedit.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testdatetimeedit.cpp new file mode 100644 index 0000000..4ce47dc --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testdatetimeedit.cpp @@ -0,0 +1,477 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testdatetimeedit.h" +#include "testwidgetslog.h" + +#include <QLayout> +#include <QLineEdit> +#include <QStyleOptionSpinBox> + +namespace QtUiTest { + +TestDateTimeEdit::TestDateTimeEdit(QObject* _q) + : TestGenericTextWidget(_q), q(qobject_cast<QDateTimeEdit*>(_q)) +{ + TestWidgetsLog(); + connect(q, SIGNAL(dateTimeChanged(QDateTime)), + this, SLOT(onDateTimeChanged(QDateTime))); +} + +void TestDateTimeEdit::onDateTimeChanged(const QDateTime& dt) +{ emit entered(dt); } + +QString TestDateTimeEdit::text() const +{ + TestWidgetsLog(); + return q->dateTime().toString(); +} + +QVariant TestDateTimeEdit::value() const +{ + return q->dateTime(); +} + +QRegExp dateFormatToRegExp(const QString& format) +{ + QString re; + QString fmt = format; + +#define REPLACE_TOK(A,B) \ + if (fmt.startsWith(A)) { \ + re += B; \ + fmt.remove(0, qstrlen(A)); \ + continue; \ + } + while (!fmt.isEmpty()) { + REPLACE_TOK("yyyy", "(\\d{4})"); + REPLACE_TOK("yy", "(\\d{2})"); + + REPLACE_TOK("MMMM", "(\\w+)"); + REPLACE_TOK("MMM", "(\\w+)"); + REPLACE_TOK("MM", "([01]\\d)"); + REPLACE_TOK("M", "(\\d\\d?)"); + + REPLACE_TOK("dddd", "(\\w+)"); + REPLACE_TOK("ddd", "(\\w+)"); + REPLACE_TOK("dd", "([0123]\\d)"); + REPLACE_TOK("d", "(\\d{1,2})"); + + REPLACE_TOK("hh", "([012]\\d)"); + REPLACE_TOK("h", "(\\d{1,2})"); + + REPLACE_TOK("HH", "([012]\\d)"); + REPLACE_TOK("H", "(\\d{1,2})"); + + REPLACE_TOK("mm", "([0-5]\\d)"); + REPLACE_TOK("m", "(\\d{1,2})"); + + REPLACE_TOK("ss", "([0-5]\\d)"); + REPLACE_TOK("s", "(\\d{1,2})"); + + REPLACE_TOK("zzz", "(\\d{3})"); + REPLACE_TOK("z", "(\\d{0,3})"); + + REPLACE_TOK("AP", "(AM|PM)"); + REPLACE_TOK("ap", "(am|pm)"); + REPLACE_TOK("A", "(AM|PM)"); + REPLACE_TOK("a", "(am|pm)"); + + re += QString("\\x%1").arg(fmt.at(0).unicode(), 4, 16, QChar('0')); + fmt.remove(0,1); + } +#undef REPLACE_TOK + + TestWidgetsLog() << format << "resulted in" << re; + + return QRegExp(re); +} + +bool TestDateTimeEdit::canEnter(const QVariant& item) const +{ + QString text; + if (item.canConvert<QDateTime>()) { + text = item.value<QDateTime>().toString( q->displayFormat() ); + } else if (item.canConvert<QDate>()) { + text = item.value<QDate>().toString( q->displayFormat() ); + } else if (item.canConvert<QTime>()) { + text = item.value<QTime>().toString( q->displayFormat() ); + } else { + text = item.toString(); + } + int dont_care = 0; + TestWidgetsLog() << text << "format:" << q->displayFormat(); + bool ret = (QValidator::Acceptable == + static_cast<QAbstractSpinBox*>(q)->validate(text, dont_care)); + if (ret) { + TestWidgetsLog() << "Can enter" << item; + } else { + TestWidgetsLog() << "Can't enter" << item; + } + return ret; +} + +QPoint TestDateTimeEdit::nextClick( const QStringList& cap, + QMap<QDateTimeEdit::Section,int> const& capMap, + bool *final, bool *ok) +{ + if (ok) *ok = false; + if (final) *final = false; + + QPoint ret; + + int activeSection = -1; + int moveUpDown = 0; + int sectionsNeedingChanges = 0; + bool ampm = q->displayedSections() & QDateTimeEdit::AmPmSection; + + /* Sections, from most to least significant. + * It is necessary to edit most significant first because that can affect + * the allowed values from less significant fields (e.g., can't select + * '30' in days if '02' is selected for month). + */ + static const QDateTimeEdit::Section sections[] = { + QDateTimeEdit::YearSection, + QDateTimeEdit::MonthSection, + QDateTimeEdit::DaySection, + QDateTimeEdit::HourSection, + QDateTimeEdit::MinuteSection, + QDateTimeEdit::SecondSection, + QDateTimeEdit::MSecSection, + QDateTimeEdit::AmPmSection, + (QDateTimeEdit::Section)0 + }; + + { + int i = 0; + for (QDateTimeEdit::Section section = sections[i]; + section; + section = sections[++i]) { + if (!(q->displayedSections() & section)) continue; + QString text = q->sectionText(section); + int cap_i = capMap.value(section); + TestWidgetsLog() << "i" << i << "text" << text << "cap_i" << cap_i + << "cap" << cap.at(cap_i); + if (text != cap.at(cap_i)) { + ++sectionsNeedingChanges; + if (-1 == activeSection) { + bool is_int = false; + int src = text.toInt(&is_int); + int dest = cap.at(cap_i).toInt(&is_int); + if (!is_int && section == QDateTimeEdit::MonthSection) { + if (q->displayFormat().contains("MMMM")) { + moveUpDown = QDate::fromString(cap.at(cap_i), "MMMM").month() - QDate::fromString(text, "MMMM").month(); + } else if (q->displayFormat().contains("MMM")) { + moveUpDown = QDate::fromString(cap.at(cap_i), "MMM").month() - QDate::fromString(text, "MMM").month(); + } + } else if (section == QDateTimeEdit::AmPmSection) { + if (text.toUpper() == "PM") + moveUpDown = -1; + else + moveUpDown = 1; + } else if (section == QDateTimeEdit::HourSection && ampm && (dest == 12 || src == 12)) { + moveUpDown = (src - dest); + } else { + moveUpDown = (dest - src); + } + activeSection = cap_i; + } + } + } + } + + /* If there is only one section that requires a change, + * AND that section is off the desired value by one, + * AND that section already has focus, + * then this should be the last necessary click. */ + if (final && (1 == sectionsNeedingChanges) && (1 == qAbs(moveUpDown)) && q->currentSectionIndex() == activeSection) + *final = true; + + TestWidgetsLog() << "activeSection" << activeSection << "currentSectionIndex" << q->currentSectionIndex(); + + if (-1 == activeSection) { + /* No clicking required; already at target value */ + if (final) *final = true; + } else if (q->currentSectionIndex() != activeSection) { + /* Clicking required; need to move cursor to correct section */ + int begin = -1, end = -1; + { + QString text = q->text(); + for (int i = 0; i < activeSection; ++i) { + QString sec = q->sectionText(q->sectionAt(i)); + text.replace(text.indexOf(sec), sec.length(), QString(sec.length(), '_')); + } + QString sec = q->sectionText(q->sectionAt(activeSection)); + begin = text.indexOf(sec); + end = begin + sec.length(); + TestWidgetsLog() << "sec" << sec << "lies from" << begin << "to" << end << "in" << text; + } + QPoint pos(0, q->height()/2); + QLineEdit* le = q->findChild<QLineEdit*>(); + QPoint clickPos; + while (le->rect().contains(pos) && clickPos.isNull()) { + int cursor = le->cursorPositionAt(pos); + if (cursor >= begin && cursor < end) { + clickPos = q->mapFromGlobal(le->mapToGlobal(pos)); + } + pos.setX(pos.x() + 2); + } + ret = clickPos; + if (ret.isNull()) { + if (ok) *ok = false; + QtUiTest::setErrorString(QString("Could not determine where to click in " + "date edit to move cursor between position %1 and %2").arg(begin).arg(end)); + return ret; + } + } else if (moveUpDown != 0) { + /* Clicking required; need to move up */ + QStyle const* style = q->style(); + QStyleOptionSpinBox opt; + opt.initFrom(q); + QRect rect = style->subControlRect(QStyle::CC_SpinBox, &opt, + (moveUpDown > 0) ? QStyle::SC_SpinBoxUp : QStyle::SC_SpinBoxDown, + q); + TestWidgetsLog() << "move " << ((moveUpDown > 0) ? "up" : "down") << rect; + ret = rect.center(); + } + + if (ok) *ok = true; + return ret; +} + +bool TestDateTimeEdit::enterByMouse(const QString& format, const QDateTime& dt) +{ + bool final = false; + bool ok = true; + + QRegExp re( dateFormatToRegExp(format) ); + if (-1 == re.indexIn( dt.toString(format) )) { + TestWidgetsLog() << "regex didn't match, re:" << re << "date:" << dt.toString(format); + return false; + } + + QStringList cap = re.capturedTexts(); + cap.removeFirst(); + + TestWidgetsLog() << "cap" << cap << "text" << q->text(); + + /* Mapping from section to index in cap. + * Wouldn't be necessary if QDateTimeEdit had the inverse of sectionAt(). + */ + QMap<QDateTimeEdit::Section,int> capMap; + for (int i = 0; i < q->sectionCount(); ++i) { + capMap.insert( q->sectionAt(i), i ); + } + + do { + QPoint nc = nextClick(cap, capMap, &final, &ok); + if (ok) { + if (!ensureVisiblePoint(nc)) return false; + QtUiTest::mouseClick(q->mapToGlobal(nc)); +// On some platforms, this takes too long +#ifndef Q_OS_MAC + QtUiTest::waitForSignal(q, SIGNAL(dateTimeChanged(QDateTime))); +#endif + } + } while (!final && ok); + + return ok; +} + +bool TestDateTimeEdit::enterByKeys(const QString& format, const QDateTime& dt, bool noCommit) +{ + if (!hasEditFocus() && !setEditFocus(true)) return false; + TestWidgetsLog() << "got focus"; + + for (int i = 0, m = q->sectionCount(); i < m; ++i) { + if (!enterSectionByKeys(q->sectionAt(i), format, dt)) + return false; + } + + if (noCommit) return true; + + return setEditFocus(false); +} + +bool TestDateTimeEdit::enter(const QVariant& item, bool noCommit) +{ + QString text; + QDateTime dt; + QString format = q->displayFormat(); + TestWidgetsLog() << "Format: " << format; + if (item.canConvert<QDateTime>()) { + dt = item.value<QDateTime>(); + text = dt.toString( format ); + TestWidgetsLog() << "QDateTime"; + } else if (item.canConvert<QDate>()) { + dt = QDateTime(item.value<QDate>(), QTime()); + text = dt.toString( format ); + TestWidgetsLog() << "QDate"; + } else if (item.canConvert<QTime>()) { + dt = QDateTime(QDate(1970,1,1), item.value<QTime>()); + text = dt.toString( format ); + TestWidgetsLog() << "QTime"; + } else { + text = item.toString(); + dt = QDateTime::fromString(text, format); + TestWidgetsLog() << "String"; + } + int dont_care = 0; + if (QValidator::Acceptable != + static_cast<QAbstractSpinBox*>(q)->validate(text, dont_care)) { + TestWidgetsLog() << "Can't enter" << item << "(text:" << text << ")"; + return false; + } + + if (text == q->text()) return true; + + if (QtUiTest::mousePreferred()) { + return enterByMouse(format, dt); + } else { + return enterByKeys(format, dt, noCommit); + } + + return false; +} + +bool TestDateTimeEdit::enterSectionByKeys(QDateTimeEdit::Section section, + const QString& fmt, const QDateTime& dt) +{ + using namespace QtUiTest; + + if (fmt.isEmpty() || !dt.isValid()) return false; + +#define TRY(str) if (fmt.contains(str)) { \ + text = dt.toString(str); \ +} + + QString text; + switch (section) { + case QDateTimeEdit::YearSection: + TRY("yyyy") + else TRY("yy"); + break; + case QDateTimeEdit::MonthSection: + TRY("MMMM") + else TRY("MMM") + else TRY("MM") + else TRY("M"); + break; + case QDateTimeEdit::DaySection: + TRY("dddd") + else TRY("ddd") + else TRY("dd") + else TRY("d"); + break; + case QDateTimeEdit::HourSection: + TRY("hh") + else TRY("h") + else TRY("HH") + else TRY("H"); + if (fmt.contains("AP") || fmt.contains("ap")) { + // Need to use 12 hour format + if (fmt.contains("hh")) { + text = dt.toString("hh ap"); + text = text.left(text.indexOf(' ')); + } + else if (fmt.contains("h")) { + text = dt.toString("h ap"); + text = text.left(text.indexOf(' ')); + } + } + break; + case QDateTimeEdit::MinuteSection: + TRY("mm") + else TRY("m"); + break; + case QDateTimeEdit::SecondSection: + TRY("ss") + else TRY("s"); + break; + case QDateTimeEdit::MSecSection: + TRY("zzz") + else TRY("z"); + break; + case QDateTimeEdit::AmPmSection: + TRY("AP") + else TRY("ap"); + break; + default: + return false; + } +#undef TRY + + if (text.isEmpty()) return false; + + QMap<int,int> sectionMap; + for (int i = 0; i < q->sectionCount(); ++i) { + sectionMap.insert(q->sectionAt(i), i); + } + + int i = 0; + while (q->currentSection() != section && ++i < 100) { + Qt::KeyboardModifiers mod = (q->currentSectionIndex() < sectionMap[section]) ? Qt::KeyboardModifiers(0) : Qt::ShiftModifier; + TestWidgetsLog() << "Entering extra key click (before " + text + ") to move to prev/next section"; + if (!keyClick(q, Qt::Key_Tab)) { + setErrorString("Key click did not go to the expected widget."); + return false; + } + } + if (q->currentSection() != section) { + setErrorString("Could not move focus to desired section."); + return false; + } + + TestWidgetsLog() << "Going to enter" << text << "in section" << section; + + foreach (const QChar& c, text) { + if (!keyClick(q, asciiToKey(c.toLatin1()))) { + return false; + } + } + + return true; +} + +bool TestDateTimeEdit::canWrap(QObject *o) +{ return qobject_cast<QDateTimeEdit*>(o); } + +} diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testdatetimeedit.h b/old/plugins/qtuitest_widgets/qtwidgets/testdatetimeedit.h new file mode 100644 index 0000000..204446d --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testdatetimeedit.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTDATETIMEEDIT_H +#define TESTDATETIMEEDIT_H + +#include "testgenerictextwidget.h" +#include <QDateTimeEdit> + +namespace QtUiTest { + +class TestDateTimeEdit : public TestGenericTextWidget +{ + Q_OBJECT +public: + TestDateTimeEdit(QObject*); + + virtual QString text() const; + virtual QVariant value() const; + + virtual bool canEnter(QVariant const&) const; + virtual bool enter(QVariant const&,bool); + + static bool canWrap(QObject*); + +protected: + bool enterByKeys(QString const&,QDateTime const&,bool); + bool enterByMouse(QString const&,QDateTime const&); + bool enterSectionByKeys(QDateTimeEdit::Section,QString const&, + QDateTime const&); + QPoint nextClick(QStringList const&, + QMap<QDateTimeEdit::Section,int> const&,bool*,bool*); + +private slots: + void onDateTimeChanged(QDateTime const&); + +signals: + void entered(QVariant const&); + +private: + QDateTimeEdit *q; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testdockwidget.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testdockwidget.cpp new file mode 100644 index 0000000..9b24e13 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testdockwidget.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testdockwidget.h" +#include "testwidgetslog.h" + +#include <QDockWidget> + +namespace QtUiTest { + +TestDockWidget::TestDockWidget(QObject* _q) + : TestGenericTextWidget(_q), q(qobject_cast<QDockWidget*>(_q)) +{ TestWidgetsLog(); } + +QString TestDockWidget::text() const +{ + TestWidgetsLog(); + return windowTitle(); +} + +QString TestDockWidget::labelText() const +{ + QString ret = text(); + if (ret.isEmpty()) + return ret; + + QObject *w = parent(); + while (w) { + QtUiTest::Widget *qw = qtuitest_cast<QtUiTest::Widget*>(w); + QtUiTest::LabelWidget *lw = qtuitest_cast<QtUiTest::LabelWidget*>(w); + if (lw) { + if (!lw->labelText().isEmpty()) { + ret.prepend(lw->labelText() + "/"); + break; + } + } + w = qw->parent(); + } + return ret; +} + +QObject* TestDockWidget::buddy() const +{ + return q->widget(); +} + +bool TestDockWidget::canWrap(QObject *o) +{ return qobject_cast<QDockWidget*>(o); } + +QString TestDockWidget::convertToPlainText(QString const &richText) +{ + static QRegExp rxBr("<br */?>"); + static QRegExp rxHtml("<[^>]+>"); + + QString ret(richText); + ret.replace(rxBr, "\n"); + ret.replace(rxHtml, QString()); + return ret; +} + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testdockwidget.h b/old/plugins/qtuitest_widgets/qtwidgets/testdockwidget.h new file mode 100644 index 0000000..d77840c --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testdockwidget.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTDOCKWIDGET_H +#define TESTDOCKWIDGET_H + +#include "testgenerictextwidget.h" + +class QDockWidget; + +namespace QtUiTest { + +class TestDockWidget : public TestGenericTextWidget, + public QtUiTest::LabelWidget +{ + Q_OBJECT + Q_INTERFACES(QtUiTest::LabelWidget) + +public: + TestDockWidget(QObject*); + + virtual QString text() const; + + virtual QString labelText() const; + virtual QObject* buddy() const; + + static bool canWrap(QObject*); + +private: + static QString convertToPlainText(QString const&); + + QDockWidget *q; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testfactory.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testfactory.cpp new file mode 100644 index 0000000..3a4182c --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testfactory.cpp @@ -0,0 +1,183 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testfactory.h" + +#include "testabstractbutton.h" +#include "testabstractitemview.h" +#include "testabstractspinbox.h" +#include "testcalendarwidget.h" +#include "testcheckbox.h" +#include "testcombobox.h" +#include "testdateedit.h" +#include "testdatetimeedit.h" +#include "testdockwidget.h" +#include "testgenericcheckwidget.h" +#include "testgenerictextwidget.h" +#include "testgroupbox.h" +#include "testheaderview.h" +#include "testignore.h" +#include "testlabel.h" +#include "testlineedit.h" +#include "testlistview.h" +#include "testmenu.h" +#include "testmenubar.h" +#include "testpushbutton.h" +#include "testtabbar.h" +#include "testtextedit.h" +#include "testtimeedit.h" +#include "testtoolbar.h" +#include "testtreeview.h" +#include "testtreewidget.h" +#include "testgenericinputmethod.h" + +#if !defined(QT_NO_WEBKIT) +# include "testwebview.h" +#endif + +#include <testwidget.h> +#include "testwidgetslog.h" +#include <QApplication> + +namespace QtUiTest { + +TestWidgetsFactory::TestWidgetsFactory() +{ +} + +QObject* TestWidgetsFactory::create(QObject* o) +{ + QObject* ret = 0; + +#define TRY(Klass) \ + if (Klass::canWrap(o)) { \ + ret = new Klass(o); \ + break; \ + } + + /* Order is important here; classes should be listed in order of + * most to least derived. */ + + do { + /* Qt widgets */ + TRY(TestDateEdit); + TRY(TestTimeEdit); + TRY(TestDateTimeEdit); + TRY(TestCalendarWidget); + TRY(TestDateTimeEdit); + TRY(TestHeaderView); + TRY(TestTreeWidget); + TRY(TestTreeView); + TRY(TestListView); + TRY(TestAbstractItemView); + TRY(TestTabBar); + TRY(TestMenuBar); + TRY(TestToolBar); + TRY(TestMenu); + TRY(TestDockWidget); +#if !defined(QT_NO_WEBKIT) + TRY(TestWebView); +#endif + TRY(TestLabel); + TRY(TestAbstractSpinBox); + TRY(TestGroupBox); + TRY(TestCheckBox); + TRY(TestComboBox); + TRY(TestLineEdit); + TRY(TestTextEdit); + TRY(TestPushButton); + TRY(TestAbstractButton); + TRY(TestGenericCheckWidget); + TRY(TestGenericTextWidget); + TRY(TestIgnore); + TRY(TestWidget); + TRY(TestGenericInputMethod); + } while(0); + + TestWidgetsLog() << o << ret; + + return ret; +} + +QStringList TestWidgetsFactory::keys() const +{ + /* Order doesn't matter here. */ + return QStringList() + << "QAbstractButton" + << "QAbstractItemView" + << "QAbstractSlider" + << "QAbstractSpinBox" + << "QCalendarWidget" + << "QCheckBox" + << "QComboBox" + << "QDateEdit" + << "QDateTimeEdit" + << "QDockWidget" + << "QFrame" + << "QGroupBox" + << "QHeaderView" + << "QLCDNumber" + << "QLabel" + << "QLineEdit" + << "QListView" + << "QMenu" + << "QMenuBar" + << "QMessageBox" + << "QProgressBar" + << "QPushButton" + << "QStackedWidget" + << "QTabBar" + << "QTextEdit" + << "QTimeEdit" + << "QToolBar" + << "QTreeView" + << "QTreeWidget" +#if !defined(QT_NO_WEBKIT) + << "QWebView" +#endif + << "QWidget" + << "QInputContext" + ; +} + +} +#include <qplugin.h> +Q_EXPORT_PLUGIN2(qttestwidgets, QtUiTest::TestWidgetsFactory) diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testfactory.h b/old/plugins/qtuitest_widgets/qtwidgets/testfactory.h new file mode 100644 index 0000000..af62e70 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testfactory.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTFACTORY_H +#define TESTFACTORY_H + +#include <QObject> + +#include <qtuitestwidgetinterface.h> + +namespace QtUiTest { + +class TestWidgetsFactory : public QObject, public QtUiTest::WidgetFactory +{ + Q_OBJECT + Q_INTERFACES(QtUiTest::WidgetFactory) + +public: + TestWidgetsFactory(); + + virtual QObject* create(QObject*); + virtual QStringList keys() const; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testgenericcheckwidget.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testgenericcheckwidget.cpp new file mode 100644 index 0000000..b35d939 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testgenericcheckwidget.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testgenericcheckwidget.h" +#include "testwidgetslog.h" + +#include <QWidget> +#include <QVariant> + +namespace QtUiTest { + +QList<QByteArray> TestGenericCheckWidget::checkProperties = QList<QByteArray>() + << "checked" +; + +TestGenericCheckWidget::TestGenericCheckWidget(QObject* _q) + : TestWidget(_q), q(qobject_cast<QWidget*>(_q)) +{ + TestWidgetsLog(); + foreach (QByteArray property, checkProperties) { + if (-1 != q->metaObject()->indexOfProperty(property)) { + checkProperty = property; + break; + } + } +} + +Qt::CheckState TestGenericCheckWidget::checkState() const +{ + TestWidgetsLog(); + return q->property(checkProperty).toBool() + ? Qt::Checked + : Qt::Unchecked; +} + +bool TestGenericCheckWidget::canWrap(QObject *o) +{ + QWidget *w; + if (!(w = qobject_cast<QWidget*>(o))) + return false; + + foreach (QByteArray property, checkProperties) + if (-1 != o->metaObject()->indexOfProperty(property)) + return true; + + return false; +} + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testgenericcheckwidget.h b/old/plugins/qtuitest_widgets/qtwidgets/testgenericcheckwidget.h new file mode 100644 index 0000000..759b1d3 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testgenericcheckwidget.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTGENERICCHECKWIDGET_H +#define TESTGENERICCHECKWIDGET_H + +#include <testwidget.h> + +namespace QtUiTest { + +class TestGenericCheckWidget : public TestWidget, public QtUiTest::CheckWidget +{ + Q_OBJECT + Q_INTERFACES(QtUiTest::CheckWidget) +public: + TestGenericCheckWidget(QObject*); + + virtual Qt::CheckState checkState() const; + + static bool canWrap(QObject*); + +private: + QWidget *q; + QByteArray checkProperty; + static QList<QByteArray> checkProperties; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testgenericinputmethod.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testgenericinputmethod.cpp new file mode 100644 index 0000000..8b01697 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testgenericinputmethod.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testgenericinputmethod.h" + +#include <qtuitestnamespace.h> +#include <QInputContext> +#include <QInputMethodEvent> +#include <QDebug> + +namespace QtUiTest { + +TestGenericInputMethod::TestGenericInputMethod(QObject *_q) + : q(qobject_cast<QInputContext*>(_q)) +{ +} + +bool TestGenericInputMethod::canEnter(QVariant const& item) const +{ + return true; +} + +bool TestGenericInputMethod::enter(QVariant const& item, bool noCommit) +{ + QInputMethodEvent event; + event.setCommitString(item.toString()); + q->sendEvent(event); + return true; +} + +bool TestGenericInputMethod::canWrap(QObject *o) +{ + return qobject_cast<QInputContext*>(o); +} + +} diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testgenericinputmethod.h b/old/plugins/qtuitest_widgets/qtwidgets/testgenericinputmethod.h new file mode 100644 index 0000000..c8f6dca --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testgenericinputmethod.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTGENERICINPUTMETHOD_H +#define TESTGENERICINPUTMETHOD_H + +#include "testwidget.h" + +class QInputContext; + +namespace QtUiTest { + +class TestGenericInputMethod : public QObject, + QtUiTest::InputWidget +{ + Q_OBJECT + Q_INTERFACES( + QtUiTest::InputWidget) + +public: + TestGenericInputMethod(QObject*); + + virtual bool canEnter(QVariant const&) const; + virtual bool enter(QVariant const&,bool); + + static bool canWrap(QObject*); + +private: + QInputContext *q; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testgenerictextwidget.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testgenerictextwidget.cpp new file mode 100644 index 0000000..a8719cc --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testgenerictextwidget.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testgenerictextwidget.h" +#include "testwidgetslog.h" + +#include <QWidget> +#include <QVariant> + +namespace QtUiTest { + +QList<QByteArray> TestGenericTextWidget::textProperties = QList<QByteArray>() + << "text" + << "plainText" + << "value" + << "title" +; +QList<QByteArray> TestGenericTextWidget::selectedTextProperties = QList<QByteArray>() + << "selectedText" +; + +TestGenericTextWidget::TestGenericTextWidget(QObject* _q) + : TestWidget(_q), q(qobject_cast<QWidget*>(_q)) +{ + TestWidgetsLog() << _q; + foreach (QByteArray property, textProperties) { + if (-1 != q->metaObject()->indexOfProperty(property)) { + textProperty = property; + break; + } + } + foreach (QByteArray property, selectedTextProperties) { + if (-1 != q->metaObject()->indexOfProperty(property)) { + selectedTextProperty = property; + break; + } + } +} + +QString TestGenericTextWidget::text() const +{ TestWidgetsLog(); return q->property(textProperty).toString(); } + +QString TestGenericTextWidget::selectedText() const +{ + TestWidgetsLog(); + QString ret; + if (!selectedTextProperty.isEmpty()) + ret = q->property(selectedTextProperty).toString(); + if (ret.isEmpty()) + ret = text(); + return ret; +} + +bool TestGenericTextWidget::canWrap(QObject *o) +{ + QWidget *w; + if (!(w = qobject_cast<QWidget*>(o))) + return false; + + foreach (QByteArray property, textProperties) + if (-1 != o->metaObject()->indexOfProperty(property)) + return true; + + return false; +} + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testgenerictextwidget.h b/old/plugins/qtuitest_widgets/qtwidgets/testgenerictextwidget.h new file mode 100644 index 0000000..baad629 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testgenerictextwidget.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTGENERICTEXTWIDGET_H +#define TESTGENERICTEXTWIDGET_H + +#include <testwidget.h> + +namespace QtUiTest { + +class TestGenericTextWidget : public TestWidget, public QtUiTest::TextWidget +{ + Q_OBJECT + Q_INTERFACES(QtUiTest::TextWidget) +public: + TestGenericTextWidget(QObject*); + + virtual QString text() const; + virtual QString selectedText() const; + + static bool canWrap(QObject*); + +private: + QWidget *q; + QByteArray textProperty; + QByteArray selectedTextProperty; + static QList<QByteArray> textProperties; + static QList<QByteArray> selectedTextProperties; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testgroupbox.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testgroupbox.cpp new file mode 100644 index 0000000..d33a9e7 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testgroupbox.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testgroupbox.h" +#include "testwidgetslog.h" + +#include <QGroupBox> +#include <QStyleOptionGroupBox> + +namespace QtUiTest { + +TestGroupBox::TestGroupBox(QObject *_q) + : TestGenericTextWidget(_q), q(qobject_cast<QGroupBox*>(_q)) +{ + connect(q, SIGNAL(toggled(bool)), this, SLOT(on_toggled(bool))); +} + +void TestGroupBox::on_toggled(bool state) +{ emit stateChanged(state); } + +Qt::CheckState TestGroupBox::checkState() const +{ return q->isChecked() ? Qt::Checked : Qt::Unchecked; } + +bool TestGroupBox::setCheckState(Qt::CheckState state) +{ + TestWidgetsLog() << state << checkState() << q->isCheckable(); + if (state == checkState()) return true; + if (!q->isCheckable()) return false; + + if (QtUiTest::mousePreferred()) { + QStyle const* style = q->style(); + QStyleOptionGroupBox opt; + opt.initFrom(q); + QRect rect = style->subControlRect(QStyle::CC_GroupBox, &opt, QStyle::SC_GroupBoxCheckBox, q); + QPoint p = rect.center(); + if (!ensureVisiblePoint(p)) return false; + if (!QtUiTest::mouseClick(q, SIGNAL(toggled(bool)), mapToGlobal( p ) )) return false; + } else { + if (!setFocus()) { + QtUiTest::setErrorString("Couldn't toggle group box check state: couldn't give " + "focus to group box."); + return false; + } + if (!QtUiTest::keyClick(q, SIGNAL(toggled(bool)), QtUiTest::Key_ActivateButton )) return false; + } + + return state == checkState(); +} + +QString TestGroupBox::labelText() const +{ + QString ret = text(); + if (ret.isEmpty()) + return ret; + + QObject *w = parent(); + while (w) { + QtUiTest::Widget *qw = qtuitest_cast<QtUiTest::Widget*>(w); + QtUiTest::LabelWidget *lw = qtuitest_cast<QtUiTest::LabelWidget*>(w); + if (lw) { + if (!lw->labelText().isEmpty()) { + ret.prepend(lw->labelText() + "/"); + break; + } + } + w = qw->parent(); + } + return ret; +} + +QObject* TestGroupBox::buddy() const +{ + QObject *buddy = q; + + if (!q->isCheckable()) { + // If the widget is a QGroupBox, and it has exactly one focusable child widget, + // consider that child widget the buddy + QList<QWidget*> focusableWidgets; + foreach (QWidget* fw, q->findChildren<QWidget*>()) { + if (fw->focusPolicy() != Qt::NoFocus) + focusableWidgets << fw; + } + if (focusableWidgets.count() == 1) { + buddy = focusableWidgets[0]; + } + } + + return buddy; +} + +bool TestGroupBox::canWrap(QObject *o) +{ return qobject_cast<QGroupBox*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testgroupbox.h b/old/plugins/qtuitest_widgets/qtwidgets/testgroupbox.h new file mode 100644 index 0000000..08fa82e --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testgroupbox.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTGROUPBOX_H +#define TESTGROUPBOX_H + +#include "testgenerictextwidget.h" + +class QGroupBox; + +namespace QtUiTest { + +class TestGroupBox : public TestGenericTextWidget, + public QtUiTest::CheckWidget, + public QtUiTest::LabelWidget + +{ + Q_OBJECT + Q_INTERFACES( + QtUiTest::CheckWidget + QtUiTest::LabelWidget) + +public: + TestGroupBox(QObject*); + + virtual Qt::CheckState checkState() const; + virtual bool setCheckState(Qt::CheckState); + + virtual QString labelText() const; + virtual QObject* buddy() const; + + static bool canWrap(QObject*); + +signals: + void stateChanged(int); + +private slots: + void on_toggled(bool); + +private: + QGroupBox *q; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testheaderview.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testheaderview.cpp new file mode 100644 index 0000000..c8f2b8f --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testheaderview.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testheaderview.h" +#include "testwidgetslog.h" + +#include <QListView> +#include <QTimer> +#include <QScrollBar> +#include <QComboBox> + +#include <qtuitestnamespace.h> + +namespace QtUiTest { + +TestHeaderView::TestHeaderView(QObject *_q) + : TestWidget(_q), q(static_cast<QHeaderView*>(_q)) +{ +} + +QStringList TestHeaderView::list() const +{ + QStringList ret; + + for (int i=0; i<q->count(); ++i) { + ret << (q->model()->headerData(i, q->orientation())).toString(); + } + + return ret; +} + +QRect TestHeaderView::visualRect(QString const &item) const +{ + int index = list().indexOf(item); + QPoint zero; + int sectionSize = q->sectionSize(index); + int sectionPos = q->sectionPosition(index); + return q->orientation() == Qt::Horizontal + ? QRect(zero.x() + sectionPos, zero.y(), sectionSize, q->height()) + : QRect(zero.x(), zero.y() + sectionPos, q->width(), sectionSize); +} + +bool TestHeaderView::canWrap(QObject* o) +{ return qobject_cast<QHeaderView*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testheaderview.h b/old/plugins/qtuitest_widgets/qtwidgets/testheaderview.h new file mode 100644 index 0000000..5970dd1 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testheaderview.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTHEADERVIEW_H +#define TESTHEADERVIEW_H + +#include <testwidget.h> + +#include <QHeaderView> + +namespace QtUiTest { + +class TestHeaderView : public TestWidget, + public QtUiTest::ListWidget +{ + Q_OBJECT + Q_INTERFACES(QtUiTest::ListWidget) + +public: + TestHeaderView(QObject*); + + virtual QStringList list() const; + virtual QRect visualRect(QString const&) const; + + static bool canWrap(QObject*); + +signals: + void selected(const QString&); + +private: + QHeaderView *q; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testignore.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testignore.cpp new file mode 100644 index 0000000..cd63018 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testignore.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testignore.h" +#include "testwidgetslog.h" + +namespace QtUiTest { + +TestIgnore::TestIgnore(QObject* _q) + : TestWidget(_q), q(_q) +{ TestWidgetsLog(); } + +bool TestIgnore::canWrap(QObject *o) +{ + QString cn = o->metaObject()->className(); + return (cn == "QStackedWidget" || + cn == "QFrame" || + cn == "QWidget"); +} + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testignore.h b/old/plugins/qtuitest_widgets/qtwidgets/testignore.h new file mode 100644 index 0000000..db0ae98 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testignore.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTIGNORE_H +#define TESTIGNORE_H + +#include <testwidget.h> + +namespace QtUiTest { + +class TestIgnore : public TestWidget +{ + Q_OBJECT +public: + TestIgnore(QObject*); + virtual bool ignoreScan() const { return true; } + + static bool canWrap(QObject*); + +private: + QObject *q; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testlabel.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testlabel.cpp new file mode 100644 index 0000000..b5ce0cc --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testlabel.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testlabel.h" +#include "testwidgetslog.h" + +#include <QLabel> +#include <QGroupBox> + +namespace QtUiTest { + +TestLabel::TestLabel(QObject* _q) + : TestGenericTextWidget(_q), q(qobject_cast<QLabel*>(_q)) +{ TestWidgetsLog(); } + +QString TestLabel::text() const +{ + TestWidgetsLog(); + QString text = TestGenericTextWidget::text(); + if (q->textFormat() != Qt::PlainText) + text = convertToPlainText(text); + + return text; +} + +QString TestLabel::labelText() const +{ + QString ret = text(); + if (ret.isEmpty()) + return ret; + + QObject *w = parent(); + while (w) { + QtUiTest::Widget *qw = qtuitest_cast<QtUiTest::Widget*>(w); + QtUiTest::LabelWidget *lw = qtuitest_cast<QtUiTest::LabelWidget*>(w); + if (lw) { + if (!lw->labelText().isEmpty()) { + ret.prepend(lw->labelText() + "/"); + break; + } + } + w = qw->parent(); + } + return ret; +} + +QObject* TestLabel::buddy() const +{ + return q->buddy(); +} + +bool TestLabel::canWrap(QObject *o) +{ return qobject_cast<QLabel*>(o); } + +QString TestLabel::convertToPlainText(QString const &richText) +{ + static QRegExp rxBr("<br */?>"); + static QRegExp rxHtml("<[^>]+>"); + + QString ret(richText); + ret.replace(rxBr, "\n"); + ret.replace(rxHtml, QString()); + return ret; +} + +// Returns a groupbox prefix for widgets that are owned by a groupbox +QString TestLabel::groupBoxName() const +{ + QWidget *parent = q; + QGroupBox *gb; + QString ret; + do { + parent = qobject_cast<QWidget*>(parent->parent()); + gb = qobject_cast<QGroupBox*>(parent); + if (gb && !gb->title().isEmpty()) + ret += gb->title() + "/"; + } while (parent); + + ret.chop(1); + return ret; +} + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testlabel.h b/old/plugins/qtuitest_widgets/qtwidgets/testlabel.h new file mode 100644 index 0000000..dbca3b4 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testlabel.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTLABEL_H +#define TESTLABEL_H + +#include "testgenerictextwidget.h" + +class QLabel; + +namespace QtUiTest { + +class TestLabel : public TestGenericTextWidget, + public QtUiTest::LabelWidget +{ + Q_OBJECT + Q_INTERFACES(QtUiTest::LabelWidget) + +public: + TestLabel(QObject*); + + virtual bool ignoreScan() const { return true; } + + virtual QString text() const; + + virtual QString labelText() const; + virtual QObject* buddy() const; + + static bool canWrap(QObject*); + +private: + static QString convertToPlainText(QString const&); + QString groupBoxName() const; + + QLabel *q; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testlineedit.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testlineedit.cpp new file mode 100644 index 0000000..4f24e5c --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testlineedit.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testlineedit.h" +#include "testtext.h" +#include "testwidgetslog.h" + +#include <QDesktopWidget> +#include <QLayout> +#include <QLineEdit> +#include <QPointer> +#include <QValidator> +#include <QVariant> +#include <QDateTimeEdit> + +namespace QtUiTest { + +TestLineEdit::TestLineEdit(QObject *_q) + : TestGenericTextWidget(_q), q(qobject_cast<QLineEdit*>(_q)) +{ + if (q && qobject_cast<QDateTimeEdit*>(q->parent())) { + // The test object of the parent will handle recording + return; + } + + connect(q, SIGNAL(textEdited(QString)), this, SLOT(onTextEdited(QString))); +} + +void TestLineEdit::onTextEdited(QString const& item) +{ emit entered(item); } + +bool TestLineEdit::canEnter(QVariant const& item) const +{ + if (!item.canConvert<QString>()) return false; + if (!q->validator()) return true; + + int dontcare = 0; + QString text = item.toString(); + return (QValidator::Acceptable==q->validator()->validate(text, dontcare)); +} + +bool TestLineEdit::enter(QVariant const& item, bool noCommit) +{ + if (!canEnter(item)) return false; + + bool hadEditFocus = false; + + if (!hadEditFocus && !setEditFocus(true)) return false; + + using namespace QtUiTest; + + QPointer<QObject> safeThis = this; + + if (!safeThis) { + setErrorString("Widget was destroyed while entering text."); + return false; + } + + QString oldText = text(); + QString selectedText = q->selectedText(); + QString itemString = item.toString(); + + QString expectedText = oldText; + if (selectedText == "") { + expectedText.insert(q->cursorPosition(), itemString); + // If there's text currently in the field, and we don't already have + // edit focus, then erase it first. + if (!oldText.isEmpty() && !hadEditFocus) { + if (!TestText::eraseTextByKeys(q)) return false; + expectedText = itemString; + } + } else { + expectedText.replace(selectedText, itemString); + } + + InputWidget *iw = qtuitest_cast<InputWidget*>(inputProxy()); + + if (!safeThis) { + setErrorString("Widget was destroyed while entering text."); + return false; + } + + TestWidgetsLog() << iw; + + if (iw) { + if (!TestText::enterTextByProxy(iw, q, itemString, expectedText, !noCommit)) return false; + } else { + if (!TestText::enterText(q, itemString, expectedText, !noCommit)) return false; + } + + if (!safeThis) { + setErrorString("Widget was destroyed while entering text."); + return false; + } + + if (!noCommit && hasEditFocus()) { + if (!setEditFocus(false)) { + return false; + } + } + + return true; +} + +bool TestLineEdit::canWrap(QObject *o) +{ return qobject_cast<QLineEdit*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testlineedit.h b/old/plugins/qtuitest_widgets/qtwidgets/testlineedit.h new file mode 100644 index 0000000..ec94ae7 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testlineedit.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTLINEEDIT_H +#define TESTLINEEDIT_H + +#include "testgenerictextwidget.h" + +class QLineEdit; + +namespace QtUiTest { + +class TestLineEdit : public TestGenericTextWidget +{ + Q_OBJECT + + +public: + TestLineEdit(QObject*); + + virtual bool canEnter(QVariant const&) const; + virtual bool enter(QVariant const&,bool); + + static bool canWrap(QObject*); + +private slots: + void onTextEdited(QString const&); + +signals: + void entered(QVariant const&); + +private: + QLineEdit *q; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testlistview.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testlistview.cpp new file mode 100644 index 0000000..96507e2 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testlistview.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testlistview.h" +#include "testwidgetslog.h" + +#include <QListView> + +#include <qtuitestnamespace.h> + +namespace QtUiTest { + +TestListView::TestListView(QObject *_q) + : TestAbstractItemView(_q), q(qobject_cast<QListView*>(_q)) +{} + +QStringList TestListView::list() const +{ + QStringList list; + + QAbstractItemModel *model = q->model(); + QModelIndex index = q->rootIndex(); + int count = 0; + + for (int i = 0, max_i = model->rowCount(index); i < max_i && count <= QTUITEST_MAX_LIST; ++i) { + if (model->hasIndex(i, q->modelColumn(), index)) { + list << model->data(model->index(i, q->modelColumn(), index)).toString(); + } + } + + return list; +} + +QModelIndex TestListView::indexForItem(QString const &item) const +{ + QModelIndex ret; + + QStringList list; + + QAbstractItemModel *model = q->model(); + QModelIndex index = q->rootIndex(); + int count = 0; + + for (int i = 0, max_i = model->rowCount(index); i < max_i && count <= QTUITEST_MAX_LIST; ++i) { + int j = q->modelColumn(); + QModelIndex child; + if (model->hasIndex(i, j, index) && model->data(model->index(i, j, index)).toString() == item) { + ret = model->index(i, j, index); + } + } + + return ret; +} + +bool TestListView::canWrap(QObject* o) +{ return qobject_cast<QListView*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testlistview.h b/old/plugins/qtuitest_widgets/qtwidgets/testlistview.h new file mode 100644 index 0000000..3a3dea9 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testlistview.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTLISTVIEW_H +#define TESTLISTVIEW_H + +#include "testabstractitemview.h" + +#include <QListView> + +namespace QtUiTest { + +class TestListView : public TestAbstractItemView +{ + Q_OBJECT + +public: + TestListView(QObject*); + virtual QStringList list() const; + static bool canWrap(QObject*); + +protected: + virtual QModelIndex indexForItem(QString const&) const; + +private: + QListView *q; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testmenu.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testmenu.cpp new file mode 100644 index 0000000..66e1e58 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testmenu.cpp @@ -0,0 +1,398 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testmenu.h" +#include "testwidgetslog.h" + +#include <QMenu> +#include <QAction> + +namespace QtUiTest { + +TestMenu::TestMenu(QObject *_q) + : TestWidget(_q), q(qobject_cast<QMenu*>(_q)), lastAction(0) +{ + // For accurate ordering of events recording, these connections + // must come before all others. + QtUiTest::connectFirst(q, SIGNAL(hovered(QAction*)), + this, SLOT(on_hovered(QAction*))); +} + +void TestMenu::on_hovered(QAction* a) +{ + if (lastAction) + QtUiTest::disconnectFirst(lastAction, 0, this, 0); + lastAction = a; + if (lastAction) { + QtUiTest::connectFirst(lastAction, SIGNAL(toggled(bool)), + this, SLOT(on_toggled(bool))); + QtUiTest::connectFirst(lastAction, SIGNAL(triggered(bool)), + this, SLOT(on_triggered(bool))); + } +} + +void TestMenu::on_toggled(bool state) +{ emit stateChanged(state); } + +QString textForAction(QMenu* m, QAction* a) +{ + QString ret; + foreach (QAction* child, m->actions()) { + if (child == a) { + ret = a->text(); + ret.replace("/","\\/"); + } else if (child->menu()) { + ret = textForAction(child->menu(), a); + if (!ret.isEmpty()) + ret.prepend(child->menu()->title().replace("/","\\/") + "/"); + } + if (!ret.isEmpty()) + break; + } + return ret; +} + +void TestMenu::on_triggered(bool) +{ + /* + Both the top level and submenus emit the triggered() signal. + We only want to emit selected() if we are the top level menu. + */ + bool top_level = true; + if (q->menuAction()) { + foreach (QWidget* w, q->menuAction()->associatedWidgets()) { + if (qobject_cast<QMenu*>(w)) { + top_level = false; + break; + } + } + } + + if (!top_level) return; + + emit selected(textForAction(q,lastAction)); +} + +QString TestMenu::text() const +{ + return list().join("\n"); +} + +QString TestMenu::selectedText() const +{ + QString ret; + + QAction *active = q->activeAction(); + if (!active) return ret; + + QMenu *child = active->menu(); + if (!child || !child->activeAction()) + return active->text().replace("/", "\\/"); + + return active->text().replace("/", "\\/") + "/" + qtuitest_cast<QtUiTest::TextWidget*>(child)->selectedText(); +} + +QStringList TestMenu::list() const +{ + QStringList ret; + + /* Iterate through every action */ + foreach( QAction *a, q->actions() ) { + if (!a->isEnabled() || a->isSeparator()) + continue; + QString t = a->text(); + t.replace("/","\\/"); + if (!t.isEmpty()) ret << t; + if (a->menu() && a->menu() != q) { + QStringList sub = qtuitest_cast<QtUiTest::ListWidget*>(a->menu())->list(); + foreach (QString s, sub) { + if (!s.isEmpty()) ret << t + "/" + s; + } + } + } + + return ret; +} + +QRect TestMenu::visualRect(QString const &item) const +{ + TestWidgetsLog() << item; + static QRegExp slashRe("[^\\\\]/"); + QRect ret; + + int ind; + if (0 != (ind = item.indexOf(slashRe)+1)) { + QString top(item.left(ind)); + QString rest(item.mid(ind+1)); + + QAction *a(q->activeAction()); + QString t = a->text(); + t.replace("/","\\/"); + if (!a || t != top || !a->menu()) { + TestWidgetsLog() << "The desired submenu" << item << "is not visible"; + return ret; + } + + ret = qtuitest_cast<QtUiTest::ListWidget*>(a->menu())->visualRect(rest); + ret.moveTopLeft( q->mapFromGlobal( a->menu()->mapToGlobal( ret.topLeft() ) ) ); + return ret; + } + + QAction *a = actionForItem(item); + if (a) ret = q->actionGeometry(a); + + return ret; +} + +QAction *TestMenu::actionForItem(QString const &item) const +{ + static QRegExp amperRe("&(.)"); + QAction *ret = 0; + foreach( QAction *a, q->actions() ) { + QString t = a->text(); + t.replace("/","\\/"); + if (t == item) { + ret = a; + break; + } else { + t.replace(amperRe, "\\1"); + if (t == item) { + ret = a; + } + } + } + + if (!ret) { + setErrorString("Item \"" + item + "\" is not available"); + } else if (!ret->isEnabled()) { + setErrorString("Item \"" + item + "\" is not enabled"); + ret = 0; + } + + return ret; +} + +Qt::CheckState TestMenu::checkState() const +{ + QAction *active = q->activeAction(); + return (active && active->isChecked()) ? Qt::Checked : Qt::Unchecked; +} + +bool TestMenu::ensureVisible(QString const&) +{ return false; } + +bool TestMenu::canSelect(QString const &item) const +{ + QStringList l = list(); + return l.contains(item) || l.contains(labelText(item)); +} + +bool TestMenu::select(QString const &item) +{ + if (!isVisible()) { + setErrorString("Can't select \"" + item + "\" because menu is not visible"); + return false; + } + + TestWidgetsLog() << item; + static QRegExp slashRe("[^\\\\]/"); + + QString topItem = item; + QString rest; + + int ind; + if (0 != (ind = item.indexOf(slashRe)+1)) { + topItem = item.left(ind); + rest = item.mid(ind+1); + } + + QRect r = visualRect(topItem); + if (r.isNull()) { + if (errorString().isEmpty()) { + setErrorString("Can't find visual rect for item \"" + topItem + "\" in menu"); + } + return false; + } + + QPoint pos = r.center(); + + bool useMouse = mousePreferred(); + if (useMouse) { + while (!rect().contains(pos)) { + QRect visibleRect = visibleRegion().boundingRect(); + QPoint globalPos = mapToGlobal(visibleRect.topLeft()); + if (pos.y() < globalPos.y()) { + TestWidgetsLog() << "click to scroll up"; + mouseClick(QPoint(globalPos.x() + visibleRect.width() / 2, globalPos.y() + 8)); + QtUiTest::wait(200); + } else { + TestWidgetsLog() << "click to scroll down"; + mouseClick(QPoint(globalPos.x() + visibleRect.width() / 2, globalPos.y() + visibleRect.height() - 8)); + QtUiTest::wait(200); + } + + pos = visualRect(topItem).center(); + } + TestWidgetsLog() << "click on item"; + if (!mouseClick(q, mapToGlobal(pos))) + return false; +// waitForSignal(q, SIGNAL(triggered(QAction*))); + } else { + Qt::Key key; + if ( pos.y() > q->actionGeometry(q->activeAction()).center().y() ) + key = Qt::Key_Down; + else + key = Qt::Key_Up; + + while ( selectedText() != topItem ) { + TestWidgetsLog() << "key" << ((key == Qt::Key_Down) ? "down" : "up"); + if (!keyClick(q, key)) return false; + } + + TestWidgetsLog() << "select key"; + // If this is the last item, it should be trigged... + if (item == topItem) { + if (!keyClick(q->activeAction(), SIGNAL(triggered(bool)), QtUiTest::Key_Activate)) + return false; + } + // ...but if it has a submenu, it won't be; rather, its menu will be shown. + else if (q->activeAction() && q->activeAction()->menu()) { + if (!keyClick(q->activeAction()->menu(), QtUiTest::Key_Activate)) + return false; + } + + // And if it doesn't have a submenu and isn't the final item... well, that shouldn't + // happen, but that will be caught below. + } + + if (topItem != item) { + QAction *a(q->activeAction()); + if (!a || !a->menu()) { + setErrorString("Failed to select \"" + item + "\" because " + + (!a ? "focus could not be given to a parent item." + : "an item was expected to have a submenu, but didn't.")); + return false; + } + + // Wait until the menu is visible + if (!a->menu()->isVisible() && !waitForEvent(a->menu(), QEvent::Show)) { + setErrorString("Failed to select \"" + item + "\" because a submenu did not become " + "visible when it should have."); + return false; + } + + TestWidgetsLog() << "calling select() on child"; + return qtuitest_cast<SelectWidget*>(a->menu())->select(rest); + } + return true; +} + +bool TestMenu::isCheckable(const QString &item) +{ + static QRegExp slashRe("[^\\\\]/"); + bool ret = false; + int ind; + if (0 != (ind = item.indexOf(slashRe)+1)) { + QString top(item.left(ind)); + QString rest(item.mid(ind+1)); + + QAction *a = actionForItem(top); + if (!a || !a->menu()) { + TestWidgetsLog() << "The desired submenu" << item << "is not valid"; + return ret; + } + + return qtuitest_cast<QtUiTest::CheckItemWidget*>(a->menu())->isCheckable(rest); + } + + QAction *a = actionForItem(item); + if (a) ret = a->isCheckable(); + + return ret; +} + +bool TestMenu::isChecked(const QString &item) const +{ + static QRegExp slashRe("[^\\\\]/"); + + bool ret = false; + int ind; + if (0 != (ind = item.indexOf(slashRe)+1)) { + QString top(item.left(ind)); + QString rest(item.mid(ind+1)); + + QAction *a = actionForItem(top); + if (!a || !a->menu()) { + TestWidgetsLog() << "The desired submenu" << item << "is not valid"; + return ret; + } + + return qtuitest_cast<QtUiTest::CheckItemWidget*>(a->menu())->isChecked(rest); + } + + QAction *a = actionForItem(item); + if (a) { + ret = a->isChecked(); + } else { + setErrorString("Cannot get check status for item \"" + item + "\""); + } + + return ret; +} + +bool TestMenu::setChecked(const QString &item, bool value) +{ + if (isChecked(item) == value) { + return true; + } + + return select(item); +} + +bool TestMenu::hasFocus() const +{ + return !q->isHidden(); +} + +bool TestMenu::canWrap(QObject *o) +{ return qobject_cast<QMenu*>(o); } + +} diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testmenu.h b/old/plugins/qtuitest_widgets/qtwidgets/testmenu.h new file mode 100644 index 0000000..17a45aa --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testmenu.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTMENU_H +#define TESTMENU_H + +#include <testwidget.h> + +#include <QtGlobal> + +class QMenu; +class QAction; + +namespace QtUiTest { + +class TestMenu : public TestWidget, public QtUiTest::TextWidget, + public QtUiTest::ListWidget, public QtUiTest::CheckWidget, + public QtUiTest::SelectWidget, public QtUiTest::CheckItemWidget +{ + Q_OBJECT + Q_INTERFACES( + QtUiTest::TextWidget + QtUiTest::ListWidget + QtUiTest::CheckWidget + QtUiTest::CheckItemWidget + QtUiTest::SelectWidget) + +public: + TestMenu(QObject*); + + virtual QString text() const; + virtual QString selectedText() const; + + virtual QStringList list() const; + virtual QRect visualRect(QString const&) const; + virtual bool ensureVisible(QString const&); + + virtual Qt::CheckState checkState() const; + + virtual bool canSelect(const QString&) const; + virtual bool select(const QString&); + + virtual bool isCheckable(const QString&); + virtual bool isChecked(const QString&) const; + virtual bool setChecked(const QString&, bool); + + virtual bool hasFocus() const; + + static bool canWrap(QObject*); + +signals: + void stateChanged(int); + void selected(const QString&); + +private slots: + void on_hovered(QAction*); + void on_triggered(bool); + void on_toggled(bool); + +private: + QMenu *q; + QAction *lastAction; + + QAction *actionForItem(QString const&) const; +}; + +} + +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testmenubar.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testmenubar.cpp new file mode 100644 index 0000000..095b5d4 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testmenubar.cpp @@ -0,0 +1,391 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testmenubar.h" +#include "testwidgetslog.h" + +#include <QMenuBar> +#include <QMenu> +#include <QAction> + +namespace QtUiTest { + +TestMenuBar::TestMenuBar(QObject *_q) + : TestWidget(_q), q(qobject_cast<QMenuBar*>(_q)), lastAction(0) +{ + // For accurate ordering of events recording, these connections + // must come before all others. +// QtUiTest::connectFirst(q, SIGNAL(hovered(QAction*)), +// this, SLOT(on_hovered(QAction*))); +} +/* +void TestMenuBar::on_hovered(QAction* a) +{ + if (lastAction) + QtUiTest::disconnectFirst(lastAction, 0, this, 0); + lastAction = a; + if (lastAction) { + QtUiTest::connectFirst(lastAction, SIGNAL(toggled(bool)), + this, SLOT(on_toggled(bool))); + QtUiTest::connectFirst(lastAction, SIGNAL(triggered(bool)), + this, SLOT(on_triggered(bool))); + } +} + +void TestMenuBar::on_toggled(bool state) +{ emit stateChanged(state); } +*/ +/* +QString textForAction(QMenu* m, QAction* a) +{ + QString ret; + foreach (QAction* child, m->actions()) { + if (child == a) { + ret = a->text(); + ret.replace("/","\\/"); + } else if (child->menu()) { + ret = textForAction(child->menu(), a); + if (!ret.isEmpty()) + ret.prepend(child->menu()->title().replace("/","\\/") + "/"); + } + if (!ret.isEmpty()) + break; + } + return ret; +} +*/ +/* +void TestMenuBar::on_triggered(bool) +{ + // Both the top level and submenus emit the triggered() signal. + // We only want to emit selected() if we are the top level menu. + + bool top_level = true; + if (q->menuAction()) { + foreach (QWidget* w, q->menuAction()->associatedWidgets()) { + if (qobject_cast<QMenu*>(w)) { + top_level = false; + break; + } + } + } + + if (!top_level) return; + + emit selected(textForAction(q,lastAction)); +// } +*/ +QString TestMenuBar::text() const +{ + return list().join("\n"); +} + +QString TestMenuBar::selectedText() const +{ + QString ret; + + QAction *active = q->activeAction(); + if (!active) return ret; + + QMenu *child = active->menu(); + if (!child || !child->activeAction()) + return active->text().replace("/", "\\/"); + + return active->text().replace("/", "\\/") + "/" + qtuitest_cast<QtUiTest::TextWidget*>(child)->selectedText(); +} + +QStringList TestMenuBar::list() const +{ + QStringList ret; + + /* Iterate through every action */ + foreach( QAction *a, q->actions() ) { + if (!a->isEnabled()) + continue; + QString t = a->text(); + t.replace("/","\\/"); + if (!t.isEmpty()) ret << t; + if (a->menu()) { + QStringList sub = qtuitest_cast<QtUiTest::ListWidget*>(a->menu())->list(); + foreach (QString s, sub) { + if (!s.isEmpty()) ret << t + "/" + s; + } + } + } + + return ret; +} + +QRect TestMenuBar::visualRect(QString const &item) const +{ + TestWidgetsLog() << item; + static QRegExp slashRe("[^\\\\]/"); + static QRegExp amperRe("&(.)"); + QRect ret; + + int ind; + if (0 != (ind = item.indexOf(slashRe)+1)) { + QString top(item.left(ind)); + QString rest(item.mid(ind+1)); + + QAction *a(q->activeAction()); + QString t = a->text(); + t.replace("/","\\/"); + if (!a || t != top || !a->menu()) { + TestWidgetsLog() << "The desired submenu" << item << "is not visible"; + return ret; + } + + ret = qtuitest_cast<QtUiTest::ListWidget*>(a->menu())->visualRect(rest); + ret.moveTopLeft( q->mapFromGlobal( a->menu()->mapToGlobal( ret.topLeft() ) ) ); + return ret; + } + + QAction *a = actionForItem(item); + if (a) ret = q->actionGeometry(a); + + return ret; +} + +QAction *TestMenuBar::actionForItem(QString const &item) const +{ + static QRegExp amperRe("&(.)"); + QAction *ret = 0; + foreach( QAction *a, q->actions() ) { + QString t = a->text(); + t.replace("/","\\/"); + if (t == item) { + ret = a; + break; + } else { + t.replace(amperRe, "\\1"); + if (t == item) { + ret = a; + } + } + } + + if (!ret) { + setErrorString("Item \"" + item + "\" is not available"); + } else if (!ret->isEnabled()) { + setErrorString("Item \"" + item + "\" is not enabled"); + ret = 0; + } + + return ret; +} + +Qt::CheckState TestMenuBar::checkState() const +{ + QAction *active = q->activeAction(); + return (active && active->isChecked()) ? Qt::Checked : Qt::Unchecked; +} + +bool TestMenuBar::ensureVisible(QString const&) +{ return false; } + +bool TestMenuBar::canSelect(QString const &item) const +{ + return list().contains(item); +} + +bool TestMenuBar::select(QString const &item) +{ + if (!isVisible()) { + setErrorString("Can't select \"" + item + "\" because menu is not visible"); + return false; + } + + TestWidgetsLog() << item; + static QRegExp slashRe("[^\\\\]/"); + + QString topItem = item; + QString rest; + + int ind; + if (0 != (ind = item.indexOf(slashRe)+1)) { + topItem = item.left(ind); + rest = item.mid(ind+1); + } + + QAction *action = actionForItem(topItem); + + QRect r = visualRect(topItem); + if (r.isNull()) { + if (errorString().isEmpty()) { + setErrorString("Can't find visual rect for item \"" + topItem + "\" in menu"); + } + return false; + } + + QPoint pos = r.center(); + + if (mousePreferred()) { + while (!rect().contains(pos)) { + QRect visibleRect = visibleRegion().boundingRect(); + QPoint globalPos = mapToGlobal(visibleRect.topLeft()); + if (pos.y() < globalPos.y()) { + TestWidgetsLog() << "click to scroll up"; + mouseClick(QPoint(globalPos.x() + visibleRect.width() / 2, globalPos.y() + 8)); + QtUiTest::wait(200); + } else { + TestWidgetsLog() << "click to scroll down"; + mouseClick(QPoint(globalPos.x() + visibleRect.width() / 2, globalPos.y() + visibleRect.height() - 8)); + QtUiTest::wait(200); + } + + pos = visualRect(topItem).center(); + } + + if (!mouseClick(action->menu(), SIGNAL(aboutToShow()), mapToGlobal(pos))) + return false; + } else { + Qt::Key key; + if ( pos.y() > q->actionGeometry(q->activeAction()).center().y() ) + key = Qt::Key_Down; + else + key = Qt::Key_Up; + + while ( selectedText() != topItem ) { + TestWidgetsLog() << "key" << ((key == Qt::Key_Down) ? "down" : "up"); + if (!keyClick(q, key)) return false; + } + + TestWidgetsLog() << "select key"; + // If this is the last item, it should be trigged... + if (item == topItem) { + if (!keyClick(q->activeAction(), SIGNAL(triggered(bool)), QtUiTest::Key_Select)) + return false; + } + // ...but if it has a submenu, it won't be; rather, its menu will be shown. + else if (q->activeAction() && q->activeAction()->menu()) { + if (!keyClick(q->activeAction()->menu(), QtUiTest::Key_Select)) + return false; + } + + // And if it doesn't have a submenu and isn't the final item... well, that shouldn't + // happen, but that will be caught below. + } + + if (topItem != item) { + + if (!action->menu()->isVisible() && !waitForEvent(action->menu(), QEvent::Show)) { + setErrorString("Failed to select \"" + item + "\" because a submenu did not become " + "visible when it should have."); + return false; + } + + TestWidgetsLog() << "calling select() on child"; + return qtuitest_cast<SelectWidget*>(action->menu())->select(rest); + } + + return true; +} + +bool TestMenuBar::isCheckable(const QString &item) +{ + static QRegExp slashRe("[^\\\\]/"); + + bool ret = false; + int ind; + if (0 != (ind = item.indexOf(slashRe)+1)) { + QString top(item.left(ind)); + QString rest(item.mid(ind+1)); + + QAction *a = actionForItem(top); + if (!a || !a->menu()) { + TestWidgetsLog() << "The desired submenu" << item << "is not valid"; + return ret; + } + + return qtuitest_cast<QtUiTest::CheckItemWidget*>(a->menu())->isCheckable(rest); + } + + QAction *a = actionForItem(item); + if (a) ret = a->isCheckable(); + + return ret; +} + +bool TestMenuBar::isChecked(const QString &item) const +{ + static QRegExp slashRe("[^\\\\]/"); + + bool ret = false; + int ind; + if (0 != (ind = item.indexOf(slashRe)+1)) { + QString top(item.left(ind)); + QString rest(item.mid(ind+1)); + + QAction *a = actionForItem(top); + + if (!a || !a->menu()) { + TestWidgetsLog() << "The desired submenu" << item << "is not valid"; + return ret; + } + + return qtuitest_cast<QtUiTest::CheckItemWidget*>(a->menu())->isChecked(rest); + } + + QAction *a = actionForItem(item); + if (a) ret = a->isChecked(); + + return ret; +} + +bool TestMenuBar::setChecked(const QString &item, bool value) +{ + if (isChecked(item) == value) { + return true; + } + + return select(item); +} + +bool TestMenuBar::hasFocus() const +{ + return !q->isHidden(); +} + +bool TestMenuBar::canWrap(QObject *o) +{ return qobject_cast<QMenuBar*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testmenubar.h b/old/plugins/qtuitest_widgets/qtwidgets/testmenubar.h new file mode 100644 index 0000000..229e4f7 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testmenubar.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTMENUBAR_H +#define TESTMENUBAR_H + +#include <testwidget.h> + +#include <QtGlobal> + +class QMenuBar; +class QAction; + +namespace QtUiTest { + +class TestMenuBar : public TestWidget, public QtUiTest::TextWidget, + public QtUiTest::ListWidget, public QtUiTest::CheckWidget, + public QtUiTest::SelectWidget, public CheckItemWidget +{ + Q_OBJECT + Q_INTERFACES( + QtUiTest::TextWidget + QtUiTest::ListWidget + QtUiTest::CheckWidget + QtUiTest::CheckItemWidget + QtUiTest::SelectWidget) + +public: + TestMenuBar(QObject*); + + virtual QString text() const; + virtual QString selectedText() const; + + virtual QStringList list() const; + virtual QRect visualRect(QString const&) const; + virtual bool ensureVisible(QString const&); + + virtual Qt::CheckState checkState() const; + + virtual bool canSelect(const QString&) const; + virtual bool select(const QString&); + + virtual bool isCheckable(const QString&); + virtual bool isChecked(const QString&) const; + virtual bool setChecked(const QString&, bool); + + virtual bool hasFocus() const; + + static bool canWrap(QObject*); + +signals: + void stateChanged(int); + void selected(const QString&); + +//private slots: +// void on_hovered(QAction*); +// void on_triggered(bool); +// void on_toggled(bool); + +private: + QMenuBar *q; + QAction *lastAction; + + QAction *actionForItem(QString const&) const; +}; + +} +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testpushbutton.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testpushbutton.cpp new file mode 100644 index 0000000..6d3bd35 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testpushbutton.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testpushbutton.h" +#include "testwidgetslog.h" + +#include <QMenu> +#include <QPushButton> + +namespace QtUiTest { + +TestPushButton::TestPushButton(QObject *_q) + : TestAbstractButton(_q), q(qobject_cast<QPushButton*>(_q)) +{} + +QStringList TestPushButton::list() const +{ + QStringList ret; + + QtUiTest::ListWidget *menu + = qtuitest_cast<QtUiTest::ListWidget*>(q->menu()); + + if (menu) + ret = menu->list(); + + return ret; +} + +QRect TestPushButton::visualRect(QString const &item) const +{ + TestWidgetsLog(); + QRect ret; + QtUiTest::ListWidget *lMenu + = qtuitest_cast<QtUiTest::ListWidget*>(q->menu()); + + if (lMenu) + ret = lMenu->visualRect(item); + return ret; +} + +bool TestPushButton::ensureVisible(QString const& item) +{ + bool ret = false; + + QtUiTest::ListWidget *menu + = qtuitest_cast<QtUiTest::ListWidget*>(q->menu()); + + if (menu) + ret = menu->ensureVisible(item); + + return ret; +} + +bool TestPushButton::canSelect(QString const &item) const +{ return list().contains(item); } + +bool TestPushButton::select(QString const &item) +{ + bool ret = false; + + QtUiTest::SelectWidget *menu + = qtuitest_cast<QtUiTest::SelectWidget*>(q->menu()); + + if (menu) + { + activate(); + ret = menu->select(item); + } + + return ret; +} + +bool TestPushButton::canWrap(QObject *o) +{ return qobject_cast<QPushButton*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testpushbutton.h b/old/plugins/qtuitest_widgets/qtwidgets/testpushbutton.h new file mode 100644 index 0000000..5a3f420 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testpushbutton.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTPUSHBUTTON_H +#define TESTPUSHBUTTON_H + +#include "testabstractbutton.h" + +class QPushButton; + +namespace QtUiTest { + +class TestPushButton : public TestAbstractButton, + public QtUiTest::ListWidget, public QtUiTest::SelectWidget +{ + Q_OBJECT + Q_INTERFACES( + QtUiTest::ListWidget + QtUiTest::SelectWidget) + +public: + TestPushButton(QObject*); + + virtual QStringList list() const; + virtual QRect visualRect(QString const&) const; + virtual bool ensureVisible(QString const&); + + virtual bool canSelect(const QString&) const; + virtual bool select(const QString&); + + static bool canWrap(QObject*); + +private: + QPushButton *q; +}; + +} + +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtabbar.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testtabbar.cpp new file mode 100644 index 0000000..4a7bd8a --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtabbar.cpp @@ -0,0 +1,231 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testtabbar.h" + +#include "testwidgetslog.h" + +#include <QTabBar> +#include <QTabWidget> +#include <QToolButton> + +namespace QtUiTest { + +TestTabBar::TestTabBar(QObject *_q) + : TestWidget(_q), q(qobject_cast<QTabBar*>(_q)) +{ + connect(q, SIGNAL(currentChanged(int)), + this, SLOT(on_currentChanged(int))); +} + +void TestTabBar::on_currentChanged(int index) +{ emit selected(q->tabText(index)); } + +QString TestTabBar::text() const +{ return list().join("\n"); } + +QString TestTabBar::selectedText() const +{ return q->tabText(q->currentIndex()); } + +QStringList TestTabBar::list() const +{ + QStringList ret; + for (int i = 0, max = q->count(); i < max; ++i) + ret << q->tabText(i); + return ret; +} + +QRect TestTabBar::visualRect(QString const &item) const +{ + int index = indexForItem(item); + if (index != -1) + return q->visibleRegion().subtracted(q->childrenRegion()).intersected(QRegion(q->tabRect(index))).boundingRect(); + else + return QRect(); +} + +bool TestTabBar::ensureVisible(QString const& item) +{ + /* First, find desired index. */ + int desired = indexForItem(item); + if (-1 == desired) return false; + + QToolButton* leftB = 0; + QToolButton* rightB = 0; + + QList<QToolButton*> buttons = q->findChildren<QToolButton*>(); + QRegion buttonRegion; + foreach (QToolButton* b, buttons) { + if (b->arrowType() == Qt::LeftArrow) { + leftB = b; + buttonRegion |= b->geometry(); + } else if (b->arrowType() == Qt::RightArrow) { + rightB = b; + buttonRegion |= b->geometry(); + } + } + QRect buttonRect = buttonRegion.boundingRect(); + + int clicks = 0; + /* While desired tab isn't visible... */ + while (q->visibleRegion().subtracted(buttonRect).intersected( q->tabRect(desired) ).isEmpty() + && clicks < 50) { + + TestWidgetsLog() << "visible:" << q->visibleRegion().boundingRect() << "buttons:" << buttonRect << "tab:" << q->tabRect(desired); + + QObject* button = 0; + + /* Shall we go to the left or the right? */ + if (q->tabRect(desired).left() >= q->visibleRegion().subtracted(buttonRect).boundingRect().right()) + button = rightB; + else + button = leftB; + + QtUiTest::ActivateWidget* aw + = qtuitest_cast<QtUiTest::ActivateWidget*>(button); + if (!aw) return false; + aw->activate(); + + ++clicks; + } + + return !q->visibleRegion().subtracted(buttonRect).intersected( q->tabRect(desired) ).isEmpty(); +} + +bool TestTabBar::canSelect(QString const& item) const +{ + return indexForItem(item) != -1; +} + +bool isAncestor(QObject* parent, QObject* child) +{ + bool ret = false; + QObject* p = child; + while (p && !ret) { + ret = (p == parent); + p = p->parent(); + } + return ret; +} + +bool TestTabBar::select(QString const& item) +{ + using namespace QtUiTest; + + QStringList allTabs; + int desired = -1; + desired = indexForItem(item); + for (int i = 0, max = q->count(); i < max && -1 == desired; ++i) { + if (q->tabText(i) == item) + desired = i; + allTabs << q->tabText(i); + } + if (-1 == desired) { + setErrorString( + "Could not select tab '" + item + "' because there is no tab with that text"); + return false; + } + if (q->currentIndex() == desired) return true; + + QString originalTab = q->tabText(q->currentIndex()); + + if (mousePreferred()) { + if (!ensureVisible(item)) return false; + QPoint p = visualRect(item).center(); + if (!ensureVisiblePoint(p)) return false; + mouseClick(mapToGlobal(p)); + QtUiTest::waitForSignal(q, SIGNAL(currentChanged(int))); + if (q->currentIndex() != desired) { + setErrorString( + "Clicked on tab '" + item + "' but it did not appear to become selected.\n" + "Selected tab is: " + selectedText()); + return false; + } + return true; + } + + if (!setFocus()) return false; + + Qt::Key key; + int diff = 0; + if (desired < q->currentIndex()) { + key = Qt::Key_Left; + diff = q->currentIndex() - desired; + } + else { + key = Qt::Key_Right; + diff = desired - q->currentIndex(); + } + for (int i = 0; i < diff; ++i) { + if (!setFocus()) return false; + if (!keyClick(q, SIGNAL(currentChanged(int)), key)) + return false; + } + + if (q->currentIndex() == desired) return true; + setErrorString( + QString("Can't change tabs: pressed the %1 key %2 times which should have " + "moved from '%3' to '%4', but the current tab ended up as '%5'.") + .arg((key == Qt::Key_Right) ? "Right" : "Left") + .arg(diff) + .arg(originalTab) + .arg(item) + .arg(q->tabText(q->currentIndex())) + ); + return false; +} + +int TestTabBar::indexForItem(QString const& item) const +{ + for (int i = 0, max = q->count(); i < max; ++i) { + if (q->tabText(i) == item || labelText(q->tabText(i)) == item) + return i; + } + return -1; +} + +bool TestTabBar::inherits(QtUiTest::WidgetType type) const +{ return (QtUiTest::TabBar == type); } + +bool TestTabBar::canWrap(QObject *o) +{ return qobject_cast<QTabBar*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtabbar.h b/old/plugins/qtuitest_widgets/qtwidgets/testtabbar.h new file mode 100644 index 0000000..b636bec --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtabbar.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTTABBAR_H +#define TESTTABBAR_H + +#include <testwidget.h> + +class QTabBar; + +namespace QtUiTest { + +class TestTabBar : public TestWidget, + public QtUiTest::TextWidget, + public QtUiTest::ListWidget, + public QtUiTest::SelectWidget +{ + Q_OBJECT + Q_INTERFACES( + QtUiTest::TextWidget + QtUiTest::ListWidget + QtUiTest::SelectWidget) + +public: + TestTabBar(QObject*); + + virtual QString text() const; + virtual QString selectedText() const; + + virtual QStringList list() const; + virtual QRect visualRect(QString const&) const; + virtual bool ensureVisible(QString const&); + + virtual bool canSelect(QString const&) const; + virtual bool select(QString const&); + + virtual bool inherits(QtUiTest::WidgetType) const; + + static bool canWrap(QObject*); + +signals: + void selected(const QString&); + +private slots: + void on_currentChanged(int); + +private: + int indexForItem(QString const&) const; + QTabBar *q; +}; + +} + +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtext.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testtext.cpp new file mode 100644 index 0000000..e62cc27 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtext.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testtext.h" +#include "testwidgetslog.h" + +#include <QPointer> +#include <QVariant> + +using namespace QtUiTest; + +bool TestText::enterText(QObject* q, QString const& item, QString const& expectedText, bool commit) +{ + QByteArray textChanged = textChangedSignal(q); + TextWidget* tw = qtuitest_cast<TextWidget*>(q); + + foreach (QChar const& c, item) { + TestWidgetsLog() << asciiToModifiers(c.toLatin1()); + if (!keyClick(q, textChanged, asciiToKey(c.toLatin1()), asciiToModifiers(c.toLatin1()) )) + return false; + } + + QString newText = tw->text(); + if (newText != expectedText) { + setErrorString(QString("After entering text, expected text of:\n%1\nBut text was:\n%2") + .arg(expectedText) + .arg(newText)); + return false; + } + + if (commit) { +#ifdef Q_OS_SYMBIAN + keyClick(Qt::Key_Select); +#else + QtUiTest::Widget* w = qtuitest_cast<QtUiTest::Widget*>(q); + if (w) return w->setEditFocus(false); +#endif + } + + return true; +} + +bool TestText::enterTextByProxy(QtUiTest::InputWidget* proxy, QObject* q, QString const& item, QString const& expectedText, bool commit) +{ + TextWidget* tw = qtuitest_cast<TextWidget*>(q); + QByteArray textChanged = textChangedSignal(q); + QPointer<QObject> safeQ(q); + + if (!proxy->enter(item, !commit)) return false; + + QString newText; + + for (int i = expectedText.length(); i != 0; --i) { + if (!safeQ) { + setErrorString("Widget was destroyed while entering text."); + return false; + } + newText = tw->text(); + if (newText == expectedText) { + break; + } + if (!waitForSignal(q, textChanged)) { + setErrorString("Text did not change on focused widget due to key clicks"); + return false; + } + } + + if (newText != expectedText) newText = tw->text(); + if (newText != expectedText) { + setErrorString(QString("After entering text, expected text of:\n%1\nBut text was:\n%2") + .arg(expectedText) + .arg(newText)); + return false; + } + + return true; +} + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtext.h b/old/plugins/qtuitest_widgets/qtwidgets/testtext.h new file mode 100644 index 0000000..6168c1e --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtext.h @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTTEXT_H +#define TESTTEXT_H + +#include <qtuitestnamespace.h> +#include <qrect.h> +#include <qpoint.h> +#include "testwidgetslog.h" + +namespace QtUiTest { + +namespace TestText { + + inline + QByteArray textChangedSignal(QObject* q) + { + QByteArray textChangedSignal("textChanged(QString)"); + if (-1 == q->metaObject()->indexOfSignal(textChangedSignal)) { + textChangedSignal = "textChanged()"; + } + textChangedSignal.prepend(QSIGNAL_CODE); + return textChangedSignal; + } + + // Erase the text in the widget q by using key clicks + template <typename T> inline + bool eraseTextByKeys(T* q) + { + using namespace QtUiTest; + + if (!q->hasFocus()) { + setErrorString("Cannot erase text from unfocused widget."); + return false; + } + + Widget* w = qtuitest_cast<Widget*>(q); + bool hadEditFocus = w->hasEditFocus(); + if (!w->setEditFocus(true)) { + setErrorString("Couldn't erase text from widget: couldn't give edit focus to widget."); + return false; + } + + const int MAX = q->text().length()+1; + int i = 0; + + int pos = q->cursorPosition(); + int oldPos = -1; + TestWidgetsLog() << "pos" << pos << "MAX" << MAX; + + while (oldPos != pos && (++i < MAX) && (pos < MAX-1)) { + keyClick(q, SIGNAL(cursorPositionChanged(int,int)), Qt::Key_Right); + oldPos = pos; + pos = q->cursorPosition(); + } + + if (i >= MAX) { + setErrorString("Could not move cursor to rightmost position in widget."); + return false; + } + + QByteArray textChanged = textChangedSignal(q); + i = 0; + do { + if (!keyClick(q, textChanged, Qt::Key_Backspace)) + return false; + } while (q->cursorPosition() != 0 && (++i < MAX)); + + if (i >= MAX || !q->text().isEmpty()) { + setErrorString("Could not erase all text by pressing backspace."); + return false; + } + + if (!w->setEditFocus(hadEditFocus)) { + setErrorString("Couldn't return widget to original edit focus state."); + return false; + } + + return true; + } + + template <typename T> inline + bool eraseTextByMouse(T* q) + { +// QtUiTest::setErrorString("Erasing text by mouse is not implemented."); +// return false; + + //FIXME: For now, erase text using keys. Not sure if erasing text using + // the mouse makes sense in Qt. + return eraseTextByKeys(q); + } + + bool enterText(QObject* q, QString const& item, QString const& expectedText, bool commit = true); + bool enterTextByProxy(QtUiTest::InputWidget* proxy, QObject* q, QString const& item, QString const& expectedText, bool commit = true); +}; + +} + +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtextedit.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testtextedit.cpp new file mode 100644 index 0000000..9e43324 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtextedit.cpp @@ -0,0 +1,298 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testtext.h" +#include "testtextedit.h" +#include "testwidgetslog.h" + +#include <QLayout> +#include <QPointer> +#include <QTextDocumentFragment> +#include <QTextEdit> +#include <QTextBlock> +#include <QTextFragment> +#include <QScrollBar> + +namespace QtUiTest { + +TestTextEdit::TestTextEdit(QObject *_q) + : TestWidget(_q) + , lastEntered() + , lastCursorPosition(-1) + , committed(false) + , q(qobject_cast<QTextEdit*>(_q)) +{ + lastCursorPosition = cursorPosition(); + connect(q, SIGNAL(textChanged()), this, SLOT(onTextChanged())); + connect(q, SIGNAL(textChanged()), this, SIGNAL(textChanged())); + connect(q, SIGNAL(cursorPositionChanged()), this, SLOT(onCursorPositionChanged())); +} + +QString TestTextEdit::text() const +{ return q->toPlainText(); } + +QString TestTextEdit::selectedText() const +{ return q->textCursor().selection().toPlainText(); } + +QStringList TestTextEdit::list() const +{ + QStringList ret; + QTextDocument *doc = q->document(); + + for (int i = 0, blockCount = doc->blockCount(); i < blockCount; ++i) { + QTextBlock block = doc->findBlockByNumber(i); + QTextBlock::iterator it; + for (it = block.begin(); !(it.atEnd()); ++it) { + QTextFragment fragment = it.fragment(); + if (fragment.isValid() && fragment.charFormat().isAnchor()) { + ret << fragment.text(); + } + } + } + + return ret; +} + +QTextFragment TestTextEdit::fragmentForItem(QString const &item) const +{ + QTextFragment ret; + QTextDocument *doc = q->document(); + + for (int i = 0, blockCount = doc->blockCount(); i < blockCount; ++i) { + QTextBlock block = doc->findBlockByNumber(i); + QTextBlock::iterator it; + for (it = block.begin(); !(it.atEnd()); ++it) { + QTextFragment fragment = it.fragment(); + if (fragment.isValid() && fragment.charFormat().isAnchor() && + fragment.text() == item) { + return fragment; + } + } + } + + return ret; +} + +QRect TestTextEdit::visualRect(QString const &item) const +{ + return visualRect(fragmentForItem(item)); +} + +QRect TestTextEdit::visualRect(QTextFragment const &fragment) const +{ + QRect ret; + + if (fragment.isValid()) { + QTextCursor cursor(q->document()); + cursor.setPosition(fragment.position()+1); + ret = q->cursorRect(cursor); + } + + return ret; +} + +bool TestTextEdit::canEnter(QVariant const& item) const +{ + return item.canConvert<QString>(); +} + +bool TestTextEdit::enter(QVariant const& item, bool noCommit) +{ + if (!canEnter(item)) return false; + + bool hadEditFocus = hasEditFocus(); + + if (!hadEditFocus && !setEditFocus(true)) return false; + + using namespace QtUiTest; + + QPointer<QObject> safeThis = this; + if (!safeThis) { + setErrorString("Widget was destroyed while entering text."); + return false; + } + + QString oldText = text(); + QString itemString = item.toString(); + QString expectedText = oldText; + expectedText.insert(q->textCursor().position(), itemString); + + /* If there's text currently in the field, and we committed it, + then erase it first. */ + if (!oldText.isEmpty() && committed) { + if (QtUiTest::mousePreferred()) { + if (!TestText::eraseTextByMouse(this)) return false; + } else { + if (!TestText::eraseTextByKeys(this)) return false; + } + expectedText = itemString; + } + + InputWidget* iw = qtuitest_cast<InputWidget*>(inputProxy()); + + if (!safeThis) { + setErrorString("Widget was destroyed while entering text."); + return false; + } + + TestWidgetsLog() << iw; + + if (iw) { + if (!TestText::enterTextByProxy(iw, q, itemString, expectedText, !noCommit)) return false; + } else { + if (!TestText::enterText(q, itemString, expectedText, !noCommit)) return false; + } + + if (!safeThis) { + setErrorString("Widget was destroyed while entering text."); + return false; + } + + if (!noCommit && hasEditFocus()) { + if (!setEditFocus(false)) { + return false; + } + } + + committed = !noCommit; + + return true; +} + +bool TestTextEdit::canSelect(QString const &item) const +{ return list().contains(item); } + +bool TestTextEdit::ensureVisible(QTextFragment const &item) +{ + QPoint p = visualRect(item).center(); + + if (q->viewport()->rect().contains(p)) { + TestWidgetsLog() << "item is already visible"; + return true; + } + + if (!QtUiTest::mousePreferred()) + return false; + + /* Figure out the points to click for scrolling in each direction */ + QScrollBar *vbar = q->verticalScrollBar(); + QScrollBar *hbar = q->horizontalScrollBar(); + QPoint up = vbar->mapToGlobal(QPoint(vbar->width()/2,5)); + QPoint down = vbar->mapToGlobal(QPoint(vbar->width()/2,vbar->height()-5)); + QPoint left = hbar->mapToGlobal(QPoint(5, hbar->height()/2)); + QPoint right = hbar->mapToGlobal(QPoint(hbar->width()-5,hbar->height()/2)); + + // While p is above rect... + while (p.y() < q->viewport()->rect().top()) { + if (!vbar->isVisible()) return false; + TestWidgetsLog() << "up" << "\nrect:" << rect() << "p:" << p; + QtUiTest::mouseClick(up); + waitForSignal(vbar, SIGNAL(valueChanged(int))); + p = visualRect(item).center(); + } + // While p is below rect... + while (p.y() > q->viewport()->rect().bottom()) { + if (!vbar->isVisible()) return false; + TestWidgetsLog() << "down" << "\nrect:" << rect() << "p:" << p; + QtUiTest::mouseClick(down); + waitForSignal(vbar, SIGNAL(valueChanged(int))); + p = visualRect(item).center(); + } + // While p is left of rect... + while (p.x() < q->viewport()->rect().left()) { + if (!hbar->isVisible()) return false; + TestWidgetsLog() << "left" << "\nrect:" << rect() << "p:" << p; + QtUiTest::mouseClick(left); + waitForSignal(hbar, SIGNAL(valueChanged(int))); + p = visualRect(item).center(); + } + // While p is right of rect... + while (p.x() > q->viewport()->rect().right()) { + if (!hbar->isVisible()) return false; + TestWidgetsLog() << "right" << "\nrect:" << rect() << "p:" << p; + QtUiTest::mouseClick(right); + waitForSignal(hbar, SIGNAL(valueChanged(int))); + p = visualRect(item).center(); + } + + if (!q->viewport()->rect().contains(p)) { + TestWidgetsLog() << "failed" << "\nrect:" << q->viewport()->rect() << "p:" << p; + return false; + } + + return true; +} + +bool TestTextEdit::select(QString const &item) +{ + QTextFragment fragment = fragmentForItem(item); + if (!fragment.isValid()) return false; + ensureVisible(fragment); + QPoint pos = visualRect(item).center(); + QtUiTest::mouseClick(q->viewport()->mapToGlobal(pos), Qt::LeftButton); + return true; + +} + +bool TestTextEdit::canWrap(QObject *o) +{ return qobject_cast<QTextEdit*>(o); } + +int TestTextEdit::cursorPosition() const +{ + return q->textCursor().position(); +} + +void TestTextEdit::onTextChanged() +{ + if (!hasFocus() || !isVisible()) return; + if (q->toPlainText() == lastEntered) return; + lastEntered = q->toPlainText(); + emit entered(lastEntered); +} + +void TestTextEdit::onCursorPositionChanged() +{ + int prev = lastCursorPosition; + lastCursorPosition = cursorPosition(); + emit cursorPositionChanged(prev, lastCursorPosition); +} + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtextedit.h b/old/plugins/qtuitest_widgets/qtwidgets/testtextedit.h new file mode 100644 index 0000000..0795baf --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtextedit.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTTEXTEDIT_H +#define TESTTEXTEDIT_H + +#include <testwidget.h> + +class QTextEdit; +class QTextFragment; + +namespace QtUiTest { + +class TestTextEdit : public TestWidget, + public QtUiTest::TextWidget, + public QtUiTest::ListWidget, + public QtUiTest::SelectWidget +{ + Q_OBJECT + Q_INTERFACES( + QtUiTest::TextWidget + QtUiTest::ListWidget + QtUiTest::SelectWidget) + +public: + TestTextEdit(QObject*); + + virtual QString text() const; + virtual QString selectedText() const; + + virtual QStringList list() const; + virtual QRect visualRect(QString const&) const; + + virtual bool canEnter(QVariant const&) const; + virtual bool enter(QVariant const&,bool); + + virtual bool canSelect(QString const&) const; + virtual bool select(QString const&); + + static bool canWrap(QObject*); + + int cursorPosition() const; + +signals: + void cursorPositionChanged(int,int); + void textChanged(); + void entered(QVariant const&); + +protected: + QTextFragment fragmentForItem(QString const&) const; + virtual QRect visualRect(QTextFragment const&) const; + virtual bool ensureVisible(QTextFragment const&); + +private slots: + void onTextChanged(); + void onCursorPositionChanged(); + +private: + QString lastEntered; + int lastCursorPosition; + bool committed; + QTextEdit *q; +}; + +} + +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtimeedit.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testtimeedit.cpp new file mode 100644 index 0000000..99fb9b4 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtimeedit.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testtimeedit.h" +#include "testwidgetslog.h" + +#include <QTimeEdit> + +namespace QtUiTest { + +TestTimeEdit::TestTimeEdit(QObject* _q) + : TestDateTimeEdit(_q), q(qobject_cast<QTimeEdit*>(_q)) +{ + TestWidgetsLog(); + + disconnect(q, SIGNAL(dateTimeChanged(QDateTime)), this, 0); + connect(q, SIGNAL(dateTimeChanged(QDateTime)), + this, SLOT(onDateTimeChanged(QDateTime))); +} + +void TestTimeEdit::onDateTimeChanged(QDateTime const& dt) +{ + emit entered(dt.time()); +} + +QString TestTimeEdit::text() const +{ + TestWidgetsLog(); + return q->time().toString(q->displayFormat()); +} + +QVariant TestTimeEdit::value() const +{ + return q->time(); +} + +bool TestTimeEdit::canWrap(QObject *o) +{ return qobject_cast<QTimeEdit*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtimeedit.h b/old/plugins/qtuitest_widgets/qtwidgets/testtimeedit.h new file mode 100644 index 0000000..d110958 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtimeedit.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTTIMEEDIT_H +#define TESTTIMEEDIT_H + +#include "testdatetimeedit.h" + +class QTimeEdit; + +namespace QtUiTest { + +class TestTimeEdit : public TestDateTimeEdit +{ + Q_OBJECT +public: + TestTimeEdit(QObject*); + + virtual QString text() const; + virtual QVariant value() const; + + static bool canWrap(QObject*); + +private slots: + void onDateTimeChanged(QDateTime const&); + +private: + QTimeEdit *q; +}; + +} + +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtoolbar.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testtoolbar.cpp new file mode 100644 index 0000000..390ad00 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtoolbar.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testtoolbar.h" +#include "testwidgetslog.h" + +#include <QToolBar> +#include <QAction> + +namespace QtUiTest { + +TestToolBar::TestToolBar(QObject *_q) + : TestWidget(_q), q(qobject_cast<QToolBar*>(_q)), lastAction(0) +{ + // For accurate ordering of events recording, these connections + // must come before all others. +// QtUiTest::connectFirst(q, SIGNAL(hovered(QAction*)), +// this, SLOT(on_hovered(QAction*))); +} + +QStringList TestToolBar::list() const +{ + QStringList ret; + + /* Iterate through every action */ + foreach( QAction *a, q->actions() ) { + if (!a->isVisible()) + continue; + QString t = a->text(); + t.replace("/","\\/"); + if (!t.isEmpty()) ret << t; + } + + return ret; +} + +QRect TestToolBar::visualRect(QString const &item) const +{ +//FIXME: Implement me + Q_UNUSED(item); + QRect ret; + return ret; +} + +bool TestToolBar::ensureVisible(QString const&) +{ return false; } + +QString TestToolBar::labelText() const +{ + return q->windowTitle(); +} + +QObject* TestToolBar::buddy() const +{ + return q; +} + +bool TestToolBar::canSelect(QString const &item) const +{ + return list().contains(item); +} + +bool TestToolBar::select(QString const &item) +{ +//FIXME: Implement me + Q_UNUSED(item); + return false; +} + +bool TestToolBar::hasFocus() const +{ + return q->hasFocus(); +} + +bool TestToolBar::canWrap(QObject *o) +{ return qobject_cast<QToolBar*>(o); } + +} diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtoolbar.h b/old/plugins/qtuitest_widgets/qtwidgets/testtoolbar.h new file mode 100644 index 0000000..817b36e --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtoolbar.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTTOOLBAR_H +#define TESTTOOLBAR_H + +#include <testwidget.h> + +#include <QtGlobal> + +class QToolBar; +class QAction; + +namespace QtUiTest { + +class TestToolBar : public TestWidget, + public QtUiTest::ListWidget, public QtUiTest::LabelWidget, + public QtUiTest::SelectWidget +{ + Q_OBJECT + Q_INTERFACES( + QtUiTest::ListWidget + QtUiTest::LabelWidget + QtUiTest::SelectWidget) + +public: + TestToolBar(QObject*); + + virtual QStringList list() const; + virtual QRect visualRect(QString const&) const; + virtual bool ensureVisible(QString const&); + + virtual QString labelText() const; + virtual QObject* buddy() const; + + virtual bool canSelect(const QString&) const; + virtual bool select(const QString&); + + virtual bool hasFocus() const; + + static bool canWrap(QObject*); + +signals: + void stateChanged(int); + void selected(const QString&); + +private: + QToolBar *q; + QAction *lastAction; +}; + +} + +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtreeview.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testtreeview.cpp new file mode 100644 index 0000000..9fc41b2 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtreeview.cpp @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testtreeview.h" +#include "testwidgetslog.h" + +#include <QTreeView> + +#include <qtuitestnamespace.h> + +namespace QtUiTest { + +TestTreeView::TestTreeView(QObject *_q) + : TestAbstractItemView(_q), q(static_cast<QTreeView*>(_q)) +{ +} + +QString TestTreeView::selectedText() const +{ + TestWidgetsLog(); + + if (q->allColumnsShowFocus()) { + return selectedValue().toStringList().join(","); + } + + return TestAbstractItemView::selectedText(); +} + +QVariant TestTreeView::selectedValue() const +{ + TestWidgetsLog(); + + if (q->allColumnsShowFocus()) { + QStringList columnText; + QModelIndex selectedIndex = q->currentIndex(); + + for (int i = 0, max_i = q->model()->columnCount(selectedIndex.parent()); i < max_i; ++i) { + if (q->isColumnHidden(i)) continue; + QModelIndex sibling(selectedIndex.sibling(selectedIndex.row(), i)); + columnText << TestWidget::printable(sibling.data().toString()); + } + + return columnText; + } + + return TestAbstractItemView::selectedText(); +} + +QStringList TestTreeView::list() const +{ + class QModelListGetter : public QModelViewIterator<QTreeView> + { + public: + QModelListGetter(QTreeView *view) + : QModelViewIterator<QTreeView>(view) {}; + + QStringList getList() { + list.clear(); + iterate(view()->rootIndex(), view()->itemsExpandable()); + return list; + } + protected: + virtual void visit(QModelIndex const &index) + { + if (index == view()->rootIndex() && !view()->rootIsDecorated()) { + return; + } else if (view()->isColumnHidden(index.column())) { + return; + } + list << itemForIndex(index); + } + + virtual bool isRowHidden(int row, const QModelIndex& index) + { + return view()->isRowHidden(row, index); + } + + virtual QString itemForIndex(QModelIndex const& index) const + { + QString ret = TestWidget::printable(index.data().toString()); + ret.replace("/","\\\\/"); + + QModelIndex rootIndex = view()->rootIndex(); + if (index.parent() != rootIndex) { + ret = itemForIndex(index.parent()) + "/" + ret; + } + return ret; + } + QStringList list; + }; + + return QModelListGetter(q).getList(); +} + +QModelIndex TestTreeView::indexForItem(QString const &item) const +{ + return indexForItem(q->rootIndex(), item); +} + +QModelIndex TestTreeView::indexForItem(QModelIndex const &index, QString const &item) const +{ + QModelIndex ret; + static QRegExp slashRe("[^\\\\]/"); + + int ind; + if (0 != (ind = item.indexOf(slashRe)+1)) { + return indexForItem(indexForItem(index, item.left(ind)), item.mid(ind+1)); + } + + QString itemUnescaped(item); + itemUnescaped.replace("\\/", "/"); + + QAbstractItemModel *model = q->model(); + int count = 0; + + for (int i = 0, max_i = model->rowCount(index); i < max_i && count <= QTUITEST_MAX_LIST; ++i) { + if (q->isRowHidden(i, index)) continue; + for (int j = 0, max_j = model->columnCount(index); j < max_j && count <= QTUITEST_MAX_LIST; ++j) { + if (q->isColumnHidden(j)) continue; + if (model->hasIndex(i, j, index) && model->data(model->index(i, j, index)).toString() == itemUnescaped) { + if (ret.isValid()) { + qWarning("QtUitest: more than one item matches '%s' in item view", qPrintable(item)); + return ret; + } else { + ret = model->index(i, j, index); + } + } + } + } + + return ret; +} + +bool TestTreeView::ensureVisible(QModelIndex const &index) +{ + if (!index.isValid()) return false; + + if (q->itemsExpandable() && !q->isExpanded(index.parent())) { + ensureVisible(index.parent()); + //FIXME: Should expand using mouse/key clicks + q->setExpanded(index.parent(), true); + } + + return TestAbstractItemView::ensureVisible(index); +} + +bool TestTreeView::canSelect(QString const &item) const +{ + return indexForItem(item).isValid(); +} + +bool TestTreeView::canWrap(QObject* o) +{ return qobject_cast<QTreeView*>(o); } + +} diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtreeview.h b/old/plugins/qtuitest_widgets/qtwidgets/testtreeview.h new file mode 100644 index 0000000..fd6632a --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtreeview.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTTREEVIEW_H +#define TESTTREEVIEW_H + +#include "testabstractitemview.h" + +class QTreeView; + +namespace QtUiTest { + +class TestTreeView : public TestAbstractItemView +{ + Q_OBJECT + +public: + TestTreeView(QObject*); + + virtual QString selectedText() const; + virtual QVariant selectedValue() const; + virtual QStringList list() const; + virtual bool canSelect(QString const&) const; + static bool canWrap(QObject*); + +protected: + virtual QModelIndex indexForItem(QString const&) const; + QModelIndex indexForItem(QModelIndex const&, QString const&) const; + virtual bool ensureVisible(QModelIndex const&); + +private: + QTreeView *q; +}; + +} + +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtreewidget.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testtreewidget.cpp new file mode 100644 index 0000000..e011b0a --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtreewidget.cpp @@ -0,0 +1,212 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testtreewidget.h" +#include "testwidgetslog.h" + +#include <QTreeWidget> + +#include <qtuitestnamespace.h> + +namespace QtUiTest { + +TestTreeWidget::TestTreeWidget(QObject *_q) + : TestTreeView(_q), q(static_cast<QTreeWidget*>(_q)) +{ +} + +QStringList TestTreeWidget::list() const +{ + QStringList ret; + QTreeWidgetItemIterator it(q); + while (*it) { + for (int i=0; i<q->columnCount(); ++i) { + QtUiTest::ListWidget *lw = qtuitest_cast<QtUiTest::ListWidget*>(q->itemWidget(*it, i)); + if (lw) { + QStringList widgetList = lw->list(); + QString parent = itemName((*it)->parent(), i); + foreach (QString s, widgetList) { + ret << parent + "/" + s; + } + } else { + ret << itemName((*it), i); + } + } + ++it; + } + + return ret; +} + +QString TestTreeWidget::itemName(QTreeWidgetItem *item, int column) const +{ + QString ret; + if (!item) return ret; + ret = item->text(column); + if (item->parent() && item->parent() != q->invisibleRootItem()) { + return itemName(item->parent(), 0) + "/" + ret; + } + + return ret; +} + +QTreeWidgetItem *TestTreeWidget::itemLookup(QTreeWidgetItem *parent, QString const &name) const +{ + QTreeWidgetItem *ret = 0; + + for (int i=0, childCount = parent->childCount(); i < childCount; ++i) { + QTreeWidgetItem *item = parent->child(i); + for (int j=0, colCount = q->columnCount(); j < colCount; ++j) { + if (item->text(j) == name) { + return item; + } + } + } + + return ret; +} + +QWidget *TestTreeWidget::itemWidgetLookup(QString const &name, QTreeWidgetItem *parent, QString &remainder) const +{ + static QRegExp slashRe("[^\\\\]/"); + int ind; + QString top = name; + if ((ind = name.indexOf(slashRe)+1)) { + top = name.left(ind); + } + + QTreeWidgetItem *widgetItem = itemLookup(parent, top); + if (widgetItem == 0) { + remainder = name; + for (int i=0, colCount = q->columnCount(); i < colCount; ++i) { + QWidget *iw = q->itemWidget(parent->child(i), 0); + if (iw) { + QtUiTest::ListWidget *lw = qtuitest_cast<QtUiTest::ListWidget*>(iw); + QStringList widgetList = lw->list(); + if (widgetList.contains(remainder)) { + return iw; + } + } + } + return 0; + } else { + if (!widgetItem->isExpanded()) { + widgetItem->setExpanded(true); + } + return itemWidgetLookup(name.mid(ind+1), widgetItem, remainder); + } +} + +bool TestTreeWidget::select(QString const &item) +{ + if (!canSelect(item)) { + TestWidgetsLog() << "can't select" << item; + return false; + } + + QModelIndex index = indexForItem(item); + if (index.isValid()) { + return TestAbstractItemView::select(index); + } + + QString remainder; + QWidget *w = itemWidgetLookup(item, q->invisibleRootItem(), remainder); + QtUiTest::Widget *qw = qtuitest_cast<QtUiTest::Widget*>(w); + QtUiTest::ListWidget *lw = qtuitest_cast<QtUiTest::ListWidget*>(w); + qw->ensureVisibleRegion(lw->visualRect(remainder)); + QtUiTest::SelectWidget *sw = qtuitest_cast<QtUiTest::SelectWidget*>(w); + if (sw) { + return sw->select(remainder); + } + + return false; +} + +bool TestTreeWidget::ensureVisible(QString const &item) +{ + if (!canSelect(item)) { + TestWidgetsLog() << "can't select" << item; + return false; + } + + QModelIndex index = indexForItem(item); + if (index.isValid()) { + return TestAbstractItemView::ensureVisible(index); + } + + QString remainder; + QWidget *w = itemWidgetLookup(item, q->invisibleRootItem(), remainder); + QtUiTest::Widget *qw = qtuitest_cast<QtUiTest::Widget*>(w); + QtUiTest::ListWidget *lw = qtuitest_cast<QtUiTest::ListWidget*>(w); + return qw->ensureVisibleRegion(lw->visualRect(remainder)); +} + +QRect TestTreeWidget::visualRect(QString const &item) const +{ + QRect ret; + + QModelIndex index = indexForItem(item); + + if (index.isValid()) { + return q->visualRect(index); + } else { + QString remainder; + QWidget *w = itemWidgetLookup(item, q->invisibleRootItem(), remainder); + QtUiTest::ListWidget *lw = qtuitest_cast<QtUiTest::ListWidget*>(w); + if (lw) { + QRect rect = lw->visualRect(remainder); + rect.moveTopLeft( q->mapFromGlobal( w->mapToGlobal( rect.topLeft() ) ) ); + return rect; + } + } + + return ret; +} + +bool TestTreeWidget::canSelect(QString const &item) const +{ + return list().contains(item); +} + +bool TestTreeWidget::canWrap(QObject* o) +{ return qobject_cast<QTreeWidget*>(o); } + +} diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testtreewidget.h b/old/plugins/qtuitest_widgets/qtwidgets/testtreewidget.h new file mode 100644 index 0000000..292362c --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testtreewidget.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTTREEWIDGET_H +#define TESTTREEWIDGET_H + +#include "testtreeview.h" + +class QTreeWidget; +class QTreeWidgetItem; + +namespace QtUiTest { + +class TestTreeWidget : public TestTreeView +{ + Q_OBJECT + +public: + TestTreeWidget(QObject*); + + virtual QRect visualRect(QString const&) const; + virtual QStringList list() const; + virtual bool canSelect(QString const&) const; + virtual bool select(QString const&); + virtual bool ensureVisible(QString const&); + static bool canWrap(QObject*); + +protected: + QString itemName(QTreeWidgetItem *item, int column) const; + QTreeWidgetItem *itemLookup(QTreeWidgetItem *parent, QString const &name) const; + QWidget *itemWidgetLookup(QString const &name, QTreeWidgetItem *parent, QString &remainder) const; + +private: + QTreeWidget *q; +}; + +} + +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testwebview.cpp b/old/plugins/qtuitest_widgets/qtwidgets/testwebview.cpp new file mode 100644 index 0000000..101287c --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testwebview.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testwebview.h" +#include "testwidgetslog.h" + +#include <QWebView> +#include <QWebPage> +#include <QWebFrame> +#include <QWebElementCollection> + +namespace QtUiTest { + +TestWebView::TestWebView(QObject *_q) + : TestWidget(_q), m_progress(0.0), q(qobject_cast<QWebView*>(_q)) +{ + connect(q->page(), SIGNAL(loadProgress(int)), this, SLOT(on_progress(int))); +} + +QString TestWebView::text() const +{ + QWebPage *page = q->page(); + if (page && page->mainFrame()) { + return page->mainFrame()->toPlainText(); + } + return QString(); +} + +QString TestWebView::selectedText() const +{ + return q->selectedText(); +} + +QStringList TestWebView::list() const +{ + QStringList ret; + + QWebPage *page = q->page(); + if (page && page->mainFrame()) { + QWebElementCollection links = page->mainFrame()->findAllElements("a[href]"); + foreach (QWebElement el, links) { + QString str = TestWidget::printable(el.toPlainText()); + if (!str.isEmpty()) ret << str; + } + } + return ret; +} + +QWebElement TestWebView::elementForItem(QString const &item) const +{ + QWebElement ret; + QWebPage *page = q->page(); + if (page && page->mainFrame()) { + QWebElementCollection links = page->mainFrame()->findAllElements("a[href]"); + foreach (QWebElement el, links) { + if (TestWidget::printable(el.toPlainText()) == item) { + ret = el; + break; + } + } + } + return ret; +} + +QRect TestWebView::visualRect(QString const &item) const +{ + return visualRect(elementForItem(item)); +} + +QRect TestWebView::visualRect(QWebElement const &el) const +{ + QRect ret; + if (!el.isNull()) { + ret = el.geometry(); + ret.translate(el.webFrame()->geometry().topLeft()-el.webFrame()->scrollPosition()); + } + return ret; +} + +bool TestWebView::canSelect(QString const &item) const +{ return list().contains(item); } + +bool TestWebView::select(QString const &item) +{ + QWebElement el(elementForItem(item)); + if (el.isNull()) return false; + + QRect rect = visualRect(el); + QPoint pos = rect.center(); + QRect geometry = q->visibleRegion().boundingRect(); //q->geometry(); + QWebFrame *frame = el.webFrame(); + QRect horizScroll = frame->scrollBarGeometry(Qt::Horizontal); + QRect vertScroll = frame->scrollBarGeometry(Qt::Vertical); + if (!horizScroll.isEmpty()) { + geometry.setBottom(horizScroll.top()-1); + } + if (!vertScroll.isEmpty()) { + geometry.setRight(vertScroll.left()-1); + } + + if (!geometry.contains(pos, true)) { + //TODO: Is there a way to get the scrollbar up/down buttons? The scrollbar is + // not a QScrollBar. For now, use the API to scroll. + + // Scroll vertically + if (geometry.bottom() < rect.bottom()) { + frame->scroll(0, rect.bottom() - geometry.bottom() + geometry.height()/2); + } else if (geometry.top() > rect.top()) { + frame->scroll(0, rect.top() - geometry.top() - geometry.height()/2); + } + + // Scroll horizontally + if (geometry.right() < pos.x()) { + frame->scroll(rect.right() - geometry.right(), 0); + } else if (geometry.left() > pos.x()) { + frame->scroll(rect.left() - geometry.left(), 0); + } + + pos = visualRect(el).center(); + } + + QtUiTest::mouseClick(q->mapToGlobal(pos), Qt::LeftButton); + waitForSignal(q, SIGNAL(linkClicked(QUrl))); + return true; +} + +void TestWebView::on_progress(int p) +{ + if (m_progress == p/100.0) + return; + m_progress = p/100.0; +} + +QVariant TestWebView::getProperty(const QString& name) const +{ + QVariant ret; + + if (name.toUpper() == "PROGRESS") { + ret = m_progress; + } else { + ret = q->property(name.toLatin1()); + } + + return ret; +} + +bool TestWebView::canWrap(QObject *o) +{ return qobject_cast<QWebView*>(o); } + +}
\ No newline at end of file diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testwebview.h b/old/plugins/qtuitest_widgets/qtwidgets/testwebview.h new file mode 100644 index 0000000..78cfec0 --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testwebview.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTWEBVIEW_H +#define TESTWEBVIEW_H + +#include <testwidget.h> + +class QWebView; +class QWebElement; + +namespace QtUiTest { + +class TestWebView : public TestWidget, + public QtUiTest::TextWidget, + public QtUiTest::ListWidget, + public QtUiTest::SelectWidget +{ + Q_OBJECT + Q_INTERFACES( + QtUiTest::TextWidget + QtUiTest::ListWidget + QtUiTest::SelectWidget) + +public: + TestWebView(QObject*); + + virtual QString text() const; + virtual QString selectedText() const; + + virtual QStringList list() const; + virtual QRect visualRect(QString const&) const; + + virtual bool canSelect(QString const&) const; + virtual bool select(QString const&); + + virtual QVariant getProperty(const QString&) const; + + static bool canWrap(QObject*); + +protected: + QWebElement elementForItem(QString const&) const; + virtual QRect visualRect(QWebElement const&) const; + +private slots: + void on_progress(int); + +private: + qreal m_progress; + QWebView *q; +}; + +} + +#endif + diff --git a/old/plugins/qtuitest_widgets/qtwidgets/testwidgetslog.h b/old/plugins/qtuitest_widgets/qtwidgets/testwidgetslog.h new file mode 100644 index 0000000..01d2efe --- /dev/null +++ b/old/plugins/qtuitest_widgets/qtwidgets/testwidgetslog.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of QtUiTest. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTWIDGETSLOG_H +#define TESTWIDGETSLOG_H + +#include <QApplication> +#include <QStringList> + +#include <QDebug> +#define qLog(A) if (1); else qDebug() << #A + +/* + This header provides a slight convenience layer on top of qLog. + + By using the TestWidgetsLog macro in the same way qLog would normally be used, + a log message will be output which automatically includes the name of the current + function. +*/ + +namespace TestWidgetsLogImpl +{ + /* + Returns a log header to be output at the beginning of each TestWidgetsLog. + */ + inline QByteArray header(char const*,int,char const* function) + { + QString ret = qApp->applicationName(); + + // Extract just the name of the function (discard return type and arguments) + QString id; + QStringList l1 = QString(function).split(" "); + QStringList l2 = l1.filter("("); + if (l2.count()) id = l2.at(0); + else id = l1.at(0); + if (id.contains("(")) id = id.left(id.indexOf("(")); + + ret += " " + id; + + return ret.toLocal8Bit(); + } +}; + +#define TestWidgetsLog() qLog(QtUitestWidgets) << TestWidgetsLogImpl::header(__FILE__,__LINE__,Q_FUNC_INFO).constData() + +#endif + |