aboutsummaryrefslogtreecommitdiff
path: root/tests/backend-dbus/gtest-mock-dbus-fixture.h
blob: 5c4e312d8a1f3c72c2e81fab27733804a5510f0b (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * Copyright 2013 Canonical Ltd.
 *
 * Authors:
 *   Charles Kerr <charles.kerr@canonical.com>
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU 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 warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "gtest-dbus-fixture.h"

#include "mock-accounts.h"
#include "mock-consolekit-manager.h"
#include "mock-consolekit-seat.h"
#include "mock-consolekit-session.h"
#include "mock-display-manager-seat.h"
#include "mock-end-session-dialog.h"
#include "mock-screen-saver.h"
#include "mock-session-manager.h"
#include "mock-upower.h"
#include "mock-user.h"
#include "mock-webcredentials.h"

/***
****
***/

class GTestMockDBusFixture: public GTestDBusFixture
{
  private:

    typedef GTestDBusFixture super;

  protected:

    MockScreenSaver * screen_saver;
    MockSessionManager * session_manager;
    MockDisplayManagerSeat * dm_seat;
    MockAccounts * accounts;
    MockConsoleKitSession * ck_session;
    MockConsoleKitSeat * ck_seat;
    MockConsoleKitManager * ck_manager;
    MockUPower * upower;
    MockEndSessionDialog * end_session_dialog;
    MockWebcredentials * webcredentials;

  protected:

    virtual void SetUp ()
    {
      super :: SetUp ();

      webcredentials = new MockWebcredentials (loop, conn);
      end_session_dialog = new MockEndSessionDialog (loop, conn);
      session_manager = new MockSessionManager (loop, conn);
      screen_saver = new MockScreenSaver (loop, conn);
      upower = new MockUPower (loop, conn);
      dm_seat = new MockDisplayManagerSeat (loop, conn);
      g_setenv ("XDG_SEAT_PATH", dm_seat->path(), TRUE);
      dm_seat->set_guest_allowed (false);
      accounts = build_accounts_mock ();
      ck_manager = new MockConsoleKitManager (loop, conn);
      ck_seat = new MockConsoleKitSeat (loop, conn, true);
      MockUser * user = accounts->find_by_username ("msmith");
      ck_session = ck_seat->add_session_by_user (user);
      ck_manager->add_seat (ck_seat);
      dm_seat->set_consolekit_seat (ck_seat);
      dm_seat->switch_to_user (user->username());
      ASSERT_EQ (ck_session, ck_manager->current_session());
    }

  protected:

    virtual void TearDown ()
    {
      delete accounts;
      delete ck_manager;
      delete dm_seat;
      delete upower;
      delete screen_saver;
      delete session_manager;
      delete end_session_dialog;
      delete webcredentials;

      super :: TearDown ();
    }

  private:

    MockAccounts * build_accounts_mock ()
    {
      struct {
        guint64 login_frequency;
        const gchar * user_name;
        const gchar * real_name;
      } users[] = {
        { 134, "whartnell",  "First Doctor"    },
        { 119, "ptroughton", "Second Doctor"   },
        { 128, "jpertwee",   "Third Doctor"    },
        { 172, "tbaker",     "Fourth Doctor"   },
        {  69, "pdavison",   "Fifth Doctor"    },
        {  31, "cbaker",     "Sixth Doctor"    },
        {  42, "smccoy",     "Seventh Doctor"  },
        {   1, "pmcgann",    "Eigth Doctor"    },
        {  13, "ceccleston", "Ninth Doctor"    },
        {  47, "dtennant",   "Tenth Doctor"    },
        {  34, "msmith",     "Eleventh Doctor" },
        {   1, "rhurndall",  "First Doctor"    }
      };

      MockAccounts * a = new MockAccounts (loop, conn);
      for (int i=0, n=G_N_ELEMENTS(users); i<n; ++i)
        a->add_user (new MockUser (loop, conn,
                                   users[i].user_name,
                                   users[i].real_name,
                                   users[i].login_frequency));
      return a;
    }
};