summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp10
-rw-r--r--tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp19
-rw-r--r--tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp106
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp40
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp14
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp52
-rw-r--r--tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp8
-rw-r--r--tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp8
-rw-r--r--tests/auto/widgets/kernel/qaction/tst_qaction.cpp6
-rw-r--r--tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp12
-rw-r--r--tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp57
-rw-r--r--tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp3
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp13
-rw-r--r--tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp2
-rw-r--r--tests/auto/widgets/widgets/qlabel/red@2x.pngbin0 -> 105 bytes
-rw-r--r--tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp24
-rw-r--r--tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp4
-rw-r--r--tests/auto/widgets/widgets/qmenubar/qmenubar.pro5
-rw-r--r--tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp24
-rw-r--r--tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm44
-rw-r--r--tests/auto/widgets/widgets/qstackedwidget/tst_qstackedwidget.cpp3
21 files changed, 314 insertions, 140 deletions
diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
index 82934982c4..d6a1c264c7 100644
--- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
@@ -350,8 +350,7 @@ void tst_QFileDialog2::task143519_deleteAndRenameActionBehavior()
// test based on task233037_selectingDirectory
struct TestContext {
- TestContext()
- : current(QDir::current()) {}
+ explicit TestContext(const QString &path) : current(path) {}
~TestContext() {
file.remove();
current.rmdir(test.dirName());
@@ -359,7 +358,9 @@ void tst_QFileDialog2::task143519_deleteAndRenameActionBehavior()
QDir current;
QDir test;
QFile file;
- } ctx;
+ };
+
+ TestContext ctx(tempDir.path());
// setup testbed
QVERIFY(ctx.current.mkdir("task143519_deleteAndRenameActionBehavior_test")); // ensure at least one item
@@ -373,6 +374,7 @@ void tst_QFileDialog2::task143519_deleteAndRenameActionBehavior()
QFileDialog fd;
fd.setViewMode(QFileDialog::List);
fd.setDirectory(ctx.test.absolutePath());
+ fd.selectFile(ctx.file.fileName());
fd.show();
QTest::qWaitForWindowActive(&fd);
@@ -387,7 +389,7 @@ void tst_QFileDialog2::task143519_deleteAndRenameActionBehavior()
// defaults
QVERIFY(openContextMenu(fd));
- QCOMPARE(fd.selectedFiles().size(), 1);
+ QCOMPARE(fd.selectedFiles(), QStringList(ctx.file.fileName()));
QCOMPARE(rm->isEnabled(), !fd.isReadOnly());
QCOMPARE(mv->isEnabled(), !fd.isReadOnly());
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
index ad7600c784..1acf885285 100644
--- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -1093,6 +1093,10 @@ static QSet<QString> fileListUnderIndex(const QFileSystemModel *model, const QMo
void tst_QFileSystemModel::specialFiles()
{
+#ifndef Q_OS_UNIX
+ QSKIP("Not implemented");
+#endif
+
QFileSystemModel model;
model.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
@@ -1101,23 +1105,8 @@ void tst_QFileSystemModel::specialFiles()
// as it will always return a valid index for existing files,
// even if the file is not visible with the given filter.
-#if defined(Q_OS_UNIX)
const QModelIndex rootIndex = model.setRootPath(QStringLiteral("/dev/"));
const QString testFileName = QStringLiteral("null");
-#elif defined(Q_OS_WIN)
- const QModelIndex rootIndex = model.setRootPath(flatDirTestPath);
-
- const QString testFileName = QStringLiteral("linkSource.lnk");
-
- QFile file(flatDirTestPath + QLatin1String("/linkTarget.txt"));
- QVERIFY(file.open(QIODevice::WriteOnly));
- file.close();
- QVERIFY(file.link(flatDirTestPath + '/' + testFileName));
-#else
- QSKIP("Not implemented");
- QModelIndex rootIndex;
- QString testFileName;
-#endif
QTRY_VERIFY(fileListUnderIndex(&model, rootIndex).contains(testFileName));
diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
index 2635a2ed82..0f63baa0e6 100644
--- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
+++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
@@ -1614,28 +1614,44 @@ class SetPage : public Operation
wizard->next();
}
QString describe() const { return QLatin1String("set page ") + QString::number(page); }
- const int page;
+ int page;
public:
- SetPage(int page) : page(page) {}
+ static QSharedPointer<SetPage> create(int page)
+ {
+ QSharedPointer<SetPage> o = QSharedPointer<SetPage>::create();
+ o->page = page;
+ return o;
+ }
};
class SetStyle : public Operation
{
void apply(QWizard *wizard) const { wizard->setWizardStyle(style); }
QString describe() const { return QLatin1String("set style ") + QString::number(style); }
- const QWizard::WizardStyle style;
+ QWizard::WizardStyle style;
public:
- SetStyle(QWizard::WizardStyle style) : style(style) {}
+ static QSharedPointer<SetStyle> create(QWizard::WizardStyle style)
+ {
+ QSharedPointer<SetStyle> o = QSharedPointer<SetStyle>::create();
+ o->style = style;
+ return o;
+ }
};
class SetOption : public Operation
{
void apply(QWizard *wizard) const { wizard->setOption(option, on); }
QString describe() const;
- const QWizard::WizardOption option;
- const bool on;
+ QWizard::WizardOption option;
+ bool on;
public:
- SetOption(QWizard::WizardOption option, bool on) : option(option), on(on) {}
+ static QSharedPointer<SetOption> create(QWizard::WizardOption option, bool on)
+ {
+ QSharedPointer<SetOption> o = QSharedPointer<SetOption>::create();
+ o->option = option;
+ o->on = on;
+ return o;
+ }
};
class OptionInfo
@@ -1660,16 +1676,16 @@ class OptionInfo
tags[QWizard::HaveCustomButton3] = "15/CB3";
for (int i = 0; i < 2; ++i) {
- QMap<QWizard::WizardOption, Operation *> operations_;
+ QMap<QWizard::WizardOption, QSharedPointer<Operation> > operations_;
foreach (QWizard::WizardOption option, tags.keys())
- operations_[option] = new SetOption(option, i == 1);
+ operations_[option] = SetOption::create(option, i == 1);
operations << operations_;
}
}
OptionInfo(OptionInfo const&);
OptionInfo& operator=(OptionInfo const&);
QMap<QWizard::WizardOption, QString> tags;
- QList<QMap<QWizard::WizardOption, Operation *> > operations;
+ QList<QMap<QWizard::WizardOption, QSharedPointer<Operation> > > operations;
public:
static OptionInfo &instance()
{
@@ -1678,7 +1694,7 @@ public:
}
QString tag(QWizard::WizardOption option) const { return tags.value(option); }
- Operation * operation(QWizard::WizardOption option, bool on) const
+ QSharedPointer<Operation> operation(QWizard::WizardOption option, bool on) const
{ return operations.at(on).value(option); }
QList<QWizard::WizardOption> options() const { return tags.keys(); }
};
@@ -1689,10 +1705,7 @@ QString SetOption::describe() const
+ QLatin1Char(on ? '1' : '0');
}
-Q_DECLARE_METATYPE(Operation *)
-Q_DECLARE_METATYPE(SetPage *)
-Q_DECLARE_METATYPE(SetStyle *)
-Q_DECLARE_METATYPE(SetOption *)
+Q_DECLARE_METATYPE(QVector<QSharedPointer<Operation> >)
class TestGroup
{
@@ -1709,14 +1722,17 @@ public:
combinations.clear();
}
- QList<Operation *> &add()
- { combinations << new QList<Operation *>; return *(combinations.last()); }
+ QVector<QSharedPointer<Operation> > &add()
+ {
+ combinations.resize(combinations.size() + 1);
+ return combinations.last();
+ }
void createTestRows()
{
for (int i = 0; i < combinations.count(); ++i) {
QTest::newRow((name.toLatin1() + ", row " + QByteArray::number(i)).constData())
- << (i == 0) << (type == Equality) << *(combinations.at(i));
+ << (i == 0) << (type == Equality) << combinations.at(i);
++nRows_;
}
}
@@ -1727,7 +1743,7 @@ private:
QString name;
Type type;
int nRows_;
- QList<QList<Operation *> *> combinations;
+ QVector<QVector<QSharedPointer<Operation> > > combinations;
};
class IntroPage : public QWizardPage
@@ -1811,9 +1827,9 @@ public:
}
}
- void applyOperations(const QList<Operation *> &operations)
+ void applyOperations(const QVector<QSharedPointer<Operation> > &operations)
{
- foreach (Operation * op, operations) {
+ foreach (const QSharedPointer<Operation> &op, operations) {
if (op) {
op->apply(this);
opsDescr += QLatin1Char('(') + op->describe() + QLatin1String(") ");
@@ -1833,31 +1849,29 @@ public:
class CombinationsTestData
{
TestGroup testGroup;
- QList<Operation *> pageOps;
- QList<Operation *> styleOps;
- QMap<bool, QList<Operation *> *> setAllOptions;
+ QVector<QSharedPointer<Operation> > pageOps;
+ QVector<QSharedPointer<Operation> > styleOps;
+ QMap<bool, QVector<QSharedPointer<Operation> > > setAllOptions;
public:
CombinationsTestData()
{
QTest::addColumn<bool>("ref");
QTest::addColumn<bool>("testEquality");
- QTest::addColumn<QList<Operation *> >("operations");
- pageOps << new SetPage(0) << new SetPage(1) << new SetPage(2);
- styleOps << new SetStyle(QWizard::ClassicStyle) << new SetStyle(QWizard::ModernStyle)
- << new SetStyle(QWizard::MacStyle);
+ QTest::addColumn<QVector<QSharedPointer<Operation> > >("operations");
+ pageOps << SetPage::create(0) << SetPage::create(1) << SetPage::create(2);
+ styleOps << SetStyle::create(QWizard::ClassicStyle) << SetStyle::create(QWizard::ModernStyle)
+ << SetStyle::create(QWizard::MacStyle);
#define SETPAGE(page) pageOps.at(page)
#define SETSTYLE(style) styleOps.at(style)
#define OPT(option, on) OptionInfo::instance().operation(option, on)
#define CLROPT(option) OPT(option, false)
#define SETOPT(option) OPT(option, true)
- setAllOptions[false] = new QList<Operation *>;
- setAllOptions[true] = new QList<Operation *>;
foreach (QWizard::WizardOption option, OptionInfo::instance().options()) {
- *setAllOptions.value(false) << CLROPT(option);
- *setAllOptions.value(true) << SETOPT(option);
+ setAllOptions[false] << CLROPT(option);
+ setAllOptions[true] << SETOPT(option);
}
-#define CLRALLOPTS *setAllOptions.value(false)
-#define SETALLOPTS *setAllOptions.value(true)
+#define CLRALLOPTS setAllOptions.value(false)
+#define SETALLOPTS setAllOptions.value(true)
}
int nRows() const { return testGroup.nRows(); }
@@ -1909,7 +1923,7 @@ public:
testGroup.createTestRows();
for (int i = 0; i < 2; ++i) {
- QList<Operation *> setOptions = *setAllOptions.value(i == 1);
+ QVector<QSharedPointer<Operation> > setOptions = setAllOptions.value(i == 1);
testGroup.reset("testAll 3.1");
testGroup.add() << setOptions;
@@ -1926,21 +1940,21 @@ public:
testGroup.createTestRows();
}
- foreach (Operation *pageOp, pageOps) {
+ foreach (const QSharedPointer<Operation> &pageOp, pageOps) {
testGroup.reset("testAll 4.1");
testGroup.add() << pageOp;
testGroup.add() << pageOp << pageOp;
testGroup.createTestRows();
for (int i = 0; i < 2; ++i) {
- QList<Operation *> optionOps = *setAllOptions.value(i == 1);
+ QVector<QSharedPointer<Operation> > optionOps = setAllOptions.value(i == 1);
testGroup.reset("testAll 4.2");
testGroup.add() << optionOps << pageOp;
testGroup.add() << pageOp << optionOps;
testGroup.createTestRows();
foreach (QWizard::WizardOption option, OptionInfo::instance().options()) {
- Operation *optionOp = OPT(option, i == 1);
+ QSharedPointer<Operation> optionOp = OPT(option, i == 1);
testGroup.reset("testAll 4.3");
testGroup.add() << optionOp << pageOp;
testGroup.add() << pageOp << optionOp;
@@ -1949,21 +1963,21 @@ public:
}
}
- foreach (Operation *styleOp, styleOps) {
+ foreach (const QSharedPointer<Operation> &styleOp, styleOps) {
testGroup.reset("testAll 5.1");
testGroup.add() << styleOp;
testGroup.add() << styleOp << styleOp;
testGroup.createTestRows();
for (int i = 0; i < 2; ++i) {
- QList<Operation *> optionOps = *setAllOptions.value(i == 1);
+ QVector<QSharedPointer<Operation> > optionOps = setAllOptions.value(i == 1);
testGroup.reset("testAll 5.2");
testGroup.add() << optionOps << styleOp;
testGroup.add() << styleOp << optionOps;
testGroup.createTestRows();
foreach (QWizard::WizardOption option, OptionInfo::instance().options()) {
- Operation *optionOp = OPT(option, i == 1);
+ QSharedPointer<Operation> optionOp = OPT(option, i == 1);
testGroup.reset("testAll 5.3");
testGroup.add() << optionOp << styleOp;
testGroup.add() << styleOp << optionOp;
@@ -1972,8 +1986,8 @@ public:
}
}
- foreach (Operation *pageOp, pageOps) {
- foreach (Operation *styleOp, styleOps) {
+ foreach (const QSharedPointer<Operation> &pageOp, pageOps) {
+ foreach (const QSharedPointer<Operation> &styleOp, styleOps) {
testGroup.reset("testAll 6.1");
testGroup.add() << pageOp;
@@ -1991,7 +2005,7 @@ public:
testGroup.createTestRows();
for (int i = 0; i < 2; ++i) {
- QList<Operation *> optionOps = *setAllOptions.value(i == 1);
+ QVector<QSharedPointer<Operation> > optionOps = setAllOptions.value(i == 1);
testGroup.reset("testAll 6.4");
testGroup.add() << optionOps << pageOp << styleOp;
testGroup.add() << pageOp << optionOps << styleOp;
@@ -2002,7 +2016,7 @@ public:
testGroup.createTestRows();
foreach (QWizard::WizardOption option, OptionInfo::instance().options()) {
- Operation *optionOp = OPT(option, i == 1);
+ QSharedPointer<Operation> optionOp = OPT(option, i == 1);
testGroup.reset("testAll 6.5");
testGroup.add() << optionOp << pageOp << styleOp;
testGroup.add() << pageOp << optionOp << styleOp;
@@ -2068,7 +2082,7 @@ void tst_QWizard::combinations()
QFETCH(bool, ref);
QFETCH(bool, testEquality);
- QFETCH(QList<Operation *>, operations);
+ QFETCH(QVector<QSharedPointer<Operation> >, operations);
TestWizard wizard;
#if !defined(QT_NO_STYLE_WINDOWSVISTA)
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
index dc527767a7..60dc7a7288 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -845,14 +845,14 @@ void tst_QGraphicsItem::parentItem()
void tst_QGraphicsItem::setParentItem()
{
QGraphicsScene scene;
- QGraphicsItem *item = scene.addRect(QRectF(0, 0, 10, 10));
+ const QScopedPointer<QGraphicsItem> item(scene.addRect(QRectF(0, 0, 10, 10)));
QCOMPARE(item->scene(), &scene);
- QGraphicsRectItem *child = new QGraphicsRectItem;
+ const QScopedPointer<QGraphicsRectItem> child(new QGraphicsRectItem);
QCOMPARE(child->scene(), (QGraphicsScene *)0);
// This implicitly adds the item to the parent's scene
- child->setParentItem(item);
+ child->setParentItem(item.data());
QCOMPARE(child->scene(), &scene);
// This just makes it a toplevel
@@ -860,8 +860,8 @@ void tst_QGraphicsItem::setParentItem()
QCOMPARE(child->scene(), &scene);
// Add the child back to the parent, then remove the parent from the scene
- child->setParentItem(item);
- scene.removeItem(item);
+ child->setParentItem(item.data());
+ scene.removeItem(item.data());
QCOMPARE(child->scene(), (QGraphicsScene *)0);
}
@@ -959,19 +959,19 @@ void tst_QGraphicsItem::flags()
QCOMPARE(item->pos(), QPointF(10, 10));
}
{
- QGraphicsItem* clippingParent = new QGraphicsRectItem;
+ const QScopedPointer<QGraphicsItem> clippingParent(new QGraphicsRectItem);
clippingParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
- QGraphicsItem* nonClippingParent = new QGraphicsRectItem;
+ const QScopedPointer<QGraphicsItem> nonClippingParent(new QGraphicsRectItem);
nonClippingParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
- QGraphicsItem* child = new QGraphicsRectItem(nonClippingParent);
+ QGraphicsItem* child = new QGraphicsRectItem(nonClippingParent.data());
QVERIFY(!child->isClipped());
- child->setParentItem(clippingParent);
+ child->setParentItem(clippingParent.data());
QVERIFY(child->isClipped());
- child->setParentItem(nonClippingParent);
+ child->setParentItem(nonClippingParent.data());
QVERIFY(!child->isClipped());
}
}
@@ -3130,7 +3130,8 @@ void tst_QGraphicsItem::isAncestorOf()
void tst_QGraphicsItem::commonAncestorItem()
{
- QGraphicsItem *ancestor = new QGraphicsRectItem;
+ QGraphicsRectItem ancestorItem;
+ QGraphicsItem *ancestor = &ancestorItem;
QGraphicsItem *grandMa = new QGraphicsRectItem;
QGraphicsItem *grandPa = new QGraphicsRectItem;
QGraphicsItem *brotherInLaw = new QGraphicsRectItem;
@@ -3630,7 +3631,7 @@ void tst_QGraphicsItem::setGroup()
QGraphicsItemGroup group1;
QGraphicsItemGroup group2;
- QGraphicsRectItem *rect = new QGraphicsRectItem;
+ const QScopedPointer<QGraphicsRectItem> rect(new QGraphicsRectItem);
QCOMPARE(rect->group(), (QGraphicsItemGroup *)0);
QCOMPARE(rect->parentItem(), (QGraphicsItem *)0);
rect->setGroup(&group1);
@@ -6835,8 +6836,8 @@ void tst_QGraphicsItem::opacity()
QFETCH(qreal, c2_effectiveOpacity);
QFETCH(qreal, c3_effectiveOpacity);
- QGraphicsRectItem *p = new QGraphicsRectItem;
- QGraphicsRectItem *c1 = new QGraphicsRectItem(p);
+ const QScopedPointer<QGraphicsRectItem> p(new QGraphicsRectItem);
+ QGraphicsRectItem *c1 = new QGraphicsRectItem(p.data());
QGraphicsRectItem *c2 = new QGraphicsRectItem(c1);
QGraphicsRectItem *c3 = new QGraphicsRectItem(c2);
@@ -7224,11 +7225,12 @@ void tst_QGraphicsItem::sceneTransformCache()
// Test that an item's scene transform is updated correctly when the
// parent is transformed.
QGraphicsScene scene;
- QGraphicsRectItem *rect = scene.addRect(0, 0, 100, 100);
+
+ const QScopedPointer<QGraphicsRectItem> rect(scene.addRect(0, 0, 100, 100));
rect->setPen(QPen(Qt::black, 0));
QGraphicsRectItem *rect2 = scene.addRect(0, 0, 100, 100);
rect2->setPen(QPen(Qt::black, 0));
- rect2->setParentItem(rect);
+ rect2->setParentItem(rect.data());
rect2->setTransform(QTransform().rotate(90), true);
rect->setTransform(QTransform::fromTranslate(0, 50), true);
QGraphicsView view(&scene);
@@ -7240,7 +7242,7 @@ void tst_QGraphicsItem::sceneTransformCache()
x.rotate(90);
QCOMPARE(rect2->sceneTransform(), x);
- scene.removeItem(rect);
+ scene.removeItem(rect.data());
//Crazy use case : rect4 child of rect3 so the transformation of rect4 will be cached.Good!
//We remove rect4 from the scene, then the validTransform bit flag is set to 0 and the index of the cache
@@ -10696,7 +10698,7 @@ void tst_QGraphicsItem::scenePosChange()
{
ScenePosChangeTester* root = new ScenePosChangeTester;
ScenePosChangeTester* child1 = new ScenePosChangeTester(root);
- ScenePosChangeTester* grandChild1 = new ScenePosChangeTester(child1);
+ const QScopedPointer<ScenePosChangeTester> grandChild1(new ScenePosChangeTester(child1));
ScenePosChangeTester* child2 = new ScenePosChangeTester(root);
ScenePosChangeTester* grandChild2 = new ScenePosChangeTester(child2);
@@ -10748,7 +10750,7 @@ void tst_QGraphicsItem::scenePosChange()
QCOMPARE(grandChild2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 3);
// remove
- scene.removeItem(grandChild1);
+ scene.removeItem(grandChild1.data());
delete grandChild2; grandChild2 = 0;
QCoreApplication::processEvents(); // QGraphicsScenePrivate::_q_updateScenePosDescendants()
root->moveBy(1.0, 1.0);
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
index 1df9a9434c..5b6f219d11 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
@@ -2924,6 +2924,9 @@ void tst_QGraphicsView::scrollBarRanges()
if (useStyledPanel && style == QStringLiteral("Macintosh") && platformName == QStringLiteral("cocoa"))
QSKIP("Insignificant on OSX");
+
+ QScopedPointer<QStyle> stylePtr;
+
QGraphicsScene scene;
QGraphicsView view(&scene);
view.setRenderHint(QPainter::Antialiasing);
@@ -2931,9 +2934,10 @@ void tst_QGraphicsView::scrollBarRanges()
view.setFrameStyle(useStyledPanel ? QFrame::StyledPanel : QFrame::NoFrame);
if (style == QString("motif"))
- view.setStyle(new FauxMotifStyle);
+ stylePtr.reset(new FauxMotifStyle);
else
- view.setStyle(QStyleFactory::create(style));
+ stylePtr.reset(QStyleFactory::create(style));
+ view.setStyle(stylePtr.data());
view.setStyleSheet(" "); // enables style propagation ;-)
int adjust = 0;
@@ -3500,7 +3504,7 @@ void tst_QGraphicsView::task245469_itemsAtPointWithClip()
static QGraphicsView *createSimpleViewAndScene()
{
QGraphicsView *view = new QGraphicsView;
- QGraphicsScene *scene = new QGraphicsScene;
+ QGraphicsScene *scene = new QGraphicsScene(view);
view->setScene(scene);
view->setBackgroundBrush(Qt::blue);
@@ -3628,7 +3632,7 @@ void tst_QGraphicsView::moveItemWhileScrolling()
MoveItemScrollView()
{
setWindowFlags(Qt::X11BypassWindowManagerHint);
- setScene(new QGraphicsScene(0, 0, 1000, 1000));
+ setScene(new QGraphicsScene(0, 0, 1000, 1000, this));
rect = scene()->addRect(0, 0, 10, 10);
rect->setPos(50, 50);
rect->setPen(QPen(Qt::black, 0));
@@ -3694,7 +3698,7 @@ void tst_QGraphicsView::centerOnDirtyItem()
toplevel.setWindowFlags(view.windowFlags() | Qt::WindowStaysOnTopHint);
view.resize(200, 200);
- QGraphicsScene *scene = new QGraphicsScene;
+ QGraphicsScene *scene = new QGraphicsScene(&view);
view.setScene(scene);
view.setSceneRect(-1000, -1000, 2000, 2000);
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
index 8cb95c867c..6fd95c8266 100644
--- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
+++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
@@ -149,6 +149,7 @@ private slots:
void QTBUG50102_SH_ItemView_ScrollMode();
void QTBUG50535_update_on_new_selection_model();
void testSelectionModelInSyncWithView();
+ void testClickToSelect();
};
class MyAbstractItemDelegate : public QAbstractItemDelegate
@@ -2113,5 +2114,56 @@ void tst_QAbstractItemView::testSelectionModelInSyncWithView()
QCOMPARE(view.selectionModel()->selection().indexes(), QModelIndexList() << model.index(0, 0));
}
+class SetSelectionTestView : public QListView
+{
+ Q_OBJECT
+public:
+ SetSelectionTestView() : QListView() {}
+
+signals:
+ void setSelectionCalled(const QRect &rect);
+
+protected:
+ void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags) Q_DECL_OVERRIDE
+ {
+ emit setSelectionCalled(rect);
+ QListView::setSelection(rect, flags);
+ }
+};
+
+void tst_QAbstractItemView::testClickToSelect()
+{
+ // This test verifies that the QRect that is passed from QAbstractItemView::mousePressEvent
+ // to the virtual method QAbstractItemView::setSelection(const QRect &, SelectionFlags)
+ // is the 1x1 rect which conains exactly the clicked pixel if no modifiers are pressed.
+
+ QStringList list;
+ list << "A" << "B" << "C";
+ QStringListModel model(list);
+
+ SetSelectionTestView view;
+ view.setModel(&model);
+ view.show();
+ QTest::qWaitForWindowExposed(&view);
+
+ QSignalSpy spy(&view, &SetSelectionTestView::setSelectionCalled);
+
+ const QModelIndex indexA(model.index(0, 0));
+ const QRect visualRectA = view.visualRect(indexA);
+ const QPoint centerA = visualRectA.center();
+
+ // Click the center of the visualRect of item "A"
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, centerA);
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.back().front().value<QRect>(), QRect(centerA, QSize(1, 1)));
+
+ // Click a point slightly away from the center
+ const QPoint nearCenterA = centerA + QPoint(1, 1);
+ QVERIFY(visualRectA.contains(nearCenterA));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, nearCenterA);
+ QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.back().front().value<QRect>(), QRect(nearCenterA, QSize(1, 1)));
+}
+
QTEST_MAIN(tst_QAbstractItemView)
#include "tst_qabstractitemview.moc"
diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
index e8bd86bee5..f8ab64e4d6 100644
--- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
+++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp
@@ -1672,16 +1672,16 @@ void tst_QListWidget::mimeData()
QMimeData *data;
- QVERIFY(data = list.mimeData(tableWidgetItemList));
+ QVERIFY((data = list.mimeData(tableWidgetItemList)));
delete data;
- QVERIFY(data = list.model()->mimeData(modelIndexList));
+ QVERIFY((data = list.model()->mimeData(modelIndexList)));
delete data;
- QVERIFY(data = list.model()->mimeData(modelIndexList));
+ QVERIFY((data = list.model()->mimeData(modelIndexList)));
delete data;
- QVERIFY(data = list.mimeData(tableWidgetItemList));
+ QVERIFY((data = list.mimeData(tableWidgetItemList)));
delete data;
// check the saved data is actually the same
diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
index 8f871b03f6..a86ffbc30d 100644
--- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
@@ -1520,16 +1520,16 @@ void tst_QTableWidget::mimeData()
QMimeData *data;
- QVERIFY(data = table.mimeData(tableWidgetItemList));
+ QVERIFY((data = table.mimeData(tableWidgetItemList)));
delete data;
- QVERIFY(data = table.model()->mimeData(modelIndexList));
+ QVERIFY((data = table.model()->mimeData(modelIndexList)));
delete data;
- QVERIFY(data = table.model()->mimeData(modelIndexList));
+ QVERIFY((data = table.model()->mimeData(modelIndexList)));
delete data;
- QVERIFY(data = table.mimeData(tableWidgetItemList));
+ QVERIFY((data = table.mimeData(tableWidgetItemList)));
delete data;
// check the saved data is actually the same
diff --git a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
index 205067d89c..e6a615d4f5 100644
--- a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
+++ b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
@@ -324,7 +324,7 @@ void tst_QAction::enabledVisibleInteraction()
void tst_QAction::task200823_tooltip()
{
- QAction *action = new QAction("foo", 0);
+ const QScopedPointer<QAction> action(new QAction("foo", Q_NULLPTR));
QString shortcut("ctrl+o");
action->setShortcut(shortcut);
@@ -338,8 +338,8 @@ void tst_QAction::task200823_tooltip()
void tst_QAction::task229128TriggeredSignalWithoutActiongroup()
{
// test without a group
- QAction *actionWithoutGroup = new QAction("Test", qApp);
- QSignalSpy spyWithoutGroup(actionWithoutGroup, SIGNAL(triggered(bool)));
+ const QScopedPointer<QAction> actionWithoutGroup(new QAction("Test", Q_NULLPTR));
+ QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), SIGNAL(triggered(bool)));
QCOMPARE(spyWithoutGroup.count(), 0);
actionWithoutGroup->trigger();
// signal should be emitted
diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
index ab9729342c..779773eff0 100644
--- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
+++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
@@ -2197,8 +2197,8 @@ void tst_QApplication::noQuitOnHide()
{
int argc = 0;
QApplication app(argc, 0);
- QWidget *window1 = new NoQuitOnHideWidget;
- window1->show();
+ NoQuitOnHideWidget window1;
+ window1.show();
QCOMPARE(app.exec(), 1);
}
@@ -2232,12 +2232,12 @@ void tst_QApplication::abortQuitOnShow()
{
int argc = 0;
QApplication app(argc, 0);
- QWidget *window1 = new ShowCloseShowWidget(false);
- window1->show();
+ ShowCloseShowWidget window1(false);
+ window1.show();
QCOMPARE(app.exec(), 0);
- QWidget *window2 = new ShowCloseShowWidget(true);
- window2->show();
+ ShowCloseShowWidget window2(true);
+ window2.show();
QCOMPARE(app.exec(), 1);
}
diff --git a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp
index a19f4aea56..1a15432c1a 100644
--- a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp
+++ b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp
@@ -43,6 +43,10 @@
#include <qformlayout.h>
+// ItemRole has enumerators for numerical values 0..2, thus the only
+// valid numerical values for storing into an ItemRole variable are 0..3:
+Q_CONSTEXPR QFormLayout::ItemRole invalidRole = QFormLayout::ItemRole(3);
+
static inline void setFrameless(QWidget *w)
{
Qt::WindowFlags flags = w->windowFlags();
@@ -390,7 +394,8 @@ void tst_QFormLayout::setFormStyle()
QCOMPARE(layout.rowWrapPolicy(), QFormLayout::DontWrapRows);
#endif
- widget.setStyle(QStyleFactory::create("windows"));
+ const QScopedPointer<QStyle> windowsStyle(QStyleFactory::create("windows"));
+ widget.setStyle(windowsStyle.data());
QCOMPARE(layout.labelAlignment(), Qt::AlignLeft);
QVERIFY(layout.formAlignment() == (Qt::AlignLeft | Qt::AlignTop));
@@ -401,14 +406,16 @@ void tst_QFormLayout::setFormStyle()
this test is cross platform.. so create dummy styles that
return all the right stylehints.
*/
- widget.setStyle(new DummyMacStyle());
+ DummyMacStyle macStyle;
+ widget.setStyle(&macStyle);
QCOMPARE(layout.labelAlignment(), Qt::AlignRight);
QVERIFY(layout.formAlignment() == (Qt::AlignHCenter | Qt::AlignTop));
QCOMPARE(layout.fieldGrowthPolicy(), QFormLayout::FieldsStayAtSizeHint);
QCOMPARE(layout.rowWrapPolicy(), QFormLayout::DontWrapRows);
- widget.setStyle(new DummyQtopiaStyle());
+ DummyQtopiaStyle qtopiaStyle;
+ widget.setStyle(&qtopiaStyle);
QCOMPARE(layout.labelAlignment(), Qt::AlignRight);
QVERIFY(layout.formAlignment() == (Qt::AlignLeft | Qt::AlignTop));
@@ -520,7 +527,7 @@ void tst_QFormLayout::insertRow_QWidget_QWidget()
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout->getWidgetPosition(lbl1, &row, &role);
QCOMPARE(row, 0);
QCOMPARE(int(role), int(QFormLayout::LabelRole));
@@ -528,7 +535,7 @@ void tst_QFormLayout::insertRow_QWidget_QWidget()
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout->getWidgetPosition(fld1, &row, &role);
QCOMPARE(row, 0);
QCOMPARE(int(role), int(QFormLayout::FieldRole));
@@ -589,7 +596,7 @@ void tst_QFormLayout::insertRow_QWidget_QLayout()
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout->getWidgetPosition(lbl1, &row, &role);
QCOMPARE(row, 0);
QCOMPARE(int(role), int(QFormLayout::LabelRole));
@@ -597,7 +604,7 @@ void tst_QFormLayout::insertRow_QWidget_QLayout()
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout->getLayoutPosition(fld1, &row, &role);
QCOMPARE(row, 0);
QCOMPARE(int(role), int(QFormLayout::FieldRole));
@@ -714,7 +721,7 @@ void tst_QFormLayout::setWidget()
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout.getWidgetPosition(&w1, &row, &role);
QCOMPARE(row, 5);
QCOMPARE(int(role), int(QFormLayout::LabelRole));
@@ -722,7 +729,7 @@ void tst_QFormLayout::setWidget()
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout.getWidgetPosition(&w2, &row, &role);
QCOMPARE(row, 3);
QCOMPARE(int(role), int(QFormLayout::FieldRole));
@@ -730,7 +737,7 @@ void tst_QFormLayout::setWidget()
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout.getWidgetPosition(&w3, &row, &role);
QCOMPARE(row, 3);
QCOMPARE(int(role), int(QFormLayout::LabelRole));
@@ -738,18 +745,20 @@ void tst_QFormLayout::setWidget()
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout.getWidgetPosition(&w4, &row, &role);
+ // not found
QCOMPARE(row, -1);
- QCOMPARE(int(role), -123);
+ QCOMPARE(int(role), int(invalidRole));
}
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout.getWidgetPosition(0, &row, &role);
+ // not found
QCOMPARE(row, -1);
- QCOMPARE(int(role), -123);
+ QCOMPARE(int(role), int(invalidRole));
}
}
@@ -782,7 +791,7 @@ void tst_QFormLayout::setLayout()
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout.getLayoutPosition(&l1, &row, &role);
QCOMPARE(row, 5);
QCOMPARE(int(role), int(QFormLayout::LabelRole));
@@ -790,7 +799,7 @@ void tst_QFormLayout::setLayout()
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout.getLayoutPosition(&l2, &row, &role);
QCOMPARE(row, 3);
QCOMPARE(int(role), int(QFormLayout::FieldRole));
@@ -798,7 +807,7 @@ void tst_QFormLayout::setLayout()
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout.getLayoutPosition(&l3, &row, &role);
QCOMPARE(row, 3);
QCOMPARE(int(role), int(QFormLayout::LabelRole));
@@ -806,18 +815,18 @@ void tst_QFormLayout::setLayout()
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout.getLayoutPosition(&l4, &row, &role);
QCOMPARE(row, -1);
- QCOMPARE(int(role), -123);
+ QCOMPARE(int(role), int(invalidRole));
}
{
int row = -1;
- QFormLayout::ItemRole role = QFormLayout::ItemRole(-123);
+ QFormLayout::ItemRole role = invalidRole;
layout.getLayoutPosition(0, &row, &role);
QCOMPARE(row, -1);
- QCOMPARE(int(role), -123);
+ QCOMPARE(int(role), int(invalidRole));
}
}
@@ -886,7 +895,7 @@ void tst_QFormLayout::takeAt()
QCOMPARE(layout->count(), 7);
for (int i = 6; i >= 0; --i) {
- layout->takeAt(0);
+ delete layout->takeAt(0);
QCOMPARE(layout->count(), i);
}
}
@@ -978,7 +987,7 @@ void tst_QFormLayout::replaceWidget()
QFormLayout::ItemRole role;
// replace editor
- layout->replaceWidget(edit1, edit3);
+ delete layout->replaceWidget(edit1, edit3);
edit1->hide(); // Not strictly needed for the test, but for normal usage it is.
QCOMPARE(layout->indexOf(edit1), -1);
QCOMPARE(layout->indexOf(edit3), editIndex);
@@ -989,7 +998,7 @@ void tst_QFormLayout::replaceWidget()
QCOMPARE(rownum, 0);
QCOMPARE(role, QFormLayout::FieldRole);
- layout->replaceWidget(label1, label2);
+ delete layout->replaceWidget(label1, label2);
label1->hide();
QCOMPARE(layout->indexOf(label1), -1);
QCOMPARE(layout->indexOf(label2), labelIndex);
diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
index 55b0ed4279..62c75cadf3 100644
--- a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
+++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
@@ -1207,7 +1207,8 @@ QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int t
void tst_QShortcut::shortcutDestroyed(QObject* obj)
{
- shortcuts.removeAll(static_cast<QShortcut *>(obj));
+ shortcuts.erase(std::remove(shortcuts.begin(), shortcuts.end(), obj),
+ shortcuts.end());
}
void tst_QShortcut::sendKeyEvents(int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4)
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 272e6ef02f..5a00b0dad9 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -10425,14 +10425,13 @@ public slots:
bool eventFilter(QObject *o, QEvent *e)
{
- if (modal && modal->button && o == modal->button) {
- switch (e->type()) {
- case QEvent::Enter:
+ switch (e->type()) {
+ case QEvent::Enter:
+ if (modal && modal->button && o == modal->button)
enters++;
- break;
- default:
- break;
- }
+ break;
+ default:
+ break;
}
return QDialog::eventFilter(o, e);
}
diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
index 31eb05a957..9e09d17903 100644
--- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
+++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
@@ -3734,7 +3734,7 @@ void tst_QDateTimeEdit::dateEditCorrectSectionSize()
QTest::keyClick(&edit, keyPair.first, keyPair.second);
QDateTimeEditPrivate* edit_d_ptr(static_cast<QDateTimeEditPrivate*>(qt_widget_private(&edit)));
- QCOMPARE(edit_d_ptr->text, expectedDisplayString);
+ QCOMPARE(edit_d_ptr->QDateTimeParser::displayText(), expectedDisplayString);
}
#endif
diff --git a/tests/auto/widgets/widgets/qlabel/red@2x.png b/tests/auto/widgets/widgets/qlabel/red@2x.png
new file mode 100644
index 0000000000..4a843e744f
--- /dev/null
+++ b/tests/auto/widgets/widgets/qlabel/red@2x.png
Binary files differ
diff --git a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp
index ad971c6b5f..6363d0c673 100644
--- a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp
+++ b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp
@@ -96,6 +96,9 @@ private Q_SLOTS:
void taskQTBUG_7902_contextMenuCrash();
#endif
+ void taskQTBUG_48157_dprPixmap();
+ void taskQTBUG_48157_dprMovie();
+
private:
QLabel *testWidget;
QPointer<Widget> test_box;
@@ -541,5 +544,26 @@ void tst_QLabel::taskQTBUG_7902_contextMenuCrash()
}
#endif
+void tst_QLabel::taskQTBUG_48157_dprPixmap()
+{
+ QLabel label;
+ QPixmap pixmap;
+ pixmap.load(QFINDTESTDATA(QStringLiteral("red@2x.png")));
+ QCOMPARE(pixmap.devicePixelRatio(), 2.0);
+ label.setPixmap(pixmap);
+ QCOMPARE(label.sizeHint(), pixmap.rect().size() / pixmap.devicePixelRatio());
+}
+
+void tst_QLabel::taskQTBUG_48157_dprMovie()
+{
+ QLabel label;
+ QMovie movie;
+ movie.setFileName(QFINDTESTDATA(QStringLiteral("red@2x.png")));
+ movie.start();
+ QCOMPARE(movie.currentPixmap().devicePixelRatio(), 2.0);
+ label.setMovie(&movie);
+ QCOMPARE(label.sizeHint(), movie.currentPixmap().size() / movie.currentPixmap().devicePixelRatio());
+}
+
QTEST_MAIN(tst_QLabel)
#include "tst_qlabel.moc"
diff --git a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp
index 5bd26c632c..6ee5f76c6a 100644
--- a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp
+++ b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp
@@ -859,6 +859,10 @@ void tst_QMainWindow::takeCentralWidget() {
QVERIFY(!mw.centralWidget());
+ // verify that we don't crash when trying to take a non-set
+ // central widget but just return a null pointer instead
+ QVERIFY(!mw.takeCentralWidget());
+
mw.setCentralWidget(w1);
QWidget *oldCentralWidget = mw.takeCentralWidget();
diff --git a/tests/auto/widgets/widgets/qmenubar/qmenubar.pro b/tests/auto/widgets/widgets/qmenubar/qmenubar.pro
index 3fb6ae61a8..e680cf4d7d 100644
--- a/tests/auto/widgets/widgets/qmenubar/qmenubar.pro
+++ b/tests/auto/widgets/widgets/qmenubar/qmenubar.pro
@@ -2,3 +2,8 @@ CONFIG += testcase
TARGET = tst_qmenubar
QT += widgets testlib
SOURCES += tst_qmenubar.cpp
+
+macos: {
+ OBJECTIVE_SOURCES += tst_qmenubar_mac.mm
+ LIBS += -framework AppKit
+}
diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
index 185bfc02a0..9a68655fb6 100644
--- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
+++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
@@ -130,6 +130,9 @@ private slots:
void cornerWidgets_data();
void cornerWidgets();
void taskQTBUG53205_crashReparentNested();
+#ifdef Q_OS_MACOS
+ void taskQTBUG56275_reinsertMenuInParentlessQMenuBar();
+#endif
protected slots:
void onSimpleActivated( QAction*);
@@ -1496,7 +1499,28 @@ void tst_QMenuBar::slotForTaskQTBUG53205()
taskQTBUG53205MenuBar->setParent(parent);
}
+#ifdef Q_OS_MACOS
+extern bool tst_qmenubar_taskQTBUG56275(QMenuBar *);
+
+void tst_QMenuBar::taskQTBUG56275_reinsertMenuInParentlessQMenuBar()
+{
+ QMenuBar menubar;
+ QMenu *menu = new QMenu("menu", &menubar);
+ QMenu* submenu = menu->addMenu("submenu");
+ submenu->addAction("action1");
+ submenu->addAction("action2");
+ menu->addAction("action3");
+ menubar.addMenu(menu);
+
+ QTest::qWait(100);
+ menubar.clear();
+ menubar.addMenu(menu);
+ QTest::qWait(100);
+
+ QVERIFY(tst_qmenubar_taskQTBUG56275(&menubar));
+}
+#endif // Q_OS_MACOS
QTEST_MAIN(tst_QMenuBar)
#include "tst_qmenubar.moc"
diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm
new file mode 100644
index 0000000000..4645de4d7a
--- /dev/null
+++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm
@@ -0,0 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** 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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+#include <QMenuBar>
+#include <QTest>
+
+bool tst_qmenubar_taskQTBUG56275(QMenuBar *menubar)
+{
+ NSMenu *mainMenu = menubar->toNSMenu();
+ return mainMenu.numberOfItems == 2
+ && [[mainMenu itemAtIndex:1].title isEqualToString:@"menu"];
+}
diff --git a/tests/auto/widgets/widgets/qstackedwidget/tst_qstackedwidget.cpp b/tests/auto/widgets/widgets/qstackedwidget/tst_qstackedwidget.cpp
index 7b5ec4fa4c..2df5f01627 100644
--- a/tests/auto/widgets/widgets/qstackedwidget/tst_qstackedwidget.cpp
+++ b/tests/auto/widgets/widgets/qstackedwidget/tst_qstackedwidget.cpp
@@ -163,7 +163,8 @@ private:
void tst_QStackedWidget::dynamicPages()
{
- QStackedWidget *sw = new QStackedWidget;
+ QStackedWidget stackedWidget;
+ QStackedWidget *sw = &stackedWidget;
TestPage *w1 = new TestPage(true);
w1->setN(3);