File indexing completed on 2024-11-24 05:00:57
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include <QAbstractEventDispatcher> 0008 #include <QMenu> 0009 #include <QSignalSpy> 0010 #include <QSystemTrayIcon> 0011 #include <QTest> 0012 0013 class KSniUnitTest : public QObject 0014 { 0015 Q_OBJECT 0016 private Q_SLOTS: 0017 // test for BUG 343976 0018 void testHideDontCrash(); 0019 }; 0020 0021 void KSniUnitTest::testHideDontCrash() 0022 { 0023 QSystemTrayIcon *sti = new QSystemTrayIcon(this); 0024 QMenu *trayIconMenu = new QMenu(); 0025 QAction *dummyAction = new QAction(QStringLiteral("foo"), sti); 0026 trayIconMenu->addAction(dummyAction); 0027 QSignalSpy menuDestroyedSpy(trayIconMenu, &QObject::destroyed); 0028 QVERIFY(menuDestroyedSpy.isValid()); 0029 sti->setContextMenu(trayIconMenu); 0030 0031 connect(sti, &QSystemTrayIcon::destroyed, trayIconMenu, &QMenu::deleteLater); 0032 sti->setVisible(true); 0033 sti->show(); 0034 0035 // now delete it 0036 delete sti; 0037 QVERIFY(menuDestroyedSpy.wait()); 0038 } 0039 0040 QTEST_MAIN(KSniUnitTest) 0041 0042 #include "ksni_unittest.moc"