~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to tests/auto/organizer/qmlorganizer/testcases/tst_organizercollectionfilter.qml

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the test suite of the Qt Toolkit.
 
7
**
 
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.
 
16
**
 
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.
 
24
**
 
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.
 
28
**
 
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.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
import QtQuick 2.0
 
43
import QtTest 1.0
 
44
import QtOrganizer 5.0
 
45
 
 
46
Rectangle {
 
47
    id: test;
 
48
 
 
49
    QOrganizerTestUtility {
 
50
        id: utility
 
51
    }
 
52
 
 
53
    Collection {
 
54
        id: testCollection
 
55
        name: 'My collection filter test'
 
56
        description: 'collection filter test'
 
57
    }
 
58
 
 
59
    TestCase {
 
60
        name: "Organizer collection filter test"
 
61
 
 
62
        function test_collectionFilter_data() {
 
63
            return [
 
64
                        { tag:  "properties",
 
65
                            code: "import QtOrganizer 5.0;CollectionFilter{}"
 
66
                        },
 
67
                    ]
 
68
        }
 
69
 
 
70
        function test_collectionFilter(data) {
 
71
 
 
72
            var list = utility.getManagerList();
 
73
            if (list.length < 0) {
 
74
                console.log("No manager to test");
 
75
                return;
 
76
            }
 
77
            //Test all manager backends
 
78
            for (var i = 0; i < list.length; i ++) {
 
79
                var managerName = list[i];
 
80
                var debugFlag = 0;
 
81
                console.log("test_collectionFilter test start! :" + managerName);
 
82
                var model = Qt.createQmlObject(
 
83
                        "import QtOrganizer 5.0;"
 
84
                        + "OrganizerModel {"
 
85
                        + "   manager: \"qtorganizer:" + managerName + ":id=qml\";"
 
86
                        + "   startPeriod:'2009-01-01';"
 
87
                        + "   endPeriod:'2012-12-31';"
 
88
                        + "   autoUpdate:true; }"
 
89
                        , test);
 
90
                utility.init(model);
 
91
                utility.waitModelChange();
 
92
                utility.empty_calendar();
 
93
 
 
94
                var collectionFilter = Qt.createQmlObject(data.code, test);
 
95
 
 
96
                var event = Qt.createQmlObject(
 
97
                        "import QtOrganizer 5.0;"
 
98
                        + "Event { "
 
99
                        + "   displayLabel: \"organizer collection filter test event\"; "
 
100
                        + "   description: \"organizer collection filter test event\"; "
 
101
                        + "   startDateTime: '2010-12-12'; "
 
102
                        + "   endDateTime: '2010-12-13'; }"
 
103
                        , test);
 
104
 
 
105
                //------Create and save the detail test------//
 
106
                var collectionLength = model.collections.length;
 
107
                model.saveCollection(testCollection)
 
108
 
 
109
                //Let's wait for the model to be up-to-date
 
110
                utility.waitModelChange(collectionLength + 1, utility.collectionChange);
 
111
 
 
112
                //we should have more than default collection now
 
113
                utility.debug("New collection length :" + model.collections.length, debugFlag);
 
114
                var savedCollection = model.collections[model.collections.length - 1];
 
115
                utility.debug("New collection id :" + savedCollection.collectionId, debugFlag);
 
116
                event.collectionId = savedCollection.collectionId;
 
117
                model.saveItem(event);
 
118
                utility.waitModelChange(1, utility.itemChange);
 
119
 
 
120
                var fetchlist = model.items;
 
121
                compare(model.itemCount, 1)
 
122
                var savedEvent = fetchlist[0];
 
123
                utility.debug("New event collection id :" + savedEvent.collectionId, debugFlag);
 
124
                compare(savedEvent.collectionId, event.collectionId);
 
125
 
 
126
                //Change collection filter id
 
127
                collectionFilter.ids = [event.collectionId];
 
128
                model.filter = collectionFilter;
 
129
                utility.waitModelChange(1);
 
130
                compare(model.itemCount, 1)
 
131
 
 
132
                //default collection
 
133
                utility.debug("default collection id :" + model.defaultCollection().collectionId, debugFlag);
 
134
                var modelCollectionFilter = model.filter;
 
135
                modelCollectionFilter.ids = [model.defaultCollection().collectionId];
 
136
                utility.waitModelChange(0);
 
137
 
 
138
                compare(model.itemCount, 0)
 
139
                //save event to default collection
 
140
                event.collectionId = model.defaultCollection().collectionId;
 
141
                model.saveItem(event);
 
142
                utility.waitModelChange(1);
 
143
 
 
144
                //empty ides:
 
145
                modelCollectionFilter.ids = [];
 
146
                utility.waitModelChange(0);
 
147
                compare(model.itemCount, 0)
 
148
 
 
149
                //remove collection filter or set empty filter
 
150
                model.filter = null;
 
151
                utility.waitModelChange(2);
 
152
                compare(model.itemCount, 2);
 
153
 
 
154
                //reset back filter
 
155
                collectionFilter = Qt.createQmlObject(data.code, test);
 
156
                collectionFilter.ids = [event.collectionId];
 
157
                model.filter = collectionFilter;
 
158
                utility.waitModelChange(1);
 
159
                compare(model.itemCount, 1);
 
160
 
 
161
                //set more collection ids
 
162
                modelCollectionFilter = model.filter
 
163
                modelCollectionFilter.ids = [model.defaultCollection().collectionId, savedCollection.collectionId];
 
164
                utility.waitModelChange(2);
 
165
                compare(model.itemCount, 2);
 
166
 
 
167
                //One invalid collection id
 
168
                modelCollectionFilter.ids = [model.defaultCollection().collectionId, "12345666666",savedCollection.collectionId];
 
169
                utility.waitModelChange(2);
 
170
                compare(model.itemCount, 2);
 
171
 
 
172
                utility.empty_calendar();
 
173
            }
 
174
        }
 
175
    }
 
176
}