~codygarver/+junk/ind-sess

« back to all changes in this revision

Viewing changes to tests/backend-dbus/mock-display-manager-seat.cc

  • Committer: Cody Garver
  • Date: 2014-04-03 17:08:08 UTC
  • Revision ID: cody@elementaryos.org-20140403170808-z56s93rorb1dzvmk
Initial import, version 12.10.5+14.04.20140324-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *   Charles Kerr <charles.kerr@canonical.com>
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License version 3, as published
 
9
 * by the Free Software Foundation.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
13
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
14
 * PURPOSE.  See the GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License along
 
17
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include "mock-display-manager-seat.h"
 
21
#include "mock-login1-seat.h"
 
22
 
 
23
namespace
 
24
{
 
25
  const char * const DISPLAY_MANAGER_NAME = "org.freedesktop.DisplayManager";
 
26
 
 
27
  std::string
 
28
  next_unique_path ()
 
29
  {
 
30
    static int id = 12; // arbitrary; doesn't matter
 
31
 
 
32
    char * tmp;
 
33
    std::string ret;
 
34
 
 
35
    tmp = g_strdup_printf ("/org/freedesktop/DisplayManager/Seat%d", id++);
 
36
    ret = tmp;
 
37
    g_free (tmp);
 
38
    return ret;
 
39
  }
 
40
}
 
41
 
 
42
/***
 
43
****
 
44
***/
 
45
 
 
46
void
 
47
MockDisplayManagerSeat :: switch_to_greeter ()
 
48
{
 
49
  my_last_action = GREETER;
 
50
}
 
51
 
 
52
gboolean
 
53
MockDisplayManagerSeat :: handle_switch_to_greeter (DisplayManagerSeat * o,
 
54
                                                    GDBusMethodInvocation * inv,
 
55
                                                    gpointer gself)
 
56
{
 
57
  static_cast<MockDisplayManagerSeat*>(gself)->switch_to_greeter ();
 
58
  display_manager_seat_complete_switch_to_greeter (o, inv);
 
59
  return true;
 
60
}
 
61
 
 
62
void
 
63
MockDisplayManagerSeat :: set_guest_allowed (bool b)
 
64
{
 
65
  display_manager_seat_set_has_guest_account (my_skeleton, b);
 
66
}
 
67
 
 
68
gboolean
 
69
MockDisplayManagerSeat :: handle_switch_to_guest (DisplayManagerSeat    * o,
 
70
                                                  GDBusMethodInvocation * inv,
 
71
                                                  const gchar           * session_name G_GNUC_UNUSED,
 
72
                                                  gpointer                gself)
 
73
{
 
74
  static_cast<MockDisplayManagerSeat*>(gself)->switch_to_guest ();
 
75
  display_manager_seat_complete_switch_to_guest (o, inv);
 
76
  return true;
 
77
}
 
78
 
 
79
void
 
80
MockDisplayManagerSeat :: switch_to_guest ()
 
81
{
 
82
  g_assert (my_login1_seat != 0);
 
83
 
 
84
  my_last_action = GUEST;
 
85
  my_login1_seat->switch_to_guest ();
 
86
}
 
87
 
 
88
gboolean
 
89
MockDisplayManagerSeat :: handle_switch_to_user (DisplayManagerSeat    * o,
 
90
                                                 GDBusMethodInvocation * inv,
 
91
                                                 const gchar           * username,
 
92
                                                 const gchar           * session_name G_GNUC_UNUSED,
 
93
                                                 gpointer                gself)
 
94
{
 
95
  static_cast<MockDisplayManagerSeat*>(gself)->switch_to_user (username);
 
96
  display_manager_seat_complete_switch_to_user (o, inv);
 
97
  return true;
 
98
}
 
99
 
 
100
void
 
101
MockDisplayManagerSeat :: switch_to_user (const char * username)
 
102
{
 
103
  g_assert (my_login1_seat != 0);
 
104
 
 
105
  my_last_action = USER;
 
106
  my_login1_seat->switch_to_user (username);
 
107
}
 
108
 
 
109
void
 
110
MockDisplayManagerSeat :: set_login1_seat (MockLogin1Seat * seat)
 
111
{
 
112
  my_login1_seat = seat;
 
113
}
 
114
 
 
115
/***
 
116
****
 
117
***/
 
118
 
 
119
MockDisplayManagerSeat :: MockDisplayManagerSeat (GMainLoop       * loop,
 
120
                                                  GDBusConnection * connection):
 
121
  MockObject (loop, connection, DISPLAY_MANAGER_NAME, next_unique_path()),
 
122
  my_skeleton (display_manager_seat_skeleton_new ()),
 
123
  my_last_action (NONE)
 
124
{
 
125
  g_signal_connect (my_skeleton, "handle-switch-to-guest",
 
126
                    G_CALLBACK(handle_switch_to_guest), this);
 
127
  g_signal_connect (my_skeleton, "handle-switch-to-user",
 
128
                    G_CALLBACK(handle_switch_to_user), this);
 
129
  g_signal_connect (my_skeleton, "handle-switch-to-greeter",
 
130
                    G_CALLBACK(handle_switch_to_greeter), this);
 
131
 
 
132
  set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton));
 
133
}
 
134
 
 
135
MockDisplayManagerSeat :: ~MockDisplayManagerSeat ()
 
136
{
 
137
  //g_signal_handlers_disconnect_by_data (my_skeleton, this);
 
138
  g_clear_object (&my_skeleton);
 
139
}