1 /*
2  * Copyright (c) 2023 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 "av_router.h"
18 #include "avsession_errors.h"
19 #include "avsession_log.h"
20 
21 using namespace testing::ext;
22 namespace OHOS {
23 namespace AVSession {
24 class AVRouterTest : public testing::Test {
25 public:
26     static void SetUpTestCase();
27     static void TearDownTestCase();
28     void SetUp() override;
29     void TearDown() override;
30 };
31 
SetUpTestCase()32 void AVRouterTest::SetUpTestCase()
33 {}
34 
TearDownTestCase()35 void AVRouterTest::TearDownTestCase()
36 {}
37 
SetUp()38 void AVRouterTest::SetUp()
39 {}
40 
TearDown()41 void AVRouterTest::TearDown()
42 {}
43 
44 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
45 /**
46 * @tc.name: StartCastDiscovery001
47 * @tc.desc: start cast discovery for default cast type "local"
48 * @tc.type: FUNC
49 * @tc.require: NA
50 */
51 static HWTEST_F(AVRouterTest, StartCastDiscovery001, TestSize.Level1)
52 {
53     SLOGI("StartCastDiscovery001 begin");
54     auto ret = AVRouter::GetInstance().StartCastDiscovery(ProtocolType::TYPE_LOCAL, {});
55     EXPECT_EQ(ret, AVSESSION_SUCCESS);
56     SLOGI("StartCastDiscovery001 end");
57 }
58 
59 /**
60 * @tc.name: StartCastDiscovery002
61 * @tc.desc: start cast discovery for invalid cast type
62 * @tc.type: FUNC
63 * @tc.require: NA
64 */
65 static HWTEST_F(AVRouterTest, StartCastDiscovery002, TestSize.Level1)
66 {
67     SLOGI("StartCastDiscovery001 begin");
68     auto ret = AVRouter::GetInstance().StartCastDiscovery(-1, {});
69     EXPECT_EQ(ret, AVSESSION_SUCCESS);
70     SLOGI("StartCastDiscovery001 end");
71 }
72 
73 /**
74 * @tc.name: StopCastDiscovery001
75 * @tc.desc: stop cast discovery success
76 * @tc.type: FUNC
77 * @tc.require: NA
78 */
79 static HWTEST_F(AVRouterTest, StopCastDiscovery001, TestSize.Level1)
80 {
81     SLOGI("StopCastDiscovery001 begin");
82     auto ret = AVRouter::GetInstance().StartCastDiscovery(ProtocolType::TYPE_LOCAL, {});
83     EXPECT_EQ(ret, AVSESSION_SUCCESS);
84     ret = AVRouter::GetInstance().StopCastDiscovery();
85     EXPECT_EQ(ret, AVSESSION_SUCCESS);
86     SLOGI("StopCastDiscovery001 end");
87 }
88 
89 /**
90 * @tc.name: SetDiscoverable001
91 * @tc.desc: setDiscoverable true
92 * @tc.type: FUNC
93 * @tc.require: NA
94 */
95 static HWTEST_F(AVRouterTest, SetDiscoverable001, TestSize.Level1)
96 {
97     SLOGI("SetDiscoverable001 begin");
98     auto ret = AVRouter::GetInstance().SetDiscoverable(true);
99     EXPECT_EQ(ret, AVSESSION_SUCCESS);
100     SLOGI("SetDiscoverable001 end");
101 }
102 
103 /**
104 * @tc.name: OnDeviceAvailable001
105 * @tc.desc: StartCast success
106 * @tc.type: FUNC
107 * @tc.require: NA
108 */
109 HWTEST_F(AVRouterTest, OnDeviceAvailable001, TestSize.Level1)
110 {
111     SLOGI("OnDeviceAvailable001 begin");
112     OutputDeviceInfo outputDeviceInfo;
113     auto ret = AVRouter::GetInstance().OnDeviceAvailable(outputDeviceInfo);
114     EXPECT_NE(ret, AVSESSION_SUCCESS);
115     SLOGI("OnDeviceAvailable001 end");
116 }
117 
118 /**
119 * @tc.name: OnCastServerDied001
120 * @tc.desc: setDiscoverable true
121 * @tc.type: FUNC
122 * @tc.require: NA
123 */
124 static HWTEST_F(AVRouterTest, OnCastServerDied001, TestSize.Level1)
125 {
126     SLOGI("OnCastServerDied001 begin");
127     auto ret = AVRouter::GetInstance().OnCastServerDied(-1);
128     EXPECT_EQ(ret, AVSESSION_ERROR);
129     SLOGI("OnCastServerDied001 end");
130 }
131 #endif
132 }
133 }