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 #include "accessibility_window_info.h" 19 20 using namespace testing; 21 using namespace testing::ext; 22 23 namespace OHOS { 24 namespace Accessibility { 25 class AccessibilityWindowInfoUnitTest : public ::testing::Test { 26 public: AccessibilityWindowInfoUnitTest()27 AccessibilityWindowInfoUnitTest() 28 {} ~AccessibilityWindowInfoUnitTest()29 ~AccessibilityWindowInfoUnitTest() 30 {} SetUpTestCase()31 static void SetUpTestCase() 32 { 33 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest Start"; 34 } TearDownTestCase()35 static void TearDownTestCase() 36 { 37 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest End"; 38 } SetUp()39 void SetUp() 40 { 41 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest SetUp() Start"; 42 windowInfo_ = std::make_shared<AccessibilityWindowInfo>(); 43 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest SetUp() End"; 44 }; TearDown()45 void TearDown() 46 { 47 GTEST_LOG_(INFO) << "AccessibilityWindowInfoUnitTest TearDown()"; 48 windowInfo_ = nullptr; 49 } 50 51 std::shared_ptr<AccessibilityWindowInfo> windowInfo_ = nullptr; 52 }; 53 54 /** 55 * @tc.number: SetAccessibilityWindowType_001 56 * @tc.name: SetAccessibilityWindowType 57 * @tc.desc: Test function SetAccessibilityWindowType 58 */ 59 HWTEST_F(AccessibilityWindowInfoUnitTest, SetAccessibilityWindowType_001, TestSize.Level1) 60 { 61 GTEST_LOG_(INFO) << "SetAccessibilityWindowType_001 start"; 62 if (!windowInfo_) { 63 GTEST_LOG_(INFO) << "windowInfo_ is null"; 64 return; 65 } 66 windowInfo_->SetAccessibilityWindowType(AccessibilityWindowType::TYPE_APPLICATION); 67 EXPECT_EQ(windowInfo_->GetAccessibilityWindowType(), AccessibilityWindowType::TYPE_APPLICATION); 68 GTEST_LOG_(INFO) << "SetAccessibilityWindowType_001 end"; 69 } 70 71 /** 72 * @tc.number: SetWindowLayer_001 73 * @tc.name: SetWindowLayer 74 * @tc.desc: Test function SetWindowLayer 75 */ 76 HWTEST_F(AccessibilityWindowInfoUnitTest, SetWindowLayer_001, TestSize.Level1) 77 { 78 GTEST_LOG_(INFO) << "SetWindowLayer_001 start"; 79 if (!windowInfo_) { 80 GTEST_LOG_(INFO) << "windowInfo_ is null"; 81 return; 82 } 83 windowInfo_->SetWindowLayer(1); 84 EXPECT_EQ(windowInfo_->GetWindowLayer(), 1); 85 GTEST_LOG_(INFO) << "SetWindowLayer_001 end"; 86 } 87 88 /** 89 * @tc.number: SetWindowId_001 90 * @tc.name: SetWindowId 91 * @tc.desc: Test function SetWindowId 92 */ 93 HWTEST_F(AccessibilityWindowInfoUnitTest, SetWindowId_001, TestSize.Level1) 94 { 95 GTEST_LOG_(INFO) << "SetWindowId_001 start"; 96 if (!windowInfo_) { 97 GTEST_LOG_(INFO) << "windowInfo_ is null"; 98 return; 99 } 100 windowInfo_->SetWindowId(1); 101 EXPECT_EQ(windowInfo_->GetWindowId(), 1); 102 GTEST_LOG_(INFO) << "SetWindowId_001 end"; 103 } 104 105 /** 106 * @tc.number: SetRectInScreen_001 107 * @tc.name: SetRectInScreen 108 * @tc.desc: Test function SetRectInScreen 109 */ 110 HWTEST_F(AccessibilityWindowInfoUnitTest, SetRectInScreen_001, TestSize.Level1) 111 { 112 GTEST_LOG_(INFO) << "SetRectInScreen_001 start"; 113 if (!windowInfo_) { 114 GTEST_LOG_(INFO) << "windowInfo_ is null"; 115 return; 116 } 117 Rect boundParam(1, 1, 2, 2); 118 windowInfo_->SetRectInScreen(boundParam); 119 Rect boundRet = windowInfo_->GetRectInScreen(); 120 EXPECT_EQ(boundRet.GetLeftTopXScreenPostion(), 1); 121 EXPECT_EQ(boundRet.GetLeftTopYScreenPostion(), 1); 122 EXPECT_EQ(boundRet.GetRightBottomXScreenPostion(), 2); 123 EXPECT_EQ(boundRet.GetRightBottomYScreenPostion(), 2); 124 GTEST_LOG_(INFO) << "SetRectInScreen_001 end"; 125 } 126 127 /** 128 * @tc.number: SetActive_001 129 * @tc.name: SetActive 130 * @tc.desc: Test function SetActive 131 */ 132 HWTEST_F(AccessibilityWindowInfoUnitTest, SetActive_001, TestSize.Level1) 133 { 134 GTEST_LOG_(INFO) << "SetActive_001 start"; 135 if (!windowInfo_) { 136 GTEST_LOG_(INFO) << "windowInfo_ is null"; 137 return; 138 } 139 windowInfo_->SetActive(true); 140 EXPECT_TRUE(windowInfo_->IsActive()); 141 GTEST_LOG_(INFO) << "SetActive_001 end"; 142 } 143 144 /** 145 * @tc.number: SetFocused_001 146 * @tc.name: SetFocused 147 * @tc.desc: Test function SetFocused 148 */ 149 HWTEST_F(AccessibilityWindowInfoUnitTest, SetFocused_001, TestSize.Level1) 150 { 151 GTEST_LOG_(INFO) << "SetFocused_001 start"; 152 if (!windowInfo_) { 153 GTEST_LOG_(INFO) << "windowInfo_ is null"; 154 return; 155 } 156 windowInfo_->SetFocused(true); 157 EXPECT_TRUE(windowInfo_->IsFocused()); 158 GTEST_LOG_(INFO) << "SetFocused_001 end"; 159 } 160 161 /** 162 * @tc.number: SetAccessibilityFocused_001 163 * @tc.name: SetAccessibilityFocused 164 * @tc.desc: Test function SetAccessibilityFocused 165 */ 166 HWTEST_F(AccessibilityWindowInfoUnitTest, SetAccessibilityFocused_001, TestSize.Level1) 167 { 168 GTEST_LOG_(INFO) << "SetAccessibilityFocused_001 start"; 169 if (!windowInfo_) { 170 GTEST_LOG_(INFO) << "windowInfo_ is null"; 171 return; 172 } 173 windowInfo_->SetAccessibilityFocused(true); 174 EXPECT_TRUE(windowInfo_->IsAccessibilityFocused()); 175 GTEST_LOG_(INFO) << "SetAccessibilityFocused_001 end"; 176 } 177 178 /** 179 * @tc.number: SetDisplayId_001 180 * @tc.name: SetDisplayId 181 * @tc.desc: Test function SetDisplayId 182 */ 183 HWTEST_F(AccessibilityWindowInfoUnitTest, SetDisplayId_001, TestSize.Level1) 184 { 185 GTEST_LOG_(INFO) << "SetDisplayId_001 start"; 186 if (!windowInfo_) { 187 GTEST_LOG_(INFO) << "windowInfo_ is null"; 188 return; 189 } 190 windowInfo_->SetDisplayId(100); 191 EXPECT_EQ(windowInfo_->GetDisplayId(), 100); 192 GTEST_LOG_(INFO) << "SetDisplayId_001 end"; 193 } 194 195 /** 196 * @tc.number: SetWindowType_001 197 * @tc.name: SetWindowType 198 * @tc.desc: Test function SetWindowType 199 */ 200 HWTEST_F(AccessibilityWindowInfoUnitTest, SetWindowType_001, TestSize.Level1) 201 { 202 GTEST_LOG_(INFO) << "SetWindowType_001 start"; 203 if (!windowInfo_) { 204 GTEST_LOG_(INFO) << "windowInfo_ is null"; 205 return; 206 } 207 windowInfo_->SetWindowType(1); 208 EXPECT_EQ(windowInfo_->GetWindowType(), 1); 209 GTEST_LOG_(INFO) << "SetWindowType_001 end"; 210 } 211 212 /** 213 * @tc.number: SetWindowMode_001 214 * @tc.name: SetWindowMode 215 * @tc.desc: Test function SetWindowMode 216 */ 217 HWTEST_F(AccessibilityWindowInfoUnitTest, SetWindowMode_001, TestSize.Level1) 218 { 219 GTEST_LOG_(INFO) << "SetWindowMode_001 start"; 220 if (!windowInfo_) { 221 GTEST_LOG_(INFO) << "windowInfo_ is null"; 222 return; 223 } 224 windowInfo_->SetWindowMode(1); 225 EXPECT_EQ(windowInfo_->GetWindowMode(), 1); 226 GTEST_LOG_(INFO) << "SetWindowMode_001 end"; 227 } 228 229 /** 230 * @tc.number: SetDecorEnable_001 231 * @tc.name: SetDecorEnable 232 * @tc.desc: Test function SetDecorEnable 233 */ 234 HWTEST_F(AccessibilityWindowInfoUnitTest, SetDecorEnable_001, TestSize.Level1) 235 { 236 GTEST_LOG_(INFO) << "SetDecorEnable_001 start"; 237 if (!windowInfo_) { 238 GTEST_LOG_(INFO) << "windowInfo_ is null"; 239 return; 240 } 241 windowInfo_->SetDecorEnable(true); 242 EXPECT_TRUE(windowInfo_->IsDecorEnable()); 243 GTEST_LOG_(INFO) << "SetDecorEnable_001 end"; 244 } 245 } // namespace Accessibility 246 } // namespace OHOS