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 "ability_debug_response_proxy.h"
19 #include "mock_ability_debug_response_stub.h"
20 #include "mock_ability_token.h"
21
22 namespace OHOS {
23 namespace AppExecFwk {
24 using namespace testing;
25 using namespace testing::ext;
26 using namespace OHOS;
27 using namespace OHOS::AppExecFwk;
28
29 class AbilityDebugResponseProxyTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 void SetUp() override;
34 void TearDown() override;
35 void WriteInterfaceToken(MessageParcel& data);
36 };
37
SetUpTestCase(void)38 void AbilityDebugResponseProxyTest::SetUpTestCase(void)
39 {}
40
TearDownTestCase(void)41 void AbilityDebugResponseProxyTest::TearDownTestCase(void)
42 {}
43
SetUp()44 void AbilityDebugResponseProxyTest::SetUp()
45 {}
46
TearDown()47 void AbilityDebugResponseProxyTest::TearDown()
48 {}
49
WriteInterfaceToken(MessageParcel & data)50 void AbilityDebugResponseProxyTest::WriteInterfaceToken(MessageParcel& data)
51 {
52 data.WriteInterfaceToken(GetDescriptor());
53 }
54
55 /**
56 * @tc.name: AbilityDebugResponseProxyTest_OnAbilitysDebugStarted_0100
57 * @tc.desc: Verify the OnAbilitysDebugStarted calls normally.
58 * @tc.type: FUNC
59 */
60 HWTEST_F(AbilityDebugResponseProxyTest, OnAbilitysDebugStarted_0100, TestSize.Level1)
61 {
62 GTEST_LOG_(INFO) << "OnAbilitysDebugStarted_0100 start";
63 auto mockStub = new (std::nothrow) MockAbilityDebugResponseStub();
64 auto proxy = new AbilityDebugResponseProxy(mockStub);
65 EXPECT_TRUE(proxy);
66
67 std::vector<sptr<IRemoteObject>> tokens;
68 sptr<MockAbilityToken> token = new (std::nothrow) MockAbilityToken();
69 EXPECT_TRUE(token);
70 tokens.push_back(token);
71 EXPECT_CALL(*mockStub, OnAbilitysDebugStarted(_)).Times(1);
72 proxy->OnAbilitysDebugStarted(tokens);
73 testing::Mock::AllowLeak(mockStub);
74
75 GTEST_LOG_(INFO) << "OnAbilitysDebugStarted_0100 end";
76 }
77
78 /**
79 * @tc.name: AbilityDebugResponseProxyTest_OnAbilitysDebugStoped_0100
80 * @tc.desc: Verify the OnAbilitysDebugStoped calls normally.
81 * @tc.type: FUNC
82 */
83 HWTEST_F(AbilityDebugResponseProxyTest, OnAbilitysDebugStoped_0100, TestSize.Level1)
84 {
85 GTEST_LOG_(INFO) << "OnAbilitysDebugStoped_0100 start";
86 auto mockStub = new (std::nothrow) MockAbilityDebugResponseStub();
87 auto proxy = new (std::nothrow) AbilityDebugResponseProxy(mockStub);
88 EXPECT_TRUE(proxy);
89
90 std::vector<sptr<IRemoteObject>> tokens;
91 sptr<MockAbilityToken> token = new (std::nothrow) MockAbilityToken();
92 EXPECT_TRUE(token);
93 tokens.push_back(token);
94
95 EXPECT_CALL(*mockStub, OnAbilitysDebugStoped(_)).Times(1);
96 proxy->OnAbilitysDebugStarted(tokens);
97 testing::Mock::AllowLeak(mockStub);
98 GTEST_LOG_(INFO) << "OnAbilitysDebugStoped_0100 end";
99 }
100 } // namespace AppExecFwk
101 } // namespace OHOS