• 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_unit_test.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::ext;
23 using namespace std;
24 
25 const int32_t MAX_STREAMS = 3;
26 const int32_t BEGIN_NUM = 0;
27 const int32_t STREAM_ID_BEGIN = 1;
28 
29 namespace {
30 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_SOUNDPOOL, "SoundIdManagerUnitTest"};
31 }
32 
33 namespace OHOS {
34 namespace Media {
SetUpTestCase(void)35 void SoundIDManagerUnitTest::SetUpTestCase(void)
36 {}
37 
TearDownTestCase(void)38 void SoundIDManagerUnitTest::TearDownTestCase(void)
39 {
40     std::cout << "sleep one second to protect PlayerEngine safely exit." << endl;
41     sleep(1);  // let PlayEngine safe exit.
42 }
43 
SetUp(void)44 void SoundIDManagerUnitTest::SetUp(void)
45 {
46     AudioStandard::AudioRendererInfo audioRenderInfo;
47     audioRenderInfo.contentType = AudioStandard::CONTENT_TYPE_MUSIC;
48     audioRenderInfo.streamUsage = AudioStandard::STREAM_USAGE_MUSIC;
49     audioRenderInfo.rendererFlags = 0;
50     soundIDManager_ = std::make_shared<SoundIDManager>();
51 }
52 
TearDown(void)53 void SoundIDManagerUnitTest::TearDown(void)
54 {
55     if (soundIDManager_ != nullptr) {
56         soundIDManager_.reset();
57     }
58 }
59 
60 /**
61  * @tc.name: soundId_function_001
62  * @tc.desc: function test MulInitThreadPool
63  * @tc.type: FUNC
64  * @tc.require:
65  */
66 HWTEST_F(SoundIDManagerUnitTest, soundId_function_001, TestSize.Level2)
67 {
68     MEDIA_LOGI("soundId_function_001 before");
69     soundIDManager_->isParsingThreadPoolStarted_.store(true);
70     EXPECT_EQ(MSERR_OK, soundIDManager_->InitThreadPool());
71     MEDIA_LOGI("soundId_function_001 after");
72 }
73 
74 /**
75  * @tc.name: soundId_function_002
76  * @tc.desc: function test DoLoad & Unload
77  * @tc.type: FUNC
78  * @tc.require:
79  */
80 HWTEST_F(SoundIDManagerUnitTest, soundId_function_002, TestSize.Level2)
81 {
82     MEDIA_LOGI("soundId_function_002 before");
83     soundIDManager_->isParsingThreadPoolStarted_.store(false);
84     EXPECT_EQ(MSERR_OK, soundIDManager_->DoLoad(0));
85     soundIDManager_->soundParsers_.emplace(0, nullptr);
86     EXPECT_EQ(MSERR_INVALID_VAL, soundIDManager_->Unload(1));
87     EXPECT_EQ(MSERR_OK, soundIDManager_->Unload(0));
88 
89     MEDIA_LOGI("soundId_function_002 after");
90 }
91 
92 }  // namespace Media
93 }  // namespace OHOS