Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mock_gbm.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_GBM_H_
20 #define MIR_TEST_DOUBLES_MOCK_GBM_H_
21 
22 #include <gmock/gmock.h>
23 
24 #pragma GCC diagnostic push
25 #pragma GCC diagnostic warning "-Wall"
26 #include <gbm.h>
27 #pragma GCC diagnostic pop
28 
29 namespace mir
30 {
31 namespace test
32 {
33 namespace doubles
34 {
35 
37 {
38 public:
40  ~FakeGBMResources() = default;
41 
42  gbm_device *device;
43  gbm_surface *surface;
44  gbm_bo *bo;
45  gbm_bo_handle bo_handle;
46 };
47 
48 class MockGBM
49 {
50 public:
51  MockGBM();
52  ~MockGBM();
53 
54  MOCK_METHOD1(gbm_create_device, struct gbm_device*(int fd));
55  MOCK_METHOD1(gbm_device_destroy, void(struct gbm_device *gbm));
56  MOCK_METHOD1(gbm_device_get_fd, int(struct gbm_device *gbm));
57 
58  MOCK_METHOD5(gbm_surface_create, struct gbm_surface*(struct gbm_device *gbm,
59  uint32_t width, uint32_t height,
60  uint32_t format, uint32_t flags));
61  MOCK_METHOD1(gbm_surface_destroy, void(struct gbm_surface *surface));
62  MOCK_METHOD1(gbm_surface_lock_front_buffer, struct gbm_bo*(struct gbm_surface *surface));
63  MOCK_METHOD2(gbm_surface_release_buffer, void(struct gbm_surface *surface, struct gbm_bo *bo));
64 
65  MOCK_METHOD5(gbm_bo_create, struct gbm_bo*(struct gbm_device *gbm,
66  uint32_t width, uint32_t height,
67  uint32_t format, uint32_t flags));
68  MOCK_METHOD1(gbm_bo_get_device, struct gbm_device*(struct gbm_bo *bo));
69  MOCK_METHOD1(gbm_bo_get_width, uint32_t(struct gbm_bo *bo));
70  MOCK_METHOD1(gbm_bo_get_height, uint32_t(struct gbm_bo *bo));
71  MOCK_METHOD1(gbm_bo_get_stride, uint32_t(struct gbm_bo *bo));
72  MOCK_METHOD1(gbm_bo_get_format, uint32_t(struct gbm_bo *bo));
73  MOCK_METHOD1(gbm_bo_get_handle, union gbm_bo_handle(struct gbm_bo *bo));
74  MOCK_METHOD3(gbm_bo_set_user_data, void(struct gbm_bo *bo, void *data,
75  void (*destroy_user_data)(struct gbm_bo *, void *)));
76  MOCK_METHOD1(gbm_bo_get_user_data, void*(struct gbm_bo *bo));
77  MOCK_METHOD3(gbm_bo_write, bool(struct gbm_bo *bo, const void *buf, size_t count));
78  MOCK_METHOD1(gbm_bo_destroy, void(struct gbm_bo *bo));
79 
81 
82 private:
83  void on_gbm_bo_set_user_data(struct gbm_bo *bo, void *data,
84  void (*destroy_user_data)(struct gbm_bo *, void *))
85  {
86  destroyers.push_back(Destroyer{bo, data, destroy_user_data});
87  }
88 
89  struct Destroyer
90  {
91  struct gbm_bo *bo;
92  void *data;
93  void (*destroy_user_data)(struct gbm_bo *, void *);
94 
95  void operator()() const { destroy_user_data(bo, data); }
96  };
97 
98  std::vector<Destroyer> destroyers;
99 };
100 
101 }
102 }
103 }
104 
105 #endif /* MIR_TEST_DOUBLES_MOCK_GBM_H_ */
gbm_device * device
Definition: mock_gbm.h:42
Definition: mock_gbm.h:36
MOCK_METHOD2(gbm_surface_release_buffer, void(struct gbm_surface *surface, struct gbm_bo *bo))
gbm_surface * surface
Definition: mock_gbm.h:43
gbm_bo_handle bo_handle
Definition: mock_gbm.h:45
unsigned int width
Definition: black_arrow.c:4
Definition: mock_gbm.h:48
gbm_bo * bo
Definition: mock_gbm.h:44
MOCK_METHOD5(gbm_surface_create, struct gbm_surface *(struct gbm_device *gbm, uint32_t width, uint32_t height, uint32_t format, uint32_t flags))
unsigned int height
Definition: black_arrow.c:5
MOCK_METHOD1(gbm_create_device, struct gbm_device *(int fd))
FakeGBMResources fake_gbm
Definition: mock_gbm.h:80
MOCK_METHOD3(gbm_bo_set_user_data, void(struct gbm_bo *bo, void *data, void(*destroy_user_data)(struct gbm_bo *, void *)))

Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Apr 11 21:14:53 UTC 2014