File indexing completed on 2024-09-08 04:30:31
0001 /************************************************************************** 0002 * Copyright (C) 2011 Matthias Fuchs <mat69@gmx.net> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU General Public License as published by * 0006 * the Free Software Foundation; either version 2 of the License, or * 0007 * (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the * 0016 * Free Software Foundation, Inc., * 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * 0018 ***************************************************************************/ 0019 0020 #ifndef KGET_SCHEDULER_TEST_H 0021 #define KGET_SCHEDULER_TEST_H 0022 0023 #include "../core/job.h" 0024 #include "../core/jobqueue.h" 0025 0026 class Scheduler; 0027 0028 // TODO how should Job::Moving and Job::FinishedKeepAlive be tested? they clearly depend on the Transfer implementation 0029 // though TestJob itself already does what Transfers ought to do 0030 0031 /** 0032 * Makes sure settings are changed on construction and then restored 0033 * once the destructor is called 0034 */ 0035 class SettingsHelper // TODO better name 0036 { 0037 public: 0038 SettingsHelper(int limit); 0039 ~SettingsHelper(); 0040 0041 private: 0042 int m_oldLimit; 0043 }; 0044 0045 /** 0046 * There to make it easy to create jobs with which to fill the test schedule queue 0047 */ 0048 class TestJob : public Job 0049 { 0050 Q_OBJECT 0051 0052 public: 0053 TestJob(Scheduler *scheduler, JobQueue *parent); 0054 0055 void start() override; 0056 void stop() override; 0057 int elapsedTime() const override; 0058 int remainingTime() const override; 0059 bool isStalled() const override; 0060 bool isWorking() const override; 0061 0062 Q_SIGNALS: 0063 void statusChanged(); 0064 }; 0065 0066 /** 0067 * Adds a public append method 0068 */ 0069 class TestQueue : public JobQueue 0070 { 0071 Q_OBJECT 0072 0073 public: 0074 TestQueue(Scheduler *scheduler); 0075 void appendPub(Job *job); 0076 }; 0077 0078 class SchedulerTest : public QObject 0079 { 0080 Q_OBJECT 0081 0082 private Q_SLOTS: 0083 /** 0084 * Tests if the scheduler reacts correctly on appending jobs, i.e. 0085 * start/stop them 0086 */ 0087 void testAppendJobs(); 0088 void testAppendJobs_data(); 0089 0090 /** 0091 * Tests Scheduler::countRunningJobs and Scheduler::hasRunningJobs 0092 */ 0093 void testCountRunningJobs(); 0094 void testCountRunningJobs_data(); 0095 0096 /** 0097 * Tests if after stopping the scheduler all jobs are not running 0098 */ 0099 void testStopScheduler(); 0100 void testStopScheduler_data(); 0101 0102 /** 0103 * Stops the scheduler and then starts it again to see if jobs 0104 * are correctly started 0105 */ 0106 void testSchedulerStopStart(); 0107 void testSchedulerStopStart_data(); 0108 0109 void testSuspendScheduler(); 0110 void testSuspendScheduler_data(); 0111 0112 /** 0113 * Tests the case where the JobQueuePolicy is set to stop 0114 * (this also happens on Scheduler::stop()) by default it is set to start. 0115 * Jobs with a Start policy might be started depending on their 0116 * other settings 0117 */ 0118 void testJobQueueStopPolicy(); 0119 void testJobQueueStopPolicy_data(); 0120 0121 /** 0122 * Tests the case where the JobQueuePolicy is set to stop, 0123 * and then set to start again. By default it is set to start. 0124 * Jobs with a Start policy might be started depending on their 0125 * other settings 0126 */ 0127 void testJobQueueStopStartPolicy(); 0128 void testJobQueueStopStartPolicy_data(); 0129 0130 void testJobErrorType(); 0131 void testJobErrorType_data(); 0132 0133 /** 0134 * There is no connection and transfers are added. 0135 * Then connection is retrieved. 0136 */ 0137 void testGettingNetworkConnection(); 0138 void testGettingNetworkConnection_data(); 0139 0140 /** 0141 * There is a connection and transfers are added. 0142 * Then connection is lost. 0143 */ 0144 void testLosingNetworkConnection(); 0145 void testLosingNetworkConnection_data(); 0146 0147 void testShouldUpdate(); 0148 void testShouldUpdate_data(); 0149 0150 private: 0151 static const int NO_LIMIT; 0152 }; 0153 0154 #endif