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

#include "ssuurlresolvertest.h"

#include <stdlib.h>
#include <zypp/media/UrlResolverPlugin.h>

#include <QtTest/QtTest>

15 16
#include "libssu/sandbox_p.h"

17 18 19 20 21 22 23
/**
 * @class SsuUrlResolverTest
 * @brief Tests libzypp UrlResolverPlugin plugin compatibility
 *
 * This test verifies the UrlResolverPlugin works well with installed version of libzypp.
 */

24 25 26 27 28 29 30 31 32 33 34
void SsuUrlResolverTest::initTestCase()
{
    m_sandbox = new Sandbox(QString("%1/configroot").arg(LOCATE_DATA_PATH),
                            Sandbox::UseDirectly, Sandbox::ChildProcesses);
    if (!m_sandbox->activate()) {
        QFAIL("Failed to activate sandbox");
    }
    if (getenv("SSU_SANDBOX_PATH")) {
        qDebug() << "Using in-tree sandbox";
        setenv("LD_PRELOAD", getenv("SSU_SANDBOX_PATH"), 1);
    } else
35
        setenv("LD_PRELOAD", SSU_SANDBOX_PATH, 1);
36 37
}

38 39 40 41
void SsuUrlResolverTest::cleanupTestCase()
{
    delete m_sandbox;
    m_sandbox = 0;
42 43
}

44 45 46 47
void SsuUrlResolverTest::test_data()
{
    QTest::addColumn<QString>("input");
    QTest::addColumn<QString>("expected");
48

49 50 51
    QTest::newRow("basic")
            << "plugin:ssu?repo=mer-core&debug&arch=i586"
            << "https://packages.testing.com//mer/i586/debug/";
52 53
}

54 55 56 57
void SsuUrlResolverTest::test()
{
    QFETCH(QString, input);
    QFETCH(QString, expected);
58

59 60 61
    zypp::media::UrlResolverPlugin::HeaderList customHeaders;
    const QString resolved = QString::fromStdString(
                                 zypp::media::UrlResolverPlugin::resolveUrl(input.toStdString(), customHeaders).asString());
62

63
    QCOMPARE(resolved, expected);
64
}