1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #define private public
18 #include "application_context.h"
19 #undef private
20 #include "mock_ability_token.h"
21 #include "mock_context_impl.h"
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace AbilityRuntime {
26 class ApplicationContextTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp() override;
31 void TearDown() override;
32 std::shared_ptr<ApplicationContext> context_ = nullptr;
33 std::shared_ptr<MockContextImpl> mock_ = nullptr;
34 };
35
SetUpTestCase(void)36 void ApplicationContextTest::SetUpTestCase(void)
37 {}
38
TearDownTestCase(void)39 void ApplicationContextTest::TearDownTestCase(void)
40 {}
41
SetUp()42 void ApplicationContextTest::SetUp()
43 {
44 context_ = std::make_shared<ApplicationContext>();
45 mock_ = std::make_shared<MockContextImpl>();
46 }
47
TearDown()48 void ApplicationContextTest::TearDown()
49 {}
50
51 /**
52 * @tc.number: RegisterAbilityLifecycleCallback_0100
53 * @tc.name: RegisterAbilityLifecycleCallback
54 * @tc.desc: Register Ability Lifecycle Callback
55 */
56 HWTEST_F(ApplicationContextTest, RegisterAbilityLifecycleCallback_0100, TestSize.Level1)
57 {
58 GTEST_LOG_(INFO) << "RegisterAbilityLifecycleCallback_0100 start";
59 context_->callbacks_.clear();
60 std::shared_ptr<AbilityLifecycleCallback> abilityLifecycleCallback = nullptr;
61 context_->RegisterAbilityLifecycleCallback(abilityLifecycleCallback);
62 EXPECT_TRUE(context_->IsAbilityLifecycleCallbackEmpty());
63 GTEST_LOG_(INFO) << "RegisterAbilityLifecycleCallback_0100 end";
64 }
65
66 /**
67 * @tc.number: RegisterEnvironmentCallback_0100
68 * @tc.name: RegisterEnvironmentCallback
69 * @tc.desc: Register Environment Callback
70 */
71 HWTEST_F(ApplicationContextTest, RegisterEnvironmentCallback_0100, TestSize.Level1)
72 {
73 GTEST_LOG_(INFO) << "RegisterEnvironmentCallback_0100 start";
74 context_->envCallbacks_.clear();
75 std::shared_ptr<EnvironmentCallback> environmentCallback = nullptr;
76 context_->RegisterEnvironmentCallback(environmentCallback);
77 EXPECT_TRUE(context_->envCallbacks_.empty());
78 GTEST_LOG_(INFO) << "RegisterEnvironmentCallback_0100 end";
79 }
80
81 /**
82 * @tc.number: GetBundleName_0100
83 * @tc.name: GetBundleName
84 * @tc.desc: Get BundleName failed
85 */
86 HWTEST_F(ApplicationContextTest, GetBundleName_0100, TestSize.Level1)
87 {
88 GTEST_LOG_(INFO) << "GetBundleName_0100 start";
89 std::shared_ptr<ContextImpl> contextImpl = nullptr;
90 context_->AttachContextImpl(contextImpl);
91 auto ret = context_->GetBundleName();
92 EXPECT_EQ(ret, "");
93 GTEST_LOG_(INFO) << "GetBundleName_0100 end";
94 }
95
96 /**
97 * @tc.number: GetBundleName_0200
98 * @tc.name: GetBundleName
99 * @tc.desc: Get BundleName sucess
100 */
101 HWTEST_F(ApplicationContextTest, GetBundleName_0200, TestSize.Level1)
102 {
103 GTEST_LOG_(INFO) << "GetBundleName_0200 start";
104 context_->AttachContextImpl(mock_);
105 auto ret = context_->GetBundleName();
106 EXPECT_EQ(ret, "com.test.bundleName");
107 GTEST_LOG_(INFO) << "GetBundleName_0200 end";
108 }
109
110 /**
111 * @tc.number: CreateBundleContext_0100
112 * @tc.name: CreateBundleContext
113 * @tc.desc: Create BundleContext failed
114 */
115 HWTEST_F(ApplicationContextTest, CreateBundleContext_0100, TestSize.Level1)
116 {
117 GTEST_LOG_(INFO) << "CreateBundleContext_0100 start";
118 std::shared_ptr<ContextImpl> contextImpl = nullptr;
119 context_->AttachContextImpl(contextImpl);
120 std::string bundleName = "com.test.bundleName";
121 auto ret = context_->CreateBundleContext(bundleName);
122 EXPECT_EQ(ret, nullptr);
123 GTEST_LOG_(INFO) << "CreateBundleContext_0100 end";
124 }
125
126 /**
127 * @tc.number: CreateBundleContext_0200
128 * @tc.name: CreateBundleContext
129 * @tc.desc: Create BundleContext sucess
130 */
131 HWTEST_F(ApplicationContextTest, CreateBundleContext_0200, TestSize.Level1)
132 {
133 GTEST_LOG_(INFO) << "CreateBundleContext_0200 start";
134 context_->AttachContextImpl(mock_);
135 std::string bundleName = "com.test.bundleName";
136 auto ret = context_->CreateBundleContext(bundleName);
137 EXPECT_NE(ret, nullptr);
138 GTEST_LOG_(INFO) << "CreateBundleContext_0200 end";
139 }
140
141 /**
142 * @tc.number: CreateModuleContext_0100
143 * @tc.name: CreateModuleContext
144 * @tc.desc: Create ModuleContext failed
145 */
146 HWTEST_F(ApplicationContextTest, CreateModuleContext_0100, TestSize.Level1)
147 {
148 GTEST_LOG_(INFO) << "CreateModuleContext_0100 start";
149 std::shared_ptr<ContextImpl> contextImpl = nullptr;
150 context_->AttachContextImpl(contextImpl);
151 std::string moduleName = "moduleName";
152 auto ret = context_->CreateModuleContext(moduleName);
153 EXPECT_EQ(ret, nullptr);
154 GTEST_LOG_(INFO) << "CreateModuleContext_0100 end";
155 }
156
157 /**
158 * @tc.number: CreateModuleContext_0200
159 * @tc.name: CreateModuleContext
160 * @tc.desc: Create ModuleContext sucess
161 */
162 HWTEST_F(ApplicationContextTest, CreateModuleContext_0200, TestSize.Level1)
163 {
164 GTEST_LOG_(INFO) << "CreateModuleContext_0200 start";
165 context_->AttachContextImpl(mock_);
166 std::string moduleName = "moduleName";
167 auto ret = context_->CreateModuleContext(moduleName);
168 EXPECT_NE(ret, nullptr);
169 GTEST_LOG_(INFO) << "CreateModuleContext_0200 end";
170 }
171
172 /**
173 * @tc.number: CreateModuleContext_0300
174 * @tc.name: CreateModuleContext
175 * @tc.desc: Create ModuleContext failed
176 */
177 HWTEST_F(ApplicationContextTest, CreateModuleContext_0300, TestSize.Level1)
178 {
179 GTEST_LOG_(INFO) << "CreateModuleContext_0300 start";
180 std::shared_ptr<ContextImpl> contextImpl = nullptr;
181 context_->AttachContextImpl(contextImpl);
182 std::string moduleName = "moduleName";
183 std::string bundleName = "com.test.bundleName";
184 auto ret = context_->CreateModuleContext(bundleName, moduleName);
185 EXPECT_EQ(ret, nullptr);
186 GTEST_LOG_(INFO) << "CreateModuleContext_0300 end";
187 }
188
189 /**
190 * @tc.number: CreateModuleContext_0400
191 * @tc.name: CreateModuleContext
192 * @tc.desc: Create ModuleContext sucess
193 */
194 HWTEST_F(ApplicationContextTest, CreateModuleContext_0400, TestSize.Level1)
195 {
196 GTEST_LOG_(INFO) << "CreateModuleContext_0400 start";
197 context_->AttachContextImpl(mock_);
198 std::string moduleName = "moduleName";
199 std::string bundleName = "com.test.bundleName";
200 auto ret = context_->CreateModuleContext(bundleName, moduleName);
201 EXPECT_NE(ret, nullptr);
202 GTEST_LOG_(INFO) << "CreateModuleContext_0400 end";
203 }
204
205 /**
206 * @tc.number: GetApplicationInfo_0100
207 * @tc.name: GetApplicationInfo
208 * @tc.desc: Get ApplicationInfo failed
209 */
210 HWTEST_F(ApplicationContextTest, GetApplicationInfo_0100, TestSize.Level1)
211 {
212 GTEST_LOG_(INFO) << "GetApplicationInfo_0100 start";
213 std::shared_ptr<ContextImpl> contextImpl = nullptr;
214 context_->AttachContextImpl(contextImpl);
215 auto ret = context_->GetApplicationInfo();
216 EXPECT_EQ(ret, nullptr);
217 GTEST_LOG_(INFO) << "GetApplicationInfo_0100 end";
218 }
219
220 /**
221 * @tc.number: GetApplicationInfo_0200
222 * @tc.name: GetApplicationInfo
223 * @tc.desc:Get ApplicationInfo sucess
224 */
225 HWTEST_F(ApplicationContextTest, GetApplicationInfo_0200, TestSize.Level1)
226 {
227 GTEST_LOG_(INFO) << "GetApplicationInfo_0200 start";
228 context_->AttachContextImpl(mock_);
229 auto ret = context_->GetApplicationInfo();
230 EXPECT_NE(ret, nullptr);
231 GTEST_LOG_(INFO) << "GetApplicationInfo_0200 end";
232 }
233
234 /**
235 * @tc.number: GetResourceManager_0100
236 * @tc.name: GetResourceManager
237 * @tc.desc: Get ResourceManager failed
238 */
239 HWTEST_F(ApplicationContextTest, GetResourceManager_0100, TestSize.Level1)
240 {
241 GTEST_LOG_(INFO) << "GetResourceManager_0100 start";
242 std::shared_ptr<ContextImpl> contextImpl = nullptr;
243 context_->AttachContextImpl(contextImpl);
244 auto ret = context_->GetResourceManager();
245 EXPECT_EQ(ret, nullptr);
246 GTEST_LOG_(INFO) << "GetResourceManager_0100 end";
247 }
248
249 /**
250 * @tc.number: GetApplicationInfo_0200
251 * @tc.name: GetResourceManager
252 * @tc.desc:Get ResourceManager sucess
253 */
254 HWTEST_F(ApplicationContextTest, GetResourceManager_0200, TestSize.Level1)
255 {
256 GTEST_LOG_(INFO) << "GetResourceManager_0200 start";
257 context_->AttachContextImpl(mock_);
258 auto ret = context_->GetResourceManager();
259 EXPECT_NE(ret, nullptr);
260 GTEST_LOG_(INFO) << "GetResourceManager_0200 end";
261 }
262
263 /**
264 * @tc.number: GetBundleCodePath_0100
265 * @tc.name: GetBundleCodePath
266 * @tc.desc: Get BundleCode Path failed
267 */
268 HWTEST_F(ApplicationContextTest, GetBundleCodePath_0100, TestSize.Level1)
269 {
270 GTEST_LOG_(INFO) << "GetBundleCodePath_0100 start";
271 std::shared_ptr<ContextImpl> contextImpl = nullptr;
272 context_->AttachContextImpl(contextImpl);
273 auto ret = context_->GetBundleCodePath();
274 EXPECT_EQ(ret, "");
275 GTEST_LOG_(INFO) << "GetBundleCodePath_0100 end";
276 }
277
278 /**
279 * @tc.number: GetBundleCodePath_0200
280 * @tc.name: GetBundleCodePath
281 * @tc.desc:Get BundleCode Path sucess
282 */
283 HWTEST_F(ApplicationContextTest, GetBundleCodePath_0200, TestSize.Level1)
284 {
285 GTEST_LOG_(INFO) << "GetBundleCodePath_0200 start";
286 context_->AttachContextImpl(mock_);
287 auto ret = context_->GetBundleCodePath();
288 EXPECT_EQ(ret, "codePath");
289 GTEST_LOG_(INFO) << "GetBundleCodePath_0200 end";
290 }
291
292 /**
293 * @tc.number: GetHapModuleInfo_0100
294 * @tc.name: GetHapModuleInfo
295 * @tc.desc: Get HapModuleInfo failed
296 */
297 HWTEST_F(ApplicationContextTest, GetHapModuleInfo_0100, TestSize.Level1)
298 {
299 GTEST_LOG_(INFO) << "GetHapModuleInfo_0100 start";
300 auto ret = context_->GetHapModuleInfo();
301 EXPECT_EQ(ret, nullptr);
302 GTEST_LOG_(INFO) << "GetHapModuleInfo_0100 end";
303 }
304
305 /**
306 * @tc.number: GetBundleCodeDir_0100
307 * @tc.name: GetBundleCodeDir
308 * @tc.desc: Get Bundle Code Dir failed
309 */
310 HWTEST_F(ApplicationContextTest, GetBundleCodeDir_0100, TestSize.Level1)
311 {
312 GTEST_LOG_(INFO) << "GetBundleCodeDir_0100 start";
313 std::shared_ptr<ContextImpl> contextImpl = nullptr;
314 context_->AttachContextImpl(contextImpl);
315 auto ret = context_->GetBundleCodeDir();
316 EXPECT_EQ(ret, "");
317 GTEST_LOG_(INFO) << "GetBundleCodeDir_0100 end";
318 }
319
320 /**
321 * @tc.number: GetBundleCodeDir_0200
322 * @tc.name: GetBundleCodeDir
323 * @tc.desc:Get Bundle Code Dir sucess
324 */
325 HWTEST_F(ApplicationContextTest, GetBundleCodeDir_0200, TestSize.Level1)
326 {
327 GTEST_LOG_(INFO) << "GetBundleCodeDir_0200 start";
328 context_->AttachContextImpl(mock_);
329 auto ret = context_->GetBundleCodeDir();
330 EXPECT_EQ(ret, "/code");
331 GTEST_LOG_(INFO) << "GetBundleCodeDir_0200 end";
332 }
333
334 /**
335 * @tc.number: GetCacheDir_0100
336 * @tc.name: GetCacheDir
337 * @tc.desc: Get Cache Dir failed
338 */
339 HWTEST_F(ApplicationContextTest, GetCacheDir_0100, TestSize.Level1)
340 {
341 GTEST_LOG_(INFO) << "GetCacheDir_0100 start";
342 std::shared_ptr<ContextImpl> contextImpl = nullptr;
343 context_->AttachContextImpl(contextImpl);
344 auto ret = context_->GetCacheDir();
345 EXPECT_EQ(ret, "");
346 GTEST_LOG_(INFO) << "GetCacheDir_0100 end";
347 }
348
349 /**
350 * @tc.number: GetCacheDir_0200
351 * @tc.name: GetCacheDir
352 * @tc.desc:Get Cache Dir sucess
353 */
354 HWTEST_F(ApplicationContextTest, GetCacheDir_0200, TestSize.Level1)
355 {
356 GTEST_LOG_(INFO) << "GetCacheDir_0200 start";
357 context_->AttachContextImpl(mock_);
358 auto ret = context_->GetCacheDir();
359 EXPECT_EQ(ret, "/cache");
360 GTEST_LOG_(INFO) << "GetCacheDir_0200 end";
361 }
362
363 /**
364 * @tc.number: GetTempDir_0100
365 * @tc.name: GetTempDir
366 * @tc.desc: Get Temp Dir failed
367 */
368 HWTEST_F(ApplicationContextTest, GetTempDir_0100, TestSize.Level1)
369 {
370 GTEST_LOG_(INFO) << "GetTempDir_0100 start";
371 std::shared_ptr<ContextImpl> contextImpl = nullptr;
372 context_->AttachContextImpl(contextImpl);
373 auto ret = context_->GetTempDir();
374 EXPECT_EQ(ret, "");
375 GTEST_LOG_(INFO) << "GetTempDir_0100 end";
376 }
377
378 /**
379 * @tc.number: GetTempDir_0200
380 * @tc.name: GetTempDir
381 * @tc.desc:Get Temp Dir sucess
382 */
383 HWTEST_F(ApplicationContextTest, GetTempDir_0200, TestSize.Level1)
384 {
385 GTEST_LOG_(INFO) << "GetTempDir_0200 start";
386 context_->AttachContextImpl(mock_);
387 auto ret = context_->GetTempDir();
388 EXPECT_EQ(ret, "/temp");
389 GTEST_LOG_(INFO) << "GetTempDir_0200 end";
390 }
391
392 /**
393 * @tc.number: GetFilesDir_0100
394 * @tc.name: GetFilesDir
395 * @tc.desc: Get Files Dir failed
396 */
397 HWTEST_F(ApplicationContextTest, GetFilesDir_0100, TestSize.Level1)
398 {
399 GTEST_LOG_(INFO) << "GetFilesDir_0100 start";
400 std::shared_ptr<ContextImpl> contextImpl = nullptr;
401 context_->AttachContextImpl(contextImpl);
402 auto ret = context_->GetFilesDir();
403 EXPECT_EQ(ret, "");
404 GTEST_LOG_(INFO) << "GetFilesDir_0100 end";
405 }
406
407 /**
408 * @tc.number: GetFilesDir_0200
409 * @tc.name: GetFilesDir
410 * @tc.desc:Get Files Dir sucess
411 */
412 HWTEST_F(ApplicationContextTest, GetFilesDir_0200, TestSize.Level1)
413 {
414 GTEST_LOG_(INFO) << "GetFilesDir_0200 start";
415 context_->AttachContextImpl(mock_);
416 auto ret = context_->GetFilesDir();
417 EXPECT_EQ(ret, "/files");
418 GTEST_LOG_(INFO) << "GetFilesDir_0200 end";
419 }
420
421 /**
422 * @tc.number: IsUpdatingConfigurations_0100
423 * @tc.name: IsUpdatingConfigurations
424 * @tc.desc: Is Updating Configurations failed
425 */
426 HWTEST_F(ApplicationContextTest, IsUpdatingConfigurations_0100, TestSize.Level1)
427 {
428 GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0100 start";
429 std::shared_ptr<ContextImpl> contextImpl = nullptr;
430 context_->AttachContextImpl(contextImpl);
431 auto ret = context_->IsUpdatingConfigurations();
432 EXPECT_EQ(ret, false);
433 GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0100 end";
434 }
435
436 /**
437 * @tc.number: IsUpdatingConfigurations_0200
438 * @tc.name: IsUpdatingConfigurations
439 * @tc.desc:Is Updating Configurations sucess
440 */
441 HWTEST_F(ApplicationContextTest, IsUpdatingConfigurations_0200, TestSize.Level1)
442 {
443 GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0200 start";
444 context_->AttachContextImpl(mock_);
445 auto ret = context_->IsUpdatingConfigurations();
446 EXPECT_EQ(ret, true);
447 GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0200 end";
448 }
449
450 /**
451 * @tc.number: PrintDrawnCompleted_0100
452 * @tc.name: PrintDrawnCompleted
453 * @tc.desc: Print Drawn Completed failed
454 */
455 HWTEST_F(ApplicationContextTest, PrintDrawnCompleted_0100, TestSize.Level1)
456 {
457 GTEST_LOG_(INFO) << "PrintDrawnCompleted_0100 start";
458 std::shared_ptr<ContextImpl> contextImpl = nullptr;
459 context_->AttachContextImpl(contextImpl);
460 auto ret = context_->PrintDrawnCompleted();
461 EXPECT_EQ(ret, false);
462 GTEST_LOG_(INFO) << "PrintDrawnCompleted_0100 end";
463 }
464
465 /**
466 * @tc.number: PrintDrawnCompleted_0200
467 * @tc.name: PrintDrawnCompleted
468 * @tc.desc:Print Drawn Completed sucess
469 */
470 HWTEST_F(ApplicationContextTest, PrintDrawnCompleted_0200, TestSize.Level1)
471 {
472 GTEST_LOG_(INFO) << "PrintDrawnCompleted_0200 start";
473 context_->AttachContextImpl(mock_);
474 auto ret = context_->PrintDrawnCompleted();
475 EXPECT_EQ(ret, true);
476 GTEST_LOG_(INFO) << "PrintDrawnCompleted_0200 end";
477 }
478
479 /**
480 * @tc.number: GetDatabaseDir_0100
481 * @tc.name: GetDatabaseDir
482 * @tc.desc: Get Data base Dir failed
483 */
484 HWTEST_F(ApplicationContextTest, GetDatabaseDir_0100, TestSize.Level1)
485 {
486 GTEST_LOG_(INFO) << "GetDatabaseDir_0100 start";
487 std::shared_ptr<ContextImpl> contextImpl = nullptr;
488 context_->AttachContextImpl(contextImpl);
489 auto ret = context_->GetDatabaseDir();
490 EXPECT_EQ(ret, "");
491 GTEST_LOG_(INFO) << "GetDatabaseDir_0100 end";
492 }
493
494 /**
495 * @tc.number: GetDatabaseDir_0200
496 * @tc.name: GetDatabaseDir
497 * @tc.desc:Get Data base Dir sucess
498 */
499 HWTEST_F(ApplicationContextTest, GetDatabaseDir_0200, TestSize.Level1)
500 {
501 GTEST_LOG_(INFO) << "GetDatabaseDir_0200 start";
502 context_->AttachContextImpl(mock_);
503 auto ret = context_->GetDatabaseDir();
504 EXPECT_EQ(ret, "/data/app/database");
505 GTEST_LOG_(INFO) << "GetDatabaseDir_0200 end";
506 }
507
508 /**
509 * @tc.number: GetPreferencesDir_0100
510 * @tc.name: GetPreferencesDir
511 * @tc.desc: Get Preferences Dir failed
512 */
513 HWTEST_F(ApplicationContextTest, GetPreferencesDir_0100, TestSize.Level1)
514 {
515 GTEST_LOG_(INFO) << "GetPreferencesDir_0100 start";
516 std::shared_ptr<ContextImpl> contextImpl = nullptr;
517 context_->AttachContextImpl(contextImpl);
518 auto ret = context_->GetPreferencesDir();
519 EXPECT_EQ(ret, "");
520 GTEST_LOG_(INFO) << "GetPreferencesDir_0100 end";
521 }
522
523 /**
524 * @tc.number: GetPreferencesDir_0200
525 * @tc.name: GetPreferencesDir
526 * @tc.desc:Get Preferences Dir sucess
527 */
528 HWTEST_F(ApplicationContextTest, GetPreferencesDir_0200, TestSize.Level1)
529 {
530 GTEST_LOG_(INFO) << "GetPreferencesDir_0200 start";
531 context_->AttachContextImpl(mock_);
532 auto ret = context_->GetPreferencesDir();
533 EXPECT_EQ(ret, "/preferences");
534 GTEST_LOG_(INFO) << "GetPreferencesDir_0200 end";
535 }
536
537 /**
538 * @tc.number: GetDistributedFilesDir_0100
539 * @tc.name: GetDistributedFilesDir
540 * @tc.desc: Get Distributed Files Dir failed
541 */
542 HWTEST_F(ApplicationContextTest, GetDistributedFilesDir_0100, TestSize.Level1)
543 {
544 GTEST_LOG_(INFO) << "GetDistributedFilesDir_0100 start";
545 std::shared_ptr<ContextImpl> contextImpl = nullptr;
546 context_->AttachContextImpl(contextImpl);
547 auto ret = context_->GetDistributedFilesDir();
548 EXPECT_EQ(ret, "");
549 GTEST_LOG_(INFO) << "GetDistributedFilesDir_0100 end";
550 }
551
552 /**
553 * @tc.number: GetDistributedFilesDir_0200
554 * @tc.name: GetDistributedFilesDir
555 * @tc.desc:Get Distributed Files Dir sucess
556 */
557 HWTEST_F(ApplicationContextTest, GetDistributedFilesDir_0200, TestSize.Level1)
558 {
559 GTEST_LOG_(INFO) << "GetDistributedFilesDir_0200 start";
560 context_->AttachContextImpl(mock_);
561 auto ret = context_->GetDistributedFilesDir();
562 EXPECT_EQ(ret, "/mnt/hmdfs/device_view/local/data/bundleName");
563 GTEST_LOG_(INFO) << "GetDistributedFilesDir_0200 end";
564 }
565
566 /**
567 * @tc.number: GetToken_0100
568 * @tc.name: GetToken
569 * @tc.desc: Get Token failed
570 */
571 HWTEST_F(ApplicationContextTest, GetToken_0100, TestSize.Level1)
572 {
573 GTEST_LOG_(INFO) << "GetToken_0100 start";
574 std::shared_ptr<ContextImpl> contextImpl = nullptr;
575 context_->AttachContextImpl(contextImpl);
576 auto ret = context_->GetToken();
577 EXPECT_EQ(ret, nullptr);
578 GTEST_LOG_(INFO) << "GetToken_0100 end";
579 }
580
581 /**
582 * @tc.number: GetToken_0200
583 * @tc.name: GetToken
584 * @tc.desc:Get Token sucess
585 */
586 HWTEST_F(ApplicationContextTest, GetToken_0200, TestSize.Level1)
587 {
588 GTEST_LOG_(INFO) << "GetToken_0200 start";
589 std::shared_ptr<ContextImpl> contextImpl = std::make_shared<ContextImpl>();
590 context_->AttachContextImpl(contextImpl);
591 sptr<IRemoteObject> token = new OHOS::AppExecFwk::MockAbilityToken();
592 context_->SetToken(token);
593 auto ret = context_->GetToken();
594 EXPECT_EQ(ret, token);
595 GTEST_LOG_(INFO) << "GetToken_0200 end";
596 }
597
598 /**
599 * @tc.number: GetArea_0100
600 * @tc.name: GetArea
601 * @tc.desc: Get Area failed
602 */
603 HWTEST_F(ApplicationContextTest, GetArea_0100, TestSize.Level1)
604 {
605 GTEST_LOG_(INFO) << "GetArea_0100 start";
606 std::shared_ptr<ContextImpl> contextImpl = nullptr;
607 context_->AttachContextImpl(contextImpl);
608 auto ret = context_->GetArea();
609 EXPECT_EQ(ret, 1);
610 GTEST_LOG_(INFO) << "GetArea_0100 end";
611 }
612
613 /**
614 * @tc.number: GetArea_0200
615 * @tc.name: GetArea
616 * @tc.desc:Get Area sucess
617 */
618 HWTEST_F(ApplicationContextTest, GetArea_0200, TestSize.Level1)
619 {
620 GTEST_LOG_(INFO) << "GetArea_0200 start";
621 std::shared_ptr<ContextImpl> contextImpl = std::make_shared<ContextImpl>();
622 context_->AttachContextImpl(contextImpl);
623 int32_t mode = 1;
624 context_->SwitchArea(mode);
625 auto ret = context_->GetArea();
626 EXPECT_EQ(ret, mode);
627 GTEST_LOG_(INFO) << "GetArea_0200 end";
628 }
629
630 /**
631 * @tc.number: GetConfiguration_0100
632 * @tc.name: GetConfiguration
633 * @tc.desc: Get Configuration failed
634 */
635 HWTEST_F(ApplicationContextTest, GetConfiguration_0100, TestSize.Level1)
636 {
637 GTEST_LOG_(INFO) << "GetConfiguration_0100 start";
638 std::shared_ptr<ContextImpl> contextImpl = nullptr;
639 context_->AttachContextImpl(contextImpl);
640 auto ret = context_->GetConfiguration();
641 EXPECT_EQ(ret, nullptr);
642 GTEST_LOG_(INFO) << "GetConfiguration_0100 end";
643 }
644
645 /**
646 * @tc.number: GetConfiguration_0200
647 * @tc.name: GetConfiguration
648 * @tc.desc:Get Configuration sucess
649 */
650 HWTEST_F(ApplicationContextTest, GetConfiguration_0200, TestSize.Level1)
651 {
652 GTEST_LOG_(INFO) << "GetConfiguration_0200 start";
653 context_->AttachContextImpl(mock_);
654 auto ret = context_->GetConfiguration();
655 EXPECT_NE(ret, nullptr);
656 GTEST_LOG_(INFO) << "GetConfiguration_0200 end";
657 }
658
659 /**
660 * @tc.number: GetBaseDir_0100
661 * @tc.name: GetBaseDir
662 * @tc.desc:Get Base Dir sucess
663 */
664 HWTEST_F(ApplicationContextTest, GetBaseDir_0100, TestSize.Level1)
665 {
666 GTEST_LOG_(INFO) << "GetBaseDir_0100 start";
667 context_->AttachContextImpl(mock_);
668 auto ret = context_->GetBaseDir();
669 EXPECT_EQ(ret, "/data/app/base");
670 GTEST_LOG_(INFO) << "GetBaseDir_0100 end";
671 }
672
673 /**
674 * @tc.number: GetDeviceType_0100
675 * @tc.name: GetDeviceType
676 * @tc.desc: Get DeviceType failed
677 */
678 HWTEST_F(ApplicationContextTest, GetDeviceType_0100, TestSize.Level1)
679 {
680 GTEST_LOG_(INFO) << "GetDeviceType_0100 start";
681 std::shared_ptr<ContextImpl> contextImpl = nullptr;
682 context_->AttachContextImpl(contextImpl);
683 auto ret = context_->GetDeviceType();
684 EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_PHONE);
685 GTEST_LOG_(INFO) << "GetDeviceType_0100 end";
686 }
687
688 /**
689 * @tc.number: GetDeviceType_0200
690 * @tc.name: GetDeviceType
691 * @tc.desc:Get DeviceType sucess
692 */
693 HWTEST_F(ApplicationContextTest, GetDeviceType_0200, TestSize.Level1)
694 {
695 GTEST_LOG_(INFO) << "GetDeviceType_0200 start";
696 context_->AttachContextImpl(mock_);
697 auto ret = context_->GetDeviceType();
698 EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_NOT_SET);
699 GTEST_LOG_(INFO) << "GetDeviceType_0200 end";
700 }
701 } // namespace AbilityRuntime
702 } // namespace OHOS