File indexing completed on 2024-05-19 04:39:27
0001 #include <QTest> 0002 #include <serialization/itemrepositoryregistry.h> 0003 #include <shell/sessioncontroller.h> 0004 0005 #include <tests/testcore.h> 0006 #include <tests/autotestshell.h> 0007 0008 using namespace KDevelop; 0009 0010 class TestItemRepositoryRegistryDeferredDeletion 0011 : public QObject 0012 { 0013 Q_OBJECT 0014 void initCore(const QString& sessionName = QString()) 0015 { 0016 auto* core = new TestCore(); 0017 core->initialize(Core::NoUi, sessionName); 0018 } 0019 0020 void destroyCore() 0021 { 0022 TestCore::shutdown(); 0023 } 0024 0025 private Q_SLOTS: 0026 void initTestCase() 0027 { 0028 AutoTestShell::init(); 0029 } 0030 0031 void testDeferredDeletion() 0032 { 0033 // Create and shutdown a TestCore, giving the session a custom name 0034 // so it will stay (won't be temporary) and request the session deletion 0035 // from the same core instance. 0036 0037 static const char sessionName[] = "test-itemrepositoryregistry-deferreddeletion"; 0038 QString repositoryPath; 0039 0040 { 0041 initCore(sessionName); 0042 0043 // The session with a custom name shall not be temporary 0044 QVERIFY(!Core::self()->activeSession()->isTemporary()); 0045 0046 // The repository shall exist 0047 repositoryPath = globalItemRepositoryRegistry().path(); 0048 QVERIFY(QFile::exists(repositoryPath)); 0049 0050 // The repository shall survive session deletion request 0051 Core::self()->sessionController()->deleteSession(Core::self()->sessionController()->activeSessionLock()); 0052 QVERIFY(QFile::exists(repositoryPath)); 0053 0054 // The repository shall die together with the core shutdown 0055 destroyCore(); 0056 QVERIFY(!QFile::exists(repositoryPath)); 0057 } 0058 } 0059 0060 void cleanupTestCase() 0061 { 0062 } 0063 }; 0064 0065 #include "test_itemrepositoryregistry_deferred.moc" 0066 0067 QTEST_MAIN(TestItemRepositoryRegistryDeferredDeletion)