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 ASSERT_NE(audioData, nullptr);
50 int32_t ret = audioData->SetRange(offset, size);
51 EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, ret);
52 }
53
54 /**
55 * @tc.name: SetRange_002
56 * @tc.desc: Verify the SetRange function.
57 * @tc.type: FUNC
58 * @tc.require: AR000H0E5U
59 */
60 HWTEST_F(AudioDataTest, SetRange_002, TestSize.Level1)
61 {
62 size_t offset = 5;
63 size_t size = 5;
64 ASSERT_NE(audioData, nullptr);
65 int32_t ret = audioData->SetRange(offset, size);
66 EXPECT_EQ(DH_SUCCESS, ret);
67 }
68
69 /**
70 * @tc.name: FindInt32_001
71 * @tc.desc: Verify the FindInt32 function.
72 * @tc.type: FUNC
73 * @tc.require: AR000H0E5U
74 */
75 HWTEST_F(AudioDataTest, FindInt32_001, TestSize.Level1)
76 {
77 const std::string name = "name";
78 int32_t value = 1;
79 ASSERT_NE(audioData, nullptr);
80 audioData->int32Map_.insert(std::make_pair(name, value));
81 EXPECT_EQ(true, audioData->FindInt32(name, value));
82 }
83
84 /**
85 * @tc.name: FindInt32_002
86 * @tc.desc: Verify the FindInt32 function.
87 * @tc.type: FUNC
88 * @tc.require: AR000H0E5U
89 */
90 HWTEST_F(AudioDataTest, FindInt32_002, TestSize.Level1)
91 {
92 const std::string name = "name";
93 int32_t value = 1;
94 ASSERT_NE(audioData, nullptr);
95 EXPECT_EQ(false, audioData->FindInt32(name, value));
96 }
97
98 /**
99 * @tc.name: FindInt64_001
100 * @tc.desc: Verify the FindInt64 function.
101 * @tc.type: FUNC
102 * @tc.require: AR000H0E5U
103 */
104 HWTEST_F(AudioDataTest, FindInt64_001, TestSize.Level1)
105 {
106 const std::string name = "name";
107 int64_t value = 1;
108 ASSERT_NE(audioData, nullptr);
109 audioData->SetInt64(name, value);
110 EXPECT_EQ(true, audioData->FindInt64(name, value));
111 }
112
113 /**
114 * @tc.name: FindInt64_002
115 * @tc.desc: Verify the FindInt64 function.
116 * @tc.type: FUNC
117 * @tc.require: AR000H0E5U
118 */
119 HWTEST_F(AudioDataTest, FindInt64_002, TestSize.Level1)
120 {
121 const std::string name = "name";
122 int64_t value = 1;
123 ASSERT_NE(audioData, nullptr);
124 EXPECT_EQ(false, audioData->FindInt64(name, value));
125 }
126
127 /**
128 * @tc.name: FindString_001
129 * @tc.desc: Verify the FindString function.
130 * @tc.type: FUNC
131 * @tc.require: AR000H0E5U
132 */
133 HWTEST_F(AudioDataTest, FindString_001, TestSize.Level1)
134 {
135 const std::string name = "name";
136 string value = "value";
137 ASSERT_NE(audioData, nullptr);
138 audioData->stringMap_.insert(std::make_pair(name, value));
139 EXPECT_EQ(true, audioData->FindString(name, value));
140 }
141
142 /**
143 * @tc.name: FindString_002
144 * @tc.desc: Verify the FindString function.
145 * @tc.type: FUNC
146 * @tc.require: AR000H0E5U
147 */
148 HWTEST_F(AudioDataTest, FindString_002, TestSize.Level1)
149 {
150 const std::string name = "name";
151 string value = "value";
152 ASSERT_NE(audioData, nullptr);
153 EXPECT_EQ(false, audioData->FindString(name, value));
154 }
155 } // namespace DistributedHardware
156 } // namespace OHOS