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
=== modified file 'src/query.cpp'
--- src/query.cpp 2013-04-22 13:19:33 +0000
+++ src/query.cpp 2013-04-23 12:32:08 +0000
@@ -56,18 +56,8 @@
56QVariant56QVariant
57Query::data(const QModelIndex & index, int role) const57Query::data(const QModelIndex & index, int role) const
58{58{
59 QVariantMap result(m_hash.value(index.row()));
60
61 if (role == 0) // contents59 if (role == 0) // contents
62 {60 return m_results.at(index.row());
63 Database* db(m_index->getDatabase());
64 if (db)
65 {
66 return result;
67 }
68 }
69 if (role == 1) // docId
70 //return docId;
71 return QVariant();61 return QVariant();
72}62}
7363
@@ -94,7 +84,7 @@
94int84int
95Query::rowCount(const QModelIndex & parent) const85Query::rowCount(const QModelIndex & parent) const
96{86{
97 return m_hash.count();87 return m_results.count();
98}88}
9989
100/*!90/*!
@@ -113,7 +103,7 @@
113void103void
114Query::onDataInvalidated()104Query::onDataInvalidated()
115{105{
116 m_hash.clear();106 m_results.clear();
117107
118 if (!m_index)108 if (!m_index)
119 return;109 return;
@@ -159,11 +149,12 @@
159 }149 }
160150
161 if(match == true){151 if(match == true){
162 m_hash.insert(m_hash.count(),i_map);152 m_results.append(i_map);
163 }153 }
164154
165 }155 }
166156
157 Q_EMIT resultsChanged(m_results);
167}158}
168159
169bool Query::queryField(QString field, QVariant value){160bool Query::queryField(QString field, QVariant value){
@@ -362,6 +353,12 @@
362 onDataInvalidated();353 onDataInvalidated();
363}354}
364355
356QList<QVariant>
357Query::getResults()
358{
359 return m_results;
360}
361
365QT_END_NAMESPACE_U1DB362QT_END_NAMESPACE_U1DB
366363
367#include "moc_query.cpp"364#include "moc_query.cpp"
368365
=== modified file 'src/query.h'
--- src/query.h 2013-04-19 11:19:43 +0000
+++ src/query.h 2013-04-23 12:32:08 +0000
@@ -36,6 +36,7 @@
36#endif36#endif
37 Q_PROPERTY(QVariant query READ getQuery WRITE setQuery NOTIFY queryChanged)37 Q_PROPERTY(QVariant query READ getQuery WRITE setQuery NOTIFY queryChanged)
38 Q_PROPERTY(QVariant range READ getRange WRITE setRange NOTIFY rangeChanged)38 Q_PROPERTY(QVariant range READ getRange WRITE setRange NOTIFY rangeChanged)
39 Q_PROPERTY(QList<QVariant> results READ getResults NOTIFY resultsChanged)
39public:40public:
40 Query(QObject* parent = 0);41 Query(QObject* parent = 0);
41 ~Query() { }42 ~Query() { }
@@ -51,6 +52,7 @@
51 void setQuery(QVariant query);52 void setQuery(QVariant query);
52 QVariant getRange();53 QVariant getRange();
53 void setRange(QVariant range);54 void setRange(QVariant range);
55 Q_INVOKABLE QList<QVariant> getResults();
5456
55 void generateQueryResults();57 void generateQueryResults();
56 bool iterateQueryList(QVariant query, QString field, QString value);58 bool iterateQueryList(QVariant query, QString field, QString value);
@@ -62,10 +64,11 @@
62 void indexChanged(Index* index);64 void indexChanged(Index* index);
63 void queryChanged(QVariant query);65 void queryChanged(QVariant query);
64 void rangeChanged(QVariant range);66 void rangeChanged(QVariant range);
67 void resultsChanged(QList<QVariant> results);
65private:68private:
66 Q_DISABLE_COPY(Query)69 Q_DISABLE_COPY(Query)
67 Index* m_index;70 Index* m_index;
68 QHash<int, QVariantMap> m_hash;71 QList<QVariant> m_results;
69 QVariant m_query;72 QVariant m_query;
70 QVariant m_range;73 QVariant m_range;
7174
7275
=== modified file 'tests/test-database.cpp'
--- tests/test-database.cpp 2013-02-14 11:33:58 +0000
+++ tests/test-database.cpp 2013-04-23 12:32:08 +0000
@@ -21,6 +21,8 @@
21#include <QObject>21#include <QObject>
2222
23#include "database.h"23#include "database.h"
24#include "index.h"
25#include "query.h"
2426
25QT_USE_NAMESPACE_U1DB27QT_USE_NAMESPACE_U1DB
2628
@@ -40,11 +42,20 @@
4042
41 Database db;43 Database db;
42 QCOMPARE(db.getPath(), QString(""));44 QCOMPARE(db.getPath(), QString(""));
43 QSignalSpy modelReset(&db, SIGNAL(pathChanged()));45 QSignalSpy modelReset(&db, SIGNAL(pathChanged(const QString&)));
44 QTemporaryFile file;46 QTemporaryFile file;
45 db.setPath(file.fileName());47 db.setPath(file.fileName());
46 QCOMPARE(db.getPath(), file.fileName());48 QCOMPARE(db.getPath(), file.fileName());
47 }49
50 Index index;
51 index.setDatabase(&db);
52 index.setName("py-phone-number");
53 index.setExpression(QStringList("managers.phone_number"));
54
55 Query query;
56 query.setIndex(&index);
57 query.setQuery("*");
58 }
4859
49 void cleanupTestCase()60 void cleanupTestCase()
50 {61 {
5162
=== modified file 'tests/tst_database.qml'
--- tests/tst_database.qml 2013-04-12 11:50:24 +0000
+++ tests/tst_database.qml 2013-04-23 12:32:08 +0000
@@ -52,37 +52,6 @@
52 defaults: { "eggs": "spam" }52 defaults: { "eggs": "spam" }
53 }53 }
5454
55
56 U1db.Index {
57 id: myIndex
58 database: myDatabase
59 name: 'by-title-field'
60 expression: ['title', 'bool(field)']
61 }
62
63 U1db.Query {
64 id: firstQuery
65 index: myIndex
66 query: ['match', false]
67 }
68
69 U1db.Query {
70 id: secondQuery
71 index: myIndex
72 range: [['a', 'b'], ['*']]
73 }
74
75 U1db.Query {
76 id: allQuery
77 index: myIndex
78 query: '*'
79 }
80
81 U1db.Query {
82 id: defaultAllQuery
83 index: myIndex
84 }
85
86 ListView {55 ListView {
87 id: myList56 id: myList
88 model: myDatabase57 model: myDatabase
8958
=== added file 'tests/tst_query.qml'
--- tests/tst_query.qml 1970-01-01 00:00:00 +0000
+++ tests/tst_query.qml 2013-04-23 12:32:08 +0000
@@ -0,0 +1,127 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * Christian Dywan <christian.dywan@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20import QtQuick 2.0
21import QtTest 1.0
22import U1db 1.0 as U1db
23
24Item {
25 width: 200; height: 200
26
27 U1db.Database {
28 id: gents
29 }
30
31 U1db.Document {
32 database: gents
33 docId: '1'
34 contents: { 'gents': [ { 'name': 'Mary', 'phone': 12345 }, { 'name': 'Rob', 'phone': 54321 }, ] }
35 }
36
37 U1db.Document {
38 database: gents
39 docId: 'a'
40 contents: { 'gents': [ { 'name': 'George', 'phone': 'NA' }, { 'name': 'Ivanka', 'phone': 50243 }, ] }
41 }
42
43 U1db.Document {
44 database: gents
45 docId: '_'
46 contents: { 'gents': [ { 'name': 'Ivanka', 'phone': 00321 }, ] }
47 }
48
49 U1db.Index {
50 id: byPhone
51 database: gents
52 name: 'by-phone'
53 expression: ['gents.phone']
54 }
55
56 U1db.Index {
57 id: byNamePhone
58 database: gents
59 name: 'by-name-phone'
60 expression: ['gents.name', 'gents.phone']
61 }
62
63 U1db.Query {
64 id: defaultPhone
65 index: byPhone
66 }
67
68 U1db.Query {
69 id: allPhone
70 index: byPhone
71 query: '*'
72 }
73
74 U1db.Query {
75 id: allPhoneList
76 index: byPhone
77 query: ['*']
78 }
79
80 U1db.Query {
81 id: allPhoneKeywords
82 index: byPhone
83 query: { 'phone': '*' }
84 }
85
86 U1db.Query {
87 id: s12345Phone
88 index: byPhone
89 query: '12345'
90 }
91
92 U1db.Query {
93 id: i12345Phone
94 index: byPhone
95 query: 12345
96 }
97
98 U1db.Query {
99 id: s1wildcardPhone
100 index: byPhone
101 query: '1*'
102 }
103
104 U1db.Query {
105 id: ivankaAllNamePhone
106 index: byNamePhone
107 query: ['Ivanka', '*']
108 }
109
110 U1db.Query {
111 id: ivankaAllNamePhoneKeywords
112 index: byNamePhone
113 query: { 'name': 'Ivanka', 'phone': '*' }
114 }
115
116TestCase {
117 name: "U1dbDatabase"
118 when: windowShown
119
120 function test_1_defaults () {
121 // We should get all documents
122 compare(defaultPhone.results, [])
123 // Results are also equivalent
124 compare(defaultPhone.results, allPhoneKeywords.results)
125 }
126} }
127

Subscribers

People subscribed via source and target branches

to all changes: