91
94
file.write(contents.toUtf8());
97
void OnlineAccountsHooksTest::writeInstalledFile(const QString &name,
98
const QString &contents)
100
QFileInfo fileInfo(name);
101
m_installDir.mkpath(fileInfo.path());
102
QFile file(m_installDir.filePath(name));
103
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
104
qWarning() << "Could not write file" << name;
108
file.write(contents.toUtf8());
94
111
void OnlineAccountsHooksTest::initTestCase()
96
113
qputenv("XDG_DATA_HOME", TEST_DIR);
223
240
QCOMPARE(profileElement.text(), profile);
243
void OnlineAccountsHooksTest::testRemoval()
248
QString stillInstalled("applications/com.ubuntu.test_StillInstalled.application");
249
writeInstalledFile(stillInstalled,
250
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
252
" <description>My application</description>\n"
254
" <service-type>some type</service-type>\n"
255
" </service-types>\n"
256
" <profile>com-ubuntu.test_StillInstalled_2.0</profile>\n"
258
QVERIFY(m_installDir.exists(stillInstalled));
260
QString myApp("applications/com.ubuntu.test_MyApp.application");
261
writeInstalledFile(myApp,
262
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
264
" <description>My application</description>\n"
266
" <service-type>some type</service-type>\n"
267
" </service-types>\n"
268
" <profile>com-ubuntu.test_MyApp_3.0</profile>\n"
270
QVERIFY(m_installDir.exists(myApp));
272
QString noProfile("applications/com.ubuntu.test_NoProfile.application");
273
writeInstalledFile(noProfile,
274
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
276
" <description>My application</description>\n"
278
" <service-type>some type</service-type>\n"
279
" </service-types>\n"
281
QVERIFY(m_installDir.exists(noProfile));
283
writeHookFile("com-ubuntu.test_StillInstalled_2.0.application",
284
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
286
" <description>My application</description>\n"
288
" <service-type>some type</service-type>\n"
289
" </service-types>\n"
292
QVERIFY(runHookProcess());
294
QVERIFY(m_installDir.exists(stillInstalled));
295
QVERIFY(!m_installDir.exists(myApp));
296
QVERIFY(m_installDir.exists(noProfile));
299
void OnlineAccountsHooksTest::testUpdate()
304
writeHookFile("com-ubuntu.test_MyApp_1.0.application",
305
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
307
" <description>My application</description>\n"
309
" <service-type>some type</service-type>\n"
310
" </service-types>\n"
313
QVERIFY(runHookProcess());
315
QString installedName("applications/com-ubuntu.test_MyApp.application");
317
// check that the file has been created, and with the correct profile
318
QFile file(m_installDir.absoluteFilePath(installedName));
319
QVERIFY(file.open(QIODevice::ReadOnly));
321
// check that's a valid XML file
323
QVERIFY(doc.setContent(&file));
324
QDomElement root = doc.documentElement();
325
QCOMPARE(root.firstChildElement("profile").text(),
326
QString("com-ubuntu.test_MyApp_1.0"));
328
/* Now remove the hook file and write a newer version of it */
330
writeHookFile("com-ubuntu.test_MyApp_1.1.application",
331
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
333
" <description>My application</description>\n"
335
" <service-type>some type</service-type>\n"
336
" </service-types>\n"
339
QVERIFY(runHookProcess());
341
// check that the file has been updated with the correct profile
343
file.setFileName(m_installDir.absoluteFilePath(installedName));
344
QVERIFY(file.open(QIODevice::ReadOnly));
345
QVERIFY(doc.setContent(&file));
346
root = doc.documentElement();
347
QCOMPARE(root.firstChildElement("profile").text(),
348
QString("com-ubuntu.test_MyApp_1.1"));
226
351
QTEST_MAIN(OnlineAccountsHooksTest);
228
353
#include "tst_online_accounts_hooks.moc"