1 /*
2 * Copyright (c) 2022 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 "hilog_tag_wrapper.h"
19 #define private public
20 #include "pending_want_manager.h"
21 #undef private
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace AAFwk {
28 namespace {
29 const int32_t CODE = 1024;
30 const int32_t UID = 20000000;
31 constexpr size_t SIZE_ONE = 1;
32 } // namespace
33
34 class PendingWantManagerDumpTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp() override;
39 void TearDown() override;
40 };
41
SetUpTestCase(void)42 void PendingWantManagerDumpTest::SetUpTestCase(void)
43 {}
44
TearDownTestCase(void)45 void PendingWantManagerDumpTest::TearDownTestCase(void)
46 {}
47
SetUp()48 void PendingWantManagerDumpTest::SetUp()
49 {}
50
TearDown()51 void PendingWantManagerDumpTest::TearDown()
52 {}
53
54 /**
55 * @tc.name: PendingWantManagerDump_DumpByRecordId_0100
56 * @tc.desc: DumpByRecordId
57 * @tc.type: FUNC
58 * @tc.require: SR000GH1GO
59 */
60 HWTEST_F(PendingWantManagerDumpTest, PendingWantManagerDump_DumpByRecordId_0100, TestSize.Level1)
61 {
62 TAG_LOGI(AAFwkTag::TEST, "PendingWantManagerDump_DumpByRecordId_0100 start");
63
64 auto pendingManager = std::make_shared<PendingWantManager>();
65 EXPECT_NE(pendingManager, nullptr);
66
67 auto pendingKey = std::make_shared<PendingWantKey>();
68 EXPECT_NE(pendingKey, nullptr);
69 pendingKey->SetCode(CODE);
70
71 auto pendingWantRecord = std::make_shared<PendingWantRecord>(pendingManager, UID, 0, nullptr, pendingKey);
72 EXPECT_NE(pendingWantRecord, nullptr);
73 pendingManager->wantRecords_ = { {pendingKey, pendingWantRecord.get()} };
74
75 std::vector<std::string> info;
76 std::string args = std::to_string(CODE);
77 pendingManager->DumpByRecordId(info, args);
78 EXPECT_GT(info.size(), SIZE_ONE);
79
80 TAG_LOGI(AAFwkTag::TEST, "info.size() = %{public}zu", info.size());
81 for (auto item : info) {
82 TAG_LOGI(AAFwkTag::TEST, "item = %{public}s", item.c_str());
83 }
84
85 TAG_LOGI(AAFwkTag::TEST, "PendingWantManagerDump_DumpByRecordId_0100 end");
86 }
87
88 /**
89 * @tc.name: PendingWantManagerDump_Dump_0100
90 * @tc.desc: Dump
91 * @tc.type: FUNC
92 * @tc.require: SR000GH1GO
93 */
94 HWTEST_F(PendingWantManagerDumpTest, PendingWantManagerDump_Dump_0100, TestSize.Level1)
95 {
96 TAG_LOGI(AAFwkTag::TEST, "PendingWantManagerDump_Dump_0100 start");
97
98 auto pendingManager = std::make_shared<PendingWantManager>();
99 EXPECT_NE(pendingManager, nullptr);
100
101 std::vector<std::string> info;
102 pendingManager->Dump(info);
103 EXPECT_EQ(info.size(), SIZE_ONE);
104
105 TAG_LOGI(AAFwkTag::TEST, "PendingWantManagerDump_Dump_0100 end");
106 }
107 } // namespace AAFwk
108 } // namespace OHOS
109