• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "sound_id_manager_unittest.h"
17 #include "media_errors.h"
18 #include "sound_id_manager.h"
19 
20 using namespace OHOS;
21 using namespace OHOS::Media;
22 using namespace testing;
23 using namespace testing::ext;
24 using namespace std;
25 
26 namespace OHOS {
27 namespace Media {
28 static const int32_t ID_TEST = 10;
29 static const int32_t NUM_TEST = 1;
30 static const int32_t LENGTH_TEST = 10;
31 static const int32_t MAX_NUM = 33;
32 static const int32_t MSERR_INVALID = -1;
SetUpTestCase(void)33 void SoundIDManagerUnittest::SetUpTestCase(void)
34 {}
35 
TearDownTestCase(void)36 void SoundIDManagerUnittest::TearDownTestCase(void)
37 {}
38 
SetUp(void)39 void SoundIDManagerUnittest::SetUp(void)
40 {
41     AudioStandard::AudioRendererInfo audioRenderInfo;
42     audioRenderInfo.contentType = AudioStandard::CONTENT_TYPE_MUSIC;
43     audioRenderInfo.streamUsage = AudioStandard::STREAM_USAGE_MUSIC;
44     audioRenderInfo.rendererFlags = 0;
45     soundIDManager_ = std::make_shared<SoundIDManager>();
46 }
47 
TearDown(void)48 void SoundIDManagerUnittest::TearDown(void)
49 {
50     soundIDManager_ = nullptr;
51 }
52 
53 /**
54  * @tc.name  : Test Load
55  * @tc.number: SoundIdLoad_001
56  * @tc.desc  : Test apiVersion > 0 && apiVersion < SOUNDPOOL_API_VERSION_ISOLATION
57  */
58 HWTEST_F(SoundIDManagerUnittest, SoundIdLoad_001, TestSize.Level0)
59 {
60     int32_t fd = ID_TEST;
61     int64_t offset = 0;
62     int64_t length = LENGTH_TEST;
63     int32_t apiVersion = NUM_TEST;
64     for (int32_t i = 0; i <= MAX_NUM; ++i)
65     {
66         soundIDManager_->soundParsers_[i] = nullptr;
67     }
68     EXPECT_EQ(MSERR_INVALID, soundIDManager_->Load(fd, offset, length, apiVersion));
69 }
70 
71 /**
72  * @tc.name  : Test Load
73  * @tc.number: SoundIdLoad_002
74  * @tc.desc  : Test apiVersion > 0 && apiVersion < SOUNDPOOL_API_VERSION_ISOLATION
75  */
76 HWTEST_F(SoundIDManagerUnittest, SoundIdLoad_002, TestSize.Level0)
77 {
78     std::string testUrl = "testUri";
79     int32_t apiVersion = NUM_TEST;
80     soundIDManager_->soundParsers_[0] = nullptr;
81     EXPECT_EQ(MSERR_INVALID, soundIDManager_->Load(testUrl, apiVersion));
82 }
83 }  // namespace Media
84 }  // namespace OHOS
85