Merge lp:~kalikiana/u1db-qt/indexRoles into lp:u1db-qt
- indexRoles
- Merge into trunk
Status: | Needs review | ||||
---|---|---|---|---|---|
Proposed branch: | lp:~kalikiana/u1db-qt/indexRoles | ||||
Merge into: | lp:u1db-qt | ||||
Diff against target: |
485 lines (+349/-8) 6 files modified
debian/control (+2/-0) examples/bookmarks/bookmarks.qml (+6/-3) examples/movies/movies.qml (+196/-0) src/query.cpp (+12/-2) tests/test-database.cpp (+15/-0) tests/tst_query.qml (+118/-3) |
||||
To merge this branch: | bzr merge lp:~kalikiana/u1db-qt/indexRoles | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Benjamin Zeller | Pending | ||
Review via email: mp+211771@code.launchpad.net |
Commit message
Expose index fields as role names
Description of the change
This is aimed to work with lp:~kalikiana/ubuntu-ui-toolkit/sortFilterModel.
TODO: Before merging we should have a unit test for it.
PS Jenkins bot (ps-jenkins) wrote : | # |
Andrew Hayzen (ahayzen) wrote : | # |
FYI the branch which I was having issues sorting can be found here [0].
0 - https:/
- 118. By Cris Dywan
-
Add sort and filter unit test cases and movies example
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:118
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 119. By Cris Dywan
-
Build and examples should depend on UI toolkit plugin
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:119
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 120. By Cris Dywan
-
Merge lp:u1db-qt
- 121. By Cris Dywan
-
Add C++ unit test checking role names of Query
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:121
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 122. By Cris Dywan
-
Work-around for sort.property not correctly re-sorting
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:122
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Unmerged revisions
- 122. By Cris Dywan
-
Work-around for sort.property not correctly re-sorting
- 121. By Cris Dywan
-
Add C++ unit test checking role names of Query
- 120. By Cris Dywan
-
Merge lp:u1db-qt
- 119. By Cris Dywan
-
Build and examples should depend on UI toolkit plugin
- 118. By Cris Dywan
-
Add sort and filter unit test cases and movies example
- 117. By Cris Dywan
-
Expose index fields as role names
Preview Diff
1 | === modified file 'debian/control' | |||
2 | --- debian/control 2014-01-22 13:14:22 +0000 | |||
3 | +++ debian/control 2014-11-12 17:08:18 +0000 | |||
4 | @@ -14,6 +14,7 @@ | |||
5 | 14 | qtdeclarative5-qtquick2-plugin, | 14 | qtdeclarative5-qtquick2-plugin, |
6 | 15 | qtdeclarative5-test-plugin, | 15 | qtdeclarative5-test-plugin, |
7 | 16 | qttools5-dev-tools, | 16 | qttools5-dev-tools, |
8 | 17 | qtdeclarative5-ubuntu-ui-toolkit-plugin, | ||
9 | 17 | ubuntu-ui-toolkit-doc, | 18 | ubuntu-ui-toolkit-doc, |
10 | 18 | xvfb, | 19 | xvfb, |
11 | 19 | libgl1-mesa-dri, | 20 | libgl1-mesa-dri, |
12 | @@ -65,6 +66,7 @@ | |||
13 | 65 | Section: doc | 66 | Section: doc |
14 | 66 | Architecture: all | 67 | Architecture: all |
15 | 67 | Depends: libu1db-qt5-3 (>= ${source:Version}), | 68 | Depends: libu1db-qt5-3 (>= ${source:Version}), |
16 | 69 | qtdeclarative5-ubuntu-ui-toolkit-plugin, | ||
17 | 68 | ${misc:Depends}, | 70 | ${misc:Depends}, |
18 | 69 | Description: Qt5 binding and QtQuick2 plugin for U1DB - examples | 71 | Description: Qt5 binding and QtQuick2 plugin for U1DB - examples |
19 | 70 | Simple Qt5 binding and QtQuick2 plugin for U1DB (https://launchpad.net/u1db). | 72 | Simple Qt5 binding and QtQuick2 plugin for U1DB (https://launchpad.net/u1db). |
20 | 71 | 73 | ||
21 | === modified file 'examples/bookmarks/bookmarks.qml' | |||
22 | --- examples/bookmarks/bookmarks.qml 2014-02-17 17:40:42 +0000 | |||
23 | +++ examples/bookmarks/bookmarks.qml 2014-11-12 17:08:18 +0000 | |||
24 | @@ -123,8 +123,8 @@ | |||
25 | 123 | property string detailsDocId: "" | 123 | property string detailsDocId: "" |
26 | 124 | property string detailsContents: "" | 124 | property string detailsContents: "" |
27 | 125 | delegate: ListItem.Subtitled { | 125 | delegate: ListItem.Subtitled { |
30 | 126 | text: contents.title || '[title:%1]'.arg(docId) | 126 | text: title |
31 | 127 | subText: contents.uri || '[uri:%1]'.arg(docId) | 127 | subText: uri |
32 | 128 | // iconSource: contents.uri + "/favicon.ico" | 128 | // iconSource: contents.uri + "/favicon.ico" |
33 | 129 | fallbackIconName: "favorite-unselected,text-html" | 129 | fallbackIconName: "favorite-unselected,text-html" |
34 | 130 | iconFrame: false | 130 | iconFrame: false |
35 | @@ -147,7 +147,7 @@ | |||
36 | 147 | ListElement { label: 'Ubuntu'; expression: "[ 'uri' ]"; query: "[ 'http://www.ubuntu*' ]" } | 147 | ListElement { label: 'Ubuntu'; expression: "[ 'uri' ]"; query: "[ 'http://www.ubuntu*' ]" } |
37 | 148 | ListElement { label: 'Search'; expression: "[ 'meta.title' ]"; query: "[ 'Search*' ]" } | 148 | ListElement { label: 'Search'; expression: "[ 'meta.title' ]"; query: "[ 'Search*' ]" } |
38 | 149 | ListElement { label: 'Engine'; expression: "[ 'meta.tags' ]"; query: "[ 'engine' ]" } | 149 | ListElement { label: 'Engine'; expression: "[ 'meta.tags' ]"; query: "[ 'engine' ]" } |
40 | 150 | ListElement { label: 'All'; expression: "[ 'meta.visits', 'meta.title' ]"; query: "[ '*', '*' ]" } | 150 | ListElement { label: 'All'; expression: "[ 'meta.visits', 'meta.title', 'uri' ]"; query: "[ '*', '*', '*' ]" } |
41 | 151 | } | 151 | } |
42 | 152 | delegate: OptionSelectorDelegate { | 152 | delegate: OptionSelectorDelegate { |
43 | 153 | text: i18n.tr(label) | 153 | text: i18n.tr(label) |
44 | @@ -156,8 +156,11 @@ | |||
45 | 156 | onSelectedIndexChanged: { | 156 | onSelectedIndexChanged: { |
46 | 157 | var d = model.get(selectedIndex) | 157 | var d = model.get(selectedIndex) |
47 | 158 | text = '%1 - %2'.arg(d.expression).arg(d.query) | 158 | text = '%1 - %2'.arg(d.expression).arg(d.query) |
48 | 159 | bookmarksList.model = null | ||
49 | 159 | allBookmarks.index.expression = eval(d.expression) | 160 | allBookmarks.index.expression = eval(d.expression) |
50 | 160 | allBookmarks.query = eval(d.query) | 161 | allBookmarks.query = eval(d.query) |
51 | 162 | // Force update of delegates and role names | ||
52 | 163 | bookmarksList.model = allBookmarks | ||
53 | 161 | } | 164 | } |
54 | 162 | } | 165 | } |
55 | 163 | } | 166 | } |
56 | 164 | 167 | ||
57 | === added directory 'examples/movies' | |||
58 | === added file 'examples/movies/movies.qml' | |||
59 | --- examples/movies/movies.qml 1970-01-01 00:00:00 +0000 | |||
60 | +++ examples/movies/movies.qml 2014-11-12 17:08:18 +0000 | |||
61 | @@ -0,0 +1,196 @@ | |||
62 | 1 | /* | ||
63 | 2 | * Copyright (C) 2014 Canonical, Ltd. | ||
64 | 3 | * | ||
65 | 4 | * Authors: | ||
66 | 5 | * Christian Dywan <christian.dywan@canonical.com> | ||
67 | 6 | * | ||
68 | 7 | * This program is free software; you can redistribute it and/or modify | ||
69 | 8 | * it under the terms of the GNU Lesser General Public License as published by | ||
70 | 9 | * the Free Software Foundation; version 3. | ||
71 | 10 | * | ||
72 | 11 | * This program is distributed in the hope that it will be useful, | ||
73 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
74 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
75 | 14 | * GNU Lesser General Public License for more details. | ||
76 | 15 | * | ||
77 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
78 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
79 | 18 | */ | ||
80 | 19 | |||
81 | 20 | import QtQuick 2.0 | ||
82 | 21 | import U1db 1.0 as U1db | ||
83 | 22 | import Ubuntu.Components 1.1 | ||
84 | 23 | import Ubuntu.Components.ListItems 0.1 as ListItem | ||
85 | 24 | import Ubuntu.Components.Popups 0.1 | ||
86 | 25 | |||
87 | 26 | MainView { | ||
88 | 27 | id: root | ||
89 | 28 | applicationName: "com.ubuntu.developer.foobar.movies" | ||
90 | 29 | |||
91 | 30 | width: units.gu(45) | ||
92 | 31 | height: units.gu(80) | ||
93 | 32 | |||
94 | 33 | /* | ||
95 | 34 | Movie database | ||
96 | 35 | */ | ||
97 | 36 | |||
98 | 37 | U1db.Database { | ||
99 | 38 | id: db | ||
100 | 39 | // path: "movies.db" | ||
101 | 40 | } | ||
102 | 41 | |||
103 | 42 | // Defaults taken from http://archive.blender.org/features-gallery/movies/index.html | ||
104 | 43 | |||
105 | 44 | U1db.Document { | ||
106 | 45 | database: db | ||
107 | 46 | docId: 'yBigBuckBunny' | ||
108 | 47 | create: true | ||
109 | 48 | defaults: { | ||
110 | 49 | 'title': 'Big Buck Bunny (Short film)', | ||
111 | 50 | producer: 'Blender Foundation', | ||
112 | 51 | year: 2008, duration: '10min', website: 'https://www.bigbugckbunny.org' | ||
113 | 52 | } | ||
114 | 53 | } | ||
115 | 54 | |||
116 | 55 | U1db.Document { | ||
117 | 56 | database: db | ||
118 | 57 | docId: 'zElephantsDream' | ||
119 | 58 | create: true | ||
120 | 59 | defaults: { | ||
121 | 60 | 'title': 'Elephants Dream (Short film)', | ||
122 | 61 | producer: 'Blender Foundation', | ||
123 | 62 | year: 2006, duration: '10min', website: 'https://www.elephantsdream.org' | ||
124 | 63 | } | ||
125 | 64 | } | ||
126 | 65 | |||
127 | 66 | U1db.Document { | ||
128 | 67 | database: db | ||
129 | 68 | docId: 'cProjectLondon' | ||
130 | 69 | create: true | ||
131 | 70 | defaults: { | ||
132 | 71 | 'title': 'Project London Trailer', | ||
133 | 72 | producer: 'Independent', | ||
134 | 73 | year: 2009, duration: '22sec', website: 'https://www.projectlondonmovie.com' | ||
135 | 74 | } | ||
136 | 75 | } | ||
137 | 76 | |||
138 | 77 | U1db.Document { | ||
139 | 78 | database: db | ||
140 | 79 | docId: 'aSoftBoy' | ||
141 | 80 | create: true | ||
142 | 81 | defaults: { | ||
143 | 82 | 'title': 'Soft Boy (Animation)', | ||
144 | 83 | producer: 'Andy Goralczyk', | ||
145 | 84 | year: 2005, duration: '17sec' | ||
146 | 85 | } | ||
147 | 86 | } | ||
148 | 87 | |||
149 | 88 | U1db.Document { | ||
150 | 89 | database: db | ||
151 | 90 | docId: 'bEsign' | ||
152 | 91 | create: true | ||
153 | 92 | defaults: { | ||
154 | 93 | 'title': 'Esign (Animation)', | ||
155 | 94 | producer: 'Chris Larkee', | ||
156 | 95 | year: 2005, duration: '4min' | ||
157 | 96 | } | ||
158 | 97 | } | ||
159 | 98 | |||
160 | 99 | U1db.Query { | ||
161 | 100 | id: allMovies | ||
162 | 101 | index: blacklist | ||
163 | 102 | query: [ { year: '*', producer: '*', duration: '*', title: '*' } ] | ||
164 | 103 | } | ||
165 | 104 | |||
166 | 105 | U1db.Index { | ||
167 | 106 | id: blacklist | ||
168 | 107 | database: db | ||
169 | 108 | expression: [ 'year', 'duration', 'title', 'producer' ] | ||
170 | 109 | } | ||
171 | 110 | |||
172 | 111 | SortFilterModel { | ||
173 | 112 | id: sortedMovies | ||
174 | 113 | model: allMovies | ||
175 | 114 | filter.pattern: RegExp(searchProducer.text) | ||
176 | 115 | filter.property: 'producer' | ||
177 | 116 | sort.property: sortBy.role | ||
178 | 117 | sort.order: Qt.DescendingOrder | ||
179 | 118 | } | ||
180 | 119 | |||
181 | 120 | /* | ||
182 | 121 | UI: list view, filters | ||
183 | 122 | */ | ||
184 | 123 | |||
185 | 124 | Page { | ||
186 | 125 | id: page | ||
187 | 126 | title: i18n.tr('Movies') | ||
188 | 127 | |||
189 | 128 | Column { | ||
190 | 129 | id: container | ||
191 | 130 | anchors.margins: units.gu(1) | ||
192 | 131 | anchors.fill: parent | ||
193 | 132 | |||
194 | 133 | ListView { | ||
195 | 134 | id: movieList | ||
196 | 135 | width: parent.width | ||
197 | 136 | height: parent.height - pillar.height | ||
198 | 137 | model: sortedMovies | ||
199 | 138 | delegate: ListItem.Subtitled { | ||
200 | 139 | text: '<b>%1</b> %2'.arg(title).arg(year) | ||
201 | 140 | subText: '%1 <b>%2</b>'.arg(duration).arg(producer) | ||
202 | 141 | fallbackIconName: "favorite-unselected,text-html" | ||
203 | 142 | iconFrame: false | ||
204 | 143 | } | ||
205 | 144 | } | ||
206 | 145 | |||
207 | 146 | Column { | ||
208 | 147 | id: pillar | ||
209 | 148 | spacing: units.gu(1) | ||
210 | 149 | width: parent.width | ||
211 | 150 | |||
212 | 151 | Label { | ||
213 | 152 | text: sortBy.role | ||
214 | 153 | } | ||
215 | 154 | |||
216 | 155 | OptionSelector { | ||
217 | 156 | id: sortBy | ||
218 | 157 | StateSaver.properties: 'selectedIndex' | ||
219 | 158 | model: ListModel { | ||
220 | 159 | ListElement { label: 'Title'; role: 'title' } | ||
221 | 160 | ListElement { label: 'Year'; role: 'year' } | ||
222 | 161 | ListElement { label: 'Length'; role: 'duration' } | ||
223 | 162 | } | ||
224 | 163 | delegate: OptionSelectorDelegate { | ||
225 | 164 | text: i18n.tr(label) | ||
226 | 165 | } | ||
227 | 166 | property string role: 'title' | ||
228 | 167 | onDelegateClicked: { | ||
229 | 168 | var selectedIndex = index | ||
230 | 169 | role = model.get(selectedIndex).role | ||
231 | 170 | // Work-around for sort.property not correctly re-sorting | ||
232 | 171 | var m = movieList.model | ||
233 | 172 | movieList.model = null | ||
234 | 173 | movieList.model = m | ||
235 | 174 | } | ||
236 | 175 | } | ||
237 | 176 | |||
238 | 177 | TextField { | ||
239 | 178 | id: searchProducer | ||
240 | 179 | StateSaver.properties: 'text' | ||
241 | 180 | placeholderText: i18n.tr('Search Producer…') | ||
242 | 181 | } | ||
243 | 182 | |||
244 | 183 | OptionSelector { | ||
245 | 184 | id: selectYear | ||
246 | 185 | StateSaver.properties: 'selectedIndex' | ||
247 | 186 | model: [ '*', 2005, 2006, 2007, 2008, 2009 ] | ||
248 | 187 | delegate: OptionSelectorDelegate { | ||
249 | 188 | text: modelData == '*' ? 'All Years' : modelData | ||
250 | 189 | } | ||
251 | 190 | property var year: model[selectedIndex] | ||
252 | 191 | } | ||
253 | 192 | } | ||
254 | 193 | } | ||
255 | 194 | } | ||
256 | 195 | } | ||
257 | 196 | |||
258 | 0 | 197 | ||
259 | === modified file 'src/query.cpp' | |||
260 | --- src/query.cpp 2014-03-13 19:31:58 +0000 | |||
261 | +++ src/query.cpp 2014-11-12 17:08:18 +0000 | |||
262 | @@ -17,7 +17,6 @@ | |||
263 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
264 | 18 | */ | 18 | */ |
265 | 19 | 19 | ||
266 | 20 | #include <QDebug> | ||
267 | 21 | #include <QSqlQuery> | 20 | #include <QSqlQuery> |
268 | 22 | #include <QFile> | 21 | #include <QFile> |
269 | 23 | #include <QSqlError> | 22 | #include <QSqlError> |
270 | @@ -64,7 +63,11 @@ | |||
271 | 64 | return m_results.at(index.row()); | 63 | return m_results.at(index.row()); |
272 | 65 | if (role == 1) // docId | 64 | if (role == 1) // docId |
273 | 66 | return m_documents.at(index.row()); | 65 | return m_documents.at(index.row()); |
275 | 67 | return QVariant(); | 66 | |
276 | 67 | int indexForRole = role - 2; | ||
277 | 68 | QVariantMap result(m_results.at(index.row()).toMap()); | ||
278 | 69 | QString field(m_index->getExpression().at(indexForRole).split(".").last()); | ||
279 | 70 | return result.value(field); | ||
280 | 68 | } | 71 | } |
281 | 69 | 72 | ||
282 | 70 | /*! | 73 | /*! |
283 | @@ -79,6 +82,13 @@ | |||
284 | 79 | QHash<int, QByteArray> roles; | 82 | QHash<int, QByteArray> roles; |
285 | 80 | roles.insert(0, "contents"); | 83 | roles.insert(0, "contents"); |
286 | 81 | roles.insert(1, "docId"); | 84 | roles.insert(1, "docId"); |
287 | 85 | if (!m_index) | ||
288 | 86 | return roles; | ||
289 | 87 | |||
290 | 88 | // A role name for each field in the index | ||
291 | 89 | uint fieldRole = 2; | ||
292 | 90 | Q_FOREACH(QString field, m_index->getExpression()) | ||
293 | 91 | roles.insert(fieldRole++, field.split(".").last().toUtf8()); | ||
294 | 82 | return roles; | 92 | return roles; |
295 | 83 | } | 93 | } |
296 | 84 | 94 | ||
297 | 85 | 95 | ||
298 | === modified file 'tests/test-database.cpp' | |||
299 | --- tests/test-database.cpp 2014-11-07 14:30:31 +0000 | |||
300 | +++ tests/test-database.cpp 2014-11-12 17:08:18 +0000 | |||
301 | @@ -82,6 +82,21 @@ | |||
302 | 82 | query.setQuery(QStringList() << "2014*" << "basketball" << "linux"); | 82 | query.setQuery(QStringList() << "2014*" << "basketball" << "linux"); |
303 | 83 | } | 83 | } |
304 | 84 | 84 | ||
305 | 85 | void testRoleNames() | ||
306 | 86 | { | ||
307 | 87 | Database db; | ||
308 | 88 | Index index; | ||
309 | 89 | index.setDatabase(&db); | ||
310 | 90 | index.setExpression(QStringList() << "species" << "traits.spots"); | ||
311 | 91 | Query query; | ||
312 | 92 | query.setIndex(&index); | ||
313 | 93 | QStringList expected(QStringList() << "docId" << "contents" << "species" << "spots"); | ||
314 | 94 | Q_FOREACH(QString roleName, expected) | ||
315 | 95 | QVERIFY2(query.roleNames().values().contains(roleName.toUtf8()), | ||
316 | 96 | qPrintable(QString("Expected role name \"%1\" not in Query").arg(roleName))); | ||
317 | 97 | QVERIFY(db.lastError().isEmpty()); | ||
318 | 98 | } | ||
319 | 99 | |||
320 | 85 | void cleanupTestCase() | 100 | void cleanupTestCase() |
321 | 86 | { | 101 | { |
322 | 87 | } | 102 | } |
323 | 88 | 103 | ||
324 | === modified file 'tests/tst_query.qml' | |||
325 | --- tests/tst_query.qml 2014-03-13 19:31:58 +0000 | |||
326 | +++ tests/tst_query.qml 2014-11-12 17:08:18 +0000 | |||
327 | @@ -20,6 +20,8 @@ | |||
328 | 20 | import QtQuick 2.0 | 20 | import QtQuick 2.0 |
329 | 21 | import QtTest 1.0 | 21 | import QtTest 1.0 |
330 | 22 | import U1db 1.0 as U1db | 22 | import U1db 1.0 as U1db |
331 | 23 | import Ubuntu.Components 1.1 | ||
332 | 24 | import Ubuntu.Test 0.1 | ||
333 | 23 | 25 | ||
334 | 24 | Item { | 26 | Item { |
335 | 25 | width: 200; height: 200 | 27 | width: 200; height: 200 |
336 | @@ -241,13 +243,79 @@ | |||
337 | 241 | signalName: "documentsChanged" | 243 | signalName: "documentsChanged" |
338 | 242 | } | 244 | } |
339 | 243 | 245 | ||
341 | 244 | TestCase { | 246 | U1db.Database { |
342 | 247 | id: animals | ||
343 | 248 | } | ||
344 | 249 | |||
345 | 250 | // Note: docId's intentionally chosen for wrong alphabetic order | ||
346 | 251 | U1db.Document { | ||
347 | 252 | database: animals | ||
348 | 253 | docId: 'k_cow' | ||
349 | 254 | contents: { 'species': 'cow', 'traits': [ { 'spots': true } ] } | ||
350 | 255 | } | ||
351 | 256 | U1db.Document { | ||
352 | 257 | database: animals | ||
353 | 258 | docId: 'z_ant' | ||
354 | 259 | contents: { 'species': 'ant' } | ||
355 | 260 | } | ||
356 | 261 | |||
357 | 262 | U1db.Document { | ||
358 | 263 | database: animals | ||
359 | 264 | docId: 'a_bee' | ||
360 | 265 | contents: { 'species': 'bee' } | ||
361 | 266 | } | ||
362 | 267 | |||
363 | 268 | U1db.Document { | ||
364 | 269 | database: animals | ||
365 | 270 | docId: 'n_cat' | ||
366 | 271 | contents: { 'species': 'cat' } | ||
367 | 272 | } | ||
368 | 273 | U1db.Index { | ||
369 | 274 | id: bySpecies | ||
370 | 275 | database: animals | ||
371 | 276 | name: 'by-species' | ||
372 | 277 | expression: [ 'species' ] | ||
373 | 278 | } | ||
374 | 279 | |||
375 | 280 | U1db.Query { | ||
376 | 281 | id: allAnimals | ||
377 | 282 | index: bySpecies | ||
378 | 283 | query: [{ 'species': '*' }] | ||
379 | 284 | } | ||
380 | 285 | |||
381 | 286 | // To double-check failures aren't due to SortFilterModel itself | ||
382 | 287 | ListModel { | ||
383 | 288 | id: fakeAnimals | ||
384 | 289 | ListElement { species: 'cow'; docId: 'k_cow' } | ||
385 | 290 | ListElement { species: 'ant'; docId: 'z_ant' } | ||
386 | 291 | ListElement { species: 'bee'; docId: 'a_bee' } | ||
387 | 292 | ListElement { species: 'cat'; docId: 'n_cat' } | ||
388 | 293 | } | ||
389 | 294 | |||
390 | 295 | SortFilterModel { | ||
391 | 296 | id: mixedAnimals | ||
392 | 297 | model: allAnimals | ||
393 | 298 | } | ||
394 | 299 | |||
395 | 300 | SortFilterModel { | ||
396 | 301 | id: sortedAnimals | ||
397 | 302 | sort.property: 'species' | ||
398 | 303 | sort.order: Qt.AscendingOrder | ||
399 | 304 | } | ||
400 | 305 | |||
401 | 306 | SortFilterModel { | ||
402 | 307 | id: filteredAnimals | ||
403 | 308 | filter.property: 'species' | ||
404 | 309 | filter.pattern: /ant/ | ||
405 | 310 | } | ||
406 | 311 | |||
407 | 312 | UbuntuTestCase { | ||
408 | 245 | name: "U1dbDatabase" | 313 | name: "U1dbDatabase" |
409 | 246 | when: windowShown | 314 | when: windowShown |
410 | 247 | 315 | ||
411 | 248 | function prettyJson(j) { | 316 | function prettyJson(j) { |
412 | 249 | var A = JSON.stringify(j) | 317 | var A = JSON.stringify(j) |
414 | 250 | if (A['0'] && A != '{}') { | 318 | if (A != undefined && A['0'] && A != '{}') { |
415 | 251 | var A = '[' | 319 | var A = '[' |
416 | 252 | for(var i in j) | 320 | for(var i in j) |
417 | 253 | A += JSON.stringify(j[i]) + ',' | 321 | A += JSON.stringify(j[i]) + ',' |
418 | @@ -260,6 +328,8 @@ | |||
419 | 260 | compare(a, b, msg, true) | 328 | compare(a, b, msg, true) |
420 | 261 | } | 329 | } |
421 | 262 | 330 | ||
422 | 331 | TestUtil { id: util } | ||
423 | 332 | |||
424 | 263 | function compare(a, b, msg, willFail) { | 333 | function compare(a, b, msg, willFail) { |
425 | 264 | /* Override built-in compare to: | 334 | /* Override built-in compare to: |
426 | 265 | Match different JSON for identical values (number hash versus list) | 335 | Match different JSON for identical values (number hash versus list) |
427 | @@ -273,7 +343,12 @@ | |||
428 | 273 | console.log('Expected failure: %1%2 != %3'.arg(msg ? msg + ': ' : '').arg(A).arg(B)) | 343 | console.log('Expected failure: %1%2 != %3'.arg(msg ? msg + ': ' : '').arg(A).arg(B)) |
429 | 274 | return | 344 | return |
430 | 275 | } | 345 | } |
432 | 276 | fail('%5%1 != %2 (%3 != %4)'.arg(A).arg(B).arg(JSON.stringify(a)).arg(JSON.stringify(b)).arg(msg ? msg + ': ' : '')) | 346 | if (!qtest_results.compare (false, |
433 | 347 | msg ? msg : "Comparison failed", | ||
434 | 348 | A + " ~ " + JSON.stringify(a), | ||
435 | 349 | B + " ~ " + JSON.stringify(b), | ||
436 | 350 | util.callerFile(), util.callerLine())) | ||
437 | 351 | throw new Error("QtQuickTest::fail") | ||
438 | 277 | } | 352 | } |
439 | 278 | if (willFail) | 353 | if (willFail) |
440 | 279 | fail('Expected to fail, but passed: %5%1 != %2 (%3 != %4)'.arg(A).arg(B).arg(JSON.stringify(a)).arg(JSON.stringify(b)).arg(msg ? msg + ': ' : '')) | 354 | fail('Expected to fail, but passed: %5%1 != %2 (%3 != %4)'.arg(A).arg(B).arg(JSON.stringify(a)).arg(JSON.stringify(b)).arg(msg ? msg + ': ' : '')) |
441 | @@ -359,5 +434,45 @@ | |||
442 | 359 | compare(allHeroesWithType.documents, ['dino', 'gokaiger', 'ooo', 'wizard'], 'go') | 434 | compare(allHeroesWithType.documents, ['dino', 'gokaiger', 'ooo', 'wizard'], 'go') |
443 | 360 | compare(allHeroesWithType.documents, allHeroesSeriesOnly.documents, 'roku') | 435 | compare(allHeroesWithType.documents, allHeroesSeriesOnly.documents, 'roku') |
444 | 361 | } | 436 | } |
445 | 437 | |||
446 | 438 | function test_7_sort_data () { | ||
447 | 439 | return [ { tag: 'Reference ListModel', model: fakeAnimals }, | ||
448 | 440 | { tag: 'U1db.Query', model: allAnimals } ] | ||
449 | 441 | } | ||
450 | 442 | |||
451 | 443 | function test_7_sort (data) { | ||
452 | 444 | // Sanity checks | ||
453 | 445 | compare(allAnimals.documents, ["a_bee", "k_cow", "n_cat", "z_ant"]) | ||
454 | 446 | tryCompareFunction(function(){return mixedAnimals.get(0).docId}, "a_bee") | ||
455 | 447 | |||
456 | 448 | sortedAnimals.model = data.model | ||
457 | 449 | compare(sortedAnimals.count, 4, "number of animals") | ||
458 | 450 | sortedAnimals.sort.property = 'species' | ||
459 | 451 | compare(sortedAnimals.get(0).docId, "z_ant", "ants document sorted first") | ||
460 | 452 | compare(sortedAnimals.get(0).species, "ant", "ants species sorted first") | ||
461 | 453 | |||
462 | 454 | sortedAnimals.sort.order = Qt.DescendingOrder | ||
463 | 455 | compare(sortedAnimals.get(0).species, "cow", "cow sorted first descending") | ||
464 | 456 | |||
465 | 457 | sortedAnimals.sort.property = 'docId' | ||
466 | 458 | sortedAnimals.sort.order = Qt.AscendingOrder | ||
467 | 459 | compare(sortedAnimals.get(0).docId, "a_bee", "bee sorted first by docId") | ||
468 | 460 | } | ||
469 | 461 | |||
470 | 462 | function test_8_filter_data () { | ||
471 | 463 | return [ { tag: 'Reference ListModel', model: fakeAnimals }, | ||
472 | 464 | { tag: 'U1db.Query', model: allAnimals } ] | ||
473 | 465 | } | ||
474 | 466 | |||
475 | 467 | function test_8_filter (data) { | ||
476 | 468 | // Sanity checks | ||
477 | 469 | compare(allAnimals.documents, ["a_bee", "k_cow", "n_cat", "z_ant"]) | ||
478 | 470 | tryCompareFunction(function(){return mixedAnimals.get(0).docId}, "a_bee") | ||
479 | 471 | |||
480 | 472 | filteredAnimals.model = data.model | ||
481 | 473 | compare(filteredAnimals.count, 1, "number of animals") | ||
482 | 474 | compare(filteredAnimals.get(0).species, "ant", "ants species role available") | ||
483 | 475 | compare(filteredAnimals.get(0).docId, "z_ant", "ants included in filter") | ||
484 | 476 | } | ||
485 | 362 | } } | 477 | } } |
486 | 363 | 478 |
PASSED: Continuous integration, rev:117 jenkins. qa.ubuntu. com/job/ u1db-qt- ci/47/ jenkins. qa.ubuntu. com/job/ u1db-qt- precise- amd64-ci/ 47 jenkins. qa.ubuntu. com/job/ u1db-qt- saucy-amd64- ci/49 jenkins. qa.ubuntu. com/job/ u1db-qt- trusty- amd64-ci/ 27 jenkins. qa.ubuntu. com/job/ u1db-qt- trusty- armhf-ci/ 27
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/u1db- qt-ci/47/ rebuild
http://