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 <memory> 17 #include <gtest/gtest.h> 18 #include "accessibility_element_operator_callback_impl.h" 19 20 using namespace testing; 21 using namespace testing::ext; 22 23 namespace OHOS { 24 namespace Accessibility { 25 namespace { 26 constexpr int32_t SEQUENCE_NUM = 1; 27 } // namespace 28 29 class AccessibilityElementOperatorCallbackImplTest : public ::testing::Test { 30 public: AccessibilityElementOperatorCallbackImplTest()31 AccessibilityElementOperatorCallbackImplTest() 32 {} ~AccessibilityElementOperatorCallbackImplTest()33 ~AccessibilityElementOperatorCallbackImplTest() 34 {} 35 36 std::shared_ptr<AccessibilityElementOperatorCallbackImpl> instance_ = nullptr; 37 SetUpTestCase()38 static void SetUpTestCase() 39 { 40 GTEST_LOG_(INFO) << "AccessibilityElementOperatorCallbackImplTest Start"; 41 } TearDownTestCase()42 static void TearDownTestCase() 43 { 44 GTEST_LOG_(INFO) << "AccessibilityElementOperatorCallbackImplTest End"; 45 } SetUp()46 void SetUp() 47 { 48 GTEST_LOG_(INFO) << "AccessibilityElementOperatorCallbackImplTest SetUp()"; 49 instance_ = std::make_shared<AccessibilityElementOperatorCallbackImpl>(); 50 }; TearDown()51 void TearDown() 52 { 53 GTEST_LOG_(INFO) << "AccessibilityElementOperatorCallbackImplTest TearDown()"; 54 instance_ = nullptr; 55 } 56 }; 57 58 /** 59 * @tc.number: SetSearchElementInfoByAccessibilityIdResult_001 60 * @tc.name: SetSearchElementInfoByAccessibilityIdResult 61 * @tc.desc: Test function SetSearchElementInfoByAccessibilityIdResult 62 */ 63 HWTEST_F( 64 AccessibilityElementOperatorCallbackImplTest, SetSearchElementInfoByAccessibilityIdResult_001, TestSize.Level1) 65 { 66 GTEST_LOG_(INFO) << "SetSearchElementInfoByAccessibilityIdResult_001 start"; 67 68 if (!instance_) { 69 GTEST_LOG_(INFO) << "Cann't get AccessibilityElementOperatorCallbackImpl instance_"; 70 return; 71 } 72 73 std::vector<AccessibilityElementInfo> infos; 74 AccessibilityElementInfo info {}; 75 infos.push_back(info); 76 instance_->SetSearchElementInfoByAccessibilityIdResult(infos, SEQUENCE_NUM); 77 EXPECT_NE(instance_.get(), nullptr); 78 GTEST_LOG_(INFO) << "SetSearchElementInfoByAccessibilityIdResult_001 end"; 79 } 80 81 /** 82 * @tc.number: SetSearchElementInfoByTextResult_001 83 * @tc.name: SetSearchElementInfoByTextResult 84 * @tc.desc: Test function SetSearchElementInfoByTextResult 85 */ 86 HWTEST_F(AccessibilityElementOperatorCallbackImplTest, SetSearchElementInfoByTextResult_001, TestSize.Level1) 87 { 88 GTEST_LOG_(INFO) << "SetSearchElementInfoByTextResult_001 start"; 89 if (!instance_) { 90 GTEST_LOG_(INFO) << "Cann't get AccessibilityElementOperatorCallbackImpl instance_"; 91 return; 92 } 93 94 std::vector<AccessibilityElementInfo> infos; 95 AccessibilityElementInfo info {}; 96 infos.push_back(info); 97 instance_->SetSearchElementInfoByTextResult(infos, SEQUENCE_NUM); 98 EXPECT_NE(instance_.get(), nullptr); 99 GTEST_LOG_(INFO) << "SetSearchElementInfoByTextResult_001 end"; 100 } 101 102 /** 103 * @tc.number: SetFindFocusedElementInfoResult_001 104 * @tc.name: SetFindFocusedElementInfoResult 105 * @tc.desc: Test function SetFindFocusedElementInfoResult 106 */ 107 HWTEST_F(AccessibilityElementOperatorCallbackImplTest, SetFindFocusedElementInfoResult_001, TestSize.Level1) 108 { 109 GTEST_LOG_(INFO) << "SetFindFocusedElementInfoResult_001 start"; 110 if (!instance_) { 111 GTEST_LOG_(INFO) << "Cann't get AccessibilityElementOperatorCallbackImpl instance_"; 112 return; 113 } 114 115 std::vector<AccessibilityElementInfo> infos; 116 AccessibilityElementInfo info {}; 117 infos.push_back(info); 118 instance_->SetFindFocusedElementInfoResult(info, SEQUENCE_NUM); 119 EXPECT_NE(instance_.get(), nullptr); 120 GTEST_LOG_(INFO) << "SetFindFocusedElementInfoResult_001 end"; 121 } 122 123 /** 124 * @tc.number: SetFocusMoveSearchResult_001 125 * @tc.name: SetFocusMoveSearchResult 126 * @tc.desc: Test function SetFocusMoveSearchResult 127 */ 128 HWTEST_F(AccessibilityElementOperatorCallbackImplTest, SetFocusMoveSearchResult_001, TestSize.Level1) 129 { 130 GTEST_LOG_(INFO) << "SetFocusMoveSearchResult_001 start"; 131 if (!instance_) { 132 GTEST_LOG_(INFO) << "Cann't get AccessibilityElementOperatorCallbackImpl instance_"; 133 return; 134 } 135 136 std::vector<AccessibilityElementInfo> infos; 137 AccessibilityElementInfo info {}; 138 infos.push_back(info); 139 instance_->SetFocusMoveSearchResult(info, SEQUENCE_NUM); 140 EXPECT_NE(instance_.get(), nullptr); 141 GTEST_LOG_(INFO) << "SetFocusMoveSearchResult_001 end"; 142 } 143 144 /** 145 * @tc.number: SetExecuteActionResult_001 146 * @tc.name: SetExecuteActionResult 147 * @tc.desc: Test function SetExecuteActionResult 148 */ 149 HWTEST_F(AccessibilityElementOperatorCallbackImplTest, SetExecuteActionResult_001, TestSize.Level1) 150 { 151 GTEST_LOG_(INFO) << "SetExecuteActionResult_001 start"; 152 if (!instance_) { 153 GTEST_LOG_(INFO) << "Cann't get AccessibilityElementOperatorCallbackImpl instance_"; 154 return; 155 } 156 157 std::vector<AccessibilityElementInfo> infos; 158 AccessibilityElementInfo info {}; 159 infos.push_back(info); 160 instance_->SetExecuteActionResult(true, SEQUENCE_NUM); 161 EXPECT_NE(instance_.get(), nullptr); 162 GTEST_LOG_(INFO) << "SetExecuteActionResult_001 end"; 163 } 164 } // namespace Accessibility 165 } // namespace OHOS