Changeset View
Changeset View
Standalone View
Standalone View
autotests/kmainwindow_unittest.cpp
Show All 20 Lines | |||||
21 | #include "kmainwindow_unittest.h" | 21 | #include "kmainwindow_unittest.h" | ||
22 | #include <QEventLoopLocker> | 22 | #include <QEventLoopLocker> | ||
23 | #include <kmainwindow.h> | 23 | #include <kmainwindow.h> | ||
24 | #include <QStatusBar> | 24 | #include <QStatusBar> | ||
25 | #include <QResizeEvent> | 25 | #include <QResizeEvent> | ||
26 | #include <ktoolbar.h> | 26 | #include <ktoolbar.h> | ||
27 | #include <ksharedconfig.h> | 27 | #include <ksharedconfig.h> | ||
28 | #include <kconfiggroup.h> | 28 | #include <kconfiggroup.h> | ||
29 | #include <QDockWidget> | ||||
29 | 30 | | |||
30 | QTEST_MAIN(KMainWindow_UnitTest) | 31 | QTEST_MAIN(KMainWindow_UnitTest) | ||
31 | 32 | | |||
32 | void KMainWindow_UnitTest::initTestCase() | 33 | void KMainWindow_UnitTest::initTestCase() | ||
33 | { | 34 | { | ||
34 | QStandardPaths::enableTestMode(true); | 35 | QStandardPaths::enableTestMode(true); | ||
35 | QFile::remove(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + KSharedConfig::openConfig()->name()); | 36 | QFile::remove(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QLatin1Char('/') + KSharedConfig::openConfig()->name()); | ||
36 | } | 37 | } | ||
▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Line(s) | |||||
221 | { | 222 | { | ||
222 | // KMainWindow::statusBar() should not find any indirect QStatusBar child | 223 | // KMainWindow::statusBar() should not find any indirect QStatusBar child | ||
223 | // (e.g. in a case like konqueror, with one statusbar per frame) | 224 | // (e.g. in a case like konqueror, with one statusbar per frame) | ||
224 | MyMainWindow mw; | 225 | MyMainWindow mw; | ||
225 | QWidget *frame1 = new QWidget(&mw); | 226 | QWidget *frame1 = new QWidget(&mw); | ||
226 | QStatusBar *frameStatusBar = new QStatusBar(frame1); | 227 | QStatusBar *frameStatusBar = new QStatusBar(frame1); | ||
227 | QVERIFY(mw.statusBar() != frameStatusBar); | 228 | QVERIFY(mw.statusBar() != frameStatusBar); | ||
228 | } | 229 | } | ||
230 | | ||||
231 | | ||||
232 | class NativeMainWindow : public KMainWindow | ||||
233 | { | ||||
234 | public: | ||||
235 | NativeMainWindow() : KMainWindow() | ||||
236 | { | ||||
237 | m_dock = new QDockWidget(QStringLiteral("dock"), this); | ||||
238 | m_dock->setObjectName(QStringLiteral("dock")); | ||||
239 | m_dock->setAllowedAreas(Qt::AllDockWidgetAreas); | ||||
240 | m_dock->setFeatures(QDockWidget::DockWidgetMovable); | ||||
241 | m_dock->setFloating(false); | ||||
242 | | ||||
243 | QWidget *w = new QWidget(m_dock); | ||||
244 | | ||||
245 | m_dock->setWidget(w); | ||||
246 | addDockWidget(Qt::RightDockWidgetArea, m_dock); | ||||
247 | | ||||
248 | setCentralWidget(new QWidget(this)); | ||||
249 | | ||||
250 | show(); | ||||
251 | | ||||
252 | setAutoSaveSettings(QStringLiteral("NativeWidgetTestGroup")); | ||||
253 | | ||||
254 | w->setAttribute(Qt::WA_NativeWindow); | ||||
255 | } | ||||
256 | | ||||
257 | QDockWidget *m_dock; | ||||
258 | }; | ||||
259 | | ||||
260 | void KMainWindow_UnitTest::testNativeWidgetSaveSettings() | ||||
261 | { | ||||
262 | { | ||||
263 | QEventLoop el; | ||||
264 | NativeMainWindow *mw = new NativeMainWindow(); | ||||
265 | connect(mw, &QObject::destroyed, &el, &QEventLoop::quit); // quit event loop when window's gone | ||||
broulikUnsubmitted Not Done broulik: ```
connect(mw, &QObject::destroyed, &el, &QEventLoop::quit);
``` | |||||
266 | | ||||
267 | QApplication::postEvent(mw, new QDeferredDeleteEvent); | ||||
broulik: `mw->deleteLater()`? | |||||
maxrd2: tried it too... will retry all of them again with isHidden() | |||||
Retried with all of these... none of them causes the failure, only closing the window manually cause it QApplication::postEvent(mw, new QDeferredDeleteEvent); // qpa/window manager sends this one.. with spontaneous flag tho QApplication::postEvent(mw, new QCloseEvent); // this one does absolutely nothing QTimer::singleShot(1000, [&](){ QApplication::sendEvent(mw, new QDeferredDeleteEvent); }); mw->close(); QTimer::singleShot(1000, [&](){ mw->close(); }); mw->deleteLater(); maxrd2: Retried with all of these... none of them causes the failure, only closing the window manually… | |||||
mw->setAttribute(Qt::WA_DeleteOnClose); anthonyfieroni: mw->setAttribute(Qt::WA_DeleteOnClose);
Then post event close or deleteLater should work | |||||
KMainWindowPrivate::init() which is called from constructor already does setAttribute(Qt::WA_DeleteOnClose), so that doesnt change anything :-/ maxrd2: KMainWindowPrivate::init() which is called from constructor already does setAttribute(Qt… | |||||
268 | | ||||
269 | el.exec(); | ||||
270 | } | ||||
271 | | ||||
272 | { | ||||
273 | QEventLoop el; | ||||
274 | NativeMainWindow *mw = new NativeMainWindow(); | ||||
275 | connect(mw, &QObject::destroyed, &el, &QEventLoop::quit); | ||||
276 | | ||||
277 | QCOMPARE(mw->m_dock->isHidden(), false); | ||||
278 | mw->m_dock->hide(); | ||||
broulik: `QCOMPARE(mw->m-dock->isVisible(), true)` | |||||
dfaure: Or rather `QVERIFY(mw->m_dock->isVisible())`, that's what QVERIFY is for ;-) | |||||
broulik: :D Right, I got distracted by the `==` | |||||
mmm.. sorry i was supposed to use isHidden() test here, isVisible() is not the opposite maxrd2: mmm.. sorry i was supposed to use isHidden() test here, isVisible() is not the opposite
will… | |||||
279 | | ||||
280 | QApplication::postEvent(mw, new QDeferredDeleteEvent); | ||||
281 | | ||||
282 | el.exec(); | ||||
283 | } | ||||
284 | | ||||
285 | { | ||||
286 | QEventLoop el; | ||||
287 | NativeMainWindow *mw = new NativeMainWindow(); | ||||
288 | connect(mw, &QObject::destroyed, &el, &QEventLoop::quit); | ||||
289 | | ||||
290 | QVERIFY(mw->m_dock->isHidden()); | ||||
291 | | ||||
292 | QApplication::postEvent(mw, new QDeferredDeleteEvent); | ||||
293 | | ||||
294 | el.exec(); | ||||
295 | } | ||||
296 | } |