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_scheduler_proxy.h"
20 #include "fault_data.h"
21 #include "mock_app_scheduler.h"
22 #undef private
23
24 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS {
28 namespace AppExecFwk {
29 namespace {
30 const std::string STRING_BUNDLE_NAME = "bundleName";
31 const std::string EMPTY_BUNDLE_NAME = "";
32 }
33 class AppSchedulerProxyTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp() override;
38 void TearDown() override;
39 sptr<MockAppScheduler> mockAppScheduler_;
40 };
41
SetUpTestCase(void)42 void AppSchedulerProxyTest::SetUpTestCase(void)
43 {}
44
TearDownTestCase(void)45 void AppSchedulerProxyTest::TearDownTestCase(void)
46 {}
47
SetUp()48 void AppSchedulerProxyTest::SetUp()
49 {
50 mockAppScheduler_ = new MockAppScheduler();
51 }
52
TearDown()53 void AppSchedulerProxyTest::TearDown()
54 {}
55
56 /**
57 * @tc.name: ScheduleNotifyAppFault_001
58 * @tc.desc: Verify that the ScheduleNotifyAppFault interface calls normally
59 * @tc.type: FUNC
60 */
61 HWTEST_F(AppSchedulerProxyTest, ScheduleNotifyAppFault_001, TestSize.Level1)
62 {
63 sptr<IRemoteObject> impl;
64 sptr<AppSchedulerProxy> appSchedulerProxy = new (std::nothrow) AppSchedulerProxy(impl);
65 FaultData faultData;
66 faultData.faultType = FaultDataType::APP_FREEZE;
67 faultData.errorObject.message = "msgContent";
68 faultData.errorObject.stack = "stack";
69 faultData.errorObject.name = "eventType";
70 int32_t result = appSchedulerProxy->ScheduleNotifyAppFault(faultData);
71 EXPECT_EQ(result, ERR_NULL_OBJECT);
72 }
73
74 /**
75 * @tc.name: ScheduleChangeAppGcState_001
76 * @tc.desc: Verify that the ScheduleChangeAppGcState interface calls normally
77 * @tc.type: FUNC
78 */
79 HWTEST_F(AppSchedulerProxyTest, ScheduleChangeAppGcState_001, TestSize.Level1)
80 {
81 sptr<IRemoteObject> impl;
82 sptr<AppSchedulerProxy> appSchedulerProxy = new (std::nothrow) AppSchedulerProxy(impl);
83 int32_t result = appSchedulerProxy->ScheduleChangeAppGcState(0);
84 EXPECT_EQ(result, ERR_NULL_OBJECT);
85 }
86
87 /**
88 * @tc.name: AttachAppDebug_001
89 * @tc.desc: Verify that AttachAppDebug interface calls normally.
90 * @tc.type: FUNC
91 */
92 HWTEST_F(AppSchedulerProxyTest, AttachAppDebug_001, TestSize.Level1)
93 {
94 EXPECT_NE(mockAppScheduler_, nullptr);
95 sptr<AppSchedulerProxy> appSchedulerProxy = new AppSchedulerProxy(mockAppScheduler_);
96 EXPECT_NE(appSchedulerProxy, nullptr);
97
98 EXPECT_CALL(*mockAppScheduler_, AttachAppDebug(_)).Times(1);
99 appSchedulerProxy->AttachAppDebug(false);
100 }
101
102 /**
103 * @tc.name: DetachAppDebug_001
104 * @tc.desc: Verify that DetachAppDebug interface calls normally.
105 * @tc.type: FUNC
106 */
107 HWTEST_F(AppSchedulerProxyTest, DetachAppDebug_001, TestSize.Level1)
108 {
109 EXPECT_NE(mockAppScheduler_, nullptr);
110 sptr<AppSchedulerProxy> appSchedulerProxy = new AppSchedulerProxy(mockAppScheduler_);;
111 EXPECT_NE(appSchedulerProxy, nullptr);
112
113 EXPECT_CALL(*mockAppScheduler_, DetachAppDebug()).Times(1);
114 appSchedulerProxy->DetachAppDebug();
115 }
116 } // namespace AppExecFwk
117 } // namespace OHOS
118