blob: 62023fb328891b306500fd7dc223a456ba339697 [file] [log] [blame]
Fengwei Yin83e0e422014-05-24 05:32:09 +08001/*
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) \
Chih-Hung Hsieh4a186d42016-05-20 11:33:26 -070023 static_assert((offsetof(type, member) == (expected_offset)), "")
Fengwei Yin83e0e422014-05-24 05:32:09 +080024
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);
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +010041 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);
Fengwei Yin83e0e422014-05-24 05:32:09 +080049
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);
Tarandeep Singh58641502017-07-31 10:51:54 -070054 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);
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -080060 CHECK_OFFSET(InputMessage::Body::Motion, classification, 48);
61 CHECK_OFFSET(InputMessage::Body::Motion, edgeFlags, 52);
Tarandeep Singh58641502017-07-31 10:51:54 -070062 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);
Siarhei Vishniakou1f7c0e42018-11-16 22:18:53 -080069
70 CHECK_OFFSET(InputMessage::Body::Finished, seq, 0);
71 CHECK_OFFSET(InputMessage::Body::Finished, handled, 4);
Fengwei Yin83e0e422014-05-24 05:32:09 +080072}
73
74} // namespace android