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
20 namespace android {
21
22 #define CHECK_OFFSET(type, member, expected_offset) \
23 static_assert((offsetof(type, member) == (expected_offset)), "")
24
25 struct Foo {
26 uint32_t dummy;
27 PointerCoords coords;
28 };
29
TestPointerCoordsAlignment()30 void TestPointerCoordsAlignment() {
31 CHECK_OFFSET(Foo, coords, 8);
32 }
33
TestInputMessageAlignment()34 void 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, displayId, 24);
42 CHECK_OFFSET(InputMessage::Body::Key, action, 28);
43 CHECK_OFFSET(InputMessage::Body::Key, flags, 32);
44 CHECK_OFFSET(InputMessage::Body::Key, keyCode, 36);
45 CHECK_OFFSET(InputMessage::Body::Key, scanCode, 40);
46 CHECK_OFFSET(InputMessage::Body::Key, metaState, 44);
47 CHECK_OFFSET(InputMessage::Body::Key, repeatCount, 48);
48 CHECK_OFFSET(InputMessage::Body::Key, downTime, 56);
49
50 CHECK_OFFSET(InputMessage::Body::Motion, seq, 0);
51 CHECK_OFFSET(InputMessage::Body::Motion, eventTime, 8);
52 CHECK_OFFSET(InputMessage::Body::Motion, deviceId, 16);
53 CHECK_OFFSET(InputMessage::Body::Motion, source, 20);
54 CHECK_OFFSET(InputMessage::Body::Motion, displayId, 24);
55 CHECK_OFFSET(InputMessage::Body::Motion, action, 28);
56 CHECK_OFFSET(InputMessage::Body::Motion, actionButton, 32);
57 CHECK_OFFSET(InputMessage::Body::Motion, flags, 36);
58 CHECK_OFFSET(InputMessage::Body::Motion, metaState, 40);
59 CHECK_OFFSET(InputMessage::Body::Motion, buttonState, 44);
60 CHECK_OFFSET(InputMessage::Body::Motion, classification, 48);
61 CHECK_OFFSET(InputMessage::Body::Motion, edgeFlags, 52);
62 CHECK_OFFSET(InputMessage::Body::Motion, downTime, 56);
63 CHECK_OFFSET(InputMessage::Body::Motion, xOffset, 64);
64 CHECK_OFFSET(InputMessage::Body::Motion, yOffset, 68);
65 CHECK_OFFSET(InputMessage::Body::Motion, xPrecision, 72);
66 CHECK_OFFSET(InputMessage::Body::Motion, yPrecision, 76);
67 CHECK_OFFSET(InputMessage::Body::Motion, pointerCount, 80);
68 CHECK_OFFSET(InputMessage::Body::Motion, pointers, 88);
69
70 CHECK_OFFSET(InputMessage::Body::Finished, seq, 0);
71 CHECK_OFFSET(InputMessage::Body::Finished, handled, 4);
72 }
73
74 } // namespace android
75