1 /*
2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 "windowmgr/include/window_manager.h"
17 #include "common/const_def.h"
18 #include "wfd_sink_unit_test.h"
19 #include <gtest/gtest.h>
20 #include <memory>
21 #include "common/sharing_log.h"
22 #include "common/const_def.h"
23 using namespace testing::ext;
24 using namespace OHOS;
25 using namespace OHOS::Sharing;
SetUpTestCase()26 void WfdSinkUnitTest::SetUpTestCase() {}
TearDownTestCase()27 void WfdSinkUnitTest::TearDownTestCase() {}
SetUp()28 void WfdSinkUnitTest::SetUp()
29 {
30 wfdSink_ = WfdSinkFactory::CreateSink(0,"wfd_sink_demo");
31 ASSERT_NE(nullptr, wfdSink_);
32 ASSERT_EQ(SharingErrorCode::ERR_OK, wfdSink_->Start());
33 }
TearDown()34 void WfdSinkUnitTest::TearDown()
35 {
36 if (wfdSink_ != nullptr) {
37 ASSERT_EQ(SharingErrorCode::ERR_OK, wfdSink_->Stop());
38 }
39 }
40 /**
41 * @tc.name: wfd_sink_SetSurface_0100
42 * @tc.desc: wfd sink SetSurface
43 * @tc.type: FUNC
44 * @tc.require:
45 */
46 HWTEST_F(WfdSinkUnitTest, wfd_sink_SetSurface_0100, TestSize.Level0)
47 {
48 EXPECT_NE(SharingErrorCode::ERR_OK, wfdSink_->AppendSurface("0", 0));
49 WindowProperty::Ptr windowPropertyPtr = std::make_shared<WindowProperty>();
50 windowPropertyPtr->height = 1920;
51 windowPropertyPtr->width = 1080;
52 windowPropertyPtr->startX = 0;
53 windowPropertyPtr->startY = 0;
54 windowPropertyPtr->isFull = false;
55 windowPropertyPtr->isShow = true;
56 int32_t windowId = WindowManager::GetInstance().CreateWindow(windowPropertyPtr);
57 sptr<Surface> surface = WindowManager::GetInstance().GetSurface(windowId);
58 ASSERT_NE(nullptr, surface);
59 if (surface) {
60 uint64_t surfaceId = surface->GetUniqueId();
61 EXPECT_NE(SharingErrorCode::ERR_OK, wfdSink_->AppendSurface("0", surfaceId));
62 }
63 }
64 /**
65 * @tc.name: wfd_sink_SetMediaFormat_0100
66 * @tc.desc: wfd sink SetMediaFormat
67 * @tc.type: FUNC
68 * @tc.require:
69 */
70 HWTEST_F(WfdSinkUnitTest, wfd_sink_SetMediaFormat_0100, TestSize.Level0)
71 {
72 CodecAttr videoAttr;
73 videoAttr.codecType = CodecId::CODEC_H264;
74 videoAttr.formatId = VideoFormat::VIDEO_1920X1080_30;
75 CodecAttr audioAttr;
76 audioAttr.codecType = CodecId::CODEC_AAC;
77 audioAttr.formatId = AudioFormat::AUDIO_48000_16_2;
78 EXPECT_NE(SharingErrorCode::ERR_OK, wfdSink_->SetMediaFormat("0", videoAttr, audioAttr));
79 }
80 /**
81 * @tc.name: wfd_sink_play_0100
82 * @tc.desc: wfd sink play
83 * @tc.type: FUNC
84 * @tc.require:
85 */
86 HWTEST_F(WfdSinkUnitTest, wfd_sink_play_0100, TestSize.Level0)
87 {
88 EXPECT_NE(SharingErrorCode::ERR_OK, wfdSink_->Play("0"));
89 }
90 /**
91 * @tc.name: wfd_sink_pause_0100
92 * @tc.desc: wfd sink pause
93 * @tc.type: FUNC
94 * @tc.require:
95 */
96 HWTEST_F(WfdSinkUnitTest, wfd_sink_pause_0100, TestSize.Level0)
97 {
98 EXPECT_NE(SharingErrorCode::ERR_OK, wfdSink_->Pause("0"));
99 }
100 /**
101 * @tc.name: wfd_sink_close_0100
102 * @tc.desc: wfd sink close
103 * @tc.type: FUNC
104 * @tc.require:
105 */
106 HWTEST_F(WfdSinkUnitTest, wfd_sink_close_0100, TestSize.Level0)
107 {
108 EXPECT_NE(SharingErrorCode::ERR_OK, wfdSink_->Close("0"));
109 }
110 /**
111 * @tc.name: wfd_sink_set_scene_0100
112 * @tc.desc: wfd sink set scene type
113 * @tc.type: FUNC
114 * @tc.require:
115 */
116 HWTEST_F(WfdSinkUnitTest, wfd_sink_set_scene_0100, TestSize.Level0)
117 {
118 OHOS::Sharing::SceneType sceneType = OHOS::Sharing::SceneType::FOREGROUND;
119 EXPECT_NE(SharingErrorCode::ERR_OK, wfdSink_->SetSceneType("0", 0, sceneType));
120 }
121 /**
122 * @tc.name: wfd_sink_mute_0100
123 * @tc.desc: wfd sink mute
124 * @tc.type: FUNC
125 * @tc.require:
126 */
127 HWTEST_F(WfdSinkUnitTest, wfd_sink_mute_0100, TestSize.Level0)
128 {
129 EXPECT_NE(SharingErrorCode::ERR_OK, wfdSink_->Mute("0"));
130 }
131 /**
132 * @tc.name: wfd_sink_unmute_0100
133 * @tc.desc: wfd sink unmute
134 * @tc.type: FUNC
135 * @tc.require:
136 */
137 HWTEST_F(WfdSinkUnitTest, wfd_sink_unmute_0100, TestSize.Level0)
138 {
139 EXPECT_NE(SharingErrorCode::ERR_OK, wfdSink_->UnMute("0"));
140 }
141 /**
142 * @tc.name: wfd_sink_GetSinkConfig_0100
143 * @tc.desc: wfd sink GetSinkConfig
144 * @tc.type: FUNC
145 * @tc.require:
146 */
147 HWTEST_F(WfdSinkUnitTest, wfd_sink_GetSinkConfig_0100, TestSize.Level0)
148 {
149 SinkConfig sinkConfig;
150 EXPECT_EQ(SharingErrorCode::ERR_OK, wfdSink_->GetSinkConfig(sinkConfig));
151 EXPECT_NE(0, sinkConfig.foregroundMaximum);
152 EXPECT_NE(0, sinkConfig.surfaceMaximum);
153 }
154