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 : ProcessOptionsTest_0100
138 * @tc.name : Marshalling
139 * @tc.desc : Marshalling
140 */
141 HWTEST_F(WantAgentTest, ProcessOptionsTest_0100, TestSize.Level1)
142 {
143 auto option = std::make_shared<ProcessOptions>();
144 Parcel parcel;
145 auto result = option->Marshalling(parcel);
146 EXPECT_EQ(result, true);
147 }
148
149 /*
150 * @tc.number : ProcessOptionsTest_0200
151 * @tc.name : Unmarshalling
152 * @tc.desc : Unmarshalling
153 */
154 HWTEST_F(WantAgentTest, ProcessOptionsTest_0200, TestSize.Level1)
155 {
156 auto option = std::make_shared<ProcessOptions>();
157 Parcel parcel;
158 option->Unmarshalling(parcel);
159 EXPECT_NE(option, nullptr);
160 }
161
162 /*
163 * @tc.number : ProcessOptionsTest_0300
164 * @tc.name : ConvertInt32ToProcessMode
165 * @tc.desc : ConvertInt32ToProcessMode
166 */
167 HWTEST_F(WantAgentTest, ProcessOptionsTest_0300, TestSize.Level1)
168 {
169 auto option = std::make_shared<ProcessOptions>();
170 int32_t value = 1;
171 option->ConvertInt32ToProcessMode(value);
172 EXPECT_NE(option, nullptr);
173 }
174
175 /*
176 * @tc.number : ProcessOptionsTest_0400
177 * @tc.name : ConvertInt32ToStartupVisibility
178 * @tc.desc : ConvertInt32ToStartupVisibility
179 */
180 HWTEST_F(WantAgentTest, ProcessOptionsTest_0400, TestSize.Level1)
181 {
182 auto option = std::make_shared<ProcessOptions>();
183 int32_t value = 1;
184 option->ConvertInt32ToStartupVisibility(value);
185 EXPECT_NE(option, nullptr);
186 }
187
188 /*
189 * @tc.number : ProcessOptionsTest_0500
190 * @tc.name : IsNewProcessMode
191 * @tc.desc : IsNewProcessMode
192 */
193 HWTEST_F(WantAgentTest, ProcessOptionsTest_0500, TestSize.Level1)
194 {
195 auto option = std::make_shared<ProcessOptions>();
196 ProcessMode value = ProcessMode::UNSPECIFIED;
197 option->IsNewProcessMode(value);
198 EXPECT_NE(option, nullptr);
199 }
200
201 /*
202 * @tc.number : ProcessOptionsTest_0600
203 * @tc.name : IsAttachToStatusBarMode
204 * @tc.desc : IsAttachToStatusBarMode
205 */
206 HWTEST_F(WantAgentTest, ProcessOptionsTest_0600, TestSize.Level1)
207 {
208 auto option = std::make_shared<ProcessOptions>();
209 ProcessMode value = ProcessMode::NEW_PROCESS_ATTACH_TO_STATUS_BAR_ITEM;
210 bool ret = option->IsAttachToStatusBarMode(value);
211 EXPECT_EQ(ret, true);
212 }
213
214
215 /*
216 * @tc.number : ProcessOptionsTest_0700
217 * @tc.name : IsAttachToStatusBarMode
218 * @tc.desc : IsAttachToStatusBarMode
219 */
220 HWTEST_F(WantAgentTest, ProcessOptionsTest_0700, TestSize.Level1)
221 {
222 auto option = std::make_shared<ProcessOptions>();
223 ProcessMode value = ProcessMode::ATTACH_TO_STATUS_BAR_ITEM;
224 bool ret = option->IsAttachToStatusBarMode(value);
225 EXPECT_EQ(ret, true);
226 }
227
228
229 /*
230 * @tc.number : ProcessOptionsTest_0800
231 * @tc.name : IsAttachToStatusBarMode
232 * @tc.desc : IsAttachToStatusBarMode
233 */
234 HWTEST_F(WantAgentTest, ProcessOptionsTest_0800, TestSize.Level1)
235 {
236 auto option = std::make_shared<ProcessOptions>();
237 ProcessMode value = ProcessMode::UNSPECIFIED;
238 bool ret = option->IsAttachToStatusBarMode(value);
239 EXPECT_EQ(ret, false);
240 }
241 } // namespace OHOS::AbilityRuntime::WantAgent
242