~larsu/indicator-session/glib-deadlock-workaround

« back to all changes in this revision

Viewing changes to tests/backend-dbus/gtest-mock-dbus-fixture.h

  • Committer: Charles Kerr
  • Date: 2013-03-22 21:34:34 UTC
  • mto: (384.2.29 ng)
  • mto: This revision was merged to the branch mainline in revision 399.
  • Revision ID: charles.kerr@canonical.com-20130322213434-a85qbob8bi4fvfx2
port indicator-session to GMenu/cmake. Code coverage increased from 0% to 95.4%.

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 "gtest-dbus-fixture.h"
 
21
 
 
22
#include "mock-accounts.h"
 
23
#include "mock-consolekit-manager.h"
 
24
#include "mock-consolekit-seat.h"
 
25
#include "mock-consolekit-session.h"
 
26
#include "mock-display-manager-seat.h"
 
27
#include "mock-end-session-dialog.h"
 
28
#include "mock-screen-saver.h"
 
29
#include "mock-session-manager.h"
 
30
#include "mock-upower.h"
 
31
#include "mock-user.h"
 
32
#include "mock-webcredentials.h"
 
33
 
 
34
/***
 
35
****
 
36
***/
 
37
 
 
38
class GTestMockDBusFixture: public GTestDBusFixture
 
39
{
 
40
  private:
 
41
 
 
42
    typedef GTestDBusFixture super;
 
43
 
 
44
  protected:
 
45
 
 
46
    MockScreenSaver * screen_saver;
 
47
    MockSessionManager * session_manager;
 
48
    MockDisplayManagerSeat * dm_seat;
 
49
    MockAccounts * accounts;
 
50
    MockConsoleKitSession * ck_session;
 
51
    MockConsoleKitSeat * ck_seat;
 
52
    MockConsoleKitManager * ck_manager;
 
53
    MockUPower * upower;
 
54
    MockEndSessionDialog * end_session_dialog;
 
55
    MockWebcredentials * webcredentials;
 
56
 
 
57
  protected:
 
58
 
 
59
    virtual void SetUp ()
 
60
    {
 
61
      super :: SetUp ();
 
62
 
 
63
      webcredentials = new MockWebcredentials (loop, conn);
 
64
      end_session_dialog = new MockEndSessionDialog (loop, conn);
 
65
      session_manager = new MockSessionManager (loop, conn);
 
66
      screen_saver = new MockScreenSaver (loop, conn);
 
67
      upower = new MockUPower (loop, conn);
 
68
      dm_seat = new MockDisplayManagerSeat (loop, conn);
 
69
      g_setenv ("XDG_SEAT_PATH", dm_seat->path(), TRUE);
 
70
      dm_seat->set_guest_allowed (false);
 
71
      accounts = build_accounts_mock ();
 
72
      ck_manager = new MockConsoleKitManager (loop, conn);
 
73
      ck_seat = new MockConsoleKitSeat (loop, conn, true);
 
74
      MockUser * user = accounts->find_by_username ("msmith");
 
75
      ck_session = ck_seat->add_session_by_user (user);
 
76
      ck_manager->add_seat (ck_seat);
 
77
      dm_seat->set_consolekit_seat (ck_seat);
 
78
      dm_seat->switch_to_user (user->username());
 
79
      ASSERT_EQ (ck_session, ck_manager->current_session());
 
80
    }
 
81
 
 
82
  protected:
 
83
 
 
84
    virtual void TearDown ()
 
85
    {
 
86
      delete accounts;
 
87
      delete ck_manager;
 
88
      delete dm_seat;
 
89
      delete upower;
 
90
      delete screen_saver;
 
91
      delete session_manager;
 
92
      delete end_session_dialog;
 
93
      delete webcredentials;
 
94
 
 
95
      super :: TearDown ();
 
96
    }
 
97
 
 
98
  private:
 
99
 
 
100
    MockAccounts * build_accounts_mock ()
 
101
    {
 
102
      struct {
 
103
        guint64 login_frequency;
 
104
        const gchar * user_name;
 
105
        const gchar * real_name;
 
106
      } users[] = {
 
107
        { 134, "whartnell",  "First Doctor"    },
 
108
        { 119, "ptroughton", "Second Doctor"   },
 
109
        { 128, "jpertwee",   "Third Doctor"    },
 
110
        { 172, "tbaker",     "Fourth Doctor"   },
 
111
        {  69, "pdavison",   "Fifth Doctor"    },
 
112
        {  31, "cbaker",     "Sixth Doctor"    },
 
113
        {  42, "smccoy",     "Seventh Doctor"  },
 
114
        {   1, "pmcgann",    "Eigth Doctor"    },
 
115
        {  13, "ceccleston", "Ninth Doctor"    },
 
116
        {  47, "dtennant",   "Tenth Doctor"    },
 
117
        {  34, "msmith",     "Eleventh Doctor" },
 
118
        {   1, "rhurndall",  "First Doctor"    }
 
119
      };
 
120
 
 
121
      MockAccounts * a = new MockAccounts (loop, conn);
 
122
      for (int i=0, n=G_N_ELEMENTS(users); i<n; ++i)
 
123
        a->add_user (new MockUser (loop, conn,
 
124
                                   users[i].user_name,
 
125
                                   users[i].real_name,
 
126
                                   users[i].login_frequency));
 
127
      return a;
 
128
    }
 
129
};
 
130