• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <unistd.h>
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 #include "audio_proxy_common.h"
20 #include "audio_proxy_common_fun_test.h"
21 #include "hdf_remote_service.h"
22 #include "hdf_sbuf.h"
23 
24 using namespace std;
25 using namespace testing::ext;
26 namespace {
27 class AudioProxyCommonTest : public testing::Test {
28 public:
29     virtual void SetUp();
30     virtual void TearDown();
31 };
32 
SetUp()33 void AudioProxyCommonTest::SetUp() {}
34 
TearDown()35 void AudioProxyCommonTest::TearDown() {}
36 
37 HWTEST_F(AudioProxyCommonTest, AudioProxyObtainHdfSBufWhenNormal, TestSize.Level1)
38 {
39     struct HdfSBuf *data = AudioProxyObtainHdfSBuf();
40     EXPECT_NE(nullptr, data);
41     HdfSbufRecycle(data);
42     data = nullptr;
43 }
44 
45 HWTEST_F(AudioProxyCommonTest, AudioProxyObtainHdfSBuf_001, TestSize.Level1)
46 {
47     struct HdfSBuf *data = nullptr;
48     struct HdfSBuf *reply = nullptr;
49     EXPECT_EQ(HDF_FAILURE, AudioProxyPreprocessSBuf(nullptr, &reply));
50     EXPECT_EQ(HDF_FAILURE, AudioProxyPreprocessSBuf(&data, nullptr));
51 }
52 
53 HWTEST_F(AudioProxyCommonTest, AudioProxyDispatchCall_001, TestSize.Level1)
54 {
55     int32_t id = 0;
56     struct HdfSBuf *data = AudioProxyObtainHdfSBuf();
57     struct HdfSBuf *reply = AudioProxyObtainHdfSBuf();
58     struct HdfRemoteService self;
59     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyDispatchCall(nullptr, id, data, reply));
60     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyDispatchCall(&self, id, nullptr, reply));
61     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyDispatchCall(&self, id, data, nullptr));
62     HdfSbufRecycle(data);
63     HdfSbufRecycle(reply);
64 }
65 
66 HWTEST_F(AudioProxyCommonTest, AudioProxyDispatchCall_002, TestSize.Level1)
67 {
68     int32_t id = 0;
69     struct HdfSBuf *data = AudioProxyObtainHdfSBuf();
70     struct HdfSBuf *reply = AudioProxyObtainHdfSBuf();
71     struct HdfRemoteService self;
72     self.dispatcher = nullptr;
73     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyDispatchCall(nullptr, id, data, reply));
74     HdfSbufRecycle(data);
75     HdfSbufRecycle(reply);
76 }
77 
78 HWTEST_F(AudioProxyCommonTest, AdapterGetRemoteHandle_001, TestSize.Level1)
79 {
80     char adapterName[NAME_LEN];
81     struct AudioHwAdapter hwAdapter;
82     struct AudioProxyManager proxyManager;
83     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyAdapterGetRemoteHandle(nullptr, &hwAdapter, adapterName));
84     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyAdapterGetRemoteHandle(&proxyManager, nullptr, adapterName));
85     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyAdapterGetRemoteHandle(&proxyManager, &hwAdapter, nullptr));
86 }
87 
88 HWTEST_F(AudioProxyCommonTest, AdapterGetRemoteHandle_002, TestSize.Level1)
89 {
90     const char *adapterName = "abc";
91     struct AudioHwAdapter hwAdapter;
92     struct AudioProxyManager proxyManager;
93     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyAdapterGetRemoteHandle(&proxyManager, &hwAdapter, adapterName));
94 }
95 
96 HWTEST_F(AudioProxyCommonTest, AudioProxyPreprocessRender_001, TestSize.Level1)
97 {
98     struct HdfSBuf *data = nullptr;
99     struct HdfSBuf *reply = nullptr;
100     struct AudioHwRender render;
101     EXPECT_EQ(HDF_FAILURE, AudioProxyPreprocessRender(nullptr, &data, &reply));
102     EXPECT_EQ(HDF_FAILURE, AudioProxyPreprocessRender(&render, nullptr, &reply));
103     EXPECT_EQ(HDF_FAILURE, AudioProxyPreprocessRender(&render, &data, nullptr));
104 }
105 
106 HWTEST_F(AudioProxyCommonTest, AudioProxyPreprocessCapture_001, TestSize.Level1)
107 {
108     struct HdfSBuf *data = nullptr;
109     struct HdfSBuf *reply = nullptr;
110     struct AudioHwCapture capture;
111     EXPECT_EQ(HDF_FAILURE, AudioProxyPreprocessCapture(nullptr, &data, &reply));
112     EXPECT_EQ(HDF_FAILURE, AudioProxyPreprocessCapture(&capture, nullptr, &reply));
113     EXPECT_EQ(HDF_FAILURE, AudioProxyPreprocessCapture(&capture, &data, nullptr));
114 }
115 
116 HWTEST_F(AudioProxyCommonTest, AudioProxyWriteSampleAttributes_001, TestSize.Level1)
117 {
118     struct HdfSBuf *data = AudioProxyObtainHdfSBuf();
119     struct AudioSampleAttributes attrs;
120     EXPECT_EQ(HDF_FAILURE, AudioProxyWriteSampleAttributes(nullptr, &attrs));
121     EXPECT_EQ(HDF_FAILURE, AudioProxyWriteSampleAttributes(data, nullptr));
122     HdfSbufRecycle(data);
123 }
124 
125 HWTEST_F(AudioProxyCommonTest, AudioProxyReadSapmleAttrbutes_001, TestSize.Level1)
126 {
127     struct HdfSBuf *data = AudioProxyObtainHdfSBuf();
128     struct AudioSampleAttributes attrs;
129     EXPECT_EQ(HDF_FAILURE, AudioProxyReadSapmleAttrbutes(nullptr, &attrs));
130     EXPECT_EQ(HDF_FAILURE, AudioProxyReadSapmleAttrbutes(data, nullptr));
131     HdfSbufRecycle(data);
132 }
133 
134 HWTEST_F(AudioProxyCommonTest, SetRenderCtrlParam_001, TestSize.Level1)
135 {
136     int cmId = AUDIO_HDI_RENDER_SET_VOLUME;
137     float param = comfun::HALF_OF_NORMAL_VALUE; // normal value
138     struct AudioHwRender hwRender;
139     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyCommonSetRenderCtrlParam(cmId, nullptr, param));
140 
141     hwRender.proxyRemoteHandle = nullptr;
142     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyCommonSetRenderCtrlParam(cmId, (AudioHandle)(&hwRender), param));
143 }
144 
145 HWTEST_F(AudioProxyCommonTest, SetRenderCtrlParam_002, TestSize.Level1)
146 {
147     int cmId = AUDIO_HDI_RENDER_SET_VOLUME;
148     float volume = comfun::MIN_VALUE_OUT_OF_BOUNDS; // The volume value is not within the threshold range [0,1]
149     struct AudioHwRender hwRender;
150     struct HdfRemoteService remoteHandle;
151     hwRender.proxyRemoteHandle = &remoteHandle;
152     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyCommonSetRenderCtrlParam(cmId, (AudioHandle)(&hwRender), volume));
153     volume = comfun::MAX_VALUE_OUT_OF_BOUNDS; // The volume value is not within the threshold range [0,1]
154     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyCommonSetRenderCtrlParam(cmId, (AudioHandle)(&hwRender), volume));
155 }
156 
157 HWTEST_F(AudioProxyCommonTest, GetRenderCtrlParam_001, TestSize.Level1)
158 {
159     int cmId = AUDIO_HDI_RENDER_SET_VOLUME;
160     float param = comfun::HALF_OF_NORMAL_VALUE; // normal value
161     struct AudioHwRender hwRender;
162     int32_t ret  = AudioProxyCommonGetRenderCtrlParam(cmId, nullptr, &param);
163     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret);
164     ret = AudioProxyCommonGetRenderCtrlParam(cmId, (AudioHandle)(&hwRender), nullptr);
165     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret);
166     hwRender.proxyRemoteHandle = nullptr;
167     ret = AudioProxyCommonGetRenderCtrlParam(cmId, (AudioHandle)(&hwRender), &param);
168     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret);
169 }
170 
171 
172 HWTEST_F(AudioProxyCommonTest, SetCaptureCtrlParam_001, TestSize.Level1)
173 {
174     int cmId = AUDIO_HDI_RENDER_SET_VOLUME;
175     float param = comfun::HALF_OF_NORMAL_VALUE; // normal value
176     struct AudioHwCapture hwCapture;
177     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyCommonSetCaptureCtrlParam(cmId, nullptr, param));
178 
179     hwCapture.proxyRemoteHandle = nullptr;
180     int32_t ret = AudioProxyCommonSetCaptureCtrlParam(cmId, (AudioHandle)(&hwCapture), param);
181     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret);
182 }
183 
184 HWTEST_F(AudioProxyCommonTest, SetCaptureCtrlParam_002, TestSize.Level1)
185 {
186     int cmId = AUDIO_HDI_CAPTURE_SET_VOLUME;
187     float volume = comfun::MIN_VALUE_OUT_OF_BOUNDS; // The volume value is not within the threshold range [0,1].
188     struct AudioHwCapture hwCapture;
189     struct HdfRemoteService remoteHandle;
190     hwCapture.proxyRemoteHandle = &remoteHandle;
191     int32_t ret = AudioProxyCommonSetCaptureCtrlParam(cmId, (AudioHandle)(&hwCapture), volume);
192     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret);
193     ret = AudioProxyCommonSetCaptureCtrlParam(cmId, (AudioHandle)(&hwCapture), volume);
194     volume = comfun::MAX_VALUE_OUT_OF_BOUNDS; // The volume value is not within the threshold range [0,1].
195     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret);
196 }
197 
198 HWTEST_F(AudioProxyCommonTest, GetCaptureCtrlParam_001, TestSize.Level1)
199 {
200     int cmId = AUDIO_HDI_CAPTURE_SET_VOLUME;
201     float param = comfun::HALF_OF_NORMAL_VALUE; // normal value
202     struct AudioHwCapture hwCapture;
203     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, AudioProxyCommonGetCaptureCtrlParam(cmId, nullptr, &param));
204     int32_t ret = AudioProxyCommonGetCaptureCtrlParam(cmId, (AudioHandle)(&hwCapture), nullptr);
205     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret);
206     hwCapture.proxyRemoteHandle = nullptr;
207     ret = AudioProxyCommonGetCaptureCtrlParam(cmId, (AudioHandle)(&hwCapture), &param);
208     EXPECT_EQ(AUDIO_HAL_ERR_INVALID_PARAM, ret);
209 }
210 
211 HWTEST_F(AudioProxyCommonTest, GetMmapPositionRead_001, TestSize.Level1)
212 {
213     uint64_t frames = 0;
214     struct HdfSBuf *reply = AudioProxyObtainHdfSBuf();
215     struct AudioTimeStamp time;
216     EXPECT_EQ(HDF_FAILURE, AudioProxyGetMmapPositionRead(nullptr, &frames, &time));
217     EXPECT_EQ(HDF_FAILURE, AudioProxyGetMmapPositionRead(reply, nullptr, &time));
218     EXPECT_EQ(HDF_FAILURE, AudioProxyGetMmapPositionRead(reply, &frames, nullptr));
219     HdfSbufRecycle(reply);
220 }
221 
222 HWTEST_F(AudioProxyCommonTest, ReqMmapBufferWrite_001, TestSize.Level1)
223 {
224     int32_t reqSize = 0;
225     struct HdfSBuf *data = AudioProxyObtainHdfSBuf();
226     struct AudioMmapBufferDescripter desc;
227     EXPECT_EQ(HDF_FAILURE, AudioProxyReqMmapBufferWrite(nullptr, reqSize, &desc));
228     EXPECT_EQ(HDF_FAILURE, AudioProxyReqMmapBufferWrite(data, reqSize, nullptr));
229     HdfSbufRecycle(data);
230 }
231 }
232