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 #include "mock_ability_token.h"
19 #define private public
20 #include "mock_ability_debug_response_stub.h"
21 #undef private
22
23 namespace OHOS {
24 namespace AppExecFwk {
25 using namespace testing;
26 using namespace testing::ext;
27
28 class AbilityDebugResponseStubTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 void SetUp() override;
33 void TearDown() override;
34 void WriteInterfaceToken(MessageParcel &parcel);
35 };
36
SetUpTestCase(void)37 void AbilityDebugResponseStubTest::SetUpTestCase(void)
38 {}
39
TearDownTestCase(void)40 void AbilityDebugResponseStubTest::TearDownTestCase(void)
41 {}
42
SetUp()43 void AbilityDebugResponseStubTest::SetUp()
44 {}
45
TearDown()46 void AbilityDebugResponseStubTest::TearDown()
47 {}
48
WriteInterfaceToken(MessageParcel & parcel)49 void AbilityDebugResponseStubTest::WriteInterfaceToken(MessageParcel &parcel)
50 {
51 parcel.WriteInterfaceToken(AbilityDebugResponseStub::GetDescriptor());
52 }
53
54 /**
55 * @tc.name: AbilityDebugResponseProxyTest_HandleOnAbilitysDebugStarted_0100
56 * @tc.desc: Verify the HandleOnAbilitysDebugStarted calls normally.
57 * @tc.type: FUNC
58 */
59 HWTEST_F(AbilityDebugResponseStubTest, HandleOnAbilitysDebugStarted_0100, TestSize.Level1)
60 {
61 GTEST_LOG_(INFO) << "AbilityDebugResponseProxyTest_HandleOnAbilitysDebugStarted_0100 start";
62 auto stub = new (std::nothrow) MockAbilityDebugResponseStub();
63 EXPECT_TRUE(stub);
64 EXPECT_CALL(*stub, OnAbilitysDebugStarted(_)).Times(1);
65
66 sptr<MockAbilityToken> token = new (std::nothrow) MockAbilityToken();
67 EXPECT_TRUE(token);
68 MessageParcel data;
69 MessageParcel reply;
70 MessageOption option(MessageOption::TF_ASYNC);
71 int tokenSize = 1;
72 WriteInterfaceToken(data);
73 data.WriteInt32(tokenSize);
74 data.WriteRemoteObject(token);
75
76 auto result = stub->OnRemoteRequest(
77 static_cast<uint32_t>(IAbilityDebugResponse::Message::ON_ABILITYS_DEBUG_STARTED), data, reply, option);
78 EXPECT_EQ(result, NO_ERROR);
79 GTEST_LOG_(INFO) << "AbilityDebugResponseProxyTest_HandleOnAbilitysDebugStarted_0100 end";
80 }
81
82 /**
83 * @tc.name: AbilityDebugResponseProxyTest_HandleOnAbilitysDebugStoped_0100
84 * @tc.desc: Verify the HandleOnAbilitysDebugStarted calls normally.
85 * @tc.type: FUNC
86 */
87 HWTEST_F(AbilityDebugResponseStubTest, HandleOnAbilitysDebugStoped_0100, TestSize.Level1)
88 {
89 GTEST_LOG_(INFO) << "AbilityDebugResponseProxyTest_HandleOnAbilitysDebugStoped_0100 start";
90 auto stub = new (std::nothrow) MockAbilityDebugResponseStub();
91 EXPECT_TRUE(stub);
92 EXPECT_CALL(*stub, OnAbilitysDebugStarted(_)).Times(1);
93
94 sptr<MockAbilityToken> token = new (std::nothrow) MockAbilityToken();
95 EXPECT_TRUE(token);
96 MessageParcel data;
97 MessageParcel reply;
98 MessageOption option(MessageOption::TF_ASYNC);
99 int tokenSize = 1;
100 WriteInterfaceToken(data);
101 data.WriteInt32(tokenSize);
102 data.WriteRemoteObject(token);
103
104 auto result = stub->OnRemoteRequest(
105 static_cast<uint32_t>(IAbilityDebugResponse::Message::ON_ABILITYS_DEBUG_STOPED), data, reply, option);
106 EXPECT_EQ(result, NO_ERROR);
107 GTEST_LOG_(INFO) << "AbilityDebugResponseProxyTest_HandleOnAbilitysDebugStoped_0100 end";
108 }
109 } // namespace AppExecFwk
110 } // namespace OHOS