2
* Copyright (C) 2013 Canonical, Ltd.
5
* Christian Dywan <christian.dywan@canonical.com>
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.
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.
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/>.
22
import U1db 1.0 as U1db
25
width: 200; height: 200
30
property bool first_row_loaded: false
31
property bool last_row_loaded: false
33
if (path == 'aDatabaseC' && docId == 'dl0')
34
first_row_loaded = true
35
if (path == 'aDatabaseC' && docId == 'dl99')
36
last_row_loaded = true
44
defaults: { "eggs": "spam" }
52
defaults: { "eggs": "spam" }
58
width: 200; height: 200
61
text: "otherDelegate index:%1".arg(index)
69
function test_0_documentCreate () {
70
compare(myDatabase.getDoc(otherDocument.docId), otherDocument.defaults)
73
function test_1_databasePopulated () {
74
spyListCompleted.wait()
75
compare(myDatabase.putDoc({"animals": ["cat", "dog", "hamster"]}) > -1, true)
77
var myPath = "aDatabaseA"
78
myDatabase.path = myPath
80
compare(myDatabase.path, myPath)
81
compare(myDatabase.putDoc({"spam": "eggs"}) > -1, true)
82
var json = {"foo": "bar"}
83
compare(myDatabase.putDoc(json, "hijklmn") > -1, true)
84
compare(myDatabase.getDoc("hijklmn"), json)
85
compare(myDatabase.getDoc("hijklmn"), json)
88
function test_2_databaseError () {
89
/* FIXME: unicode in Qt console output doesn't work inside dpkg
90
ignoreWarning('u1db: Invalid docID 日本語')
91
myDatabase.putDoc({"": ""}, "日本語")
92
spyErrorChanged.wait()
93
compare(myDatabase.error.indexOf("Invalid docID") > -1, true)
97
function test_3_documentContents () {
98
var json = {"content": {"notetext": "Lorem ipsum"}}
99
myDatabase.putDoc(json, "qwertzui")
100
myDocument.docId = ''
101
compare(myDocument.contents, undefined)
102
myDocument.docId = 'qwertzui'
103
compare(myDocument.contents, json)
104
compare(myDocument.contents.content.notetext, 'Lorem ipsum')
106
var path = myDatabase.path
107
myDatabase.path = ':memory:'
108
myDatabase.path = path
109
spyContentsChanged.wait()
112
function test_4_putIndex () {
113
myDatabase.putIndex("by-phone-number", ["managers.phone_number"])
114
compare(myDatabase.getIndexExpressions('by-phone-number'), ["managers.phone_number"])
115
myDatabase.putDoc({ 'managers': [
116
{ 'name': 'Mary', 'phone_number': '12345' },
117
{ 'name': 'Rob', 'phone_number': '54321' },
119
// FIXME compare(myDatabase.getIndexKeys('by-phone-number'), ['12345', '54321'])
122
function test_6_fillDocument () {
123
var path = "aDatabaseC"
124
myDatabase.path = path
125
spyPathChanged.wait()
126
for (var i = 0; i < 100; i++)
127
myDatabase.putDoc({'foo': 'bar'} ,'dl' + Number(i).toLocaleString())
128
myDatabase.path = ":memory:"
129
spyPathChanged.wait()
130
compare(myDatabase.listDocs(), [])
131
compare(myList.count, 0)
132
myDatabase.first_row_loaded = false
133
myDatabase.last_row_loaded = false
134
myDatabase.path = path
135
spyPathChanged.wait()
136
compare(myList.count, 100)
138
// FIXME compare(myDatabase.first_row_loaded, true)
139
// FIXME compare(myDatabase.last_row_loaded, false)
145
signalName: "pathChanged"
149
id: spyContentsChanged
151
signalName: "contentsChanged"
157
signalName: "errorChanged"
162
target: myDatabase.Component
163
signalName: "completed"
169
signalName: "docLoaded"