1 /*
2 * Copyright (c) 2021 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
18 #include "SoftBus_Test_Permission.h"
19 #include "net_trans_common.h"
20 #include "wifi_utils.h"
21
22 using namespace testing::ext;
23
24 class TransFuncTest : public testing::Test {
25 public:
26 // 测试套前置和后置操作
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29
30 // 测试用例前置和后置操作
31 void SetUp();
32 void TearDown();
33 };
34
SetUp()35 void TransFuncTest::SetUp() {}
36
TearDown()37 void TransFuncTest::TearDown() {}
38
SetUpTestCase()39 void TransFuncTest::SetUpTestCase()
40 {
41 LOG("SetUp begin");
42 TestSetUp();
43 SoftBus_Test_Permission::AddPermission(DEF_PKG_NAME);
44
45 int ret = RegisterDeviceStateDefCallback();
46 EXPECT_EQ(SOFTBUS_OK, ret) << "call reg node state callback fail";
47 ret = CheckRemoteDeviceIsNull(BOOL_TRUE);
48 ASSERT_EQ(SOFTBUS_OK, ret) << "get node fail,please check network";
49
50 LOG("SetUp end");
51 }
52
TearDownTestCase()53 void TransFuncTest::TearDownTestCase()
54 {
55 int ret = UnRegisterDeviceStateDefCallback();
56 EXPECT_EQ(SOFTBUS_OK, ret) << "call unReg node state callback fail";
57
58 TestTearDown();
59 SoftBus_Test_Permission::RemovePermission(DEF_PKG_NAME);
60 }
61
62 /**
63 * @tc.number : SUB_Softbus_Trans_SendByte_Func_0100
64 * @tc.name : SendByte Packet size 1B, send and receive successful
65 * @tc.desc : Test the SendByte specification
66 * @tc.type : FUNC
67 * @tc.size : MediumTest
68 */
69 HWTEST_F(TransFuncTest, SUB_Softbus_Trans_SendByte_Func_0100, TestSize.Level3)
70 {
71 int ret;
72 ret = CreateSsAndOpenSession4Data();
73 ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
74
75 int size = 1;
76 ret = SendData4Data(DATA_TYPE_BYTE, size);
77 EXPECT_EQ(SOFTBUS_OK, ret) << "SendData4Data(byte, 1B) fail";
78
79 ret = CloseSessionAndRemoveSs4Data();
80 EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
81 }
82
83 /**
84 * @tc.number : SUB_Softbus_Trans_SendMessage_Func_0100
85 * @tc.name : SendMessage Packet size 1B, send and receive successful
86 * @tc.desc : Test the SendMessage specification
87 * @tc.type : FUNC
88 * @tc.size : MediumTest
89 */
90 HWTEST_F(TransFuncTest, SUB_Softbus_Trans_SendMessage_Func_0100, TestSize.Level3)
91 {
92 int ret;
93 ret = CreateSsAndOpenSession4Data();
94 ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
95
96 int size = 1;
97 ret = SendData4Data(DATA_TYPE_MSG, size);
98 EXPECT_EQ(SOFTBUS_OK, ret) << "SendData4Data(msg, 1B) fail";
99
100 ret = CloseSessionAndRemoveSs4Data();
101 EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
102 }
103