Merge lp:~kalikiana/u1db-qt/query4a into lp:u1db-qt

Proposed by Cris Dywan
Status: Merged
Approved by: Cris Dywan
Approved revision: 74
Merged at revision: 80
Proposed branch: lp:~kalikiana/u1db-qt/query4a
Merge into: lp:u1db-qt
Diff against target: 311 lines (+155/-48)
5 files modified
src/query.cpp (+11/-14)
src/query.h (+4/-1)
tests/test-database.cpp (+13/-2)
tests/tst_database.qml (+0/-31)
tests/tst_query.qml (+127/-0)
To merge this branch: bzr merge lp:~kalikiana/u1db-qt/query4a
Reviewer Review Type Date Requested Status
Cris Dywan Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+160351@code.launchpad.net

Commit message

Initial ground work splitting off query tests

Description of the change

Initial ground work splitting off query tests

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/query.cpp'
2--- src/query.cpp 2013-04-22 13:19:33 +0000
3+++ src/query.cpp 2013-04-23 12:32:08 +0000
4@@ -56,18 +56,8 @@
5 QVariant
6 Query::data(const QModelIndex & index, int role) const
7 {
8- QVariantMap result(m_hash.value(index.row()));
9-
10 if (role == 0) // contents
11- {
12- Database* db(m_index->getDatabase());
13- if (db)
14- {
15- return result;
16- }
17- }
18- if (role == 1) // docId
19- //return docId;
20+ return m_results.at(index.row());
21 return QVariant();
22 }
23
24@@ -94,7 +84,7 @@
25 int
26 Query::rowCount(const QModelIndex & parent) const
27 {
28- return m_hash.count();
29+ return m_results.count();
30 }
31
32 /*!
33@@ -113,7 +103,7 @@
34 void
35 Query::onDataInvalidated()
36 {
37- m_hash.clear();
38+ m_results.clear();
39
40 if (!m_index)
41 return;
42@@ -159,11 +149,12 @@
43 }
44
45 if(match == true){
46- m_hash.insert(m_hash.count(),i_map);
47+ m_results.append(i_map);
48 }
49
50 }
51
52+ Q_EMIT resultsChanged(m_results);
53 }
54
55 bool Query::queryField(QString field, QVariant value){
56@@ -362,6 +353,12 @@
57 onDataInvalidated();
58 }
59
60+QList<QVariant>
61+Query::getResults()
62+{
63+ return m_results;
64+}
65+
66 QT_END_NAMESPACE_U1DB
67
68 #include "moc_query.cpp"
69
70=== modified file 'src/query.h'
71--- src/query.h 2013-04-19 11:19:43 +0000
72+++ src/query.h 2013-04-23 12:32:08 +0000
73@@ -36,6 +36,7 @@
74 #endif
75 Q_PROPERTY(QVariant query READ getQuery WRITE setQuery NOTIFY queryChanged)
76 Q_PROPERTY(QVariant range READ getRange WRITE setRange NOTIFY rangeChanged)
77+ Q_PROPERTY(QList<QVariant> results READ getResults NOTIFY resultsChanged)
78 public:
79 Query(QObject* parent = 0);
80 ~Query() { }
81@@ -51,6 +52,7 @@
82 void setQuery(QVariant query);
83 QVariant getRange();
84 void setRange(QVariant range);
85+ Q_INVOKABLE QList<QVariant> getResults();
86
87 void generateQueryResults();
88 bool iterateQueryList(QVariant query, QString field, QString value);
89@@ -62,10 +64,11 @@
90 void indexChanged(Index* index);
91 void queryChanged(QVariant query);
92 void rangeChanged(QVariant range);
93+ void resultsChanged(QList<QVariant> results);
94 private:
95 Q_DISABLE_COPY(Query)
96 Index* m_index;
97- QHash<int, QVariantMap> m_hash;
98+ QList<QVariant> m_results;
99 QVariant m_query;
100 QVariant m_range;
101
102
103=== modified file 'tests/test-database.cpp'
104--- tests/test-database.cpp 2013-02-14 11:33:58 +0000
105+++ tests/test-database.cpp 2013-04-23 12:32:08 +0000
106@@ -21,6 +21,8 @@
107 #include <QObject>
108
109 #include "database.h"
110+#include "index.h"
111+#include "query.h"
112
113 QT_USE_NAMESPACE_U1DB
114
115@@ -40,11 +42,20 @@
116
117 Database db;
118 QCOMPARE(db.getPath(), QString(""));
119- QSignalSpy modelReset(&db, SIGNAL(pathChanged()));
120+ QSignalSpy modelReset(&db, SIGNAL(pathChanged(const QString&)));
121 QTemporaryFile file;
122 db.setPath(file.fileName());
123 QCOMPARE(db.getPath(), file.fileName());
124- }
125+
126+ Index index;
127+ index.setDatabase(&db);
128+ index.setName("py-phone-number");
129+ index.setExpression(QStringList("managers.phone_number"));
130+
131+ Query query;
132+ query.setIndex(&index);
133+ query.setQuery("*");
134+ }
135
136 void cleanupTestCase()
137 {
138
139=== modified file 'tests/tst_database.qml'
140--- tests/tst_database.qml 2013-04-12 11:50:24 +0000
141+++ tests/tst_database.qml 2013-04-23 12:32:08 +0000
142@@ -52,37 +52,6 @@
143 defaults: { "eggs": "spam" }
144 }
145
146-
147- U1db.Index {
148- id: myIndex
149- database: myDatabase
150- name: 'by-title-field'
151- expression: ['title', 'bool(field)']
152- }
153-
154- U1db.Query {
155- id: firstQuery
156- index: myIndex
157- query: ['match', false]
158- }
159-
160- U1db.Query {
161- id: secondQuery
162- index: myIndex
163- range: [['a', 'b'], ['*']]
164- }
165-
166- U1db.Query {
167- id: allQuery
168- index: myIndex
169- query: '*'
170- }
171-
172- U1db.Query {
173- id: defaultAllQuery
174- index: myIndex
175- }
176-
177 ListView {
178 id: myList
179 model: myDatabase
180
181=== added file 'tests/tst_query.qml'
182--- tests/tst_query.qml 1970-01-01 00:00:00 +0000
183+++ tests/tst_query.qml 2013-04-23 12:32:08 +0000
184@@ -0,0 +1,127 @@
185+/*
186+ * Copyright (C) 2013 Canonical, Ltd.
187+ *
188+ * Authors:
189+ * Christian Dywan <christian.dywan@canonical.com>
190+ *
191+ * This program is free software; you can redistribute it and/or modify
192+ * it under the terms of the GNU Lesser General Public License as published by
193+ * the Free Software Foundation; version 3.
194+ *
195+ * This program is distributed in the hope that it will be useful,
196+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
197+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
198+ * GNU Lesser General Public License for more details.
199+ *
200+ * You should have received a copy of the GNU Lesser General Public License
201+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
202+ */
203+
204+import QtQuick 2.0
205+import QtTest 1.0
206+import U1db 1.0 as U1db
207+
208+Item {
209+ width: 200; height: 200
210+
211+ U1db.Database {
212+ id: gents
213+ }
214+
215+ U1db.Document {
216+ database: gents
217+ docId: '1'
218+ contents: { 'gents': [ { 'name': 'Mary', 'phone': 12345 }, { 'name': 'Rob', 'phone': 54321 }, ] }
219+ }
220+
221+ U1db.Document {
222+ database: gents
223+ docId: 'a'
224+ contents: { 'gents': [ { 'name': 'George', 'phone': 'NA' }, { 'name': 'Ivanka', 'phone': 50243 }, ] }
225+ }
226+
227+ U1db.Document {
228+ database: gents
229+ docId: '_'
230+ contents: { 'gents': [ { 'name': 'Ivanka', 'phone': 00321 }, ] }
231+ }
232+
233+ U1db.Index {
234+ id: byPhone
235+ database: gents
236+ name: 'by-phone'
237+ expression: ['gents.phone']
238+ }
239+
240+ U1db.Index {
241+ id: byNamePhone
242+ database: gents
243+ name: 'by-name-phone'
244+ expression: ['gents.name', 'gents.phone']
245+ }
246+
247+ U1db.Query {
248+ id: defaultPhone
249+ index: byPhone
250+ }
251+
252+ U1db.Query {
253+ id: allPhone
254+ index: byPhone
255+ query: '*'
256+ }
257+
258+ U1db.Query {
259+ id: allPhoneList
260+ index: byPhone
261+ query: ['*']
262+ }
263+
264+ U1db.Query {
265+ id: allPhoneKeywords
266+ index: byPhone
267+ query: { 'phone': '*' }
268+ }
269+
270+ U1db.Query {
271+ id: s12345Phone
272+ index: byPhone
273+ query: '12345'
274+ }
275+
276+ U1db.Query {
277+ id: i12345Phone
278+ index: byPhone
279+ query: 12345
280+ }
281+
282+ U1db.Query {
283+ id: s1wildcardPhone
284+ index: byPhone
285+ query: '1*'
286+ }
287+
288+ U1db.Query {
289+ id: ivankaAllNamePhone
290+ index: byNamePhone
291+ query: ['Ivanka', '*']
292+ }
293+
294+ U1db.Query {
295+ id: ivankaAllNamePhoneKeywords
296+ index: byNamePhone
297+ query: { 'name': 'Ivanka', 'phone': '*' }
298+ }
299+
300+TestCase {
301+ name: "U1dbDatabase"
302+ when: windowShown
303+
304+ function test_1_defaults () {
305+ // We should get all documents
306+ compare(defaultPhone.results, [])
307+ // Results are also equivalent
308+ compare(defaultPhone.results, allPhoneKeywords.results)
309+ }
310+} }
311+

Subscribers

People subscribed via source and target branches

to all changes: