coreconfigtest.cpp 3.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/**
 * @file coreconfigtest.cpp
 * @copyright 2013 Jolla Ltd.
 * @author Martin Kampas <martin.kampas@tieto.com>
 * @date 2013
 */

#include "coreconfigtest.h"

#include <QtTest/QtTest>

12
#include "libssu/ssucoreconfig_p.h"
13

14 15 16
void CoreconfigTest::testCredentialsScope()
{
    QCOMPARE(SsuCoreConfig::instance()->credentialsScope("/*ignored*/", false), QString("example"));
17 18 19

}

20 21 22 23
void CoreconfigTest::testCredentials()
{
    QCOMPARE(SsuCoreConfig::instance()->credentials("example").first, QString("example_username"));
    QCOMPARE(SsuCoreConfig::instance()->credentials("example").second, QString("example_password"));
24 25
}

26 27 28
void CoreconfigTest::testCredentialsUrl()
{
    QCOMPARE(SsuCoreConfig::instance()->credentialsUrl("example"), QString("http://creden.tia.ls/"));
29 30
}

31 32 33 34 35
void CoreconfigTest::testFlavour()
{
    QCOMPARE(SsuCoreConfig::instance()->flavour(), QString("testing"));
    SsuCoreConfig::instance()->setFlavour("release");
    QCOMPARE(SsuCoreConfig::instance()->flavour(), QString("release"));
36 37
}

38 39 40 41 42 43 44 45 46 47 48 49
void CoreconfigTest::testDeviceMode()
{
    SsuCoreConfig::instance()->remove("deviceMode");
    QCOMPARE(SsuCoreConfig::instance()->deviceMode(), Ssu::ReleaseMode);
    SsuCoreConfig::instance()->setDeviceMode(Ssu::ReleaseMode, Ssu::Add);
    QCOMPARE(SsuCoreConfig::instance()->deviceMode(), Ssu::ReleaseMode);
    SsuCoreConfig::instance()->setDeviceMode(Ssu::LenientMode, Ssu::Add);
    QCOMPARE(SsuCoreConfig::instance()->deviceMode(), Ssu::ReleaseMode | Ssu::LenientMode);
    SsuCoreConfig::instance()->setDeviceMode(Ssu::ReleaseMode, Ssu::Remove);
    QCOMPARE(SsuCoreConfig::instance()->deviceMode(), Ssu::LenientMode);
    SsuCoreConfig::instance()->setDeviceMode(Ssu::ReleaseMode, Ssu::Replace);
    QCOMPARE(SsuCoreConfig::instance()->deviceMode(), Ssu::ReleaseMode);
50 51
}

52 53 54 55 56
void CoreconfigTest::testDomain()
{
    QCOMPARE(SsuCoreConfig::instance()->domain(), QString(""));
    SsuCoreConfig::instance()->setDomain("foo");
    QCOMPARE(SsuCoreConfig::instance()->domain(), QString("foo"));
57 58
}

59 60 61 62 63 64 65 66 67
void CoreconfigTest::testRegistered()
{
    QCOMPARE(SsuCoreConfig::instance()->isRegistered(), false);
    SsuCoreConfig::instance()->setValue("registered", true);
    QCOMPARE(SsuCoreConfig::instance()->isRegistered(), false);
    SsuCoreConfig::instance()->setValue("privateKey", "fooKey");
    QCOMPARE(SsuCoreConfig::instance()->isRegistered(), false);
    SsuCoreConfig::instance()->setValue("certificate", "fooCert");
    QCOMPARE(SsuCoreConfig::instance()->isRegistered(), true);
68 69
}

70 71 72 73 74 75 76
void CoreconfigTest::testLastCredentialsUpdate()
{
    QCOMPARE(SsuCoreConfig::instance()->lastCredentialsUpdate(), QDateTime());
    SsuCoreConfig::instance()->setValue("lastCredentialsUpdate",
                                        QDateTime::fromString("2013-04-08", Qt::ISODate));
    QCOMPARE(SsuCoreConfig::instance()->lastCredentialsUpdate(),
             QDateTime::fromString("2013-04-08", Qt::ISODate));
77 78
}

79 80 81 82 83 84 85 86 87 88
void CoreconfigTest::testRelease()
{
    QCOMPARE(SsuCoreConfig::instance()->release(false), QString("latest"));
    QCOMPARE(SsuCoreConfig::instance()->release(true), QString("next"));
    SsuCoreConfig::instance()->setRelease("next", false);
    QCOMPARE(SsuCoreConfig::instance()->release(false), QString("next"));
    QCOMPARE(SsuCoreConfig::instance()->release(true), QString("next"));
    SsuCoreConfig::instance()->setRelease("latest", true);
    QCOMPARE(SsuCoreConfig::instance()->release(false), QString("next"));
    QCOMPARE(SsuCoreConfig::instance()->release(true), QString("latest"));
89 90
}

91 92 93 94 95
void CoreconfigTest::testSslVerify()
{
    QCOMPARE(SsuCoreConfig::instance()->useSslVerify(), true);
    SsuCoreConfig::instance()->setValue("ssl-verify", false);
    QCOMPARE(SsuCoreConfig::instance()->useSslVerify(), false);
96
}