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<WantAgent> wantAgent = std::make_shared<WantAgent>(nullptr);
80 EXPECT_EQ(wantAgent->GetPendingWant(), nullptr);
81 }
82
83 /*
84 * @tc.number : WantAgent_0200
85 * @tc.name : WantAgentInfo Constructors
86 * @tc.desc : 1.Constructors and GetPendingWant
87 */
88 HWTEST_F(WantAgentTest, WantAgent_0200, Function | MediumTest | Level1)
89 {
90 sptr<IWantSender> target(new (std::nothrow) PendingWantRecord());
91 std::shared_ptr<PendingWant> pendingWant = std::make_shared<PendingWant>(target);
92 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>(pendingWant);
93 EXPECT_EQ(wantAgent->GetPendingWant(), pendingWant);
94 }
95
96 /*
97 * @tc.number : WantAgent_0300
98 * @tc.name : WantAgentInfo Constructors
99 * @tc.desc : 1.Constructors and SetPendingWant
100 */
101 HWTEST_F(WantAgentTest, WantAgent_0300, Function | MediumTest | Level1)
102 {
103 sptr<IWantSender> target(new (std::nothrow) PendingWantRecord());
104 std::shared_ptr<PendingWant> pendingWant = std::make_shared<PendingWant>(target);
105 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>(pendingWant);
106 EXPECT_NE(wantAgent, nullptr);
107 wantAgent->SetPendingWant(pendingWant);
108 }
109
110 /*
111 * @tc.number : WantAgent_0400
112 * @tc.name : WantAgentInfo Constructors
113 * @tc.desc : 1.Constructors and Marshalling
114 */
115 HWTEST_F(WantAgentTest, WantAgent_0400, Function | MediumTest | Level1)
116 {
117 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>(nullptr);
118 Parcel parcel;
119 bool ret = wantAgent->Marshalling(parcel);
120 EXPECT_EQ(ret, true);
121 }
122
123 /*
124 * @tc.number : WantAgent_0500
125 * @tc.name : WantAgentInfo Constructors
126 * @tc.desc : 1.Constructors and Unmarshalling
127 */
128 HWTEST_F(WantAgentTest, WantAgent_0500, Function | MediumTest | Level1)
129 {
130 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>(nullptr);
131 Parcel parcel;
132 bool ret = wantAgent->Unmarshalling(parcel);
133 EXPECT_EQ(ret, true);
134 }
135
136 /*
137 * @tc.number : WantAgent_0600
138 * @tc.name : SetIsMultithreadingSupported test
139 * @tc.desc : SetIsMultithreadingSupported
140 */
141 HWTEST_F(WantAgentTest, WantAgent_0600, Function | MediumTest | Level1)
142 {
143 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>();
144 wantAgent->SetIsMultithreadingSupported(true);
145 EXPECT_EQ(wantAgent->isMultithreadingSupported_, true);
146 }
147
148 /*
149 * @tc.number : WantAgent_0700
150 * @tc.name : GetIsMultithreadingSupported test
151 * @tc.desc : GetIsMultithreadingSupported
152 */
153 HWTEST_F(WantAgentTest, WantAgent_0700, Function | MediumTest | Level1)
154 {
155 std::shared_ptr<WantAgent> wantAgent = std::make_shared<WantAgent>();
156 wantAgent->isMultithreadingSupported_ = true;
157 bool test = wantAgent->GetIsMultithreadingSupported();
158 EXPECT_EQ(test, true);
159 }
160
161 /*
162 * @tc.number : ProcessOptionsTest_0100
163 * @tc.name : Marshalling
164 * @tc.desc : Marshalling
165 */
166 HWTEST_F(WantAgentTest, ProcessOptionsTest_0100, TestSize.Level1)
167 {
168 auto option = std::make_shared<ProcessOptions>();
169 Parcel parcel;
170 auto result = option->Marshalling(parcel);
171 EXPECT_EQ(result, true);
172 }
173
174 /*
175 * @tc.number : ProcessOptionsTest_0200
176 * @tc.name : Unmarshalling
177 * @tc.desc : Unmarshalling
178 */
179 HWTEST_F(WantAgentTest, ProcessOptionsTest_0200, TestSize.Level1)
180 {
181 auto option = std::make_shared<ProcessOptions>();
182 Parcel parcel;
183 option->Unmarshalling(parcel);
184 EXPECT_NE(option, nullptr);
185 }
186
187 /*
188 * @tc.number : ProcessOptionsTest_0300
189 * @tc.name : ConvertInt32ToProcessMode
190 * @tc.desc : ConvertInt32ToProcessMode
191 */
192 HWTEST_F(WantAgentTest, ProcessOptionsTest_0300, TestSize.Level1)
193 {
194 auto option = std::make_shared<ProcessOptions>();
195 int32_t value = 1;
196 option->ConvertInt32ToProcessMode(value);
197 EXPECT_NE(option, nullptr);
198 }
199
200 /*
201 * @tc.number : ProcessOptionsTest_0400
202 * @tc.name : ConvertInt32ToStartupVisibility
203 * @tc.desc : ConvertInt32ToStartupVisibility
204 */
205 HWTEST_F(WantAgentTest, ProcessOptionsTest_0400, TestSize.Level1)
206 {
207 auto option = std::make_shared<ProcessOptions>();
208 int32_t value = 1;
209 option->ConvertInt32ToStartupVisibility(value);
210 EXPECT_NE(option, nullptr);
211 }
212
213 /*
214 * @tc.number : ProcessOptionsTest_0500
215 * @tc.name : IsNewProcessMode
216 * @tc.desc : IsNewProcessMode
217 */
218 HWTEST_F(WantAgentTest, ProcessOptionsTest_0500, TestSize.Level1)
219 {
220 auto option = std::make_shared<ProcessOptions>();
221 ProcessMode value = ProcessMode::UNSPECIFIED;
222 option->IsNewProcessMode(value);
223 EXPECT_NE(option, nullptr);
224 }
225
226 /*
227 * @tc.number : ProcessOptionsTest_0600
228 * @tc.name : IsAttachToStatusBarMode
229 * @tc.desc : IsAttachToStatusBarMode
230 */
231 HWTEST_F(WantAgentTest, ProcessOptionsTest_0600, TestSize.Level1)
232 {
233 auto option = std::make_shared<ProcessOptions>();
234 ProcessMode value = ProcessMode::NEW_PROCESS_ATTACH_TO_STATUS_BAR_ITEM;
235 bool ret = option->IsAttachToStatusBarMode(value);
236 EXPECT_EQ(ret, true);
237 }
238
239
240 /*
241 * @tc.number : ProcessOptionsTest_0700
242 * @tc.name : IsAttachToStatusBarMode
243 * @tc.desc : IsAttachToStatusBarMode
244 */
245 HWTEST_F(WantAgentTest, ProcessOptionsTest_0700, TestSize.Level1)
246 {
247 auto option = std::make_shared<ProcessOptions>();
248 ProcessMode value = ProcessMode::ATTACH_TO_STATUS_BAR_ITEM;
249 bool ret = option->IsAttachToStatusBarMode(value);
250 EXPECT_EQ(ret, true);
251 }
252
253
254 /*
255 * @tc.number : ProcessOptionsTest_0800
256 * @tc.name : IsAttachToStatusBarMode
257 * @tc.desc : IsAttachToStatusBarMode
258 */
259 HWTEST_F(WantAgentTest, ProcessOptionsTest_0800, TestSize.Level1)
260 {
261 auto option = std::make_shared<ProcessOptions>();
262 ProcessMode value = ProcessMode::UNSPECIFIED;
263 bool ret = option->IsAttachToStatusBarMode(value);
264 EXPECT_EQ(ret, false);
265 }
266
267 /*
268 * @tc.number : ProcessOptionsTest_0900
269 * @tc.name : IsAttachToStatusBarItemMode
270 * @tc.desc : IsAttachToStatusBarItemMode
271 */
272 HWTEST_F(WantAgentTest, ProcessOptionsTest_0900, TestSize.Level1)
273 {
274 auto option = std::make_shared<ProcessOptions>();
275 ProcessMode value = ProcessMode::UNSPECIFIED;
276 bool ret = option->IsAttachToStatusBarItemMode(value);
277 EXPECT_EQ(ret, false);
278 }
279
280 /*
281 * @tc.number : ProcessOptionsTest_1000
282 * @tc.name : IsNewHiddenProcessMode
283 * @tc.desc : IsNewHiddenProcessMode
284 */
285 HWTEST_F(WantAgentTest, ProcessOptionsTest_1000, TestSize.Level1)
286 {
287 ProcessMode value = ProcessMode::NEW_HIDDEN_PROCESS;
288 EXPECT_EQ(ProcessOptions::IsNewHiddenProcessMode(value), true);
289 }
290 } // namespace OHOS::AbilityRuntime::WantAgent
291