Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mock_hwc_composer_device_1.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3,
6  * as 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: Kevin DuBois <kevin.dubois@canonical.com>
17  */
18 
19 #ifndef MIR_TEST_DOUBLES_MOCK_HWC_COMPOSER_DEVICE_1_H_
20 #define MIR_TEST_DOUBLES_MOCK_HWC_COMPOSER_DEVICE_1_H_
21 
22 #include <hardware/hwcomposer.h>
23 #include <gmock/gmock.h>
24 
25 namespace mir
26 {
27 namespace test
28 {
29 namespace doubles
30 {
31 
32 class MockHWCComposerDevice1 : public hwc_composer_device_1
33 {
34 public:
36  {
37  using namespace testing;
38 
39  common.version = HWC_DEVICE_API_VERSION_1_1;
40 
41  registerProcs = hook_registerProcs;
42  eventControl = hook_eventControl;
43  set = hook_set;
44  prepare = hook_prepare;
45  blank = hook_blank;
46  getDisplayConfigs = hook_getDisplayConfigs;
47  getDisplayAttributes = hook_getDisplayAttributes;
48 
49  ON_CALL(*this, set_interface(_,_,_))
50  .WillByDefault(Invoke(this, &MockHWCComposerDevice1::save_last_set_arguments));
51  ON_CALL(*this, prepare_interface(_,_,_))
52  .WillByDefault(Invoke(this, &MockHWCComposerDevice1::save_last_prepare_arguments));
53  }
54 
55  int save_args(hwc_display_contents_1_t* out, hwc_display_contents_1_t** in)
56  {
57  if ((nullptr == in) || (nullptr == *in))
58  return -1;
59 
60  hwc_display_contents_1_t* primary_display = *in;
61  memcpy(out, primary_display, sizeof(hwc_display_contents_1_t));
62 
63  return 0;
64 
65  }
66  int save_last_prepare_arguments(struct hwc_composer_device_1 *, size_t, hwc_display_contents_1_t** displays)
67  {
68  return save_args(&display0_prepare_content, displays);
69  }
70 
71  int save_last_set_arguments(struct hwc_composer_device_1 *, size_t, hwc_display_contents_1_t** displays)
72  {
73  return save_args(&display0_set_content, displays);
74  }
75 
76  static void hook_registerProcs(struct hwc_composer_device_1* mock_hwc, hwc_procs_t const* procs)
77  {
78  MockHWCComposerDevice1* mocker = static_cast<MockHWCComposerDevice1*>(mock_hwc);
79  return mocker->registerProcs_interface(mock_hwc, procs);
80  }
81  static int hook_eventControl(struct hwc_composer_device_1* mock_hwc, int disp, int event, int enabled)
82  {
83  MockHWCComposerDevice1* mocker = static_cast<MockHWCComposerDevice1*>(mock_hwc);
84  return mocker->eventControl_interface(mock_hwc, disp, event, enabled);
85  }
86  static int hook_set(struct hwc_composer_device_1 *mock_hwc, size_t numDisplays, hwc_display_contents_1_t** displays)
87  {
88  MockHWCComposerDevice1* mocker = static_cast<MockHWCComposerDevice1*>(mock_hwc);
89  return mocker->set_interface(mock_hwc, numDisplays, displays);
90  }
91  static int hook_prepare(struct hwc_composer_device_1 *mock_hwc, size_t numDisplays, hwc_display_contents_1_t** displays)
92  {
93  MockHWCComposerDevice1* mocker = static_cast<MockHWCComposerDevice1*>(mock_hwc);
94  return mocker->prepare_interface(mock_hwc, numDisplays, displays);
95  }
96  static int hook_blank(struct hwc_composer_device_1 *mock_hwc, int disp, int blank)
97  {
98  MockHWCComposerDevice1* mocker = static_cast<MockHWCComposerDevice1*>(mock_hwc);
99  return mocker->blank_interface(mock_hwc, disp, blank);
100  }
101 
102  static int hook_getDisplayConfigs(struct hwc_composer_device_1* mock_hwc, int disp, uint32_t* configs, size_t* numConfigs)
103  {
104  MockHWCComposerDevice1* mocker = static_cast<MockHWCComposerDevice1*>(mock_hwc);
105  return mocker->getDisplayConfigs_interface(mock_hwc, disp, configs, numConfigs);
106  }
107 
108  static int hook_getDisplayAttributes(struct hwc_composer_device_1* mock_hwc, int disp, uint32_t config, const uint32_t* attributes, int32_t* values)
109  {
110  MockHWCComposerDevice1* mocker = static_cast<MockHWCComposerDevice1*>(mock_hwc);
111  return mocker->getDisplayAttributes_interface(mock_hwc, disp, config, attributes, values);
112  }
113 
114  MOCK_METHOD2(registerProcs_interface, void(struct hwc_composer_device_1*, hwc_procs_t const*));
115  MOCK_METHOD4(eventControl_interface, int(struct hwc_composer_device_1* dev, int disp, int event, int enabled));
116  MOCK_METHOD3(set_interface, int(struct hwc_composer_device_1 *, size_t, hwc_display_contents_1_t**));
117  MOCK_METHOD3(prepare_interface, int(struct hwc_composer_device_1 *, size_t, hwc_display_contents_1_t**));
118  MOCK_METHOD3(blank_interface, int(struct hwc_composer_device_1 *, int, int));
119  MOCK_METHOD4(getDisplayConfigs_interface, int(struct hwc_composer_device_1*, int, uint32_t*, size_t*));
120  MOCK_METHOD5(getDisplayAttributes_interface, int(struct hwc_composer_device_1*, int, uint32_t, const uint32_t*, int32_t*));
121 
122  hwc_display_contents_1_t display0_set_content;
123  hwc_display_contents_1_t display0_prepare_content;
124 };
125 
126 }
127 }
128 }
129 
130 #endif /* MIR_TEST_DOUBLES_MOCK_HWC_COMPOSER_DEVICE_1_H_ */

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Oct 15 00:23:28 UTC 2013