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 if (hidumper_ == nullptr) {
47 return;
48 }
49 std::string result;
50 std::vector<std::string> args;
51 EXPECT_EQ(true, hidumper_->Dump(args, result));
52 args = { "-h"};
53 EXPECT_EQ(true, hidumper_->Dump(args, result));
54 args = {"--sourceDevId"};
55 EXPECT_NE(true, hidumper_->Dump(args, result));
56 args = {"--sinkInfo"};
57 hidumper_->Dump(args, result);
58 args = {"--ability"};
59 EXPECT_EQ(true, hidumper_->Dump(args, result));
60 args = {"-h", "--ability"};
61 EXPECT_EQ(true, hidumper_->Dump(args, result));
62 }
63
64 /**
65 * @tc.name: GetSourceDevId_001
66 * @tc.desc: Verify the GetSourceDevId function.
67 * @tc.type: FUNC
68 * @tc.require: AR000H0E6G
69 */
70 HWTEST_F(DAudioHidumperTest, GetSourceDevId_001, TestSize.Level1)
71 {
72 if (hidumper_ == nullptr) {
73 return;
74 }
75 std::string result = "123";
76 EXPECT_NE(HDF_SUCCESS, hidumper_->GetSourceDevId(result));
77 }
78
79 /**
80 * @tc.name: GetSinkInfo_001
81 * @tc.desc: Verify the GetSinkInfo function.
82 * @tc.type: FUNC
83 * @tc.require: AR000H0E6G
84 */
85 HWTEST_F(DAudioHidumperTest, GetSinkInfo_001, TestSize.Level1)
86 {
87 if (hidumper_ == nullptr) {
88 return;
89 }
90 std::string result = "123";
91 EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, hidumper_->GetSinkInfo(result));
92 }
93
94 /**
95 * @tc.name: StartDumpData_001
96 * @tc.desc: Verify the StartDumpData function.
97 * @tc.type: FUNC
98 * @tc.require: AR000H0E5F
99 */
100 HWTEST_F(DAudioHidumperTest, StartDumpData_001, TestSize.Level1)
101 {
102 if (hidumper_ == nullptr) {
103 return;
104 }
105 std::string result = "";
106 EXPECT_EQ(HDF_SUCCESS, hidumper_->StartDumpData(result));
107 EXPECT_EQ(true, hidumper_->QueryDumpDataFlag());
108 }
109 } // DistributedHardware
110 } // OHOS
111