~ubuntu-branches/ubuntu/quantal/kde-runtime/quantal

« back to all changes in this revision

Viewing changes to nepomuk/services/storage/test/removablemediamodeltest.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-06-03 21:50:00 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20120603215000-vn7oarsq0ynrydj5
Tags: upstream-4.8.80
Import upstream version 4.8.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
   This file is part of the Nepomuk KDE project.
3
 
   Copyright (C) 2011 Sebastian Trueg <trueg@kde.org>
4
 
 
5
 
   This library is free software; you can redistribute it and/or
6
 
   modify it under the terms of the GNU Lesser General Public
7
 
   License as published by the Free Software Foundation; either
8
 
   version 2.1 of the License, or (at your option) version 3, or any
9
 
   later version accepted by the membership of KDE e.V. (or its
10
 
   successor approved by the membership of KDE e.V.), which shall
11
 
   act as a proxy defined in Section 6 of version 3 of the license.
12
 
 
13
 
   This library is distributed in the hope that it will be useful,
14
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
   Lesser General Public License for more details.
17
 
 
18
 
   You should have received a copy of the GNU Lesser General Public
19
 
   License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 
*/
21
 
 
22
 
#include "removablemediamodeltest.h"
23
 
#ifdef __GNUC__
24
 
#define private public
25
 
#endif
26
 
#include "../removablemediamodel.h"
27
 
#ifdef __GNUC__
28
 
#undef private
29
 
#endif
30
 
 
31
 
#include <QtTest>
32
 
#include "qtest_kde.h"
33
 
#include "qtest_dms.h"
34
 
 
35
 
#include <QtDBus>
36
 
#include <Soprano/Soprano>
37
 
#include <KDebug>
38
 
 
39
 
#include <Solid/DeviceNotifier>
40
 
#include <Solid/DeviceInterface>
41
 
#include <Solid/Block>
42
 
#include <Solid/Device>
43
 
#include <Solid/StorageDrive>
44
 
#include <Solid/StorageVolume>
45
 
#include <Solid/StorageAccess>
46
 
#include <Solid/Predicate>
47
 
 
48
 
#include <Nepomuk/Vocabulary/NIE>
49
 
 
50
 
#ifndef FAKE_COMPUTER_XML
51
 
    #error "FAKE_COMPUTER_XML not set. An XML file describing a computer is required for this test"
52
 
#endif
53
 
 
54
 
#define SOLID_FAKEHW_SERVICE QDBusConnection::sessionBus().baseService()
55
 
#define SOLID_FAKEHW_PATH "/org/kde/solid/fakehw"
56
 
#define SOLID_FAKEHW_INTERFACE "local.qttest.Solid.Backends.Fake.FakeManager"
57
 
 
58
 
// TODO: also test mounting a different device to the same mount path
59
 
 
60
 
using namespace Nepomuk;
61
 
using namespace Nepomuk::Vocabulary;
62
 
using namespace Soprano;
63
 
 
64
 
Q_DECLARE_METATYPE(Soprano::Node)
65
 
Q_DECLARE_METATYPE(Soprano::Statement)
66
 
 
67
 
 
68
 
namespace {
69
 
/// Plug a device in the fake Solid hw manager.
70
 
void plugDevice(const QString& udi) {
71
 
    QDBusInterface(SOLID_FAKEHW_SERVICE, SOLID_FAKEHW_PATH, SOLID_FAKEHW_INTERFACE, QDBusConnection::sessionBus())
72
 
            .call(QLatin1String("plug"), udi);
73
 
}
74
 
 
75
 
/// Unplug a device in the fake Solid hw manager.
76
 
void unplugDevice(const QString& udi) {
77
 
    QDBusInterface(SOLID_FAKEHW_SERVICE, SOLID_FAKEHW_PATH, SOLID_FAKEHW_INTERFACE, QDBusConnection::sessionBus())
78
 
            .call(QLatin1String("unplug"), udi);
79
 
}
80
 
 
81
 
const char* s_udiXyz123 = "/org/kde/solid/fakehw/volume_part1_size_993284096";
82
 
}
83
 
 
84
 
void RemovableMediaModelTest::initTestCase()
85
 
{
86
 
    // make sure Solid uses the fake manager
87
 
    setenv("SOLID_FAKEHW", FAKE_COMPUTER_XML, 1);
88
 
 
89
 
    // we simply need some memory model for now - nothing fancy
90
 
    m_model = Soprano::createModel();
91
 
    m_model->setParent(this);
92
 
    m_rmModel = new RemovableMediaModel(m_model, this);
93
 
}
94
 
 
95
 
 
96
 
void RemovableMediaModelTest::testConvertFileUrlsInStatement_data()
97
 
{
98
 
    QTest::addColumn<Statement>( "original" );
99
 
    QTest::addColumn<Statement>( "converted" );
100
 
 
101
 
    const Statement randomStatement(QUrl("nepomuk:/res/xyz"), QUrl("onto:someProp"), LiteralValue("foobar"));
102
 
    QTest::newRow("noFileUrls") << randomStatement << randomStatement;
103
 
 
104
 
    const Statement randomFileSubject(QUrl("file:///tmp/test"), QUrl("onto:someProp"), LiteralValue("foobar"));
105
 
    QTest::newRow("randomFileUrlInSubject") << randomFileSubject << randomFileSubject;
106
 
 
107
 
    const Statement convertableFileSubject(QUrl("file:///media/XO-Y4/test.txt"), QUrl("onto:someProp"), LiteralValue("foobar"));
108
 
    QTest::newRow("convertableFileUrlInSubject") << convertableFileSubject << convertableFileSubject;
109
 
 
110
 
    const Statement convertableFileObjectWithoutNieUrl(QUrl("nepomuk:/res/xyz"), QUrl("onto:someProp"), QUrl("file:///media/XO-Y4/test.txt"));
111
 
    QTest::newRow("convertableFileUrlInObjectWithoutNieUrl") << convertableFileObjectWithoutNieUrl << convertableFileObjectWithoutNieUrl;
112
 
 
113
 
    const Statement convertableFileObjectWithNieUrl1_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/XO-Y4/test.txt"));
114
 
    const Statement convertableFileObjectWithNieUrl1_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("filex://xyz-123/test.txt"));
115
 
    QTest::newRow("convertableFileUrlInObjectWithNieUrl1") << convertableFileObjectWithNieUrl1_original << convertableFileObjectWithNieUrl1_converted;
116
 
 
117
 
    const Statement convertableFileObjectWithNieUrl2_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/XO-Y4"));
118
 
    const Statement convertableFileObjectWithNieUrl2_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("filex://xyz-123"));
119
 
    QTest::newRow("convertableFileUrlInObjectWithNieUrl2") << convertableFileObjectWithNieUrl2_original << convertableFileObjectWithNieUrl2_converted;
120
 
 
121
 
    const Statement convertableFileObjectWithNieUrl3_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/nfs/test.txt"));
122
 
    const Statement convertableFileObjectWithNieUrl3_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("nfs://thehost/solid-path/test.txt"));
123
 
    QTest::newRow("convertableFileUrlInObjectWithNieUrl3") << convertableFileObjectWithNieUrl3_original << convertableFileObjectWithNieUrl3_converted;
124
 
 
125
 
    const Statement convertableFileObjectWithNieUrl4_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/nfs"));
126
 
    const Statement convertableFileObjectWithNieUrl4_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("nfs://thehost/solid-path"));
127
 
    QTest::newRow("convertableFileUrlInObjectWithNieUrl4") << convertableFileObjectWithNieUrl4_original << convertableFileObjectWithNieUrl4_converted;
128
 
 
129
 
    const Statement convertableFileObjectWithNieUrl5_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/XO-Y4/file with spaces.txt"));
130
 
    const Statement convertableFileObjectWithNieUrl5_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("filex://xyz-123/file with spaces.txt"));
131
 
    QTest::newRow("convertableFileUrlInObjectWithNieUrl5") << convertableFileObjectWithNieUrl5_original << convertableFileObjectWithNieUrl5_converted;
132
 
 
133
 
    const Statement convertableFileObjectWithNieUrl6_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/whatever with spaces/file with spaces.txt"));
134
 
    const Statement convertableFileObjectWithNieUrl6_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("filex://whatever/file with spaces.txt"));
135
 
    QTest::newRow("convertableFileUrlInObjectWithNieUrl6") << convertableFileObjectWithNieUrl6_original << convertableFileObjectWithNieUrl6_converted;
136
 
 
137
 
    const Statement convertableFileObjectWithNieUrl7_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/dvd/file with spaces.txt"));
138
 
    const Statement convertableFileObjectWithNieUrl7_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("optical://SOLIDMAN_BEGINS/file with spaces.txt"));
139
 
    QTest::newRow("convertableFileUrlInObjectWithNieUrl7") << convertableFileObjectWithNieUrl7_original << convertableFileObjectWithNieUrl7_converted;
140
 
}
141
 
 
142
 
 
143
 
void RemovableMediaModelTest::testConvertFileUrlsInStatement()
144
 
{
145
 
    QFETCH(Statement, original);
146
 
    QFETCH(Statement, converted);
147
 
 
148
 
    QCOMPARE(m_rmModel->convertFileUrls(original), converted);
149
 
}
150
 
 
151
 
void RemovableMediaModelTest::testConvertFileUrlsInQuery_data()
152
 
{
153
 
    QTest::addColumn<QString>( "original" );
154
 
    QTest::addColumn<QString>( "converted" );
155
 
 
156
 
    QString query = QString::fromLatin1("select ?r where { ?r ?p <file:///media/foobar/test.txt> . }");
157
 
    QTest::newRow("queryWithNonConvertableFileUrl") << query << query;
158
 
 
159
 
    QTest::newRow("queryWithConvertableFileUrl1")
160
 
            << QString::fromLatin1("select ?r where { ?r ?p <file:///media/XO-Y4/test.txt> . }")
161
 
            << QString::fromLatin1("select ?r where { ?r ?p <filex://xyz-123/test.txt> . }");
162
 
 
163
 
    QTest::newRow("queryWithConvertableFileUrl1WeirdFormatting")
164
 
            << QString::fromLatin1("select ?r where { ?r ?p      <file:///media/XO-Y4/test.txt>      . }")
165
 
            << QString::fromLatin1("select ?r where { ?r ?p      <filex://xyz-123/test.txt>      . }");
166
 
 
167
 
    QTest::newRow("queryWithConvertableFileUrl2")
168
 
            << QString::fromLatin1("select ?r where { ?r ?p <file:///media/nfs/test.txt> . }")
169
 
            << QString::fromLatin1("select ?r where { ?r ?p <nfs://thehost/solid-path/test.txt> . }");
170
 
 
171
 
    QTest::newRow("queryWithConvertableRegex1")
172
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . FILTER(REGEX(?u, '^file:///media/XO-Y4/test')) . }")
173
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . FILTER(REGEX(?u, '^filex://xyz-123/test')) . }");
174
 
 
175
 
    QTest::newRow("queryWithConvertableRegex1WithWeirdFormatting")
176
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . filter(reGEx(  STR(?u)  ,  'file:///media/XO-Y4/test'  ) ) . }")
177
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . filter(reGEx(  STR(?u)  ,  'filex://xyz-123/test'  ) ) . }");
178
 
 
179
 
    QTest::newRow("queryWithConvertableRegex2")
180
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . FILTER(REGEX(?u, '^file:///media/nfs/')) . }")
181
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . FILTER(REGEX(?u, '^nfs://thehost/solid-path/')) . }");
182
 
 
183
 
    QTest::newRow("queryWithConvertableRegex3")
184
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . FILTER(REGEX(?u, '''^file:///media/nfs/''')) . }")
185
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . FILTER(REGEX(?u, '''^nfs://thehost/solid-path/''')) . }");
186
 
 
187
 
    // looking for anything in /media includes files from any storage mounted somewhere under /media
188
 
    QTest::newRow("queryWithConvertableRegex4")
189
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . FILTER(REGEX(?u, '^file:///media')) . }")
190
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . "
191
 
                                   "FILTER(("
192
 
                                   "REGEX(?u, '^file:///media') || "
193
 
                                   "REGEX(?u, '^optical://solidman_begins/') || "
194
 
                                   "REGEX(?u, '^filex://whatever/') || "
195
 
                                   "REGEX(?u, '^nfs://thehost/solid-path/') || "
196
 
                                   "REGEX(?u, '^filex://xyz-123/'))"
197
 
                                   ") . }");
198
 
 
199
 
    QTest::newRow("queryWithConvertableRegex4WithWeirdFormatting")
200
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . filter   (  reGEX(  str( ?u)  , '^file:///media'  ) ) . }")
201
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . "
202
 
                                   "filter   (  ("
203
 
                                   "REGEX(str( ?u), '^file:///media') || "
204
 
                                   "REGEX(str( ?u), '^optical://solidman_begins/') || "
205
 
                                   "REGEX(str( ?u), '^filex://whatever/') || "
206
 
                                   "REGEX(str( ?u), '^nfs://thehost/solid-path/') || "
207
 
                                   "REGEX(str( ?u), '^filex://xyz-123/'))"
208
 
                                   " ) . }");
209
 
 
210
 
    QTest::newRow("queryWithConvertableRegex4")
211
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . FILTER(REGEX(?u, '^file:///media/nfs')) . }")
212
 
            << QString::fromLatin1("select ?r where { ?r nie:url ?u . FILTER((REGEX(?u, '^file:///media/nfs') || REGEX(?u, '^nfs://thehost/solid-path/'))) . }");
213
 
 
214
 
    QTest::newRow("queryWithNotReallyAFileUrl")
215
 
            << QString::fromLatin1("select ?r where { ?r ?p ?u . FILTER(REGEX(?u, 'ffile:///media/nfs/')) . }")
216
 
            << QString::fromLatin1("select ?r where { ?r ?p ?u . FILTER(REGEX(?u, 'ffile:///media/nfs/')) . }");
217
 
}
218
 
 
219
 
void RemovableMediaModelTest::testConvertFileUrlsInQuery()
220
 
{
221
 
    QFETCH(QString, original);
222
 
    QFETCH(QString, converted);
223
 
 
224
 
    QCOMPARE(m_rmModel->convertFileUrls(original), converted);
225
 
}
226
 
 
227
 
void RemovableMediaModelTest::testConvertFilxUrl_data()
228
 
{
229
 
    QTest::addColumn<Node>( "original" );
230
 
    QTest::addColumn<Node>( "converted" );
231
 
 
232
 
    const Node nothingToConvertFilex(QUrl("filex://abc-789/hello/world"));
233
 
    QTest::newRow("nothingToConvertFilex") << nothingToConvertFilex << nothingToConvertFilex;
234
 
 
235
 
    const Node convertFilex1(QUrl("filex://xyz-123/hello/world"));
236
 
    QTest::newRow("convertFilex1") << convertFilex1 << Node(QUrl("file:///media/XO-Y4/hello/world"));
237
 
 
238
 
    const Node convertFilex2(QUrl("filex://xyz-123"));
239
 
    QTest::newRow("convertFilex2") << convertFilex2 << Node(QUrl("file:///media/XO-Y4"));
240
 
 
241
 
    const Node convertFilex3(QUrl("filex://xyz-123/hello world"));
242
 
    QTest::newRow("convertFilex3") << convertFilex3 << Node(QUrl("file:///media/XO-Y4/hello world"));
243
 
 
244
 
    const Node convertFilex4(QUrl("filex://whatever/hello world"));
245
 
    QTest::newRow("convertFilex4") << convertFilex4 << Node(QUrl("file:///media/whatever with spaces/hello world"));
246
 
 
247
 
    const Node convertnfs(QUrl("nfs://thehost/solid-path"));
248
 
    QTest::newRow("convertnfs") << convertnfs << Node(QUrl("file:///media/nfs"));
249
 
 
250
 
    const Node convertOptical1(QUrl("optical://SOLIDMAN_BEGINS"));
251
 
    QTest::newRow("convertOptical1") << convertOptical1 << Node(QUrl("file:///media/dvd"));
252
 
 
253
 
    const Node convertOptical2(QUrl("optical://SOLIDMAN_BEGINS/file with spaces.txt"));
254
 
    QTest::newRow("convertOptical2") << convertOptical2 << Node(QUrl("file:///media/dvd/file with spaces.txt"));
255
 
}
256
 
 
257
 
void RemovableMediaModelTest::testConvertFilxUrl()
258
 
{
259
 
    QFETCH(Node, original);
260
 
    QFETCH(Node, converted);
261
 
 
262
 
    QCOMPARE(m_rmModel->convertFilexUrl(original), converted);
263
 
}
264
 
 
265
 
void RemovableMediaModelTest::testConvertFilxUrls_data()
266
 
{
267
 
    QTest::addColumn<Statement>( "original" );
268
 
    QTest::addColumn<Statement>( "converted" );
269
 
 
270
 
    const Statement randomStatement(QUrl("nepomuk:/res/xyz"), QUrl("onto:someProp"), LiteralValue("foobar"));
271
 
    QTest::newRow("noFileUrls") << randomStatement << randomStatement;
272
 
 
273
 
    const Statement randomFilexSubject(QUrl("filex://123-123/tmp/test"), QUrl("onto:someProp"), LiteralValue("foobar"));
274
 
    QTest::newRow("randomFilexUrlInSubject") << randomFilexSubject << randomFilexSubject;
275
 
 
276
 
    const Statement convertableFilexSubject(QUrl("filex://xyz-123/test.txt"), QUrl("onto:someProp"), LiteralValue("foobar"));
277
 
    QTest::newRow("convertableFilexUrlInSubject") << convertableFilexSubject << convertableFilexSubject;
278
 
 
279
 
    const Statement convertableFilexObjectWithoutNieUrl(QUrl("nepomuk:/res/xyz"), QUrl("onto:someProp"), QUrl("filex://xyz-123/test.txt"));
280
 
    QTest::newRow("convertableFilexUrlInObjectWithoutNieUrl") << convertableFilexObjectWithoutNieUrl << convertableFilexObjectWithoutNieUrl;
281
 
 
282
 
    const Statement convertableFilexObjectWithNieUrl1_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("filex://xyz-123/test.txt"));
283
 
    const Statement convertableFilexObjectWithNieUrl1_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/XO-Y4/test.txt"));
284
 
    QTest::newRow("convertableFilexUrlInObjectWithNieUrl1") << convertableFilexObjectWithNieUrl1_original << convertableFilexObjectWithNieUrl1_converted;
285
 
 
286
 
    const Statement convertableFilexObjectWithNieUrl2_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("filex://xyz-123"));
287
 
    const Statement convertableFilexObjectWithNieUrl2_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/XO-Y4"));
288
 
    QTest::newRow("convertableFilexUrlInObjectWithNieUrl2") << convertableFilexObjectWithNieUrl2_original << convertableFilexObjectWithNieUrl2_converted;
289
 
 
290
 
    const Statement convertableFilexObjectWithNieUrl3_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("nfs://thehost/solid-path/test.txt"));
291
 
    const Statement convertableFilexObjectWithNieUrl3_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/nfs/test.txt"));
292
 
    QTest::newRow("convertableFileUrlInObjectWithNieUrl3") << convertableFilexObjectWithNieUrl3_original << convertableFilexObjectWithNieUrl3_converted;
293
 
 
294
 
    const Statement convertableFilexObjectWithNieUrl4_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("nfs://thehost/solid-path"));
295
 
    const Statement convertableFilexObjectWithNieUrl4_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/nfs"));
296
 
    QTest::newRow("convertableFileUrlInObjectWithNieUrl4") << convertableFilexObjectWithNieUrl4_original << convertableFilexObjectWithNieUrl4_converted;
297
 
 
298
 
    const Statement convertableFilexObjectWithNieUrl5_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("filex://xyz-123/file with spaces.txt"));
299
 
    const Statement convertableFilexObjectWithNieUrl5_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/XO-Y4/file with spaces.txt"));
300
 
    QTest::newRow("convertableFileUrlInObjectWithNieUrl5") << convertableFilexObjectWithNieUrl5_original << convertableFilexObjectWithNieUrl5_converted;
301
 
 
302
 
    const Statement convertableFileObjectWithNieUrl6_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("filex://whatever/file with spaces.txt"));
303
 
    const Statement convertableFileObjectWithNieUrl6_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/whatever with spaces/file with spaces.txt"));
304
 
    QTest::newRow("convertableFileUrlInObjectWithNieUrl6") << convertableFileObjectWithNieUrl6_original << convertableFileObjectWithNieUrl6_converted;
305
 
 
306
 
    const Statement convertableFileObjectWithNieUrl7_original(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("optical://SOLIDMAN_BEGINS/file with spaces.txt"));
307
 
    const Statement convertableFileObjectWithNieUrl7_converted(QUrl("nepomuk:/res/xyz"), NIE::url(), QUrl("file:///media/dvd/file with spaces.txt"));
308
 
    QTest::newRow("convertableFileUrlInObjectWithNieUrl7") << convertableFileObjectWithNieUrl7_original << convertableFileObjectWithNieUrl7_converted;
309
 
}
310
 
 
311
 
void RemovableMediaModelTest::testConvertFilxUrls()
312
 
{
313
 
    QFETCH(Statement, original);
314
 
    QFETCH(Statement, converted);
315
 
 
316
 
    QCOMPARE(m_rmModel->convertFilexUrls(original), converted);
317
 
}
318
 
 
319
 
void RemovableMediaModelTest::testConversionWithUnmount()
320
 
{
321
 
    KUrl fileXUrl("filex://xyz-123/hello/world");
322
 
    KUrl fileUrl("file:///media/XO-Y4/hello/world");
323
 
 
324
 
    // device mounted
325
 
    plugDevice(QLatin1String(s_udiXyz123));
326
 
 
327
 
    // conversion should work
328
 
    QCOMPARE(m_rmModel->convertFileUrl(fileUrl), Soprano::Node(fileXUrl));
329
 
    QCOMPARE(m_rmModel->convertFilexUrl(fileXUrl), Soprano::Node(fileUrl));
330
 
 
331
 
 
332
 
    // add some data to query
333
 
    m_rmModel->addStatement(QUrl("nepomuk:/res/foobar"), NIE::url(), fileUrl);
334
 
 
335
 
    // make sure it is converted when queried
336
 
    QCOMPARE(m_rmModel->listStatements(QUrl("nepomuk:/res/foobar"), NIE::url(), Soprano::Node()).allElements().count(), 1);
337
 
    QCOMPARE(m_rmModel->listStatements(QUrl("nepomuk:/res/foobar"), NIE::url(), Soprano::Node()).allElements().first().object(),
338
 
             Soprano::Node(fileUrl));
339
 
    QCOMPARE(m_rmModel->executeQuery(QString::fromLatin1("select ?u where { <nepomuk:/res/foobar> ?p ?u . }"),
340
 
                                     Soprano::Query::QueryLanguageSparql).iterateBindings(0).allElements().count(), 1);
341
 
    QCOMPARE(m_rmModel->executeQuery(QString::fromLatin1("select ?u where { <nepomuk:/res/foobar> ?p ?u . }"),
342
 
                                     Soprano::Query::QueryLanguageSparql).iterateBindings(0).allElements().first(),
343
 
             Soprano::Node(fileUrl));
344
 
 
345
 
 
346
 
    // unmount device
347
 
    unplugDevice(s_udiXyz123);
348
 
 
349
 
    // now conversion should do noting
350
 
    QCOMPARE(m_rmModel->convertFileUrl(fileUrl), Soprano::Node(fileUrl));
351
 
    QCOMPARE(m_rmModel->convertFilexUrl(fileXUrl), Soprano::Node(fileXUrl));
352
 
 
353
 
    // make sure nothing is converted anymore
354
 
    QCOMPARE(m_rmModel->listStatements(QUrl("nepomuk:/res/foobar"), NIE::url(), Soprano::Node()).allElements().count(), 1);
355
 
    QCOMPARE(m_rmModel->listStatements(QUrl("nepomuk:/res/foobar"), NIE::url(), Soprano::Node()).allElements().first().object(),
356
 
             Soprano::Node(fileXUrl));
357
 
    QCOMPARE(m_rmModel->executeQuery(QString::fromLatin1("select ?u where { <nepomuk:/res/foobar> ?p ?u . }"),
358
 
                                     Soprano::Query::QueryLanguageSparql).iterateBindings(0).allElements().count(), 1);
359
 
    QCOMPARE(m_rmModel->executeQuery(QString::fromLatin1("select ?u where { <nepomuk:/res/foobar> ?p ?u . }"),
360
 
                                     Soprano::Query::QueryLanguageSparql).iterateBindings(0).allElements().first(),
361
 
             Soprano::Node(fileXUrl));
362
 
 
363
 
 
364
 
    // re-plug device for other tests
365
 
    plugDevice(QLatin1String(s_udiXyz123));
366
 
}
367
 
 
368
 
QTEST_KDEMAIN_CORE(RemovableMediaModelTest)
369
 
 
370
 
#include "removablemediamodeltest.moc"