1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17
18 #define private public
19 #include "app_lifecycle_deal.h"
20 #include "mock_app_scheduler.h"
21 #undef private
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace AppExecFwk {
28 class AppLifecycleDealTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 void SetUp() override;
33 void TearDown() override;
34 };
35
SetUpTestCase(void)36 void AppLifecycleDealTest::SetUpTestCase(void)
37 {}
38
TearDownTestCase(void)39 void AppLifecycleDealTest::TearDownTestCase(void)
40 {}
41
SetUp()42 void AppLifecycleDealTest::SetUp()
43 {}
44
TearDown()45 void AppLifecycleDealTest::TearDown()
46 {}
47
48 /**
49 * @tc.name: NotifyAppFault_001
50 * @tc.desc: Verify that the NotifyAppFault interface calls normally
51 * @tc.type: FUNC
52 */
53 HWTEST_F(AppLifecycleDealTest, NotifyAppFault_001, TestSize.Level1)
54 {
55 auto appLifeCycle = std::make_shared<AppLifeCycleDeal>();
56 FaultData faultData;
57 int32_t result = appLifeCycle->NotifyAppFault(faultData);
58 EXPECT_EQ(result, ERR_INVALID_VALUE);
59 }
60
61 /**
62 * @tc.name: NotifyAppFault_002
63 * @tc.desc: Verify that the NotifyAppFault interface calls normally
64 * @tc.type: FUNC
65 */
66 HWTEST_F(AppLifecycleDealTest, NotifyAppFault_002, TestSize.Level1)
67 {
68 auto appLifeCycle = std::make_shared<AppLifeCycleDeal>();
69 sptr<MockAppScheduler> mockAppScheduler = new (std::nothrow) MockAppScheduler();
70 appLifeCycle->SetApplicationClient(mockAppScheduler);
71 FaultData faultData;
72 auto retsult = appLifeCycle->NotifyAppFault(faultData);
73 EXPECT_EQ(ERR_OK, retsult);
74 }
75
76 /**
77 * @tc.name: AttachAppDebug_001
78 * @tc.desc: Test the normal state of AttachAppDebug
79 * @tc.type: FUNC
80 */
81 HWTEST_F(AppLifecycleDealTest, AttachAppDebug_001, TestSize.Level1)
82 {
83 auto appLifeCycle = std::make_shared<AppLifeCycleDeal>();
84 EXPECT_NE(appLifeCycle, nullptr);
85 auto result = appLifeCycle->AttachAppDebug();
86 EXPECT_EQ(result, ERR_INVALID_VALUE);
87 }
88
89 /**
90 * @tc.name: AttachAppDebug_002
91 * @tc.desc: Test the abnormal state of AttachAppDebug
92 * @tc.type: FUNC
93 */
94 HWTEST_F(AppLifecycleDealTest, AttachAppDebug_002, TestSize.Level1)
95 {
96 auto appLifeCycle = std::make_shared<AppLifeCycleDeal>();
97 EXPECT_NE(appLifeCycle, nullptr);
98 sptr<MockAppScheduler> mockAppScheduler = new (std::nothrow) MockAppScheduler();
99 appLifeCycle->SetApplicationClient(mockAppScheduler);
100 auto result = appLifeCycle->AttachAppDebug();
101 EXPECT_EQ(ERR_OK, result);
102 }
103
104 /**
105 * @tc.name: DetachAppDebug_001
106 * @tc.desc: Test the abnormal state of DetachAppDebug
107 * @tc.type: FUNC
108 */
109 HWTEST_F(AppLifecycleDealTest, DetachAppDebug_001, TestSize.Level1)
110 {
111 auto appLifeCycle = std::make_shared<AppLifeCycleDeal>();
112 EXPECT_NE(appLifeCycle, nullptr);
113 auto result = appLifeCycle->DetachAppDebug();
114 EXPECT_EQ(result, ERR_INVALID_VALUE);
115 }
116
117 /**
118 * @tc.name: DetachAppDebug_002
119 * @tc.desc: Test the normal state of DetachAppDebug
120 * @tc.type: FUNC
121 */
122 HWTEST_F(AppLifecycleDealTest, DetachAppDebug_002, TestSize.Level1)
123 {
124 auto appLifeCycle = std::make_shared<AppLifeCycleDeal>();
125 EXPECT_NE(appLifeCycle, nullptr);
126 sptr<MockAppScheduler> mockAppScheduler = new (std::nothrow) MockAppScheduler();
127 appLifeCycle->SetApplicationClient(mockAppScheduler);
128 auto result = appLifeCycle->DetachAppDebug();
129 EXPECT_EQ(ERR_OK, result);
130 }
131
132 /**
133 * @tc.name: ChangeAppGcState_001
134 * @tc.desc: Verify that the ChangeAppGcState interface calls normally
135 * @tc.type: FUNC
136 */
137 HWTEST_F(AppLifecycleDealTest, ChangeAppGcState_001, TestSize.Level1)
138 {
139 auto appLifeCycle = std::make_shared<AppLifeCycleDeal>();
140 int32_t result = appLifeCycle->ChangeAppGcState(0);
141 EXPECT_EQ(result, ERR_INVALID_VALUE);
142 sptr<MockAppScheduler> mockAppScheduler = new (std::nothrow) MockAppScheduler();
143 appLifeCycle->SetApplicationClient(mockAppScheduler);
144 int32_t result1 = appLifeCycle->ChangeAppGcState(0);
145 EXPECT_EQ(ERR_OK, result1);
146 }
147 } // namespace AppExecFwk
148 } // namespace OHOS
149