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 <gtest/gtest.h>
17 #include <chrono>
18 #include <thread>
19
20 #include "accesstoken_kit.h"
21 #include "avsession_errors.h"
22 #include "avsession_log.h"
23 #include "avsession_service.h"
24 #include "migrate_avsession_constant.h"
25 #include "migrate_avsession_proxy.h"
26 #include "nativetoken_kit.h"
27 #include "token_setproc.h"
28 #include "softbus_distributed_data_manager.h"
29 #include "softbus_session_manager.h"
30
31 using namespace testing::ext;
32 using namespace OHOS::AVSession;
33
34 std::shared_ptr<SoftbusDistributedDataManager> g_SoftbusDistributedDataManager {nullptr};
35 std::shared_ptr<MigrateAVSessionProxy> g_MigrateAVSessionProxy {nullptr};
36 std::shared_ptr<AVSessionService> g_AVSessionService {nullptr};
37
38 class SoftbusSessionManagerSupplementTest : public testing::Test {
39 public:
40 static void SetUpTestCase();
41 static void TearDownTestCase();
42 void SetUp();
43 void TearDown();
44 };
45
SetUpTestCase()46 void SoftbusSessionManagerSupplementTest::SetUpTestCase()
47 {
48 g_SoftbusDistributedDataManager = std::make_shared<SoftbusDistributedDataManager>();
49 g_AVSessionService = std::make_shared<AVSessionService>(OHOS::AVSESSION_SERVICE_ID);
50 g_MigrateAVSessionProxy = std::make_shared<MigrateAVSessionProxy>(g_AVSessionService.get());
51 }
52
TearDownTestCase()53 void SoftbusSessionManagerSupplementTest::TearDownTestCase()
54 {
55 g_SoftbusDistributedDataManager = nullptr;
56 g_MigrateAVSessionProxy = nullptr;
57 g_AVSessionService = nullptr;
58 }
59
SetUp()60 void SoftbusSessionManagerSupplementTest::SetUp() {}
61
TearDown()62 void SoftbusSessionManagerSupplementTest::TearDown() {}
63
64 /**
65 * @tc.name: CreateProxy001
66 * @tc.desc: fail to create
67 * @tc.type: FUNC
68 * @tc.require:
69 */
70 static HWTEST_F(SoftbusSessionManagerSupplementTest, CreateProxy001, TestSize.Level1)
71 {
72 std::string peerNetworkId = "";
73 std::string packageName = "";
74 bool ret = g_SoftbusDistributedDataManager->CreateProxy(nullptr, peerNetworkId, packageName);
75 EXPECT_EQ(ret, false);
76 }
77
78 /**
79 * @tc.name: CreateProxy002
80 * @tc.desc: fail to create
81 * @tc.type: FUNC
82 * @tc.require:
83 */
84 static HWTEST_F(SoftbusSessionManagerSupplementTest, CreateProxy002, TestSize.Level1)
85 {
86 std::string peerNetworkId = "";
87 std::string packageName = "";
88 bool ret = g_SoftbusDistributedDataManager->CreateProxy(g_MigrateAVSessionProxy, peerNetworkId, packageName);
89 EXPECT_EQ(ret, false);
90 }
91
92 /**
93 * @tc.name: CreateProxy003
94 * @tc.desc: fail to create
95 * @tc.type: FUNC
96 * @tc.require:
97 */
98 static HWTEST_F(SoftbusSessionManagerSupplementTest, CreateProxy003, TestSize.Level1)
99 {
100 std::string peerNetworkId = "";
101 std::string packageName = "test";
102 bool ret = g_SoftbusDistributedDataManager->CreateProxy(g_MigrateAVSessionProxy, peerNetworkId, packageName);
103 EXPECT_EQ(ret, false);
104 }
105
106 /**
107 * @tc.name: CreateProxy004
108 * @tc.desc: fail to create
109 * @tc.type: FUNC
110 * @tc.require:
111 */
112 static HWTEST_F(SoftbusSessionManagerSupplementTest, CreateProxy004, TestSize.Level1)
113 {
114 std::string peerNetworkId = "test";
115 std::string packageName = "";
116 bool ret = g_SoftbusDistributedDataManager->CreateProxy(g_MigrateAVSessionProxy, peerNetworkId, packageName);
117 EXPECT_EQ(ret, false);
118 }
119
120 /**
121 * @tc.name: CreateProxy005
122 * @tc.desc: fail to create
123 * @tc.type: FUNC
124 * @tc.require:
125 */
126 static HWTEST_F(SoftbusSessionManagerSupplementTest, CreateProxy005, TestSize.Level1)
127 {
128 std::string peerNetworkId = "0.0.0.0";
129 std::string packageName = "packageName";
130 g_SoftbusDistributedDataManager->mProxySocketMap_.insert({peerNetworkId, 0});
131 bool ret = g_SoftbusDistributedDataManager->CreateProxy(g_MigrateAVSessionProxy, peerNetworkId, packageName);
132 EXPECT_EQ(ret, false);
133 }