1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the Qt Mobility Components.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
48
property bool start: false
49
property SignalSpy contactsChangedSpy
50
property ContactModel contactModel
51
property Contact testContact
56
function waitForContactsChanged (expectedCount) {
57
contactsChangedSpy.wait();
58
compare (contactsChangedSpy.count, expectedCount)
61
function test_addAndRemoveDetails()
63
//TODO verify this test case when we remove dynamic properties from the Api
64
//currently removing details from the contact is not updated in contact model
65
//TODO add a test case to remove the same detail N times and remove a detail which doesnt exist etc...
66
var model = Qt.createQmlObject(
67
"import QtContacts 5.0;" +
68
"ContactModel {id:model;autoUpdate:true;onContactsChanged:{console.log(\"CONTACTS CHANGED!\")}}", testHelper);
69
var tmp = Qt.createQmlObject(
70
"import QtContacts 5.0;" +
71
"Contact {Name{}}", testHelper);
72
var spy2 = Qt.createQmlObject("import QtTest 1.0;" +"SignalSpy {id: theSpy;signalName: \"contactsChanged\";}", testHelper);
73
contactsChangedSpy = spy2;
74
contactsChangedSpy.target = model;
75
contactsChangedSpy.clear()
76
testHelper.model = model;
77
waitForContactsChanged (1)
78
testHelper.emptyContactsDb();
80
var phone = Qt.createQmlObject("import QtContacts 5.0;" +
81
"PhoneNumber {number: '99999999'}", testContact);
82
var nick = Qt.createQmlObject("import QtContacts 5.0;" +
83
"Nickname {nickname: 'jack'}", testContact);
84
var label = Qt.createQmlObject("import QtContacts 5.0;" +
85
"DisplayLabel {label: 'Alice In Wonderland'}", testContact);
86
var mail = Qt.createQmlObject("import QtContacts 5.0;" +
87
"EmailAddress {emailAddress: 'joe.john@ovi.com'}", testContact);
88
testContact.name.firstName = "Joe"
89
testContact.name.lastName = "John"
90
testContact.addDetail(phone)
91
testContact.addDetail(nick)
92
testContact.addDetail(label)
93
testContact.addDetail(mail)
94
contactsChangedSpy.clear()
95
model.saveContact(testContact)
96
waitForContactsChanged (1)
97
testContact = model.contacts[0]
98
compare(testContact.phoneNumber.number,"99999999")
99
compare(testContact.nickname.nickname,"jack")
100
compare(testContact.displayLabel.label,"Alice In Wonderland")
101
compare(testContact.email.emailAddress,"joe.john@ovi.com")
102
testContact.removeDetail(testContact.detail(ContactDetail.NickName));
103
testContact.removeDetail(testContact.detail(ContactDetail.DisplayLabel));
104
testContact.removeDetail(testContact.detail(ContactDetail.PhoneNumber));
105
testContact.removeDetail(testContact.detail(ContactDetail.Email));
106
contactsChangedSpy.clear()
107
model.saveContact(testContact)
108
waitForContactsChanged (1)
109
testContact = model.contacts[0]
110
verify(!testContact.detail(ContactDetail.NickName))
111
verify(!testContact.detail(ContactDetail.DisplayLabel))
112
verify(!testContact.detail(ContactDetail.PhoneNumber))
113
verify(!testContact.detail(ContactDetail.Email))
114
compare(model.contacts.length, 1)
115
testHelper.emptyContactsDb();
116
model.autoUpdate = false;
119
property Component component
120
property ContactsTestHelper testHelper
123
component = Qt.createComponent("ContactsTestHelper.qml");
124
testHelper = component.createObject(top);
125
if (testHelper == undefined)
126
console.log("Unable to load component from " + name + " error is ", component.errorString())
127
verify(testHelper != undefined, 'Unable to load component ' + name);
131
testHelper.destroy();
140
function test_contact() {
142
compare(contact.modified, false)
145
console.log("type is: " + contact.type)
146
compare(contact.type, Type.Contact) // Type is Contact and not Group
149
console.log("contactId is: " + JSON.stringify(contact.contactId) )
150
compare(contact.contactId, "qtcontacts:::")
153
console.log("manager is: " + JSON.stringify(contact.manager))
154
compare(contact.manager, "")
166
function test_contactAddDetail() {
168
contact2.addDetail(phoneNumber)
169
compare(contact2.phoneNumber.number, "99999999")
180
function test_contactUpdateDetail() {
181
// update existing Detail
182
contact3.phoneNumber.number = "88888"
183
compare(contact3.phoneNumber.number, "88888")
193
function test_contactRemoveDetail() {
194
// delete one existing Detail
195
contact4.removeDetail(phoneNumber4);
196
verify(!contact4.phoneNumber.number)