• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "fault_data.h"
20 #include "message_parcel.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 class AppSchedulerHostTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     void SetUp() override;
34     void TearDown() override;
35 
36     sptr<MockAppScheduler> mockAppScheduler_;
37 
38     void WriteInterfaceToken(MessageParcel& data);
39 };
40 
SetUpTestCase(void)41 void AppSchedulerHostTest::SetUpTestCase(void)
42 {}
43 
TearDownTestCase(void)44 void AppSchedulerHostTest::TearDownTestCase(void)
45 {}
46 
SetUp()47 void AppSchedulerHostTest::SetUp()
48 {
49     GTEST_LOG_(INFO) << "AppSchedulerHostTest::SetUp()";
50 
51     mockAppScheduler_ = new MockAppScheduler();
52 }
53 
TearDown()54 void AppSchedulerHostTest::TearDown()
55 {}
56 
WriteInterfaceToken(MessageParcel & data)57 void AppSchedulerHostTest::WriteInterfaceToken(MessageParcel& data)
58 {
59     GTEST_LOG_(INFO) << "AppSchedulerHostTest::WriteInterfaceToken()";
60 
61     data.WriteInterfaceToken(AppSchedulerHost::GetDescriptor());
62 }
63 
64 /**
65  * @tc.name: HandleNotifyAppFault_001
66  * @tc.desc: Verify that the HandleNotifyAppFault interface calls normally
67  * @tc.type: FUNC
68  */
69 HWTEST_F(AppSchedulerHostTest, HandleNotifyAppFault_001, TestSize.Level1)
70 {
71     MessageParcel data;
72     MessageParcel reply;
73     MessageOption option;
74     WriteInterfaceToken(data);
75     FaultData faultData;
76     faultData.errorObject.name = "testName";
77     faultData.errorObject.message = "testMessage";
78     faultData.errorObject.stack = "testStack";
79     faultData.faultType = FaultDataType::UNKNOWN;
80     data.WriteParcelable(&faultData);
81     EXPECT_CALL(*mockAppScheduler_, ScheduleNotifyAppFault(_)).Times(1);
82     auto result = mockAppScheduler_->OnRemoteRequest(
83         static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_NOTIFY_FAULT), data, reply, option);
84     EXPECT_EQ(result, NO_ERROR);
85 }
86 } // namespace AppExecFwk
87 } // namespace OHOS
88