1 /*
2 * Copyright (c) 2022-2024 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 "daudio_hidumper_test.h"
17 #include "daudio_hitrace.h"
18 #include "daudio_errorcode.h"
19
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace DistributedHardware {
SetUpTestCase(void)24 void DAudioHidumperTest::SetUpTestCase(void) {}
25
TearDownTestCase(void)26 void DAudioHidumperTest::TearDownTestCase(void) {}
27
SetUp()28 void DAudioHidumperTest::SetUp()
29 {
30 hidumper_ = std::make_shared<DaudioHidumper>();
31 }
32
TearDown()33 void DAudioHidumperTest::TearDown()
34 {
35 hidumper_ = nullptr;
36 }
37
38 /**
39 * @tc.name: OnStateChange_001
40 * @tc.desc: Verify the OnStateChange function.
41 * @tc.type: FUNC
42 * @tc.require: AR000H0E6G
43 */
44 HWTEST_F(DAudioHidumperTest, Dump_001, TestSize.Level1)
45 {
46 ASSERT_TRUE(hidumper_ != nullptr);
47 std::string result;
48 std::vector<std::string> args;
49 EXPECT_EQ(true, hidumper_->Dump(args, result));
50 args = { "-h"};
51 EXPECT_EQ(true, hidumper_->Dump(args, result));
52 args = {"--sourceDevId"};
53 EXPECT_NE(true, hidumper_->Dump(args, result));
54 args = {"--sinkInfo"};
55 hidumper_->Dump(args, result);
56 args = {"--ability"};
57 EXPECT_EQ(true, hidumper_->Dump(args, result));
58 args = {"-h", "--ability"};
59 EXPECT_EQ(true, hidumper_->Dump(args, result));
60 }
61
62 /**
63 * @tc.name: GetSourceDevId_001
64 * @tc.desc: Verify the GetSourceDevId function.
65 * @tc.type: FUNC
66 * @tc.require: AR000H0E6G
67 */
68 HWTEST_F(DAudioHidumperTest, GetSourceDevId_001, TestSize.Level1)
69 {
70 ASSERT_TRUE(hidumper_ != nullptr);
71 std::string result = "123";
72 EXPECT_NE(HDF_SUCCESS, hidumper_->GetSourceDevId(result));
73 }
74
75 /**
76 * @tc.name: GetSinkInfo_001
77 * @tc.desc: Verify the GetSinkInfo function.
78 * @tc.type: FUNC
79 * @tc.require: AR000H0E6G
80 */
81 HWTEST_F(DAudioHidumperTest, GetSinkInfo_001, TestSize.Level1)
82 {
83 ASSERT_TRUE(hidumper_ != nullptr);
84 std::string result = "123";
85 EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, hidumper_->GetSinkInfo(result));
86 }
87
88 /**
89 * @tc.name: StartDumpData_001
90 * @tc.desc: Verify the StartDumpData function.
91 * @tc.type: FUNC
92 * @tc.require: AR000H0E5F
93 */
94 HWTEST_F(DAudioHidumperTest, StartDumpData_001, TestSize.Level1)
95 {
96 ASSERT_TRUE(hidumper_ != nullptr);
97 std::string result = "";
98 EXPECT_EQ(HDF_SUCCESS, hidumper_->StartDumpData(result));
99 EXPECT_EQ(true, hidumper_->QueryDumpDataFlag());
100 }
101 } // DistributedHardware
102 } // OHOS
103