1 /*
2 * Copyright (C) 2025 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 "service_dump_manager_unittest.h"
17 #include "media_errors.h"
18
19 namespace OHOS {
20 namespace Media {
21 using namespace std;
22 using namespace testing;
23 using namespace testing::ext;
24
25 static const int32_t NUM_1 = 1;
26
SetUpTestCase(void)27 void ServiceDumpManagerUnitTest::SetUpTestCase(void)
28 {
29 }
30
TearDownTestCase(void)31 void ServiceDumpManagerUnitTest::TearDownTestCase(void)
32 {
33 }
34
SetUp(void)35 void ServiceDumpManagerUnitTest::SetUp(void)
36 {
37 manager_ = std::make_shared<ServiceDumpManager>();
38 }
39
TearDown(void)40 void ServiceDumpManagerUnitTest::TearDown(void)
41 {
42 manager_ = nullptr;
43 }
44
45 /**
46 * @tc.name : Test Dump
47 * @tc.number: Dump_001
48 * @tc.desc : Test RegisterDfxDumper
49 * Test Dump args.find(static_cast<std::u16string>(iter.first)) != args.end()
50 * Test Dump fd != -1
51 * Test Dump iter.second(fd) != MSERR_OK
52 * Test Dump args.find(static_cast<std::u16string>(iter.first)) == args.end()
53 * * Test UnregisterDfxDumper
54 */
55 HWTEST_F(ServiceDumpManagerUnitTest, Dump_001, TestSize.Level0)
56 {
57 // Test RegisterDfxDumper
58 ASSERT_NE(manager_, nullptr);
__anon61bfaf300102(int32_t fd) 59 DfxDumper dumper = [](int32_t fd) -> int32_t { return MSERR_INVALID_OPERATION;};
60 std::u16string key = u"TestDumper";
61 manager_->RegisterDfxDumper(key, dumper);
62
63 // Test Dump fd != -1
64 // Test Dump iter.second(fd) != MSERR_OK
65 int32_t fd = NUM_1;
66 std::unordered_set<std::u16string> args = { u"TestDumper"};
67 auto result = manager_->Dump(fd, args);
68 EXPECT_EQ(result, MSERR_INVALID_OPERATION);
69 // Test Dump args.find(static_cast<std::u16string>(iter.first)) == args.end()
70 args.clear();
71 result = manager_->Dump(fd, args);
72 EXPECT_EQ(result, MSERR_OK);
73
74 // Test UnregisterDfxDumper
75 manager_->UnregisterDfxDumper();
76 }
77
78 } // namespace Media
79 } // namespace OHOS