File indexing completed on 2025-01-05 04:59:58
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Mario Bensi <mbensi@ipsquad.net> 0003 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 0007 #include <testlib/qtest_zanshin.h> 0008 0009 #include "presentation/errorhandler.h" 0010 0011 #include "testlib/fakejob.h" 0012 0013 class FakeErrorHandler : public Presentation::ErrorHandler 0014 { 0015 public: 0016 void doDisplayMessage(const QString &message) override 0017 { 0018 m_message = message; 0019 } 0020 0021 QString m_message; 0022 }; 0023 0024 class ErrorHandlerTest : public QObject 0025 { 0026 Q_OBJECT 0027 private slots: 0028 void shouldDisplayErrorMessage() 0029 { 0030 // GIVEN 0031 0032 // create job 0033 auto job = new FakeJob(this); 0034 job->setExpectedError(KJob::KilledJobError, QStringLiteral("Foo")); 0035 0036 // create ErrorHandler 0037 FakeErrorHandler errorHandler; 0038 0039 const QString message = QStringLiteral("I Failed !!!!!!!!!!"); 0040 0041 // WHEN 0042 errorHandler.installHandler(job, message); 0043 0044 // THEN 0045 QTest::qWait(150); 0046 QCOMPARE(errorHandler.m_message, QStringLiteral("I Failed !!!!!!!!!!: Foo")); 0047 } 0048 0049 void shouldDisplayNothing() 0050 { 0051 // GIVEN 0052 0053 // create job 0054 auto job = new FakeJob(this); 0055 0056 // create ErrorHandler 0057 FakeErrorHandler errorHandler; 0058 0059 const QString message = QStringLiteral("I Failed !!!!!!!!!!"); 0060 0061 // WHEN 0062 errorHandler.installHandler(job, message); 0063 0064 // THEN 0065 QTest::qWait(150); 0066 QVERIFY(errorHandler.m_message.isEmpty()); 0067 } 0068 }; 0069 0070 ZANSHIN_TEST_MAIN(ErrorHandlerTest) 0071 0072 #include "errorhandlertest.moc"