!13 【communication】dsoftbus软总线测试用例提交

Merge pull request !13 from Greada/kq0323
This commit is contained in:
openharmony_ci 2022-03-24 06:47:23 +00:00 committed by Gitee
commit 7ccf367664
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
16 changed files with 3513 additions and 1 deletions

27
communication/BUILD.gn Normal file
View File

@ -0,0 +1,27 @@
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos_var.gni")
group("communication") {
testonly = true
if (is_standard_system) {
deps = [
"softbus_standard/network:SoftBusNetTest",
"softbus_standard/transmission:SoftBusTransFileFunTest",
"softbus_standard/transmission:SoftBusTransFunTest",
"softbus_standard/transmission:SoftBusTransSessionFunTest",
]
} else {
deps = [ "wifi_standard:ActsWifiJSTest" ]
}
}

View File

@ -0,0 +1,79 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "SoftBus_Test_Permission.h"
#include "permission/permission.h"
#include "permission/permission_kit.h"
using namespace std;
using namespace OHOS::Security::Permission;
const static std::string SYSTEM_APP_PERMISSION =
"com.permission.MANAGE_DISTRIBUTED_PERMISSION";
const static std::string DANGER_APP_PERMISSION =
"ohos.permission.DISTRIBUTED_DATASYNC";
const static std::string BIND_DISCOVER_SERVICE =
"com.hwddmp.permission.BIND_DISCOVER_SERVICE";
const static std::string TEST_LABEL = "test label";
const static std::string TEST_DESCRIPTION = "test description";
const static int TEST_LABEL_ID = 9527;
const static int TEST_DESCRIPTION_ID = 9528;
void SoftBus_Test_Permission::AddPermission(const string& pkgName)
{
std::vector<PermissionDef> permDefList;
PermissionDef permissionDefAlpha = {.permissionName = SYSTEM_APP_PERMISSION,
.bundleName = pkgName,
.grantMode = GrantMode::SYSTEM_GRANT,
.availableScope = AVAILABLE_SCOPE_ALL,
.label = TEST_LABEL,
.labelId = TEST_LABEL_ID,
.description = TEST_DESCRIPTION,
.descriptionId = TEST_DESCRIPTION_ID};
PermissionDef permissionDefBeta = {.permissionName = DANGER_APP_PERMISSION,
.bundleName = pkgName,
.grantMode = GrantMode::SYSTEM_GRANT,
.availableScope = AVAILABLE_SCOPE_ALL,
.label = TEST_LABEL,
.labelId = TEST_LABEL_ID,
.description = TEST_DESCRIPTION,
.descriptionId = TEST_DESCRIPTION_ID};
PermissionDef permissionDefGamma = {.permissionName = BIND_DISCOVER_SERVICE,
.bundleName = pkgName,
.grantMode = GrantMode::SYSTEM_GRANT,
.availableScope = AVAILABLE_SCOPE_ALL,
.label = TEST_LABEL,
.labelId = TEST_LABEL_ID,
.description = TEST_DESCRIPTION,
.descriptionId = TEST_DESCRIPTION_ID};
permDefList.emplace_back(permissionDefAlpha);
permDefList.emplace_back(permissionDefBeta);
permDefList.emplace_back(permissionDefGamma);
PermissionKit::AddDefPermissions(permDefList);
std::vector<std::string> permList;
permList.push_back(SYSTEM_APP_PERMISSION);
permList.push_back(DANGER_APP_PERMISSION);
permList.push_back(BIND_DISCOVER_SERVICE);
PermissionKit::AddSystemGrantedReqPermissions(pkgName, permList);
PermissionKit::GrantSystemGrantedPermission(pkgName, SYSTEM_APP_PERMISSION);
PermissionKit::GrantSystemGrantedPermission(pkgName, DANGER_APP_PERMISSION);
PermissionKit::GrantSystemGrantedPermission(pkgName, BIND_DISCOVER_SERVICE);
}
void SoftBus_Test_Permission::RemovePermission(const string& pkgName)
{
PermissionKit::RemoveDefPermissions(pkgName);
PermissionKit::RemoveSystemGrantedReqPermissions(pkgName);
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_PERMISSION_H
#define TEST_PERMISSION_H
#include <string>
class SoftBus_Test_Permission {
public:
static void AddPermission(const std::string& pkgName);
static void RemovePermission(const std::string& pkgName);
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,279 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NET_TRANS_COMMON_H
#define NET_TRANS_COMMON_H
#include "common_list.h"
#include "discovery_service.h"
#include "session.h"
#include "softbus_bus_center.h"
#include "softbus_common.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_utils.h"
#include <pthread.h>
#include <securec.h>
#include <sys/time.h>
#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif
#define DEF_GROUP_ID "DEF_GROUP_ID"
#define DEF_SESSION_KEY "DEF_SESSION_KEY"
#define DEF_PKG_NAME "com.communication.demo1"
#define PKG_NAME_TWO "com.communication.demo2"
#define PKG_NAME_THREE "com.communication.demo3"
#define PKG_NAME_FOUR "com.communication.demo4"
#define SESSION_NAME_DATA "com.communication.demo1.data"
#define SESSION_NAME_CTL "com.communication.demo1.control"
#define SESSION_NAME_PASS "com.communication.demo1.passive"
#define SESSION_NAME_FAIL "com.communication.demo1.fail"
#define SESSION_NAME_PERF "com.communication.demo1.perf"
#define SESSION_NAME_PROXY "com.communication.demo1.proxy"
#define SESSION_NAME_FILE "com.communication.demo1.file"
#define DSOFT_PKG_NAME "com.plrdtest.dsoftbus"
#define SESSION_NAME_DSOFT_DATA "com.plrdtest.dsoftbus.data"
#define RECV_FILE_PATH "/data/"
#define CTRL_MSG_CLOSE_WIFI_THREE_SEC "close wifi 3sec"
#define CTRL_MSG_CLOSE_WIFI_TEN_MIN "close wifi 10min"
#define CTRL_MSG_CLOSE_WIFI_FIVE_MIN "close wifi 5min"
#define CTRL_MSG_CLOSE_WIFI_TEN_SEC "close wifi 10sec"
#define CTRL_MSG_CHANGE_WIFI_TEN_SEC "change wifi 10sec"
#define CTRL_MSG_CHANGE_WIFI_SIXTY_SEC "change wifi 60sec"
#define CTRL_MSG_CLOSE_WIFI_LOOP20 "close wifi loop 20"
#define CTRL_MSG_CHANGE_WIFI_LOOP20 "change wifi loop 20"
#define CTRL_MSG_CLOSE_WIFI_LOOP100 "close wifi loop 100"
#define CTRL_MSG_CHANGE_WIFI_LOOP100 "change wifi loop 100"
#define CTRL_MSG_OPEN_SESSION "open session"
#define CTRL_MSG_OPEN_SESSION_MSG "open session msg"
#define CTRL_MSG_OPEN_SESSION_NOT_EXIST "open session not exist"
#define CTRL_MSG_OPEN_SESSION_FAIL "open session fail"
#define CTRL_MSG_CLOSE_SESSION "close session"
#define CTRL_MSG_CLOSE_BR "close br"
#define CTRL_MSG_CLOSE_OPEN_BR "close-open br"
#define CTRL_MSG_CLOSE_AIR "close air"
#define CTRL_MSG_CLOSE_OPEN_AIR "close-open air"
#define CTRL_MSG_SEND_BIG_DATA "send big data"
#define WAIT_DEF_VALUE (-1)
#define WAIT_SUCCESS_VALUE 1
#define WAIT_FAIL_VALUE 0
#define SESSION_ID_MIN 1
#define MAX_SESSION_NUM 16
#define BOOL_TRUE 1
#define BOOL_FALSE 0
#define OPEN_SESSION_TIMEOUT 19
#define MULTI_REMOTE_DEV_COUNT 3
#define DEF_REMOTE_DEV_COUNT 1
#define SIZE_1K 1024
#define CMD_DOWN_ETH "ifconfig eth0 down"
#define CMD_CONFIG_ETH_WRONG_IP "ifconfig eth0 193.168.7.88 up"
#define CMD_CONFIG_ETH_RIGHT_IP "ifconfig eth0 192.168.3.88 up"
#define CMD_PIDOF_SOFTBUS "pidof softbus_server"
#define CMD_CONFIG_WLAN_WRONG_IP "ifconfig wlan0 193.168.3.88 up"
#define MAX_SESSION_SERVER_NUM_CLIENT 8
#define MAX_SESSION_SERVER_NUM_SERVER 32
#define TRANS_BYTES_LENGTH_MAX (4 * 1024 * 1024)
#define TRANS_MESSAGE_LENGTH_MAX 4096
#define TRANS_PROXY_BYTES_LENGTH_MAX (4 * 1024)
#define TRANS_PROXY_MESSAGE_LENGTH_MAX 1024
#define DEF_SEND_DATA_SID_COUNT 4
#define GROUP_ID_LEN 4
#define CASE_0 0
#define CASE_1 1
#define CASE_2 2
#define CASE_3 3
#define CASE_4 4
#define CASE_5 5
#define CASE_6 6
#define CASE_7 7
#define CASE_8 8
#define CASE_9 9
#define CASE_10 10
typedef enum {
SESSION_4DATA = 1,
SESSION_4CTL,
} WaitSessionType;
typedef enum {
DATA_TYPE_MSG = 1,
DATA_TYPE_BYTE,
} DataType;
typedef enum {
STATE_ONLINE = 1,
STATE_OFFLINE,
} WaitNodeStateType;
typedef enum {
CONC_CLOSE_SESSION = 1,
CONC_LEAVE_NET,
CONC_DIS_NET_RECOVERY,
CONC_DIS_NET_NOT_RECOVERY,
CONC_DOWN_NET,
CONC_SEND_DATA_ONLY,
CONC_CLOSE_SESSION_REMOTE,
} ConcurrentType;
typedef enum {
CTRL_CODE_CLOSE_WIFI_TEN_SEC = 1,
CTRL_CODE_CLOSE_WIFI_TEN_MIN,
CTRL_CODE_CLOSE_WIFI_FIVE_MIN,
CTRL_CODE_CLOSE_WIFI_THREE_SEC,
CTRL_CODE_CHANGE_WIFI_TEN_SEC,
CTRL_CODE_CHANGE_WIFI_SIXTY_SEC,
CTRL_CODE_CHANGE_WIFI_LOOP20,
CTRL_CODE_CLOSE_WIFI_LOOP20,
CTRL_CODE_CHANGE_WIFI_LOOP100,
CTRL_CODE_CLOSE_WIFI_LOOP100,
CTRL_CODE_OPEN_SESSION,
CTRL_CODE_OPEN_SESSION_MSG,
CTRL_CODE_OPEN_SESSION_FAIL,
CTRL_CODE_OPEN_SESSION_NOT_EXIST,
CTRL_CODE_CLOSE_SESSION,
CTRL_CODE_CLOSE_BR,
CTRL_CODE_CLOSE_OPEN_BR,
CTRL_CODE_CLOSE_AIR,
CTRL_CODE_CLOSE_OPEN_AIR,
CTRL_CODE_SEND_BIG_DATA,
} CtrlCodeType;
#define LOG(format, ...) \
do { \
time_t timeSec; \
time(&timeSec); \
struct tm tmRst; \
localtime_r(&timeSec, &tmRst); \
char strTime[10]; \
strftime(strTime, sizeof(strTime), "%H:%M:%S", &tmRst); \
fprintf(stdout, "[Test-softbus] %s " format "\n", strTime, \
##__VA_ARGS__); \
} while (0)
int Wait(int timeout);
int Wait4Session(int timeout, WaitSessionType type);
int WaitNodeCount(int timeout, WaitNodeStateType state, int expectCount);
void TestSetUp(void);
void TestTearDown(void);
int StartDiscoveryDevice(void);
int JoinNetwork(void);
int LeaveNetWork(void);
int RegisterDeviceStateDefCallback(void);
int UnRegisterDeviceStateDefCallback(void);
int DiscoverAndJoinNetwork(void);
int CheckRemoteDeviceIsNull(int isSetNetId);
int GetRemoteDeviceNetId(char** netId);
int SetCurrentNetworkId(int index);
int SetRemoteDeviceNetIdToGarray(void);
uint64_t GetCurrentTimeOfMs(void);
void ResetWaitFlag(void);
void ResetWaitFlag4Data(void);
void ResetWaitFlag4Ctl(void);
void ResetWaitCount4Offline(void);
void ResetWaitCount4Online(void);
int SendData4Data(DataType type, int size);
int SendCtrlMsgToRemote(CtrlCodeType code);
int CreateSsAndOpenSession4Data(void);
int CreateSsAndOpenSession4Ctl(void);
int OpenSession4Ctl(void);
int OpenSession4Data(void);
int OpenSessionBatch4Data(char groupId[][GROUP_ID_LEN],
int* sessionId,
int count);
int OpenSessionBatch4Ctl(char groupId[][GROUP_ID_LEN],
int* sessionId,
int count);
int CloseSessionBatch4Data(int* sessionId, int count);
int CloseSessionBatch4Ctl(int* sessionId, int count);
void* OpenSessionTask4Data(void* param);
void* OpenSessionTask4Ctl(void* param);
int OpenSession4Perf(void);
int OpenSession4PerfWithParam(const char* sessionName,
const char* groupId,
char* netId);
int SendData4Perf(int sessionId, char* dataMsg, char* dataByte);
void SetTransStartTime(void);
void* SendDataTask1(void* param);
void* SendDataTask2(void* param);
void* SendDataTask3(void* param);
char* GetSoftbusPid(void);
char* GetNetworkId(void);
int GetCurrentSessionId4Data(void);
int GetCurrentSessionId4Ctl(void);
void SetCurrentSessionId4Data(int sessionId);
void SetCurrentSessionId4Ctl(int sessionId);
ISessionListener* GetSessionListenser4Data(void);
ISessionListener* GetSessionListenser4Ctl(void);
ISessionListener* GetSessionListenser4Pass(void);
ISessionListener* GetSessionListenser4Perf(void);
ISessionListener* GetSessionListenser4Proxy(void);
SessionAttribute* GetSessionAttr4Pass(void);
SessionAttribute* GetSessionAttr4Ctl(void);
SessionAttribute* GetSessionAttr4Data(void);
SessionAttribute* GetSessionAttr4Perf(void);
SessionAttribute* GetSessionAttr4Proxy(void);
IFileReceiveListener* GetRecvFileListener(void);
IFileSendListener* GetSendFileListener(void);
pthread_barrier_t* GetThreadBarrier(void);
int GetThreadResult4Data(void);
int GetThreadResult4Ctl(void);
int* GetSid4Task2(void);
int* GetSid4Task3(void);
void ResetMsgStat4Control(void);
void ResetByteStat4Control(void);
ConnectionAddr* GetConnectAddr(void);
void ResetClosedSessionCount4Data(void);
void ResetClosedSessionCount4Ctrl(void);
int GetClosedSessionCount4Data(void);
int GetClosedSessionCount4Ctrl(void);
void ResetOpenSessionCount4Data(void);
void ResetOpenSessionCount4Ctrl(void);
int GetOpenSessionCount4Data(void);
int GetOpenSessionCount4Ctrl(void);
int CloseSessionAndRemoveSs4Data(void);
int CloseSessionAndRemoveSs4Ctl(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,295 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "wifi_utils.h"
#include <arpa/inet.h>
using std::unique_ptr;
using namespace OHOS::Wifi;
const static int WIFI_SA_ID = 1125;
const static int TWO_SECOND = 2;
const static int FIVE_SECOND = 5;
static char* const def_ssid = "OpenHarmony_Private_Net_01";
static unique_ptr<WifiDevice> wifiDevicePtr = WifiDevice::GetInstance(WIFI_SA_ID);
int WiFiUtils::EnableWifi()
{
bool isActive = false;
int ret = wifiDevicePtr->IsWifiActive(isActive);
if (ret != SOFTBUS_OK) {
LOG("[wifi]call IsWifiActive fail, ret:%d", ret);
}
if (!isActive) {
LOG("[wifi]not active, call enable...");
ret = wifiDevicePtr->EnableWifi();
if (ret != SOFTBUS_OK) {
LOG("[wifi]call EnableWifi fail, ret:%d", ret);
return SOFTBUS_ERR;
}
LOG("[wifi]call EnableWifi success, wait state active");
int timeout = 10;
do {
ret = wifiDevicePtr->IsWifiActive(isActive);
if (ret != SOFTBUS_OK) {
LOG("[wifi]call IsWifiActive fail, ret:%d", ret);
}
if (isActive) {
LOG("[wifi]is active, timeout:%d", timeout);
break;
}
sleep(FIVE_SECOND);
timeout--;
} while (timeout > 0);
if (timeout <= 0) {
LOG("[wifi]wait wifi state fail[timeout]");
return SOFTBUS_ERR;
} else {
LOG("[wifi]wait wifi state success");
return SOFTBUS_OK;
}
} else {
LOG("[wifi]is active, do nothing");
return SOFTBUS_OK;
}
}
int WiFiUtils::DisableWifi()
{
bool isActive = false;
int ret = wifiDevicePtr->IsWifiActive(isActive);
if (ret != SOFTBUS_OK) {
LOG("[wifi]call IsWifiActive fail, ret:%d", ret);
}
if (isActive) {
LOG("[wifi]is active, call disable...");
ret = wifiDevicePtr->DisableWifi();
if (ret != SOFTBUS_OK) {
LOG("[wifi]call DisableWifi fail, ret:%d", ret);
return SOFTBUS_ERR;
}
LOG("[wifi]call DisableWifi success, wait state active");
int timeout = 10;
do {
ret = wifiDevicePtr->IsWifiActive(isActive);
if (ret != SOFTBUS_OK) {
LOG("[wifi]call IsWifiActive fail, ret:%d", ret);
}
if (!isActive) {
LOG("[wifi]not active, timeout:%d", timeout);
break;
}
sleep(1);
timeout--;
} while (timeout > 0);
if (timeout <= 0) {
LOG("[wifi]wait wifi state fail[timeout]");
return SOFTBUS_ERR;
} else {
LOG("[wifi]wait wifi state success");
return SOFTBUS_OK;
}
} else {
LOG("[wifi]not active, do nothing");
return SOFTBUS_OK;
}
}
int WiFiUtils::DisableThenEnable(int delaySeconds)
{
int ret = DisableWifi();
if (ret != SOFTBUS_OK) {
LOG("[wifi]DisableWifi fail");
return ret;
}
sleep(delaySeconds);
ret = EnableWifi();
if (ret != SOFTBUS_OK) {
LOG("[wifi]EnableWifi fail");
}
return ret;
}
int WiFiUtils::CheckIsConnectToDefault(void)
{
WifiLinkedInfo linkInfo;
int ret = wifiDevicePtr->GetLinkedInfo(linkInfo);
if (ret != SOFTBUS_OK) {
LOG("[wifi]call GetLinkedInfo fail, ret:%d", ret);
} else {
char rstBuff[16];
struct in_addr inputAddr = {0};
inputAddr.s_addr = htonl(linkInfo.ipAddress);
inet_ntop(AF_INET, &inputAddr, rstBuff, sizeof(rstBuff));
LOG("[wifi]link info,netid:%d, ssid:%s, state:%d, ip:%u,%s",
linkInfo.networkId, linkInfo.ssid.c_str(), linkInfo.connState,
linkInfo.ipAddress, rstBuff);
if (strncmp(linkInfo.ssid.c_str(), def_ssid, strlen(def_ssid)) == 0) {
LOG("[wifi]check success");
return SOFTBUS_OK;
} else {
LOG("[wifi]check fail");
}
}
return SOFTBUS_ERR;
}
int WiFiUtils::ConnectTo(const std::string& ssid, const std::string& passwd)
{
WifiDeviceConfig deviceConfig;
deviceConfig.ssid = ssid;
deviceConfig.preSharedKey = passwd;
deviceConfig.keyMgmt = "WPA-PSK";
int netId;
int ret = wifiDevicePtr->AddDeviceConfig(deviceConfig, netId);
if (ret != SOFTBUS_OK) {
LOG("[wifi]call AddDeviceConfig fail, ret:%d", ret);
} else {
LOG("[wifi]call AddDeviceConfig success, netId:%d", netId);
}
ret = wifiDevicePtr->ConnectToNetwork(netId);
if (ret != SOFTBUS_OK) {
LOG("[wifi]call ConnectTo fail, ret:%d", ret);
return SOFTBUS_ERR;
} else {
LOG("[wifi]call ConnectTo success, netId:%d", netId);
}
int timeout = 10;
char rstBuff[16];
WifiLinkedInfo linkInfo;
struct in_addr inputAddr = {0};
while (timeout > 0) {
sleep(TWO_SECOND);
ret = wifiDevicePtr->GetLinkedInfo(linkInfo);
if (ret != SOFTBUS_OK) {
LOG("[wifi]call GetLinkedInfo fail, ret:%d", ret);
} else {
LOG("[wifi]call GetLinkedInfo success, now state:%d",
linkInfo.connState);
if (linkInfo.connState == ConnState::CONNECTED &&
linkInfo.ipAddress != 0) {
inputAddr.s_addr = htonl(linkInfo.ipAddress);
inet_ntop(AF_INET, &inputAddr, rstBuff, sizeof(rstBuff));
LOG("[wifi]state OK,netid:%d, ssid:%s, state:%d, ip:%u,%s",
linkInfo.networkId, linkInfo.ssid.c_str(),
linkInfo.connState, linkInfo.ipAddress, rstBuff);
break;
}
}
timeout -= TWO_SECOND;
}
if (timeout == 0) {
inputAddr.s_addr = htonl(linkInfo.ipAddress);
inet_ntop(AF_INET, &inputAddr, rstBuff, sizeof(rstBuff));
LOG("[wifi]state(timeout=0),netid:%d, ssid:%s, state:%d, ip:%u,%s",
linkInfo.networkId, linkInfo.ssid.c_str(), linkInfo.connState,
linkInfo.ipAddress, rstBuff);
}
return SOFTBUS_OK;
}
int WiFiUtils::ConnectToNew(const std::string& ssid,
const std::string& passwd)
{
int ret = wifiDevicePtr->Disconnect();
LOG("[wifi]call Disconnect ret:%d", ret);
ret = ConnectTo(ssid, passwd);
return ret;
}
int WiFiUtils::ConnectToOpenAP(const std::string& ssid)
{
WifiDeviceConfig deviceConfig;
deviceConfig.ssid = ssid;
deviceConfig.keyMgmt = "NONE";
int netId;
int ret = wifiDevicePtr->AddDeviceConfig(deviceConfig, netId);
if (ret != SOFTBUS_OK) {
LOG("[wifi]call AddDeviceConfig fail, ret:%d", ret);
} else {
LOG("[wifi]call AddDeviceConfig success, netId:%d", netId);
}
ret = wifiDevicePtr->ConnectToNetwork(netId);
if (ret != SOFTBUS_OK) {
LOG("[wifi]call ConnectTo fail, ret:%d", ret);
return SOFTBUS_ERR;
} else {
LOG("[wifi]call ConnectTo success, netId:%d", netId);
}
sleep(FIVE_SECOND);
int state;
ret = wifiDevicePtr->GetWifiState(state);
LOG("[wifi]call GetWifiState ret:%d,state:%d", ret, state);
WifiLinkedInfo linkInfo;
ret = wifiDevicePtr->GetLinkedInfo(linkInfo);
if (ret != SOFTBUS_OK) {
LOG("[wifi]call GetLinkedInfo fail, ret:%d", ret);
} else {
LOG("[wifi]call GetLinkedInfo success");
char rstBuff[16];
struct in_addr inputAddr = {0};
inputAddr.s_addr = htonl(linkInfo.ipAddress);
inet_ntop(AF_INET, &inputAddr, rstBuff, sizeof(rstBuff));
LOG("[wifi]link info,netid:%d, ssid:%s, state:%d, ip:%u,%s",
linkInfo.networkId, linkInfo.ssid.c_str(), linkInfo.connState,
linkInfo.ipAddress, rstBuff);
}
return SOFTBUS_OK;
}
int WiFiUtils::EnableThenConnect(const std::string& ssid,
const std::string& passwd)
{
int ret = EnableWifi();
if (ret != SOFTBUS_OK) {
LOG("[wifi]EnableWifi fail");
return ret;
}
ret = ConnectTo(ssid, passwd);
if (ret != SOFTBUS_OK) {
LOG("[wifi]ConnectTo fail");
}
return ret;
}
int WiFiUtils::DisableThenEnableAndConnect(int delaySeconds,
const std::string& ssid,
const std::string& passwd)
{
int ret = DisableWifi();
if (ret != SOFTBUS_OK) {
LOG("[wifi]DisableWifi fail");
return ret;
}
sleep(delaySeconds);
ret = EnableWifi();
if (ret != SOFTBUS_OK) {
LOG("[wifi]EnableWifi fail");
return ret;
}
ret = ConnectTo(ssid, passwd);
if (ret != SOFTBUS_OK) {
LOG("[wifi]ConnectTo fail");
}
return ret;
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_WIFI_UTILS_H
#define TEST_WIFI_UTILS_H
#include "net_trans_common.h"
#include "wifi_device.h"
class WiFiUtils {
public:
static int EnableWifi();
static int DisableWifi();
static int DisableThenEnable(int delaySeconds);
static int ConnectTo(const std::string& ssid, const std::string& passwd);
static int ConnectToNew(const std::string& ssid, const std::string& passwd);
static int ConnectToOpenAP(const std::string& ssid);
static int EnableThenConnect(const std::string& ssid,
const std::string& passwd);
static int DisableThenEnableAndConnect(int delaySeconds,
const std::string& ssid,
const std::string& passwd);
static int CheckIsConnectToDefault(void);
};
#endif

View File

@ -0,0 +1,50 @@
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "dct/softbus_base/SoftBusNetTest"
ohos_moduletest_suite("SoftBusNetTest") {
module_out_path = module_output_path
sources = [
"../common/SoftBus_Test_Permission.cpp",
"../common/net_trans_common.c",
"../common/wifi_utils.cpp",
"src/Net_Bindself_Func_Test.cpp",
]
include_dirs = [
"../common",
"//third_party/cJSON",
"//utils/native/base/include",
"//foundation/communication/dsoftbus/core/common/include",
"//foundation/communication/dsoftbus/adapter/common/include",
"//foundation/communication/dsoftbus/interfaces/kits/common",
"//foundation/communication/dsoftbus/interfaces/kits/bus_center",
"//foundation/communication/dsoftbus/interfaces/kits/discovery",
"//foundation/communication/dsoftbus/interfaces/kits/transport",
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include",
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/include",
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/interfaces",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/net_helper",
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/log",
]
deps = [
#"//foundation/communication/dsoftbus/core/frame/standard/client:softbus_client",
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard",
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard:wifi_sdk",
"//third_party/googletest:gtest_main",
]
external_deps = [ "dsoftbus_standard:softbus_client" ]
}

View File

@ -0,0 +1,21 @@
{
"kits": [
{
"push": [
"SoftBusTransFunTest ->/data/local/tmp/SoftBusTransFunTest"
],
"temp": "PushKit",
"post-push": [
"chmod -R 777 /data/local/tmp/*"
]
}
],
"dirver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "SoftBusTransFunTest",
"runtime-hint": "ls",
"native-test-device-path": "/data/local/tmp/"
},
"description": "configuration for SoftBusTransFunTest Tests"
}

View File

@ -0,0 +1,210 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "net_trans_common.h"
#include "SoftBus_Test_Permission.h"
#include "wifi_utils.h"
using namespace testing::ext;
const static int TEN_SECOND = 10;
class Net_Bindself_Func_Test : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void Net_Bindself_Func_Test::SetUp() {}
void Net_Bindself_Func_Test::TearDown() {}
void Net_Bindself_Func_Test::SetUpTestCase()
{
LOG("[SetUp] begin");
TestSetUp();
SoftBus_Test_Permission::AddPermission(DEF_PKG_NAME);
int ret = RegisterDeviceStateDefCallback();
EXPECT_EQ(SOFTBUS_OK, ret) << "call reg node state callback fail";
LOG("[SetUp] end");
}
void Net_Bindself_Func_Test::TearDownTestCase()
{
int ret = UnRegisterDeviceStateDefCallback();
EXPECT_EQ(SOFTBUS_OK, ret) << "call unReg node state callback fail";
TestTearDown();
SoftBus_Test_Permission::RemovePermission(DEF_PKG_NAME);
}
static void WaitOnly(int seconds)
{
if (seconds < TEN_SECOND) {
sleep(seconds);
} else {
while (seconds > 0) {
sleep(TEN_SECOND);
seconds -= TEN_SECOND;
LOG("###wait:%d", seconds);
}
}
}
/**
* @tc.number : SUB_Softbus_Net_Bind_Func_0100
* @tc.name : get net id
* @tc.desc : Test networking function
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(Net_Bindself_Func_Test,
SUB_Softbus_Net_Bind_Func_0100,
TestSize.Level3)
{
char* netId = NULL;
int count = GetRemoteDeviceNetId(&netId);
LOG("GetRemoteDeviceNetId count:%d", count);
if (count > 0) {
for (int i = 0; i < count; i++) {
LOG("GetRemoteDeviceNetId id:%s", *(&netId + i));
}
free(netId);
}
}
/**
* @tc.number : SUB_Softbus_Net_Bind_Func_0200
* @tc.name : discovery device
* @tc.desc : Test networking function
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(Net_Bindself_Func_Test,
SUB_Softbus_Net_Bind_Func_0200,
TestSize.Level3)
{
int ret = StartDiscoveryDevice();
EXPECT_EQ(SOFTBUS_OK, ret) << "Discover fail";
}
/**
* @tc.number : SUB_Softbus_Net_Bind_Func_0300
* @tc.name : check node
* @tc.desc : Test networking function
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(Net_Bindself_Func_Test,
SUB_Softbus_Net_Bind_Func_0300,
TestSize.Level3)
{
int ret = CheckRemoteDeviceIsNull(BOOL_FALSE);
EXPECT_EQ(SOFTBUS_OK, ret) << "check node fail";
}
/**
* @tc.number : SUB_Softbus_Net_Bind_Func_0400
* @tc.name : check node multi
* @tc.desc : Test networking function
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(Net_Bindself_Func_Test,
SUB_Softbus_Net_Bind_Func_0400,
TestSize.Level3)
{
int nodeCount = SetRemoteDeviceNetIdToGarray();
LOG("######node count:%d", nodeCount);
EXPECT_TRUE(nodeCount >= DEF_REMOTE_DEV_COUNT)
<< "check node fail, count:" << nodeCount;
}
/**
* @tc.number : SUB_Softbus_Net_Bind_Func_0500
* @tc.name : check node and senddata
* @tc.desc : Test networking function
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(Net_Bindself_Func_Test,
SUB_Softbus_Net_Bind_Func_0500,
TestSize.Level3)
{
int ret = CheckRemoteDeviceIsNull(BOOL_TRUE);
EXPECT_EQ(SOFTBUS_OK, ret) << "check node fail";
ret = CreateSsAndOpenSession4Ctl();
EXPECT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[ctrl] fail";
ret = CreateSsAndOpenSession4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
int dataLen = 888;
int sessionId = GetCurrentSessionId4Ctl();
char* sendData = (char*)malloc(dataLen);
ASSERT_TRUE(sendData != NULL);
(void)memset_s(sendData, dataLen, 'C', dataLen);
ret = SendBytes(sessionId, sendData, dataLen);
EXPECT_EQ(SOFTBUS_OK, ret) << "SendBytes[ctrl] fail";
ret = SendMessage(sessionId, sendData, dataLen);
EXPECT_EQ(SOFTBUS_OK, ret) << "SendMessage[ctrl] fail";
ret = SendData4Data(DATA_TYPE_BYTE, dataLen);
EXPECT_EQ(SOFTBUS_OK, ret) << "SendData4Data(byte) fail";
ret = SendData4Data(DATA_TYPE_MSG, dataLen);
EXPECT_EQ(SOFTBUS_OK, ret) << "SendData4Data(msg) fail";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "close and remove[data] fail";
ret = CloseSessionAndRemoveSs4Ctl();
EXPECT_EQ(SOFTBUS_OK, ret) << "close and remove[ctrl] fail";
free(sendData);
}
/**
* @tc.number : SUB_Softbus_Net_Bind_Func_0600
* @tc.name : jion network and leve network
* @tc.desc : Test networking function
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(Net_Bindself_Func_Test,
SUB_Softbus_Net_Bind_Func_0600,
TestSize.Level2)
{
int ret;
int size = 1024;
ret = LeaveNetWork();
EXPECT_EQ(SOFTBUS_OK, ret) << "LeaveNetWork fail";
WaitOnly(10);
ret = JoinNetwork();
EXPECT_EQ(SOFTBUS_OK, ret) << "JoinNetwork fail";
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
ret = SendData4Data(DATA_TYPE_BYTE, size);
EXPECT_EQ(SOFTBUS_OK, ret) << "SendData4Data(byte,1K) fail";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
ret = LeaveNetWork();
EXPECT_EQ(SOFTBUS_OK, ret) << "LeaveNetWork fail";
WaitOnly(20);
ret = JoinNetwork();
EXPECT_EQ(SOFTBUS_OK, ret) << "JoinNetwork fail";
}

View File

@ -0,0 +1,122 @@
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "dct/softbus_base/SoftBusTransTest"
ohos_moduletest_suite("SoftBusTransFunTest") {
module_out_path = module_output_path
sources = [
"../common/SoftBus_Test_Permission.cpp",
"../common/net_trans_common.c",
"../common/wifi_utils.cpp",
"src/trans_func_test.cpp",
]
include_dirs = [
"../common",
"//third_party/cJSON",
"//utils/native/base/include",
"//foundation/communication/dsoftbus/core/common/include",
"//foundation/communication/dsoftbus/adapter/common/include",
"//foundation/communication/dsoftbus/interfaces/kits/common",
"//foundation/communication/dsoftbus/interfaces/kits/bus_center",
"//foundation/communication/dsoftbus/interfaces/kits/discovery",
"//foundation/communication/dsoftbus/interfaces/kits/transport",
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include",
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/include",
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/interfaces",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/net_helper",
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/log",
]
deps = [
#"//foundation/communication/dsoftbus/core/frame/standard/client:softbus_client",
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard",
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard:wifi_sdk",
"//third_party/googletest:gtest_main",
]
external_deps = [ "dsoftbus_standard:softbus_client" ]
}
ohos_moduletest_suite("SoftBusTransSessionFunTest") {
module_out_path = module_output_path
sources = [
"../common/SoftBus_Test_Permission.cpp",
"../common/net_trans_common.c",
"../common/wifi_utils.cpp",
"src/trans_session_func_test.cpp",
]
include_dirs = [
"../common",
"//third_party/cJSON",
"//utils/native/base/include",
"//foundation/communication/dsoftbus/core/common/include",
"//foundation/communication/dsoftbus/adapter/common/include",
"//foundation/communication/dsoftbus/interfaces/kits/common",
"//foundation/communication/dsoftbus/interfaces/kits/bus_center",
"//foundation/communication/dsoftbus/interfaces/kits/discovery",
"//foundation/communication/dsoftbus/interfaces/kits/transport",
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include",
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/include",
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/interfaces",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/net_helper",
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/log",
]
deps = [
#"//foundation/communication/dsoftbus/core/frame/standard/client:softbus_client",
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard",
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard:wifi_sdk",
"//third_party/googletest:gtest_main",
]
external_deps = [ "dsoftbus_standard:softbus_client" ]
}
ohos_moduletest_suite("SoftBusTransFileFunTest") {
module_out_path = module_output_path
sources = [
"../common/SoftBus_Test_Permission.cpp",
"../common/net_trans_common.c",
"../common/wifi_utils.cpp",
"src/trans_file_func_test.cpp",
]
include_dirs = [
"../common",
"//third_party/cJSON",
"//utils/native/base/include",
"//foundation/communication/dsoftbus/core/common/include",
"//foundation/communication/dsoftbus/adapter/common/include",
"//foundation/communication/dsoftbus/interfaces/kits/common",
"//foundation/communication/dsoftbus/interfaces/kits/bus_center",
"//foundation/communication/dsoftbus/interfaces/kits/discovery",
"//foundation/communication/dsoftbus/interfaces/kits/transport",
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include",
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/include",
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard/interfaces",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/net_helper",
"//foundation/communication/wifi/services/wifi_standard/wifi_framework/common/log",
]
deps = [
#"//foundation/communication/dsoftbus/core/frame/standard/client:softbus_client",
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard",
"//foundation/communication/wifi/interfaces/innerkits/native_cpp/wifi_standard:wifi_sdk",
"//third_party/googletest:gtest_main",
]
external_deps = [ "dsoftbus_standard:softbus_client" ]
}

View File

@ -0,0 +1,21 @@
{
"kits": [
{
"push": [
"SoftBusTransFunTest ->/data/local/tmp/SoftBusTransFunTest"
],
"temp": "PushKit",
"post-push": [
"chmod -R 777 /data/local/tmp/*"
]
}
],
"dirver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "SoftBusTransFunTest",
"runtime-hint": "ls",
"native-test-device-path": "/data/local/tmp/"
},
"description": "configuration for SoftBusTransFunTest Tests"
}

View File

@ -0,0 +1,184 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "net_trans_common.h"
#include "SoftBus_Test_Permission.h"
#include "wifi_utils.h"
static int g_waitFlag = WAIT_DEF_VALUE;
static int FileSessionOpened(int sessionId, int result)
{
LOG("[cb][file]open session sid[%d],rst[%d]", sessionId, result);
if (result == SOFTBUS_OK) {
g_waitFlag = WAIT_SUCCESS_VALUE;
} else {
g_waitFlag = WAIT_FAIL_VALUE;
}
return SOFTBUS_OK;
}
static void FileSessionClosed(int sessionId)
{
LOG("[cb][file]close session sid[%d]", sessionId);
}
static void FileBytesReceived(int sessionId,
const void* data,
unsigned int dataLen)
{
LOG("[cb][file]ByteRec sid:%d, data len:%d", sessionId, dataLen);
if (data == NULL) {
LOG("[cb][file]ByteRec invalid data=null sid[%d]", sessionId);
g_waitFlag = WAIT_FAIL_VALUE;
} else {
g_waitFlag = WAIT_SUCCESS_VALUE;
}
}
static void FileMessageReceived(int sessionId,
const void* data,
unsigned int dataLen)
{
LOG("[cb][file]MessageRec sid:%d, data len:%d", sessionId, dataLen);
if (data == NULL) {
LOG("[cb][file]MessageRec invalid data=null sid[%d]", sessionId);
g_waitFlag = WAIT_FAIL_VALUE;
} else {
g_waitFlag = WAIT_SUCCESS_VALUE;
}
}
static SessionAttribute g_fileSessionAttr = {
.dataType = TYPE_FILE,
};
static ISessionListener g_fileSessionListener = {
.OnSessionOpened = FileSessionOpened,
.OnSessionClosed = FileSessionClosed,
.OnBytesReceived = FileBytesReceived,
.OnMessageReceived = FileMessageReceived,
};
static const char* g_fileOne[] = {
"/data/SoftBusNetTest_BindSelf_1.xml",
};
using namespace testing::ext;
class TransFileFuncTest : public testing::Test {
public:
// 测试套前置和后置操作
static void SetUpTestCase();
static void TearDownTestCase();
// 测试用例前置和后置操作
void SetUp();
void TearDown();
};
void TransFileFuncTest::SetUp() {}
void TransFileFuncTest::TearDown() {}
void TransFileFuncTest::SetUpTestCase()
{
LOG("SetUp begin");
TestSetUp();
SoftBus_Test_Permission::AddPermission(DEF_PKG_NAME);
int ret = RegisterDeviceStateDefCallback();
EXPECT_EQ(SOFTBUS_OK, ret) << "call reg node state callback fail";
ret = CheckRemoteDeviceIsNull(BOOL_TRUE);
ASSERT_EQ(SOFTBUS_OK, ret) << "get node fail,please check network";
// set listener
ret = SetFileSendListener(DEF_PKG_NAME, SESSION_NAME_FILE,
GetSendFileListener());
EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
ret = SetFileReceiveListener(DEF_PKG_NAME, SESSION_NAME_FILE,
GetRecvFileListener(), RECV_FILE_PATH);
EXPECT_EQ(SOFTBUS_OK, ret) << "call SetFileSendListener fail";
LOG("SetUp end");
}
void TransFileFuncTest::TearDownTestCase()
{
int ret = UnRegisterDeviceStateDefCallback();
EXPECT_EQ(SOFTBUS_OK, ret) << "call unReg node state callback fail";
TestTearDown();
SoftBus_Test_Permission::RemovePermission(DEF_PKG_NAME);
}
static int WaitFile(int timeout)
{
LOG("start waitfile,timeout:%d", timeout);
int count = 0;
int t = timeout;
while (t > 0) {
sleep(1);
if (g_waitFlag != WAIT_DEF_VALUE) {
LOG("waitfile success[flag:%d][time:%d]", g_waitFlag, count);
break;
}
t--;
count++;
}
if (g_waitFlag != WAIT_SUCCESS_VALUE) {
LOG("waitfile fail[exp:%d, real:%d][used time:%d]", WAIT_SUCCESS_VALUE,
g_waitFlag, count);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
/**
* @tc.number : SUB_Softbus_Trans_SendFile_Func_0100
* @tc.name : test SendFile
* @tc.desc : Test send file function
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransFileFuncTest,
SUB_Softbus_Trans_SendFile_Func_0100,
TestSize.Level2)
{
int ret;
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE,
&g_fileSessionListener);
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[file] fail";
g_waitFlag = WAIT_DEF_VALUE;
int sid = OpenSession(SESSION_NAME_FILE, SESSION_NAME_FILE, GetNetworkId(),
DEF_GROUP_ID, &g_fileSessionAttr);
EXPECT_TRUE(sid >= SESSION_ID_MIN)
<< "call OpenSession[file] fail, sid=" << sid;
if (sid >= SESSION_ID_MIN) {
ret = WaitFile(10);
EXPECT_EQ(SOFTBUS_OK, ret) << "wait opensession fail[file]";
}
ResetWaitFlag();
ret = SendFile(sid, g_fileOne, NULL, 1);
EXPECT_EQ(SOFTBUS_OK, ret) << "call SendFile fail";
ret = Wait(10);
EXPECT_EQ(SOFTBUS_OK, ret) << "wait send fail rst fail";
CloseSession(sid);
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_FILE);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[proxy] fail";
}

View File

@ -0,0 +1,105 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "net_trans_common.h"
#include "SoftBus_Test_Permission.h"
#include "wifi_utils.h"
using namespace testing::ext;
class TransFuncTest : public testing::Test {
public:
// 测试套前置和后置操作
static void SetUpTestCase();
static void TearDownTestCase();
// 测试用例前置和后置操作
void SetUp();
void TearDown();
};
void TransFuncTest::SetUp() {}
void TransFuncTest::TearDown() {}
void TransFuncTest::SetUpTestCase()
{
LOG("SetUp begin");
TestSetUp();
SoftBus_Test_Permission::AddPermission(DEF_PKG_NAME);
int ret = RegisterDeviceStateDefCallback();
EXPECT_EQ(SOFTBUS_OK, ret) << "call reg node state callback fail";
ret = WiFiUtils::CheckIsConnectToDefault();
ASSERT_EQ(SOFTBUS_OK, ret) << "connect to default failed";
ret = CheckRemoteDeviceIsNull(BOOL_TRUE);
ASSERT_EQ(SOFTBUS_OK, ret) << "get node fail,please check network";
LOG("SetUp end");
}
void TransFuncTest::TearDownTestCase()
{
int ret = UnRegisterDeviceStateDefCallback();
EXPECT_EQ(SOFTBUS_OK, ret) << "call unReg node state callback fail";
TestTearDown();
SoftBus_Test_Permission::RemovePermission(DEF_PKG_NAME);
}
/**
* @tc.number : SUB_Softbus_Trans_SendByte_Func_0100
* @tc.name : SendByte Packet size 1B, send and receive successful
* @tc.desc : Test the SendByte specification
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransFuncTest, SUB_Softbus_Trans_SendByte_Func_0100, TestSize.Level3)
{
int ret;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
int size = 1;
ret = SendData4Data(DATA_TYPE_BYTE, size);
EXPECT_EQ(SOFTBUS_OK, ret) << "SendData4Data(byte, 1B) fail";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
}
/**
* @tc.number : SUB_Softbus_Trans_SendMessage_Func_0100
* @tc.name : SendMessage Packet size 1B, send and receive successful
* @tc.desc : Test the SendMessage specification
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransFuncTest,
SUB_Softbus_Trans_SendMessage_Func_0100,
TestSize.Level3)
{
int ret;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
int size = 1;
ret = SendData4Data(DATA_TYPE_MSG, size);
EXPECT_EQ(SOFTBUS_OK, ret) << "SendData4Data(msg, 1B) fail";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
}

View File

@ -0,0 +1,212 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "net_trans_common.h"
#include "SoftBus_Test_Permission.h"
#include "wifi_utils.h"
using namespace testing::ext;
class TransSessionFuncTest : public testing::Test {
public:
// 测试套前置和后置操作
static void SetUpTestCase();
static void TearDownTestCase();
// 测试用例前置和后置操作
void SetUp();
void TearDown();
};
void TransSessionFuncTest::SetUp() {}
void TransSessionFuncTest::TearDown() {}
void TransSessionFuncTest::SetUpTestCase()
{
LOG("SetUp begin");
TestSetUp();
SoftBus_Test_Permission::AddPermission(DEF_PKG_NAME);
SoftBus_Test_Permission::AddPermission(PKG_NAME_TWO);
SoftBus_Test_Permission::AddPermission(PKG_NAME_THREE);
int ret = RegisterDeviceStateDefCallback();
EXPECT_EQ(SOFTBUS_OK, ret) << "call reg node state callback fail";
ret = WiFiUtils::CheckIsConnectToDefault();
ASSERT_EQ(SOFTBUS_OK, ret) << "connect to default failed";
ret = CheckRemoteDeviceIsNull(BOOL_TRUE);
ASSERT_EQ(SOFTBUS_OK, ret) << "get node fail,please check network";
LOG("SetUp end");
}
void TransSessionFuncTest::TearDownTestCase()
{
int ret = UnRegisterDeviceStateDefCallback();
EXPECT_EQ(SOFTBUS_OK, ret) << "call unReg node state callback fail";
TestTearDown();
SoftBus_Test_Permission::RemovePermission(DEF_PKG_NAME);
SoftBus_Test_Permission::RemovePermission(PKG_NAME_TWO);
SoftBus_Test_Permission::RemovePermission(PKG_NAME_THREE);
}
/**
* @tc.number : SUB_Softbus_Trans_Session_Func_0100
* @tc.name : one Client creates SessionServer + 1, Max succeeds, 1
* fails
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransSessionFuncTest,
SUB_Softbus_Trans_Session_Func_0100,
TestSize.Level3)
{
int ret;
char sessionNames[][SESSION_NAME_SIZE_MAX] = {
"com.communication.demo1.1", "com.communication.demo1.2",
"com.communication.demo1.3", "com.communication.demo1.4",
"com.communication.demo1.5", "com.communication.demo1.6",
"com.communication.demo1.7", "com.communication.demo1.8"};
for (int i = 0; i < MAX_SESSION_SERVER_NUM_CLIENT; i++) {
ret = CreateSessionServer(DEF_PKG_NAME, sessionNames[i],
GetSessionListenser4Data());
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS fail,i=" << i;
}
string sessionName = "max+1";
ret = CreateSessionServer(DEF_PKG_NAME, sessionName.c_str(),
GetSessionListenser4Data());
printf("CreateSS max+1, ret:%d \n", ret);
EXPECT_NE(SOFTBUS_OK, ret) << "CreateSS max+1 success, expect fail";
for (int i = 0; i < MAX_SESSION_SERVER_NUM_CLIENT; i++) {
ret = RemoveSessionServer(DEF_PKG_NAME, sessionNames[i]);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS fail,i=" << i;
}
ret = RemoveSessionServer(DEF_PKG_NAME, sessionName.c_str());
printf("RemoveSS max+1, ret:%d \n", ret);
EXPECT_NE(SOFTBUS_OK, ret) << "RemoveSS max+1 success, expect fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Session_Func_0200
* @tc.name : OpenSession + 1, Max succeeds, 1 fails
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransSessionFuncTest,
SUB_Softbus_Trans_Session_Func_0200,
TestSize.Level3)
{
int ret;
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA,
GetSessionListenser4Data());
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[data] fail";
ret = CreateSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL,
GetSessionListenser4Ctl());
EXPECT_EQ(SOFTBUS_OK, ret) << "CreateSS[ctrl] fail";
int count = MAX_SESSION_NUM / 2;
int sessionId4Data[count];
int sessionId4Ctrl[count];
char groupId[][4] = {"g1", "g2", "g3", "g4",
"g5", "g6", "g7", "g8"};
ret = OpenSessionBatch4Data(groupId, sessionId4Data, count);
EXPECT_EQ(SOFTBUS_OK, ret) << "OpenSessionWithDiffGroupId4Data fail";
ret = OpenSessionBatch4Ctl(groupId, sessionId4Ctrl, count);
EXPECT_EQ(SOFTBUS_OK, ret) << "OpenSessionWithDiffGroupId4Ctl fail";
// open max+1, expect fail
int sessionId;
sessionId =
OpenSession(SESSION_NAME_DATA, SESSION_NAME_DATA, GetNetworkId(),
DEF_GROUP_ID, GetSessionAttr4Data());
EXPECT_FALSE(sessionId >= SESSION_ID_MIN)
<< "call OpenSession[data] fail,sid=" << sessionId;
// close session
ret = CloseSessionBatch4Data(sessionId4Data, count);
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionBatch4Data fail";
ret = CloseSessionBatch4Ctl(sessionId4Ctrl, count);
EXPECT_EQ(SOFTBUS_OK, ret) << "CloseSessionBatch4Ctl fail";
// remove session server
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_DATA);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[data] fail";
ret = RemoveSessionServer(DEF_PKG_NAME, SESSION_NAME_CTL);
EXPECT_EQ(SOFTBUS_OK, ret) << "RemoveSS[ctrl] fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Session_Func_0300
* @tc.name : Obtain DevicedName based on Sessionid
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransSessionFuncTest,
SUB_Softbus_Trans_Session_Func_0300,
TestSize.Level3)
{
int ret;
ret = CreateSsAndOpenSession4Data();
ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[data] fail";
int sessionId = GetCurrentSessionId4Data();
char mySessionName[SESSION_NAME_SIZE_MAX] = {0};
ret = GetMySessionName(sessionId, mySessionName, SESSION_NAME_SIZE_MAX);
EXPECT_EQ(SOFTBUS_OK, ret)
<< "call GetMySessionName fail, sid:" << sessionId;
EXPECT_STREQ(SESSION_NAME_DATA, mySessionName)
<< "my session name cmp fail";
char peerSessionName[SESSION_NAME_SIZE_MAX] = {0};
ret = GetPeerSessionName(sessionId, peerSessionName, SESSION_NAME_SIZE_MAX);
EXPECT_EQ(SOFTBUS_OK, ret) << "call GetPeerSessionName fail";
EXPECT_STREQ(SESSION_NAME_DATA, peerSessionName)
<< "peer session name cmp fail";
ret = CloseSessionAndRemoveSs4Data();
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
}
/**
* @tc.number : SUB_Softbus_Trans_Session_Func_0400
* @tc.name : Obtain DevicedId based on Sessionid
* @tc.desc : Test session management
* @tc.type : FUNC
* @tc.size : MediumTest
*/
HWTEST_F(TransSessionFuncTest,
SUB_Softbus_Trans_Session_Func_0400,
TestSize.Level3)
{
int ret;
ret = CreateSsAndOpenSession4Ctl();
ASSERT_EQ(SOFTBUS_OK, ret) << "create Ss and openS[ctl] fail";
char deviceId[SESSION_NAME_SIZE_MAX] = {0};
ret = GetPeerDeviceId(GetCurrentSessionId4Ctl(), deviceId,
SESSION_NAME_SIZE_MAX);
EXPECT_EQ(SOFTBUS_OK, ret) << "call GetPeerDeviceId fail";
EXPECT_STREQ(GetNetworkId(), deviceId) << "peer device id cmp fail";
ret = CloseSessionAndRemoveSs4Ctl();
EXPECT_EQ(SOFTBUS_OK, ret) << "close session and remove Ss fail";
}

View File

@ -15,7 +15,7 @@ import("//test/xts/tools/build/suite.gni")
_all_test_packages = [
"${DCTS_ROOT}/distributeddatamgr:distributeddatatest",
#"${DCTS_ROOT}/distributedschedule:distributedschetest",
"${DCTS_ROOT}/communication:communication",
]
_all_test_packages_ivi = [