1 /*
2 * Copyright (c) 2024 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 <gtest/gtest.h>
17 #include "playback_capturer_manager.h"
18 #include "audio_info.h"
19
20 using namespace testing::ext;
21 namespace OHOS {
22 namespace AudioStandard {
23 static PlaybackCapturerManager *playbackCapturerMgr_ = PlaybackCapturerManager::GetInstance();
24
25 class PlaybackPlaybackCapturerManagerUnitTest : public testing::Test {
26 public:
27 static void SetUpTestCase(void);
28 static void TearDownTestCase(void);
29 void SetUp();
30 void TearDown();
31 };
32
SetUpTestCase(void)33 void PlaybackPlaybackCapturerManagerUnitTest::SetUpTestCase(void)
34 {
35 // input testsuit setup step,setup invoked before all testcases
36 }
37
TearDownTestCase(void)38 void PlaybackPlaybackCapturerManagerUnitTest::TearDownTestCase(void)
39 {
40 // input testsuit teardown step,teardown invoked after all testcases
41 }
42
SetUp(void)43 void PlaybackPlaybackCapturerManagerUnitTest::SetUp(void)
44 {
45 // input testcase setup step,setup invoked before each testcases
46 }
47
TearDown(void)48 void PlaybackPlaybackCapturerManagerUnitTest::TearDown(void)
49 {
50 // input testcase teardown step,teardown invoked after each testcases
51 }
52
53 /**
54 * @tc.name : Test IsStreamSupportInnerCapturer API via legal state
55 * @tc.type : FUNC
56 * @tc.number: IsStreamSupportInnerCapturer_001
57 * @tc.desc : Test IsStreamSupportInnerCapturer interface. Is stream support inner capturer and return ret.
58 */
59 HWTEST(PlaybackPlaybackCapturerManagerUnitTest, IsStreamSupportInnerCapturer_001, TestSize.Level1)
60 {
61 std::vector<int32_t> usage;
62 usage.push_back(STREAM_USAGE_MEDIA);
63 usage.push_back(STREAM_USAGE_MUSIC);
64 usage.push_back(STREAM_USAGE_GAME);
65 usage.push_back(STREAM_USAGE_MOVIE);
66 usage.push_back(STREAM_USAGE_AUDIOBOOK);
67 playbackCapturerMgr_->SetSupportStreamUsage(usage);
68 for (int32_t usageItem : usage) {
69 bool ret = IsStreamSupportInnerCapturer(usageItem);
70 EXPECT_TRUE(ret);
71 }
72 }
73
74 /**
75 * @tc.name : Test IsStreamSupportInnerCapturer API via illegal state
76 * @tc.type : FUNC
77 * @tc.number: IsStreamSupportInnerCapturer_002
78 * @tc.desc : Test IsStreamSupportInnerCapturer interface. Is stream support inner capturer and return ret.
79 */
80 HWTEST(PlaybackPlaybackCapturerManagerUnitTest, IsStreamSupportInnerCapturer_002, TestSize.Level1)
81 {
82 std::vector<int32_t> usage;
83 playbackCapturerMgr_->SetSupportStreamUsage(usage);
84 bool ret = playbackCapturerMgr_->IsStreamSupportInnerCapturer(STREAM_USAGE_RANGING);
85 EXPECT_FALSE(ret);
86 }
87
88 /**
89 * @tc.name : Test IsStreamSupportInnerCapturer API via legal state
90 * @tc.type : FUNC
91 * @tc.number: IsStreamSupportInnerCapturer_003
92 * @tc.desc : Test IsStreamSupportInnerCapturer interface. Is stream support inner capturer and return ret.
93 */
94 HWTEST(PlaybackPlaybackCapturerManagerUnitTest, IsStreamSupportInnerCapturer_003, TestSize.Level1)
95 {
96 std::vector<int32_t> usage;
97 usage.push_back(STREAM_USAGE_MEDIA);
98 usage.push_back(STREAM_USAGE_MUSIC);
99 usage.push_back(STREAM_USAGE_GAME);
100 usage.push_back(STREAM_USAGE_MOVIE);
101 usage.push_back(STREAM_USAGE_AUDIOBOOK);
102 playbackCapturerMgr_->SetSupportStreamUsage(usage);
103 bool ret = playbackCapturerMgr_->IsStreamSupportInnerCapturer(STREAM_USAGE_MEDIA);
104 EXPECT_TRUE(ret);
105 }
106
107 /**
108 * @tc.name : Test IsPrivacySupportInnerCapturer API via legal state
109 * @tc.type : FUNC
110 * @tc.number: IsPrivacySupportInnerCapturer_001
111 * @tc.desc : Test IsPrivacySupportInnerCapturer interface. Is privacy support innter capturer and return ret.
112 */
113 HWTEST(PlaybackPlaybackCapturerManagerUnitTest, IsPrivacySupportInnerCapturer_001, TestSize.Level1)
114 {
115 bool ret = IsPrivacySupportInnerCapturer(PRIVACY_TYPE_PUBLIC);
116 EXPECT_TRUE(ret);
117 }
118
119 /**
120 * @tc.name : Test IsPrivacySupportInnerCapturer API via legal state
121 * @tc.type : FUNC
122 * @tc.number: IsPrivacySupportInnerCapturer_002
123 * @tc.desc : Test IsPrivacySupportInnerCapturer interface. Is privacy support innter capturer and return ret.
124 */
125 HWTEST(PlaybackPlaybackCapturerManagerUnitTest, IsPrivacySupportInnerCapturer_002, TestSize.Level1)
126 {
127 bool ret = IsPrivacySupportInnerCapturer(PRIVACY_TYPE_PRIVATE);
128 EXPECT_FALSE(ret);
129 }
130
131 /**
132 * @tc.name : Test SetInnerCapturerState API via legal and illegal state
133 * @tc.type : FUNC
134 * @tc.number: SetInnerCapturerState_001
135 * @tc.desc : Test SetInnerCapturerState interface. Set inner capturer state.
136 */
137 HWTEST(PlaybackPlaybackCapturerManagerUnitTest, SetInnerCapturerState_001, TestSize.Level1)
138 {
139 SetInnerCapturerState(true);
140 bool ret = GetInnerCapturerState();
141 EXPECT_TRUE(ret);
142 SetInnerCapturerState(false);
143 ret = GetInnerCapturerState();
144 EXPECT_FALSE(ret);
145 }
146
147 }
148 }