~mardy/ubuntu-system-settings-online-accounts/handle-errors-1349975

« back to all changes in this revision

Viewing changes to tests/click-hooks/tst_online_accounts_hooks.cpp

  • Committer: Alberto Mardegan
  • Date: 2015-10-29 15:45:25 UTC
  • mfrom: (295.1.6 trunk)
  • Revision ID: alberto.mardegan@canonical.com-20151029154525-f6obiia8r9zg79nl
Merge trunk

[ Alberto Mardegan ]
* Regenerate hooks whenever file time changes (LP: #1510640)
[ CI Train Bot ]
* Resync trunk. added: po/hi.po
[ Alberto Mardegan ]
* Simplify hooks, load v2api library added: click-hooks/accounts.cpp
  click-hooks/accounts.hook.in click-hooks/acl-updater.cpp click-
  hooks/acl-updater.h click-hooks/click-hooks.pro click-hooks/online-
  accounts-hooks2.pro online-accounts-
  service/com.ubuntu.OnlineAccounts.Manager.service.in tests/click-
  hooks/click-hooks.pro tests/click-hooks/fake_signond.h tests/click-
  hooks/signond.py tests/click-hooks/tst_online_accounts_hooks2.cpp
  tests/click-hooks/tst_online_accounts_hooks2.pro renamed: click-
  hooks/click-hooks.pro => click-hooks/online-accounts-hooks.pro
  tests/click-hooks/click-hooks.pro => tests/click-
  hooks/tst_online_accounts_hooks.pro
[ CI Train Bot ]
* Resync trunk. added: po/mr.po po/th.po

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <QProcess>
29
29
#include <QSignalSpy>
30
30
#include <QTest>
 
31
#include <sys/types.h>
 
32
#include <time.h>
 
33
#include <utime.h>
31
34
 
32
35
#define TEST_DIR "/tmp/hooks-test"
33
36
 
334
337
    QString stillInstalled("applications/com.ubuntu.test_StillInstalled.application");
335
338
    writeInstalledFile(stillInstalled,
336
339
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 
340
        "<!--this file is auto-generated by online-accounts-hooks; do not modify-->\n"
337
341
        "<application>\n"
338
342
        "  <description>My application</description>\n"
339
343
        "  <service-types>\n"
346
350
    QString myApp("applications/com.ubuntu.test_MyApp.application");
347
351
    writeInstalledFile(myApp,
348
352
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 
353
        "<!--this file is auto-generated by online-accounts-hooks; do not modify-->\n"
349
354
        "<application>\n"
350
355
        "  <description>My application</description>\n"
351
356
        "  <service-types>\n"
366
371
        "</application>");
367
372
    QVERIFY(m_installDir.exists(noProfile));
368
373
 
 
374
    QString notOurs("applications/com.ubuntu.test_NotOurs.application");
 
375
    writeInstalledFile(notOurs,
 
376
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 
377
        "<!--this file is auto-generated by online-accounts-hooks2; do not modify-->\n"
 
378
        "<application>\n"
 
379
        "  <description>My application</description>\n"
 
380
        "  <service-types>\n"
 
381
        "    <service-type>some type</service-type>\n"
 
382
        "  </service-types>\n"
 
383
        "  <profile>com-ubuntu.test_NotOurs_0.1.0</profile>\n"
 
384
        "</application>");
 
385
    QVERIFY(m_installDir.exists(notOurs));
 
386
 
369
387
    writeHookFile("com-ubuntu.test_StillInstalled_2.0.application",
370
388
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
371
389
        "<application>\n"
380
398
    QVERIFY(m_installDir.exists(stillInstalled));
381
399
    QVERIFY(!m_installDir.exists(myApp));
382
400
    QVERIFY(m_installDir.exists(noProfile));
 
401
    QVERIFY(m_installDir.exists(noProfile));
383
402
}
384
403
 
385
404
void OnlineAccountsHooksTest::testAccountRemoval()
393
412
    QString stillInstalled("providers/com.ubuntu.test_StillInstalled.provider");
394
413
    writeInstalledFile(stillInstalled,
395
414
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 
415
        "<!--this file is auto-generated by online-accounts-hooks; do not modify-->\n"
396
416
        "<provider>\n"
397
417
        "  <profile>com-ubuntu.test_StillInstalled_2.0</profile>\n"
398
418
        "</provider>");
415
435
    QString myProvider("providers/com.ubuntu.test_MyProvider.provider");
416
436
    writeInstalledFile(myProvider,
417
437
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 
438
        "<!--this file is auto-generated by online-accounts-hooks; do not modify-->\n"
418
439
        "<provider>\n"
419
440
        "  <profile>com-ubuntu.test_MyProvider_3.0</profile>\n"
420
441
        "</provider>");
447
468
    clearHooksDir();
448
469
    clearInstallDir();
449
470
 
 
471
    time_t oldTime = time(NULL) - 3;
 
472
 
450
473
    writeHookFile("com-ubuntu.test_MyApp_1.0.application",
451
474
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
452
475
        "<application>\n"
493
516
    root = doc.documentElement();
494
517
    QCOMPARE(root.firstChildElement("profile").text(),
495
518
             QString("com-ubuntu.test_MyApp_1.1"));
 
519
 
 
520
    // Create an *older* file
 
521
    clearHooksDir();
 
522
    QString fileName("com-ubuntu.test_MyApp_1.2.application");
 
523
    writeHookFile(fileName,
 
524
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 
525
        "<application>\n"
 
526
        "  <description>My application</description>\n"
 
527
        "  <service-types>\n"
 
528
        "    <service-type>some type</service-type>\n"
 
529
        "  </service-types>\n"
 
530
        "</application>");
 
531
    struct utimbuf sourceTime;
 
532
    sourceTime.actime = sourceTime.modtime = oldTime;
 
533
    utime(m_hooksDir.filePath(fileName).toUtf8().constData(), &sourceTime);
 
534
 
 
535
    QVERIFY(runHookProcess());
 
536
 
 
537
    // check that the file has been updated with the correct profile
 
538
    file.close();
 
539
    file.setFileName(m_installDir.absoluteFilePath(installedName));
 
540
    QVERIFY(file.open(QIODevice::ReadOnly));
 
541
    QVERIFY(doc.setContent(&file));
 
542
    root = doc.documentElement();
 
543
    QCOMPARE(root.firstChildElement("profile").text(),
 
544
             QString("com-ubuntu.test_MyApp_1.2"));
496
545
}
497
546
 
498
547
void OnlineAccountsHooksTest::testDesktopEntry_data()