Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mock_android_alloc_device.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 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 #ifndef MIR_TEST_DOUBLES_MOCK_ANDROID_ALLOC_DEVICE_H_
19 #define MIR_TEST_DOUBLES_MOCK_ANDROID_ALLOC_DEVICE_H_
20 
21 #include <gmock/gmock.h>
22 #include <hardware/gralloc.h>
23 
24 namespace mir
25 {
26 namespace test
27 {
28 namespace android
29 {
30 class ICSAllocInterface
31 {
32 public:
33  virtual ~ICSAllocInterface() {/* TODO: make nothrow */}
34  virtual int alloc_interface(alloc_device_t* dev, int w, int h,
35  int format, int usage, buffer_handle_t* handle, int* stride) = 0;
36  virtual int free_interface(alloc_device_t* dev, buffer_handle_t handle) = 0;
37  virtual int dump_interface(alloc_device_t* dev, char *buf, int len) = 0;
38 
39 };
40 }
41 namespace doubles
42 {
43 class MockAllocDevice : public android::ICSAllocInterface,
44  public alloc_device_t
45 {
46 public:
47 
49  {
50  using namespace testing;
51 
53  fake_stride = 300;
54 
55  alloc = hook_alloc;
56  free = hook_free;
57  dump = hook_dump;
58  ON_CALL(*this, alloc_interface(_,_,_,_,_,_,_))
59  .WillByDefault(DoAll(
60  SetArgPointee<5>(buffer_handle),
61  SetArgPointee<6>(fake_stride),
62  Return(0)));
63  ON_CALL(*this, free_interface(_,_))
64  .WillByDefault(Return(0));
65 
66  }
67 
69  {
70  ::free((void*)buffer_handle);
71  }
72 
73  static int hook_alloc(alloc_device_t* mock_alloc,
74  int w, int h, int format, int usage,
75  buffer_handle_t* handle, int* stride)
76  {
77  MockAllocDevice* mocker = static_cast<MockAllocDevice*>(mock_alloc);
78  return mocker->alloc_interface(mock_alloc, w, h, format, usage, handle, stride);
79  }
80 
81  static int hook_free(alloc_device_t* mock_alloc, buffer_handle_t handle)
82  {
83  MockAllocDevice* mocker = static_cast<MockAllocDevice*>(mock_alloc);
84  return mocker->free_interface(mock_alloc, handle);
85  }
86 
87  static void hook_dump(alloc_device_t* mock_alloc, char* buf, int buf_len)
88  {
89  MockAllocDevice* mocker = static_cast<MockAllocDevice*>(mock_alloc);
90  mocker->dump_interface(mock_alloc, buf, buf_len);
91  }
92 
93  native_handle_t* mock_generate_sane_android_handle(int numFd, int numInt)
94  {
95  native_handle_t *handle;
96  int total=numFd + numInt;
97  int header_offset=3;
98 
99  handle = (native_handle_t*) malloc(sizeof(int) * (header_offset+ total));
100  handle->version = 0x389;
101  handle->numFds = numFd;
102  handle->numInts = numInt;
103  for(int i=0; i<total; i++)
104  {
105  handle->data[i] = i*3;
106  }
107 
108  return handle;
109  }
110 
111  MOCK_METHOD7(alloc_interface, int(alloc_device_t*, int, int, int, int, buffer_handle_t*, int*));
112  MOCK_METHOD2(free_interface, int(alloc_device_t*, buffer_handle_t));
113  MOCK_METHOD3(dump_interface, int(alloc_device_t*, char*, int));
114 
115  native_handle_t* buffer_handle;
116  unsigned int fake_stride;
117 };
118 }
119 }
120 } // namespace mir
121 
122 #endif /* MIR_TEST_DOUBLES_MOCK_ANDROID_ALLOC_DEVICE_H_ */
MockAllocDevice()
Definition: mock_android_alloc_device.h:48
static int hook_alloc(alloc_device_t *mock_alloc, int w, int h, int format, int usage, buffer_handle_t *handle, int *stride)
Definition: mock_android_alloc_device.h:73
MOCK_METHOD3(dump_interface, int(alloc_device_t *, char *, int))
MOCK_METHOD7(alloc_interface, int(alloc_device_t *, int, int, int, int, buffer_handle_t *, int *))
Definition: dimensions.h:35
static void hook_dump(alloc_device_t *mock_alloc, char *buf, int buf_len)
Definition: mock_android_alloc_device.h:87
MOCK_METHOD2(free_interface, int(alloc_device_t *, buffer_handle_t))
static int hook_free(alloc_device_t *mock_alloc, buffer_handle_t handle)
Definition: mock_android_alloc_device.h:81
native_handle_t * buffer_handle
Definition: mock_android_alloc_device.h:115
Definition: mock_android_alloc_device.h:43
~MockAllocDevice()
Definition: mock_android_alloc_device.h:68
native_handle_t * mock_generate_sane_android_handle(int numFd, int numInt)
Definition: mock_android_alloc_device.h:93
unsigned int fake_stride
Definition: mock_android_alloc_device.h:116

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