~afrantzis/unity-system-compositor/notification-timeouts

« back to all changes in this revision

Viewing changes to tests/integration-tests/dbus_bus.cpp

  • Committer: Tarmac
  • Author(s): Alexandros Frantzis
  • Date: 2015-04-09 12:30:27 UTC
  • mfrom: (203.2.3 spinner-process-no-qt)
  • Revision ID: tarmac-20150409123027-asnzo3olka7rti6a
Reimplement ExternalSpinner without Qt.

Approved by PS Jenkins bot, Alan Griffiths.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
 
19
19
#include "dbus_bus.h"
 
20
#include "run_command.h"
20
21
 
21
22
#include <sstream>
22
23
#include <stdexcept>
23
24
 
24
 
#include <cstdio>
25
 
#include <cstdlib>
26
25
#include <csignal>
27
26
 
28
 
namespace
29
 
{
30
 
 
31
 
std::string run_command(std::string const& cmd)
32
 
{
33
 
    auto fp = ::popen(cmd.c_str(), "r");
34
 
    if (!fp)
35
 
        throw std::runtime_error("Failed to execute command: " + cmd);
36
 
 
37
 
    std::string reply;
38
 
 
39
 
    char buffer[64];
40
 
    while (!feof(fp))
41
 
    {
42
 
        auto nread = fread(buffer, 1, 64, fp);
43
 
        reply.append(buffer, nread);
44
 
    }
45
 
 
46
 
    pclose(fp);
47
 
 
48
 
    return reply;
49
 
}
50
 
 
51
 
}
52
 
 
53
27
usc::test::DBusBus::DBusBus()
54
28
    : pid{0}
55
29
{
56
 
    auto launch = run_command("dbus-daemon --session --print-address=1 --print-pid=1 --fork");
 
30
    auto launch = usc::test::run_command(
 
31
        "dbus-daemon --session --print-address=1 --print-pid=1 --fork");
57
32
    std::stringstream ss{launch};
58
33
 
59
34
    std::getline(ss, address_);