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 "ability_debug_deal.h"
20 #include "ability_record.h"
21 #undef private
22 #include "want.h"
23
24 namespace OHOS {
25 namespace AAFwk {
26 using namespace testing;
27 using namespace testing::ext;
28 namespace {
29 const std::string STRING_PROCESS_NAME = "process_name";
30 }
31 class AbilityDebugDealTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp() override;
36 void TearDown() override;
37 std::shared_ptr<AbilityDebugDeal> deal_;
38 std::vector<sptr<IRemoteObject>> tokens_;
39 };
40
SetUpTestCase(void)41 void AbilityDebugDealTest::SetUpTestCase(void)
42 {}
43
TearDownTestCase(void)44 void AbilityDebugDealTest::TearDownTestCase(void)
45 {}
46
SetUp()47 void AbilityDebugDealTest::SetUp()
48 {
49 deal_ = std::make_shared<AbilityDebugDeal>();
50 }
51
TearDown()52 void AbilityDebugDealTest::TearDown()
53 {}
54
55 /**
56 * @tc.name: AbilityDebugDealTest_RegisterAbilityDebugResponse_0100
57 * @tc.desc: Verify register ability debug response calls normally.
58 * @tc.type: FUNC
59 */
60 HWTEST_F(AbilityDebugDealTest, RegisterAbilityDebugResponse_0100, TestSize.Level1)
61 {
62 GTEST_LOG_(INFO) << "AbilityDebugDealTest_RegisterAbilityDebugResponse_0100 start";
63 EXPECT_EQ(deal_->abilityDebugResponse_, nullptr);
64 deal_->RegisterAbilityDebugResponse();
65 EXPECT_NE(deal_->abilityDebugResponse_, nullptr);
66 GTEST_LOG_(INFO) << "AbilityDebugDealTest_RegisterAbilityDebugResponse_0100 end";
67 }
68
69 /**
70 * @tc.name: OnAbilitysDebugStarted_0100
71 * @tc.desc: Verify that OnAbilitysDebugStoped set isAttachDebug_ of AbilityRecord to true correctly.
72 * @tc.type: FUNC
73 */
74 HWTEST_F(AbilityDebugDealTest, OnAbilitysDebugStarted_0100, TestSize.Level1)
75 {
76 EXPECT_NE(deal_, nullptr);
77
78 Want want;
79 OHOS::AppExecFwk::AbilityInfo abilityInfo;
80 abilityInfo.process = STRING_PROCESS_NAME;
81 OHOS::AppExecFwk::ApplicationInfo applicationInfo;
82 auto record = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
83 EXPECT_NE(record, nullptr);
84 EXPECT_FALSE(record->isAttachDebug_);
85 const sptr<IRemoteObject> token = new Token(record);
86 tokens_.emplace_back(token);
87
88 deal_->OnAbilitysDebugStarted(tokens_);
89 auto ability_record = Token::GetAbilityRecordByToken(token);
90 EXPECT_TRUE(ability_record->isAttachDebug_);
91 }
92
93 /**
94 * @tc.name: OnAbilitysDebugStoped_0100
95 * @tc.desc: Verify that OnAbilitysDebugStoped set isAttachDebug_ of AbilityRecord to false correctly.
96 * @tc.type: FUNC
97 */
98 HWTEST_F(AbilityDebugDealTest, OnAbilitysDebugStoped_0100, TestSize.Level1)
99 {
100 EXPECT_NE(deal_, nullptr);
101
102 Want want;
103 OHOS::AppExecFwk::AbilityInfo abilityInfo;
104 abilityInfo.process = STRING_PROCESS_NAME;
105 OHOS::AppExecFwk::ApplicationInfo applicationInfo;
106 auto record = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
107 EXPECT_NE(record, nullptr);
108 EXPECT_FALSE(record->isAttachDebug_);
109 const sptr<IRemoteObject> token = new Token(record);
110 tokens_.emplace_back(token);
111
112 deal_->OnAbilitysDebugStarted(tokens_);
113 auto ability_record = Token::GetAbilityRecordByToken(token);
114 EXPECT_TRUE(ability_record->isAttachDebug_);
115 deal_->OnAbilitysDebugStoped(tokens_);
116 EXPECT_FALSE(ability_record->isAttachDebug_);
117 }
118 } // namespace AppExecFwk
119 } // namespace OHOS