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

« back to all changes in this revision

Viewing changes to tests/utils/ProviderFixture.cpp

  • Committer: Michi Henning
  • Date: 2016-08-23 23:45:34 UTC
  • mfrom: (53.1.4 devel)
  • Revision ID: michi.henning@canonical.com-20160823234534-4owayhnhcp67g39q
Merged devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2016 Canonical Ltd
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authors: James Henstridge <james.henstridge@canonical.com>
 
17
 */
 
18
 
 
19
#include "ProviderFixture.h"
 
20
 
 
21
#include <unity/storage/internal/dbus_error.h>
 
22
 
 
23
#include <QSignalSpy>
 
24
 
 
25
using namespace unity::storage::provider;
 
26
using namespace std;
 
27
 
 
28
namespace
 
29
{
 
30
 
 
31
const auto SERVICE_CONNECTION_NAME = QStringLiteral("service-session-bus");
 
32
const auto BUS_PATH = QStringLiteral("/provider");
 
33
 
 
34
}  // namespace
 
35
 
 
36
ProviderFixture::ProviderFixture()
 
37
{
 
38
    dbus_.reset(new DBusEnvironment);
 
39
    dbus_->start_services();
 
40
    service_connection_.reset(new QDBusConnection(QDBusConnection::connectToBus(dbus_->busAddress(),
 
41
                                                  SERVICE_CONNECTION_NAME)));
 
42
    account_manager_.reset(new OnlineAccounts::Manager("", *service_connection_));
 
43
}
 
44
 
 
45
ProviderFixture::~ProviderFixture()
 
46
{
 
47
    test_server_.reset();
 
48
    service_connection_.reset();
 
49
    QDBusConnection::disconnectFromBus(SERVICE_CONNECTION_NAME);
 
50
    dbus_.reset();
 
51
}
 
52
 
 
53
QDBusConnection const& ProviderFixture::connection() const
 
54
{
 
55
    return dbus_->connection();
 
56
}
 
57
 
 
58
void ProviderFixture::set_provider(unique_ptr<ProviderBase>&& provider)
 
59
{
 
60
    account_manager_->waitForReady();
 
61
    OnlineAccounts::Account* account = account_manager_->account(2, "oauth2-service");
 
62
    ASSERT_NE(nullptr, account);
 
63
 
 
64
    test_server_.reset(
 
65
        new unity::storage::provider::testing::TestServer(move(provider), account,
 
66
                                                          *service_connection_, BUS_PATH.toStdString()));
 
67
}
 
68
 
 
69
void ProviderFixture::wait_for(QDBusPendingCall const& call)
 
70
{
 
71
    QDBusPendingCallWatcher watcher(call);
 
72
    QSignalSpy spy(&watcher, &QDBusPendingCallWatcher::finished);
 
73
    ASSERT_TRUE(spy.wait());
 
74
}
 
75
 
 
76
QString ProviderFixture::bus_path() const
 
77
{
 
78
    return BUS_PATH;
 
79
}