Merge lp:~aacid/ubuntu-ui-toolkit/save_stat_loading_already_loaded_image into lp:ubuntu-ui-toolkit/staging
- save_stat_loading_already_loaded_image
- Merge into staging
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Cris Dywan | ||||
Approved revision: | 2177 | ||||
Merged at revision: | 2169 | ||||
Proposed branch: | lp:~aacid/ubuntu-ui-toolkit/save_stat_loading_already_loaded_image | ||||
Merge into: | lp:ubuntu-ui-toolkit/staging | ||||
Diff against target: |
268 lines (+120/-20) 9 files modified
src/UbuntuToolkit/ucqquickimageextension.cpp (+53/-2) src/UbuntuToolkit/ucqquickimageextension_p.h (+1/-0) tests/unit/qquick_image_extension/borderInName.sci (+0/-7) tests/unit/qquick_image_extension/data/borderInName.sci (+7/-0) tests/unit/qquick_image_extension/data/hundred_faces.qml (+13/-0) tests/unit/qquick_image_extension/data/test@18.sci (+7/-0) tests/unit/qquick_image_extension/qquick_image_extension.pro (+1/-1) tests/unit/qquick_image_extension/test@18.sci (+0/-7) tests/unit/qquick_image_extension/tst_qquick_image_extension.cpp (+38/-3) |
||||
To merge this branch: | bzr merge lp:~aacid/ubuntu-ui-toolkit/save_stat_loading_already_loaded_image | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
ubuntu-sdk-build-bot | continuous-integration | Approve | |
Cris Dywan | Approve | ||
Zsombor Egri | Needs Fixing | ||
Review via email: mp+316235@code.launchpad.net |
Commit message
Save a stat if the image we're loading is already in the cache
No need to call UCUnits:
Description of the change
Adding some description, i think CI may be failing because i don't have one.
Zsombor Egri (zsombi) wrote : | # |
I have one small request to it, otherwise good.
- 2170. By Albert Astals Cid
-
Use a registered type
- 2171. By Albert Astals Cid
-
comment++
- 2172. By Albert Astals Cid
-
Add a test that proves this is working
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2172
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2172
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2172
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2172
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2172
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2172
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2172
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2172
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2172
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2172
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
- 2173. By Albert Astals Cid
-
Need core private here
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2173
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2173
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2173
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2173
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2173
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
- 2174. By Albert Astals Cid
-
Fix gles build
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2174
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2174
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2174
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2174
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2174
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
- 2175. By Albert Astals Cid
-
"Better" way of waiting for the image to have the source size set
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2175
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2175
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2175
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2175
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2175
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
- 2176. By Albert Astals Cid
-
workaround qqmlengine_p.h using foreach
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2176
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2176
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2176
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:2176
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:2176
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
- 2177. By Albert Astals Cid
-
Unfortunately can't cache the ixd, causes crashes in some tests
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:2177
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:2177
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:2177
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:2177
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:2177
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
Cris Dywan (kalikiana) wrote : | # |
Finally seems to be passing CI. And thanks for adding the test case (especially since the implementation is not straight-forward now)!
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:2177
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:2177
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:2177
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:2177
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | === modified file 'src/UbuntuToolkit/ucqquickimageextension.cpp' | |||
2 | --- src/UbuntuToolkit/ucqquickimageextension.cpp 2016-09-12 09:03:50 +0000 | |||
3 | +++ src/UbuntuToolkit/ucqquickimageextension.cpp 2017-02-06 13:21:12 +0000 | |||
4 | @@ -22,7 +22,13 @@ | |||
5 | 22 | #include <QtCore/QFile> | 22 | #include <QtCore/QFile> |
6 | 23 | #include <QtCore/QFileInfo> | 23 | #include <QtCore/QFileInfo> |
7 | 24 | #include <QtGui/QGuiApplication> | 24 | #include <QtGui/QGuiApplication> |
8 | 25 | #include <QtQuick/private/qquickitem_p.h> | ||
9 | 25 | #include <QtQuick/private/qquickimagebase_p.h> | 26 | #include <QtQuick/private/qquickimagebase_p.h> |
10 | 27 | #include <QtQuick/private/qquickpixmapcache_p.h> | ||
11 | 28 | |||
12 | 29 | #define foreach Q_FOREACH | ||
13 | 30 | #include <QtQml/private/qqmlengine_p.h> | ||
14 | 31 | #undef foreach | ||
15 | 26 | 32 | ||
16 | 27 | #include "ucunits_p.h" | 33 | #include "ucunits_p.h" |
17 | 28 | 34 | ||
18 | @@ -61,11 +67,35 @@ | |||
19 | 61 | return m_source; | 67 | return m_source; |
20 | 62 | } | 68 | } |
21 | 63 | 69 | ||
22 | 70 | |||
23 | 64 | void UCQQuickImageExtension::setSource(const QUrl& url) | 71 | void UCQQuickImageExtension::setSource(const QUrl& url) |
24 | 65 | { | 72 | { |
25 | 66 | if (url != m_source) { | 73 | if (url != m_source) { |
26 | 67 | m_source = url; | 74 | m_source = url; |
28 | 68 | reloadSource(); | 75 | // We need to wait until the component is complete |
29 | 76 | // so that m_image->sourceSize() is actually valid | ||
30 | 77 | if (QQuickItemPrivate::get(m_image)->componentComplete) { | ||
31 | 78 | reloadSource(); | ||
32 | 79 | } else { | ||
33 | 80 | // This is a bit convoluted but i couldn't find a better way to get notified of when | ||
34 | 81 | // the image actually finishes constructing. | ||
35 | 82 | // Since what we're interested in reloadSource() is the image having the sourceSize set, | ||
36 | 83 | // what we do is connect to the sourceSizeChanged signal. | ||
37 | 84 | // The problem is that this signal isn't fired if the Image {} doesn't have sourceSize set | ||
38 | 85 | // so we tell the engine to fire the sourceSizeChanged signal when the image finishes constructing | ||
39 | 86 | // This way if the Image {} has a sourceSize set the lambda gets called because of it | ||
40 | 87 | // and if there's no sourceSize set the lambda gets called because we registered the finalize callback | ||
41 | 88 | |||
42 | 89 | connect(m_image, &QQuickImageBase::sourceSizeChanged, | ||
43 | 90 | this, | ||
44 | 91 | [&] { | ||
45 | 92 | QObject::disconnect(m_image, &QQuickImageBase::sourceSizeChanged, this, nullptr); | ||
46 | 93 | reloadSource(); | ||
47 | 94 | }); | ||
48 | 95 | |||
49 | 96 | QQmlEnginePrivate *engPriv = QQmlEnginePrivate::get(qmlEngine(m_image)); | ||
50 | 97 | engPriv->registerFinalizeCallback(m_image, m_image->metaObject()->indexOfSignal("sourceSizeChanged()")); | ||
51 | 98 | } | ||
52 | 69 | } | 99 | } |
53 | 70 | } | 100 | } |
54 | 71 | 101 | ||
55 | @@ -80,6 +110,25 @@ | |||
56 | 80 | return; | 110 | return; |
57 | 81 | } | 111 | } |
58 | 82 | 112 | ||
59 | 113 | // If the url we're trying to load is already in the cache and | ||
60 | 114 | // the devicePixelRatio is 1, we save calling UCUnits::resolveResource | ||
61 | 115 | // and just set that image directly. | ||
62 | 116 | // UCUnits::resolveResource is not cheap (does a stat on disk) | ||
63 | 117 | if (qFuzzyCompare(qGuiApp->devicePixelRatio(), (qreal)1.0)) { | ||
64 | 118 | QSize ss = m_image->sourceSize(); | ||
65 | 119 | if (ss.isNull() && m_image->image().isNull()) { | ||
66 | 120 | // For some reason QQuickImage returns 0x0 as sourceSize | ||
67 | 121 | // when the sourceSize is not set (and the image has not yet been loaded) | ||
68 | 122 | // so set it back to -1x-1 | ||
69 | 123 | ss = QSize(-1, -1); | ||
70 | 124 | } | ||
71 | 125 | |||
72 | 126 | if (QQuickPixmap::isCached(m_source, ss)) { | ||
73 | 127 | m_image->setSource(m_source); | ||
74 | 128 | return; | ||
75 | 129 | } | ||
76 | 130 | } | ||
77 | 131 | |||
78 | 83 | QString resolved = UCUnits::instance()->resolveResource(m_source); | 132 | QString resolved = UCUnits::instance()->resolveResource(m_source); |
79 | 84 | 133 | ||
80 | 85 | if (resolved.isEmpty()) { | 134 | if (resolved.isEmpty()) { |
81 | @@ -98,7 +147,9 @@ | |||
82 | 98 | || selectedFilePath.endsWith(QStringLiteral(".svgz"))) { | 147 | || selectedFilePath.endsWith(QStringLiteral(".svgz"))) { |
83 | 99 | // Take care to pass the original fragment | 148 | // Take care to pass the original fragment |
84 | 100 | QUrl selectedFileUrl(QUrl::fromLocalFile(selectedFilePath)); | 149 | QUrl selectedFileUrl(QUrl::fromLocalFile(selectedFilePath)); |
86 | 101 | selectedFileUrl.setFragment(fragment); | 150 | if (m_source.hasFragment()) { |
87 | 151 | selectedFileUrl.setFragment(fragment); | ||
88 | 152 | } | ||
89 | 102 | m_image->setSource(selectedFileUrl); | 153 | m_image->setSource(selectedFileUrl); |
90 | 103 | } else { | 154 | } else { |
91 | 104 | // Need to scale the pixel-based image to suit the devicePixelRatio setting ourselves. | 155 | // Need to scale the pixel-based image to suit the devicePixelRatio setting ourselves. |
92 | 105 | 156 | ||
93 | === modified file 'src/UbuntuToolkit/ucqquickimageextension_p.h' | |||
94 | --- src/UbuntuToolkit/ucqquickimageextension_p.h 2016-09-09 17:49:07 +0000 | |||
95 | +++ src/UbuntuToolkit/ucqquickimageextension_p.h 2017-02-06 13:21:12 +0000 | |||
96 | @@ -19,6 +19,7 @@ | |||
97 | 19 | #ifndef UCQQUICKIMAGEEXTENSION_P_H | 19 | #ifndef UCQQUICKIMAGEEXTENSION_P_H |
98 | 20 | #define UCQQUICKIMAGEEXTENSION_P_H | 20 | #define UCQQUICKIMAGEEXTENSION_P_H |
99 | 21 | 21 | ||
100 | 22 | #include <QtCore/QEvent> | ||
101 | 22 | #include <QtCore/QByteArray> | 23 | #include <QtCore/QByteArray> |
102 | 23 | #include <QtCore/QObject> | 24 | #include <QtCore/QObject> |
103 | 24 | #include <QtCore/QSharedPointer> | 25 | #include <QtCore/QSharedPointer> |
104 | 25 | 26 | ||
105 | === removed file 'tests/unit/qquick_image_extension/borderInName.sci' | |||
106 | --- tests/unit/qquick_image_extension/borderInName.sci 2013-05-06 16:33:54 +0000 | |||
107 | +++ tests/unit/qquick_image_extension/borderInName.sci 1970-01-01 00:00:00 +0000 | |||
108 | @@ -1,7 +0,0 @@ | |||
109 | 1 | source: "borderInName.png" | ||
110 | 2 | border.left: 9 | ||
111 | 3 | border.right: 2 | ||
112 | 4 | border.top: 9 | ||
113 | 5 | border.bottom: 0 | ||
114 | 6 | horizontalTileMode: Stretch | ||
115 | 7 | verticalTileMode: Stretch | ||
116 | 8 | 0 | ||
117 | === added directory 'tests/unit/qquick_image_extension/data' | |||
118 | === added file 'tests/unit/qquick_image_extension/data/borderInName.sci' | |||
119 | --- tests/unit/qquick_image_extension/data/borderInName.sci 1970-01-01 00:00:00 +0000 | |||
120 | +++ tests/unit/qquick_image_extension/data/borderInName.sci 2017-02-06 13:21:12 +0000 | |||
121 | @@ -0,0 +1,7 @@ | |||
122 | 1 | source: "borderInName.png" | ||
123 | 2 | border.left: 9 | ||
124 | 3 | border.right: 2 | ||
125 | 4 | border.top: 9 | ||
126 | 5 | border.bottom: 0 | ||
127 | 6 | horizontalTileMode: Stretch | ||
128 | 7 | verticalTileMode: Stretch | ||
129 | 0 | 8 | ||
130 | === added file 'tests/unit/qquick_image_extension/data/face.png' | |||
131 | 1 | Binary files tests/unit/qquick_image_extension/data/face.png 1970-01-01 00:00:00 +0000 and tests/unit/qquick_image_extension/data/face.png 2017-02-06 13:21:12 +0000 differ | 9 | Binary files tests/unit/qquick_image_extension/data/face.png 1970-01-01 00:00:00 +0000 and tests/unit/qquick_image_extension/data/face.png 2017-02-06 13:21:12 +0000 differ |
132 | === added file 'tests/unit/qquick_image_extension/data/hundred_faces.qml' | |||
133 | --- tests/unit/qquick_image_extension/data/hundred_faces.qml 1970-01-01 00:00:00 +0000 | |||
134 | +++ tests/unit/qquick_image_extension/data/hundred_faces.qml 2017-02-06 13:21:12 +0000 | |||
135 | @@ -0,0 +1,13 @@ | |||
136 | 1 | |||
137 | 2 | import QtQuick 2.4 | ||
138 | 3 | import Ubuntu.Components 1.3 | ||
139 | 4 | |||
140 | 5 | Repeater { | ||
141 | 6 | width: 400 | ||
142 | 7 | height: 600 | ||
143 | 8 | |||
144 | 9 | model: 100 | ||
145 | 10 | delegate: Image { | ||
146 | 11 | source: "face.png" | ||
147 | 12 | } | ||
148 | 13 | } | ||
149 | 0 | 14 | ||
150 | === added file 'tests/unit/qquick_image_extension/data/test@18.sci' | |||
151 | --- tests/unit/qquick_image_extension/data/test@18.sci 1970-01-01 00:00:00 +0000 | |||
152 | +++ tests/unit/qquick_image_extension/data/test@18.sci 2017-02-06 13:21:12 +0000 | |||
153 | @@ -0,0 +1,7 @@ | |||
154 | 1 | source: "test@18.png" | ||
155 | 2 | border.left: 9 | ||
156 | 3 | border.right: 2 | ||
157 | 4 | border.top: 9 | ||
158 | 5 | border.bottom: 0 | ||
159 | 6 | horizontalTileMode: Stretch | ||
160 | 7 | verticalTileMode: Stretch | ||
161 | 0 | 8 | ||
162 | === modified file 'tests/unit/qquick_image_extension/qquick_image_extension.pro' | |||
163 | --- tests/unit/qquick_image_extension/qquick_image_extension.pro 2016-05-31 09:02:35 +0000 | |||
164 | +++ tests/unit/qquick_image_extension/qquick_image_extension.pro 2017-02-06 13:21:12 +0000 | |||
165 | @@ -1,3 +1,3 @@ | |||
166 | 1 | include(../test-include.pri) | 1 | include(../test-include.pri) |
167 | 2 | SOURCES += tst_qquick_image_extension.cpp | 2 | SOURCES += tst_qquick_image_extension.cpp |
169 | 3 | QT += quick-private | 3 | QT += core-private quick-private |
170 | 4 | 4 | ||
171 | === removed file 'tests/unit/qquick_image_extension/test@18.sci' | |||
172 | --- tests/unit/qquick_image_extension/test@18.sci 2013-05-06 16:33:54 +0000 | |||
173 | +++ tests/unit/qquick_image_extension/test@18.sci 1970-01-01 00:00:00 +0000 | |||
174 | @@ -1,7 +0,0 @@ | |||
175 | 1 | source: "test@18.png" | ||
176 | 2 | border.left: 9 | ||
177 | 3 | border.right: 2 | ||
178 | 4 | border.top: 9 | ||
179 | 5 | border.bottom: 0 | ||
180 | 6 | horizontalTileMode: Stretch | ||
181 | 7 | verticalTileMode: Stretch | ||
182 | 8 | 0 | ||
183 | === modified file 'tests/unit/qquick_image_extension/tst_qquick_image_extension.cpp' | |||
184 | --- tests/unit/qquick_image_extension/tst_qquick_image_extension.cpp 2016-09-09 17:49:07 +0000 | |||
185 | +++ tests/unit/qquick_image_extension/tst_qquick_image_extension.cpp 2017-02-06 13:21:12 +0000 | |||
186 | @@ -23,6 +23,8 @@ | |||
187 | 23 | #define protected public | 23 | #define protected public |
188 | 24 | #include <UbuntuToolkit/private/ucqquickimageextension_p.h> | 24 | #include <UbuntuToolkit/private/ucqquickimageextension_p.h> |
189 | 25 | #undef protected | 25 | #undef protected |
190 | 26 | #include <QtCore/private/qabstractfileengine_p.h> | ||
191 | 27 | #include <QQuickView> | ||
192 | 26 | 28 | ||
193 | 27 | UT_USE_NAMESPACE | 29 | UT_USE_NAMESPACE |
194 | 28 | 30 | ||
195 | @@ -32,6 +34,20 @@ | |||
196 | 32 | return QDir::temp().entryList(nameFilters, QDir::Files).count(); | 34 | return QDir::temp().entryList(nameFilters, QDir::Files).count(); |
197 | 33 | } | 35 | } |
198 | 34 | 36 | ||
199 | 37 | int nFaces = 0; | ||
200 | 38 | |||
201 | 39 | class DummyFileEngineHandler : public QAbstractFileEngineHandler | ||
202 | 40 | { | ||
203 | 41 | public: | ||
204 | 42 | QAbstractFileEngine *create(const QString &fileName) const | ||
205 | 43 | { | ||
206 | 44 | if (fileName.endsWith("/face.png")) | ||
207 | 45 | nFaces++; | ||
208 | 46 | |||
209 | 47 | return nullptr; | ||
210 | 48 | } | ||
211 | 49 | }; | ||
212 | 50 | |||
213 | 35 | class tst_UCQQuickImageExtension : public QObject | 51 | class tst_UCQQuickImageExtension : public QObject |
214 | 36 | { | 52 | { |
215 | 37 | Q_OBJECT | 53 | Q_OBJECT |
216 | @@ -78,7 +94,7 @@ | |||
217 | 78 | 94 | ||
218 | 79 | void rewriteContainsBorderInName() { | 95 | void rewriteContainsBorderInName() { |
219 | 80 | UCQQuickImageExtension image; | 96 | UCQQuickImageExtension image; |
221 | 81 | QString sciFilePath = "borderInName.sci"; | 97 | QString sciFilePath = "data/borderInName.sci"; |
222 | 82 | QString result; | 98 | QString result; |
223 | 83 | 99 | ||
224 | 84 | QTextStream resultStream(&result); | 100 | QTextStream resultStream(&result); |
225 | @@ -86,7 +102,7 @@ | |||
226 | 86 | 102 | ||
227 | 87 | QString expected; | 103 | QString expected; |
228 | 88 | QTextStream expectedStream(&expected); | 104 | QTextStream expectedStream(&expected); |
230 | 89 | expectedStream << "source: \"image://scaling/1/./borderInName.png\"" << endl; | 105 | expectedStream << "source: \"image://scaling/1/data/borderInName.png\"" << endl; |
231 | 90 | expectedStream << "border.left: 9" << endl; | 106 | expectedStream << "border.left: 9" << endl; |
232 | 91 | expectedStream << "border.right: 2" << endl; | 107 | expectedStream << "border.right: 2" << endl; |
233 | 92 | expectedStream << "border.top: 9" << endl; | 108 | expectedStream << "border.top: 9" << endl; |
234 | @@ -105,7 +121,7 @@ | |||
235 | 105 | QQuickImageBase baseImage; | 121 | QQuickImageBase baseImage; |
236 | 106 | UCQQuickImageExtension* image1 = new UCQQuickImageExtension(&baseImage); | 122 | UCQQuickImageExtension* image1 = new UCQQuickImageExtension(&baseImage); |
237 | 107 | UCQQuickImageExtension* image2 = new UCQQuickImageExtension(&baseImage); | 123 | UCQQuickImageExtension* image2 = new UCQQuickImageExtension(&baseImage); |
239 | 108 | QUrl sciFileUrl = QUrl::fromLocalFile("./test.sci"); | 124 | QUrl sciFileUrl = QUrl::fromLocalFile("./data/test.sci"); |
240 | 109 | 125 | ||
241 | 110 | unsigned int initialNumberOfSciFiles = numberOfTemporarySciFiles(); | 126 | unsigned int initialNumberOfSciFiles = numberOfTemporarySciFiles(); |
242 | 111 | 127 | ||
243 | @@ -124,6 +140,25 @@ | |||
244 | 124 | delete image2; | 140 | delete image2; |
245 | 125 | QCOMPARE(numberOfTemporarySciFiles(), initialNumberOfSciFiles + 1); | 141 | QCOMPARE(numberOfTemporarySciFiles(), initialNumberOfSciFiles + 1); |
246 | 126 | } | 142 | } |
247 | 143 | |||
248 | 144 | void onlyOneStatRepeatedImage() { | ||
249 | 145 | DummyFileEngineHandler handler; | ||
250 | 146 | |||
251 | 147 | QQuickView view(QUrl::fromLocalFile("./data/hundred_faces.qml")); | ||
252 | 148 | |||
253 | 149 | // Wait until the app is idle | ||
254 | 150 | bool idle = false; | ||
255 | 151 | while (!idle) { | ||
256 | 152 | QEventLoop l; | ||
257 | 153 | idle = !l.processEvents(); | ||
258 | 154 | } | ||
259 | 155 | // We have actually loaded the image | ||
260 | 156 | QVERIFY(nFaces > 0); | ||
261 | 157 | // The number at the moment of writing this test is 4, but we | ||
262 | 158 | // can't know what Qt does internally, so i'm going for a relatively safe <10 | ||
263 | 159 | // the important part is that is not 100 times (i.e. one for every Image item) | ||
264 | 160 | QVERIFY(nFaces < 10); | ||
265 | 161 | } | ||
266 | 127 | }; | 162 | }; |
267 | 128 | 163 | ||
268 | 129 | QTEST_MAIN(tst_UCQQuickImageExtension) | 164 | QTEST_MAIN(tst_UCQQuickImageExtension) |
That looks quite nice. Any chance we can unit test it? At least to see that no scaling is applied when unneeded.