Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mock_drm.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17  */
18 
19 #ifndef MIR_TEST_DOUBLES_MOCK_DRM_H_
20 #define MIR_TEST_DOUBLES_MOCK_DRM_H_
21 
22 #include <gmock/gmock.h>
23 
24 #include <xf86drm.h>
25 #include <xf86drmMode.h>
26 
27 namespace mir
28 {
29 namespace geometry
30 {
31 struct Size;
32 }
33 
34 namespace test
35 {
36 namespace doubles
37 {
38 
40 {
41 public:
44 
45  int fd() const;
46  int write_fd() const;
47  drmModeRes* resources_ptr();
48 
49  void add_crtc(uint32_t id, drmModeModeInfo mode);
50  void add_encoder(uint32_t encoder_id, uint32_t crtc_id, uint32_t possible_crtcs_mask);
51  void add_connector(uint32_t connector_id, uint32_t type, drmModeConnection connection,
52  uint32_t encoder_id, std::vector<drmModeModeInfo>& modes,
53  std::vector<uint32_t>& possible_encoder_ids,
54  geometry::Size const& physical_size);
55 
56  void prepare();
57  void reset();
58 
59  drmModeCrtc* find_crtc(uint32_t id);
60  drmModeEncoder* find_encoder(uint32_t id);
61  drmModeConnector* find_connector(uint32_t id);
62 
64  static drmModeModeInfo create_mode(uint16_t hdisplay, uint16_t vdisplay,
65  uint32_t clock, uint16_t htotal, uint16_t vtotal,
66  ModePreference preferred);
67 
68 private:
69  int pipe_fds[2];
70 
71  drmModeRes resources;
72  std::vector<drmModeCrtc> crtcs;
73  std::vector<drmModeEncoder> encoders;
74  std::vector<drmModeConnector> connectors;
75 
76  std::vector<uint32_t> crtc_ids;
77  std::vector<uint32_t> encoder_ids;
78  std::vector<uint32_t> connector_ids;
79 
80  std::vector<drmModeModeInfo> modes;
81  std::vector<drmModeModeInfo> modes_empty;
82  std::vector<uint32_t> connector_encoder_ids;
83 };
84 
85 class MockDRM
86 {
87 public:
88  MockDRM();
89  ~MockDRM() noexcept;
90 
91  MOCK_METHOD2(drmOpen, int(const char *name, const char *busid));
92  MOCK_METHOD1(drmClose, int(int fd));
93  MOCK_METHOD3(drmIoctl, int(int fd, unsigned long request, void *arg));
94 
95  MOCK_METHOD1(drmModeGetResources, drmModeResPtr(int fd));
96  MOCK_METHOD2(drmModeGetConnector, drmModeConnectorPtr(int fd, uint32_t connectorId));
97  MOCK_METHOD2(drmModeGetEncoder, drmModeEncoderPtr(int fd, uint32_t encoder_id));
98  MOCK_METHOD2(drmModeGetCrtc, drmModeCrtcPtr(int fd, uint32_t crtcId));
99  MOCK_METHOD8(drmModeSetCrtc, int(int fd, uint32_t crtcId, uint32_t bufferId,
100  uint32_t x, uint32_t y, uint32_t *connectors,
101  int count, drmModeModeInfoPtr mode));
102 
103  MOCK_METHOD1(drmModeFreeResources, void(drmModeResPtr ptr));
104  MOCK_METHOD1(drmModeFreeConnector, void(drmModeConnectorPtr ptr));
105  MOCK_METHOD1(drmModeFreeEncoder, void(drmModeEncoderPtr ptr));
106  MOCK_METHOD1(drmModeFreeCrtc, void(drmModeCrtcPtr ptr));
107 
108  MOCK_METHOD8(drmModeAddFB, int(int fd, uint32_t width, uint32_t height,
109  uint8_t depth, uint8_t bpp, uint32_t pitch,
110  uint32_t bo_handle, uint32_t *buf_id));
111  MOCK_METHOD2(drmModeRmFB, int(int fd, uint32_t bufferId));
112 
113  MOCK_METHOD5(drmModePageFlip, int(int fd, uint32_t crtc_id, uint32_t fb_id,
114  uint32_t flags, void *user_data));
115  MOCK_METHOD2(drmHandleEvent, int(int fd, drmEventContextPtr evctx));
116 
117  MOCK_METHOD2(drmGetMagic, int(int fd, drm_magic_t *magic));
118  MOCK_METHOD2(drmAuthMagic, int(int fd, drm_magic_t magic));
119 
120  MOCK_METHOD4(drmPrimeHandleToFD, int(int fd, uint32_t handle, uint32_t flags, int *prime_fd));
121  MOCK_METHOD3(drmPrimeFDToHandle, int(int fd, int prime_fd, uint32_t *handle));
122 
123  MOCK_METHOD1(drmSetMaster, int(int fd));
124  MOCK_METHOD1(drmDropMaster, int(int fd));
125 
126  MOCK_METHOD5(drmModeSetCursor, int (int fd, uint32_t crtcId, uint32_t bo_handle, uint32_t width, uint32_t height));
127  MOCK_METHOD4(drmModeMoveCursor,int (int fd, uint32_t crtcId, int x, int y));
128 
129  MOCK_METHOD2(drmSetInterfaceVersion, int (int fd, drmSetVersion* sv));
130  MOCK_METHOD1(drmGetBusid, char* (int fd));
131 
133 };
134 
135 }
136 }
137 }
138 
139 #endif /* MIR_TEST_DOUBLES_DRM_MOCK_H_ */

Copyright © 2012,2013 Canonical Ltd.
Generated on Wed Oct 30 18:52:19 UTC 2013