~jamesh/storage-provider-webdav/landing-20161118

« back to all changes in this revision

Viewing changes to tests/utils/ProviderEnvironment.cpp

  • Committer: Tarmac
  • Author(s): James Henstridge
  • Date: 2016-09-23 05:03:11 UTC
  • mfrom: (7.1.13 provider-test-fixture)
  • Revision ID: tarmac-20160923050311-bb3m6zal58cpccqu
Add test infrastructure for testing DavProvider.

Approved by Michi Henning, unity-api-1-bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "ProviderEnvironment.h"
 
2
 
 
3
#include <cassert>
 
4
 
 
5
using namespace std;
 
6
using namespace unity::storage::provider;
 
7
using namespace unity::storage::qt::client;
 
8
 
 
9
namespace
 
10
{
 
11
 
 
12
const auto SERVICE_CONNECTION_NAME = QStringLiteral("service-session-bus");
 
13
const auto OBJECT_PATH = QStringLiteral("/provider");
 
14
 
 
15
}
 
16
 
 
17
ProviderEnvironment::ProviderEnvironment(unique_ptr<ProviderBase>&& provider,
 
18
                                         OnlineAccounts::AccountId account_id,
 
19
                                         DBusEnvironment const& dbus_env)
 
20
{
 
21
    client_connection_.reset(new QDBusConnection(dbus_env.connection()));
 
22
    server_connection_.reset(new QDBusConnection(
 
23
        QDBusConnection::connectToBus(dbus_env.busAddress(),
 
24
                                      SERVICE_CONNECTION_NAME)));
 
25
 
 
26
    account_manager_.reset(new OnlineAccounts::Manager("", *server_connection_));
 
27
    account_manager_->waitForReady();
 
28
    OnlineAccounts::Account* account = account_manager_->account(account_id);
 
29
    assert(account != nullptr);
 
30
    server_.reset(new testing::TestServer(move(provider), account,
 
31
                                          *server_connection_,
 
32
                                          OBJECT_PATH.toStdString()));
 
33
 
 
34
    client_runtime_ = Runtime::create(*client_connection_);
 
35
    client_account_ = client_runtime_->make_test_account(server_connection_->baseService(), OBJECT_PATH);
 
36
}
 
37
 
 
38
ProviderEnvironment::~ProviderEnvironment()
 
39
{
 
40
    client_account_.reset();
 
41
    client_runtime_->shutdown();
 
42
    client_runtime_.reset();
 
43
 
 
44
    server_.reset();
 
45
    account_manager_.reset();
 
46
 
 
47
    server_connection_.reset();
 
48
    QDBusConnection::disconnectFromBus(SERVICE_CONNECTION_NAME);
 
49
    client_connection_.reset();
 
50
}
 
51
 
 
52
shared_ptr<Account> ProviderEnvironment::get_client() const
 
53
{
 
54
    return client_account_;
 
55
}