Add static asserts for InputMessage sizes
We currently don't test the total size of InputMessage.
But that's still important, to ensure it doesn't extend further than
expected.
Add asserts for the sizes of Header and Body.
Bug: none
Test: presubmit
Change-Id: I2dbda2136186b22a9247fde058a9c356b07c808d
diff --git a/libs/input/tests/StructLayout_test.cpp b/libs/input/tests/StructLayout_test.cpp
index 8d8cf06..0fb6cfc 100644
--- a/libs/input/tests/StructLayout_test.cpp
+++ b/libs/input/tests/StructLayout_test.cpp
@@ -73,4 +73,20 @@
CHECK_OFFSET(InputMessage::Body::Finished, handled, 4);
}
+void TestHeaderSize() {
+ static_assert(sizeof(InputMessage::Header) == 8);
+}
+
+/**
+ * We cannot use the Body::size() method here because it is not static for
+ * the Motion type, where "pointerCount" variable affects the size and can change at runtime.
+ */
+void TestBodySize() {
+ static_assert(sizeof(InputMessage::Body::Key) == 64);
+ static_assert(sizeof(InputMessage::Body::Motion) ==
+ offsetof(InputMessage::Body::Motion, pointers) +
+ sizeof(InputMessage::Body::Motion::Pointer) * MAX_POINTERS);
+ static_assert(sizeof(InputMessage::Body::Finished) == 8);
+}
+
} // namespace android