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 testing::Mock::AllowLeak(stub);
80 GTEST_LOG_(INFO) << "AbilityDebugResponseProxyTest_HandleOnAbilitysDebugStarted_0100 end";
81 }
82
83 /**
84 * @tc.name: AbilityDebugResponseProxyTest_HandleOnAbilitysDebugStoped_0100
85 * @tc.desc: Verify the HandleOnAbilitysDebugStarted calls normally.
86 * @tc.type: FUNC
87 */
88 HWTEST_F(AbilityDebugResponseStubTest, HandleOnAbilitysDebugStoped_0100, TestSize.Level1)
89 {
90 GTEST_LOG_(INFO) << "AbilityDebugResponseProxyTest_HandleOnAbilitysDebugStoped_0100 start";
91 auto stub = new (std::nothrow) MockAbilityDebugResponseStub();
92 EXPECT_TRUE(stub);
93 EXPECT_CALL(*stub, OnAbilitysDebugStarted(_)).Times(1);
94
95 sptr<MockAbilityToken> token = new (std::nothrow) MockAbilityToken();
96 EXPECT_TRUE(token);
97 MessageParcel data;
98 MessageParcel reply;
99 MessageOption option(MessageOption::TF_ASYNC);
100 int tokenSize = 1;
101 WriteInterfaceToken(data);
102 data.WriteInt32(tokenSize);
103 data.WriteRemoteObject(token);
104
105 auto result = stub->OnRemoteRequest(
106 static_cast<uint32_t>(IAbilityDebugResponse::Message::ON_ABILITYS_DEBUG_STOPED), data, reply, option);
107 EXPECT_EQ(result, NO_ERROR);
108 testing::Mock::AllowLeak(stub);
109 GTEST_LOG_(INFO) << "AbilityDebugResponseProxyTest_HandleOnAbilitysDebugStoped_0100 end";
110 }
111 } // namespace AppExecFwk
112 } // namespace OHOS