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 <securec.h>
18
19 #include "softbus_errcode.h"
20 #include "softbus_adapter_mem.h"
21 #include "lnn_lane_query.h"
22 #include "lnn_lane.h"
23
24 using namespace testing::ext;
25
26 namespace OHOS {
27 constexpr char NODE_NETWORK_ID[] = "111122223333abcdef";
28 constexpr uint32_t LOW_BW = 500 * 1024;
29 constexpr uint32_t MID_BW = 1000 * 1024;
30 constexpr uint32_t HIGH_BW = 160 * 1024 * 1024;
31
32 class LNNLaneQueryTest : public testing::Test {
33 public:
LNNLaneQueryTest()34 LNNLaneQueryTest()
35 {
36 }
~LNNLaneQueryTest()37 ~LNNLaneQueryTest()
38 {
39 }
40 static void SetUpTestCase(void);
41 static void TearDownTestCase(void);
SetUp()42 void SetUp() override
43 {
44 }
TearDown()45 void TearDown() override
46 {
47 }
48 };
49
SetUpTestCase(void)50 void LNNLaneQueryTest::SetUpTestCase(void)
51 {
52 }
53
TearDownTestCase(void)54 void LNNLaneQueryTest::TearDownTestCase(void)
55 {
56 }
57
58 /*
59 * @tc.name: LNN_QUERY_LANE_001
60 * @tc.desc: QueryLane
61 * @tc.type: FUNC
62 * @tc.require:
63 */
64 HWTEST_F(LNNLaneQueryTest, LNN_LANE_QUERY_001, TestSize.Level1)
65 {
66 QosInfo qosInfo = {0};
67 int32_t ret = LnnQueryLaneResource(nullptr, &qosInfo);
68 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
69
70 LaneQueryInfo query;
71 memset_s(&query, sizeof(LaneQueryInfo), 0, sizeof(LaneQueryInfo));
72 query.transType = LANE_T_BYTE;
73 (void)memcpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
74
75 ret = LnnQueryLaneResource(&query, &qosInfo);
76 EXPECT_NE(ret, SOFTBUS_OK);
77
78 ret = LnnQueryLaneResource(&query, nullptr);
79 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
80
81 ret = LnnQueryLaneResource(&query, &qosInfo);
82 EXPECT_NE(ret, SOFTBUS_OK);
83
84 ret = LnnQueryLaneResource(&query, &qosInfo);
85 EXPECT_NE(ret, SOFTBUS_OK);
86 }
87
88 /*
89 * @tc.name: LNN_QUERY_LANE_002
90 * @tc.desc: QueryLane
91 * @tc.type: FUNC
92 * @tc.require:
93 */
94 HWTEST_F(LNNLaneQueryTest, LNN_LANE_QUERY_002, TestSize.Level1)
95 {
96 QosInfo qosInfo = {0};
97 int32_t ret = QueryLaneResource(nullptr, &qosInfo);
98 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
99
100 LaneQueryInfo query;
101 query.transType = LANE_T_BYTE;
102 (void)memcpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
103 ret = QueryLaneResource(&query, nullptr);
104 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
105
106 qosInfo.minBW = LOW_BW;
107 ret = QueryLaneResource(&query, &qosInfo);
108 EXPECT_NE(ret, SOFTBUS_OK);
109
110 qosInfo.minBW = MID_BW;
111 ret = QueryLaneResource(&query, &qosInfo);
112 EXPECT_NE(ret, SOFTBUS_OK);
113 }
114
115 /*
116 * @tc.name: LNN_QUERY_LANE_003
117 * @tc.desc: QueryLane
118 * @tc.type: FUNC
119 * @tc.require:
120 */
121 HWTEST_F(LNNLaneQueryTest, LNN_LANE_QUERY_003, TestSize.Level1)
122 {
123 QosInfo qosInfo = {0};
124 LaneQueryInfo query;
125 query.transType = LANE_T_MSG;
126 (void)memcpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
127
128 qosInfo.minBW = LOW_BW;
129 int32_t ret = QueryLaneResource(&query, &qosInfo);
130 EXPECT_NE(ret, SOFTBUS_OK);
131
132 qosInfo.minBW = MID_BW;
133 ret = QueryLaneResource(&query, &qosInfo);
134 EXPECT_NE(ret, SOFTBUS_OK);
135 }
136
137 /*
138 * @tc.name: LNN_QUERY_LANE_004
139 * @tc.desc: QueryLane
140 * @tc.type: FUNC
141 * @tc.require:
142 */
143 HWTEST_F(LNNLaneQueryTest, LNN_LANE_QUERY_004, TestSize.Level1)
144 {
145 QosInfo qosInfo = {0};
146 LaneQueryInfo query;
147 query.transType = LANE_T_FILE;
148 (void)memcpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
149
150 qosInfo.minBW = LOW_BW;
151 int32_t ret = QueryLaneResource(&query, &qosInfo);
152 EXPECT_NE(ret, SOFTBUS_OK);
153
154 qosInfo.minBW = MID_BW;
155 ret = QueryLaneResource(&query, &qosInfo);
156 EXPECT_NE(ret, SOFTBUS_OK);
157
158 qosInfo.minBW = HIGH_BW;
159 ret = QueryLaneResource(&query, &qosInfo);
160 EXPECT_NE(ret, SOFTBUS_OK);
161 }
162
163 /*
164 * @tc.name: LNN_QUERY_LANE_005
165 * @tc.desc: QueryLane
166 * @tc.type: FUNC
167 * @tc.require:
168 */
169 HWTEST_F(LNNLaneQueryTest, LNN_LANE_QUERY_005, TestSize.Level1)
170 {
171 QosInfo qosInfo = {0};
172 LaneQueryInfo query;
173 query.transType = LANE_T_RAW_STREAM;
174 (void)memcpy_s(query.networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
175
176 qosInfo.minBW = MID_BW;
177 int32_t ret = QueryLaneResource(&query, &qosInfo);
178 EXPECT_NE(ret, SOFTBUS_OK);
179
180 query.transType = LANE_T_COMMON_VIDEO;
181 ret = QueryLaneResource(&query, &qosInfo);
182 EXPECT_NE(ret, SOFTBUS_OK);
183
184 query.transType = LANE_T_COMMON_VOICE;
185 ret = QueryLaneResource(&query, &qosInfo);
186 EXPECT_NE(ret, SOFTBUS_OK);
187 }
188 }