Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 <gtest/gtest.h> |
| 18 | |
| 19 | #include <binder/Parcel.h> |
| 20 | |
| 21 | #include <input/InputWindow.h> |
| 22 | #include <input/InputTransport.h> |
| 23 | |
| 24 | namespace android { |
| 25 | namespace test { |
| 26 | |
| 27 | TEST(InputWindowInfo, ParcellingWithoutChannel) { |
| 28 | InputWindowInfo i; |
| 29 | i.inputChannel = nullptr; |
| 30 | |
| 31 | Parcel p; |
| 32 | ASSERT_EQ(OK, i.write(p)); |
| 33 | p.setDataPosition(0); |
| 34 | InputWindowInfo i2 = InputWindowInfo::read(p); |
| 35 | ASSERT_TRUE(i2.inputChannel == nullptr); |
| 36 | } |
| 37 | |
| 38 | TEST(InputWindowInfo, Parcelling) { |
| 39 | sp<InputChannel> channel, junkChannel; |
| 40 | status_t result = InputChannel::openInputChannelPair("name", channel, junkChannel); |
| 41 | ASSERT_EQ(OK, result) << "openInputChannelPair should have returned valid channels"; |
| 42 | |
| 43 | InputWindowInfo i; |
| 44 | i.inputChannel = channel; |
| 45 | i.name = "Foobar"; |
| 46 | i.layoutParamsFlags = 7; |
| 47 | i.layoutParamsType = 39; |
| 48 | i.dispatchingTimeout = 12; |
| 49 | i.frameLeft = 93; |
| 50 | i.frameTop = 34; |
| 51 | i.frameRight = 16; |
| 52 | i.frameBottom = 19; |
| 53 | i.scaleFactor = 0.3; |
| 54 | i.visible = false; |
| 55 | i.canReceiveKeys = false; |
| 56 | i.hasFocus = false; |
| 57 | i.hasWallpaper = false; |
| 58 | i.paused = false; |
| 59 | i.layer = 7; |
| 60 | i.ownerPid = 19; |
| 61 | i.ownerUid = 24; |
| 62 | i.inputFeatures = 29; |
| 63 | i.displayId = 34; |
| 64 | |
| 65 | Parcel p; |
| 66 | i.write(p); |
| 67 | |
| 68 | p.setDataPosition(0); |
| 69 | InputWindowInfo i2 = InputWindowInfo::read(p); |
| 70 | ASSERT_EQ(i.inputChannel->getName(), i2.inputChannel->getName()); |
| 71 | ASSERT_EQ(i.name, i2.name); |
| 72 | ASSERT_EQ(i.layoutParamsFlags, i2.layoutParamsFlags); |
| 73 | ASSERT_EQ(i.layoutParamsType, i2.layoutParamsType); |
| 74 | ASSERT_EQ(i.dispatchingTimeout, i2.dispatchingTimeout); |
| 75 | ASSERT_EQ(i.frameLeft, i2.frameLeft); |
| 76 | ASSERT_EQ(i.frameTop, i2.frameTop); |
| 77 | ASSERT_EQ(i.frameRight, i2.frameRight); |
| 78 | ASSERT_EQ(i.frameBottom, i2.frameBottom); |
| 79 | ASSERT_EQ(i.scaleFactor, i2.scaleFactor); |
| 80 | ASSERT_EQ(i.visible, i2.visible); |
| 81 | ASSERT_EQ(i.canReceiveKeys, i2.canReceiveKeys); |
| 82 | ASSERT_EQ(i.hasFocus, i2.hasFocus); |
| 83 | ASSERT_EQ(i.hasWallpaper, i2.hasWallpaper); |
| 84 | ASSERT_EQ(i.paused, i2.paused); |
| 85 | ASSERT_EQ(i.layer, i2.layer); |
| 86 | ASSERT_EQ(i.ownerPid, i2.ownerPid); |
| 87 | ASSERT_EQ(i.ownerUid, i2.ownerUid); |
| 88 | ASSERT_EQ(i.inputFeatures, i2.inputFeatures); |
| 89 | ASSERT_EQ(i.displayId, i2.displayId); |
| 90 | } |
| 91 | |
| 92 | } // namespace test |
| 93 | } // namespace android |