1 /*
2 * Copyright (c) 2021 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 <singleton.h>
17 #include <gtest/gtest.h>
18 #include "gmock/gmock.h"
19
20 #include "ability_context.h"
21 #include "ohos_application.h"
22 #include "ability_handler.h"
23 #include "ability_info.h"
24 #include "ability.h"
25
26 #include "mock_ability_manager_client_interface1.h"
27 #include "mock_resourceManager_interface1.h"
28
29 namespace OHOS {
30 namespace AppExecFwk {
31 using namespace testing::ext;
32
33 class AbilityContextInterfaceTest : public testing::Test {
34 public:
AbilityContextInterfaceTest()35 AbilityContextInterfaceTest() : context_(nullptr)
36 {}
~AbilityContextInterfaceTest()37 ~AbilityContextInterfaceTest()
38 {}
39 std::unique_ptr<OHOS::AppExecFwk::AbilityContext> context_ = nullptr;
40 static void SetUpTestCase(void);
41 static void TearDownTestCase(void);
42 void SetUp();
43 void TearDown();
44 };
45
SetUpTestCase(void)46 void AbilityContextInterfaceTest::SetUpTestCase(void)
47 {}
TearDownTestCase(void)48 void AbilityContextInterfaceTest::TearDownTestCase(void)
49 {}
SetUp()50 void AbilityContextInterfaceTest::SetUp()
51 {}
TearDown()52 void AbilityContextInterfaceTest::TearDown()
53 {}
54
55 /**
56 * @tc.number: AaFwk_AbilityContext_SetColorMode_0100
57 * @tc.name: SetColorMode
58 * @tc.desc: Test the attachbasecontext call to verify that the return value of SetColorMode is correct.
59 */
60 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_SetColorMode_0100, Function | MediumTest | Level1)
61 {
62 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_SetColorMode_0100 start";
63 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
64 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
65 abilityContext->AttachBaseContext(contextDeal);
66 int testValue = 1;
67 abilityContext->SetColorMode(testValue);
68 EXPECT_EQ(testValue, abilityContext->GetColorMode());
69 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_SetColorMode_0100 end";
70 }
71
72 /**
73 * @tc.number: AaFwk_AbilityContext_SetColorMode_0200
74 * @tc.name: SetColorMode
75 * @tc.desc: Test the attachbasecontext call to verify that the return value of SetColorMode is correct.
76 */
77 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_SetColorMode_0200, Function | MediumTest | Level3)
78 {
79 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_SetColorMode_0200 start";
80 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
81 int testValue = 0;
82 abilityContext->SetColorMode(testValue);
83 EXPECT_GT(testValue, abilityContext->GetColorMode());
84 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_SetColorMode_0200 end";
85 }
86
87 /**
88 * @tc.number: AaFwk_AbilityContext_GetColorMode_0100
89 * @tc.name: GetColorMode
90 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetColorMode is correct.
91 */
92 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetColorMode_0100, Function | MediumTest | Level1)
93 {
94 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetColorMode_0100 start";
95 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
96 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
97 abilityContext->AttachBaseContext(contextDeal);
98 int testValue = 1;
99 abilityContext->SetColorMode(testValue);
100 EXPECT_EQ(testValue, abilityContext->GetColorMode());
101 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetColorMode_0100 end";
102 }
103
104 /**
105 * @tc.number: AaFwk_AbilityContext_GetColorMode_0200
106 * @tc.name: GetColorMode
107 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetColorMode is correct.
108 */
109 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetColorMode_0200, Function | MediumTest | Level3)
110 {
111 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetColorMode_0200 start";
112 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
113 int testValue = 0;
114 abilityContext->SetColorMode(testValue);
115 EXPECT_GT(testValue, abilityContext->GetColorMode());
116 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetColorMode_0200 end";
117 }
118
119 /**
120 * @tc.number: AaFwk_AbilityContext_SetTheme_0100
121 * @tc.name: SetTheme
122 * @tc.desc: Test the attachbasecontext call to verify that the return value of SetTheme is correct.
123 */
124 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_SetTheme_0100, Function | MediumTest | Level1)
125 {
126 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_SetTheme_0100 start";
127 int testValue = 1;
128 std::map<std::string, std::string> testList = {
129 {"Pattern1", "PatternA"}, {"Pattern2", "PatternB"}, {"Pattern3", "PatternC"} };
130 std::shared_ptr<Global::Resource::ResourceManager2> resourceManager(Global::Resource::CreateResourceManager2());
131 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
132 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
133 ASSERT_NE(abilityContext, nullptr);
134 resourceManager->SetThemeById(testValue, testList);
135 contextDeal->initResourceManager(resourceManager);
136 abilityContext->AttachBaseContext(contextDeal);
137 abilityContext->SetTheme(testValue);
138 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_SetTheme_0100 end";
139 }
140
141 /**
142 * @tc.number: AaFwk_AbilityContext_SetTheme_0200
143 * @tc.name: SetTheme
144 * @tc.desc: Test the attachbasecontext call to verify that the return value of SetTheme is correct.
145 */
146 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_SetTheme_0200, Function | MediumTest | Level3)
147 {
148 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_SetTheme_0200 start";
149 int testValue = 2;
150 std::shared_ptr<Global::Resource::ResourceManager2> resourceManager(Global::Resource::CreateResourceManager2());
151 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
152 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
153 ASSERT_NE(abilityContext, nullptr);
154 abilityContext->SetTheme(testValue);
155 abilityContext->AttachBaseContext(contextDeal);
156 abilityContext->SetTheme(testValue);
157 contextDeal->initResourceManager(resourceManager);
158 abilityContext->SetTheme(testValue);
159 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_SetTheme_0200 end";
160 }
161
162 /**
163 * @tc.number: AaFwk_AbilityContext_StartAbilities_0100
164 * @tc.name: StartAbilities
165 * @tc.desc: Test the attachbasecontext call to verify that the return value of StartAbilities is correct.
166 */
167 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_StartAbilities_0100, Function | MediumTest | Level1)
168 {
169 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_StartAbilities_0100 start";
170 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
171 std::shared_ptr<MockAbilityContextTest> abilityContext = std::make_shared<MockAbilityContextTest>();
172 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
173 abilityInfo->type = OHOS::AppExecFwk::AbilityType::DATA;
174 contextDeal->SetAbilityInfo(abilityInfo);
175 abilityContext->AttachBaseContext(contextDeal);
176 std::vector<AAFwk::Want> testlist = { AAFwk::Want(), AAFwk::Want() };
177 abilityContext->StartAbilities(testlist);
178 EXPECT_TRUE((testlist.size() == abilityContext->GetStartAbilityRunCount()));
179 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_StartAbilities_0100 end";
180 }
181
182 /**
183 * @tc.number: AaFwk_AbilityContext_GetPreferencesDir_0100
184 * @tc.name: GetPreferencesDir
185 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetPreferencesDir is correct.
186 */
187 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetPreferencesDir_0100, Function | MediumTest | Level1)
188 {
189 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetPreferencesDir_0100 start";
190 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
191 std::shared_ptr<ApplicationInfo> applicationInfo = std::make_shared<ApplicationInfo>();
192 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
193 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
194 const std::string testValue = "./1234test/preferences";
195 abilityInfo->name = "test1234.1234test";
196 applicationInfo->dataDir = ".";
197 contextDeal->SetAbilityInfo(abilityInfo);
198 contextDeal->SetApplicationInfo(applicationInfo);
199 abilityContext->AttachBaseContext(contextDeal);
200 EXPECT_STREQ(testValue.c_str(), abilityContext->GetPreferencesDir().c_str());
201 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetPreferencesDir_0100 end";
202 }
203
204 /**
205 * @tc.number: AaFwk_AbilityContext_GetPattern_0100
206 * @tc.name: GetPattern
207 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetPattern is correct.
208 */
209 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetPattern_0100, Function | MediumTest | Level1)
210 {
211 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetPattern_0100 start";
212 int testValue = 0;
213 std::map<std::string, std::string> testList = {
214 {"Pattern1", "PatternA"}, {"Pattern2", "PatternB"}, {"Pattern3", "PatternC"} };
215 std::shared_ptr<Global::Resource::ResourceManager2> resourceManager(Global::Resource::CreateResourceManager2());
216 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
217 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
218 resourceManager->SetPatternById(testValue, testList);
219 contextDeal->initResourceManager(resourceManager);
220 abilityContext->AttachBaseContext(contextDeal);
221 abilityContext->SetPattern(testValue);
222 std::map<std::string, std::string> retVal = abilityContext->GetPattern();
223 EXPECT_TRUE((retVal == testList));
224 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetPattern_0100 end";
225 }
226
227 /**
228 * @tc.number: AaFwk_AbilityContext_GetTheme_0100
229 * @tc.name: GetTheme
230 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetTheme is correct.
231 */
232 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetTheme_0100, Function | MediumTest | Level1)
233 {
234 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetTheme_0100 start";
235 int testValue = 0;
236 std::map<std::string, std::string> testList = { {"Theme1", "ThemeA"}, {"Theme2", "ThemeB"}, {"Theme3", "ThemeC"} };
237 std::shared_ptr<Global::Resource::ResourceManager2> resourceManager(Global::Resource::CreateResourceManager2());
238 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
239 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
240 ASSERT_NE(abilityContext, nullptr);
241 resourceManager->SetThemeById(testValue, testList);
242 contextDeal->initResourceManager(resourceManager);
243 abilityContext->AttachBaseContext(contextDeal);
244 std::map<std::string, std::string> retVal = abilityContext->GetTheme();
245 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetTheme_0100 end";
246 }
247
248 /**
249 * @tc.number: AaFwk_AbilityContext_GetString_ById_0100
250 * @tc.name: GetString
251 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetString is correct.
252 */
253 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetString_ById_0100, Function | MediumTest | Level1)
254 {
255 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetString_ById_0100 start";
256 std::shared_ptr<Global::Resource::ResourceManager2> resourceManager(Global::Resource::CreateResourceManager2());
257 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
258 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
259 int testCount = 0;
260 std::string testValue = "GetString test";
261 resourceManager->SetStringById(testCount, testValue);
262 contextDeal->initResourceManager(resourceManager);
263 abilityContext->AttachBaseContext(contextDeal);
264 EXPECT_STREQ(testValue.c_str(), abilityContext->GetString(testCount).c_str());
265 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetString_ById_0100 end";
266 }
267
268 /**
269 * @tc.number: AaFwk_AbilityContext_GetString_ByIdAndFormat_0100
270 * @tc.name: GetString
271 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetString is correct.
272 */
273 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetString_ByIdAndFormat_0100, Function | MediumTest | Level1)
274 {
275 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetString_ByIdAndFormat_0100 start";
276 std::shared_ptr<Global::Resource::ResourceManager2> resourceManager(Global::Resource::CreateResourceManager2());
277 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
278 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
279 ASSERT_NE(abilityContext, nullptr);
280 std::string testByName = "";
281 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetString_ByIdAndFormat_0100 end";
282 }
283
284 /**
285 * @tc.number: AaFwk_AbilityContext_GetStringArray_0100
286 * @tc.name: GetStringArray
287 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetStringArray is correct.
288 */
289 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetStringArray_0100, Function | MediumTest | Level1)
290 {
291 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetStringArray_0100 start";
292 std::shared_ptr<Global::Resource::ResourceManager2> resourceManager(Global::Resource::CreateResourceManager2());
293 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
294 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
295 int testCount = 0;
296 std::vector<std::string> testValue = { "123", "456", "789" };
297 resourceManager->SetStringArrayById(testCount, testValue);
298 contextDeal->initResourceManager(resourceManager);
299 abilityContext->AttachBaseContext(contextDeal);
300 std::vector<std::string> retVal = abilityContext->GetStringArray(testCount);
301 EXPECT_TRUE((retVal == testValue));
302 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetStringArray_0100 end";
303 }
304
305 /**
306 * @tc.number: AaFwk_AbilityContext_GetStringArray_0200
307 * @tc.name: GetStringArray
308 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetStringArray is correct.
309 */
310 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetStringArray_0200, Function | MediumTest | Level3)
311 {
312 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetStringArray_0200 start";
313 std::shared_ptr<Global::Resource::ResourceManager2> resourceManager(Global::Resource::CreateResourceManager2());
314 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
315 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
316 int testCount = 0;
317 std::vector<std::string> testValue = { "123", "456", "789" };
318 resourceManager->SetStringArrayById(testCount + 1, testValue);
319 contextDeal->initResourceManager(resourceManager);
320 abilityContext->AttachBaseContext(contextDeal);
321 std::vector<std::string> retVal = abilityContext->GetStringArray(testCount);
322 EXPECT_FALSE((retVal == testValue));
323 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetStringArray_0200 end";
324 }
325
326 /**
327 * @tc.number: AaFwk_AbilityContext_GetIntArray_0100
328 * @tc.name: GetIntArray
329 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetIntArray is correct.
330 */
331 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetIntArray_0100, Function | MediumTest | Level1)
332 {
333 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetIntArray_0100 start";
334 std::shared_ptr<Global::Resource::ResourceManager2> resourceManager(Global::Resource::CreateResourceManager2());
335 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
336 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
337 int testCount = 0;
338 std::vector<int> testValue = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
339 resourceManager->SetIntArrayById(testCount, testValue);
340 contextDeal->initResourceManager(resourceManager);
341 abilityContext->AttachBaseContext(contextDeal);
342 std::vector<int> retVal = abilityContext->GetIntArray(testCount);
343 EXPECT_TRUE((retVal == testValue));
344 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetIntArray_0100 end";
345 }
346
347 /**
348 * @tc.number: AaFwk_AbilityContext_GetIntArray_0200
349 * @tc.name: GetIntArray
350 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetIntArray is correct.
351 */
352 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetIntArray_0200, Function | MediumTest | Level3)
353 {
354 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetIntArray_0200 start";
355 std::shared_ptr<Global::Resource::ResourceManager2> resourceManager(Global::Resource::CreateResourceManager2());
356 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
357 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
358 int testCount = 0;
359 std::vector<int> testValue = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
360 resourceManager->SetIntArrayById(testCount + 1, testValue);
361 contextDeal->initResourceManager(resourceManager);
362 abilityContext->AttachBaseContext(contextDeal);
363 std::vector<int> retVal = abilityContext->GetIntArray(testCount);
364 EXPECT_FALSE((retVal == testValue));
365 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetIntArray_0200 end";
366 }
367
368 /**
369 * @tc.number: AaFwk_AbilityContext_GetColor_0100
370 * @tc.name: GetColor
371 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetColor is correct.
372 */
373 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetColor_0100, Function | MediumTest | Level1)
374 {
375 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetColor_0100 start";
376 std::shared_ptr<Global::Resource::ResourceManager2> resourceManager(Global::Resource::CreateResourceManager2());
377 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
378 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
379 int testCount = 0;
380 uint32_t testValue = 1;
381 const int testVal = static_cast<int>(testValue);
382 resourceManager->SetColorById(testCount, testValue);
383 contextDeal->initResourceManager(resourceManager);
384 abilityContext->AttachBaseContext(contextDeal);
385 EXPECT_EQ(testVal, abilityContext->GetColor(testCount));
386 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetColor_0100 end";
387 }
388
389 /**
390 * @tc.number: AaFwk_AbilityContext_GetColor_0200
391 * @tc.name: GetColor
392 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetColor is correct.
393 */
394 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetColor_0200, Function | MediumTest | Level3)
395 {
396 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetColor_0200 start";
397 std::shared_ptr<Global::Resource::ResourceManager2> resourceManager(Global::Resource::CreateResourceManager2());
398 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
399 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
400 int testCount = 0;
401 uint32_t testValue = 1;
402 const int testVal = static_cast<int>(testValue);
403 resourceManager->SetColorById(testCount + 1, testValue);
404 contextDeal->initResourceManager(resourceManager);
405 abilityContext->AttachBaseContext(contextDeal);
406 EXPECT_NE(testVal, abilityContext->GetColor(testCount));
407 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetColor_0200 end";
408 }
409
410 /**
411 * @tc.number: AaFwk_AbilityContext_GetThemeId_0100
412 * @tc.name: GetThemeId
413 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetThemeId is correct.
414 */
415 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetThemeId_0100, Function | MediumTest | Level1)
416 {
417 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetThemeId_0100 start";
418 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
419 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
420 ASSERT_NE(abilityContext, nullptr);
421 abilityContext->AttachBaseContext(contextDeal);
422 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetThemeId_0100 end";
423 }
424
425 /**
426 * @tc.number: AaFwk_AbilityContext_GetDisplayOrientation_0100
427 * @tc.name: GetDisplayOrientation
428 * @tc.desc: Test the attachbasecontext call to verify that the return value of GetDisplayOrientation is correct.
429 */
430 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetDisplayOrientation_0100, Function | MediumTest | Level1)
431 {
432 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetDisplayOrientation_0100 start";
433 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
434 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
435 std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
436 int testValue = 1;
437 abilityInfo->orientation = static_cast<DisplayOrientation>(testValue);
438 contextDeal->SetAbilityInfo(abilityInfo);
439 abilityContext->AttachBaseContext(contextDeal);
440 EXPECT_EQ(testValue, abilityContext->GetDisplayOrientation());
441 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetDisplayOrientation_0100 end";
442 }
443
444 /**
445 * @tc.number: AaFwk_AbilityContext_SetPattern_0100
446 * @tc.name: SetPattern
447 * @tc.desc: Test the attachbasecontext call to verify that the return value of SetPattern is correct.
448 */
449 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_SetPattern_0100, Function | MediumTest | Level1)
450 {
451 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_SetPattern_0100 start";
452 std::shared_ptr<Global::Resource::ResourceManager2> resourceManager(Global::Resource::CreateResourceManager2());
453 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
454 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
455 int testCount = 0;
456 std::map<std::string, std::string> testList = { {"123", "abc"}, {"456", "def"} };
457 resourceManager->SetPatternById(testCount, testList);
458 contextDeal->initResourceManager(resourceManager);
459 abilityContext->AttachBaseContext(contextDeal);
460 abilityContext->SetPattern(testCount);
461 std::map<std::string, std::string> retVal;
462 EXPECT_FALSE((retVal == testList));
463 retVal = abilityContext->GetPattern();
464 EXPECT_TRUE((retVal == testList));
465 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_SetPattern_0100 end";
466 }
467
468 HWTEST_F(AbilityContextInterfaceTest, AaFwk_AbilityContext_GetMissionId_0100, Function | MediumTest | Level1)
469 {
470 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetMissionId_0100 start";
471 std::shared_ptr<AbilityContext> abilityContext = std::make_shared<AbilityContext>();
472 std::shared_ptr<MockAbilityContextDeal> contextDeal = std::make_shared<MockAbilityContextDeal>();
473 const int testValue = 1;
474
475 EXPECT_NE(testValue, abilityContext->GetMissionId());
476
477 abilityContext->AttachBaseContext(contextDeal);
478
479 EXPECT_NE(testValue, abilityContext->GetMissionId());
480
481 AAFwk::LifeCycleStateInfo lifeInfo;
482 lifeInfo.missionId = testValue;
483 contextDeal->SetLifeCycleStateInfo(lifeInfo);
484
485 EXPECT_EQ(testValue, abilityContext->GetMissionId());
486
487 GTEST_LOG_(INFO) << "AaFwk_AbilityContext_GetMissionId_0100 end";
488 }
489 } // namespace AppExecFwk
490 } // namespace OHOS
491