• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "client_trans_channel_manager.h"
20 #include "softbus_def.h"
21 #include "softbus_errcode.h"
22 
23 #define TEST_DATA_LENGTH 1024
24 
25 using namespace std;
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 class ClientTransChannelManagerTest : public testing::Test {
30 public:
ClientTransChannelManagerTest()31     ClientTransChannelManagerTest() {}
~ClientTransChannelManagerTest()32     ~ClientTransChannelManagerTest() {}
33     static void SetUpTestCase(void);
34     static void TearDownTestCase(void);
SetUp()35     void SetUp() override {}
TearDown()36     void TearDown() override {}
37 };
38 
SetUpTestCase(void)39 void ClientTransChannelManagerTest::SetUpTestCase(void) {}
TearDownTestCase(void)40 void ClientTransChannelManagerTest::TearDownTestCase(void) {}
41 
42 /**
43  * @tc.name: ClientTransCloseChannelTest001
44  * @tc.desc: client trans channel manager test, use the wrong or normal parameter.
45  * @tc.type: FUNC
46  * @tc.require:
47  */
48 HWTEST_F(ClientTransChannelManagerTest, ClientTransCloseChannelTest001, TestSize.Level0)
49 {
50     int channelId = 1;
51     int ret = ClientTransCloseChannel(channelId, CHANNEL_TYPE_PROXY);
52     EXPECT_EQ(SOFTBUS_OK, ret);
53 
54     ret = ClientTransCloseChannel(channelId, CHANNEL_TYPE_TCP_DIRECT);
55     EXPECT_EQ(SOFTBUS_OK, ret);
56 
57     ret = ClientTransCloseChannel(channelId, CHANNEL_TYPE_AUTH);
58     EXPECT_EQ(SOFTBUS_OK, ret);
59 
60     ret = ClientTransCloseChannel(channelId, CHANNEL_TYPE_BUTT);
61     EXPECT_EQ(SOFTBUS_TRANS_INVALID_CHANNEL_TYPE, ret);
62 }
63 
64 
65 /**
66  * @tc.name: ClientTransChannelSendBytesTest001
67  * @tc.desc: client trans channel send byte test, use the wrong or normal parameter.
68  * @tc.type: FUNC
69  * @tc.require:
70  */
71 HWTEST_F(ClientTransChannelManagerTest, ClientTransChannelSendBytesTest001, TestSize.Level0)
72 {
73     int channelId = 1;
74     const void *data = (const void *)"test";
75 
76     int ret = ClientTransChannelSendBytes(channelId, CHANNEL_TYPE_AUTH, nullptr, TEST_DATA_LENGTH);
77     EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
78 
79     ret = ClientTransChannelSendBytes(channelId, CHANNEL_TYPE_AUTH, data, TEST_DATA_LENGTH);
80     EXPECT_EQ(SOFTBUS_ERR, ret);
81 
82     ret = ClientTransChannelSendBytes(channelId, CHANNEL_TYPE_PROXY, data, TEST_DATA_LENGTH);
83     EXPECT_EQ(SOFTBUS_ERR, ret);
84 
85     ret = ClientTransChannelSendBytes(channelId, CHANNEL_TYPE_TCP_DIRECT, data, TEST_DATA_LENGTH);
86     EXPECT_EQ(SOFTBUS_ERR, ret);
87 
88     ret = ClientTransChannelSendBytes(channelId, CHANNEL_TYPE_BUTT, data, TEST_DATA_LENGTH);
89     EXPECT_EQ(SOFTBUS_ERR, ret);
90 }
91 
92 /**
93  * @tc.name: ClientTransChannelSendMessageTest001
94  * @tc.desc: client trans channel send message test, use the wrong or normal parameter.
95  * @tc.type: FUNC
96  * @tc.require:
97  */
98 HWTEST_F(ClientTransChannelManagerTest, ClientTransChannelSendMessageTest001, TestSize.Level0)
99 {
100     int channelId = 1;
101     const void *data = (const void *)"test";
102 
103     int ret = ClientTransChannelSendMessage(channelId, CHANNEL_TYPE_AUTH, nullptr, TEST_DATA_LENGTH);
104     EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
105 
106     ret = ClientTransChannelSendMessage(channelId, CHANNEL_TYPE_AUTH, data, TEST_DATA_LENGTH);
107     EXPECT_EQ(SOFTBUS_ERR, ret);
108 
109     ret = ClientTransChannelSendMessage(channelId, CHANNEL_TYPE_PROXY, data, TEST_DATA_LENGTH);
110     EXPECT_EQ(SOFTBUS_ERR, ret);
111 
112     ret = ClientTransChannelSendMessage(channelId, CHANNEL_TYPE_TCP_DIRECT, data, TEST_DATA_LENGTH);
113     EXPECT_EQ(SOFTBUS_TRANS_TDC_CHANNEL_NOT_FOUND, ret);
114 
115     ret = ClientTransChannelSendMessage(channelId, CHANNEL_TYPE_BUTT, data, TEST_DATA_LENGTH);
116     EXPECT_EQ(SOFTBUS_TRANS_CHANNEL_TYPE_INVALID, ret);
117 }
118 
119 /**
120  * @tc.name: ClientTransChannelSendStreamTest001
121  * @tc.desc: client trans channel send stream test, use the wrong or normal parameter.
122  * @tc.type: FUNC
123  * @tc.require:
124  */
125 HWTEST_F(ClientTransChannelManagerTest, ClientTransChannelSendStreamTest001, TestSize.Level0)
126 {
127     int channelId = 1;
128     const StreamData data = {0};
129     const StreamData ext = {0};
130     const StreamFrameInfo param = {0};
131 
132     int ret = ClientTransChannelSendStream(channelId, CHANNEL_TYPE_UDP, nullptr, &ext, &param);
133     EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
134 
135     ret = ClientTransChannelSendStream(channelId, CHANNEL_TYPE_UDP, &data, &ext, &param);
136     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
137 
138     ret = ClientTransChannelSendStream(channelId, CHANNEL_TYPE_BUTT, &data, &ext, &param);
139     EXPECT_EQ(SOFTBUS_TRANS_CHANNEL_TYPE_INVALID, ret);
140 }
141 
142 /**
143  * @tc.name: ClientTransChannelSendFileTest001
144  * @tc.desc: client trans channel send file test, use the wrong or normal parameter.
145  * @tc.type: FUNC
146  * @tc.require:
147  */
148 HWTEST_F(ClientTransChannelManagerTest, ClientTransChannelSendFileTest001, TestSize.Level0)
149 {
150     int channelId = 1;
151     int fileCnt = 1;
152     const char *sFileList[] = { "/data/test.txt" };
153     const char *dFileList[] = { "/data/test.txt" };
154     int ret = ClientTransChannelSendFile(channelId, CHANNEL_TYPE_UDP, sFileList, dFileList, fileCnt);
155     EXPECT_EQ(SOFTBUS_TRANS_UDP_GET_CHANNEL_FAILED, ret);
156 
157     ret = ClientTransChannelSendFile(channelId, CHANNEL_TYPE_PROXY, sFileList, dFileList, fileCnt);
158     EXPECT_EQ(SOFTBUS_ERR, ret);
159 
160     ret = ClientTransChannelSendFile(channelId, CHANNEL_TYPE_BUTT, sFileList, dFileList, fileCnt);
161     EXPECT_EQ(SOFTBUS_TRANS_CHANNEL_TYPE_INVALID, ret);
162 }
163 } // namespace OHOS