File indexing completed on 2024-05-12 04:39:33
0001 /* 0002 SPDX-FileCopyrightText: 2018 Anton Anikin <anton@anikin.xyz> 0003 SPDX-FileCopyrightText: 2020 Friedrich W. H. Kossebau <kossebau@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "test_compileanalyzejob.h" 0009 0010 #include "compileanalyzejob.h" 0011 0012 #include <tests/autotestshell.h> 0013 #include <tests/testcore.h> 0014 0015 #include <QTest> 0016 0017 using namespace KDevelop; 0018 0019 class JobTester : public CompileAnalyzeJob 0020 { 0021 Q_OBJECT 0022 0023 public: 0024 JobTester() 0025 { 0026 setToolDisplayName("TestAnalyzer"); 0027 connect(this, &JobTester::infoMessage, this, &JobTester::collectStarted); 0028 } 0029 0030 public: 0031 using CompileAnalyzeJob::parseProgress; 0032 0033 const QVector<QString>& started() const 0034 { 0035 return m_started; 0036 } 0037 0038 // implementation detail not accessible 0039 #if 0 0040 void setTotalCount(int totalCount) 0041 { 0042 m_totalCount = totalCount; 0043 } 0044 0045 int finishedCount() const 0046 { 0047 return m_finishedCount; 0048 } 0049 #endif 0050 0051 private Q_SLOTS: 0052 void collectStarted(KJob*, const QString& name) 0053 { 0054 m_started += name; 0055 } 0056 0057 private: 0058 QVector<QString> m_started; 0059 }; 0060 0061 void TestCompileAnalyzeJob::initTestCase() 0062 { 0063 AutoTestShell::init(); 0064 TestCore::initialize(Core::NoUi); 0065 } 0066 0067 void TestCompileAnalyzeJob::cleanupTestCase() 0068 { 0069 TestCore::shutdown(); 0070 } 0071 0072 void TestCompileAnalyzeJob::testJob() 0073 { 0074 JobTester jobTester; 0075 0076 // test progress parsing ======================================================================= 0077 0078 static const QStringList stdoutOutput1 = { 0079 QStringLiteral("TestAnalyzer check started for source2.cpp"), 0080 QStringLiteral("TestAnalyzer check started for source1.cpp") 0081 }; 0082 0083 static const QStringList stdoutOutput2 = { 0084 QStringLiteral("TestAnalyzer check finished for source2.cpp"), 0085 QStringLiteral("TestAnalyzer check started for source3.cpp"), 0086 QStringLiteral("TestAnalyzer check started for source4.cpp") 0087 }; 0088 0089 static const QStringList stdoutOutput3 = { 0090 QStringLiteral("TestAnalyzer check finished for source1.cpp"), 0091 QStringLiteral("TestAnalyzer check finished for source4.cpp") 0092 }; 0093 0094 static const QStringList stdoutOutput4 = { 0095 QStringLiteral("TestAnalyzer check finished for source3.cpp"), 0096 }; 0097 0098 // jobTester.setTotalCount(4); 0099 0100 jobTester.parseProgress(stdoutOutput1); 0101 QCOMPARE(jobTester.started().size(), 2); 0102 QCOMPARE(jobTester.started().at(0), QStringLiteral("source2.cpp")); 0103 QCOMPARE(jobTester.started().at(1), QStringLiteral("source1.cpp")); 0104 // QCOMPARE(jobTester.finishedCount(), 0); 0105 QCOMPARE(jobTester.percent(), (unsigned long)0); 0106 0107 jobTester.parseProgress(stdoutOutput2); 0108 QCOMPARE(jobTester.started().size(), 4); 0109 QCOMPARE(jobTester.started().at(2), QStringLiteral("source3.cpp")); 0110 QCOMPARE(jobTester.started().at(3), QStringLiteral("source4.cpp")); 0111 // QCOMPARE(jobTester.finishedCount(), 1); 0112 // QCOMPARE(jobTester.percent(), (unsigned long)25); 0113 0114 jobTester.parseProgress(stdoutOutput3); 0115 QCOMPARE(jobTester.started().size(), 4); 0116 // QCOMPARE(jobTester.finishedCount(), 3); 0117 // QCOMPARE(jobTester.percent(), (unsigned long)75); 0118 0119 jobTester.parseProgress(stdoutOutput4); 0120 QCOMPARE(jobTester.started().size(), 4); 0121 // QCOMPARE(jobTester.finishedCount(), 4); 0122 // QCOMPARE(jobTester.percent(), (unsigned long)100); 0123 0124 QCOMPARE(jobTester.started().at(0), QStringLiteral("source2.cpp")); 0125 QCOMPARE(jobTester.started().at(1), QStringLiteral("source1.cpp")); 0126 QCOMPARE(jobTester.started().at(2), QStringLiteral("source3.cpp")); 0127 QCOMPARE(jobTester.started().at(3), QStringLiteral("source4.cpp")); 0128 } 0129 0130 QTEST_GUILESS_MAIN(TestCompileAnalyzeJob) 0131 0132 #include "test_compileanalyzejob.moc" 0133 #include "moc_test_compileanalyzejob.cpp"