File indexing completed on 2024-06-16 04:23:07

0001 /*
0002     SPDX-FileCopyrightText: 2012 Sven Brauch <svenbrauch@googlemail.com>
0003     SPDX-FileCopyrightText: 2012 Milian Wolff <mail@milianw.de>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KDEVPLATFORM_TEST_BACKGROUNDPARSER_H
0009 #define KDEVPLATFORM_TEST_BACKGROUNDPARSER_H
0010 
0011 #include <QObject>
0012 
0013 #include <serialization/indexedstring.h>
0014 #include <language/duchain/topducontext.h>
0015 
0016 #include <language/backgroundparser/parsejob.h>
0017 
0018 #include "testlanguagesupport.h"
0019 
0020 class JobPrototype
0021 {
0022 public:
0023     JobPrototype()
0024         : m_priority(0)
0025         , m_duration(0)
0026         , m_flags(ParseJob::IgnoresSequentialProcessing)
0027     {
0028     }
0029     JobPrototype(const QUrl& url, int priority, ParseJob::SequentialProcessingFlags flags, int duration = 0)
0030         : m_url(url)
0031         , m_priority(priority)
0032         , m_duration(duration)
0033         , m_flags(flags)
0034     {
0035         Q_ASSERT(url.isValid());
0036     }
0037     IndexedString m_url;
0038     int m_priority;
0039     int m_duration;
0040     ParseJob::SequentialProcessingFlags m_flags;
0041 };
0042 
0043 Q_DECLARE_TYPEINFO(JobPrototype, Q_MOVABLE_TYPE);
0044 
0045 class TestParseJob;
0046 
0047 class JobPlan
0048     : public QObject
0049 {
0050     Q_OBJECT
0051 
0052 public:
0053     JobPlan();
0054 
0055     void addJob(const JobPrototype& job);
0056 
0057     void addJobsToParser();
0058     bool runJobs(int timeoutMS);
0059 
0060     void clear();
0061 
0062     JobPrototype jobForUrl(const IndexedString& url) const;
0063 
0064     int numJobs() const;
0065     int numFinishedJobs() const;
0066     int numCreatedJobs() const;
0067 
0068 private Q_SLOTS:
0069     void updateReady(const KDevelop::IndexedString& url, const KDevelop::ReferencedTopDUContext& context);
0070     void parseJobCreated(KDevelop::ParseJob*);
0071 
0072 private:
0073     friend class TestBackgroundparser;
0074 
0075     QVector<JobPrototype> m_jobs;
0076     QVector<IndexedString> m_finishedJobs;
0077     QVector<IndexedString> m_createdJobs;
0078 };
0079 
0080 class TestBackgroundparser
0081     : public QObject
0082 {
0083     Q_OBJECT
0084 
0085 private Q_SLOTS:
0086     void initTestCase();
0087     void cleanupTestCase();
0088     void init();
0089 
0090     void testShutdownWithRunningJobs();
0091 
0092     void testParseOrdering_simple();
0093     void testParseOrdering_lockup();
0094     void testParseOrdering_foregroundThread();
0095     void testParseOrdering_noSequentialProcessing();
0096 
0097     void testNoDeadlockInJobCreation();
0098     void testSuspendResume();
0099 
0100     void benchmark();
0101 
0102     void benchmarkDocumentChanges();
0103 
0104 private:
0105     JobPlan m_jobPlan;
0106     TestLanguageSupport* m_langSupport = nullptr;
0107 };
0108 
0109 #endif // KDEVPLATFORM_TEST_BACKGROUNDPARSER_H