1 /*
2 * Copyright (c) 2022-2023 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 #define private public
18 #include "application_context.h"
19 #undef private
20 #include "mock_ability_token.h"
21 #include "mock_application_state_change_callback.h"
22 #include "mock_context_impl.h"
23 #include "running_process_info.h"
24 #include "want.h"
25 #include "configuration_convertor.h"
26 #include "ability_manager_errors.h"
27 #include "exit_reason.h"
28 using namespace testing::ext;
29
30
31 namespace OHOS {
32 namespace AbilityRuntime {
33 class ApplicationContextTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp() override;
38 void TearDown() override;
39 std::shared_ptr<ApplicationContext> context_ = nullptr;
40 std::shared_ptr<MockContextImpl> mock_ = nullptr;
41 };
42
SetUpTestCase(void)43 void ApplicationContextTest::SetUpTestCase(void)
44 {}
45
TearDownTestCase(void)46 void ApplicationContextTest::TearDownTestCase(void)
47 {}
48
SetUp()49 void ApplicationContextTest::SetUp()
50 {
51 context_ = std::make_shared<ApplicationContext>();
52 mock_ = std::make_shared<MockContextImpl>();
53 }
54
TearDown()55 void ApplicationContextTest::TearDown()
56 {}
57
58 /**
59 * @tc.number: RegisterAbilityLifecycleCallback_0100
60 * @tc.name: RegisterAbilityLifecycleCallback
61 * @tc.desc: Register Ability Lifecycle Callback
62 */
63 HWTEST_F(ApplicationContextTest, RegisterAbilityLifecycleCallback_0100, TestSize.Level1)
64 {
65 GTEST_LOG_(INFO) << "RegisterAbilityLifecycleCallback_0100 start";
66 context_->callbacks_.clear();
67 std::shared_ptr<AbilityLifecycleCallback> abilityLifecycleCallback = nullptr;
68 context_->RegisterAbilityLifecycleCallback(abilityLifecycleCallback);
69 EXPECT_TRUE(context_->IsAbilityLifecycleCallbackEmpty());
70 GTEST_LOG_(INFO) << "RegisterAbilityLifecycleCallback_0100 end";
71 }
72
73 /**
74 * @tc.number: RegisterEnvironmentCallback_0100
75 * @tc.name: RegisterEnvironmentCallback
76 * @tc.desc: Register Environment Callback
77 */
78 HWTEST_F(ApplicationContextTest, RegisterEnvironmentCallback_0100, TestSize.Level1)
79 {
80 GTEST_LOG_(INFO) << "RegisterEnvironmentCallback_0100 start";
81 context_->envCallbacks_.clear();
82 std::shared_ptr<EnvironmentCallback> environmentCallback = nullptr;
83 context_->RegisterEnvironmentCallback(environmentCallback);
84 EXPECT_TRUE(context_->envCallbacks_.empty());
85 GTEST_LOG_(INFO) << "RegisterEnvironmentCallback_0100 end";
86 }
87
88 /**
89 * @tc.number: GetBundleName_0100
90 * @tc.name: GetBundleName
91 * @tc.desc: Get BundleName failed
92 */
93 HWTEST_F(ApplicationContextTest, GetBundleName_0100, TestSize.Level1)
94 {
95 GTEST_LOG_(INFO) << "GetBundleName_0100 start";
96 std::shared_ptr<ContextImpl> contextImpl = nullptr;
97 context_->AttachContextImpl(contextImpl);
98 auto ret = context_->GetBundleName();
99 EXPECT_EQ(ret, "");
100 GTEST_LOG_(INFO) << "GetBundleName_0100 end";
101 }
102
103 /**
104 * @tc.number: GetBundleName_0200
105 * @tc.name: GetBundleName
106 * @tc.desc: Get BundleName sucess
107 */
108 HWTEST_F(ApplicationContextTest, GetBundleName_0200, TestSize.Level1)
109 {
110 GTEST_LOG_(INFO) << "GetBundleName_0200 start";
111 context_->AttachContextImpl(mock_);
112 auto ret = context_->GetBundleName();
113 EXPECT_EQ(ret, "com.test.bundleName");
114 GTEST_LOG_(INFO) << "GetBundleName_0200 end";
115 }
116
117 /**
118 * @tc.number: CreateBundleContext_0100
119 * @tc.name: CreateBundleContext
120 * @tc.desc: Create BundleContext failed
121 */
122 HWTEST_F(ApplicationContextTest, CreateBundleContext_0100, TestSize.Level1)
123 {
124 GTEST_LOG_(INFO) << "CreateBundleContext_0100 start";
125 std::shared_ptr<ContextImpl> contextImpl = nullptr;
126 context_->AttachContextImpl(contextImpl);
127 std::string bundleName = "com.test.bundleName";
128 auto ret = context_->CreateBundleContext(bundleName);
129 EXPECT_EQ(ret, nullptr);
130 GTEST_LOG_(INFO) << "CreateBundleContext_0100 end";
131 }
132
133 /**
134 * @tc.number: CreateBundleContext_0200
135 * @tc.name: CreateBundleContext
136 * @tc.desc: Create BundleContext sucess
137 */
138 HWTEST_F(ApplicationContextTest, CreateBundleContext_0200, TestSize.Level1)
139 {
140 GTEST_LOG_(INFO) << "CreateBundleContext_0200 start";
141 context_->AttachContextImpl(mock_);
142 std::string bundleName = "com.test.bundleName";
143 auto ret = context_->CreateBundleContext(bundleName);
144 EXPECT_NE(ret, nullptr);
145 GTEST_LOG_(INFO) << "CreateBundleContext_0200 end";
146 }
147
148 /**
149 * @tc.number: CreateModuleContext_0100
150 * @tc.name: CreateModuleContext
151 * @tc.desc: Create ModuleContext failed
152 */
153 HWTEST_F(ApplicationContextTest, CreateModuleContext_0100, TestSize.Level1)
154 {
155 GTEST_LOG_(INFO) << "CreateModuleContext_0100 start";
156 std::shared_ptr<ContextImpl> contextImpl = nullptr;
157 context_->AttachContextImpl(contextImpl);
158 std::string moduleName = "moduleName";
159 auto ret = context_->CreateModuleContext(moduleName);
160 EXPECT_EQ(ret, nullptr);
161 GTEST_LOG_(INFO) << "CreateModuleContext_0100 end";
162 }
163
164 /**
165 * @tc.number: CreateModuleContext_0200
166 * @tc.name: CreateModuleContext
167 * @tc.desc: Create ModuleContext sucess
168 */
169 HWTEST_F(ApplicationContextTest, CreateModuleContext_0200, TestSize.Level1)
170 {
171 GTEST_LOG_(INFO) << "CreateModuleContext_0200 start";
172 context_->AttachContextImpl(mock_);
173 std::string moduleName = "moduleName";
174 auto ret = context_->CreateModuleContext(moduleName);
175 EXPECT_NE(ret, nullptr);
176 GTEST_LOG_(INFO) << "CreateModuleContext_0200 end";
177 }
178
179 /**
180 * @tc.number: CreateModuleContext_0300
181 * @tc.name: CreateModuleContext
182 * @tc.desc: Create ModuleContext failed
183 */
184 HWTEST_F(ApplicationContextTest, CreateModuleContext_0300, TestSize.Level1)
185 {
186 GTEST_LOG_(INFO) << "CreateModuleContext_0300 start";
187 std::shared_ptr<ContextImpl> contextImpl = nullptr;
188 context_->AttachContextImpl(contextImpl);
189 std::string moduleName = "moduleName";
190 std::string bundleName = "com.test.bundleName";
191 auto ret = context_->CreateModuleContext(bundleName, moduleName);
192 EXPECT_EQ(ret, nullptr);
193 GTEST_LOG_(INFO) << "CreateModuleContext_0300 end";
194 }
195
196 /**
197 * @tc.number: CreateModuleContext_0400
198 * @tc.name: CreateModuleContext
199 * @tc.desc: Create ModuleContext sucess
200 */
201 HWTEST_F(ApplicationContextTest, CreateModuleContext_0400, TestSize.Level1)
202 {
203 GTEST_LOG_(INFO) << "CreateModuleContext_0400 start";
204 context_->AttachContextImpl(mock_);
205 std::string moduleName = "moduleName";
206 std::string bundleName = "com.test.bundleName";
207 auto ret = context_->CreateModuleContext(bundleName, moduleName);
208 EXPECT_NE(ret, nullptr);
209 GTEST_LOG_(INFO) << "CreateModuleContext_0400 end";
210 }
211
212 /**
213 * @tc.number: GetApplicationInfo_0100
214 * @tc.name: GetApplicationInfo
215 * @tc.desc: Get ApplicationInfo failed
216 */
217 HWTEST_F(ApplicationContextTest, GetApplicationInfo_0100, TestSize.Level1)
218 {
219 GTEST_LOG_(INFO) << "GetApplicationInfo_0100 start";
220 std::shared_ptr<ContextImpl> contextImpl = nullptr;
221 context_->AttachContextImpl(contextImpl);
222 auto ret = context_->GetApplicationInfo();
223 EXPECT_EQ(ret, nullptr);
224 GTEST_LOG_(INFO) << "GetApplicationInfo_0100 end";
225 }
226
227 /**
228 * @tc.number: GetApplicationInfo_0200
229 * @tc.name: GetApplicationInfo
230 * @tc.desc:Get ApplicationInfo sucess
231 */
232 HWTEST_F(ApplicationContextTest, GetApplicationInfo_0200, TestSize.Level1)
233 {
234 GTEST_LOG_(INFO) << "GetApplicationInfo_0200 start";
235 context_->AttachContextImpl(mock_);
236 auto ret = context_->GetApplicationInfo();
237 EXPECT_NE(ret, nullptr);
238 GTEST_LOG_(INFO) << "GetApplicationInfo_0200 end";
239 }
240
241 /**
242 * @tc.number: GetResourceManager_0100
243 * @tc.name: GetResourceManager
244 * @tc.desc: Get ResourceManager failed
245 */
246 HWTEST_F(ApplicationContextTest, GetResourceManager_0100, TestSize.Level1)
247 {
248 GTEST_LOG_(INFO) << "GetResourceManager_0100 start";
249 std::shared_ptr<ContextImpl> contextImpl = nullptr;
250 context_->AttachContextImpl(contextImpl);
251 auto ret = context_->GetResourceManager();
252 EXPECT_EQ(ret, nullptr);
253 GTEST_LOG_(INFO) << "GetResourceManager_0100 end";
254 }
255
256 /**
257 * @tc.number: GetApplicationInfo_0200
258 * @tc.name: GetResourceManager
259 * @tc.desc:Get ResourceManager sucess
260 */
261 HWTEST_F(ApplicationContextTest, GetResourceManager_0200, TestSize.Level1)
262 {
263 GTEST_LOG_(INFO) << "GetResourceManager_0200 start";
264 context_->AttachContextImpl(mock_);
265 auto ret = context_->GetResourceManager();
266 EXPECT_NE(ret, nullptr);
267 GTEST_LOG_(INFO) << "GetResourceManager_0200 end";
268 }
269
270 /**
271 * @tc.number: GetBundleCodePath_0100
272 * @tc.name: GetBundleCodePath
273 * @tc.desc: Get BundleCode Path failed
274 */
275 HWTEST_F(ApplicationContextTest, GetBundleCodePath_0100, TestSize.Level1)
276 {
277 GTEST_LOG_(INFO) << "GetBundleCodePath_0100 start";
278 std::shared_ptr<ContextImpl> contextImpl = nullptr;
279 context_->AttachContextImpl(contextImpl);
280 auto ret = context_->GetBundleCodePath();
281 EXPECT_EQ(ret, "");
282 GTEST_LOG_(INFO) << "GetBundleCodePath_0100 end";
283 }
284
285 /**
286 * @tc.number: GetBundleCodePath_0200
287 * @tc.name: GetBundleCodePath
288 * @tc.desc:Get BundleCode Path sucess
289 */
290 HWTEST_F(ApplicationContextTest, GetBundleCodePath_0200, TestSize.Level1)
291 {
292 GTEST_LOG_(INFO) << "GetBundleCodePath_0200 start";
293 context_->AttachContextImpl(mock_);
294 auto ret = context_->GetBundleCodePath();
295 EXPECT_EQ(ret, "codePath");
296 GTEST_LOG_(INFO) << "GetBundleCodePath_0200 end";
297 }
298
299 /**
300 * @tc.number: GetHapModuleInfo_0100
301 * @tc.name: GetHapModuleInfo
302 * @tc.desc: Get HapModuleInfo failed
303 */
304 HWTEST_F(ApplicationContextTest, GetHapModuleInfo_0100, TestSize.Level1)
305 {
306 GTEST_LOG_(INFO) << "GetHapModuleInfo_0100 start";
307 auto ret = context_->GetHapModuleInfo();
308 EXPECT_EQ(ret, nullptr);
309 GTEST_LOG_(INFO) << "GetHapModuleInfo_0100 end";
310 }
311
312 /**
313 * @tc.number: GetBundleCodeDir_0100
314 * @tc.name: GetBundleCodeDir
315 * @tc.desc: Get Bundle Code Dir failed
316 */
317 HWTEST_F(ApplicationContextTest, GetBundleCodeDir_0100, TestSize.Level1)
318 {
319 GTEST_LOG_(INFO) << "GetBundleCodeDir_0100 start";
320 std::shared_ptr<ContextImpl> contextImpl = nullptr;
321 context_->AttachContextImpl(contextImpl);
322 auto ret = context_->GetBundleCodeDir();
323 EXPECT_EQ(ret, "");
324 GTEST_LOG_(INFO) << "GetBundleCodeDir_0100 end";
325 }
326
327 /**
328 * @tc.number: GetBundleCodeDir_0200
329 * @tc.name: GetBundleCodeDir
330 * @tc.desc:Get Bundle Code Dir sucess
331 */
332 HWTEST_F(ApplicationContextTest, GetBundleCodeDir_0200, TestSize.Level1)
333 {
334 GTEST_LOG_(INFO) << "GetBundleCodeDir_0200 start";
335 context_->AttachContextImpl(mock_);
336 auto ret = context_->GetBundleCodeDir();
337 EXPECT_EQ(ret, "/code");
338 GTEST_LOG_(INFO) << "GetBundleCodeDir_0200 end";
339 }
340
341 /**
342 * @tc.number: GetTempDir_0100
343 * @tc.name: GetTempDir
344 * @tc.desc: Get Temp Dir failed
345 */
346 HWTEST_F(ApplicationContextTest, GetTempDir_0100, TestSize.Level1)
347 {
348 GTEST_LOG_(INFO) << "GetTempDir_0100 start";
349 std::shared_ptr<ContextImpl> contextImpl = nullptr;
350 context_->AttachContextImpl(contextImpl);
351 auto ret = context_->GetTempDir();
352 EXPECT_EQ(ret, "");
353 GTEST_LOG_(INFO) << "GetTempDir_0100 end";
354 }
355
356 /**
357 * @tc.number: GetTempDir_0200
358 * @tc.name: GetTempDir
359 * @tc.desc:Get Temp Dir sucess
360 */
361 HWTEST_F(ApplicationContextTest, GetTempDir_0200, TestSize.Level1)
362 {
363 GTEST_LOG_(INFO) << "GetTempDir_0200 start";
364 context_->AttachContextImpl(mock_);
365 auto ret = context_->GetTempDir();
366 EXPECT_EQ(ret, "/temp");
367 GTEST_LOG_(INFO) << "GetTempDir_0200 end";
368 }
369
370 /**
371 * @tc.number: GetResourceDir_0100
372 * @tc.name: GetResourceDir
373 * @tc.desc: Get Resource Dir failed
374 */
375 HWTEST_F(ApplicationContextTest, GetResourceDir_0100, TestSize.Level1)
376 {
377 GTEST_LOG_(INFO) << "GetResourceDir_0100 start";
378 std::shared_ptr<ContextImpl> contextImpl = nullptr;
379 context_->AttachContextImpl(contextImpl);
380 auto ret = context_->GetResourceDir();
381 EXPECT_EQ(ret, "");
382 GTEST_LOG_(INFO) << "GetResourceDir_0100 end";
383 }
384
385 /**
386 * @tc.number: GetResourceDir_0200
387 * @tc.name: GetResourceDir
388 * @tc.desc: Get Resource Dir failed
389 */
390 HWTEST_F(ApplicationContextTest, GetResourceDir_0200, TestSize.Level1)
391 {
392 GTEST_LOG_(INFO) << "GetResourceDir_0200 start";
393 context_->AttachContextImpl(mock_);
394 auto ret = context_->GetResourceDir();
395 EXPECT_EQ(ret, "/resfile");
396 GTEST_LOG_(INFO) << "GetResourceDir_0200 end";
397 }
398
399 /**
400 * @tc.number: GetGroupDir_0100
401 * @tc.name: GetGroupDir
402 * @tc.desc: Get Group Dir failed
403 */
404 HWTEST_F(ApplicationContextTest, GetGroupDir_0100, TestSize.Level1)
405 {
406 GTEST_LOG_(INFO) << "GetGroupDir_0100 start";
407 std::shared_ptr<ContextImpl> contextImpl = nullptr;
408 context_->AttachContextImpl(contextImpl);
409 auto ret = context_->GetGroupDir("1");
410 EXPECT_EQ(ret, "");
411 GTEST_LOG_(INFO) << "GetGroupDir_0100 end";
412 }
413
414 /**
415 * @tc.number: GetGroupDir_0200
416 * @tc.name: GetGroupDir
417 * @tc.desc:Get Group Dir sucess
418 */
419 HWTEST_F(ApplicationContextTest, GetGroupDir_0200, TestSize.Level1)
420 {
421 GTEST_LOG_(INFO) << "GetGroupDir_0200 start";
422 context_->AttachContextImpl(mock_);
423 auto ret = context_->GetGroupDir("1");
424 EXPECT_EQ(ret, "/group");
425 GTEST_LOG_(INFO) << "GetGroupDir_0200 end";
426 }
427
428 /**
429 * @tc.number: GetSystemDatabaseDir_0100
430 * @tc.name: GetSystemDatabaseDir
431 * @tc.desc: Get Group Dir failed
432 */
433 HWTEST_F(ApplicationContextTest, GetSystemDatabaseDir_0100, TestSize.Level1)
434 {
435 GTEST_LOG_(INFO) << "GetSystemDatabaseDir_0100 start";
436 std::shared_ptr<ContextImpl> contextImpl = nullptr;
437 context_->AttachContextImpl(contextImpl);
438 std::string databaseDir;
439 auto ret = context_->GetSystemDatabaseDir("1", true, databaseDir);
440 EXPECT_EQ(ret, OHOS::ERR_INVALID_VALUE);
441 GTEST_LOG_(INFO) << "GetSystemDatabaseDir_0100 end";
442 }
443
444 /**
445 * @tc.number: GetSystemDatabaseDir_0200
446 * @tc.name: GetSystemDatabaseDir
447 * @tc.desc:Get Group Dir sucess
448 */
449 HWTEST_F(ApplicationContextTest, GetSystemDatabaseDir_0200, TestSize.Level1)
450 {
451 GTEST_LOG_(INFO) << "GetSystemDatabaseDir_0200 start";
452 context_->AttachContextImpl(mock_);
453 std::string databaseDir;
454 auto ret = context_->GetSystemDatabaseDir("1", true, databaseDir);
455 EXPECT_EQ(ret, 0);
456 GTEST_LOG_(INFO) << "GetSystemDatabaseDir_0200 end";
457 }
458
459 /**
460 * @tc.number: GetSystemPreferencesDir_0100
461 * @tc.name: GetSystemPreferencesDir
462 * @tc.desc: Get Group Dir failed
463 */
464 HWTEST_F(ApplicationContextTest, GetSystemPreferencesDir_0100, TestSize.Level1)
465 {
466 GTEST_LOG_(INFO) << "GetSystemPreferencesDir_0100 start";
467 std::shared_ptr<ContextImpl> contextImpl = nullptr;
468 context_->AttachContextImpl(contextImpl);
469 std::string preferencesDir;
470 auto ret = context_->GetSystemPreferencesDir("1", true, preferencesDir);
471 EXPECT_EQ(ret, OHOS::ERR_INVALID_VALUE);
472 GTEST_LOG_(INFO) << "GetSystemPreferencesDir_0100 end";
473 }
474
475 /**
476 * @tc.number: GetSystemPreferencesDir_0200
477 * @tc.name: GetSystemPreferencesDir
478 * @tc.desc:Get System Preferences Dir sucess
479 */
480 HWTEST_F(ApplicationContextTest, GetSystemPreferencesDir_0200, TestSize.Level1)
481 {
482 GTEST_LOG_(INFO) << "GetSystemDatabaseDir_0200 start";
483 context_->AttachContextImpl(mock_);
484 std::string preferencesDir;
485 auto ret = context_->GetSystemPreferencesDir("1", true, preferencesDir);
486 EXPECT_EQ(ret, 0);
487 GTEST_LOG_(INFO) << "GetSystemPreferencesDir_0200 end";
488 }
489
490 /**
491 * @tc.number: GetFilesDir_0100
492 * @tc.name: GetFilesDir
493 * @tc.desc: Get Files Dir failed
494 */
495 HWTEST_F(ApplicationContextTest, GetFilesDir_0100, TestSize.Level1)
496 {
497 GTEST_LOG_(INFO) << "GetFilesDir_0100 start";
498 std::shared_ptr<ContextImpl> contextImpl = nullptr;
499 context_->AttachContextImpl(contextImpl);
500 auto ret = context_->GetFilesDir();
501 EXPECT_EQ(ret, "");
502 GTEST_LOG_(INFO) << "GetFilesDir_0100 end";
503 }
504
505 /**
506 * @tc.number: GetFilesDir_0200
507 * @tc.name: GetFilesDir
508 * @tc.desc:Get Files Dir sucess
509 */
510 HWTEST_F(ApplicationContextTest, GetFilesDir_0200, TestSize.Level1)
511 {
512 GTEST_LOG_(INFO) << "GetFilesDir_0200 start";
513 context_->AttachContextImpl(mock_);
514 auto ret = context_->GetFilesDir();
515 EXPECT_EQ(ret, "/files");
516 GTEST_LOG_(INFO) << "GetFilesDir_0200 end";
517 }
518
519 /**
520 * @tc.number: IsUpdatingConfigurations_0100
521 * @tc.name: IsUpdatingConfigurations
522 * @tc.desc: Is Updating Configurations failed
523 */
524 HWTEST_F(ApplicationContextTest, IsUpdatingConfigurations_0100, TestSize.Level1)
525 {
526 GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0100 start";
527 std::shared_ptr<ContextImpl> contextImpl = nullptr;
528 context_->AttachContextImpl(contextImpl);
529 auto ret = context_->IsUpdatingConfigurations();
530 EXPECT_EQ(ret, false);
531 GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0100 end";
532 }
533
534 /**
535 * @tc.number: IsUpdatingConfigurations_0200
536 * @tc.name: IsUpdatingConfigurations
537 * @tc.desc:Is Updating Configurations sucess
538 */
539 HWTEST_F(ApplicationContextTest, IsUpdatingConfigurations_0200, TestSize.Level1)
540 {
541 GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0200 start";
542 context_->AttachContextImpl(mock_);
543 auto ret = context_->IsUpdatingConfigurations();
544 EXPECT_EQ(ret, true);
545 GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0200 end";
546 }
547
548 /**
549 * @tc.number: PrintDrawnCompleted_0100
550 * @tc.name: PrintDrawnCompleted
551 * @tc.desc: Print Drawn Completed failed
552 */
553 HWTEST_F(ApplicationContextTest, PrintDrawnCompleted_0100, TestSize.Level1)
554 {
555 GTEST_LOG_(INFO) << "PrintDrawnCompleted_0100 start";
556 std::shared_ptr<ContextImpl> contextImpl = nullptr;
557 context_->AttachContextImpl(contextImpl);
558 auto ret = context_->PrintDrawnCompleted();
559 EXPECT_EQ(ret, false);
560 GTEST_LOG_(INFO) << "PrintDrawnCompleted_0100 end";
561 }
562
563 /**
564 * @tc.number: PrintDrawnCompleted_0200
565 * @tc.name: PrintDrawnCompleted
566 * @tc.desc:Print Drawn Completed sucess
567 */
568 HWTEST_F(ApplicationContextTest, PrintDrawnCompleted_0200, TestSize.Level1)
569 {
570 GTEST_LOG_(INFO) << "PrintDrawnCompleted_0200 start";
571 context_->AttachContextImpl(mock_);
572 auto ret = context_->PrintDrawnCompleted();
573 EXPECT_EQ(ret, true);
574 GTEST_LOG_(INFO) << "PrintDrawnCompleted_0200 end";
575 }
576
577 /**
578 * @tc.number: GetDatabaseDir_0100
579 * @tc.name: GetDatabaseDir
580 * @tc.desc: Get Data base Dir failed
581 */
582 HWTEST_F(ApplicationContextTest, GetDatabaseDir_0100, TestSize.Level1)
583 {
584 GTEST_LOG_(INFO) << "GetDatabaseDir_0100 start";
585 std::shared_ptr<ContextImpl> contextImpl = nullptr;
586 context_->AttachContextImpl(contextImpl);
587 auto ret = context_->GetDatabaseDir();
588 EXPECT_EQ(ret, "");
589 GTEST_LOG_(INFO) << "GetDatabaseDir_0100 end";
590 }
591
592 /**
593 * @tc.number: GetDatabaseDir_0200
594 * @tc.name: GetDatabaseDir
595 * @tc.desc:Get Data base Dir sucess
596 */
597 HWTEST_F(ApplicationContextTest, GetDatabaseDir_0200, TestSize.Level1)
598 {
599 GTEST_LOG_(INFO) << "GetDatabaseDir_0200 start";
600 context_->AttachContextImpl(mock_);
601 auto ret = context_->GetDatabaseDir();
602 EXPECT_EQ(ret, "/data/app/database");
603 GTEST_LOG_(INFO) << "GetDatabaseDir_0200 end";
604 }
605
606 /**
607 * @tc.number: GetPreferencesDir_0100
608 * @tc.name: GetPreferencesDir
609 * @tc.desc: Get Preferences Dir failed
610 */
611 HWTEST_F(ApplicationContextTest, GetPreferencesDir_0100, TestSize.Level1)
612 {
613 GTEST_LOG_(INFO) << "GetPreferencesDir_0100 start";
614 std::shared_ptr<ContextImpl> contextImpl = nullptr;
615 context_->AttachContextImpl(contextImpl);
616 auto ret = context_->GetPreferencesDir();
617 EXPECT_EQ(ret, "");
618 GTEST_LOG_(INFO) << "GetPreferencesDir_0100 end";
619 }
620
621 /**
622 * @tc.number: GetPreferencesDir_0200
623 * @tc.name: GetPreferencesDir
624 * @tc.desc:Get Preferences Dir sucess
625 */
626 HWTEST_F(ApplicationContextTest, GetPreferencesDir_0200, TestSize.Level1)
627 {
628 GTEST_LOG_(INFO) << "GetPreferencesDir_0200 start";
629 context_->AttachContextImpl(mock_);
630 auto ret = context_->GetPreferencesDir();
631 EXPECT_EQ(ret, "/preferences");
632 GTEST_LOG_(INFO) << "GetPreferencesDir_0200 end";
633 }
634
635 /**
636 * @tc.number: GetDistributedFilesDir_0100
637 * @tc.name: GetDistributedFilesDir
638 * @tc.desc: Get Distributed Files Dir failed
639 */
640 HWTEST_F(ApplicationContextTest, GetDistributedFilesDir_0100, TestSize.Level1)
641 {
642 GTEST_LOG_(INFO) << "GetDistributedFilesDir_0100 start";
643 std::shared_ptr<ContextImpl> contextImpl = nullptr;
644 context_->AttachContextImpl(contextImpl);
645 auto ret = context_->GetDistributedFilesDir();
646 EXPECT_EQ(ret, "");
647 GTEST_LOG_(INFO) << "GetDistributedFilesDir_0100 end";
648 }
649
650 /**
651 * @tc.number: GetDistributedFilesDir_0200
652 * @tc.name: GetDistributedFilesDir
653 * @tc.desc:Get Distributed Files Dir sucess
654 */
655 HWTEST_F(ApplicationContextTest, GetDistributedFilesDir_0200, TestSize.Level1)
656 {
657 GTEST_LOG_(INFO) << "GetDistributedFilesDir_0200 start";
658 context_->AttachContextImpl(mock_);
659 auto ret = context_->GetDistributedFilesDir();
660 EXPECT_EQ(ret, "/mnt/hmdfs/device_view/local/data/bundleName");
661 GTEST_LOG_(INFO) << "GetDistributedFilesDir_0200 end";
662 }
663
664 /**
665 * @tc.number: GetCloudFileDir_0100
666 * @tc.name: GetCloudFileDir
667 * @tc.desc: Get Cloud File Dir failed
668 */
669 HWTEST_F(ApplicationContextTest, GetCloudFileDir_0100, TestSize.Level1)
670 {
671 GTEST_LOG_(INFO) << "GetCloudFileDir_0100 start";
672 std::shared_ptr<ContextImpl> contextImpl = nullptr;
673 context_->AttachContextImpl(contextImpl);
674 auto ret = context_->GetCloudFileDir();
675 EXPECT_EQ(ret, "");
676 GTEST_LOG_(INFO) << "GetCloudFileDir_0100 end";
677 }
678
679 /**
680 * @tc.number: GetToken_0100
681 * @tc.name: GetToken
682 * @tc.desc: Get Token failed
683 */
684 HWTEST_F(ApplicationContextTest, GetToken_0100, TestSize.Level1)
685 {
686 GTEST_LOG_(INFO) << "GetToken_0100 start";
687 std::shared_ptr<ContextImpl> contextImpl = nullptr;
688 context_->AttachContextImpl(contextImpl);
689 auto ret = context_->GetToken();
690 EXPECT_EQ(ret, nullptr);
691 GTEST_LOG_(INFO) << "GetToken_0100 end";
692 }
693
694 /**
695 * @tc.number: GetToken_0200
696 * @tc.name: GetToken
697 * @tc.desc:Get Token sucess
698 */
699 HWTEST_F(ApplicationContextTest, GetToken_0200, TestSize.Level1)
700 {
701 GTEST_LOG_(INFO) << "GetToken_0200 start";
702 std::shared_ptr<ContextImpl> contextImpl = std::make_shared<ContextImpl>();
703 context_->AttachContextImpl(contextImpl);
704 sptr<IRemoteObject> token = new OHOS::AppExecFwk::MockAbilityToken();
705 context_->SetToken(token);
706 auto ret = context_->GetToken();
707 EXPECT_EQ(ret, token);
708 GTEST_LOG_(INFO) << "GetToken_0200 end";
709 }
710
711 /**
712 * @tc.number: GetArea_0100
713 * @tc.name: GetArea
714 * @tc.desc: Get Area failed
715 */
716 HWTEST_F(ApplicationContextTest, GetArea_0100, TestSize.Level1)
717 {
718 GTEST_LOG_(INFO) << "GetArea_0100 start";
719 std::shared_ptr<ContextImpl> contextImpl = nullptr;
720 context_->AttachContextImpl(contextImpl);
721 auto ret = context_->GetArea();
722 EXPECT_EQ(ret, 1);
723 GTEST_LOG_(INFO) << "GetArea_0100 end";
724 }
725
726 /**
727 * @tc.number: GetArea_0200
728 * @tc.name: GetArea
729 * @tc.desc:Get Area sucess
730 */
731 HWTEST_F(ApplicationContextTest, GetArea_0200, TestSize.Level1)
732 {
733 GTEST_LOG_(INFO) << "GetArea_0200 start";
734 std::shared_ptr<ContextImpl> contextImpl = std::make_shared<ContextImpl>();
735 context_->AttachContextImpl(contextImpl);
736 int32_t mode = 1;
737 context_->SwitchArea(mode);
738 auto ret = context_->GetArea();
739 EXPECT_EQ(ret, mode);
740 GTEST_LOG_(INFO) << "GetArea_0200 end";
741 }
742
743 /**
744 * @tc.number: GetConfiguration_0100
745 * @tc.name: GetConfiguration
746 * @tc.desc: Get Configuration failed
747 */
748 HWTEST_F(ApplicationContextTest, GetConfiguration_0100, TestSize.Level1)
749 {
750 GTEST_LOG_(INFO) << "GetConfiguration_0100 start";
751 std::shared_ptr<ContextImpl> contextImpl = nullptr;
752 context_->AttachContextImpl(contextImpl);
753 auto ret = context_->GetConfiguration();
754 EXPECT_EQ(ret, nullptr);
755 GTEST_LOG_(INFO) << "GetConfiguration_0100 end";
756 }
757
758 /**
759 * @tc.number: GetConfiguration_0200
760 * @tc.name: GetConfiguration
761 * @tc.desc:Get Configuration sucess
762 */
763 HWTEST_F(ApplicationContextTest, GetConfiguration_0200, TestSize.Level1)
764 {
765 GTEST_LOG_(INFO) << "GetConfiguration_0200 start";
766 context_->AttachContextImpl(mock_);
767 auto ret = context_->GetConfiguration();
768 EXPECT_NE(ret, nullptr);
769 GTEST_LOG_(INFO) << "GetConfiguration_0200 end";
770 }
771
772 /**
773 * @tc.number: GetBaseDir_0100
774 * @tc.name: GetBaseDir
775 * @tc.desc:Get Base Dir sucess
776 */
777 HWTEST_F(ApplicationContextTest, GetBaseDir_0100, TestSize.Level1)
778 {
779 GTEST_LOG_(INFO) << "GetBaseDir_0100 start";
780 context_->AttachContextImpl(mock_);
781 auto ret = context_->GetBaseDir();
782 EXPECT_EQ(ret, "/data/app/base");
783 GTEST_LOG_(INFO) << "GetBaseDir_0100 end";
784 }
785
786 /**
787 * @tc.number: GetDeviceType_0100
788 * @tc.name: GetDeviceType
789 * @tc.desc: Get DeviceType failed
790 */
791 HWTEST_F(ApplicationContextTest, GetDeviceType_0100, TestSize.Level1)
792 {
793 GTEST_LOG_(INFO) << "GetDeviceType_0100 start";
794 std::shared_ptr<ContextImpl> contextImpl = nullptr;
795 context_->AttachContextImpl(contextImpl);
796 auto ret = context_->GetDeviceType();
797 EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_PHONE);
798 GTEST_LOG_(INFO) << "GetDeviceType_0100 end";
799 }
800
801 /**
802 * @tc.number: GetDeviceType_0200
803 * @tc.name: GetDeviceType
804 * @tc.desc:Get DeviceType sucess
805 */
806 HWTEST_F(ApplicationContextTest, GetDeviceType_0200, TestSize.Level1)
807 {
808 GTEST_LOG_(INFO) << "GetDeviceType_0200 start";
809 context_->AttachContextImpl(mock_);
810 auto ret = context_->GetDeviceType();
811 EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_NOT_SET);
812 GTEST_LOG_(INFO) << "GetDeviceType_0200 end";
813 }
814
815 /**
816 * @tc.number: UnregisterEnvironmentCallback_0100
817 * @tc.name: UnregisterEnvironmentCallback
818 * @tc.desc: unregister Environment Callback
819 */
820 HWTEST_F(ApplicationContextTest, UnregisterEnvironmentCallback_0100, TestSize.Level1)
821 {
822 GTEST_LOG_(INFO) << "UnregisterEnvironmentCallback_0100 start";
823 context_->envCallbacks_.clear();
824 std::shared_ptr<EnvironmentCallback> environmentCallback = nullptr;
825 context_->UnregisterEnvironmentCallback(environmentCallback);
826 EXPECT_TRUE(context_->envCallbacks_.empty());
827 GTEST_LOG_(INFO) << "UnregisterEnvironmentCallback_0100 end";
828 }
829
830 /**
831 * @tc.number: DispatchOnAbilityCreate_0100
832 * @tc.name: DispatchOnAbilityCreate
833 * @tc.desc: DispatchOnAbilityCreate
834 */
835 HWTEST_F(ApplicationContextTest, DispatchOnAbilityCreate_0100, TestSize.Level1)
836 {
837 GTEST_LOG_(INFO) << "DispatchOnAbilityCreate_0100 start";
838 EXPECT_NE(context_, nullptr);
839 std::shared_ptr<NativeReference> ability = nullptr;
840 context_->DispatchOnAbilityCreate(ability);
841 GTEST_LOG_(INFO) << "DispatchOnAbilityCreate_0100 end";
842 }
843
844 /**
845 * @tc.number: DispatchOnWindowStageCreate_0100
846 * @tc.name: DispatchOnWindowStageCreate
847 * @tc.desc: DispatchOnWindowStageCreate
848 */
849 HWTEST_F(ApplicationContextTest, DispatchOnWindowStageCreate_0100, TestSize.Level1)
850 {
851 GTEST_LOG_(INFO) << "DispatchOnWindowStageCreate_0100 start";
852 EXPECT_NE(context_, nullptr);
853 std::shared_ptr<NativeReference> ability = nullptr;
854 std::shared_ptr<NativeReference> windowStage = nullptr;
855 context_->DispatchOnWindowStageCreate(ability, windowStage);
856 GTEST_LOG_(INFO) << "DispatchOnWindowStageCreate_0100 end";
857 }
858
859 /**
860 * @tc.number: DispatchOnWindowStageDestroy_0100
861 * @tc.name: DispatchOnWindowStageDestroy
862 * @tc.desc: DispatchOnWindowStageDestroy
863 */
864 HWTEST_F(ApplicationContextTest, DispatchOnWindowStageDestroy_0100, TestSize.Level1)
865 {
866 GTEST_LOG_(INFO) << "DispatchOnWindowStageDestroy_0100 start";
867 EXPECT_NE(context_, nullptr);
868 std::shared_ptr<NativeReference> ability = nullptr;
869 std::shared_ptr<NativeReference> windowStage = nullptr;
870 context_->DispatchOnWindowStageDestroy(ability, windowStage);
871 GTEST_LOG_(INFO) << "DispatchOnWindowStageDestroy_0100 end";
872 }
873
874 /**
875 * @tc.number: DispatchWindowStageFocus_0100
876 * @tc.name: DispatchWindowStageFocus
877 * @tc.desc: DispatchWindowStageFocus
878 */
879 HWTEST_F(ApplicationContextTest, DispatchWindowStageFocus_0100, TestSize.Level1)
880 {
881 GTEST_LOG_(INFO) << "DispatchWindowStageFocus_0100 start";
882 EXPECT_NE(context_, nullptr);
883 std::shared_ptr<NativeReference> ability = nullptr;
884 std::shared_ptr<NativeReference> windowStage = nullptr;
885 context_->DispatchWindowStageFocus(ability, windowStage);
886 GTEST_LOG_(INFO) << "DispatchWindowStageFocus_0100 end";
887 }
888
889 /**
890 * @tc.number: DispatchWindowStageUnfocus_0100
891 * @tc.name: DispatchWindowStageUnfocus
892 * @tc.desc: DispatchWindowStageUnfocus
893 */
894 HWTEST_F(ApplicationContextTest, DispatchWindowStageUnfocus_0100, TestSize.Level1)
895 {
896 GTEST_LOG_(INFO) << "DispatchWindowStageUnfocus_0100 start";
897 EXPECT_NE(context_, nullptr);
898 std::shared_ptr<NativeReference> ability = nullptr;
899 std::shared_ptr<NativeReference> windowStage = nullptr;
900 context_->DispatchWindowStageUnfocus(ability, windowStage);
901 GTEST_LOG_(INFO) << "DispatchWindowStageUnfocus_0100 end";
902 }
903
904 /**
905 * @tc.number: DispatchOnAbilityDestroy_0100
906 * @tc.name: DispatchOnAbilityDestroy
907 * @tc.desc: DispatchOnAbilityDestroy
908 */
909 HWTEST_F(ApplicationContextTest, DispatchOnAbilityDestroy_0100, TestSize.Level1)
910 {
911 GTEST_LOG_(INFO) << "DispatchOnAbilityDestroy_0100 start";
912 EXPECT_NE(context_, nullptr);
913 std::shared_ptr<NativeReference> ability = nullptr;
914 context_->DispatchOnAbilityDestroy(ability);
915 GTEST_LOG_(INFO) << "DispatchOnAbilityDestroy_0100 end";
916 }
917
918 /**
919 * @tc.number: DispatchOnAbilityForeground_0100
920 * @tc.name: DispatchOnAbilityForeground
921 * @tc.desc: DispatchOnAbilityForeground
922 */
923 HWTEST_F(ApplicationContextTest, DispatchOnAbilityForeground_0100, TestSize.Level1)
924 {
925 GTEST_LOG_(INFO) << "DispatchOnAbilityForeground_0100 start";
926 EXPECT_NE(context_, nullptr);
927 std::shared_ptr<NativeReference> ability = nullptr;
928 context_->DispatchOnAbilityForeground(ability);
929 GTEST_LOG_(INFO) << "DispatchOnAbilityForeground_0100 end";
930 }
931
932 /**
933 * @tc.number: DispatchOnAbilityBackground_0100
934 * @tc.name: DispatchOnAbilityBackground
935 * @tc.desc: DispatchOnAbilityBackground
936 */
937 HWTEST_F(ApplicationContextTest, DispatchOnAbilityBackground_0100, TestSize.Level1)
938 {
939 GTEST_LOG_(INFO) << "DispatchOnAbilityBackground_0100 start";
940 EXPECT_NE(context_, nullptr);
941 std::shared_ptr<NativeReference> ability = nullptr;
942 context_->DispatchOnAbilityBackground(ability);
943 GTEST_LOG_(INFO) << "DispatchOnAbilityBackground_0100 end";
944 }
945
946 /**
947 * @tc.number: DispatchOnAbilityContinue_0100
948 * @tc.name: DispatchOnAbilityContinue
949 * @tc.desc: DispatchOnAbilityContinue
950 */
951 HWTEST_F(ApplicationContextTest, DispatchOnAbilityContinue_0100, TestSize.Level1)
952 {
953 GTEST_LOG_(INFO) << "DispatchOnAbilityContinue_0100 start";
954 EXPECT_NE(context_, nullptr);
955 std::shared_ptr<NativeReference> ability = nullptr;
956 context_->DispatchOnAbilityContinue(ability);
957 GTEST_LOG_(INFO) << "DispatchOnAbilityContinue_0100 end";
958 }
959
960 /**
961 * @tc.number: SetApplicationInfo_0100
962 * @tc.name: SetApplicationInfo
963 * @tc.desc: SetApplicationInfo
964 */
965 HWTEST_F(ApplicationContextTest, SetApplicationInfo_0100, TestSize.Level1)
966 {
967 GTEST_LOG_(INFO) << "SetApplicationInfo_0100 start";
968 EXPECT_NE(context_, nullptr);
969 std::shared_ptr<AppExecFwk::ApplicationInfo> info = nullptr;
970 context_->SetApplicationInfo(info);
971 GTEST_LOG_(INFO) << "SetApplicationInfo_0100 end";
972 }
973
974 /**
975 * @tc.number: SetColorMode_0100
976 * @tc.name: SetColorMode
977 * @tc.desc: SetColorMode
978 */
979 HWTEST_F(ApplicationContextTest, SetColorMode_0100, TestSize.Level1)
980 {
981 GTEST_LOG_(INFO) << "SetColorMode_0100 start";
982 int32_t colorMode = 1;
983 context_->SetColorMode(colorMode);
984 EXPECT_TRUE(context_ != nullptr);
985 GTEST_LOG_(INFO) << "SetColorMode_0100 end";
986 }
987
988 /**
989 * @tc.number: SetLanguage_0100
990 * @tc.name: SetLanguage
991 * @tc.desc: SetLanguage
992 */
993 HWTEST_F(ApplicationContextTest, SetLanguage_0100, TestSize.Level1)
994 {
995 GTEST_LOG_(INFO) << "SetLanguage_0100 start";
996 EXPECT_NE(context_, nullptr);
997 std::string language = "zh-cn";
998 context_->SetLanguage(language);
999 EXPECT_EQ(language, "zh-cn");
1000 GTEST_LOG_(INFO) << "SetLanguage_0100 end";
1001 }
1002
1003 /**
1004 * @tc.number: KillProcessBySelf_0100
1005 * @tc.name: KillProcessBySelf
1006 * @tc.desc: KillProcessBySelf
1007 */
1008 HWTEST_F(ApplicationContextTest, KillProcessBySelf_0100, TestSize.Level1)
1009 {
1010 GTEST_LOG_(INFO) << "KillProcessBySelf_0100 start";
1011 EXPECT_NE(context_, nullptr);
1012 context_->KillProcessBySelf();
1013 GTEST_LOG_(INFO) << "KillProcessBySelf_0100 end";
1014 }
1015
1016 /**
1017 * @tc.number: ClearUpApplicationData_0100
1018 * @tc.name: ClearUpApplicationData
1019 * @tc.desc: ClearUpApplicationData
1020 */
1021 HWTEST_F(ApplicationContextTest, ClearUpApplicationData_0100, TestSize.Level1)
1022 {
1023 GTEST_LOG_(INFO) << "ClearUpApplicationData_0100 start";
1024 EXPECT_NE(context_, nullptr);
1025 context_->AttachContextImpl(mock_);
1026 context_->ClearUpApplicationData();
1027 GTEST_LOG_(INFO) << "ClearUpApplicationData_0100 end";
1028 }
1029
1030 /**
1031 * @tc.number: GetProcessRunningInformation_0100
1032 * @tc.name: GetProcessRunningInformation
1033 * @tc.desc: GetProcessRunningInformation
1034 */
1035 HWTEST_F(ApplicationContextTest, GetProcessRunningInformation_0100, TestSize.Level1)
1036 {
1037 GTEST_LOG_(INFO) << "GetProcessRunningInformation_0100 start";
1038 std::shared_ptr<ContextImpl> contextImpl = nullptr;
1039 context_->AttachContextImpl(contextImpl);
1040 AppExecFwk::RunningProcessInfo info;
1041 auto ret = context_->GetProcessRunningInformation(info);
1042 EXPECT_EQ(ret, -1);
1043 GTEST_LOG_(INFO) << "GetProcessRunningInformation_0100 end";
1044 }
1045
1046 /**
1047 * @tc.number: GetCacheDir_0100
1048 * @tc.name: GetCacheDir
1049 * @tc.desc: Get Bundle Code Dir failed
1050 */
1051 HWTEST_F(ApplicationContextTest, GetCacheDir_0100, TestSize.Level1)
1052 {
1053 GTEST_LOG_(INFO) << "GetCacheDir_0100 start";
1054 std::shared_ptr<ContextImpl> contextImpl = nullptr;
1055 context_->AttachContextImpl(contextImpl);
1056 auto ret = context_->GetCacheDir();
1057 EXPECT_EQ(ret, "");
1058 GTEST_LOG_(INFO) << "GetCacheDir_0100 end";
1059 }
1060
1061 /**
1062 * @tc.number: RegisterApplicationStateChangeCallback_0100
1063 * @tc.name: RegisterApplicationStateChangeCallback
1064 * @tc.desc: Pass in nullptr parameters, and the callback saved in the ApplicationContext is also nullptr
1065 */
1066 HWTEST_F(ApplicationContextTest, RegisterApplicationStateChangeCallback_0100, TestSize.Level1)
1067 {
1068 GTEST_LOG_(INFO) << "RegisterApplicationStateChangeCallback_0100 start";
1069 std::shared_ptr<MockApplicationStateChangeCallback> applicationStateCallback = nullptr;
1070 context_->RegisterApplicationStateChangeCallback(applicationStateCallback);
1071 EXPECT_EQ(1, context_->applicationStateCallback_.size());
1072 GTEST_LOG_(INFO) << "RegisterApplicationStateChangeCallback_0100 end";
1073 }
1074
1075 /**
1076 * @tc.number: NotifyApplicationForeground_0100
1077 * @tc.name: NotifyApplicationForeground and RegisterApplicationStateChangeCallback
1078 * @tc.desc: Pass 1 register a valid callback, NotifyApplicationForeground is called
1079 * 2 the callback saved in the ApplicationContext is valid
1080 */
1081 HWTEST_F(ApplicationContextTest, NotifyApplicationForeground_0100, TestSize.Level1)
1082 {
1083 GTEST_LOG_(INFO) << "NotifyApplicationForeground_0100 start";
1084
1085 auto applicationStateCallback = std::make_shared<MockApplicationStateChangeCallback>();
1086 context_->RegisterApplicationStateChangeCallback(applicationStateCallback);
1087 EXPECT_CALL(*applicationStateCallback, NotifyApplicationForeground()).Times(1);
1088 context_->NotifyApplicationForeground();
1089 context_->applicationStateCallback_[0];
1090 EXPECT_NE(context_, nullptr);
1091 GTEST_LOG_(INFO) << "NotifyApplicationForeground_0100 end";
1092 }
1093
1094 /**
1095 * @tc.number: NotifyApplicationBackground_0100
1096 * @tc.name: NotifyApplicationBackground and RegisterApplicationStateChangeCallback
1097 * @tc.desc: Pass 1 register a valid callback, NotifyApplicationBackground is called
1098 * 2 the callback saved in the ApplicationContext is valid
1099 */
1100 HWTEST_F(ApplicationContextTest, NotifyApplicationBackground_0100, TestSize.Level1)
1101 {
1102 GTEST_LOG_(INFO) << "NotifyApplicationBackground_0100 start";
1103
1104 auto applicationStateCallback = std::make_shared<MockApplicationStateChangeCallback>();
1105 context_->RegisterApplicationStateChangeCallback(applicationStateCallback);
1106 EXPECT_CALL(*applicationStateCallback, NotifyApplicationBackground()).Times(1);
1107 context_->NotifyApplicationBackground();
1108 context_->applicationStateCallback_[0];
1109 EXPECT_NE(context_, nullptr);
1110 GTEST_LOG_(INFO) << "NotifyApplicationBackground_0100 end";
1111 }
1112
1113 /**
1114 * @tc.number: GetApplicationInfoUpdateFlag_0100
1115 * @tc.name: GetApplicationInfoUpdateFlag
1116 * @tc.desc: GetApplicationInfoUpdateFlag
1117 */
1118 HWTEST_F(ApplicationContextTest, GetApplicationInfoUpdateFlag_0100, TestSize.Level1)
1119 {
1120 GTEST_LOG_(INFO) << "GetApplicationInfoUpdateFlag_0100 start";
1121 auto result = context_->GetApplicationInfoUpdateFlag();
1122 EXPECT_EQ(result, false);
1123 GTEST_LOG_(INFO) << "GetApplicationInfoUpdateFlag_0100 end";
1124 }
1125
1126 /**
1127 * @tc.number: SetApplicationInfoUpdateFlag_0100
1128 * @tc.name: SetApplicationInfoUpdateFlag
1129 * @tc.desc: SetApplicationInfoUpdateFlag
1130 */
1131 HWTEST_F(ApplicationContextTest, SetApplicationInfoUpdateFlag_0100, TestSize.Level1)
1132 {
1133 GTEST_LOG_(INFO) << "SetApplicationInfoUpdateFlag_0100 start";
1134 EXPECT_TRUE(context_ != nullptr);
1135 bool flag = true;
1136 context_->SetApplicationInfoUpdateFlag(flag);
1137 GTEST_LOG_(INFO) << "SetApplicationInfoUpdateFlag_0100 end";
1138 }
1139
1140 /**
1141 * @tc.number: CreateModuleResourceManager_0100
1142 * @tc.name: CreateModuleResourceManager
1143 * @tc.desc: Create ModuleContext failed
1144 */
1145 HWTEST_F(ApplicationContextTest, CreateModuleResourceManager_0100, TestSize.Level1)
1146 {
1147 GTEST_LOG_(INFO) << "CreateModuleResourceManager_0100 start";
1148 std::shared_ptr<ContextImpl> contextImpl = nullptr;
1149 context_->AttachContextImpl(contextImpl);
1150 std::string moduleName = "moduleName";
1151 std::string bundleName = "com.test.bundleName";
1152 auto ret = context_->CreateModuleResourceManager(bundleName, moduleName);
1153 EXPECT_EQ(ret, nullptr);
1154 GTEST_LOG_(INFO) << "CreateModuleResourceManager_0100 end";
1155 }
1156
1157 /**
1158 * @tc.number: CreateSystemHspModuleResourceManager_0100
1159 * @tc.name: CreateSystemHspModuleResourceManager
1160 * @tc.desc: Create ModuleContext failed
1161 */
1162 HWTEST_F(ApplicationContextTest, CreateSystemHspModuleResourceManager_0100, TestSize.Level1)
1163 {
1164 GTEST_LOG_(INFO) << "CreateSystemHspModuleResourceManager_0100 start";
1165 std::shared_ptr<ContextImpl> contextImpl = std::make_shared<ContextImpl>();
1166 context_->AttachContextImpl(contextImpl);
1167 std::string moduleName = "moduleName";
1168 std::string bundleName = "com.test.bundleName";
1169 std::shared_ptr<Global::Resource::ResourceManager> resourceManager = nullptr;
1170 context_->CreateSystemHspModuleResourceManager(bundleName, moduleName, resourceManager);
1171 EXPECT_NE(context_, nullptr);
1172 GTEST_LOG_(INFO) << "CreateModuleResourceManager_0100 end";
1173 }
1174
1175 /**
1176 * @tc.number: GetAllTempDir_0100
1177 * @tc.name: GetAllTempDir
1178 * @tc.desc: GetAllTempDir
1179 */
1180 HWTEST_F(ApplicationContextTest, GetAllTempDir_0100, TestSize.Level1)
1181 {
1182 GTEST_LOG_(INFO) << "GetAllTempDir_0100 start";
1183 std::vector<std::string> tempPaths;
1184 context_->GetAllTempDir(tempPaths);
1185 EXPECT_NE(context_, nullptr);
1186 GTEST_LOG_(INFO) << "GetAllTempDir_0100 end";
1187 }
1188
1189 /**
1190 * @tc.number: RestartApp_0100
1191 * @tc.name: RestartApp
1192 * @tc.desc: RestartApp
1193 */
1194 HWTEST_F(ApplicationContextTest, RestartApp_0100, TestSize.Level1)
1195 {
1196 AAFwk::Want want;
1197 int32_t res = context_->RestartApp(want);
1198 EXPECT_EQ(res, OHOS::ERR_INVALID_VALUE);
1199 }
1200
1201 /**
1202 * @tc.number: DispatchConfigurationUpdated_0100
1203 * @tc.name: DispatchConfigurationUpdated
1204 * @tc.desc: DispatchConfigurationUpdated
1205 */
1206 HWTEST_F(ApplicationContextTest, DispatchConfigurationUpdated_0100, TestSize.Level1)
1207 {
1208 AppExecFwk::Configuration config;
1209 context_->DispatchConfigurationUpdated(config);
1210 EXPECT_NE(context_, nullptr);
1211 }
1212
1213 /**
1214 * @tc.number: DispatchMemoryLevel_0100
1215 * @tc.name: DispatchMemoryLevel
1216 * @tc.desc: DispatchMemoryLevel
1217 */
1218 HWTEST_F(ApplicationContextTest, DispatchMemoryLevel_0100, TestSize.Level1)
1219 {
1220 int level = 0;
1221 context_->DispatchMemoryLevel(level);
1222 EXPECT_NE(context_, nullptr);
1223 }
1224
1225 /**
1226 * @tc.number: RegisterAppConfigUpdateObserver_0100
1227 * @tc.name: RegisterAppConfigUpdateObserver
1228 * @tc.desc: RegisterAppConfigUpdateObserver
1229 */
1230 HWTEST_F(ApplicationContextTest, RegisterAppConfigUpdateObserver_0100, TestSize.Level1)
1231 {
1232 AppConfigUpdateCallback appConfigChangeCallback;
1233 context_->RegisterAppConfigUpdateObserver(appConfigChangeCallback);
1234 EXPECT_NE(context_, nullptr);
1235 }
1236
1237 /**
1238 * @tc.number: GetAppRunningUniqueId_0100
1239 * @tc.name: GetAppRunningUniqueId
1240 * @tc.desc: GetAppRunningUniqueId
1241 */
1242 HWTEST_F(ApplicationContextTest, GetAppRunningUniqueId_0100, TestSize.Level1)
1243 {
1244 context_->GetAppRunningUniqueId();
1245 EXPECT_NE(context_, nullptr);
1246 }
1247
1248 /**
1249 * @tc.number: SetAppRunningUniqueId_0100
1250 * @tc.name: SetAppRunningUniqueId
1251 * @tc.desc: SetAppRunningUniqueId
1252 */
1253 HWTEST_F(ApplicationContextTest, SetAppRunningUniqueId_0100, TestSize.Level1)
1254 {
1255 std::string appRunningUniqueId;
1256 context_->SetAppRunningUniqueId(appRunningUniqueId);
1257 EXPECT_NE(context_, nullptr);
1258 }
1259
1260 /**
1261 * @tc.number: SetSupportedProcessCacheSelf_0100
1262 * @tc.name: SetSupportedProcessCacheSelf
1263 * @tc.desc: SetSupportedProcessCacheSelf fail with no permission
1264 */
1265 HWTEST_F(ApplicationContextTest, SetSupportedProcessCacheSelf_0100, TestSize.Level1)
1266 {
1267 bool isSupport = false;
1268 int32_t res = context_->SetSupportedProcessCacheSelf(isSupport);
1269 EXPECT_EQ(res, OHOS::ERR_INVALID_VALUE);
1270 }
1271
1272 /**
1273 * @tc.number: GetCurrentAppCloneIndex_0100
1274 * @tc.name: GetCurrentAppCloneIndex
1275 * @tc.desc: GetCurrentAppCloneIndex fail with no permission
1276 */
1277 HWTEST_F(ApplicationContextTest, GetCurrentAppCloneIndex_0100, TestSize.Level1)
1278 {
1279 int32_t res = context_->GetCurrentAppCloneIndex();
1280 EXPECT_EQ(res, 0);
1281 }
1282
1283 /**
1284 * @tc.number: SetCurrentAppCloneIndex_0100
1285 * @tc.name: SetCurrentAppCloneIndex
1286 * @tc.desc: SetCurrentAppCloneIndex fail with no permission
1287 */
1288 HWTEST_F(ApplicationContextTest, SetCurrentAppCloneIndex_0100, TestSize.Level1)
1289 {
1290 int32_t appIndex = 3;
1291 context_->SetCurrentAppCloneIndex(appIndex);
1292 int32_t res = context_->GetCurrentAppCloneIndex();
1293 EXPECT_EQ(res, appIndex);
1294 }
1295
1296 /**
1297 * @tc.number: GetCurrentAppMode_0100
1298 * @tc.name: GetCurrentAppMode
1299 * @tc.desc: GetCurrentAppMode fail with no permission
1300 */
1301 HWTEST_F(ApplicationContextTest, GetCurrentAppMode_0100, TestSize.Level1)
1302 {
1303 int32_t res = context_->GetCurrentAppMode();
1304 EXPECT_EQ(res, 0);
1305 }
1306
1307 /**
1308 * @tc.number:SetCurrentAppMode_0100
1309 * @tc.name: SetCurrentAppMode
1310 * @tc.desc: SetCurrentAppMode fail with no permission
1311 */
1312 HWTEST_F(ApplicationContextTest, SetCurrentAppMode_0100, TestSize.Level1)
1313 {
1314 int32_t appMode = 7;
1315 context_->SetCurrentAppMode(appMode);
1316 int32_t res = context_->GetCurrentAppMode();
1317 EXPECT_EQ(res, appMode);
1318 }
1319
1320 /**
1321 * @tc.number:DispatchOnAbilityWillContinue_0100
1322 * @tc.name: DispatchOnAbilityWillContinue
1323 * @tc.desc: DispatchOnAbilityWillContinue fail with no permission
1324 */
1325 HWTEST_F(ApplicationContextTest, DispatchOnAbilityWillContinue_0100, TestSize.Level1)
1326 {
1327 GTEST_LOG_(INFO) << "DispatchOnAbilityWillContinue_0100 start";
1328 std::shared_ptr<NativeReference> ability = nullptr;
1329 context_->DispatchOnAbilityWillContinue(ability);
1330 EXPECT_TRUE(context_ != nullptr);
1331 GTEST_LOG_(INFO) << "DispatchOnAbilityWillContinue_0100 end";
1332 }
1333
1334 /**
1335 * @tc.number:DispatchOnWindowStageWillRestore_0100
1336 * @tc.name: DispatchOnWindowStageWillRestore
1337 * @tc.desc: DispatchOnWindowStageWillRestore fail with no permission
1338 */
1339 HWTEST_F(ApplicationContextTest, DispatchOnWindowStageWillRestore_0100, TestSize.Level1)
1340 {
1341 GTEST_LOG_(INFO) << "DispatchOnWindowStageWillRestore_0100 start";
1342 std::shared_ptr<NativeReference> ability = nullptr;
1343 std::shared_ptr<NativeReference> winstage = nullptr;
1344 context_->DispatchOnWindowStageWillRestore(ability, winstage);
1345 EXPECT_TRUE(context_ != nullptr);
1346 GTEST_LOG_(INFO) << "DispatchOnWindowStageWillRestore_0100 end";
1347 }
1348
1349 /**
1350 * @tc.number:DispatchOnWindowStageRestore_0100
1351 * @tc.name: DispatchOnWindowStageRestore
1352 * @tc.desc: DispatchOnWindowStageRestore fail with no permission
1353 */
1354 HWTEST_F(ApplicationContextTest, DispatchOnWindowStageRestore_0100, TestSize.Level1)
1355 {
1356 GTEST_LOG_(INFO) << "DispatchOnWindowStageRestore_0100 start";
1357 std::shared_ptr<NativeReference> ability = nullptr;
1358 std::shared_ptr<NativeReference> winstage = nullptr;
1359 context_->DispatchOnWindowStageRestore(ability, winstage);
1360 EXPECT_TRUE(context_ != nullptr);
1361 GTEST_LOG_(INFO) << "DispatchOnWindowStageRestore_0100 end";
1362 }
1363
1364 /**
1365 * @tc.number:DispatchOnAbilityWillSaveState_0100
1366 * @tc.name: DispatchOnAbilityWillSaveState
1367 * @tc.desc: DispatchOnAbilityWillSaveState fail with no permission
1368 */
1369 HWTEST_F(ApplicationContextTest, DispatchOnAbilityWillSaveState_0100, TestSize.Level1)
1370 {
1371 GTEST_LOG_(INFO) << "DispatchOnAbilityWillSaveState_0100 start";
1372 std::shared_ptr<NativeReference> ability = nullptr;
1373 context_->DispatchOnAbilityWillSaveState(ability);
1374 EXPECT_TRUE(context_ != nullptr);
1375 GTEST_LOG_(INFO) << "DispatchOnAbilityWillSaveState_0100 end";
1376 }
1377
1378 /**
1379 * @tc.number:DispatchOnAbilitySaveState_0100
1380 * @tc.name: DispatchOnAbilitySaveState
1381 * @tc.desc: DispatchOnAbilitySaveState fail with no permission
1382 */
1383 HWTEST_F(ApplicationContextTest, DispatchOnAbilitySaveState_0100, TestSize.Level1)
1384 {
1385 GTEST_LOG_(INFO) << "DispatchOnAbilitySaveState_0100 start";
1386 std::shared_ptr<NativeReference> ability = nullptr;
1387 context_->DispatchOnAbilitySaveState(ability);
1388 EXPECT_TRUE(context_ != nullptr);
1389 GTEST_LOG_(INFO) << "DispatchOnAbilitySaveState_0100 end";
1390 }
1391
1392 /**
1393 * @tc.number:DispatchOnWillNewWant_0100
1394 * @tc.name: DispatchOnWillNewWant
1395 * @tc.desc: DispatchOnWillNewWant fail with no permission
1396 */
1397 HWTEST_F(ApplicationContextTest, DispatchOnWillNewWant_0100, TestSize.Level1)
1398 {
1399 GTEST_LOG_(INFO) << "DispatchOnWillNewWant_0100 start";
1400 std::shared_ptr<NativeReference> ability = nullptr;
1401 context_->DispatchOnWillNewWant(ability);
1402 EXPECT_TRUE(context_ != nullptr);
1403 GTEST_LOG_(INFO) << "DispatchOnWillNewWant_0100 end";
1404 }
1405
1406 /**
1407 * @tc.number:DispatchOnNewWant_0100
1408 * @tc.name: DispatchOnNewWant
1409 * @tc.desc: DispatchOnNewWant fail with no permission
1410 */
1411 HWTEST_F(ApplicationContextTest, DispatchOnNewWant_0100, TestSize.Level1)
1412 {
1413 GTEST_LOG_(INFO) << "DispatchOnNewWant_0100 start";
1414 std::shared_ptr<NativeReference> ability = nullptr;
1415 context_->DispatchOnNewWant(ability);
1416 EXPECT_TRUE(context_ != nullptr);
1417 GTEST_LOG_(INFO) << "DispatchOnNewWant_0100 end";
1418 }
1419
1420 /**
1421 * @tc.number:DispatchOnAbilityWillCreate_0100
1422 * @tc.name: DispatchOnAbilityWillCreate
1423 * @tc.desc: DispatchOnAbilityWillCreate fail with no permission
1424 */
1425 HWTEST_F(ApplicationContextTest, DispatchOnAbilityWillCreate_0100, TestSize.Level1)
1426 {
1427 GTEST_LOG_(INFO) << "DispatchOnAbilityWillCreate_0100 start";
1428 std::shared_ptr<NativeReference> ability = nullptr;
1429 context_->DispatchOnAbilityWillCreate(ability);
1430 EXPECT_TRUE(context_ != nullptr);
1431 GTEST_LOG_(INFO) << "DispatchOnAbilityWillCreate_0100 end";
1432 }
1433
1434 /**
1435 * @tc.number:DispatchOnWindowStageWillCreate_0100
1436 * @tc.name: DispatchOnWindowStageWillCreate
1437 * @tc.desc: DispatchOnWindowStageWillCreate fail with no permission
1438 */
1439 HWTEST_F(ApplicationContextTest, DispatchOnWindowStageWillCreate_0100, TestSize.Level1)
1440 {
1441 GTEST_LOG_(INFO) << "DispatchOnWindowStageWillCreate_0100 start";
1442 std::shared_ptr<NativeReference> ability = nullptr;
1443 std::shared_ptr<NativeReference> winstage = nullptr;
1444 context_->DispatchOnWindowStageWillCreate(ability, winstage);
1445 EXPECT_TRUE(context_ != nullptr);
1446 GTEST_LOG_(INFO) << "DispatchOnWindowStageWillCreate_0100 end";
1447 }
1448
1449 /**
1450 * @tc.number:DispatchOnWindowStageWillDestroy_0100
1451 * @tc.name: DispatchOnWindowStageWillDestroy
1452 * @tc.desc: DispatchOnWindowStageWillDestroy fail with no permission
1453 */
1454 HWTEST_F(ApplicationContextTest, DispatchOnWindowStageWillDestroy_0100, TestSize.Level1)
1455 {
1456 GTEST_LOG_(INFO) << "DispatchOnWindowStageWillDestroy_0100 start";
1457 std::shared_ptr<NativeReference> ability = nullptr;
1458 std::shared_ptr<NativeReference> winstage = nullptr;
1459 context_->DispatchOnWindowStageWillDestroy(ability, winstage);
1460 EXPECT_TRUE(context_ != nullptr);
1461 GTEST_LOG_(INFO) << "DispatchOnWindowStageWillDestroy_0100 end";
1462 }
1463
1464 /**
1465 * @tc.number:DispatchOnAbilityWillDestroy_0100
1466 * @tc.name: DispatchOnAbilityWillDestroy
1467 * @tc.desc: DispatchOnAbilityWillDestroy fail with no permission
1468 */
1469 HWTEST_F(ApplicationContextTest, DispatchOnAbilityWillDestroy_0100, TestSize.Level1)
1470 {
1471 GTEST_LOG_(INFO) << "DispatchOnAbilityWillDestroy_0100 start";
1472 std::shared_ptr<NativeReference> ability = nullptr;
1473 context_->DispatchOnAbilityWillDestroy(ability);
1474 EXPECT_TRUE(context_ != nullptr);
1475 GTEST_LOG_(INFO) << "DispatchOnAbilityWillDestroy_0100 end";
1476 }
1477
1478 /**
1479 * @tc.number:DispatchOnAbilityWillForeground_0100
1480 * @tc.name: DispatchOnAbilityWillForeground
1481 * @tc.desc: DispatchOnAbilityWillForeground fail with no permission
1482 */
1483 HWTEST_F(ApplicationContextTest, DispatchOnAbilityWillForeground_0100, TestSize.Level1)
1484 {
1485 GTEST_LOG_(INFO) << "DispatchOnAbilityWillForeground_0100 start";
1486 std::shared_ptr<NativeReference> ability = nullptr;
1487 context_->DispatchOnAbilityWillForeground(ability);
1488 EXPECT_TRUE(context_ != nullptr);
1489 GTEST_LOG_(INFO) << "DispatchOnAbilityWillForeground_0100 end";
1490 }
1491
1492 /**
1493 * @tc.number:DispatchOnAbilityWillBackground_0100
1494 * @tc.name: DispatchOnAbilityWillBackground
1495 * @tc.desc: DispatchOnAbilityWillBackground fail with no permission
1496 */
1497 HWTEST_F(ApplicationContextTest, DispatchOnAbilityWillBackground_0100, TestSize.Level1)
1498 {
1499 GTEST_LOG_(INFO) << "DispatchOnAbilityWillBackground_0100 start";
1500 std::shared_ptr<NativeReference> ability = nullptr;
1501 context_->DispatchOnAbilityWillBackground(ability);
1502 EXPECT_TRUE(context_ != nullptr);
1503 GTEST_LOG_(INFO) << "DispatchOnAbilityWillBackground_0100 end";
1504 }
1505
1506 /**
1507 * @tc.number:SetFont_0100
1508 * @tc.name: SetFont
1509 * @tc.desc: SetFont fail with no permission
1510 */
1511 HWTEST_F(ApplicationContextTest, SetFont_0100, TestSize.Level1)
1512 {
1513 context_->SetFont("awk");
1514 EXPECT_TRUE(context_ != nullptr);
1515 }
1516
1517 /**
1518 * @tc.number:SetMcc_0100
1519 * @tc.name: SetMcc
1520 * @tc.desc: SetMcc fail with no permission
1521 */
1522 HWTEST_F(ApplicationContextTest, SetMcc_0100, TestSize.Level1)
1523 {
1524 context_->SetMcc("mcc");
1525 EXPECT_TRUE(context_ != nullptr);
1526 }
1527
1528 /**
1529 * @tc.number:SetMnc_0100
1530 * @tc.name: SetMnc
1531 * @tc.desc: SetMnc fail with no permission
1532 */
1533 HWTEST_F(ApplicationContextTest, SetMnc_0100, TestSize.Level1)
1534 {
1535 context_->SetMnc("mnc");
1536 EXPECT_TRUE(context_ != nullptr);
1537 }
1538
1539 /**
1540 * @tc.number:GetDataDir_0100
1541 * @tc.name: GetDataDir
1542 * @tc.desc: Get DataDir fail
1543 */
1544 HWTEST_F(ApplicationContextTest, GetDataDir_0100, TestSize.Level1)
1545 {
1546 std::string res = context_->GetDataDir();
1547 EXPECT_TRUE(context_ != nullptr);
1548 }
1549
1550 /**
1551 * @tc.number:SetFontSizeScale_0100
1552 * @tc.name: SetFontSizeScale
1553 * @tc.desc: SetFontSizeScale fail with no permission
1554 */
1555 HWTEST_F(ApplicationContextTest, SetFontSizeScale_0100, TestSize.Level1)
1556 {
1557 GTEST_LOG_(INFO) << "SetFontSizeScale_0100 start";
1558 context_->AttachContextImpl(mock_);
1559 double fontSizeScale = 1.5;
1560 bool result1 = context_->SetFontSizeScale(fontSizeScale);
1561 EXPECT_TRUE(result1);
1562 mock_ = nullptr;
1563 context_->AttachContextImpl(mock_);
1564 bool result = context_->SetFontSizeScale(fontSizeScale);
1565 EXPECT_FALSE(result);
1566 GTEST_LOG_(INFO) << "SetFontSizeScale_0100 end";
1567 }
1568
1569 /**
1570 * @tc.number:RegisterProcessSecurityExit_0100
1571 * @tc.name: RegisterProcessSecurityExit
1572 * @tc.desc: RegisterProcessSecurityExit fail with no permission
1573 */
1574 HWTEST_F(ApplicationContextTest, RegisterProcessSecurityExit_0100, TestSize.Level1)
1575 {
1576 GTEST_LOG_(INFO) << "RegisterProcessSecurityExit_0100 start";
__anon50769c580102(const AAFwk::ExitReason &exitReason)1577 AppProcessExitCallback appProcessExitCallback = [](const AAFwk::ExitReason &exitReason){};
1578 context_->appProcessExitCallback_ = nullptr;
1579 context_->RegisterProcessSecurityExit(appProcessExitCallback);
1580 EXPECT_TRUE(context_->appProcessExitCallback_ != nullptr);
1581 GTEST_LOG_(INFO) << "RegisterProcessSecurityExit_0100 end";
1582 }
1583
1584 /**
1585 * @tc.number:SetCurrentInstanceKey_0100
1586 * @tc.name: SetCurrentInstanceKey
1587 * @tc.desc: SetCurrentInstanceKey fail with no permission
1588 */
1589 HWTEST_F(ApplicationContextTest, SetCurrentInstanceKey_0100, TestSize.Level1)
1590 {
1591 GTEST_LOG_(INFO) << "SetCurrentInstanceKey_0100 start";
1592 std::string instanceKey = "InstanceKey";
1593 context_->SetCurrentInstanceKey(instanceKey);
1594 std::string key = context_->GetCurrentInstanceKey();
1595 EXPECT_TRUE(key == instanceKey);
1596 GTEST_LOG_(INFO) << "SetCurrentInstanceKey_0100 end";
1597 }
1598
1599 /**
1600 * @tc.number:GetAllRunningInstanceKeys_0100
1601 * @tc.name: GetAllRunningInstanceKeys
1602 * @tc.desc: GetAllRunningInstanceKeys fail with no permission
1603 */
1604 HWTEST_F(ApplicationContextTest, GetAllRunningInstanceKeys_0100, TestSize.Level1)
1605 {
1606 GTEST_LOG_(INFO) << "GetAllRunningInstanceKeys_0100 start";
1607 std::vector<std::string> instanceKeys;
1608 int32_t keys = context_->GetAllRunningInstanceKeys(instanceKeys);
1609 EXPECT_TRUE(keys == -1);
1610 GTEST_LOG_(INFO) << "GetAllRunningInstanceKeys_0100 end";
1611 }
1612
1613 /**
1614 * @tc.number:ProcessSecurityExit_0100
1615 * @tc.name: ProcessSecurityExit
1616 * @tc.desc: ProcessSecurityExit fail with no permission
1617 */
1618 HWTEST_F(ApplicationContextTest, ProcessSecurityExit_0100, TestSize.Level1)
1619 {
1620 GTEST_LOG_(INFO) << "ProcessSecurityExit_0100 start";
1621 context_->AttachContextImpl(mock_);
1622 AAFwk::ExitReason exitReason = { AAFwk::Reason::REASON_JS_ERROR, "Js Error." };
1623 context_->ProcessSecurityExit(exitReason);
1624 EXPECT_TRUE(context_->appProcessExitCallback_ == nullptr);
1625 GTEST_LOG_(INFO) << "ProcessSecurityExit_0100 end";
1626 }
1627
1628 /**
1629 * @tc.number:GetProcessName_0100
1630 * @tc.name: GetProcessName
1631 * @tc.desc: GetProcessName fail with null contextImpl
1632 */
1633 HWTEST_F(ApplicationContextTest, GetProcessName_0100, TestSize.Level1)
1634 {
1635 GTEST_LOG_(INFO) << "GetProcessName_0100 start";
1636 ASSERT_NE(context_, nullptr);
1637 context_->AttachContextImpl(nullptr);
1638 auto processName = context_->GetProcessName();
1639 EXPECT_TRUE(processName.empty());
1640 GTEST_LOG_(INFO) << "GetProcessName_0100 end";
1641 }
1642
1643 /**
1644 * @tc.number:GetProcessName_0200
1645 * @tc.name: GetProcessName
1646 * @tc.desc: GetProcessName success
1647 */
1648 HWTEST_F(ApplicationContextTest, GetProcessName_0200, TestSize.Level1)
1649 {
1650 GTEST_LOG_(INFO) << "GetProcessName_0200 start";
1651 ASSERT_NE(context_, nullptr);
1652 context_->AttachContextImpl(mock_);
1653 auto processName = context_->GetProcessName();
1654 EXPECT_EQ(processName, "processName");
1655 GTEST_LOG_(INFO) << "GetProcessName_0200 end";
1656 }
1657
1658 /**
1659 * @tc.number:CreateAreaModeContext_0100
1660 * @tc.name: CreateAreaModeContext
1661 * @tc.desc: CreateAreaModeContext fail with null contextImpl
1662 */
1663 HWTEST_F(ApplicationContextTest, CreateAreaModeContext_0100, TestSize.Level1)
1664 {
1665 GTEST_LOG_(INFO) << "CreateAreaModeContext_0100 start";
1666 ASSERT_NE(context_, nullptr);
1667 context_->AttachContextImpl(nullptr);
1668 auto areaModeContext = context_->CreateAreaModeContext(0);
1669 EXPECT_EQ(areaModeContext, nullptr);
1670 GTEST_LOG_(INFO) << "CreateAreaModeContext_0100 end";
1671 }
1672
1673 /**
1674 * @tc.number:CreateAreaModeContext_0200
1675 * @tc.name: CreateAreaModeContext
1676 * @tc.desc: CreateAreaModeContext success
1677 */
1678 HWTEST_F(ApplicationContextTest, CreateAreaModeContext_0200, TestSize.Level1)
1679 {
1680 GTEST_LOG_(INFO) << "CreateAreaModeContext_0200 start";
1681 ASSERT_NE(context_, nullptr);
1682 context_->AttachContextImpl(mock_);
1683 auto areaModeContext = context_->CreateAreaModeContext(0);
1684 EXPECT_EQ(areaModeContext, nullptr);
1685 GTEST_LOG_(INFO) << "CreateAreaModeContext_0200 end";
1686 }
1687
1688 #ifdef SUPPORT_GRAPHICS
1689 /**
1690 * @tc.number:CreateDisplayContext_0100
1691 * @tc.name: CreateDisplayContext
1692 * @tc.desc: CreateDisplayContext fail with null contextImpl
1693 */
1694 HWTEST_F(ApplicationContextTest, CreateDisplayContext_0100, TestSize.Level1)
1695 {
1696 GTEST_LOG_(INFO) << "CreateDisplayContext_0100 start";
1697 ASSERT_NE(context_, nullptr);
1698 context_->AttachContextImpl(nullptr);
1699 auto displayContext = context_->CreateDisplayContext(0);
1700 EXPECT_EQ(displayContext, nullptr);
1701 GTEST_LOG_(INFO) << "CreateDisplayContext_0100 end";
1702 }
1703
1704 /**
1705 * @tc.number:CreateDisplayContext_0200
1706 * @tc.name: CreateDisplayContext
1707 * @tc.desc: CreateDisplayContext success
1708 */
1709 HWTEST_F(ApplicationContextTest, CreateDisplayContext_0200, TestSize.Level1)
1710 {
1711 GTEST_LOG_(INFO) << "CreateDisplayContext_0200 start";
1712 ASSERT_NE(context_, nullptr);
1713 context_->AttachContextImpl(mock_);
1714 auto displayContext = context_->CreateDisplayContext(0);
1715 EXPECT_EQ(displayContext, nullptr);
1716 GTEST_LOG_(INFO) << "CreateDisplayContext_0200 end";
1717 }
1718 #endif
1719 } // namespace AbilityRuntime
1720 } // namespace OHOS