Merge lp:~ahayzen/ubuntu-ui-extras/job-impressions-update into lp:~phablet-team/ubuntu-ui-extras/printer-staging

Proposed by Andrew Hayzen
Status: Merged
Approved by: Jonas G. Drange
Approved revision: 156
Merged at revision: 149
Proposed branch: lp:~ahayzen/ubuntu-ui-extras/job-impressions-update
Merge into: lp:~phablet-team/ubuntu-ui-extras/printer-staging
Prerequisite: lp:~ahayzen/ubuntu-ui-extras/job-model-split-update
Diff against target: 458 lines (+130/-32)
15 files modified
modules/Ubuntu/Components/Extras/Example/PrinterQueue.qml (+1/-4)
modules/Ubuntu/Components/Extras/Printers/CMakeLists.txt (+1/-1)
modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp (+16/-0)
modules/Ubuntu/Components/Extras/Printers/models/jobmodel.cpp (+21/-0)
modules/Ubuntu/Components/Extras/Printers/models/jobmodel.h (+4/-0)
modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp (+2/-2)
modules/Ubuntu/Components/Extras/Printers/models/printermodel.h (+2/-2)
modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp (+7/-0)
modules/Ubuntu/Components/Extras/Printers/printer/signalratelimiter.cpp (+28/-6)
modules/Ubuntu/Components/Extras/Printers/printer/signalratelimiter.h (+8/-6)
modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp (+7/-0)
po/ubuntu-ui-extras.pot (+2/-2)
tests/unittests/Printers/CMakeLists.txt (+3/-3)
tests/unittests/Printers/mockbackend.h (+2/-0)
tests/unittests/Printers/tst_signalratelimiter.cpp (+26/-6)
To merge this branch: bzr merge lp:~ahayzen/ubuntu-ui-extras/job-impressions-update
Reviewer Review Type Date Requested Status
Jonas G. Drange (community) Approve
Andrew Hayzen Pending
Review via email: mp+319687@code.launchpad.net

This proposal supersedes a proposal from 2017-03-09.

Commit message

* Connect job-impressions-completed from cups to PrinterJob::impressionsCompleted()
* In the job model listen to printerStateChanged as changes t job-impressions-completed causes that signal
* Improve the PrinterSignalHandler to limit the maximum wait time of unprocessed signals to four times the timeout
* Add unit test for SignalRateLimiter to check it does perform a flush
* Rename PrinterSignalHandler to SignalRateLimiter

Description of the change

* Connect job-impressions-completed from cups to PrinterJob::impressionsCompleted()
* In the job model listen to printerStateChanged as changes t job-impressions-completed causes that signal
* Improve the PrinterSignalHandler to limit the maximum wait time of unprocessed signals to four times the timeout
* Add unit test for SignalRateLimiter to check it does perform a flush
* Rename PrinterSignalHandler to SignalRateLimiter

To post a comment you must log in.
Revision history for this message
Andrew Hayzen (ahayzen) wrote : Posted in a previous version of this proposal

Testing:
- Add a printer which has an address of lpd://127.0.0.1 so that it will spool on the cups server
- Download the serverguide.pdf (which has loads of pages) from [0]
- Open the PrinterQueue.qml example and open the printer you just added
- Add the serverguide.pdf to the printer queue for the printer you just added
- Watch the printing N pages count increment (also note the freezes that happen, eg if there is already a job being rendered when starting the example it can freeze)

0 - http://bazaar.launchpad.net/~ubuntu-docviewer-dev/ubuntu-docviewer-app/lo-viewer/download/head:/serverguide.pdf-20150423201617-20cgubqqf8rhokei-1/serverguide.pdf

Revision history for this message
Andrew Hayzen (ahayzen) wrote : Posted in a previous version of this proposal

Should job-media-sheets-completed be used instead of job-impressesions-completed? Does this then take duplex into account?

review: Needs Information
Revision history for this message
Jonas G. Drange (jonas-drange) wrote : Posted in a previous version of this proposal

ack on the rate limiter! good stuff

Revision history for this message
Jonas G. Drange (jonas-drange) wrote : Posted in a previous version of this proposal

Re: job-media-*, I'd have to read the IPP spec to be sure. Maybe mimic SCP here?

Revision history for this message
Jonas G. Drange (jonas-drange) wrote : Posted in a previous version of this proposal

Got this one:
void PrinterJob::loadDefaults() 12
QObject::connect: Cannot queue arguments of type 'QVector<int>'
(Make sure 'QVector<int>' is registered using qRegisterMetaType().)

Introduced by this branch?

review: Needs Information
Revision history for this message
Jonas G. Drange (jonas-drange) wrote : Posted in a previous version of this proposal

The window only freezes, no queues are displayed. I think we need to fix that.

And the freezing is introduced by this branch, because using printer-staging trunk, going to Printers.qml -> <printer> -> Jobs enumerates the jobs without the lag.

review: Needs Fixing
153. By Andrew Hayzen

* Pull of upstream

154. By Andrew Hayzen

* Try to use job-media-sheets-completed first

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

This is now much more stable for me :-)

Also I've tried sending a few (non-)duplex jobs for my HP printer, job-media-sheets-completed and job-impressions-completed are always the same (I wonder if the driver isn't correct).

The spec states the following:
- job-media-sheets-completed: "This job attribute specifies the media-sheets completed marking and stacking for the entire job so far whether those sheets have been processed on one side or on both."
- job-impressions-completed: "This job attribute specifies the number of impressions completed for the job so far. For printing devices, the impressions completed includes interpreting, marking, and stacking the output."

155. By Andrew Hayzen

* Pull of upstream
* Fix tests (emulation in MockBackend::printerGetJobAttributes)

156. By Andrew Hayzen

* Pull of upstream

Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

works well! Thank you!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/Extras/Example/PrinterQueue.qml'
2--- modules/Ubuntu/Components/Extras/Example/PrinterQueue.qml 2017-03-01 13:45:14 +0000
3+++ modules/Ubuntu/Components/Extras/Example/PrinterQueue.qml 2017-03-15 17:52:16 +0000
4@@ -72,10 +72,7 @@
5 ListItemLayout {
6 id: modelLayout
7 title.text: displayName
8- subtitle.text: model.title + " (" + model.id + ") State: " + model.state
9- + " Color: " + model.colorModel + " CreationTime: "
10- + model.creationTime + " PageRange: "
11- + model.printRange + " Messages: " + model.messages;
12+ subtitle.text: model.title + " (" + model.id + ")\nPrinting " + model.impressionsCompleted + " pages"
13 subtitle.wrapMode: Text.WrapAtWordBoundaryOrAnywhere
14 subtitle.maximumLineCount: 3
15 }
16
17=== modified file 'modules/Ubuntu/Components/Extras/Printers/CMakeLists.txt'
18--- modules/Ubuntu/Components/Extras/Printers/CMakeLists.txt 2017-03-15 17:52:16 +0000
19+++ modules/Ubuntu/Components/Extras/Printers/CMakeLists.txt 2017-03-15 17:52:16 +0000
20@@ -42,7 +42,7 @@
21
22 printer/printer.cpp
23 printer/printerjob.cpp
24- printer/printersignalhandler.cpp
25+ printer/signalratelimiter.cpp
26 printers/printers.cpp
27
28 enums.h
29
30=== modified file 'modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp'
31--- modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-03-15 17:52:16 +0000
32+++ modules/Ubuntu/Components/Extras/Printers/backend/backend_cups.cpp 2017-03-15 17:52:16 +0000
33@@ -487,6 +487,16 @@
34 map.insert("Duplex", QVariant(""));
35 }
36
37+ // Try job-media-sheets-completed first as it should include duplex
38+ // if it doesn't exist fallback to job-impressions-completed
39+ if (__CUPS_ATTR_EXISTS(rawMap, "job-media-sheets-completed", int)) {
40+ map.insert("impressionsCompleted", rawMap.value("job-media-sheets-completed"));
41+ } else if (__CUPS_ATTR_EXISTS(rawMap, "job-impressions-completed", int)) {
42+ map.insert("impressionsCompleted", rawMap.value("job-impressions-completed"));
43+ } else {
44+ map.insert("impressionsCompleted", QVariant(0));
45+ }
46+
47 if (__CUPS_ATTR_EXISTS(rawMap, "landscape", bool)) {
48 map.insert("landscape", rawMap.value("landscape"));
49 } else {
50@@ -535,6 +545,12 @@
51 map.insert("Size", QVariant(0));
52 }
53
54+ // If there is a state then get it, as there could have been a signal
55+ // flood. Which then means a forceJobRefresh is able to update the state
56+ if (__CUPS_ATTR_EXISTS(rawMap, "job-state", int)) {
57+ map.insert("State", rawMap.value("job-state").toInt());
58+ }
59+
60 if (__CUPS_ATTR_EXISTS(rawMap, "job-originating-user-name", QString)) {
61 map.insert("User", rawMap.value("job-originating-user-name"));
62 } else {
63
64=== modified file 'modules/Ubuntu/Components/Extras/Printers/models/jobmodel.cpp'
65--- modules/Ubuntu/Components/Extras/Printers/models/jobmodel.cpp 2017-03-15 17:52:16 +0000
66+++ modules/Ubuntu/Components/Extras/Printers/models/jobmodel.cpp 2017-03-15 17:52:16 +0000
67@@ -41,6 +41,13 @@
68 connect(m_backend, SIGNAL(jobLoaded(QString, int, QMap<QString, QVariant>)),
69 this, SLOT(updateJob(QString, int, QMap<QString, QVariant>)));
70
71+ // Impressions completed happens via printer state changed
72+ QObject::connect(m_backend, &PrinterBackend::printerStateChanged,
73+ &m_signalHandler, &SignalRateLimiter::onPrinterStateChanged);
74+
75+ QObject::connect(&m_signalHandler, SIGNAL(printerModified(const QString&)),
76+ this, SLOT(jobSignalPrinterModified(const QString&)));
77+
78 // Add already existing jobs
79 // TODO: even this should probably be in a background thread?
80 // so that it doesn't block startup?
81@@ -134,6 +141,20 @@
82 }
83 }
84
85+void JobModel::jobSignalPrinterModified(const QString &printerName)
86+{
87+ // Find the active or pending job and force a refresh
88+ // We force refresh pending jobs incase there is a flood of signals
89+ // meaning that the jobStateChanged signal might not have happened yet
90+ Q_FOREACH(auto job, m_jobs) {
91+ if (job->printerName() == printerName
92+ && (job->state() == PrinterEnum::JobState::Processing
93+ || job->state() == PrinterEnum::JobState::Pending)) {
94+ Q_EMIT forceJobRefresh(printerName, job->jobId());
95+ }
96+ }
97+}
98+
99 void JobModel::addJob(QSharedPointer<PrinterJob> job)
100 {
101 int i = m_jobs.size();
102
103=== modified file 'modules/Ubuntu/Components/Extras/Printers/models/jobmodel.h'
104--- modules/Ubuntu/Components/Extras/Printers/models/jobmodel.h 2017-03-15 17:52:16 +0000
105+++ modules/Ubuntu/Components/Extras/Printers/models/jobmodel.h 2017-03-15 17:52:16 +0000
106@@ -20,6 +20,7 @@
107 #include "printers_global.h"
108 #include "backend/backend.h"
109 #include "printer/printerjob.h"
110+#include "printer/signalratelimiter.h"
111
112 #include <QAbstractListModel>
113 #include <QByteArray>
114@@ -89,6 +90,7 @@
115 PrinterBackend *m_backend;
116
117 QList<QSharedPointer<PrinterJob>> m_jobs;
118+ SignalRateLimiter m_signalHandler;
119 private Q_SLOTS:
120 void jobCreated(const QString &text, const QString &printer_uri,
121 const QString &printer_name, uint printer_state,
122@@ -111,10 +113,12 @@
123 uint job_state, const QString &job_state_reasons,
124 const QString &job_name,
125 uint job_impressions_completed);
126+ void jobSignalPrinterModified(const QString &printerName);
127 void updateJob(QString printerName, int jobId, QMap<QString, QVariant> attributes);
128
129 Q_SIGNALS:
130 void countChanged();
131+ void forceJobRefresh(const QString &printerName, const int jobId);
132 };
133
134 class PRINTERS_DECL_EXPORT JobFilter : public QSortFilterProxyModel
135
136=== modified file 'modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp'
137--- modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp 2017-03-15 17:52:16 +0000
138+++ modules/Ubuntu/Components/Extras/Printers/models/printermodel.cpp 2017-03-15 17:52:16 +0000
139@@ -32,9 +32,9 @@
140 QObject::connect(m_backend, &PrinterBackend::printerAdded,
141 this, &PrinterModel::printerAdded);
142 QObject::connect(m_backend, &PrinterBackend::printerModified,
143- &m_signalHandler, &PrinterSignalHandler::onPrinterModified);
144+ &m_signalHandler, &SignalRateLimiter::onPrinterModified);
145 QObject::connect(m_backend, &PrinterBackend::printerStateChanged,
146- &m_signalHandler, &PrinterSignalHandler::onPrinterModified);
147+ &m_signalHandler, &SignalRateLimiter::onPrinterModified);
148 QObject::connect(m_backend, &PrinterBackend::printerDeleted,
149 this, &PrinterModel::printerDeleted);
150
151
152=== modified file 'modules/Ubuntu/Components/Extras/Printers/models/printermodel.h'
153--- modules/Ubuntu/Components/Extras/Printers/models/printermodel.h 2017-03-15 17:52:16 +0000
154+++ modules/Ubuntu/Components/Extras/Printers/models/printermodel.h 2017-03-15 17:52:16 +0000
155@@ -21,7 +21,7 @@
156
157 #include "models/jobmodel.h"
158 #include "printer/printer.h"
159-#include "printer/printersignalhandler.h"
160+#include "printer/signalratelimiter.h"
161
162 #include <QAbstractListModel>
163 #include <QByteArray>
164@@ -104,7 +104,7 @@
165 PrinterBackend *m_backend;
166
167 QList<QSharedPointer<Printer>> m_printers;
168- PrinterSignalHandler m_signalHandler;
169+ SignalRateLimiter m_signalHandler;
170
171 private Q_SLOTS:
172 void printerLoaded(QSharedPointer<Printer> printer);
173
174=== modified file 'modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp'
175--- modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp 2017-03-15 17:52:16 +0000
176+++ modules/Ubuntu/Components/Extras/Printers/printer/printerjob.cpp 2017-03-15 17:52:16 +0000
177@@ -178,6 +178,7 @@
178 }
179 }
180
181+ setImpressionsCompleted(attributes.value("impressionsCompleted").toInt());
182 setLandscape(attributes.value("landscape").toBool());
183 setMessages(attributes.value("messages").toStringList());
184
185@@ -204,6 +205,12 @@
186 }
187
188 setReverse(attributes.value("OutputOrder").toString() == "Reverse");
189+
190+ // If there was a state then set it
191+ if (attributes.contains("State")) {
192+ setState(static_cast<PrinterEnum::JobState>(attributes.value("State").toInt()));
193+ }
194+
195 setSize(attributes.value("Size").toInt());
196 setUser(attributes.value("User").toString());
197 }
198
199=== renamed file 'modules/Ubuntu/Components/Extras/Printers/printer/printersignalhandler.cpp' => 'modules/Ubuntu/Components/Extras/Printers/printer/signalratelimiter.cpp'
200--- modules/Ubuntu/Components/Extras/Printers/printer/printersignalhandler.cpp 2017-02-21 10:46:29 +0000
201+++ modules/Ubuntu/Components/Extras/Printers/printer/signalratelimiter.cpp 2017-03-15 17:52:16 +0000
202@@ -14,9 +14,9 @@
203 * along with this program. If not, see <http://www.gnu.org/licenses/>.
204 */
205
206-#include "printersignalhandler.h"
207+#include "signalratelimiter.h"
208
209-PrinterSignalHandler::PrinterSignalHandler(int triggerEventDelay,
210+SignalRateLimiter::SignalRateLimiter(int triggerEventDelay,
211 QObject *parent)
212 : QObject(parent)
213 {
214@@ -24,11 +24,11 @@
215 connect(&m_timer, SIGNAL(timeout()), this, SLOT(process()));
216 }
217
218-PrinterSignalHandler::~PrinterSignalHandler()
219+SignalRateLimiter::~SignalRateLimiter()
220 {
221 }
222
223-void PrinterSignalHandler::process()
224+void SignalRateLimiter::process()
225 {
226 Q_FOREACH(auto printer, m_unprocessed) {
227 Q_EMIT printerModified(printer);
228@@ -37,7 +37,7 @@
229 m_timer.stop();
230 }
231
232-void PrinterSignalHandler::onPrinterModified(
233+void SignalRateLimiter::onPrinterModified(
234 const QString &text, const QString &printerUri,
235 const QString &printerName, uint printerState,
236 const QString &printerStateReason, bool acceptingJobs)
237@@ -49,11 +49,22 @@
238 Q_UNUSED(printerStateReason);
239 Q_UNUSED(acceptingJobs);
240
241+ // Track when the first item was added to the unprocessed queue
242+ if (m_unprocessed.count() == 0) {
243+ m_unprocessed_time = QDateTime::currentDateTime();
244+ }
245+
246 m_unprocessed << printerName;
247 m_timer.start();
248+
249+ // Ensure that process is fired if we have reached four times
250+ // longer than the timer, this is due to many signals coming in rapidly
251+ if (m_unprocessed_time.msecsTo(QDateTime::currentDateTime()) > m_timer.interval() * 4) {
252+ process();
253+ }
254 }
255
256-void PrinterSignalHandler::onPrinterStateChanged(
257+void SignalRateLimiter::onPrinterStateChanged(
258 const QString &text, const QString &printerUri,
259 const QString &printerName, uint printerState,
260 const QString &printerStateReason, bool acceptingJobs)
261@@ -64,6 +75,17 @@
262 Q_UNUSED(printerStateReason);
263 Q_UNUSED(acceptingJobs);
264
265+ // Track when the first item was added to the unprocessed queue
266+ if (m_unprocessed.count() == 0) {
267+ m_unprocessed_time = QDateTime::currentDateTime();
268+ }
269+
270 m_unprocessed << printerName;
271 m_timer.start();
272+
273+ // Ensure that process is fired if we have reached four times
274+ // longer than the timer, this is due to many signals coming in rapidly
275+ if (m_unprocessed_time.msecsTo(QDateTime::currentDateTime()) > m_timer.interval() * 4) {
276+ process();
277+ }
278 }
279
280=== renamed file 'modules/Ubuntu/Components/Extras/Printers/printer/printersignalhandler.h' => 'modules/Ubuntu/Components/Extras/Printers/printer/signalratelimiter.h'
281--- modules/Ubuntu/Components/Extras/Printers/printer/printersignalhandler.h 2017-02-21 10:46:29 +0000
282+++ modules/Ubuntu/Components/Extras/Printers/printer/signalratelimiter.h 2017-03-15 17:52:16 +0000
283@@ -14,24 +14,26 @@
284 * along with this program. If not, see <http://www.gnu.org/licenses/>.
285 */
286
287-#ifndef USC_PRINTER_SIGNAL_HANDLER_H
288-#define USC_PRINTER_SIGNAL_HANDLER_H
289+#ifndef USC_SIGNAL_RATE_LIMITER_H
290+#define USC_SIGNAL_RATE_LIMITER_H
291
292 #include "printers_global.h"
293
294+#include <QDateTime>
295 #include <QObject>
296 #include <QSet>
297 #include <QTimer>
298
299-class PRINTERS_DECL_EXPORT PrinterSignalHandler : public QObject
300+class PRINTERS_DECL_EXPORT SignalRateLimiter : public QObject
301 {
302 Q_OBJECT
303 QTimer m_timer;
304 QSet<QString> m_unprocessed;
305+ QDateTime m_unprocessed_time;
306 public:
307- explicit PrinterSignalHandler(int triggerEventDelay = 500,
308+ explicit SignalRateLimiter(int triggerEventDelay = 500,
309 QObject *parent = Q_NULLPTR);
310- ~PrinterSignalHandler();
311+ ~SignalRateLimiter();
312
313 public Q_SLOTS:
314 void onPrinterModified(
315@@ -52,4 +54,4 @@
316 void printerModified(const QString &printerName);
317 };
318
319-#endif // USC_PRINTER_SIGNAL_HANDLER_H
320+#endif // USC_SIGNAL_RATE_LIMITERR_H
321
322=== modified file 'modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp'
323--- modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-03-15 17:52:16 +0000
324+++ modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp 2017-03-15 17:52:16 +0000
325@@ -65,6 +65,13 @@
326
327 jobAdded(m_jobs.getJob(printerName, jobId));
328 });
329+
330+ // If the jobModel forces a refresh, load extended attributes for the job
331+ connect(&m_jobs, &JobModel::forceJobRefresh, [this](
332+ const QString &printerName, const int jobId) {
333+ jobAdded(m_jobs.getJob(printerName, jobId));
334+ });
335+
336 connect(&m_model, &QAbstractItemModel::rowsInserted, [this](
337 const QModelIndex &parent, int first, int) {
338 auto printer = m_model.data(
339
340=== modified file 'po/ubuntu-ui-extras.pot'
341--- po/ubuntu-ui-extras.pot 2017-03-10 13:15:27 +0000
342+++ po/ubuntu-ui-extras.pot 2017-03-15 17:52:16 +0000
343@@ -8,7 +8,7 @@
344 msgstr ""
345 "Project-Id-Version: ubuntu-ui-extras\n"
346 "Report-Msgid-Bugs-To: \n"
347-"POT-Creation-Date: 2017-03-10 14:13+0100\n"
348+"POT-Creation-Date: 2017-03-15 17:39+0000\n"
349 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
350 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
351 "Language-Team: LANGUAGE <LL@li.org>\n"
352@@ -99,7 +99,7 @@
353 msgid "Stopped"
354 msgstr ""
355
356-#: modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp:332
357+#: modules/Ubuntu/Components/Extras/Printers/printers/printers.cpp:367
358 msgid "Test page"
359 msgstr ""
360
361
362=== modified file 'tests/unittests/Printers/CMakeLists.txt'
363--- tests/unittests/Printers/CMakeLists.txt 2017-03-08 16:13:02 +0000
364+++ tests/unittests/Printers/CMakeLists.txt 2017-03-15 17:52:16 +0000
365@@ -45,9 +45,9 @@
366 target_link_libraries(testPrintersJobFilter UbuntuComponentsExtrasPrintersQml Qt5::Test Qt5::Gui)
367 add_test(tst_jobfilter testPrintersJobFilter)
368
369-add_executable(testPrintersSignalHandler tst_signalhandler.cpp ${MOCK_SOURCES})
370-target_link_libraries(testPrintersSignalHandler UbuntuComponentsExtrasPrintersQml Qt5::Test Qt5::Gui)
371-add_test(tst_signalhandler testPrintersSignalHandler)
372+add_executable(testPrintersSignalRateLimiter tst_signalratelimiter.cpp ${MOCK_SOURCES})
373+target_link_libraries(testPrintersSignalRateLimiter UbuntuComponentsExtrasPrintersQml Qt5::Test Qt5::Gui)
374+add_test(tst_signalratelimiter testPrintersSignalRateLimiter)
375
376 add_executable(testPrintersDevice tst_printerdevice.cpp ${MOCK_SOURCES})
377 target_link_libraries(testPrintersDevice UbuntuComponentsExtrasPrintersQml Qt5::Test Qt5::Gui)
378
379=== modified file 'tests/unittests/Printers/mockbackend.h'
380--- tests/unittests/Printers/mockbackend.h 2017-03-15 17:52:16 +0000
381+++ tests/unittests/Printers/mockbackend.h 2017-03-15 17:52:16 +0000
382@@ -236,6 +236,7 @@
383 attributes.insert("CompletedTime", job->completedTime());
384 attributes.insert("CreationTime", job->creationTime());
385 attributes.insert("Duplex", Utils::duplexModeToPpdChoice(job->getDuplexMode()));
386+ attributes.insert("impressionsCompleted", job->impressionsCompleted());
387 attributes.insert("landscape", job->landscape());
388 attributes.insert("messages", job->messages());
389 if (job->printRangeMode() == PrinterEnum::PrintRange::AllPages) {
390@@ -246,6 +247,7 @@
391 attributes.insert("ProcessingTime", job->processingTime());
392 attributes.insert("Quality", job->getPrintQuality().name);
393 attributes.insert("OutputOrder", job->reverse() ? "Reverse" : "Normal");
394+ attributes.insert("State", static_cast<int>(job->state()));
395 attributes.insert("Size", job->size());
396 attributes.insert("User", job->user());
397
398
399=== renamed file 'tests/unittests/Printers/tst_signalhandler.cpp' => 'tests/unittests/Printers/tst_signalratelimiter.cpp'
400--- tests/unittests/Printers/tst_signalhandler.cpp 2017-02-21 10:46:29 +0000
401+++ tests/unittests/Printers/tst_signalratelimiter.cpp 2017-03-15 17:52:16 +0000
402@@ -14,31 +14,51 @@
403 * along with this program. If not, see <http://www.gnu.org/licenses/>.
404 */
405
406-#include "printer/printersignalhandler.h"
407+#include "printer/signalratelimiter.h"
408
409+#include <QDateTime>
410 #include <QDebug>
411 #include <QObject>
412 #include <QSignalSpy>
413 #include <QTest>
414
415-class TestSignalHandler : public QObject
416+class TestSignalRateLimiter : public QObject
417 {
418 Q_OBJECT
419 private Q_SLOTS:
420 void testEmptyCount()
421 {
422- PrinterSignalHandler handler(500);
423+ SignalRateLimiter handler(500);
424 QSignalSpy modifiedSpy(&handler, SIGNAL(printerModified(const QString&)));
425
426- for (int i = 0; i < 500; i++) {
427+ for (int i = 0; i < 20; i++) {
428 handler.onPrinterStateChanged("spam!", "ipp://bar/baz", "printer-a", 0, "none", true);
429 }
430
431 modifiedSpy.wait(1000);
432 QCOMPARE(modifiedSpy.count(), 1);
433 }
434+ void testUnprocessedTime()
435+ {
436+ // Keep sending jobs with no gap for longer than four times the
437+ // event delay. Check that two signals are emitted.
438+ // One from the forcing of the signal and one as the timer finishes
439+
440+ int eventDelay = 200;
441+ SignalRateLimiter handler(eventDelay);
442+ QSignalSpy modifiedSpy(&handler, SIGNAL(printerModified(const QString&)));
443+
444+ QDateTime start = QDateTime::currentDateTime();
445+
446+ while (start.msecsTo(QDateTime::currentDateTime()) < eventDelay * 5) {
447+ handler.onPrinterStateChanged("spam!", "ipp://foo/bar", "printer-a", 0, "none", true);
448+ }
449+
450+ modifiedSpy.wait(eventDelay * 2);
451+ QCOMPARE(modifiedSpy.count(), 2);
452+ }
453 };
454
455-QTEST_GUILESS_MAIN(TestSignalHandler)
456-#include "tst_signalhandler.moc"
457+QTEST_GUILESS_MAIN(TestSignalRateLimiter)
458+#include "tst_signalratelimiter.moc"
459

Subscribers

People subscribed via source and target branches