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 TestItemRepositoryRegistryAutomaticDeletion
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({QString()});
0029     }
0030 
0031     void testTemporarySessionDeletion()
0032     {
0033         // Create and shutdown a TestCore. The session created by it is temporary
0034         // and thus shall be deleted upon core shutdown together with its
0035         // item-repository directory.
0036 
0037         {
0038             initCore();
0039 
0040             // The session created by TestCore shall be temporary
0041             QVERIFY(Core::self()->activeSession()->isTemporary());
0042 
0043             // The repository shall exist
0044             QString repositoryPath = globalItemRepositoryRegistry().path();
0045             QVERIFY(QFile::exists(repositoryPath));
0046 
0047             // The repository shall die with the core shutdown
0048             destroyCore();
0049             QVERIFY(!QFile::exists(repositoryPath));
0050         }
0051     }
0052 
0053     void cleanupTestCase()
0054     {
0055     }
0056 };
0057 
0058 #include "test_itemrepositoryregistry_automatic.moc"
0059 
0060 QTEST_MAIN(TestItemRepositoryRegistryAutomaticDeletion)