~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to tests/auto/contacts/qcontactjsondbstoragelocations/missingstoragelocations/nouserdatastorage/tst_nouserdatastorage.cpp

  • 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
// This module implements no userdata storage location related test data for
 
43
// a set of tests shared with other similar modules for cases of no system
 
44
// storage and no storages at all.
 
45
 
 
46
#include "tst_missingstorage.h"
 
47
 
 
48
Q_DECLARE_METATYPE(QContactAbstractRequest::StorageLocations)
 
49
Q_DECLARE_METATYPE(QContactManager::Error)
 
50
 
 
51
tst_StoragesLocationsMissing::tst_StoragesLocationsMissing()
 
52
{
 
53
    QString partitions_json = QFINDTESTDATA("partitions.json");
 
54
    QVERIFY2(!partitions_json.isEmpty(), "partitions.json file is missing");
 
55
    QVERIFY2(m_jsondbProcess.start(partitions_json), "Failed to start JsonDb process");
 
56
}
 
57
 
 
58
tst_StoragesLocationsMissing::~tst_StoragesLocationsMissing()
 
59
{
 
60
        m_jsondbProcess.terminate();
 
61
}
 
62
 
 
63
void tst_StoragesLocationsMissing::init()
 
64
{
 
65
    // Make sure all tests in this test case start with an empty system storage.
 
66
    QContactIdFetchRequest idFetchRequest;
 
67
    idFetchRequest.setManager(m_contactManager);
 
68
    idFetchRequest.setStorageLocations(QContactAbstractRequest::SystemStorage);
 
69
    idFetchRequest.start();
 
70
    idFetchRequest.waitForFinished();
 
71
    if (!idFetchRequest.ids().isEmpty()) {
 
72
        QContactRemoveRequest removeRequest;
 
73
        removeRequest.setManager(m_contactManager);
 
74
        removeRequest.setContactIds(idFetchRequest.ids());
 
75
        removeRequest.start();
 
76
        removeRequest.waitForFinished();
 
77
    }
 
78
}
 
79
 
 
80
void tst_StoragesLocationsMissing::fetchData()
 
81
{
 
82
    QTest::addColumn<int>("storageLocations");
 
83
    QTest::addColumn<QContactManager::Error>("expectedError");
 
84
 
 
85
    QTest::newRow("from user") << int(QContactAbstractRequest::UserDataStorage)
 
86
                               << QContactManager::InvalidStorageLocationError;
 
87
 
 
88
    QTest::newRow("from system") << int(QContactAbstractRequest::SystemStorage)
 
89
                                 << QContactManager::DoesNotExistError;
 
90
 
 
91
    QTest::newRow("from both") << int(QContactAbstractRequest::SystemStorage | QContactAbstractRequest::UserDataStorage)
 
92
                               << QContactManager::InvalidStorageLocationError;
 
93
 
 
94
    QTest::newRow("from invalid") << (0x8)
 
95
                                  << QContactManager::InvalidStorageLocationError;
 
96
 
 
97
    QTest::newRow("from invalid with user") << int(0x8 | QContactAbstractRequest::UserDataStorage)
 
98
                                            << QContactManager::InvalidStorageLocationError;
 
99
 
 
100
    QTest::newRow("from invalid with system") << int(0x8 | QContactAbstractRequest::SystemStorage)
 
101
                                              << QContactManager::InvalidStorageLocationError;
 
102
}
 
103
 
 
104
void tst_StoragesLocationsMissing::idData()
 
105
{
 
106
    QTest::addColumn<QString>("jsonId");
 
107
    QTest::addColumn<int>("storageLocation");
 
108
    QTest::addColumn<QContactManager::Error>("expectedError");
 
109
 
 
110
    QTest::newRow("from user") << QString("a096c227-fc6f-46ad-89b8-1883fb490a38")
 
111
                               << int(QContactAbstractRequest::UserDataStorage)
 
112
                               << QContactManager::InvalidStorageLocationError;
 
113
 
 
114
    QTest::newRow("from system") << QString("a096c227-fc6f-46ad-89b8-1883fb490a38")
 
115
                                 << int(QContactAbstractRequest::SystemStorage)
 
116
                                 << QContactManager::DoesNotExistError;
 
117
 
 
118
    QTest::newRow("from invalid") << QString("a096c227-fc6f-46ad-89b8-1883fb490a38")
 
119
                                  << (0x8)
 
120
                                  << QContactManager::InvalidStorageLocationError;
 
121
 
 
122
    QTest::newRow("with empty id") << QString()
 
123
                                   << (0x0)
 
124
                                   << QContactManager::InvalidStorageLocationError;
 
125
}
 
126
 
 
127
void tst_StoragesLocationsMissing::idsData()
 
128
{
 
129
    QTest::addColumn<QString>("jsonId");
 
130
    QTest::addColumn<int>("firstStorageLocation");
 
131
    QTest::addColumn<int>("secondStorageLocation");
 
132
    QTest::addColumn<QContactManager::Error>("expectedError");
 
133
 
 
134
    QTest::newRow("from user") << QString("a096c227-fc6f-46ad-89b8-1883fb490a38")
 
135
                               << int(QContactAbstractRequest::UserDataStorage)
 
136
                               << int(QContactAbstractRequest::UserDataStorage)
 
137
                               << QContactManager::InvalidStorageLocationError;
 
138
 
 
139
 
 
140
    QTest::newRow("from system") << QString("a096c227-fc6f-46ad-89b8-1883fb490a38")
 
141
                                 << int(QContactAbstractRequest::SystemStorage)
 
142
                                 << int(QContactAbstractRequest::SystemStorage)
 
143
                                 << QContactManager::DoesNotExistError;
 
144
 
 
145
    QTest::newRow("from user and system") << QString("a096c227-fc6f-46ad-89b8-1883fb490a38")
 
146
                               << int(QContactAbstractRequest::UserDataStorage)
 
147
                               << int(QContactAbstractRequest::SystemStorage)
 
148
                               << QContactManager::InvalidStorageLocationError;
 
149
 
 
150
    QTest::newRow("from invalid with user") << QString("a096c227-fc6f-46ad-89b8-1883fb490a38")
 
151
                                  << (0x8)
 
152
                                  << int(QContactAbstractRequest::UserDataStorage)
 
153
                                  << QContactManager::InvalidStorageLocationError;
 
154
 
 
155
    QTest::newRow("from invalid with system") << QString("a096c227-fc6f-46ad-89b8-1883fb490a38")
 
156
                                  << (0x8)
 
157
                                  << int(QContactAbstractRequest::SystemStorage)
 
158
                                  << QContactManager::InvalidStorageLocationError;
 
159
 
 
160
    QTest::newRow("from user and system with an empty id") << QString()
 
161
                                  << int(QContactAbstractRequest::UserDataStorage)
 
162
                                  << int(QContactAbstractRequest::SystemStorage)
 
163
                                  << QContactManager::InvalidStorageLocationError;
 
164
}
 
165
 
 
166
void tst_StoragesLocationsMissing::saveData()
 
167
{
 
168
    QTest::addColumn<int>("storageLocation");
 
169
    QTest::addColumn<QContactManager::Error>("expectedError");
 
170
 
 
171
    QTest::newRow("to user") << int(QContactAbstractRequest::UserDataStorage)
 
172
                             << QContactManager::InvalidStorageLocationError;
 
173
 
 
174
    QTest::newRow("to system") << int(QContactAbstractRequest::SystemStorage)
 
175
                               << QContactManager::NoError;
 
176
 
 
177
    QTest::newRow("to invalid") << (0x8)
 
178
                                << QContactManager::InvalidStorageLocationError;
 
179
}
 
180
 
 
181