~michihenning/storage-framework/stand-alone-provider-headers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (C) 2016 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: James Henstridge <james.henstridge@canonical.com>
 */

#include "ProviderFixture.h"

#include <unity/storage/internal/dbus_error.h>

#include <QSignalSpy>

using namespace unity::storage::provider;
using namespace std;

namespace
{

const auto SERVICE_CONNECTION_NAME = QStringLiteral("service-session-bus");
const auto BUS_PATH = QStringLiteral("/provider");

}  // namespace

ProviderFixture::ProviderFixture()
{
    dbus_.reset(new DBusEnvironment);
    dbus_->start_services();
    service_connection_.reset(new QDBusConnection(QDBusConnection::connectToBus(dbus_->busAddress(),
                                                  SERVICE_CONNECTION_NAME)));
    account_manager_.reset(new OnlineAccounts::Manager("", *service_connection_));
}

ProviderFixture::~ProviderFixture()
{
    test_server_.reset();
    service_connection_.reset();
    QDBusConnection::disconnectFromBus(SERVICE_CONNECTION_NAME);
    dbus_.reset();
}

QDBusConnection const& ProviderFixture::connection() const
{
    return dbus_->connection();
}

void ProviderFixture::set_provider(unique_ptr<ProviderBase>&& provider)
{
    account_manager_->waitForReady();
    OnlineAccounts::Account* account = account_manager_->account(2, "oauth2-service");
    ASSERT_NE(nullptr, account);

    test_server_.reset(
        new unity::storage::provider::testing::TestServer(move(provider), account,
                                                          *service_connection_, BUS_PATH.toStdString()));
}

void ProviderFixture::wait_for(QDBusPendingCall const& call)
{
    QDBusPendingCallWatcher watcher(call);
    QSignalSpy spy(&watcher, &QDBusPendingCallWatcher::finished);
    ASSERT_TRUE(spy.wait());
}

QString ProviderFixture::bus_path() const
{
    return BUS_PATH;
}