1 /*
2 * Copyright (c) 2021-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 "ability_context.h"
18 #include "completed_callback.h"
19 #include "context_container.h"
20 #include "element_name.h"
21 #include "event_handler.h"
22 #include "base_types.h"
23 #include "pending_want.h"
24 #include "pending_want_record.h"
25 #include "process_options.h"
26 #include "want.h"
27 #define private public
28 #define protected public
29 #include "want_agent.h"
30 #undef private
31 #undef protected
32 #include "want_agent_constant.h"
33 #include "want_agent_helper.h"
34 #include "want_agent_info.h"
35 #include "want_params.h"
36 #include "want_receiver_stub.h"
37 #include "want_sender_stub.h"
38
39 using namespace testing::ext;
40 using namespace OHOS::AAFwk;
41 using namespace OHOS;
42 using OHOS::AppExecFwk::ElementName;
43 using namespace OHOS::AppExecFwk;
44 using namespace OHOS::AbilityRuntime::WantAgent;
45 using vector_str = std::vector<std::string>;
46
47 namespace OHOS::AbilityRuntime::WantAgent {
48 class WantAgentTest : public testing::Test {
49 public:
WantAgentTest()50 WantAgentTest()
51 {}
~WantAgentTest()52 ~WantAgentTest()
53 {}
54 static void SetUpTestCase(void);
55 static void TearDownTestCase(void);
56 void SetUp();
57 void TearDown();
58 };
59
SetUpTestCase(void)60 void WantAgentTest::SetUpTestCase(void)
61 {}
62
TearDownTestCase(void)63 void WantAgentTest::TearDownTestCase(void)
64 {}
65
SetUp(void)66 void WantAgentTest::SetUp(void)
67 {}
68
TearDown(void)69 void WantAgentTest::TearDown(void)
70 {}
71
72 /*
73 * @tc.number : WantAgent_0100
74 * @tc.name : WantAgentInfo Constructors
75 * @tc.desc : 1.Constructors and GetPendingWant
76 */
77 HWTEST_F(WantAgentTest, WantAgent_0100, Function | MediumTest | Level1)
78 {
79 std::shared_ptr<PendingWant> pendingWant = nullptr;
80 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>(pendingWant);
81 EXPECT_EQ(wantAgent->GetPendingWant(), nullptr);
82 }
83
84 /*
85 * @tc.number : WantAgent_0200
86 * @tc.name : WantAgentInfo Constructors
87 * @tc.desc : 1.Constructors and GetPendingWant
88 */
89 HWTEST_F(WantAgentTest, WantAgent_0200, Function | MediumTest | Level1)
90 {
91 sptr<IWantSender> target(new (std::nothrow) PendingWantRecord());
92 std::shared_ptr<PendingWant> pendingWant = std::make_shared<PendingWant>(target);
93 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>(pendingWant);
94 EXPECT_EQ(wantAgent->GetPendingWant(), pendingWant);
95 }
96
97 /*
98 * @tc.number : WantAgent_0300
99 * @tc.name : WantAgentInfo Constructors
100 * @tc.desc : 1.Constructors and SetPendingWant
101 */
102 HWTEST_F(WantAgentTest, WantAgent_0300, Function | MediumTest | Level1)
103 {
104 sptr<IWantSender> target(new (std::nothrow) PendingWantRecord());
105 std::shared_ptr<PendingWant> pendingWant = std::make_shared<PendingWant>(target);
106 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>(pendingWant);
107 EXPECT_NE(wantAgent, nullptr);
108 wantAgent->SetPendingWant(pendingWant);
109 }
110
111 /*
112 * @tc.number : WantAgent_0400
113 * @tc.name : WantAgentInfo Constructors
114 * @tc.desc : 1.Constructors and Marshalling
115 */
116 HWTEST_F(WantAgentTest, WantAgent_0400, Function | MediumTest | Level1)
117 {
118 std::shared_ptr<PendingWant> pendingWant = nullptr;
119 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>(pendingWant);
120 Parcel parcel;
121 bool ret = wantAgent->Marshalling(parcel);
122 EXPECT_EQ(ret, true);
123 }
124
125 /*
126 * @tc.number : WantAgent_0500
127 * @tc.name : WantAgentInfo Constructors
128 * @tc.desc : 1.Constructors and Unmarshalling
129 */
130 HWTEST_F(WantAgentTest, WantAgent_0500, Function | MediumTest | Level1)
131 {
132 std::shared_ptr<PendingWant> pendingWant = nullptr;
133 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>(pendingWant);
134 Parcel parcel;
135 bool ret = wantAgent->Unmarshalling(parcel);
136 EXPECT_EQ(ret, true);
137 }
138
139 /*
140 * @tc.number : WantAgent_0600
141 * @tc.name : SetIsMultithreadingSupported test
142 * @tc.desc : SetIsMultithreadingSupported
143 */
144 HWTEST_F(WantAgentTest, WantAgent_0600, Function | MediumTest | Level1)
145 {
146 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>();
147 wantAgent->SetIsMultithreadingSupported(true);
148 EXPECT_EQ(wantAgent->isMultithreadingSupported_, true);
149 }
150
151 /*
152 * @tc.number : WantAgent_0700
153 * @tc.name : GetIsMultithreadingSupported test
154 * @tc.desc : GetIsMultithreadingSupported
155 */
156 HWTEST_F(WantAgentTest, WantAgent_0700, Function | MediumTest | Level1)
157 {
158 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>();
159 wantAgent->isMultithreadingSupported_ = true;
160 bool test = wantAgent->GetIsMultithreadingSupported();
161 EXPECT_EQ(test, true);
162 }
163
164 /*
165 * @tc.number : WantAgent_0800
166 * @tc.name : LocalWantAgent Constructor
167 * @tc.desc : LocalWantAgent Constructor
168 */
169 HWTEST_F(WantAgentTest, WantAgent_0800, Function | MediumTest | Level1)
170 {
171 std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
172 std::shared_ptr<LocalPendingWant> localPendingWant = std::make_shared<LocalPendingWant>(
173 "TestBundleName", want, 0);
174 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>(localPendingWant);
175 ASSERT_EQ(wantAgent->IsLocal(), 1);
176 ASSERT_EQ(wantAgent->GetLocalPendingWant()->GetBundleName(), "TestBundleName");
177 }
178
179 /*
180 * @tc.number : ProcessOptionsTest_0100
181 * @tc.name : Marshalling
182 * @tc.desc : Marshalling
183 */
184 HWTEST_F(WantAgentTest, ProcessOptionsTest_0100, TestSize.Level1)
185 {
186 auto option = std::make_shared<ProcessOptions>();
187 Parcel parcel;
188 auto result = option->Marshalling(parcel);
189 EXPECT_EQ(result, true);
190 }
191
192 /*
193 * @tc.number : ProcessOptionsTest_0200
194 * @tc.name : Unmarshalling
195 * @tc.desc : Unmarshalling
196 */
197 HWTEST_F(WantAgentTest, ProcessOptionsTest_0200, TestSize.Level1)
198 {
199 auto option = std::make_shared<ProcessOptions>();
200 Parcel parcel;
201 option->Unmarshalling(parcel);
202 EXPECT_NE(option, nullptr);
203 }
204
205 /*
206 * @tc.number : ProcessOptionsTest_0300
207 * @tc.name : ConvertInt32ToProcessMode
208 * @tc.desc : ConvertInt32ToProcessMode
209 */
210 HWTEST_F(WantAgentTest, ProcessOptionsTest_0300, TestSize.Level1)
211 {
212 auto option = std::make_shared<ProcessOptions>();
213 int32_t value = 1;
214 option->ConvertInt32ToProcessMode(value);
215 EXPECT_NE(option, nullptr);
216 }
217
218 /*
219 * @tc.number : ProcessOptionsTest_0400
220 * @tc.name : ConvertInt32ToStartupVisibility
221 * @tc.desc : ConvertInt32ToStartupVisibility
222 */
223 HWTEST_F(WantAgentTest, ProcessOptionsTest_0400, TestSize.Level1)
224 {
225 auto option = std::make_shared<ProcessOptions>();
226 int32_t value = 1;
227 option->ConvertInt32ToStartupVisibility(value);
228 EXPECT_NE(option, nullptr);
229 }
230
231 /*
232 * @tc.number : ProcessOptionsTest_0500
233 * @tc.name : IsNewProcessMode
234 * @tc.desc : IsNewProcessMode
235 */
236 HWTEST_F(WantAgentTest, ProcessOptionsTest_0500, TestSize.Level1)
237 {
238 auto option = std::make_shared<ProcessOptions>();
239 ProcessMode value = ProcessMode::UNSPECIFIED;
240 option->IsNewProcessMode(value);
241 EXPECT_NE(option, nullptr);
242 }
243
244 /*
245 * @tc.number : ProcessOptionsTest_0600
246 * @tc.name : IsAttachToStatusBarMode
247 * @tc.desc : IsAttachToStatusBarMode
248 */
249 HWTEST_F(WantAgentTest, ProcessOptionsTest_0600, TestSize.Level1)
250 {
251 auto option = std::make_shared<ProcessOptions>();
252 ProcessMode value = ProcessMode::NEW_PROCESS_ATTACH_TO_STATUS_BAR_ITEM;
253 bool ret = option->IsAttachToStatusBarMode(value);
254 EXPECT_EQ(ret, true);
255 }
256
257
258 /*
259 * @tc.number : ProcessOptionsTest_0700
260 * @tc.name : IsAttachToStatusBarMode
261 * @tc.desc : IsAttachToStatusBarMode
262 */
263 HWTEST_F(WantAgentTest, ProcessOptionsTest_0700, TestSize.Level1)
264 {
265 auto option = std::make_shared<ProcessOptions>();
266 ProcessMode value = ProcessMode::ATTACH_TO_STATUS_BAR_ITEM;
267 bool ret = option->IsAttachToStatusBarMode(value);
268 EXPECT_EQ(ret, true);
269 }
270
271
272 /*
273 * @tc.number : ProcessOptionsTest_0800
274 * @tc.name : IsAttachToStatusBarMode
275 * @tc.desc : IsAttachToStatusBarMode
276 */
277 HWTEST_F(WantAgentTest, ProcessOptionsTest_0800, TestSize.Level1)
278 {
279 auto option = std::make_shared<ProcessOptions>();
280 ProcessMode value = ProcessMode::UNSPECIFIED;
281 bool ret = option->IsAttachToStatusBarMode(value);
282 EXPECT_EQ(ret, false);
283 }
284
285 /*
286 * @tc.number : ProcessOptionsTest_0900
287 * @tc.name : IsAttachToStatusBarItemMode
288 * @tc.desc : IsAttachToStatusBarItemMode
289 */
290 HWTEST_F(WantAgentTest, ProcessOptionsTest_0900, TestSize.Level1)
291 {
292 auto option = std::make_shared<ProcessOptions>();
293 ProcessMode value = ProcessMode::UNSPECIFIED;
294 bool ret = option->IsAttachToStatusBarItemMode(value);
295 EXPECT_EQ(ret, false);
296 }
297
298 /*
299 * @tc.number : ProcessOptionsTest_1000
300 * @tc.name : IsNewHiddenProcessMode
301 * @tc.desc : IsNewHiddenProcessMode
302 */
303 HWTEST_F(WantAgentTest, ProcessOptionsTest_1000, TestSize.Level1)
304 {
305 ProcessMode value = ProcessMode::NEW_HIDDEN_PROCESS;
306 EXPECT_EQ(ProcessOptions::IsNewHiddenProcessMode(value), true);
307 }
308
309
310 } // namespace OHOS::AbilityRuntime::WantAgent
311