summaryrefslogtreecommitdiffstats
path: root/tests/auto/qactiongroup
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2009-03-23 10:18:55 +0100
committerSimon Hausmann <simon.hausmann@nokia.com>2009-03-23 10:18:55 +0100
commite5fcad302d86d316390c6b0f62759a067313e8a9 (patch)
treec2afbf6f1066b6ce261f14341cf6d310e5595bc1 /tests/auto/qactiongroup
Long live Qt 4.5!
Diffstat (limited to 'tests/auto/qactiongroup')
-rw-r--r--tests/auto/qactiongroup/.gitignore1
-rw-r--r--tests/auto/qactiongroup/qactiongroup.pro4
-rw-r--r--tests/auto/qactiongroup/tst_qactiongroup.cpp274
3 files changed, 279 insertions, 0 deletions
diff --git a/tests/auto/qactiongroup/.gitignore b/tests/auto/qactiongroup/.gitignore
new file mode 100644
index 0000000000..daba003e96
--- /dev/null
+++ b/tests/auto/qactiongroup/.gitignore
@@ -0,0 +1 @@
+tst_qactiongroup
diff --git a/tests/auto/qactiongroup/qactiongroup.pro b/tests/auto/qactiongroup/qactiongroup.pro
new file mode 100644
index 0000000000..d468815674
--- /dev/null
+++ b/tests/auto/qactiongroup/qactiongroup.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+SOURCES += tst_qactiongroup.cpp
+
+
diff --git a/tests/auto/qactiongroup/tst_qactiongroup.cpp b/tests/auto/qactiongroup/tst_qactiongroup.cpp
new file mode 100644
index 0000000000..acdb08917d
--- /dev/null
+++ b/tests/auto/qactiongroup/tst_qactiongroup.cpp
@@ -0,0 +1,274 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+
+#include <qcombobox.h>
+#include <qmainwindow.h>
+#include <qmenubar.h>
+#include <qmenu.h>
+#include <qtoolbar.h>
+
+
+#include <qaction.h>
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+class tst_QActionGroup : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QActionGroup();
+ virtual ~tst_QActionGroup();
+
+private slots:
+ void enabledPropagation();
+ void visiblePropagation();
+ void dropDownDeleted();
+ void exclusive();
+
+ void separators();
+ void testActionInTwoQActionGroup();
+};
+
+tst_QActionGroup::tst_QActionGroup()
+{
+}
+
+tst_QActionGroup::~tst_QActionGroup()
+{
+}
+
+void tst_QActionGroup::enabledPropagation()
+{
+ QActionGroup testActionGroup( 0 );
+
+ QAction* childAction = new QAction( &testActionGroup );
+ QAction* anotherChildAction = new QAction( &testActionGroup );
+ QAction* freeAction = new QAction(0);
+
+ QVERIFY( testActionGroup.isEnabled() );
+ QVERIFY( childAction->isEnabled() );
+
+ testActionGroup.setEnabled( false );
+ QVERIFY( !testActionGroup.isEnabled() );
+ QVERIFY( !childAction->isEnabled() );
+ QVERIFY( !anotherChildAction->isEnabled() );
+
+ childAction->setEnabled(true);
+ QVERIFY( !childAction->isEnabled());
+
+ anotherChildAction->setEnabled( false );
+
+ testActionGroup.setEnabled( true );
+ QVERIFY( testActionGroup.isEnabled() );
+ QVERIFY( childAction->isEnabled() );
+ QVERIFY( !anotherChildAction->isEnabled() );
+
+ testActionGroup.setEnabled( false );
+ QAction *lastChildAction = new QAction(&testActionGroup);
+
+ QVERIFY(!lastChildAction->isEnabled());
+ testActionGroup.setEnabled( true );
+ QVERIFY(lastChildAction->isEnabled());
+
+ freeAction->setEnabled(false);
+ testActionGroup.addAction(freeAction);
+ QVERIFY(!freeAction->isEnabled());
+ delete freeAction;
+}
+
+void tst_QActionGroup::visiblePropagation()
+{
+ QActionGroup testActionGroup( 0 );
+
+ QAction* childAction = new QAction( &testActionGroup );
+ QAction* anotherChildAction = new QAction( &testActionGroup );
+ QAction* freeAction = new QAction(0);
+
+ QVERIFY( testActionGroup.isVisible() );
+ QVERIFY( childAction->isVisible() );
+
+ testActionGroup.setVisible( false );
+ QVERIFY( !testActionGroup.isVisible() );
+ QVERIFY( !childAction->isVisible() );
+ QVERIFY( !anotherChildAction->isVisible() );
+
+ anotherChildAction->setVisible(false);
+
+ testActionGroup.setVisible( true );
+ QVERIFY( testActionGroup.isVisible() );
+ QVERIFY( childAction->isVisible() );
+
+ QVERIFY( !anotherChildAction->isVisible() );
+
+ testActionGroup.setVisible( false );
+ QAction *lastChildAction = new QAction(&testActionGroup);
+
+ QVERIFY(!lastChildAction->isVisible());
+ testActionGroup.setVisible( true );
+ QVERIFY(lastChildAction->isVisible());
+
+ freeAction->setVisible(false);
+ testActionGroup.addAction(freeAction);
+ QVERIFY(!freeAction->isVisible());
+ delete freeAction;
+}
+
+void tst_QActionGroup::exclusive()
+{
+ QActionGroup group(0);
+ group.setExclusive(false);
+ QVERIFY( !group.isExclusive() );
+
+ QAction* actOne = new QAction( &group );
+ actOne->setCheckable( true );
+ QAction* actTwo = new QAction( &group );
+ actTwo->setCheckable( true );
+ QAction* actThree = new QAction( &group );
+ actThree->setCheckable( true );
+
+ group.setExclusive( true );
+ QVERIFY( !actOne->isChecked() );
+ QVERIFY( !actTwo->isChecked() );
+ QVERIFY( !actThree->isChecked() );
+
+ actOne->setChecked( true );
+ QVERIFY( actOne->isChecked() );
+ QVERIFY( !actTwo->isChecked() );
+ QVERIFY( !actThree->isChecked() );
+
+ actTwo->setChecked( true );
+ QVERIFY( !actOne->isChecked() );
+ QVERIFY( actTwo->isChecked() );
+ QVERIFY( !actThree->isChecked() );
+}
+
+void tst_QActionGroup::dropDownDeleted()
+{
+ QSKIP("dropDownDeleted test for Qt 4.0 not expected to work since it is not implemented yet", SkipAll);
+
+ QMainWindow mw;
+ QToolBar *tb = new QToolBar(&mw);
+ QActionGroup *actGroup = new QActionGroup(&mw);
+
+ /// ### actGroup->setUsesDropDown(true);
+ QAction *actOne = new QAction(actGroup);
+ actOne->setText("test one");
+ QAction *actTwo = new QAction(actGroup);
+ actOne->setText("test one");
+ QAction *actThree= new QAction(actGroup);
+ actOne->setText("test one");
+
+ QListIterator<QAction*> it(actGroup->actions());
+ while (it.hasNext())
+ tb->addAction(it.next());
+
+ QList<QComboBox*> comboList = qFindChildren<QComboBox*>(tb);
+ QCOMPARE(comboList[0]->count(), 3);
+
+ delete actOne;
+ QCOMPARE((int)comboList[0]->count(), 2);
+ delete actTwo;
+ QCOMPARE((int)comboList[0]->count(), 1);
+ delete actThree;
+ QCOMPARE((int)comboList[0]->count(), 0);
+
+ delete actGroup;
+}
+
+void tst_QActionGroup::separators()
+{
+ QMainWindow mw;
+ QMenu menu(&mw);
+ QActionGroup actGroup(&mw);
+
+ mw.show();
+
+ QAction *action = new QAction(&actGroup);
+ action->setText("test one");
+
+ QAction *separator = new QAction(&actGroup);
+ separator->setSeparator(true);
+ actGroup.addAction(separator);
+
+ QListIterator<QAction*> it(actGroup.actions());
+ while (it.hasNext())
+ menu.addAction(it.next());
+
+ QCOMPARE((int)menu.actions().size(), 2);
+
+ it = QListIterator<QAction*>(actGroup.actions());
+ while (it.hasNext())
+ menu.removeAction(it.next());
+
+ QCOMPARE((int)menu.actions().size(), 0);
+
+ action = new QAction(&actGroup);
+ action->setText("test two");
+
+ it = QListIterator<QAction*>(actGroup.actions());
+ while (it.hasNext())
+ menu.addAction(it.next());
+
+ QCOMPARE((int)menu.actions().size(), 3);
+}
+
+void tst_QActionGroup::testActionInTwoQActionGroup()
+{
+ QAction action1("Action 1", this);
+
+ QActionGroup group1(this);
+ QActionGroup group2(this);
+
+ group1.addAction(&action1);
+ group2.addAction(&action1);
+
+ QCOMPARE(action1.actionGroup(), &group2);
+ QCOMPARE(group2.actions().first(), &action1);
+ QCOMPARE(group1.actions().isEmpty(), true);
+}
+
+QTEST_MAIN(tst_QActionGroup)
+#include "tst_qactiongroup.moc"