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

Proposed by Andrew Hayzen
Status: Superseded
Proposed branch: lp:~ahayzen/ubuntu-ui-extras/fix-copies-not-set-updateFrom
Merge into: lp:ubuntu-ui-extras/staging
Diff against target: 150 lines (+93/-7)
3 files modified
debian/changelog (+2/-2)
modules/Ubuntu/Components/Extras/Printers/printer/printer.cpp (+1/-0)
tests/unittests/Printers/tst_printer.cpp (+90/-5)
To merge this branch: bzr merge lp:~ahayzen/ubuntu-ui-extras/fix-copies-not-set-updateFrom
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+321539@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.
135. By Andrew Hayzen

* Remove debug line

Unmerged revisions

Preview Diff

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

Subscribers

People subscribed via source and target branches