summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMailson Menezes <mailson.menezes@openbossa.org>2012-03-07 13:45:43 -0300
committerAnselmo L. S. Melo <anselmo.melo@openbossa.org>2012-03-15 14:20:40 +0100
commit3c99e49b2307d34c92538c1414a28a982f34a0c3 (patch)
treea1b8944081402da2b0da5ec78615273e6587617e
parentf4b432196c8f06cde25fca1aab6fd14a868ff2dc (diff)
UiAction tests
Change-Id: I359a97f601a149e4e1fcbfb22e57c489b8c42f72 Reviewed-by: Anselmo L. S. Melo <anselmo.melo@openbossa.org>
-rw-r--r--tests/auto/utils/uiaction/tst_uiaction.cpp408
-rw-r--r--tests/auto/utils/uiaction/uiaction.pro2
2 files changed, 241 insertions, 169 deletions
diff --git a/tests/auto/utils/uiaction/tst_uiaction.cpp b/tests/auto/utils/uiaction/tst_uiaction.cpp
index 2fa7adc..edab551 100644
--- a/tests/auto/utils/uiaction/tst_uiaction.cpp
+++ b/tests/auto/utils/uiaction/tst_uiaction.cpp
@@ -44,12 +44,16 @@
#include <UiHelpers/UiAction>
#include <UiHelpers/UiActionGroup>
-#include <qapplication.h>
-#include <qevent.h>
-#include <qaction.h>
-#include <qmenu.h>
-#include <qplatformtheme_qpa.h>
-#include <private/qguiapplication_p.h>
+#include <QCoreApplication>
+
+// #include <qapplication.h>
+// #include <qevent.h>
+// #include <qaction.h>
+// #include <qmenu.h>
+// #include <qplatformtheme_qpa.h>
+// #include <private/qguiapplication_p.h>
+
+QT_USE_NAMESPACE_UIHELPERS
class tst_UiAction : public QObject
{
@@ -60,7 +64,7 @@ public:
virtual ~tst_UiAction();
- // void updateState(QActionEvent *e);
+ void updateState(UiActionEvent *e);
public slots:
void initTestCase();
@@ -69,13 +73,13 @@ private slots:
void getSetCheck();
void setText_data();
void setText();
- void setIconText_data() { setText_data(); }
- void setIconText();
+ // void setIconText_data() { setText_data(); }
+ // void setIconText();
void actionEvent();
- void setStandardKeys();
- void alternateShortcuts();
- void enabledVisibleInteraction();
- void task200823_tooltip();
+ // void setStandardKeys();
+ // void alternateShortcuts();
+ // void enabledVisibleInteraction();
+ // void task200823_tooltip();
void task229128TriggeredSignalWithoutActiongroup();
void task229128TriggeredSignalWhenInActiongroup();
@@ -84,6 +88,7 @@ private:
int m_keyboardScheme;
UiAction *m_lastAction;
// QWidget *m_tstWidget;
+ QObject *m_tstObject;
};
// Testing get/set functions
@@ -101,12 +106,12 @@ void tst_UiAction::getSetCheck()
// QMenu * QAction::menu()
// void QAction::setMenu(QMenu *)
- QMenu *var2 = new QMenu(0);
+ /*QMenu *var2 = new QMenu(0);
obj1.setMenu(var2);
QCOMPARE(var2, obj1.menu());
obj1.setMenu((QMenu *)0);
QCOMPARE((QMenu *)0, obj1.menu());
- delete var2;
+ delete var2;*/
QCOMPARE(obj1.priority(), UiAction::NormalPriority);
obj1.setPriority(UiAction::LowPriority);
@@ -126,10 +131,63 @@ void tst_UiAction::getSetCheck()
// tst_QAction *tst;
// };
+class MyObject : public QObject
+{
+ Q_OBJECT
+public:
+ MyObject(tst_UiAction *tst, QObject *parent = 0) : QObject(parent), action(0) { this->tst = tst; }
+ virtual bool event(QEvent *e);
+ void addAction(UiAction *);
+ void removeAction(UiAction *);
+
+private:
+ tst_UiAction *tst;
+ UiAction *action;
+};
+
+bool MyObject::event(QEvent *e)
+{
+ switch (e->type()) {
+ case QEvent::ActionAdded:
+ case QEvent::ActionRemoved:
+ case QEvent::ActionChanged:
+ tst->updateState((UiActionEvent*)e);
+ break;
+ default:
+ return QObject::event(e);
+ }
+
+ return true;
+}
+
+void MyObject::addAction(UiAction *action)
+{
+ if (this->action == action)
+ removeAction(action);
+
+ UiAction *before = this->action;
+ this->action = action;
+
+ UiActionEvent e(QEvent::ActionAdded, action, before);
+ QCoreApplication::sendEvent(this, &e);
+}
+
+void MyObject::removeAction(UiAction *action)
+{
+ if (!action)
+ return;
+
+ if (this->action == action) {
+ this->action = 0;
+ UiActionEvent e(QEvent::ActionRemoved, action);
+ QCoreApplication::sendEvent(this, &e);
+ }
+}
+
tst_UiAction::tst_UiAction()// : m_keyboardScheme(QPlatformTheme::WindowsKeyboardScheme)
{
- if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
- m_keyboardScheme = theme->themeHint(QPlatformTheme::KeyboardScheme).toInt();
+ // if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
+ // m_keyboardScheme = theme->themeHint(QPlatformTheme::KeyboardScheme).toInt();
}
tst_UiAction::~tst_UiAction()
@@ -142,60 +200,69 @@ void tst_UiAction::initTestCase()
m_lastEventType = 0;
m_lastAction = 0;
- MyWidget *mw = new MyWidget(this);
- m_tstWidget = mw;
- mw->show();
- qApp->setActiveWindow(mw);
+ // MyWidget *mw = new MyWidget(this);
+ // m_tstWidget = mw;
+ // mw->show();
+ // qApp->setActiveWindow(mw);
+ MyObject *mo = new MyObject(this);
+ m_tstObject = mo;
}
void tst_UiAction::cleanupTestCase()
{
- QWidget *testWidget = m_tstWidget;
- if (testWidget) {
- testWidget->hide();
- delete testWidget;
- }
+ // QWidget *testWidget = m_tstWidget;
+ // if (testWidget) {
+ // testWidget->hide();
+ // delete testWidget;
+ // }
+ QObject *testObject = m_tstObject;
+ if (testObject)
+ delete testObject;
}
-void tst_QAction::setText_data()
+void tst_UiAction::setText_data()
{
QTest::addColumn<QString>("text");
- QTest::addColumn<QString>("iconText");
- QTest::addColumn<QString>("textFromIconText");
+ // QTest::addColumn<QString>("iconText");
+ // QTest::addColumn<QString>("textFromIconText");
//next we fill it with data
- QTest::newRow("Normal") << "Action" << "Action" << "Action";
- QTest::newRow("Ampersand") << "Search && Destroy" << "Search & Destroy" << "Search && Destroy";
- QTest::newRow("Mnemonic and ellipsis") << "O&pen File ..." << "Open File" << "Open File";
+ // QTest::newRow("Normal") << "Action" << "Action" << "Action";
+ // QTest::newRow("Ampersand") << "Search && Destroy" << "Search & Destroy" << "Search && Destroy";
+ // QTest::newRow("Mnemonic and ellipsis") << "O&pen File ..." << "Open File" << "Open File";
+ QTest::newRow("Normal") << "Action";
+ QTest::newRow("Ampersand") << "Search && Destroy";
+ QTest::newRow("Mnemonic and ellipsis") << "O&pen File ...";
}
-void tst_QAction::setText()
+void tst_UiAction::setText()
{
QFETCH(QString, text);
- QAction action(0);
+ UiAction action(0);
action.setText(text);
QCOMPARE(action.text(), text);
- QFETCH(QString, iconText);
- QCOMPARE(action.iconText(), iconText);
+ // QFETCH(QString, iconText);
+ // QCOMPARE(action.iconText(), iconText);
}
-void tst_QAction::setIconText()
-{
- QFETCH(QString, iconText);
-
- QAction action(0);
- action.setIconText(iconText);
- QCOMPARE(action.iconText(), iconText);
-
- QFETCH(QString, textFromIconText);
- QCOMPARE(action.text(), textFromIconText);
-}
+// void tst_QAction::setIconText()
+// {
+// QFETCH(QString, iconText);
+//
+// QAction action(0);
+// action.setIconText(iconText);
+// QCOMPARE(action.iconText(), iconText);
+//
+// QFETCH(QString, textFromIconText);
+// QCOMPARE(action.text(), textFromIconText);
+// }
-void tst_QAction::updateState(QActionEvent *e)
+// TODO: Use a QObject instead of a QWidget and reimplement QActionEvent
+void tst_UiAction::updateState(UiActionEvent *e)
{
if (!e) {
m_lastEventType = 0;
@@ -206,143 +273,147 @@ void tst_QAction::updateState(QActionEvent *e)
}
}
-void tst_QAction::actionEvent()
+void tst_UiAction::actionEvent()
{
- QAction a(0);
+ UiAction a(0);
a.setText("action text");
+ MyObject *tstMyObject = qobject_cast<MyObject*>(m_tstObject);
+
// add action
- m_tstWidget->addAction(&a);
+ tstMyObject->addAction(&a);
qApp->processEvents();
QCOMPARE(m_lastEventType, (int)QEvent::ActionAdded);
QCOMPARE(m_lastAction, &a);
// change action
- a.setText("new action text");
- qApp->processEvents();
-
- QCOMPARE(m_lastEventType, (int)QEvent::ActionChanged);
- QCOMPARE(m_lastAction, &a);
+ // a.setText("new action text");
+ // qApp->processEvents();
+ //
+ // QCOMPARE(m_lastEventType, (int)QEvent::ActionChanged);
+ // QCOMPARE(m_lastAction, &a);
// remove action
- m_tstWidget->removeAction(&a);
+ tstMyObject->removeAction(&a);
qApp->processEvents();
QCOMPARE(m_lastEventType, (int)QEvent::ActionRemoved);
QCOMPARE(m_lastAction, &a);
}
-//basic testing of standard keys
-void tst_QAction::setStandardKeys()
-{
- QAction act(0);
- act.setShortcut(QKeySequence("CTRL+L"));
- QList<QKeySequence> list;
- act.setShortcuts(list);
- act.setShortcuts(QKeySequence::Copy);
- QVERIFY(act.shortcut() == act.shortcuts().first());
-
- QList<QKeySequence> expected;
- const QKeySequence ctrlC = QKeySequence(QStringLiteral("CTRL+C"));
- const QKeySequence ctrlInsert = QKeySequence(QStringLiteral("CTRL+INSERT"));
- switch (m_keyboardScheme) {
- case QPlatformTheme::MacKeyboardScheme:
- expected << ctrlC;
- break;
- case QPlatformTheme::WindowsKeyboardScheme:
- expected << ctrlC << ctrlInsert;
- break;
- default: // X11
- expected << ctrlC << QKeySequence(QStringLiteral("F16")) << ctrlInsert;
- break;
- }
-
- QCOMPARE(act.shortcuts(), expected);
-}
-
-
-void tst_QAction::alternateShortcuts()
-{
- //test the alternate shortcuts (by adding more than 1 shortcut)
-
- QWidget *wid = m_tstWidget;
-
- {
- QAction act(wid);
- wid->addAction(&act);
- QList<QKeySequence> shlist = QList<QKeySequence>() << QKeySequence("CTRL+P") << QKeySequence("CTRL+A");
- act.setShortcuts(shlist);
-
- QSignalSpy spy(&act, SIGNAL(triggered()));
-
- act.setAutoRepeat(true);
- QTest::keyClick(wid, Qt::Key_A, Qt::ControlModifier);
- QCOMPARE(spy.count(), 1); //act should have been triggered
-
- act.setAutoRepeat(false);
- QTest::keyClick(wid, Qt::Key_A, Qt::ControlModifier);
- QCOMPARE(spy.count(), 2); //act should have been triggered a 2nd time
-
- //end of the scope of the action, it will be destroyed and removed from wid
- //This action should also unregister its shortcuts
- }
-
-
- //this tests a crash (if the action did not unregister its alternate shortcuts)
- QTest::keyClick(wid, Qt::Key_A, Qt::ControlModifier);
-}
-
-void tst_QAction::enabledVisibleInteraction()
-{
- QAction act(0);
- // check defaults
- QVERIFY(act.isEnabled());
- QVERIFY(act.isVisible());
-
- // !visible => !enabled
- act.setVisible(false);
- QVERIFY(!act.isEnabled());
- act.setVisible(true);
- QVERIFY(act.isEnabled());
- act.setEnabled(false);
- QVERIFY(act.isVisible());
-
- // check if shortcut is disabled if not visible
- m_tstWidget->addAction(&act);
- act.setShortcut(QKeySequence("Ctrl+T"));
- QSignalSpy spy(&act, SIGNAL(triggered()));
- act.setEnabled(true);
- act.setVisible(false);
- QTest::keyClick(m_tstWidget, Qt::Key_T, Qt::ControlModifier);
- QCOMPARE(spy.count(), 0); //act is not visible, so don't trigger
- act.setVisible(false);
- act.setEnabled(true);
- QTest::keyClick(m_tstWidget, Qt::Key_T, Qt::ControlModifier);
- QCOMPARE(spy.count(), 0); //act is not visible, so don't trigger
- act.setVisible(true);
- act.setEnabled(true);
- QTest::keyClick(m_tstWidget, Qt::Key_T, Qt::ControlModifier);
- QCOMPARE(spy.count(), 1); //act is visible and enabled, so trigger
-}
-
-void tst_QAction::task200823_tooltip()
-{
- QAction *action = new QAction("foo", 0);
- QString shortcut("ctrl+o");
- action->setShortcut(shortcut);
-
- // we want a non-standard tooltip that shows the shortcut
- action->setToolTip(QString("%1 (%2)").arg(action->text()).arg(action->shortcut().toString()));
+// TODO: Rewrite test after shortcuts in UiAction is written
+// //basic testing of standard keys
+// void tst_QAction::setStandardKeys()
+// {
+// QAction act(0);
+// act.setShortcut(QKeySequence("CTRL+L"));
+// QList<QKeySequence> list;
+// act.setShortcuts(list);
+// act.setShortcuts(QKeySequence::Copy);
+// QVERIFY(act.shortcut() == act.shortcuts().first());
+//
+// QList<QKeySequence> expected;
+// const QKeySequence ctrlC = QKeySequence(QStringLiteral("CTRL+C"));
+// const QKeySequence ctrlInsert = QKeySequence(QStringLiteral("CTRL+INSERT"));
+// switch (m_keyboardScheme) {
+// case QPlatformTheme::MacKeyboardScheme:
+// expected << ctrlC;
+// break;
+// case QPlatformTheme::WindowsKeyboardScheme:
+// expected << ctrlC << ctrlInsert;
+// break;
+// default: // X11
+// expected << ctrlC << QKeySequence(QStringLiteral("F16")) << ctrlInsert;
+// break;
+// }
+//
+// QCOMPARE(act.shortcuts(), expected);
+// }
+//
+//
+// void tst_QAction::alternateShortcuts()
+// {
+// //test the alternate shortcuts (by adding more than 1 shortcut)
+//
+// QWidget *wid = m_tstWidget;
+//
+// {
+// QAction act(wid);
+// wid->addAction(&act);
+// QList<QKeySequence> shlist = QList<QKeySequence>() << QKeySequence("CTRL+P") << QKeySequence("CTRL+A");
+// act.setShortcuts(shlist);
+//
+// QSignalSpy spy(&act, SIGNAL(triggered()));
+//
+// act.setAutoRepeat(true);
+// QTest::keyClick(wid, Qt::Key_A, Qt::ControlModifier);
+// QCOMPARE(spy.count(), 1); //act should have been triggered
+//
+// act.setAutoRepeat(false);
+// QTest::keyClick(wid, Qt::Key_A, Qt::ControlModifier);
+// QCOMPARE(spy.count(), 2); //act should have been triggered a 2nd time
+//
+// //end of the scope of the action, it will be destroyed and removed from wid
+// //This action should also unregister its shortcuts
+// }
+//
+//
+// //this tests a crash (if the action did not unregister its alternate shortcuts)
+// QTest::keyClick(wid, Qt::Key_A, Qt::ControlModifier);
+// }
- QString ref = QString("foo (%1)").arg(QKeySequence(shortcut).toString());
- QCOMPARE(action->toolTip(), ref);
-}
+// TODO: Needs 'enable' property to run the test
+// void tst_QAction::enabledVisibleInteraction()
+// {
+// QAction act(0);
+// // check defaults
+// QVERIFY(act.isEnabled());
+// QVERIFY(act.isVisible());
+//
+// // !visible => !enabled
+// act.setVisible(false);
+// QVERIFY(!act.isEnabled());
+// act.setVisible(true);
+// QVERIFY(act.isEnabled());
+// act.setEnabled(false);
+// QVERIFY(act.isVisible());
+//
+// // check if shortcut is disabled if not visible
+// m_tstWidget->addAction(&act);
+// act.setShortcut(QKeySequence("Ctrl+T"));
+// QSignalSpy spy(&act, SIGNAL(triggered()));
+// act.setEnabled(true);
+// act.setVisible(false);
+// QTest::keyClick(m_tstWidget, Qt::Key_T, Qt::ControlModifier);
+// QCOMPARE(spy.count(), 0); //act is not visible, so don't trigger
+// act.setVisible(false);
+// act.setEnabled(true);
+// QTest::keyClick(m_tstWidget, Qt::Key_T, Qt::ControlModifier);
+// QCOMPARE(spy.count(), 0); //act is not visible, so don't trigger
+// act.setVisible(true);
+// act.setEnabled(true);
+// QTest::keyClick(m_tstWidget, Qt::Key_T, Qt::ControlModifier);
+// QCOMPARE(spy.count(), 1); //act is visible and enabled, so trigger
+// }
+
+// void tst_QAction::task200823_tooltip()
+// {
+// QAction *action = new QAction("foo", 0);
+// QString shortcut("ctrl+o");
+// action->setShortcut(shortcut);
+//
+// // we want a non-standard tooltip that shows the shortcut
+// action->setToolTip(QString("%1 (%2)").arg(action->text()).arg(action->shortcut().toString()));
+//
+// QString ref = QString("foo (%1)").arg(QKeySequence(shortcut).toString());
+// QCOMPARE(action->toolTip(), ref);
+// }
-void tst_QAction::task229128TriggeredSignalWithoutActiongroup()
+void tst_UiAction::task229128TriggeredSignalWithoutActiongroup()
{
// test without a group
- QAction *actionWithoutGroup = new QAction("Test", qApp);
+ UiAction *actionWithoutGroup = new UiAction("Test", qApp);
QSignalSpy spyWithoutGroup(actionWithoutGroup, SIGNAL(triggered(bool)));
QCOMPARE(spyWithoutGroup.count(), 0);
actionWithoutGroup->trigger();
@@ -359,11 +430,11 @@ void tst_QAction::task229128TriggeredSignalWithoutActiongroup()
QCOMPARE(spyWithoutGroup.count(), 1);
}
-void tst_QAction::task229128TriggeredSignalWhenInActiongroup()
+void tst_UiAction::task229128TriggeredSignalWhenInActiongroup()
{
- QActionGroup ag(0);
- QAction *action = new QAction("Test", &ag);
- QAction *checkedAction = new QAction("Test 2", &ag);
+ UiActionGroup ag(0);
+ UiAction *action = new UiAction("Test", &ag);
+ UiAction *checkedAction = new UiAction("Test 2", &ag);
ag.addAction(action);
action->setCheckable(true);
ag.addAction(checkedAction);
@@ -371,7 +442,8 @@ void tst_QAction::task229128TriggeredSignalWhenInActiongroup()
checkedAction->setChecked(true);
QSignalSpy actionSpy(checkedAction, SIGNAL(triggered(bool)));
- QSignalSpy actionGroupSpy(&ag, SIGNAL(triggered(QAction *)));
+ qRegisterMetaType<UiAction*>("UiAction*");
+ QSignalSpy actionGroupSpy(&ag, SIGNAL(triggered(UiAction *)));
QCOMPARE(actionGroupSpy.count(), 0);
QCOMPARE(actionSpy.count(), 0);
checkedAction->trigger();
diff --git a/tests/auto/utils/uiaction/uiaction.pro b/tests/auto/utils/uiaction/uiaction.pro
index e543bda..32573ce 100644
--- a/tests/auto/utils/uiaction/uiaction.pro
+++ b/tests/auto/utils/uiaction/uiaction.pro
@@ -2,6 +2,6 @@ CONFIG += testcase
TARGET = tst_uiaction
QT += testlib uihelpers
-QT += gui-private core-private widgets
+QT += gui-private core-private
SOURCES += tst_uiaction.cpp