~codygarver/+junk/ind-sess

« back to all changes in this revision

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

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