Home | History | Annotate | Download | only in tests
      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/Binder.h>
     20 #include <binder/Parcel.h>
     21 
     22 #include <input/InputWindow.h>
     23 #include <input/InputTransport.h>
     24 
     25 namespace android {
     26 namespace test {
     27 
     28 TEST(InputWindowInfo, ParcellingWithoutToken) {
     29     InputWindowInfo i;
     30     i.token = nullptr;
     31 
     32     Parcel p;
     33     ASSERT_EQ(OK, i.write(p));
     34     p.setDataPosition(0);
     35     InputWindowInfo i2 = InputWindowInfo::read(p);
     36     ASSERT_TRUE(i2.token == nullptr);
     37 }
     38 
     39 TEST(InputWindowInfo, Parcelling) {
     40     sp<IBinder> touchableRegionCropHandle = new BBinder();
     41     InputWindowInfo i;
     42     i.token = new BBinder();
     43     i.name = "Foobar";
     44     i.layoutParamsFlags = 7;
     45     i.layoutParamsType = 39;
     46     i.dispatchingTimeout = 12;
     47     i.frameLeft = 93;
     48     i.frameTop = 34;
     49     i.frameRight = 16;
     50     i.frameBottom = 19;
     51     i.surfaceInset = 17;
     52     i.globalScaleFactor = 0.3;
     53     i.windowXScale = 0.4;
     54     i.windowYScale = 0.5;
     55     i.visible = false;
     56     i.canReceiveKeys = false;
     57     i.hasFocus = false;
     58     i.hasWallpaper = false;
     59     i.paused = false;
     60     i.layer = 7;
     61     i.ownerPid = 19;
     62     i.ownerUid = 24;
     63     i.inputFeatures = 29;
     64     i.displayId = 34;
     65     i.portalToDisplayId = 2;
     66     i.replaceTouchableRegionWithCrop = true;
     67     i.touchableRegionCropHandle = touchableRegionCropHandle;
     68 
     69     Parcel p;
     70     i.write(p);
     71 
     72     p.setDataPosition(0);
     73     InputWindowInfo i2 = InputWindowInfo::read(p);
     74     ASSERT_EQ(i.token, i2.token);
     75     ASSERT_EQ(i.name, i2.name);
     76     ASSERT_EQ(i.layoutParamsFlags, i2.layoutParamsFlags);
     77     ASSERT_EQ(i.layoutParamsType, i2.layoutParamsType);
     78     ASSERT_EQ(i.dispatchingTimeout, i2.dispatchingTimeout);
     79     ASSERT_EQ(i.frameLeft, i2.frameLeft);
     80     ASSERT_EQ(i.frameTop, i2.frameTop);
     81     ASSERT_EQ(i.frameRight, i2.frameRight);
     82     ASSERT_EQ(i.frameBottom, i2.frameBottom);
     83     ASSERT_EQ(i.surfaceInset, i2.surfaceInset);
     84     ASSERT_EQ(i.globalScaleFactor, i2.globalScaleFactor);
     85     ASSERT_EQ(i.windowXScale, i2.windowXScale);
     86     ASSERT_EQ(i.windowYScale, i2.windowYScale);
     87     ASSERT_EQ(i.visible, i2.visible);
     88     ASSERT_EQ(i.canReceiveKeys, i2.canReceiveKeys);
     89     ASSERT_EQ(i.hasFocus, i2.hasFocus);
     90     ASSERT_EQ(i.hasWallpaper, i2.hasWallpaper);
     91     ASSERT_EQ(i.paused, i2.paused);
     92     ASSERT_EQ(i.layer, i2.layer);
     93     ASSERT_EQ(i.ownerPid, i2.ownerPid);
     94     ASSERT_EQ(i.ownerUid, i2.ownerUid);
     95     ASSERT_EQ(i.inputFeatures, i2.inputFeatures);
     96     ASSERT_EQ(i.displayId, i2.displayId);
     97     ASSERT_EQ(i.portalToDisplayId, i2.portalToDisplayId);
     98     ASSERT_EQ(i.replaceTouchableRegionWithCrop, i2.replaceTouchableRegionWithCrop);
     99     ASSERT_EQ(i.touchableRegionCropHandle, i2.touchableRegionCropHandle);
    100 }
    101 
    102 } // namespace test
    103 } // namespace android
    104