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