Merge lp:~ahayzen/ubuntu-ui-extras/fix-copies-not-set-updateFrom into lp:ubuntu-ui-extras/staging

Proposed by Andrew Hayzen
Status: Merged
Merged at revision: 133
Proposed branch: lp:~ahayzen/ubuntu-ui-extras/fix-copies-not-set-updateFrom
Merge into: lp:ubuntu-ui-extras/staging
Diff against target: 129 lines (+89/-5)
2 files modified
modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp (+1/-0)
tests/unittests/Printers/tst_printer.cpp (+88/-5)
To merge this branch: bzr merge lp:~ahayzen/ubuntu-ui-extras/fix-copies-not-set-updateFrom
Reviewer Review Type Date Requested Status
system-apps-ci-bot continuous-integration Needs Fixing
Jonas G. Drange (community) Approve
Review via email: mp+321540@code.launchpad.net

Commit message

* Set m_copies when using updateFrom and add test for updateFrom

Description of the change

* Set m_copies when using updateFrom and add test for updateFrom

To post a comment you must log in.
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

Good that you added a test. Thanks!

review: Approve
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp'
2--- modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-03-21 13:01:42 +0000
3+++ modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp 2017-03-31 11:03:30 +0000
4@@ -410,6 +410,7 @@
5 // Note: do not use loadAttributes otherwise can cause UI block
6 m_acceptJobs = other->m_acceptJobs;
7 m_backend = other->m_backend;
8+ m_copies = other->m_copies;
9 m_defaultColorModel = other->m_defaultColorModel;
10 m_defaultPrintQuality = other->m_defaultPrintQuality;
11 m_deviceUri = other->m_deviceUri;
12
13=== modified file 'tests/unittests/Printers/tst_printer.cpp'
14--- tests/unittests/Printers/tst_printer.cpp 2017-03-20 13:31:55 +0000
15+++ tests/unittests/Printers/tst_printer.cpp 2017-03-31 11:03:30 +0000
16@@ -36,14 +36,17 @@
17 void init()
18 {
19 m_backend = new MockPrinterBackend(m_printerName);
20- m_instance = new Printer(m_backend);
21+ m_instance = QSharedPointer<Printer>(new Printer(m_backend));
22 }
23 void cleanup()
24 {
25- QSignalSpy destroyedSpy(m_instance, SIGNAL(destroyed(QObject*)));
26- m_instance->deleteLater();
27+ QSignalSpy destroyedSpy(m_instance.data(), SIGNAL(destroyed(QObject*)));
28+ m_instance.clear();
29 QTRY_COMPARE(destroyedSpy.count(), 1);
30- delete m_backend;
31+
32+ if (m_backend) {
33+ delete m_backend;
34+ }
35 }
36 void testName()
37 {
38@@ -370,10 +373,90 @@
39 // Ideally, all QObjects in the Printer API needs to be tested here.
40 QCOMPARE(p.jobs()->thread(), &thread);
41 }
42+
43+ void testUpdateFrom()
44+ {
45+ // Setup any variables for flipped values
46+ bool newAcceptJobs = !m_instance->acceptJobs();
47+ int newCopies = m_instance->copies() + 1;
48+ QString newDeviceUri = m_instance->deviceUri() + "/test";
49+ bool newShared = !m_instance->shared();
50+ QString newLastMessage = m_instance->lastMessage() + "test";
51+
52+ // Setup color model and quality models
53+ ColorModel colorA;
54+ colorA.text = "ColorA";
55+
56+ ColorModel defaultColorModel;
57+ defaultColorModel.text = "ColorB";
58+ QList<ColorModel> colorModels({colorA, defaultColorModel});
59+
60+ PrintQuality qualityA;
61+ qualityA.name = "QualityA";
62+
63+ PrintQuality defaultPrintQuality;
64+ defaultPrintQuality.name = "QualityB";
65+ QList<PrintQuality> qualities({qualityA, defaultPrintQuality});
66+
67+ QList<PrinterEnum::DuplexMode> duplexModes({
68+ PrinterEnum::DuplexMode::DuplexNone,
69+ PrinterEnum::DuplexMode::DuplexLongSide,
70+ PrinterEnum::DuplexMode::DuplexShortSide,
71+ PrinterEnum::DuplexMode::DuplexShortSide
72+ });
73+
74+ auto newDefaultDuplexMode = m_instance->defaultDuplexMode() == PrinterEnum::DuplexMode::DuplexNone
75+ ? PrinterEnum::DuplexMode::DuplexShortSide
76+ : PrinterEnum::DuplexMode::DuplexNone;
77+
78+ // Create a printer that has different settings to the default
79+ QString printerName = "test-printer-b";
80+
81+ MockPrinterBackend *backend = new MockPrinterBackend(printerName);
82+ backend->printerOptions[printerName].insert("AcceptJobs", newAcceptJobs);
83+ backend->printerOptions[printerName].insert("Copies", QString::number(newCopies));
84+ backend->printerOptions[printerName].insert("DefaultColorModel", QVariant::fromValue(defaultColorModel));
85+ backend->printerOptions[printerName].insert("DefaultPrintQuality", QVariant::fromValue(defaultPrintQuality));
86+ backend->printerOptions[printerName].insert(
87+ "DeviceUri", newDeviceUri);
88+ backend->printerOptions[printerName].insert("Shared", newShared);
89+ backend->printerOptions[printerName].insert(
90+ "StateMessage", newLastMessage);
91+ backend->printerOptions[printerName].insert(
92+ "SupportedColorModels", QVariant::fromValue(colorModels));
93+ backend->printerOptions[printerName].insert(
94+ "SupportedPrintQualities", QVariant::fromValue(qualities));
95+
96+ backend->m_supportedDuplexModes = duplexModes;
97+ backend->printerOptions[printerName].insert(
98+ "Duplex", Utils::duplexModeToPpdChoice(newDefaultDuplexMode));
99+
100+ QSharedPointer<Printer> p = QSharedPointer<Printer>(new Printer(backend));
101+
102+ // Update the default printer from this
103+ m_instance->updateFrom(p);
104+
105+ // Check we have the new values
106+ QCOMPARE(m_instance->acceptJobs(), newAcceptJobs);
107+ QCOMPARE(m_instance->copies(), newCopies);
108+ QCOMPARE(m_instance->defaultColorModel(), defaultColorModel);
109+ QCOMPARE(m_instance->defaultPrintQuality(), defaultPrintQuality);
110+ QCOMPARE(m_instance->deviceUri(), newDeviceUri);
111+ QCOMPARE(m_instance->shared(), newShared);
112+ QCOMPARE(m_instance->lastMessage(), newLastMessage);
113+ QCOMPARE(m_instance->supportedColorModels(), colorModels);
114+ QCOMPARE(m_instance->supportedPrintQualities(), qualities);
115+
116+ // We test that the duplexModes have changed to check that the backend
117+ // has changed, as m_backend is private we can't check directly
118+ QCOMPARE(m_instance->defaultDuplexMode(), newDefaultDuplexMode);
119+ QCOMPARE(m_instance->supportedDuplexModes(), duplexModes);
120+ }
121+
122 private:
123 QString m_printerName = "my-printer";
124 MockPrinterBackend *m_backend = nullptr;
125- Printer *m_instance = nullptr;
126+ QSharedPointer<Printer> m_instance;
127 };
128
129 QTEST_GUILESS_MAIN(TestPrinter)

Subscribers

People subscribed via source and target branches