• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "sa_interceptor_stub.h"
20 #undef private
21 #include "ability_manager_errors.h"
22 #include "mock_sa_interceptor_stub.h"
23 
24 using namespace testing::ext;
25 using namespace testing;
26 
27 namespace OHOS {
28 namespace AbilityRuntime {
29 const int32_t INVALIED_ID = 10000;
30 class SAInterceptorStubTest : public testing::Test {
31 public:
32     static void SetUpTestCase(void);
33     static void TearDownTestCase(void);
34     void SetUp();
35     void TearDown();
36     void WriteInterfaceToken(MessageParcel& data);
37     sptr<MockSAInterceptorStub> stub_{ nullptr };
38 };
39 
SetUpTestCase(void)40 void SAInterceptorStubTest::SetUpTestCase(void)
41 {}
TearDownTestCase(void)42 void SAInterceptorStubTest::TearDownTestCase(void)
43 {}
SetUp()44 void SAInterceptorStubTest::SetUp()
45 {
46     stub_ = new MockSAInterceptorStub(0);
47 }
TearDown()48 void SAInterceptorStubTest::TearDown()
49 {}
50 
WriteInterfaceToken(MessageParcel & data)51 void SAInterceptorStubTest::WriteInterfaceToken(MessageParcel& data)
52 {
53     data.WriteInterfaceToken(MockSAInterceptorStub::GetDescriptor());
54 }
55 
56 /*
57  * @tc.number: OnRemoteRequest_001
58  * @tc.name: OnRemoteRequest
59  * @tc.desc: Verify OnRemoteRequest functionality
60  */
61 HWTEST_F(SAInterceptorStubTest, OnRemoteRequest_001, TestSize.Level1)
62 {
63     MessageParcel data;
64     MessageParcel reply;
65     MessageOption option;
66     WriteInterfaceToken(data);
67     int res = stub_->OnRemoteRequest(INVALIED_ID, data, reply, option);
68     EXPECT_EQ(res, IPC_STUB_UNKNOW_TRANS_ERR);
69 }
70 
71 /*
72  * @tc.number: OnRemoteRequest_002
73  * @tc.name: OnRemoteRequest
74  * @tc.desc: Verify OnRemoteRequest functionality
75  */
76 HWTEST_F(SAInterceptorStubTest, OnRemoteRequest_002, TestSize.Level1)
77 {
78     MessageParcel data;
79     MessageParcel reply;
80     MessageOption option;
81     int res = stub_->OnRemoteRequest(static_cast<int32_t>(ISAInterceptor::SAInterceptorCmd::ON_DO_CHECK_STARTING),
82         data, reply, option);
83     EXPECT_EQ(res, AAFwk::ERR_SA_INTERCEPTOR_DESCRIPTOR_MISMATCH);
84 }
85 
86 /*
87  * @tc.number: OnRemoteRequest_003
88  * @tc.name: OnRemoteRequest
89  * @tc.desc: Verify OnRemoteRequest functionality
90  */
91 HWTEST_F(SAInterceptorStubTest, OnRemoteRequest_003, TestSize.Level1)
92 {
93     MessageParcel data;
94     MessageParcel reply;
95     MessageOption option;
96     WriteInterfaceToken(data);
97     int res = stub_->OnRemoteRequest(static_cast<int32_t>(ISAInterceptor::SAInterceptorCmd::ON_DO_CHECK_STARTING),
98         data, reply, option);
99     EXPECT_EQ(res, NO_ERROR);
100 }
101 
102 /*
103  * @tc.number: HandleOnCheckStarting_001
104  * @tc.name: HandleOnCheckStarting
105  * @tc.desc: Verify HandleOnCheckStarting functionality
106  */
107 HWTEST_F(SAInterceptorStubTest, HandleOnCheckStarting_001, TestSize.Level1)
108 {
109     MessageParcel data;
110     MessageParcel reply;
111     int res = stub_->HandleOnCheckStarting(data, reply);
112     EXPECT_EQ(res, NO_ERROR);
113 }
114 }  // namespace AbilityRuntime
115 }  // namespace OHOS
116