• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
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 "audio_background_adapter_unit_test.h"
17 #include <unistd.h>
18 #include <chrono>
19 #include <thread>
20 #include <memory>
21 #include "player.h"
22 #include "player_server.h"
23 #include "media_dfx.h"
24 #include "media_log.h"
25 
26 namespace OHOS {
27 namespace Media {
28 namespace Test {
29 using namespace std;
30 using namespace testing::ext;
31 constexpr int32_t CONSTRUCTED_UID_1 = 999999;
32 constexpr int32_t CONSTRUCTED_UID_2 = 1000000;
SetUpTestCase(void)33 void AudioBackGroundAdapterUnitTest::SetUpTestCase(void) {}
34 
TearDownTestCase(void)35 void AudioBackGroundAdapterUnitTest::TearDownTestCase(void) {}
36 
SetUp(void)37 void AudioBackGroundAdapterUnitTest::SetUp(void) {}
38 
TearDown(void)39 void AudioBackGroundAdapterUnitTest::TearDown(void) {}
40 
41 /**
42  * @tc.name  : AddListener
43  * @tc.number: AddListener
44  * @tc.desc  : FUNC
45  */
46 HWTEST_F(AudioBackGroundAdapterUnitTest, AddListener, TestSize.Level1)
47 {
48     auto playerServer = PlayerServer::Create();
49     EXPECT_NE(playerServer, nullptr);
50     AudioBackgroundAdapter::Instance().AddListener(playerServer, CONSTRUCTED_UID_1);
51     playerServer = nullptr;
52     auto playerServer2 = PlayerServer::Create();
53     EXPECT_NE(playerServer2, nullptr);
54     AudioBackgroundAdapter::Instance().AddListener(playerServer2, CONSTRUCTED_UID_1);
55     auto playerServer3 = PlayerServer::Create();
56     EXPECT_NE(playerServer3, nullptr);
57     AudioBackgroundAdapter::Instance().AddListener(playerServer3, CONSTRUCTED_UID_1);
58     EXPECT_NE(AudioBackgroundAdapter::Instance().playerMap_.size(), 0);
59     playerServer2 = nullptr;
60     playerServer3 = nullptr;
61 }
62 
63 /**
64  * @tc.name  : OnBackgroundMute
65  * @tc.number: OnBackgroundMute
66  * @tc.desc  : FUNC
67  */
68 HWTEST_F(AudioBackGroundAdapterUnitTest, OnBackgroundMute, TestSize.Level1)
69 {
70     auto playerServer = std::static_pointer_cast<PlayerServer>(PlayerServer::Create());
71     ASSERT_NE(playerServer, nullptr);
72     playerServer->lastOpStatus_ = PLAYER_STARTED;
73     AudioBackgroundAdapter::Instance().AddListener(playerServer, CONSTRUCTED_UID_2);
74     AudioBackgroundAdapter::Instance().OnBackgroundMute(CONSTRUCTED_UID_2);
75     AudioBackgroundAdapter::Instance().OnAudioRestart();
76     std::this_thread::sleep_for(std::chrono::milliseconds(100));
77 }
78 
79 }  // namespace Test
80 }  // namespace Media
81 }  // namespace OHOS