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 using namespace testing::ext;
28 
29 
30 namespace OHOS {
31 namespace AbilityRuntime {
32 class ApplicationContextTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp() override;
37     void TearDown() override;
38     std::shared_ptr<ApplicationContext> context_ = nullptr;
39     std::shared_ptr<MockContextImpl> mock_ = nullptr;
40 };
41 
SetUpTestCase(void)42 void ApplicationContextTest::SetUpTestCase(void)
43 {}
44 
TearDownTestCase(void)45 void ApplicationContextTest::TearDownTestCase(void)
46 {}
47 
SetUp()48 void ApplicationContextTest::SetUp()
49 {
50     context_ = std::make_shared<ApplicationContext>();
51     mock_ = std::make_shared<MockContextImpl>();
52 }
53 
TearDown()54 void ApplicationContextTest::TearDown()
55 {}
56 
57 /**
58  * @tc.number: RegisterAbilityLifecycleCallback_0100
59  * @tc.name: RegisterAbilityLifecycleCallback
60  * @tc.desc: Register Ability Lifecycle Callback
61  */
62 HWTEST_F(ApplicationContextTest, RegisterAbilityLifecycleCallback_0100, TestSize.Level1)
63 {
64     GTEST_LOG_(INFO) << "RegisterAbilityLifecycleCallback_0100 start";
65     context_->callbacks_.clear();
66     std::shared_ptr<AbilityLifecycleCallback> abilityLifecycleCallback = nullptr;
67     context_->RegisterAbilityLifecycleCallback(abilityLifecycleCallback);
68     EXPECT_TRUE(context_->IsAbilityLifecycleCallbackEmpty());
69     GTEST_LOG_(INFO) << "RegisterAbilityLifecycleCallback_0100 end";
70 }
71 
72 /**
73  * @tc.number: RegisterEnvironmentCallback_0100
74  * @tc.name: RegisterEnvironmentCallback
75  * @tc.desc: Register Environment Callback
76  */
77 HWTEST_F(ApplicationContextTest, RegisterEnvironmentCallback_0100, TestSize.Level1)
78 {
79     GTEST_LOG_(INFO) << "RegisterEnvironmentCallback_0100 start";
80     context_->envCallbacks_.clear();
81     std::shared_ptr<EnvironmentCallback> environmentCallback = nullptr;
82     context_->RegisterEnvironmentCallback(environmentCallback);
83     EXPECT_TRUE(context_->envCallbacks_.empty());
84     GTEST_LOG_(INFO) << "RegisterEnvironmentCallback_0100 end";
85 }
86 
87 /**
88  * @tc.number: GetBundleName_0100
89  * @tc.name: GetBundleName
90  * @tc.desc: Get BundleName failed
91  */
92 HWTEST_F(ApplicationContextTest, GetBundleName_0100, TestSize.Level1)
93 {
94     GTEST_LOG_(INFO) << "GetBundleName_0100 start";
95     std::shared_ptr<ContextImpl> contextImpl = nullptr;
96     context_->AttachContextImpl(contextImpl);
97     auto ret = context_->GetBundleName();
98     EXPECT_EQ(ret, "");
99     GTEST_LOG_(INFO) << "GetBundleName_0100 end";
100 }
101 
102 /**
103  * @tc.number: GetBundleName_0200
104  * @tc.name: GetBundleName
105  * @tc.desc: Get BundleName sucess
106  */
107 HWTEST_F(ApplicationContextTest, GetBundleName_0200, TestSize.Level1)
108 {
109     GTEST_LOG_(INFO) << "GetBundleName_0200 start";
110     context_->AttachContextImpl(mock_);
111     auto ret = context_->GetBundleName();
112     EXPECT_EQ(ret, "com.test.bundleName");
113     GTEST_LOG_(INFO) << "GetBundleName_0200 end";
114 }
115 
116 /**
117  * @tc.number: CreateBundleContext_0100
118  * @tc.name: CreateBundleContext
119  * @tc.desc: Create BundleContext failed
120  */
121 HWTEST_F(ApplicationContextTest, CreateBundleContext_0100, TestSize.Level1)
122 {
123     GTEST_LOG_(INFO) << "CreateBundleContext_0100 start";
124     std::shared_ptr<ContextImpl> contextImpl = nullptr;
125     context_->AttachContextImpl(contextImpl);
126     std::string bundleName = "com.test.bundleName";
127     auto ret = context_->CreateBundleContext(bundleName);
128     EXPECT_EQ(ret, nullptr);
129     GTEST_LOG_(INFO) << "CreateBundleContext_0100 end";
130 }
131 
132 /**
133  * @tc.number: CreateBundleContext_0200
134  * @tc.name: CreateBundleContext
135  * @tc.desc: Create BundleContext sucess
136  */
137 HWTEST_F(ApplicationContextTest, CreateBundleContext_0200, TestSize.Level1)
138 {
139     GTEST_LOG_(INFO) << "CreateBundleContext_0200 start";
140     context_->AttachContextImpl(mock_);
141     std::string bundleName = "com.test.bundleName";
142     auto ret = context_->CreateBundleContext(bundleName);
143     EXPECT_NE(ret, nullptr);
144     GTEST_LOG_(INFO) << "CreateBundleContext_0200 end";
145 }
146 
147 /**
148  * @tc.number: CreateModuleContext_0100
149  * @tc.name: CreateModuleContext
150  * @tc.desc: Create ModuleContext failed
151  */
152 HWTEST_F(ApplicationContextTest, CreateModuleContext_0100, TestSize.Level1)
153 {
154     GTEST_LOG_(INFO) << "CreateModuleContext_0100 start";
155     std::shared_ptr<ContextImpl> contextImpl = nullptr;
156     context_->AttachContextImpl(contextImpl);
157     std::string moduleName = "moduleName";
158     auto ret = context_->CreateModuleContext(moduleName);
159     EXPECT_EQ(ret, nullptr);
160     GTEST_LOG_(INFO) << "CreateModuleContext_0100 end";
161 }
162 
163 /**
164  * @tc.number: CreateModuleContext_0200
165  * @tc.name: CreateModuleContext
166  * @tc.desc: Create ModuleContext sucess
167  */
168 HWTEST_F(ApplicationContextTest, CreateModuleContext_0200, TestSize.Level1)
169 {
170     GTEST_LOG_(INFO) << "CreateModuleContext_0200 start";
171     context_->AttachContextImpl(mock_);
172     std::string moduleName = "moduleName";
173     auto ret = context_->CreateModuleContext(moduleName);
174     EXPECT_NE(ret, nullptr);
175     GTEST_LOG_(INFO) << "CreateModuleContext_0200 end";
176 }
177 
178 /**
179  * @tc.number: CreateModuleContext_0300
180  * @tc.name: CreateModuleContext
181  * @tc.desc: Create ModuleContext failed
182  */
183 HWTEST_F(ApplicationContextTest, CreateModuleContext_0300, TestSize.Level1)
184 {
185     GTEST_LOG_(INFO) << "CreateModuleContext_0300 start";
186     std::shared_ptr<ContextImpl> contextImpl = nullptr;
187     context_->AttachContextImpl(contextImpl);
188     std::string moduleName = "moduleName";
189     std::string bundleName = "com.test.bundleName";
190     auto ret = context_->CreateModuleContext(bundleName, moduleName);
191     EXPECT_EQ(ret, nullptr);
192     GTEST_LOG_(INFO) << "CreateModuleContext_0300 end";
193 }
194 
195 /**
196  * @tc.number: CreateModuleContext_0400
197  * @tc.name: CreateModuleContext
198  * @tc.desc: Create ModuleContext sucess
199  */
200 HWTEST_F(ApplicationContextTest, CreateModuleContext_0400, TestSize.Level1)
201 {
202     GTEST_LOG_(INFO) << "CreateModuleContext_0400 start";
203     context_->AttachContextImpl(mock_);
204     std::string moduleName = "moduleName";
205     std::string bundleName = "com.test.bundleName";
206     auto ret = context_->CreateModuleContext(bundleName, moduleName);
207     EXPECT_NE(ret, nullptr);
208     GTEST_LOG_(INFO) << "CreateModuleContext_0400 end";
209 }
210 
211 /**
212  * @tc.number: GetApplicationInfo_0100
213  * @tc.name: GetApplicationInfo
214  * @tc.desc: Get ApplicationInfo failed
215  */
216 HWTEST_F(ApplicationContextTest, GetApplicationInfo_0100, TestSize.Level1)
217 {
218     GTEST_LOG_(INFO) << "GetApplicationInfo_0100 start";
219     std::shared_ptr<ContextImpl> contextImpl = nullptr;
220     context_->AttachContextImpl(contextImpl);
221     auto ret = context_->GetApplicationInfo();
222     EXPECT_EQ(ret, nullptr);
223     GTEST_LOG_(INFO) << "GetApplicationInfo_0100 end";
224 }
225 
226 /**
227  * @tc.number: GetApplicationInfo_0200
228  * @tc.name: GetApplicationInfo
229  * @tc.desc:Get ApplicationInfo sucess
230  */
231 HWTEST_F(ApplicationContextTest, GetApplicationInfo_0200, TestSize.Level1)
232 {
233     GTEST_LOG_(INFO) << "GetApplicationInfo_0200 start";
234     context_->AttachContextImpl(mock_);
235     auto ret = context_->GetApplicationInfo();
236     EXPECT_NE(ret, nullptr);
237     GTEST_LOG_(INFO) << "GetApplicationInfo_0200 end";
238 }
239 
240 /**
241  * @tc.number: GetResourceManager_0100
242  * @tc.name: GetResourceManager
243  * @tc.desc: Get ResourceManager failed
244  */
245 HWTEST_F(ApplicationContextTest, GetResourceManager_0100, TestSize.Level1)
246 {
247     GTEST_LOG_(INFO) << "GetResourceManager_0100 start";
248     std::shared_ptr<ContextImpl> contextImpl = nullptr;
249     context_->AttachContextImpl(contextImpl);
250     auto ret = context_->GetResourceManager();
251     EXPECT_EQ(ret, nullptr);
252     GTEST_LOG_(INFO) << "GetResourceManager_0100 end";
253 }
254 
255 /**
256  * @tc.number: GetApplicationInfo_0200
257  * @tc.name: GetResourceManager
258  * @tc.desc:Get ResourceManager sucess
259  */
260 HWTEST_F(ApplicationContextTest, GetResourceManager_0200, TestSize.Level1)
261 {
262     GTEST_LOG_(INFO) << "GetResourceManager_0200 start";
263     context_->AttachContextImpl(mock_);
264     auto ret = context_->GetResourceManager();
265     EXPECT_NE(ret, nullptr);
266     GTEST_LOG_(INFO) << "GetResourceManager_0200 end";
267 }
268 
269 /**
270  * @tc.number: GetBundleCodePath_0100
271  * @tc.name: GetBundleCodePath
272  * @tc.desc: Get BundleCode Path failed
273  */
274 HWTEST_F(ApplicationContextTest, GetBundleCodePath_0100, TestSize.Level1)
275 {
276     GTEST_LOG_(INFO) << "GetBundleCodePath_0100 start";
277     std::shared_ptr<ContextImpl> contextImpl = nullptr;
278     context_->AttachContextImpl(contextImpl);
279     auto ret = context_->GetBundleCodePath();
280     EXPECT_EQ(ret, "");
281     GTEST_LOG_(INFO) << "GetBundleCodePath_0100 end";
282 }
283 
284 /**
285  * @tc.number: GetBundleCodePath_0200
286  * @tc.name: GetBundleCodePath
287  * @tc.desc:Get BundleCode Path sucess
288  */
289 HWTEST_F(ApplicationContextTest, GetBundleCodePath_0200, TestSize.Level1)
290 {
291     GTEST_LOG_(INFO) << "GetBundleCodePath_0200 start";
292     context_->AttachContextImpl(mock_);
293     auto ret = context_->GetBundleCodePath();
294     EXPECT_EQ(ret, "codePath");
295     GTEST_LOG_(INFO) << "GetBundleCodePath_0200 end";
296 }
297 
298 /**
299  * @tc.number: GetHapModuleInfo_0100
300  * @tc.name: GetHapModuleInfo
301  * @tc.desc: Get HapModuleInfo failed
302  */
303 HWTEST_F(ApplicationContextTest, GetHapModuleInfo_0100, TestSize.Level1)
304 {
305     GTEST_LOG_(INFO) << "GetHapModuleInfo_0100 start";
306     auto ret = context_->GetHapModuleInfo();
307     EXPECT_EQ(ret, nullptr);
308     GTEST_LOG_(INFO) << "GetHapModuleInfo_0100 end";
309 }
310 
311 /**
312  * @tc.number: GetBundleCodeDir_0100
313  * @tc.name: GetBundleCodeDir
314  * @tc.desc: Get Bundle Code Dir failed
315  */
316 HWTEST_F(ApplicationContextTest, GetBundleCodeDir_0100, TestSize.Level1)
317 {
318     GTEST_LOG_(INFO) << "GetBundleCodeDir_0100 start";
319     std::shared_ptr<ContextImpl> contextImpl = nullptr;
320     context_->AttachContextImpl(contextImpl);
321     auto ret = context_->GetBundleCodeDir();
322     EXPECT_EQ(ret, "");
323     GTEST_LOG_(INFO) << "GetBundleCodeDir_0100 end";
324 }
325 
326 /**
327  * @tc.number: GetBundleCodeDir_0200
328  * @tc.name: GetBundleCodeDir
329  * @tc.desc:Get Bundle Code Dir sucess
330  */
331 HWTEST_F(ApplicationContextTest, GetBundleCodeDir_0200, TestSize.Level1)
332 {
333     GTEST_LOG_(INFO) << "GetBundleCodeDir_0200 start";
334     context_->AttachContextImpl(mock_);
335     auto ret = context_->GetBundleCodeDir();
336     EXPECT_EQ(ret, "/code");
337     GTEST_LOG_(INFO) << "GetBundleCodeDir_0200 end";
338 }
339 
340 /**
341  * @tc.number: GetTempDir_0100
342  * @tc.name: GetTempDir
343  * @tc.desc: Get Temp Dir failed
344  */
345 HWTEST_F(ApplicationContextTest, GetTempDir_0100, TestSize.Level1)
346 {
347     GTEST_LOG_(INFO) << "GetTempDir_0100 start";
348     std::shared_ptr<ContextImpl> contextImpl = nullptr;
349     context_->AttachContextImpl(contextImpl);
350     auto ret = context_->GetTempDir();
351     EXPECT_EQ(ret, "");
352     GTEST_LOG_(INFO) << "GetTempDir_0100 end";
353 }
354 
355 /**
356  * @tc.number: GetTempDir_0200
357  * @tc.name: GetTempDir
358  * @tc.desc:Get Temp Dir sucess
359  */
360 HWTEST_F(ApplicationContextTest, GetTempDir_0200, TestSize.Level1)
361 {
362     GTEST_LOG_(INFO) << "GetTempDir_0200 start";
363     context_->AttachContextImpl(mock_);
364     auto ret = context_->GetTempDir();
365     EXPECT_EQ(ret, "/temp");
366     GTEST_LOG_(INFO) << "GetTempDir_0200 end";
367 }
368 
369 /**
370  * @tc.number: GetResourceDir_0100
371  * @tc.name: GetResourceDir
372  * @tc.desc: Get Resource Dir failed
373  */
374 HWTEST_F(ApplicationContextTest, GetResourceDir_0100, TestSize.Level1)
375 {
376     GTEST_LOG_(INFO) << "GetResourceDir_0100 start";
377     std::shared_ptr<ContextImpl> contextImpl = nullptr;
378     context_->AttachContextImpl(contextImpl);
379     auto ret = context_->GetResourceDir();
380     EXPECT_EQ(ret, "");
381     GTEST_LOG_(INFO) << "GetResourceDir_0100 end";
382 }
383 
384 /**
385  * @tc.number: GetResourceDir_0200
386  * @tc.name: GetResourceDir
387  * @tc.desc: Get Resource Dir failed
388  */
389 HWTEST_F(ApplicationContextTest, GetResourceDir_0200, TestSize.Level1)
390 {
391     GTEST_LOG_(INFO) << "GetResourceDir_0200 start";
392     context_->AttachContextImpl(mock_);
393     auto ret = context_->GetResourceDir();
394     EXPECT_EQ(ret, "/resfile");
395     GTEST_LOG_(INFO) << "GetResourceDir_0200 end";
396 }
397 
398 /**
399  * @tc.number: GetGroupDir_0100
400  * @tc.name: GetGroupDir
401  * @tc.desc: Get Group Dir failed
402  */
403 HWTEST_F(ApplicationContextTest, GetGroupDir_0100, TestSize.Level1)
404 {
405     GTEST_LOG_(INFO) << "GetGroupDir_0100 start";
406     std::shared_ptr<ContextImpl> contextImpl = nullptr;
407     context_->AttachContextImpl(contextImpl);
408     auto ret = context_->GetGroupDir("1");
409     EXPECT_EQ(ret, "");
410     GTEST_LOG_(INFO) << "GetGroupDir_0100 end";
411 }
412 
413 /**
414  * @tc.number: GetGroupDir_0200
415  * @tc.name: GetGroupDir
416  * @tc.desc:Get Group Dir sucess
417  */
418 HWTEST_F(ApplicationContextTest, GetGroupDir_0200, TestSize.Level1)
419 {
420     GTEST_LOG_(INFO) << "GetGroupDir_0200 start";
421     context_->AttachContextImpl(mock_);
422     auto ret = context_->GetGroupDir("1");
423     EXPECT_EQ(ret, "/group");
424     GTEST_LOG_(INFO) << "GetGroupDir_0200 end";
425 }
426 
427 /**
428  * @tc.number: GetSystemDatabaseDir_0100
429  * @tc.name: GetSystemDatabaseDir
430  * @tc.desc: Get Group Dir failed
431  */
432 HWTEST_F(ApplicationContextTest, GetSystemDatabaseDir_0100, TestSize.Level1)
433 {
434     GTEST_LOG_(INFO) << "GetSystemDatabaseDir_0100 start";
435     std::shared_ptr<ContextImpl> contextImpl = nullptr;
436     context_->AttachContextImpl(contextImpl);
437     std::string databaseDir;
438     auto ret = context_->GetSystemDatabaseDir("1", true, databaseDir);
439     EXPECT_EQ(ret, OHOS::ERR_INVALID_VALUE);
440     GTEST_LOG_(INFO) << "GetSystemDatabaseDir_0100 end";
441 }
442 
443 /**
444  * @tc.number: GetSystemDatabaseDir_0200
445  * @tc.name: GetSystemDatabaseDir
446  * @tc.desc:Get Group Dir sucess
447  */
448 HWTEST_F(ApplicationContextTest, GetSystemDatabaseDir_0200, TestSize.Level1)
449 {
450     GTEST_LOG_(INFO) << "GetSystemDatabaseDir_0200 start";
451     context_->AttachContextImpl(mock_);
452     std::string databaseDir;
453     auto ret = context_->GetSystemDatabaseDir("1", true, databaseDir);
454     EXPECT_EQ(ret, 0);
455     GTEST_LOG_(INFO) << "GetSystemDatabaseDir_0200 end";
456 }
457 
458 /**
459  * @tc.number: GetSystemPreferencesDir_0100
460  * @tc.name: GetSystemPreferencesDir
461  * @tc.desc: Get Group Dir failed
462  */
463 HWTEST_F(ApplicationContextTest, GetSystemPreferencesDir_0100, TestSize.Level1)
464 {
465     GTEST_LOG_(INFO) << "GetSystemPreferencesDir_0100 start";
466     std::shared_ptr<ContextImpl> contextImpl = nullptr;
467     context_->AttachContextImpl(contextImpl);
468     std::string preferencesDir;
469     auto ret = context_->GetSystemPreferencesDir("1", true, preferencesDir);
470     EXPECT_EQ(ret, OHOS::ERR_INVALID_VALUE);
471     GTEST_LOG_(INFO) << "GetSystemPreferencesDir_0100 end";
472 }
473 
474 /**
475  * @tc.number: GetSystemPreferencesDir_0200
476  * @tc.name: GetSystemPreferencesDir
477  * @tc.desc:Get System Preferences Dir sucess
478  */
479 HWTEST_F(ApplicationContextTest, GetSystemPreferencesDir_0200, TestSize.Level1)
480 {
481     GTEST_LOG_(INFO) << "GetSystemDatabaseDir_0200 start";
482     context_->AttachContextImpl(mock_);
483     std::string preferencesDir;
484     auto ret = context_->GetSystemPreferencesDir("1", true, preferencesDir);
485     EXPECT_EQ(ret, 0);
486     GTEST_LOG_(INFO) << "GetSystemPreferencesDir_0200 end";
487 }
488 
489 /**
490  * @tc.number: GetFilesDir_0100
491  * @tc.name: GetFilesDir
492  * @tc.desc: Get Files Dir failed
493  */
494 HWTEST_F(ApplicationContextTest, GetFilesDir_0100, TestSize.Level1)
495 {
496     GTEST_LOG_(INFO) << "GetFilesDir_0100 start";
497     std::shared_ptr<ContextImpl> contextImpl = nullptr;
498     context_->AttachContextImpl(contextImpl);
499     auto ret = context_->GetFilesDir();
500     EXPECT_EQ(ret, "");
501     GTEST_LOG_(INFO) << "GetFilesDir_0100 end";
502 }
503 
504 /**
505  * @tc.number: GetFilesDir_0200
506  * @tc.name: GetFilesDir
507  * @tc.desc:Get Files Dir sucess
508  */
509 HWTEST_F(ApplicationContextTest, GetFilesDir_0200, TestSize.Level1)
510 {
511     GTEST_LOG_(INFO) << "GetFilesDir_0200 start";
512     context_->AttachContextImpl(mock_);
513     auto ret = context_->GetFilesDir();
514     EXPECT_EQ(ret, "/files");
515     GTEST_LOG_(INFO) << "GetFilesDir_0200 end";
516 }
517 
518 /**
519  * @tc.number: IsUpdatingConfigurations_0100
520  * @tc.name: IsUpdatingConfigurations
521  * @tc.desc: Is Updating Configurations failed
522  */
523 HWTEST_F(ApplicationContextTest, IsUpdatingConfigurations_0100, TestSize.Level1)
524 {
525     GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0100 start";
526     std::shared_ptr<ContextImpl> contextImpl = nullptr;
527     context_->AttachContextImpl(contextImpl);
528     auto ret = context_->IsUpdatingConfigurations();
529     EXPECT_EQ(ret, false);
530     GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0100 end";
531 }
532 
533 /**
534  * @tc.number: IsUpdatingConfigurations_0200
535  * @tc.name: IsUpdatingConfigurations
536  * @tc.desc:Is Updating Configurations sucess
537  */
538 HWTEST_F(ApplicationContextTest, IsUpdatingConfigurations_0200, TestSize.Level1)
539 {
540     GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0200 start";
541     context_->AttachContextImpl(mock_);
542     auto ret = context_->IsUpdatingConfigurations();
543     EXPECT_EQ(ret, true);
544     GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0200 end";
545 }
546 
547 /**
548  * @tc.number: PrintDrawnCompleted_0100
549  * @tc.name: PrintDrawnCompleted
550  * @tc.desc: Print Drawn Completed failed
551  */
552 HWTEST_F(ApplicationContextTest, PrintDrawnCompleted_0100, TestSize.Level1)
553 {
554     GTEST_LOG_(INFO) << "PrintDrawnCompleted_0100 start";
555     std::shared_ptr<ContextImpl> contextImpl = nullptr;
556     context_->AttachContextImpl(contextImpl);
557     auto ret = context_->PrintDrawnCompleted();
558     EXPECT_EQ(ret, false);
559     GTEST_LOG_(INFO) << "PrintDrawnCompleted_0100 end";
560 }
561 
562 /**
563  * @tc.number: PrintDrawnCompleted_0200
564  * @tc.name: PrintDrawnCompleted
565  * @tc.desc:Print Drawn Completed sucess
566  */
567 HWTEST_F(ApplicationContextTest, PrintDrawnCompleted_0200, TestSize.Level1)
568 {
569     GTEST_LOG_(INFO) << "PrintDrawnCompleted_0200 start";
570     context_->AttachContextImpl(mock_);
571     auto ret = context_->PrintDrawnCompleted();
572     EXPECT_EQ(ret, true);
573     GTEST_LOG_(INFO) << "PrintDrawnCompleted_0200 end";
574 }
575 
576 /**
577  * @tc.number: GetDatabaseDir_0100
578  * @tc.name: GetDatabaseDir
579  * @tc.desc: Get Data base Dir failed
580  */
581 HWTEST_F(ApplicationContextTest, GetDatabaseDir_0100, TestSize.Level1)
582 {
583     GTEST_LOG_(INFO) << "GetDatabaseDir_0100 start";
584     std::shared_ptr<ContextImpl> contextImpl = nullptr;
585     context_->AttachContextImpl(contextImpl);
586     auto ret = context_->GetDatabaseDir();
587     EXPECT_EQ(ret, "");
588     GTEST_LOG_(INFO) << "GetDatabaseDir_0100 end";
589 }
590 
591 /**
592  * @tc.number: GetDatabaseDir_0200
593  * @tc.name: GetDatabaseDir
594  * @tc.desc:Get Data base Dir sucess
595  */
596 HWTEST_F(ApplicationContextTest, GetDatabaseDir_0200, TestSize.Level1)
597 {
598     GTEST_LOG_(INFO) << "GetDatabaseDir_0200 start";
599     context_->AttachContextImpl(mock_);
600     auto ret = context_->GetDatabaseDir();
601     EXPECT_EQ(ret, "/data/app/database");
602     GTEST_LOG_(INFO) << "GetDatabaseDir_0200 end";
603 }
604 
605 /**
606  * @tc.number: GetPreferencesDir_0100
607  * @tc.name: GetPreferencesDir
608  * @tc.desc: Get Preferences Dir failed
609  */
610 HWTEST_F(ApplicationContextTest, GetPreferencesDir_0100, TestSize.Level1)
611 {
612     GTEST_LOG_(INFO) << "GetPreferencesDir_0100 start";
613     std::shared_ptr<ContextImpl> contextImpl = nullptr;
614     context_->AttachContextImpl(contextImpl);
615     auto ret = context_->GetPreferencesDir();
616     EXPECT_EQ(ret, "");
617     GTEST_LOG_(INFO) << "GetPreferencesDir_0100 end";
618 }
619 
620 /**
621  * @tc.number: GetPreferencesDir_0200
622  * @tc.name: GetPreferencesDir
623  * @tc.desc:Get Preferences Dir sucess
624  */
625 HWTEST_F(ApplicationContextTest, GetPreferencesDir_0200, TestSize.Level1)
626 {
627     GTEST_LOG_(INFO) << "GetPreferencesDir_0200 start";
628     context_->AttachContextImpl(mock_);
629     auto ret = context_->GetPreferencesDir();
630     EXPECT_EQ(ret, "/preferences");
631     GTEST_LOG_(INFO) << "GetPreferencesDir_0200 end";
632 }
633 
634 /**
635  * @tc.number: GetDistributedFilesDir_0100
636  * @tc.name: GetDistributedFilesDir
637  * @tc.desc: Get Distributed Files Dir failed
638  */
639 HWTEST_F(ApplicationContextTest, GetDistributedFilesDir_0100, TestSize.Level1)
640 {
641     GTEST_LOG_(INFO) << "GetDistributedFilesDir_0100 start";
642     std::shared_ptr<ContextImpl> contextImpl = nullptr;
643     context_->AttachContextImpl(contextImpl);
644     auto ret = context_->GetDistributedFilesDir();
645     EXPECT_EQ(ret, "");
646     GTEST_LOG_(INFO) << "GetDistributedFilesDir_0100 end";
647 }
648 
649 /**
650  * @tc.number: GetDistributedFilesDir_0200
651  * @tc.name: GetDistributedFilesDir
652  * @tc.desc:Get Distributed Files Dir sucess
653  */
654 HWTEST_F(ApplicationContextTest, GetDistributedFilesDir_0200, TestSize.Level1)
655 {
656     GTEST_LOG_(INFO) << "GetDistributedFilesDir_0200 start";
657     context_->AttachContextImpl(mock_);
658     auto ret = context_->GetDistributedFilesDir();
659     EXPECT_EQ(ret, "/mnt/hmdfs/device_view/local/data/bundleName");
660     GTEST_LOG_(INFO) << "GetDistributedFilesDir_0200 end";
661 }
662 
663 /**
664  * @tc.number: GetCloudFileDir_0100
665  * @tc.name: GetCloudFileDir
666  * @tc.desc: Get Cloud File Dir failed
667  */
668 HWTEST_F(ApplicationContextTest, GetCloudFileDir_0100, TestSize.Level1)
669 {
670     GTEST_LOG_(INFO) << "GetCloudFileDir_0100 start";
671     std::shared_ptr<ContextImpl> contextImpl = nullptr;
672     context_->AttachContextImpl(contextImpl);
673     auto ret = context_->GetCloudFileDir();
674     EXPECT_EQ(ret, "");
675     GTEST_LOG_(INFO) << "GetCloudFileDir_0100 end";
676 }
677 
678 /**
679  * @tc.number: GetToken_0100
680  * @tc.name: GetToken
681  * @tc.desc: Get Token failed
682  */
683 HWTEST_F(ApplicationContextTest, GetToken_0100, TestSize.Level1)
684 {
685     GTEST_LOG_(INFO) << "GetToken_0100 start";
686     std::shared_ptr<ContextImpl> contextImpl = nullptr;
687     context_->AttachContextImpl(contextImpl);
688     auto ret = context_->GetToken();
689     EXPECT_EQ(ret, nullptr);
690     GTEST_LOG_(INFO) << "GetToken_0100 end";
691 }
692 
693 /**
694  * @tc.number: GetToken_0200
695  * @tc.name: GetToken
696  * @tc.desc:Get Token sucess
697  */
698 HWTEST_F(ApplicationContextTest, GetToken_0200, TestSize.Level1)
699 {
700     GTEST_LOG_(INFO) << "GetToken_0200 start";
701     std::shared_ptr<ContextImpl> contextImpl = std::make_shared<ContextImpl>();
702     context_->AttachContextImpl(contextImpl);
703     sptr<IRemoteObject> token = new OHOS::AppExecFwk::MockAbilityToken();
704     context_->SetToken(token);
705     auto ret = context_->GetToken();
706     EXPECT_EQ(ret, token);
707     GTEST_LOG_(INFO) << "GetToken_0200 end";
708 }
709 
710 /**
711  * @tc.number: GetArea_0100
712  * @tc.name: GetArea
713  * @tc.desc: Get Area failed
714  */
715 HWTEST_F(ApplicationContextTest, GetArea_0100, TestSize.Level1)
716 {
717     GTEST_LOG_(INFO) << "GetArea_0100 start";
718     std::shared_ptr<ContextImpl> contextImpl = nullptr;
719     context_->AttachContextImpl(contextImpl);
720     auto ret = context_->GetArea();
721     EXPECT_EQ(ret, 1);
722     GTEST_LOG_(INFO) << "GetArea_0100 end";
723 }
724 
725 /**
726  * @tc.number: GetArea_0200
727  * @tc.name: GetArea
728  * @tc.desc:Get Area sucess
729  */
730 HWTEST_F(ApplicationContextTest, GetArea_0200, TestSize.Level1)
731 {
732     GTEST_LOG_(INFO) << "GetArea_0200 start";
733     std::shared_ptr<ContextImpl> contextImpl = std::make_shared<ContextImpl>();
734     context_->AttachContextImpl(contextImpl);
735     int32_t mode = 1;
736     context_->SwitchArea(mode);
737     auto ret = context_->GetArea();
738     EXPECT_EQ(ret, mode);
739     GTEST_LOG_(INFO) << "GetArea_0200 end";
740 }
741 
742 /**
743  * @tc.number: GetConfiguration_0100
744  * @tc.name: GetConfiguration
745  * @tc.desc: Get Configuration failed
746  */
747 HWTEST_F(ApplicationContextTest, GetConfiguration_0100, TestSize.Level1)
748 {
749     GTEST_LOG_(INFO) << "GetConfiguration_0100 start";
750     std::shared_ptr<ContextImpl> contextImpl = nullptr;
751     context_->AttachContextImpl(contextImpl);
752     auto ret = context_->GetConfiguration();
753     EXPECT_EQ(ret, nullptr);
754     GTEST_LOG_(INFO) << "GetConfiguration_0100 end";
755 }
756 
757 /**
758  * @tc.number: GetConfiguration_0200
759  * @tc.name: GetConfiguration
760  * @tc.desc:Get Configuration sucess
761  */
762 HWTEST_F(ApplicationContextTest, GetConfiguration_0200, TestSize.Level1)
763 {
764     GTEST_LOG_(INFO) << "GetConfiguration_0200 start";
765     context_->AttachContextImpl(mock_);
766     auto ret = context_->GetConfiguration();
767     EXPECT_NE(ret, nullptr);
768     GTEST_LOG_(INFO) << "GetConfiguration_0200 end";
769 }
770 
771 /**
772  * @tc.number: GetBaseDir_0100
773  * @tc.name: GetBaseDir
774  * @tc.desc:Get Base Dir sucess
775  */
776 HWTEST_F(ApplicationContextTest, GetBaseDir_0100, TestSize.Level1)
777 {
778     GTEST_LOG_(INFO) << "GetBaseDir_0100 start";
779     context_->AttachContextImpl(mock_);
780     auto ret = context_->GetBaseDir();
781     EXPECT_EQ(ret, "/data/app/base");
782     GTEST_LOG_(INFO) << "GetBaseDir_0100 end";
783 }
784 
785 /**
786  * @tc.number: GetDeviceType_0100
787  * @tc.name: GetDeviceType
788  * @tc.desc: Get DeviceType failed
789  */
790 HWTEST_F(ApplicationContextTest, GetDeviceType_0100, TestSize.Level1)
791 {
792     GTEST_LOG_(INFO) << "GetDeviceType_0100 start";
793     std::shared_ptr<ContextImpl> contextImpl = nullptr;
794     context_->AttachContextImpl(contextImpl);
795     auto ret = context_->GetDeviceType();
796     EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_PHONE);
797     GTEST_LOG_(INFO) << "GetDeviceType_0100 end";
798 }
799 
800 /**
801  * @tc.number: GetDeviceType_0200
802  * @tc.name: GetDeviceType
803  * @tc.desc:Get DeviceType sucess
804  */
805 HWTEST_F(ApplicationContextTest, GetDeviceType_0200, TestSize.Level1)
806 {
807     GTEST_LOG_(INFO) << "GetDeviceType_0200 start";
808     context_->AttachContextImpl(mock_);
809     auto ret = context_->GetDeviceType();
810     EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_NOT_SET);
811     GTEST_LOG_(INFO) << "GetDeviceType_0200 end";
812 }
813 
814 /**
815  * @tc.number: UnregisterEnvironmentCallback_0100
816  * @tc.name: UnregisterEnvironmentCallback
817  * @tc.desc: unregister Environment Callback
818  */
819 HWTEST_F(ApplicationContextTest, UnregisterEnvironmentCallback_0100, TestSize.Level1)
820 {
821     GTEST_LOG_(INFO) << "UnregisterEnvironmentCallback_0100 start";
822     context_->envCallbacks_.clear();
823     std::shared_ptr<EnvironmentCallback> environmentCallback = nullptr;
824     context_->UnregisterEnvironmentCallback(environmentCallback);
825     EXPECT_TRUE(context_->envCallbacks_.empty());
826     GTEST_LOG_(INFO) << "UnregisterEnvironmentCallback_0100 end";
827 }
828 
829 /**
830  * @tc.number: DispatchOnAbilityCreate_0100
831  * @tc.name: DispatchOnAbilityCreate
832  * @tc.desc: DispatchOnAbilityCreate
833  */
834 HWTEST_F(ApplicationContextTest, DispatchOnAbilityCreate_0100, TestSize.Level1)
835 {
836     GTEST_LOG_(INFO) << "DispatchOnAbilityCreate_0100 start";
837     EXPECT_NE(context_, nullptr);
838     std::shared_ptr<NativeReference> ability = nullptr;
839     context_->DispatchOnAbilityCreate(ability);
840     GTEST_LOG_(INFO) << "DispatchOnAbilityCreate_0100 end";
841 }
842 
843 /**
844  * @tc.number: DispatchOnWindowStageCreate_0100
845  * @tc.name: DispatchOnWindowStageCreate
846  * @tc.desc: DispatchOnWindowStageCreate
847  */
848 HWTEST_F(ApplicationContextTest, DispatchOnWindowStageCreate_0100, TestSize.Level1)
849 {
850     GTEST_LOG_(INFO) << "DispatchOnWindowStageCreate_0100 start";
851     EXPECT_NE(context_, nullptr);
852     std::shared_ptr<NativeReference> ability = nullptr;
853     std::shared_ptr<NativeReference> windowStage = nullptr;
854     context_->DispatchOnWindowStageCreate(ability, windowStage);
855     GTEST_LOG_(INFO) << "DispatchOnWindowStageCreate_0100 end";
856 }
857 
858 /**
859  * @tc.number: DispatchOnWindowStageDestroy_0100
860  * @tc.name: DispatchOnWindowStageDestroy
861  * @tc.desc: DispatchOnWindowStageDestroy
862  */
863 HWTEST_F(ApplicationContextTest, DispatchOnWindowStageDestroy_0100, TestSize.Level1)
864 {
865     GTEST_LOG_(INFO) << "DispatchOnWindowStageDestroy_0100 start";
866     EXPECT_NE(context_, nullptr);
867     std::shared_ptr<NativeReference> ability = nullptr;
868     std::shared_ptr<NativeReference> windowStage = nullptr;
869     context_->DispatchOnWindowStageDestroy(ability, windowStage);
870     GTEST_LOG_(INFO) << "DispatchOnWindowStageDestroy_0100 end";
871 }
872 
873 /**
874  * @tc.number: DispatchWindowStageFocus_0100
875  * @tc.name: DispatchWindowStageFocus
876  * @tc.desc: DispatchWindowStageFocus
877  */
878 HWTEST_F(ApplicationContextTest, DispatchWindowStageFocus_0100, TestSize.Level1)
879 {
880     GTEST_LOG_(INFO) << "DispatchWindowStageFocus_0100 start";
881     EXPECT_NE(context_, nullptr);
882     std::shared_ptr<NativeReference> ability = nullptr;
883     std::shared_ptr<NativeReference> windowStage = nullptr;
884     context_->DispatchWindowStageFocus(ability, windowStage);
885     GTEST_LOG_(INFO) << "DispatchWindowStageFocus_0100 end";
886 }
887 
888 /**
889  * @tc.number: DispatchWindowStageUnfocus_0100
890  * @tc.name: DispatchWindowStageUnfocus
891  * @tc.desc: DispatchWindowStageUnfocus
892  */
893 HWTEST_F(ApplicationContextTest, DispatchWindowStageUnfocus_0100, TestSize.Level1)
894 {
895     GTEST_LOG_(INFO) << "DispatchWindowStageUnfocus_0100 start";
896     EXPECT_NE(context_, nullptr);
897     std::shared_ptr<NativeReference> ability = nullptr;
898     std::shared_ptr<NativeReference> windowStage = nullptr;
899     context_->DispatchWindowStageUnfocus(ability, windowStage);
900     GTEST_LOG_(INFO) << "DispatchWindowStageUnfocus_0100 end";
901 }
902 
903 /**
904  * @tc.number: DispatchOnAbilityDestroy_0100
905  * @tc.name: DispatchOnAbilityDestroy
906  * @tc.desc: DispatchOnAbilityDestroy
907  */
908 HWTEST_F(ApplicationContextTest, DispatchOnAbilityDestroy_0100, TestSize.Level1)
909 {
910     GTEST_LOG_(INFO) << "DispatchOnAbilityDestroy_0100 start";
911     EXPECT_NE(context_, nullptr);
912     std::shared_ptr<NativeReference> ability = nullptr;
913     context_->DispatchOnAbilityDestroy(ability);
914     GTEST_LOG_(INFO) << "DispatchOnAbilityDestroy_0100 end";
915 }
916 
917 /**
918  * @tc.number: DispatchOnAbilityForeground_0100
919  * @tc.name: DispatchOnAbilityForeground
920  * @tc.desc: DispatchOnAbilityForeground
921  */
922 HWTEST_F(ApplicationContextTest, DispatchOnAbilityForeground_0100, TestSize.Level1)
923 {
924     GTEST_LOG_(INFO) << "DispatchOnAbilityForeground_0100 start";
925     EXPECT_NE(context_, nullptr);
926     std::shared_ptr<NativeReference> ability = nullptr;
927     context_->DispatchOnAbilityForeground(ability);
928     GTEST_LOG_(INFO) << "DispatchOnAbilityForeground_0100 end";
929 }
930 
931 /**
932  * @tc.number: DispatchOnAbilityBackground_0100
933  * @tc.name: DispatchOnAbilityBackground
934  * @tc.desc: DispatchOnAbilityBackground
935  */
936 HWTEST_F(ApplicationContextTest, DispatchOnAbilityBackground_0100, TestSize.Level1)
937 {
938     GTEST_LOG_(INFO) << "DispatchOnAbilityBackground_0100 start";
939     EXPECT_NE(context_, nullptr);
940     std::shared_ptr<NativeReference> ability = nullptr;
941     context_->DispatchOnAbilityBackground(ability);
942     GTEST_LOG_(INFO) << "DispatchOnAbilityBackground_0100 end";
943 }
944 
945 /**
946  * @tc.number: DispatchOnAbilityContinue_0100
947  * @tc.name: DispatchOnAbilityContinue
948  * @tc.desc: DispatchOnAbilityContinue
949  */
950 HWTEST_F(ApplicationContextTest, DispatchOnAbilityContinue_0100, TestSize.Level1)
951 {
952     GTEST_LOG_(INFO) << "DispatchOnAbilityContinue_0100 start";
953     EXPECT_NE(context_, nullptr);
954     std::shared_ptr<NativeReference> ability = nullptr;
955     context_->DispatchOnAbilityContinue(ability);
956     GTEST_LOG_(INFO) << "DispatchOnAbilityContinue_0100 end";
957 }
958 
959 /**
960  * @tc.number: SetApplicationInfo_0100
961  * @tc.name: SetApplicationInfo
962  * @tc.desc: SetApplicationInfo
963  */
964 HWTEST_F(ApplicationContextTest, SetApplicationInfo_0100, TestSize.Level1)
965 {
966     GTEST_LOG_(INFO) << "SetApplicationInfo_0100 start";
967     EXPECT_NE(context_, nullptr);
968     std::shared_ptr<AppExecFwk::ApplicationInfo> info = nullptr;
969     context_->SetApplicationInfo(info);
970     GTEST_LOG_(INFO) << "SetApplicationInfo_0100 end";
971 }
972 
973 /**
974  * @tc.number: SetColorMode_0100
975  * @tc.name: SetColorMode
976  * @tc.desc: SetColorMode
977  */
978 HWTEST_F(ApplicationContextTest, SetColorMode_0100, TestSize.Level1)
979 {
980     GTEST_LOG_(INFO) << "SetColorMode_0100 start";
981     EXPECT_NE(context_, nullptr);
982     int32_t colorMode = 1;
983     context_->SetColorMode(colorMode);
984     EXPECT_EQ(colorMode, 1);
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 }  // namespace AbilityRuntime
1539 }  // namespace OHOS