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 #define private public
17 #include "audio_data_test.h"
18 #undef private
19
20 #include "daudio_constants.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace DistributedHardware {
SetUpTestCase(void)27 void AudioDataTest::SetUpTestCase(void) {}
28
TearDownTestCase(void)29 void AudioDataTest::TearDownTestCase(void) {}
30
SetUp(void)31 void AudioDataTest::SetUp(void)
32 {
33 size_t capacity = 20;
34 audioData = std::make_shared<AudioData>(capacity);
35 }
36
TearDown(void)37 void AudioDataTest::TearDown(void) {}
38
39 /**
40 * @tc.name: SetRange_001
41 * @tc.desc: Verify the SetRange function.
42 * @tc.type: FUNC
43 * @tc.require: AR000H0E5U
44 */
45 HWTEST_F(AudioDataTest, SetRange_001, TestSize.Level1)
46 {
47 size_t offset = 100;
48 size_t size = 100;
49 int32_t ret = audioData->SetRange(offset, size);
50 EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, ret);
51 }
52
53 /**
54 * @tc.name: SetRange_002
55 * @tc.desc: Verify the SetRange function.
56 * @tc.type: FUNC
57 * @tc.require: AR000H0E5U
58 */
59 HWTEST_F(AudioDataTest, SetRange_002, TestSize.Level1)
60 {
61 size_t offset = 5;
62 size_t size = 5;
63 int32_t ret = audioData->SetRange(offset, size);
64 EXPECT_EQ(DH_SUCCESS, ret);
65 }
66
67 /**
68 * @tc.name: FindInt32_001
69 * @tc.desc: Verify the FindInt32 function.
70 * @tc.type: FUNC
71 * @tc.require: AR000H0E5U
72 */
73 HWTEST_F(AudioDataTest, FindInt32_001, TestSize.Level1)
74 {
75 const std::string name = "name";
76 int32_t value = 1;
77 audioData->int32Map_.insert(std::make_pair(name, value));
78 EXPECT_EQ(true, audioData->FindInt32(name, value));
79 }
80
81 /**
82 * @tc.name: FindInt32_002
83 * @tc.desc: Verify the FindInt32 function.
84 * @tc.type: FUNC
85 * @tc.require: AR000H0E5U
86 */
87 HWTEST_F(AudioDataTest, FindInt32_002, TestSize.Level1)
88 {
89 const std::string name = "name";
90 int32_t value = 1;
91 EXPECT_EQ(false, audioData->FindInt32(name, value));
92 }
93
94 /**
95 * @tc.name: FindInt64_001
96 * @tc.desc: Verify the FindInt64 function.
97 * @tc.type: FUNC
98 * @tc.require: AR000H0E5U
99 */
100 HWTEST_F(AudioDataTest, FindInt64_001, TestSize.Level1)
101 {
102 const std::string name = "name";
103 int64_t value = 1;
104 audioData->SetInt64(name, value);
105 EXPECT_EQ(true, audioData->FindInt64(name, value));
106 }
107
108 /**
109 * @tc.name: FindInt64_002
110 * @tc.desc: Verify the FindInt64 function.
111 * @tc.type: FUNC
112 * @tc.require: AR000H0E5U
113 */
114 HWTEST_F(AudioDataTest, FindInt64_002, TestSize.Level1)
115 {
116 const std::string name = "name";
117 int64_t value = 1;
118 EXPECT_EQ(false, audioData->FindInt64(name, value));
119 }
120
121 /**
122 * @tc.name: FindString_001
123 * @tc.desc: Verify the FindString function.
124 * @tc.type: FUNC
125 * @tc.require: AR000H0E5U
126 */
127 HWTEST_F(AudioDataTest, FindString_001, TestSize.Level1)
128 {
129 const std::string name = "name";
130 string value = "value";
131 audioData->stringMap_.insert(std::make_pair(name, value));
132 EXPECT_EQ(true, audioData->FindString(name, value));
133 }
134
135 /**
136 * @tc.name: FindString_002
137 * @tc.desc: Verify the FindString function.
138 * @tc.type: FUNC
139 * @tc.require: AR000H0E5U
140 */
141 HWTEST_F(AudioDataTest, FindString_002, TestSize.Level1)
142 {
143 const std::string name = "name";
144 string value = "value";
145 EXPECT_EQ(false, audioData->FindString(name, value));
146 }
147 } // namespace DistributedHardware
148 } // namespace OHOS
149