1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 #include <memory> 18 19 #include "accessibility_operator.h" 20 #include "accessibility_window_info.h" 21 #include "mock_accessible_ability_channel_impl.h" 22 23 using namespace testing; 24 using namespace testing::ext; 25 using namespace std; 26 27 namespace OHOS { 28 namespace Accessibility { 29 class AccessibilityWindowInfoUnitTest : public ::testing::Test { 30 public: AccessibilityWindowInfoUnitTest()31 AccessibilityWindowInfoUnitTest() {} ~AccessibilityWindowInfoUnitTest()32 ~AccessibilityWindowInfoUnitTest() {} 33 SetUpTestCase()34 static void SetUpTestCase() 35 { 36 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest Start"; 37 } TearDownTestCase()38 static void TearDownTestCase() 39 { 40 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest End"; 41 } SetUp()42 void SetUp() 43 { 44 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest SetUp()"; 45 }; TearDown()46 void TearDown() 47 { 48 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest TearDown()"; 49 } 50 }; 51 52 /** 53 * @tc.number: GetWindowId_001 54 * @tc.name: SetWindowId/GetWindowId 55 * @tc.desc: Test function SetWindowId/GetWindowId 56 */ 57 HWTEST_F(AccessibilityWindowInfoUnitTest, GetWindowId_001, TestSize.Level1) 58 { 59 GTEST_LOG_(INFO) << "GetWindowId_001 start"; 60 AccessibilityWindowInfo window {}; 61 window.SetWindowId(1); 62 EXPECT_TRUE(window.GetWindowId() == 1); 63 GTEST_LOG_(INFO) << "GetWindowId_001 end"; 64 } 65 66 /** 67 * @tc.number: GetWindowTitle_001 68 * @tc.name: SetWindowTitle/GetWindowTitle 69 * @tc.desc: Test function SetWindowTitle/GetWindowTitle 70 */ 71 HWTEST_F(AccessibilityWindowInfoUnitTest, GetWindowTitle_001, TestSize.Level1) 72 { 73 GTEST_LOG_(INFO) << "GetWindowTitle_001 start"; 74 AccessibilityWindowInfo window {}; 75 string title = "test"; 76 window.SetWindowTitle(title); 77 EXPECT_TRUE(!strcmp(window.GetWindowTitle().c_str(), "test")); 78 GTEST_LOG_(INFO) << "GetWindowTitle_001 end"; 79 } 80 81 /** 82 * @tc.number: GetWindowType_001 83 * @tc.name: SetWindowType/GetWindowType 84 * @tc.desc: Test function SetWindowType/GetWindowType 85 */ 86 HWTEST_F(AccessibilityWindowInfoUnitTest, GetWindowType_001, TestSize.Level1) 87 { 88 GTEST_LOG_(INFO) << "GetWindowType_001 start"; 89 AccessibilityWindowInfo window {}; 90 window.SetWindowType(WindowType::TYPE_APPLICATION); 91 EXPECT_TRUE(window.GetWindowType() == WindowType::TYPE_APPLICATION); 92 GTEST_LOG_(INFO) << "GetWindowType_001 end"; 93 } 94 95 /** 96 * @tc.number: GetWindowLayer_001 97 * @tc.name: SetWindowLayer/GetWindowLayer 98 * @tc.desc: Test function SetWindowLayer/GetWindowLayer 99 */ 100 HWTEST_F(AccessibilityWindowInfoUnitTest, GetWindowLayer_001, TestSize.Level1) 101 { 102 GTEST_LOG_(INFO) << "GetWindowLayer_001 start"; 103 AccessibilityWindowInfo window {}; 104 window.SetWindowLayer(100); 105 EXPECT_TRUE(window.GetWindowLayer() == 100); 106 GTEST_LOG_(INFO) << "GetWindowLayer_001 end"; 107 } 108 109 /** 110 * @tc.number: GetAnchor_001 111 * @tc.name: SetAnchorId/GetAnchorId 112 * @tc.desc: Test function SetAnchorId/GetAnchorId 113 */ 114 HWTEST_F(AccessibilityWindowInfoUnitTest, GetAnchorId_001, TestSize.Level1) 115 { 116 GTEST_LOG_(INFO) << "GetAnchorId_001 start"; 117 AccessibilityWindowInfo window {}; 118 window.SetAnchorId(1); 119 EXPECT_TRUE(window.GetAnchorId() == 1); 120 GTEST_LOG_(INFO) << "GetAnchorId_001 end"; 121 } 122 123 /** 124 * @tc.number: GetParentId_001 125 * @tc.name: SetParentId/GetParentId 126 * @tc.desc: Test function SetParentId/GetParentId 127 */ 128 HWTEST_F(AccessibilityWindowInfoUnitTest, GetParentId_001, TestSize.Level1) 129 { 130 GTEST_LOG_(INFO) << "GetParentId_001 start"; 131 AccessibilityWindowInfo window {}; 132 window.SetParentId(100); 133 EXPECT_TRUE(window.GetParentId() == 100); 134 GTEST_LOG_(INFO) << "GetParentId_001 end"; 135 } 136 137 /** 138 * @tc.number: GetChannelId_001 139 * @tc.name: SetChannelId/GetChannelId 140 * @tc.desc: Test function SetChannelId/GetChannelId 141 */ 142 HWTEST_F(AccessibilityWindowInfoUnitTest, GetChannelId_001, TestSize.Level1) 143 { 144 GTEST_LOG_(INFO) << "GetChannelId_001 start"; 145 AccessibilityWindowInfo window {}; 146 window.SetChannelId(1); 147 EXPECT_TRUE(window.GetChannelId() == 1); 148 GTEST_LOG_(INFO) << "GetChannelId_001 end"; 149 } 150 151 /** 152 * @tc.number: GetRectInScreen_001 153 * @tc.name: SetRectInScreen/GetRectInScreen 154 * @tc.desc: Test function SetRectInScreen/GetRectInScreen 155 */ 156 HWTEST_F(AccessibilityWindowInfoUnitTest, SetRectInScreen_001, TestSize.Level1) 157 { 158 GTEST_LOG_(INFO) << "GetChannelId_001 start"; 159 AccessibilityWindowInfo window {}; 160 Rect bounds(1, 2, 3, 4); 161 window.SetRectInScreen(bounds); 162 EXPECT_TRUE(window.GetRectInScreen().GetLeftTopXScreenPostion() == 1); 163 EXPECT_TRUE(window.GetRectInScreen().GetLeftTopYScreenPostion() == 2); 164 EXPECT_TRUE(window.GetRectInScreen().GetRightBottomXScreenPostion() == 3); 165 EXPECT_TRUE(window.GetRectInScreen().GetRightBottomYScreenPostion() == 4); 166 GTEST_LOG_(INFO) << "GetChannelId_001 end"; 167 } 168 169 /** 170 * @tc.number: IsActive_001 171 * @tc.name: IsActive 172 * @tc.desc: Test function IsActive 173 */ 174 HWTEST_F(AccessibilityWindowInfoUnitTest, IsActive_001, TestSize.Level1) 175 { 176 GTEST_LOG_(INFO) << "SetChannelId_001 start"; 177 AccessibilityWindowInfo window {}; 178 window.SetActive(true); 179 EXPECT_TRUE(window.IsActive()); 180 GTEST_LOG_(INFO) << "SetChannelId_001 end"; 181 } 182 183 /** 184 * @tc.number: IsFocused_001 185 * @tc.name: IsFocused 186 * @tc.desc: Test function IsFocused 187 */ 188 HWTEST_F(AccessibilityWindowInfoUnitTest, IsFocused_001, TestSize.Level1) 189 { 190 GTEST_LOG_(INFO) << "IsFocused_001 start"; 191 AccessibilityWindowInfo window {}; 192 window.SetFocused(true); 193 EXPECT_TRUE(window.IsFocused()); 194 GTEST_LOG_(INFO) << "IsFocused_001 end"; 195 } 196 197 /** 198 * @tc.number: IsAccessibilityFocused_001 199 * @tc.name: IsAccessibilityFocused 200 * @tc.desc: Test function IsAccessibilityFocused 201 */ 202 HWTEST_F(AccessibilityWindowInfoUnitTest, IsAccessibilityFocused_001, TestSize.Level1) 203 { 204 GTEST_LOG_(INFO) << "IsAccessibilityFocused_001 start"; 205 AccessibilityWindowInfo window {}; 206 window.SetAccessibilityFocused(true); 207 EXPECT_TRUE(window.IsAccessibilityFocused()); 208 GTEST_LOG_(INFO) << "IsAccessibilityFocused_001 end"; 209 } 210 211 /** 212 * @tc.number: AddChild_001 213 * @tc.name: IsAccessibilityFocused 214 * @tc.desc: Test function IsAccessibilityFocused 215 */ 216 HWTEST_F(AccessibilityWindowInfoUnitTest, AddChild_001, TestSize.Level1) 217 { 218 GTEST_LOG_(INFO) << "AddChild_001 start"; 219 AccessibilityWindowInfo window {}; 220 window.AddChild(1); 221 EXPECT_TRUE(window.GetChildNum() == 1); 222 window.AddChild(3); 223 EXPECT_TRUE(window.GetChildNum() == 2); 224 GTEST_LOG_(INFO) << "AddChild_001 end"; 225 } 226 227 /** 228 * @tc.number: ReadFromParcel_001 229 * @tc.name: ReadFromParcel 230 * @tc.desc: Test function ReadFromParcel 231 */ 232 HWTEST_F(AccessibilityWindowInfoUnitTest, ReadFromParcel_001, TestSize.Level1) 233 { 234 GTEST_LOG_(INFO) << "ReadFromParcel_001 start"; 235 236 Parcel parcel; 237 AccessibilityWindowInfo windowInfo {}; 238 windowInfo.Marshalling(parcel); 239 EXPECT_TRUE(windowInfo.ReadFromParcel(parcel)); 240 241 GTEST_LOG_(INFO) << "ReadFromParcel_001 end"; 242 } 243 } // namespace Accessibility 244 } // namespace OHOS