diff options
| author | 2022-11-25 18:51:11 +0000 | |
|---|---|---|
| committer | 2022-11-25 18:51:11 +0000 | |
| commit | eddd157f5effcd950bc7a2f72ee87ce6d7706f41 (patch) | |
| tree | 0b25e40378da438244dc035c8d87037eb2ec2da1 /services | |
| parent | 1be799e7263029c60e36f4e58d7ecd4f79921e9e (diff) | |
| parent | 1f2db4f98af16aca68216ab99c783b4cb6c2626f (diff) | |
Merge "Add explicit copy assignment operator for NotifyMotionArgs."
Diffstat (limited to 'services')
| -rw-r--r-- | services/inputflinger/include/NotifyArgs.h | 2 | ||||
| -rw-r--r-- | services/inputflinger/tests/Android.bp | 1 | ||||
| -rw-r--r-- | services/inputflinger/tests/NotifyArgs_test.cpp | 85 |
3 files changed, 88 insertions, 0 deletions
diff --git a/services/inputflinger/include/NotifyArgs.h b/services/inputflinger/include/NotifyArgs.h index f28dbf3039..c46f90501f 100644 --- a/services/inputflinger/include/NotifyArgs.h +++ b/services/inputflinger/include/NotifyArgs.h @@ -116,6 +116,8 @@ struct NotifyMotionArgs { NotifyMotionArgs(const NotifyMotionArgs& other); + NotifyMotionArgs& operator=(const android::NotifyMotionArgs&) = default; + bool operator==(const NotifyMotionArgs& rhs) const; std::string dump() const; diff --git a/services/inputflinger/tests/Android.bp b/services/inputflinger/tests/Android.bp index e55e121583..cf2a96a876 100644 --- a/services/inputflinger/tests/Android.bp +++ b/services/inputflinger/tests/Android.bp @@ -46,6 +46,7 @@ cc_test { "InputDispatcher_test.cpp", "InputReader_test.cpp", "LatencyTracker_test.cpp", + "NotifyArgs_test.cpp", "PreferStylusOverTouch_test.cpp", "TestInputListener.cpp", "UinputDevice.cpp", diff --git a/services/inputflinger/tests/NotifyArgs_test.cpp b/services/inputflinger/tests/NotifyArgs_test.cpp new file mode 100644 index 0000000000..671558509d --- /dev/null +++ b/services/inputflinger/tests/NotifyArgs_test.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <NotifyArgs.h> +#include <utils/Timers.h> + +#include <gtest/gtest.h> +#include "android/input.h" +#include "input/Input.h" +#include "input/TouchVideoFrame.h" + +namespace android { + +// --- NotifyArgsTest --- + +/** + * Validate basic copy assignment. + */ +TEST(NotifyMotionArgsTest, TestCopyAssignmentOperator) { + int32_t id = 123; + nsecs_t downTime = systemTime(); + nsecs_t eventTime = downTime++; + nsecs_t readTime = downTime++; + int32_t deviceId = 7; + uint32_t source = AINPUT_SOURCE_TOUCHSCREEN; + int32_t displayId = 42; + uint32_t policyFlags = POLICY_FLAG_GESTURE; + int32_t action = AMOTION_EVENT_ACTION_HOVER_MOVE; + int32_t actionButton = AMOTION_EVENT_BUTTON_PRIMARY; + int32_t flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED; + int32_t metaState = AMETA_SCROLL_LOCK_ON; + uint32_t buttonState = AMOTION_EVENT_BUTTON_PRIMARY | AMOTION_EVENT_BUTTON_SECONDARY; + MotionClassification classification = MotionClassification::DEEP_PRESS; + int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP; + uint32_t pointerCount = 2; + PointerProperties pointerProperties[pointerCount]; + PointerCoords pointerCoords[pointerCount]; + float x = 0; + float y = 10; + + for (size_t i = 0; i < pointerCount; i++) { + pointerProperties[i].clear(); + pointerProperties[i].id = i; + pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + + pointerCoords[i].clear(); + pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, x++); + pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, y++); + } + + float xPrecision = 1.2f; + float yPrecision = 3.4f; + float xCursorPosition = 5.6f; + float yCursorPosition = 7.8f; + + std::vector<int16_t> videoData = {1, 2, 3, 4}; + timeval timestamp = {5, 6}; + TouchVideoFrame frame(2, 2, std::move(videoData), timestamp); + std::vector<TouchVideoFrame> videoFrames = {frame}; + const NotifyMotionArgs args(id, eventTime, readTime, deviceId, source, displayId, policyFlags, + action, actionButton, flags, metaState, buttonState, classification, + edgeFlags, pointerCount, pointerProperties, pointerCoords, + xPrecision, yPrecision, xCursorPosition, yCursorPosition, downTime, + videoFrames); + + NotifyMotionArgs otherArgs{}; + otherArgs = args; + + EXPECT_EQ(args, otherArgs); +} + +} // namespace android
\ No newline at end of file |