~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to tests/auto/organizer/qmlorganizer/testcases/tst_organizerunionfilter.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'
 
56
        description: 'unionFilter test'
 
57
    }
 
58
    CollectionFilter {
 
59
        id: collectionFilter
 
60
    }
 
61
    IdFilter {
 
62
        id: idFilter
 
63
    }
 
64
 
 
65
    TestCase {
 
66
        name: "Organizer union filter test"
 
67
        function test_unionFilter_data() {
 
68
            return [
 
69
                        { tag:  "properties",
 
70
                            code: "import QtOrganizer 5.0;"
 
71
                                  + "UnionFilter{\n"
 
72
                                  + "    id:unionFilter"
 
73
                                  + "}\n"
 
74
                        },
 
75
                    ]
 
76
        }
 
77
 
 
78
        function test_unionFilter(data) {
 
79
            var list = utility.getManagerList();
 
80
            if (list.length < 0) {
 
81
                console.log("No manager to test");
 
82
                return;
 
83
            }
 
84
            //Test all manager backends
 
85
            for (var i = 0; i < list.length; i ++) {
 
86
                var managerName = list[i];
 
87
                var debugFlag = 0;
 
88
                console.log("test_unionFilter test start! :" + managerName);
 
89
                var model = Qt.createQmlObject(
 
90
                        "import QtOrganizer 5.0;"
 
91
                        + "OrganizerModel {"
 
92
                        + "   manager: \"qtorganizer:" + managerName + ":id=qml\";"
 
93
                        + "   startPeriod:'2009-01-01';"
 
94
                        + "   endPeriod:'2012-12-31';"
 
95
                        + "   autoUpdate:true; }"
 
96
                        , test);
 
97
 
 
98
                var unionFilter = Qt.createQmlObject(data.code, test);
 
99
 
 
100
                var event = Qt.createQmlObject(
 
101
                        "import QtOrganizer 5.0;"
 
102
                        + "Event { "
 
103
                        + "   id:event;"
 
104
                        + "   displayLabel: \"organizer union filter test event\"; "
 
105
                        + "   description: \"organizer union filter test event\"; "
 
106
                        + "   startDateTime: '2010-12-12'; "
 
107
                        + "   endDateTime: '2010-12-13'; }"
 
108
                        , test);
 
109
 
 
110
                utility.init(model);
 
111
                utility.waitModelChange();
 
112
                utility.empty_calendar();
 
113
                //------prepare filter data: save event and collection------//
 
114
                var collectionLegnth = model.collections.length
 
115
 
 
116
                model.saveCollection(testCollection)
 
117
                //Let's wait for the model to be up-to-date
 
118
                utility.waitModelChange(collectionLegnth + 1, utility.collectionChange);
 
119
 
 
120
                //we should have more than default collection now
 
121
                var savedCollection = model.collections[model.collections.length - 1];
 
122
                model.saveItem(event);
 
123
                utility.waitModelChange(1);
 
124
                compare(model.itemCount, 1)
 
125
 
 
126
                //event with new collection id
 
127
                event.collectionId = savedCollection.collectionId;
 
128
                model.saveItem(event);
 
129
                utility.waitModelChange(2);
 
130
                compare(model.itemCount, 2)
 
131
 
 
132
                var fetchlist = model.items;
 
133
                var idEventId;
 
134
                var collectionEventId;
 
135
                if (fetchlist[1].collectionId == savedCollection.collectionId) {
 
136
                    idEventId = fetchlist[0].itemId;
 
137
                    collectionEventId = fetchlist[1].itemId;
 
138
                } else if (fetchlist[0].collectionId == savedCollection.collectionId) {
 
139
                    idEventId = fetchlist[1].itemId;
 
140
                    collectionEventId = fetchlist[0].itemId;
 
141
                } else {
 
142
                    console.log("Something Wrong!");
 
143
                }
 
144
 
 
145
                utility.debug("Single filter", debugFlag);
 
146
                idFilter.ids = [idEventId];
 
147
                //Single filter
 
148
                unionFilter.filters = [idFilter];
 
149
                model.filter = unionFilter;
 
150
                utility.waitModelChange(1);
 
151
 
 
152
                compare(model.itemCount, 1)
 
153
                //Change collection filter id
 
154
                collectionFilter.ids = [savedCollection.collectionId];
 
155
                //Duoble filters
 
156
                model.filter.filters = [idFilter, collectionFilter]
 
157
                utility.debug("Duoble filter", debugFlag);
 
158
                utility.waitModelChange(2);
 
159
                compare(model.itemCount, 2)
 
160
 
 
161
                //Double filter 2
 
162
                //Change collection filter id
 
163
                collectionFilter.ids = [savedCollection.collectionId, model.defaultCollection().collectionId];
 
164
                model.filter.filters = [idFilter, collectionFilter]
 
165
                utility.debug("Duoble filter 2", debugFlag);
 
166
                utility.waitModelChange(2);
 
167
                compare(model.itemCount, 2)
 
168
 
 
169
                //Double filter 3
 
170
                //Change collection filter id
 
171
                collectionFilter.ids = [savedCollection.collectionId, model.defaultCollection().collectionId];
 
172
                idFilter.ids = [idEventId, collectionEventId];
 
173
                utility.debug("Duoble filter ~3", debugFlag);
 
174
                model.filter.filters = [idFilter, collectionFilter]
 
175
                utility.debug("Duoble filter 3" + collectionFilter.ids, debugFlag);
 
176
                utility.waitModelChange(2);
 
177
                compare(model.itemCount, 2)
 
178
                utility.debug("Test over!", debugFlag);
 
179
 
 
180
                utility.empty_calendar();
 
181
            }
 
182
        }
 
183
    }
 
184
}