Merge lp:~ahayzen/qtubuntu-print/add-unit-tests into lp:qtubuntu-print
- add-unit-tests
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Michael Sheldon |
Approved revision: | 31 |
Merged at revision: | 3 |
Proposed branch: | lp:~ahayzen/qtubuntu-print/add-unit-tests |
Merge into: | lp:qtubuntu-print |
Prerequisite: | lp:~ahayzen/qtubuntu-print/empty-branch-for-bileto |
Diff against target: |
574 lines (+373/-75) 11 files modified
CMakeLists.txt (+11/-69) po/CMakeLists.txt (+8/-1) po/qtubuntu-print.pot (+5/-5) src/CMakeLists.txt (+71/-0) tests/CMakeLists.txt (+2/-0) tests/unittests/CMakeLists.txt (+35/-0) tests/unittests/fakeprint/CMakeLists.txt (+49/-0) tests/unittests/fakeprint/fakeprint.json (+3/-0) tests/unittests/fakeprint/main.cpp (+72/-0) tests/unittests/tst_fakeprinterinfo.cpp (+53/-0) tests/unittests/tst_printerinfo.cpp (+64/-0) |
To merge this branch: | bzr merge lp:~ahayzen/qtubuntu-print/add-unit-tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Sheldon (community) | Approve | ||
Andrew Hayzen (community) | Abstain | ||
Review via email: mp+317785@code.launchpad.net |
Commit message
* Move src files into their own directory
* Modify po to read src correctly
* Add unit tests for qtubuntu-print checking the printerName exists and the name, makeandmodel and location are correct
* Add fakeprint plugin to unittests which checks we are actually loading a custom plugin and not the system one
Description of the change
* Move src files into their own directory
* Modify po to read src correctly
* Add unit tests for qtubuntu-print checking the printerName exists and the name, makeandmodel and location are correct
* Add fakeprint plugin to unittests which checks we are actually loading a custom plugin and not the system one
- 26. By Andrew Hayzen
-
* Set vars for use in the parent scope, so we hardcode less dirs
- 27. By Andrew Hayzen
-
* Fix qmake not running
- 28. By Andrew Hayzen
-
* Make the find_package required
- 29. By Andrew Hayzen
-
* Pull of upstream fix for missing depends
Andrew Hayzen (ahayzen) wrote : | # |
Fixed in the upstream branch, the packaging fixes had removed qt5-default as a build-dep which meant that the qmake command in cmake to get the QT_INSTALL_PLUGINS directory failed with "qmake: could not find a Qt installation of ''".
- 30. By Andrew Hayzen
-
* Pull of upstream removal of qt5-default and using -qt=qt5
Michael Sheldon (michael-sheldon) wrote : | # |
One small query in the diff comments, otherwise looks good
- 31. By Andrew Hayzen
-
* Fix for typo
Michael Sheldon (michael-sheldon) wrote : | # |
Looks good :)
Preview Diff
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2017-02-21 14:37:32 +0000 |
3 | +++ CMakeLists.txt 2017-02-21 14:37:32 +0000 |
4 | @@ -1,6 +1,11 @@ |
5 | project(qtubuntu-print) |
6 | cmake_minimum_required(VERSION 2.8.9) |
7 | |
8 | +# Set the global vars |
9 | +set(CMAKE_AUTOMOC ON) |
10 | +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra") |
11 | + |
12 | + |
13 | # Load translation tools |
14 | find_program(INTLTOOL_MERGE intltool-merge) |
15 | if(NOT INTLTOOL_MERGE) |
16 | @@ -12,68 +17,8 @@ |
17 | message(FATAL_ERROR "Could not find intltool-extract, please install the intltool package") |
18 | endif() |
19 | |
20 | -# Set the vars |
21 | -set(CMAKE_AUTOMOC ON) |
22 | -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra") |
23 | - |
24 | -# Find packages |
25 | -find_package(Qt5Core) |
26 | -find_package(Qt5DBus) |
27 | -find_package(Qt5PrintSupport) |
28 | -find_package(Qt5Widgets) |
29 | -find_package(PkgConfig REQUIRED) |
30 | -pkg_check_modules(CONTENTHUB REQUIRED libcontent-hub) |
31 | - |
32 | -# Replicate qmake CONFIG += plugin |
33 | -add_definitions(${QT_DEFINITIONS}) |
34 | -add_definitions(-DQT_PLUGIN) |
35 | -add_definitions(-DQT_NO_DEBUG) |
36 | -add_definitions(-DQT_SHARED) |
37 | - |
38 | -# Disable use of cups in Qt print support |
39 | -add_definitions(-DQT_NO_CUPS) |
40 | - |
41 | -# Setup include directories |
42 | -include(GNUInstallDirs) |
43 | - |
44 | -include_directories( |
45 | - ${CMAKE_CURRENT_SOURCE_DIR} |
46 | - ${CMAKE_CURRENT_BINARY_DIR} |
47 | - ${Qt5Core_INCLUDE_DIRS} |
48 | - ${Qt5Core_PRIVATE_INCLUDE_DIRS} |
49 | - ${Qt5DBus_INCLUDE_DIRS} |
50 | - ${Qt5PrintSupport_INCLUDE_DIRS} |
51 | - ${Qt5PrintSupport_PRIVATE_INCLUDE_DIRS} |
52 | - ${LIBCONTENT_HUB_INCLUDE_DIRS} |
53 | -) |
54 | - |
55 | -# Setup the library sources and name |
56 | -set(LIBNAME qtubuntu-print) |
57 | - |
58 | -set( |
59 | - qtubuntu_print_SRC |
60 | - constants.h |
61 | - i18n.cpp |
62 | - main.cpp |
63 | - qubuntuprintdevice.cpp |
64 | - qubuntuprintengine.cpp |
65 | - qubuntuprintsupport.cpp |
66 | -) |
67 | - |
68 | -add_library(${LIBNAME} SHARED ${qtubuntu_print_SRC}) |
69 | - |
70 | -qt5_use_modules(${LIBNAME} Core DBus PrintSupport Widgets) |
71 | -target_link_libraries(${LIBNAME} content-hub) |
72 | - |
73 | - |
74 | -# Install the plugin file |
75 | -execute_process( |
76 | - COMMAND qmake -qt=qt5 -query QT_INSTALL_PLUGINS |
77 | - OUTPUT_VARIABLE QT_INSTALL_PLUGINS_DIR |
78 | - OUTPUT_STRIP_TRAILING_WHITESPACE |
79 | - ) |
80 | -install(TARGETS ${LIBNAME} DESTINATION ${QT_INSTALL_PLUGINS_DIR}/printsupport) |
81 | - |
82 | +# Setup code |
83 | +add_subdirectory(src) |
84 | |
85 | # Setup gettext defs and include po directory |
86 | set(GETTEXT_PACKAGE "qtubuntu-print") |
87 | @@ -81,10 +26,7 @@ |
88 | |
89 | add_subdirectory(po) |
90 | |
91 | - |
92 | -# Show files in QtC |
93 | -file(GLOB QTC_FILES |
94 | - RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} |
95 | - *.cpp *.h *.json) |
96 | - |
97 | -add_custom_target(qtubuntu_print_qtc_files DEPENDS main.cpp SOURCES ${QTC_FILES}) |
98 | +# Setup tests |
99 | +enable_testing() |
100 | + |
101 | +add_subdirectory(tests) |
102 | |
103 | === modified file 'po/CMakeLists.txt' |
104 | --- po/CMakeLists.txt 2017-02-21 14:37:32 +0000 |
105 | +++ po/CMakeLists.txt 2017-02-21 14:37:32 +0000 |
106 | @@ -7,6 +7,10 @@ |
107 | set(POT_FILE ${DOMAIN}.pot) |
108 | file(GLOB PO_FILES *.po) |
109 | |
110 | +file(GLOB I18N_SRC_FILES |
111 | + RELATIVE ${CMAKE_SOURCE_DIR} |
112 | + ${SRC_SOURCE_DIR}/*.h ${SRC_SOURCE_DIR}/*.cpp) |
113 | + |
114 | add_custom_target(${POT_FILE} ALL |
115 | COMMAND touch ${POT_FILE} |
116 | COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE} -o ${POT_FILE} |
117 | @@ -17,7 +21,7 @@ |
118 | -j |
119 | --package-name=qtubuntu-print |
120 | --copyright-holder='Canonical Ltd.' |
121 | - ${qtubuntu_print_SRC} |
122 | + ${I18N_SRC_FILES} |
123 | COMMAND ${CMAKE_COMMAND} -E copy ${POT_FILE} ${CMAKE_CURRENT_SOURCE_DIR}) |
124 | |
125 | foreach(PO_FILE ${PO_FILES}) |
126 | @@ -28,3 +32,6 @@ |
127 | DESTINATION ${INSTALL_DIR} |
128 | RENAME ${DOMAIN}.mo) |
129 | endforeach(PO_FILE) |
130 | + |
131 | +# Show .pot in QtC |
132 | +add_custom_target(qtubuntu_print_qtc_pot_files SOURCES ${POT_FILE}) |
133 | |
134 | === modified file 'po/qtubuntu-print.pot' |
135 | --- po/qtubuntu-print.pot 2017-02-21 14:37:32 +0000 |
136 | +++ po/qtubuntu-print.pot 2017-02-21 14:37:32 +0000 |
137 | @@ -8,7 +8,7 @@ |
138 | msgstr "" |
139 | "Project-Id-Version: qtubuntu-print\n" |
140 | "Report-Msgid-Bugs-To: \n" |
141 | -"POT-Creation-Date: 2017-02-16 15:47+0000\n" |
142 | +"POT-Creation-Date: 2017-02-20 15:53+0000\n" |
143 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
144 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
145 | "Language-Team: LANGUAGE <LL@li.org>\n" |
146 | @@ -17,20 +17,20 @@ |
147 | "Content-Type: text/plain; charset=CHARSET\n" |
148 | "Content-Transfer-Encoding: 8bit\n" |
149 | |
150 | -#: constants.h:27 |
151 | +#: src/constants.h:30 |
152 | msgid "Ubuntu Printing Service" |
153 | msgstr "" |
154 | |
155 | -#: qubuntuprintdevice.cpp:39 |
156 | +#: src/qubuntuprintdevice.cpp:39 |
157 | msgid "Internal" |
158 | msgstr "" |
159 | |
160 | -#: qubuntuprintengine.cpp:114 |
161 | +#: src/qubuntuprintengine.cpp:114 |
162 | msgid "Printing failed" |
163 | msgstr "" |
164 | |
165 | #. TRANSLATORS: %0 is the name of the application (ubuntu-printing-app) |
166 | -#: qubuntuprintengine.cpp:116 |
167 | +#: src/qubuntuprintengine.cpp:116 |
168 | #, qt-format |
169 | msgid "Unable to find %0, please ensure that it is installed" |
170 | msgstr "" |
171 | |
172 | === added directory 'src' |
173 | === added file 'src/CMakeLists.txt' |
174 | --- src/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
175 | +++ src/CMakeLists.txt 2017-02-21 14:37:32 +0000 |
176 | @@ -0,0 +1,71 @@ |
177 | +# Find packages |
178 | +find_package(Qt5Core REQUIRED) |
179 | +find_package(Qt5DBus REQUIRED) |
180 | +find_package(Qt5PrintSupport REQUIRED) |
181 | +find_package(Qt5Widgets REQUIRED) |
182 | +find_package(PkgConfig REQUIRED) |
183 | +pkg_check_modules(CONTENTHUB REQUIRED libcontent-hub) |
184 | + |
185 | +# Replicate qmake CONFIG += plugin |
186 | +add_definitions(${QT_DEFINITIONS}) |
187 | +add_definitions(-DQT_PLUGIN) |
188 | +add_definitions(-DQT_NO_DEBUG) |
189 | +add_definitions(-DQT_SHARED) |
190 | + |
191 | +# Disable use of cups in Qt print support |
192 | +add_definitions(-DQT_NO_CUPS) |
193 | + |
194 | +# Setup include directories |
195 | +include(GNUInstallDirs) |
196 | + |
197 | +include_directories( |
198 | + ${CMAKE_CURRENT_SOURCE_DIR} |
199 | + ${CMAKE_CURRENT_BINARY_DIR} |
200 | + ${Qt5Core_INCLUDE_DIRS} |
201 | + ${Qt5Core_PRIVATE_INCLUDE_DIRS} |
202 | + ${Qt5DBus_INCLUDE_DIRS} |
203 | + ${Qt5PrintSupport_INCLUDE_DIRS} |
204 | + ${Qt5PrintSupport_PRIVATE_INCLUDE_DIRS} |
205 | + ${LIBCONTENT_HUB_INCLUDE_DIRS} |
206 | +) |
207 | + |
208 | +# Setup the library sources and name |
209 | +set(LIBNAME qtubuntu-print) |
210 | + |
211 | +set( |
212 | + qtubuntu_print_SRC |
213 | + constants.h |
214 | + i18n.cpp |
215 | + main.cpp |
216 | + qubuntuprintdevice.cpp |
217 | + qubuntuprintengine.cpp |
218 | + qubuntuprintsupport.cpp |
219 | +) |
220 | + |
221 | +add_library(${LIBNAME} SHARED ${qtubuntu_print_SRC}) |
222 | + |
223 | +qt5_use_modules(${LIBNAME} Core DBus PrintSupport Widgets) |
224 | +target_link_libraries(${LIBNAME} content-hub) |
225 | + |
226 | + |
227 | +# Install the plugin file |
228 | +execute_process( |
229 | + COMMAND qmake -qt=qt5 -query QT_INSTALL_PLUGINS |
230 | + OUTPUT_VARIABLE QT_INSTALL_PLUGINS_DIR |
231 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
232 | + ) |
233 | +install(TARGETS ${LIBNAME} DESTINATION ${QT_INSTALL_PLUGINS_DIR}/printsupport) |
234 | + |
235 | + |
236 | +# Show files in QtC |
237 | +file(GLOB QTC_FILES |
238 | + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} |
239 | + *.cpp *.h *.json) |
240 | + |
241 | +add_custom_target(qtubuntu_print_qtc_files DEPENDS main.cpp SOURCES ${QTC_FILES}) |
242 | + |
243 | + |
244 | +# Set variables for outside use |
245 | +set(SRC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) |
246 | +set(SRC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE) |
247 | +set(SRC_LIBNAME "lib${LIBNAME}" PARENT_SCOPE) |
248 | |
249 | === renamed file 'constants.h' => 'src/constants.h' |
250 | === renamed file 'i18n.cpp' => 'src/i18n.cpp' |
251 | === renamed file 'i18n.h' => 'src/i18n.h' |
252 | === renamed file 'main.cpp' => 'src/main.cpp' |
253 | === renamed file 'qtubuntu-print.json' => 'src/qtubuntu-print.json' |
254 | === renamed file 'qubuntuprintdevice.cpp' => 'src/qubuntuprintdevice.cpp' |
255 | === renamed file 'qubuntuprintdevice_p.h' => 'src/qubuntuprintdevice_p.h' |
256 | === renamed file 'qubuntuprintengine.cpp' => 'src/qubuntuprintengine.cpp' |
257 | === renamed file 'qubuntuprintengine_p.h' => 'src/qubuntuprintengine_p.h' |
258 | === renamed file 'qubuntuprintsupport.cpp' => 'src/qubuntuprintsupport.cpp' |
259 | === renamed file 'qubuntuprintsupport_p.h' => 'src/qubuntuprintsupport_p.h' |
260 | === added directory 'tests' |
261 | === added file 'tests/CMakeLists.txt' |
262 | --- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
263 | +++ tests/CMakeLists.txt 2017-02-21 14:37:32 +0000 |
264 | @@ -0,0 +1,2 @@ |
265 | +add_subdirectory(unittests) |
266 | + |
267 | |
268 | === added directory 'tests/unittests' |
269 | === added file 'tests/unittests/CMakeLists.txt' |
270 | --- tests/unittests/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
271 | +++ tests/unittests/CMakeLists.txt 2017-02-21 14:37:32 +0000 |
272 | @@ -0,0 +1,35 @@ |
273 | +include_directories( |
274 | + ${CMAKE_CURRENT_SOURCE_DIR} |
275 | + ${CMAKE_CURRENT_BINARY_DIR} |
276 | +) |
277 | + |
278 | +find_package(Qt5PrintSupport REQUIRED) |
279 | +find_package(Qt5Test REQUIRED) |
280 | + |
281 | +# Add the fakeprint plugin |
282 | +add_subdirectory(fakeprint) |
283 | + |
284 | +# Copy the library to a plugins folder |
285 | +add_custom_target(unittest_copyFiles ALL |
286 | + COMMENT "Copying files: ${SRC_LIBNAME}.so and ${FAKEPRINT_LIBNAME}.so into separate PLUGIN/printsupport/lib.so folders" |
287 | + DEPENDS qtubuntu-print fakeprint) |
288 | + |
289 | +add_custom_command( |
290 | + TARGET unittest_copyFiles |
291 | + COMMAND ${CMAKE_COMMAND} -E copy "${SRC_BINARY_DIR}/${SRC_LIBNAME}.so" "${CMAKE_CURRENT_BINARY_DIR}/qtubuntu-print/printsupport/${SRC_LIBNAME}.so" |
292 | + DEPENDS qtubuntu-print |
293 | + ) |
294 | +add_custom_command( |
295 | + TARGET unittest_copyFiles |
296 | + COMMAND ${CMAKE_COMMAND} -E copy "${FAKEPRINT_BINARY_DIR}/${FAKEPRINT_LIBNAME}.so" "${CMAKE_CURRENT_BINARY_DIR}/fakeprint/printsupport/${FAKEPRINT_LIBNAME}.so" |
297 | + DEPENDS fakeprint |
298 | + ) |
299 | + |
300 | +# Add the tests |
301 | +add_executable(testFakePrinterInfo tst_fakeprinterinfo.cpp) |
302 | +target_link_libraries(testFakePrinterInfo Qt5::Test Qt5::PrintSupport) |
303 | +add_test(tst_fakeprinterInfo testFakePrinterInfo) |
304 | + |
305 | +add_executable(testPrinterInfo tst_printerinfo.cpp) |
306 | +target_link_libraries(testPrinterInfo Qt5::Test Qt5::PrintSupport) |
307 | +add_test(tst_printerInfo testPrinterInfo) |
308 | |
309 | === added directory 'tests/unittests/fakeprint' |
310 | === added file 'tests/unittests/fakeprint/CMakeLists.txt' |
311 | --- tests/unittests/fakeprint/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
312 | +++ tests/unittests/fakeprint/CMakeLists.txt 2017-02-21 14:37:32 +0000 |
313 | @@ -0,0 +1,49 @@ |
314 | +# Find packages |
315 | +find_package(Qt5Core REQUIRED) |
316 | +find_package(Qt5PrintSupport REQUIRED) |
317 | +find_package(PkgConfig REQUIRED) |
318 | + |
319 | +# Replicate qmake CONFIG += plugin |
320 | +add_definitions(${QT_DEFINITIONS}) |
321 | +add_definitions(-DQT_PLUGIN) |
322 | +add_definitions(-DQT_NO_DEBUG) |
323 | +add_definitions(-DQT_SHARED) |
324 | + |
325 | +# Disable use of cups in Qt print support |
326 | +add_definitions(-DQT_NO_CUPS) |
327 | + |
328 | +# Setup include directories |
329 | +include(GNUInstallDirs) |
330 | + |
331 | +include_directories( |
332 | + ${CMAKE_CURRENT_SOURCE_DIR} |
333 | + ${CMAKE_CURRENT_BINARY_DIR} |
334 | + ${Qt5Core_INCLUDE_DIRS} |
335 | + ${Qt5Core_PRIVATE_INCLUDE_DIRS} |
336 | + ${Qt5PrintSupport_INCLUDE_DIRS} |
337 | + ${Qt5PrintSupport_PRIVATE_INCLUDE_DIRS} |
338 | + ${LIBCONTENT_HUB_INCLUDE_DIRS} |
339 | +) |
340 | + |
341 | +# Setup the library sources and name |
342 | +set(LIBNAME fakeprint) |
343 | +set( |
344 | + fakeprint_SRC |
345 | + main.cpp |
346 | +) |
347 | + |
348 | +add_library(${LIBNAME} SHARED ${fakeprint_SRC}) |
349 | +qt5_use_modules(${LIBNAME} Core PrintSupport) |
350 | + |
351 | +# Show files in QtC |
352 | +file(GLOB QTC_FILES |
353 | + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} |
354 | + *.cpp *.h *.json) |
355 | + |
356 | +add_custom_target(fake_print_qtc_files DEPENDS main.cpp SOURCES ${QTC_FILES}) |
357 | + |
358 | + |
359 | +# Set variables for outside use |
360 | +set(FAKEPRINT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE) |
361 | +set(FAKEPRINT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE) |
362 | +set(FAKEPRINT_LIBNAME "lib${LIBNAME}" PARENT_SCOPE) |
363 | |
364 | === added file 'tests/unittests/fakeprint/fakeprint.json' |
365 | --- tests/unittests/fakeprint/fakeprint.json 1970-01-01 00:00:00 +0000 |
366 | +++ tests/unittests/fakeprint/fakeprint.json 2017-02-21 14:37:32 +0000 |
367 | @@ -0,0 +1,3 @@ |
368 | +{ |
369 | + "Keys": [ "fakeprint" ] |
370 | +} |
371 | |
372 | === added file 'tests/unittests/fakeprint/main.cpp' |
373 | --- tests/unittests/fakeprint/main.cpp 1970-01-01 00:00:00 +0000 |
374 | +++ tests/unittests/fakeprint/main.cpp 2017-02-21 14:37:32 +0000 |
375 | @@ -0,0 +1,72 @@ |
376 | +/* |
377 | + * Copyright (C) 2016-2017 Canonical Ltd |
378 | + * |
379 | + * This file is part of qtubuntu-print. |
380 | + * |
381 | + * qtubuntu-print is free software; you can redistribute it and/or modify |
382 | + * it under the terms of the GNU Lesser General Public License as published by |
383 | + * the Free Software Foundation; version 3. |
384 | + * |
385 | + * qtubuntu-print is distributed in the hope that it will be useful, |
386 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
387 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
388 | + * GNU Lesser General Public License for more details. |
389 | + * |
390 | + * You should have received a copy of the GNU Lesser General Public License |
391 | + * along with qtubuntu-print. If not, see <http://www.gnu.org/licenses/>. |
392 | + * |
393 | + * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> |
394 | + */ |
395 | +#include <QtPrintSupport/qpa/qplatformprintersupport.h> |
396 | +#include <QtPrintSupport/qpa/qplatformprintplugin.h> |
397 | +#include <QtCore/QStringList> |
398 | + |
399 | +#define JSON_KEY "fakeprint" |
400 | +#define PRINTER_NAME "fakeprinter" |
401 | + |
402 | +QT_BEGIN_NAMESPACE |
403 | + |
404 | + |
405 | +class QFakePrintSupport : public QPlatformPrinterSupport |
406 | +{ |
407 | +public: |
408 | + QStringList availablePrintDeviceIds() const Q_DECL_OVERRIDE; |
409 | + QString defaultPrintDeviceId() const Q_DECL_OVERRIDE; |
410 | +}; |
411 | + |
412 | +QStringList QFakePrintSupport::availablePrintDeviceIds() const |
413 | +{ |
414 | + return QStringList(PRINTER_NAME); |
415 | +} |
416 | + |
417 | +QString QFakePrintSupport::defaultPrintDeviceId() const |
418 | +{ |
419 | + return PRINTER_NAME; |
420 | +} |
421 | + |
422 | + |
423 | +class QFakePrintSupportPlugin : public QPlatformPrinterSupportPlugin |
424 | +{ |
425 | + Q_OBJECT |
426 | + Q_PLUGIN_METADATA(IID QPlatformPrinterSupportFactoryInterface_iid FILE "fakeprint.json") |
427 | + |
428 | +public: |
429 | + QStringList keys() const; |
430 | + QPlatformPrinterSupport *create(const QString &) Q_DECL_OVERRIDE; |
431 | +}; |
432 | + |
433 | +QStringList QFakePrintSupportPlugin::keys() const |
434 | +{ |
435 | + return QStringList(QStringLiteral(JSON_KEY)); |
436 | +} |
437 | + |
438 | +QPlatformPrinterSupport *QFakePrintSupportPlugin::create(const QString &key) |
439 | +{ |
440 | + if (key.compare(key, QLatin1String(JSON_KEY), Qt::CaseInsensitive) == 0) |
441 | + return new QFakePrintSupport; |
442 | + return 0; |
443 | +} |
444 | + |
445 | +QT_END_NAMESPACE |
446 | + |
447 | +#include "main.moc" |
448 | |
449 | === added file 'tests/unittests/tst_fakeprinterinfo.cpp' |
450 | --- tests/unittests/tst_fakeprinterinfo.cpp 1970-01-01 00:00:00 +0000 |
451 | +++ tests/unittests/tst_fakeprinterinfo.cpp 2017-02-21 14:37:32 +0000 |
452 | @@ -0,0 +1,53 @@ |
453 | +/* |
454 | + * Copyright (C) 2017 Canonical Ltd |
455 | + * |
456 | + * This file is part of qtubuntu-print. |
457 | + * |
458 | + * qtubuntu-print is free software; you can redistribute it and/or modify |
459 | + * it under the terms of the GNU Lesser General Public License as published by |
460 | + * the Free Software Foundation; version 3. |
461 | + * |
462 | + * qtubuntu-print is distributed in the hope that it will be useful, |
463 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
464 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
465 | + * GNU Lesser General Public License for more details. |
466 | + * |
467 | + * You should have received a copy of the GNU Lesser General Public License |
468 | + * along with qtubuntu-print. If not, see <http://www.gnu.org/licenses/>. |
469 | + * |
470 | + * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> |
471 | + */ |
472 | +#include <QtCore/QDebug> |
473 | +#include <QtCore/QObject> |
474 | +#include <QtCore/QString> |
475 | +#include <QtCore/QStringList> |
476 | +#include <QtPrintSupport/QPrinterInfo> |
477 | +#include <QtTest/QSignalSpy> |
478 | +#include <QtTest/QTest> |
479 | + |
480 | +#define PRINTER_NAME QStringLiteral("fakeprinter") |
481 | + |
482 | +// This test ensures that we are able to load a plugin not from the system |
483 | +// Qt uses the first found plugin which will be the libfakeprint.so which has |
484 | +// been copied into fakeprinter/printsupport/libfakeprint.so (relative to this) |
485 | +class TestFakePrinterInfo : public QObject |
486 | +{ |
487 | + Q_OBJECT |
488 | +private Q_SLOTS: |
489 | + void initTestCase() |
490 | + { |
491 | + QCoreApplication::addLibraryPath("fakeprint"); |
492 | + } |
493 | + |
494 | + void testAvailablePrinterNames() |
495 | + { |
496 | + QCOMPARE(QPrinterInfo::availablePrinterNames(), QStringList() << PRINTER_NAME); |
497 | + } |
498 | + void testDefaultPrinterName() |
499 | + { |
500 | + QCOMPARE(QPrinterInfo::defaultPrinterName(), PRINTER_NAME); |
501 | + } |
502 | +}; |
503 | + |
504 | +QTEST_GUILESS_MAIN(TestFakePrinterInfo) |
505 | +#include "tst_fakeprinterinfo.moc" |
506 | |
507 | === added file 'tests/unittests/tst_printerinfo.cpp' |
508 | --- tests/unittests/tst_printerinfo.cpp 1970-01-01 00:00:00 +0000 |
509 | +++ tests/unittests/tst_printerinfo.cpp 2017-02-21 14:37:32 +0000 |
510 | @@ -0,0 +1,64 @@ |
511 | +/* |
512 | + * Copyright (C) 2017 Canonical Ltd |
513 | + * |
514 | + * This file is part of qtubuntu-print. |
515 | + * |
516 | + * qtubuntu-print is free software; you can redistribute it and/or modify |
517 | + * it under the terms of the GNU Lesser General Public License as published by |
518 | + * the Free Software Foundation; version 3. |
519 | + * |
520 | + * qtubuntu-print is distributed in the hope that it will be useful, |
521 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
522 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
523 | + * GNU Lesser General Public License for more details. |
524 | + * |
525 | + * You should have received a copy of the GNU Lesser General Public License |
526 | + * along with qtubuntu-print. If not, see <http://www.gnu.org/licenses/>. |
527 | + * |
528 | + * Authored-by: Andrew Hayzen <andrew.hayzen@canonical.com> |
529 | + */ |
530 | +#include <QtCore/QDebug> |
531 | +#include <QtCore/QObject> |
532 | +#include <QtCore/QString> |
533 | +#include <QtCore/QStringList> |
534 | +#include <QtPrintSupport/QPrinterInfo> |
535 | +#include <QtTest/QSignalSpy> |
536 | +#include <QtTest/QTest> |
537 | + |
538 | +#define PRINTER_NAME QStringLiteral("Ubuntu Printing Service") |
539 | +#define PRINTER_LOCATION QStringLiteral("Internal") |
540 | + |
541 | +// This test ensures that we are able to load a plugin qtubuntu-print and it |
542 | +// acts as expected |
543 | +// Qt uses the first found plugin which will be the libqtubuntu-print.so which |
544 | +// has been copied into qtubuntu-print/printsupport/libqtubuntu-print.so |
545 | +// (relative to this) |
546 | +class TestPrinterInfo : public QObject |
547 | +{ |
548 | + Q_OBJECT |
549 | +private Q_SLOTS: |
550 | + void initTestCase() |
551 | + { |
552 | + QCoreApplication::addLibraryPath("qtubuntu-print"); |
553 | + } |
554 | + |
555 | + void testAvailablePrinterNames() |
556 | + { |
557 | + QCOMPARE(QPrinterInfo::availablePrinterNames(), QStringList() << PRINTER_NAME); |
558 | + } |
559 | + void testDefaultPrinterName() |
560 | + { |
561 | + QCOMPARE(QPrinterInfo::defaultPrinterName(), PRINTER_NAME); |
562 | + } |
563 | + void testMakeModel() |
564 | + { |
565 | + QCOMPARE(QPrinterInfo::printerInfo(PRINTER_NAME).makeAndModel(), PRINTER_NAME); |
566 | + } |
567 | + void testLocation() |
568 | + { |
569 | + QCOMPARE(QPrinterInfo::printerInfo(PRINTER_NAME).location(), PRINTER_LOCATION); |
570 | + } |
571 | +}; |
572 | + |
573 | +QTEST_GUILESS_MAIN(TestPrinterInfo) |
574 | +#include "tst_printerinfo.moc" |
The deb generated in the silo is ending up with libqtubuntu- print.so in /printsupport rather than /usr/lib/ */qt5/plugins/ printsupport. Seems the qmake reading is broken.