• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 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 <android/input.h>
18 #include <android-base/result.h>
19 #include <gtest/gtest.h>
20 #include <input/Input.h>
21 #include <input/InputVerifier.h>
22 #include <string>
23 #include <vector>
24 
25 namespace android {
26 
27 using android::base::Result;
28 
TEST(InputVerifierTest,CreationWithInvalidUtfStringDoesNotCrash)29 TEST(InputVerifierTest, CreationWithInvalidUtfStringDoesNotCrash) {
30     constexpr char bytes[] = {static_cast<char>(0xC0), static_cast<char>(0x80)};
31     const std::string name(bytes, sizeof(bytes));
32     InputVerifier verifier(name);
33 }
34 
TEST(InputVerifierTest,ProcessSourceClassPointer)35 TEST(InputVerifierTest, ProcessSourceClassPointer) {
36     InputVerifier verifier("Verify testOnTouchEventScroll");
37 
38     std::vector<PointerProperties> properties;
39     properties.push_back({});
40     properties.back().clear();
41     properties.back().id = 0;
42     properties.back().toolType = ToolType::UNKNOWN;
43 
44     std::vector<PointerCoords> coords;
45     coords.push_back({});
46     coords.back().clear();
47     coords.back().setAxisValue(AMOTION_EVENT_AXIS_X, 75);
48     coords.back().setAxisValue(AMOTION_EVENT_AXIS_Y, 300);
49 
50     const Result<void> result =
51             verifier.processMovement(/*deviceId=*/0, AINPUT_SOURCE_CLASS_POINTER,
52                                      AMOTION_EVENT_ACTION_DOWN, /*actionButton=*/0,
53                                      /*pointerCount=*/properties.size(), properties.data(),
54                                      coords.data(), /*flags=*/0, /*buttonState=*/0);
55     ASSERT_RESULT_OK(result);
56 }
57 
58 } // namespace android
59