• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "app_state_observer_test.h"
17 
18 #include "test_log.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace DistributedSchedule {
25 namespace {
26 constexpr int32_t FOREGROUND = 2;
27 constexpr int32_t BACKGROUND = 4;
28 }
29 
SetUpTestCase()30 void AppStateObserverTest::SetUpTestCase()
31 {
32     DTEST_LOG << "AppStateObserverTest::SetUpTestCase" << std::endl;
33 }
34 
TearDownTestCase()35 void AppStateObserverTest::TearDownTestCase()
36 {
37     DTEST_LOG << "AppStateObserverTest::TearDownTestCase" << std::endl;
38 }
39 
TearDown()40 void AppStateObserverTest::TearDown()
41 {
42     DTEST_LOG << "AppStateObserverTest::TearDown" << std::endl;
43 }
44 
SetUp()45 void AppStateObserverTest::SetUp()
46 {
47     DTEST_LOG << "AppStateObserverTest::SetUp" << std::endl;
48     appStateObserver_ = new AppStateObserver();
49 }
50 
51 /**
52  * @tc.name: OnAbilityStateChanged_001
53  * @tc.desc: call OnAbilityStateChanged from distributedsched
54  * @tc.type: FUNC
55  * @tc.require: I6SJQ6
56  */
57 HWTEST_F(AppStateObserverTest, OnAbilityStateChanged_001, TestSize.Level3)
58 {
59     DTEST_LOG << "AppStateObserverTest OnAbilityStateChanged_001 begin" << std::endl;
60 
61     AppExecFwk::AppStateData appStateData;
62     appStateObserver_->OnForegroundApplicationChanged(appStateData);
63 
64     AppExecFwk::AbilityStateData extensionStateData;
65     appStateObserver_->OnExtensionStateChanged(extensionStateData);
66 
67     AppExecFwk::ProcessData processData;
68     appStateObserver_->OnProcessCreated(processData);
69     appStateObserver_->OnProcessDied(processData);
70 
71     AppExecFwk::AbilityStateData abilityStateData;
72     appStateObserver_->OnAbilityStateChanged(abilityStateData);
73     EXPECT_NE(appStateObserver_, nullptr);
74     DTEST_LOG << "AppStateObserverTest OnAbilityStateChanged_001 end" << std::endl;
75 }
76 
77 /**
78  * @tc.name: OnAbilityStateChanged_002
79  * @tc.desc: call OnAbilityStateChanged from distributedsched
80  * @tc.type: FUNC
81  * @tc.require: I6SJQ6
82  */
83 HWTEST_F(AppStateObserverTest, OnAbilityStateChanged_002, TestSize.Level3)
84 {
85     DTEST_LOG << "AppStateObserverTest OnAbilityStateChanged_001 begin" << std::endl;
86     AppExecFwk::AbilityStateData abilityStateData;
87     abilityStateData.abilityState = FOREGROUND;
88     appStateObserver_->OnAbilityStateChanged(abilityStateData);
89     EXPECT_NE(appStateObserver_, nullptr);
90 
91     appStateObserver_->OnAbilityStateChanged(abilityStateData);
92     EXPECT_NE(appStateObserver_, nullptr);
93     DTEST_LOG << "AppStateObserverTest OnAbilityStateChanged_001 end" << std::endl;
94 }
95 
96 /**
97  * @tc.name: OnAbilityStateChanged_003
98  * @tc.desc: call OnAbilityStateChanged from distributedsched
99  * @tc.type: FUNC
100  * @tc.require: I6SJQ6
101  */
102 HWTEST_F(AppStateObserverTest, OnAbilityStateChanged_003, TestSize.Level3)
103 {
104     DTEST_LOG << "AppStateObserverTest OnAbilityStateChanged_001 begin" << std::endl;
105     AppExecFwk::AbilityStateData abilityStateData;
106     abilityStateData.abilityState = BACKGROUND;
107     appStateObserver_->OnAbilityStateChanged(abilityStateData);
108     EXPECT_NE(appStateObserver_, nullptr);
109 
110     appStateObserver_->OnAbilityStateChanged(abilityStateData);
111     EXPECT_NE(appStateObserver_, nullptr);
112     DTEST_LOG << "AppStateObserverTest OnAbilityStateChanged_003 end" << std::endl;
113 }
114 }
115 }