• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     } else {
71         std::vector<AccessibilityElementInfo> infos;
72         AccessibilityElementInfo info {};
73         infos.push_back(info);
74         instance_->SetSearchElementInfoByAccessibilityIdResult(infos, SEQUENCE_NUM);
75         EXPECT_NE(instance_.get(), nullptr);
76     }
77     GTEST_LOG_(INFO) << "SetSearchElementInfoByAccessibilityIdResult_001 end";
78 }
79 
80 /**
81  * @tc.number: SetSearchDefaultFocusByWindowIdResult_001
82  * @tc.name: SetSearchDefaultFocusByWindowIdResult
83  * @tc.desc: Test function SetSearchDefaultFocusByWindowIdResult
84  */
85 HWTEST_F(
86     AccessibilityElementOperatorCallbackImplTest, SetSearchDefaultFocusByWindowIdResult_001, TestSize.Level1)
87 {
88     GTEST_LOG_(INFO) << "SetSearchDefaultFocusByWindowIdResult_001 start";
89 
90     if (!instance_) {
91         GTEST_LOG_(INFO) << "Cann't get AccessibilityElementOperatorCallbackImpl instance_";
92     } else {
93         std::vector<AccessibilityElementInfo> infos;
94         AccessibilityElementInfo info {};
95         infos.push_back(info);
96         instance_->SetSearchDefaultFocusByWindowIdResult(infos, SEQUENCE_NUM);
97         EXPECT_NE(instance_.get(), nullptr);
98     }
99     GTEST_LOG_(INFO) << "SetSearchDefaultFocusByWindowIdResult_001 end";
100 }
101 
102 /**
103  * @tc.number: SetSearchElementInfoByTextResult_001
104  * @tc.name: SetSearchElementInfoByTextResult
105  * @tc.desc: Test function SetSearchElementInfoByTextResult
106  */
107 HWTEST_F(AccessibilityElementOperatorCallbackImplTest, SetSearchElementInfoByTextResult_001, TestSize.Level1)
108 {
109     GTEST_LOG_(INFO) << "SetSearchElementInfoByTextResult_001 start";
110     if (!instance_) {
111         GTEST_LOG_(INFO) << "Cann't get AccessibilityElementOperatorCallbackImpl instance_";
112     } else {
113         std::vector<AccessibilityElementInfo> infos;
114         AccessibilityElementInfo info {};
115         infos.push_back(info);
116         instance_->SetSearchElementInfoByTextResult(infos, SEQUENCE_NUM);
117         EXPECT_NE(instance_.get(), nullptr);
118     }
119     GTEST_LOG_(INFO) << "SetSearchElementInfoByTextResult_001 end";
120 }
121 
122 /**
123  * @tc.number: SetFindFocusedElementInfoResult_001
124  * @tc.name: SetFindFocusedElementInfoResult
125  * @tc.desc: Test function SetFindFocusedElementInfoResult
126  */
127 HWTEST_F(AccessibilityElementOperatorCallbackImplTest, SetFindFocusedElementInfoResult_001, TestSize.Level1)
128 {
129     GTEST_LOG_(INFO) << "SetFindFocusedElementInfoResult_001 start";
130     if (!instance_) {
131         GTEST_LOG_(INFO) << "Cann't get AccessibilityElementOperatorCallbackImpl instance_";
132     } else {
133         std::vector<AccessibilityElementInfo> infos;
134         AccessibilityElementInfo info {};
135         infos.push_back(info);
136         instance_->SetFindFocusedElementInfoResult(info, SEQUENCE_NUM);
137         EXPECT_NE(instance_.get(), nullptr);
138     }
139     GTEST_LOG_(INFO) << "SetFindFocusedElementInfoResult_001 end";
140 }
141 
142 /**
143  * @tc.number: SetFocusMoveSearchResult_001
144  * @tc.name: SetFocusMoveSearchResult
145  * @tc.desc: Test function SetFocusMoveSearchResult
146  */
147 HWTEST_F(AccessibilityElementOperatorCallbackImplTest, SetFocusMoveSearchResult_001, TestSize.Level1)
148 {
149     GTEST_LOG_(INFO) << "SetFocusMoveSearchResult_001 start";
150     if (!instance_) {
151         GTEST_LOG_(INFO) << "Cann't get AccessibilityElementOperatorCallbackImpl instance_";
152     } else {
153         std::vector<AccessibilityElementInfo> infos;
154         AccessibilityElementInfo info {};
155         infos.push_back(info);
156         instance_->SetFocusMoveSearchResult(info, SEQUENCE_NUM);
157         EXPECT_NE(instance_.get(), nullptr);
158     }
159     GTEST_LOG_(INFO) << "SetFocusMoveSearchResult_001 end";
160 }
161 
162 /**
163  * @tc.number: SetExecuteActionResult_001
164  * @tc.name: SetExecuteActionResult
165  * @tc.desc: Test function SetExecuteActionResult
166  */
167 HWTEST_F(AccessibilityElementOperatorCallbackImplTest, SetExecuteActionResult_001, TestSize.Level1)
168 {
169     GTEST_LOG_(INFO) << "SetExecuteActionResult_001 start";
170     if (!instance_) {
171         GTEST_LOG_(INFO) << "Cann't get AccessibilityElementOperatorCallbackImpl instance_";
172     } else {
173         std::vector<AccessibilityElementInfo> infos;
174         AccessibilityElementInfo info {};
175         infos.push_back(info);
176         instance_->SetExecuteActionResult(true, SEQUENCE_NUM);
177         EXPECT_NE(instance_.get(), nullptr);
178     }
179     GTEST_LOG_(INFO) << "SetExecuteActionResult_001 end";
180 }
181 
182 /**
183  * @tc.number: SetSearchElementInfoBySpecificPropertyResult_001
184  * @tc.name: SetSearchElementInfoBySpecificPropertyResult
185  * @tc.desc: Test function SetSearchElementInfoBySpecificPropertyResult
186  */
187 HWTEST_F(
188     AccessibilityElementOperatorCallbackImplTest, SetSearchElementInfoBySpecificPropertyResult_001, TestSize.Level1)
189 {
190     GTEST_LOG_(INFO) << "SetSearchElementInfoBySpecificPropertyResult_001 start";
191 
192     if (!instance_) {
193         GTEST_LOG_(INFO) << "Cann't get AccessibilityElementOperatorCallbackImpl instance_";
194     } else {
195         std::list<AccessibilityElementInfo> infos;
196         std::list<AccessibilityElementInfo> treeInfos;
197         AccessibilityElementInfo info {};
198         infos.push_back(info);
199         treeInfos.push_back(info);
200         instance_->SetSearchElementInfoBySpecificPropertyResult(infos, treeInfos, SEQUENCE_NUM);
201         EXPECT_NE(instance_.get(), nullptr);
202     }
203     GTEST_LOG_(INFO) << "SetSearchElementInfoBySpecificPropertyResult_001 end";
204 }
205 } // namespace Accessibility
206 } // namespace OHOS