File indexing completed on 2025-01-12 04:55:08
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 SPDX-FileCopyrightText: 2021 Harald Sitter <sitter@kde.org> 0004 */ 0005 0006 #include <QProcess> 0007 #include <QTemporaryDir> 0008 #include <QTest> 0009 0010 #include <chrono> 0011 #include <filesystem> 0012 #include <fstream> 0013 #include <iostream> 0014 0015 using namespace std::chrono_literals; 0016 namespace fs = std::filesystem; 0017 0018 class CleanupTest : public QObject 0019 { 0020 Q_OBJECT 0021 private Q_SLOTS: 0022 void testRun() 0023 { 0024 const QString binary = QFINDTESTDATA("drkonqi-coredump-cleanup"); 0025 QTemporaryDir tempDir; 0026 QVERIFY(tempDir.isValid()); 0027 0028 const fs::path dir = tempDir.path().toStdString(); 0029 const fs::path recentFile = fs::path(dir) / "recent.ini"; 0030 const fs::path oldFile = fs::path(dir) / "old.ini"; 0031 { 0032 std::ofstream output(recentFile); 0033 } 0034 { 0035 std::ofstream output(oldFile); 0036 const auto time = fs::last_write_time(oldFile); 0037 fs::last_write_time(oldFile, time - std::chrono::weeks(2)); 0038 } 0039 0040 const int exitCode = QProcess::execute(binary, {tempDir.path()}); 0041 QCOMPARE(exitCode, 0); 0042 QVERIFY(fs::exists(recentFile)); 0043 QVERIFY(!fs::exists(oldFile)); 0044 } 0045 }; 0046 0047 QTEST_GUILESS_MAIN(CleanupTest) 0048 0049 #include "cleanuptest.moc"