1 /*
2 * Copyright (C) 2022 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 <NotifyArgs.h>
18 #include <utils/Timers.h>
19
20 #include <gtest/gtest.h>
21 #include "android/input.h"
22 #include "input/Input.h"
23 #include "input/TouchVideoFrame.h"
24
25 namespace android {
26
27 // --- NotifyArgsTest ---
28
29 /**
30 * Validate basic copy assignment.
31 */
TEST(NotifyMotionArgsTest,TestCopyAssignmentOperator)32 TEST(NotifyMotionArgsTest, TestCopyAssignmentOperator) {
33 int32_t id = 123;
34 nsecs_t downTime = systemTime();
35 nsecs_t eventTime = downTime++;
36 nsecs_t readTime = downTime++;
37 int32_t deviceId = 7;
38 uint32_t source = AINPUT_SOURCE_TOUCHSCREEN;
39 ui::LogicalDisplayId displayId = ui::LogicalDisplayId{42};
40 uint32_t policyFlags = POLICY_FLAG_GESTURE;
41 int32_t action = AMOTION_EVENT_ACTION_HOVER_MOVE;
42 int32_t actionButton = AMOTION_EVENT_BUTTON_PRIMARY;
43 int32_t flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
44 int32_t metaState = AMETA_SCROLL_LOCK_ON;
45 uint32_t buttonState = AMOTION_EVENT_BUTTON_PRIMARY | AMOTION_EVENT_BUTTON_SECONDARY;
46 MotionClassification classification = MotionClassification::DEEP_PRESS;
47 int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP;
48 uint32_t pointerCount = 2;
49 PointerProperties pointerProperties[pointerCount];
50 PointerCoords pointerCoords[pointerCount];
51 float x = 0;
52 float y = 10;
53
54 for (size_t i = 0; i < pointerCount; i++) {
55 pointerProperties[i].clear();
56 pointerProperties[i].id = i;
57 pointerProperties[i].toolType = ToolType::FINGER;
58
59 pointerCoords[i].clear();
60 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, x++);
61 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, y++);
62 }
63
64 float xPrecision = 1.2f;
65 float yPrecision = 3.4f;
66 float xCursorPosition = 5.6f;
67 float yCursorPosition = 7.8f;
68
69 std::vector<int16_t> videoData = {1, 2, 3, 4};
70 timeval timestamp = {5, 6};
71 TouchVideoFrame frame(2, 2, std::move(videoData), timestamp);
72 std::vector<TouchVideoFrame> videoFrames = {frame};
73 const NotifyMotionArgs args(id, eventTime, readTime, deviceId, source, displayId, policyFlags,
74 action, actionButton, flags, metaState, buttonState, classification,
75 edgeFlags, pointerCount, pointerProperties, pointerCoords,
76 xPrecision, yPrecision, xCursorPosition, yCursorPosition, downTime,
77 videoFrames);
78
79 NotifyMotionArgs otherArgs{};
80 otherArgs = args;
81
82 EXPECT_EQ(args, otherArgs);
83 }
84
85 } // namespace android