1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <input/InputTransport.h>
18#include <input/Input.h>
19
20namespace android {
21
22#define CHECK_OFFSET(type, member, expected_offset) \
23  static_assert((offsetof(type, member) == (expected_offset)), "")
24
25struct Foo {
26  uint32_t dummy;
27  PointerCoords coords;
28};
29
30void TestPointerCoordsAlignment() {
31  CHECK_OFFSET(Foo, coords, 8);
32}
33
34void TestInputMessageAlignment() {
35  CHECK_OFFSET(InputMessage, body, 8);
36
37  CHECK_OFFSET(InputMessage::Body::Key, seq, 0);
38  CHECK_OFFSET(InputMessage::Body::Key, eventTime, 8);
39  CHECK_OFFSET(InputMessage::Body::Key, deviceId, 16);
40  CHECK_OFFSET(InputMessage::Body::Key, source, 20);
41  CHECK_OFFSET(InputMessage::Body::Key, action, 24);
42  CHECK_OFFSET(InputMessage::Body::Key, flags, 28);
43  CHECK_OFFSET(InputMessage::Body::Key, keyCode, 32);
44  CHECK_OFFSET(InputMessage::Body::Key, scanCode, 36);
45  CHECK_OFFSET(InputMessage::Body::Key, metaState, 40);
46  CHECK_OFFSET(InputMessage::Body::Key, repeatCount, 44);
47  CHECK_OFFSET(InputMessage::Body::Key, downTime, 48);
48
49  CHECK_OFFSET(InputMessage::Body::Motion, seq, 0);
50  CHECK_OFFSET(InputMessage::Body::Motion, eventTime, 8);
51  CHECK_OFFSET(InputMessage::Body::Motion, deviceId, 16);
52  CHECK_OFFSET(InputMessage::Body::Motion, source, 20);
53  CHECK_OFFSET(InputMessage::Body::Motion, action, 24);
54  CHECK_OFFSET(InputMessage::Body::Motion, actionButton, 28);
55  CHECK_OFFSET(InputMessage::Body::Motion, flags, 32);
56  CHECK_OFFSET(InputMessage::Body::Motion, metaState, 36);
57  CHECK_OFFSET(InputMessage::Body::Motion, buttonState, 40);
58  CHECK_OFFSET(InputMessage::Body::Motion, edgeFlags, 44);
59  CHECK_OFFSET(InputMessage::Body::Motion, downTime, 48);
60  CHECK_OFFSET(InputMessage::Body::Motion, xOffset, 56);
61  CHECK_OFFSET(InputMessage::Body::Motion, yOffset, 60);
62  CHECK_OFFSET(InputMessage::Body::Motion, xPrecision, 64);
63  CHECK_OFFSET(InputMessage::Body::Motion, yPrecision, 68);
64  CHECK_OFFSET(InputMessage::Body::Motion, pointerCount, 72);
65  CHECK_OFFSET(InputMessage::Body::Motion, pointers, 80);
66}
67
68} // namespace android
69