增加dsoftbus UT用例覆盖

Signed-off-by: gaoxiangyu <gaoxiangyu@kaihong.com>
This commit is contained in:
gaoxiangyu 2024-09-14 09:54:30 +08:00
parent 2ff842edae
commit 9a559dbfcd
6 changed files with 48 additions and 57 deletions

View File

@ -265,30 +265,37 @@ HWTEST_F(ServiceConnectionTest, ClientConnection002, TestSize.Level1)
HWTEST_F(ServiceConnectionTest, ClientConnection003, TestSize.Level1)
{
int32_t ret;
ConnBleConnection connection;
ConnectBlePriority priority;
int32_t underlayerHandle = 1;
const char *bleMac = "11:22:33:44:55:66";
ConnBleConnection *connection =
ConnBleCreateConnection(bleMac, BLE_GATT, CONN_SIDE_CLIENT, underlayerHandle, false);
ASSERT_NE(nullptr, connection);
NiceMock<ConnectionBleInterfaceMock> bleMock;
priority = CONN_BLE_PRIORITY_BALANCED;
ret = ConnGattClientUpdatePriority(NULL, priority);
EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
connection.underlayerHandle = 1;
connection.connectionId = 1;
connection.state = BLE_CONNECTION_STATE_CONNECTING;
SoftBusMutexInit(&connection.lock, nullptr);
ret = ConnGattClientUpdatePriority(&connection, priority);
connection->connectionId = 1;
connection->state = BLE_CONNECTION_STATE_CONNECTING;
ret = ConnGattClientUpdatePriority(connection, priority);
EXPECT_EQ(SOFTBUS_CONN_BLE_INTERNAL_ERR, ret);
connection.state = BLE_CONNECTION_STATE_SERVICE_SEARCHING;
connection->state = BLE_CONNECTION_STATE_SERVICE_SEARCHING;
EXPECT_CALL(bleMock, ConvertBtMacToBinary).WillRepeatedly(Return(SOFTBUS_INVALID_PARAM));
SoftBusMutexInit(&connection.lock, nullptr);
ret = ConnGattClientUpdatePriority(&connection, priority);
ret = ConnGattClientUpdatePriority(connection, priority);
EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
connection.state = BLE_CONNECTION_STATE_CONNECTED;
connection->state = BLE_CONNECTION_STATE_CONNECTED;
EXPECT_CALL(bleMock, ConvertBtMacToBinary).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(bleMock, BleGattcSetPriority).WillRepeatedly(Return(SOFTBUS_OK));
for (int32_t i = 0; i <= 3; i++) {
ret = ConnGattClientUpdatePriority(&connection, (ConnectBlePriority)i);
ret = ConnGattClientUpdatePriority(connection, (ConnectBlePriority)i);
if (i == 3) {
EXPECT_EQ(SOFTBUS_CONN_BLE_INTERNAL_ERR, ret);
break;
}
EXPECT_EQ(SOFTBUS_OK, ret);
}
}
@ -497,4 +504,26 @@ HWTEST_F(ServiceConnectionTest, ServiceDeleteCallback, TestSize.Level1)
g_callback->mtuChangeCallback(bleConnection->underlayerHandle, 5);
SoftBusSleepMs(500);
}
/*
* @tc.name: ServiceStopCallback 001
* @tc.desc: Test ServiceStopCallback.
* @tc.in: Test module, Test number, Test Levels.
* @tc.out: Zero
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ServiceConnectionTest, ServiceAttrHandleCallback, TestSize.Level1)
{
int32_t effectHandle = -1;
int32_t invalidAttrHandle = 11;
int32_t invalidSrvcHandle = 10;
bool ret = g_callback->isConcernedAttrHandle(invalidSrvcHandle, invalidAttrHandle);
EXPECT_EQ(false, ret);
ret = g_callback->isConcernedAttrHandle(effectHandle, invalidAttrHandle);
EXPECT_EQ(false, ret);
ret = g_callback->isConcernedAttrHandle(effectHandle, effectHandle);
EXPECT_EQ(true, ret);
SoftBusSleepMs(500);
}
}

View File

@ -361,27 +361,5 @@ HWTEST_F(ConnectionBleTransTest, QueueBlock, TestSize.Level1)
ret = ConnBleDequeueBlock(&msg);
EXPECT_EQ(SOFTBUS_OK, ret);
ConnBleDeinitSendQueue();
NiceMock<ConnectionBleTransInterfaceMock> bleMock;
EXPECT_CALL(bleMock, WaitQueueLength).WillRepeatedly(Return(!SOFTBUS_OK));
ret = ConnBleEnqueueNonBlock(&queueNode);
EXPECT_NE(SOFTBUS_OK, ret);
{
InSequence seq;
EXPECT_CALL(bleMock, GetMsg).Times(1).WillOnce(Return(!SOFTBUS_OK));
EXPECT_CALL(bleMock, GetMsg).Times(1).WillOnce(Return(SOFTBUS_OK));
ret = ConnBleDequeueBlock(&msg);
EXPECT_NE(SOFTBUS_OK, ret);
EXPECT_CALL(bleMock, GetMsg).Times(1).WillOnce(Return(!SOFTBUS_OK));
EXPECT_CALL(bleMock, GetMsg).Times(1).WillOnce(Return(!SOFTBUS_OK));
EXPECT_CALL(bleMock, GetMsg).Times(1).WillOnce(Return(SOFTBUS_OK));
ret = ConnBleDequeueBlock(&msg);
EXPECT_NE(SOFTBUS_OK, ret);
EXPECT_CALL(bleMock, GetMsg).Times(1).WillOnce(Return(!SOFTBUS_OK));
EXPECT_CALL(bleMock, GetMsg).Times(1).WillOnce(Return(!SOFTBUS_OK));
EXPECT_CALL(bleMock, GetMsg).Times(1).WillOnce(Return(!SOFTBUS_OK));
ret = ConnBleDequeueBlock(&msg);
EXPECT_NE(SOFTBUS_OK, ret);
}
}
}

View File

@ -95,5 +95,10 @@ int BleGattcUnRegister(int clientId)
{
return GetConnectionBleInterface()->BleGattcUnRegister(clientId);
}
int BleGattcSetPriority(int clientId, const BdAddr *bdAddr, BtGattPriority priority)
{
return GetConnectionBleInterface()->BleGattcSetPriority(clientId, bdAddr, priority);
}
}
}

View File

@ -28,6 +28,7 @@
#include "softbus_config_type.h"
#include "softbus_conn_ble_connection.h"
#include "ohos_bt_def.h"
#include "ohos_bt_gatt_client.h"
namespace OHOS {
@ -48,6 +49,7 @@ public:
virtual bool GetJsonObjectSignedNumberItem(const cJSON *json, const char * const string, int *target) = 0;
virtual int BleGattsAddService(int serverId, BtUuid srvcUuid, bool isPrimary, int number) = 0;
virtual int BleGattcUnRegister(int clientId) = 0;
virtual int BleGattcSetPriority(int clientId, const BdAddr *bdAddr, BtGattPriority priority) = 0;
};
class ConnectionBleInterfaceMock : public ConnectionBleInterface {
@ -66,6 +68,7 @@ public:
MOCK_METHOD3(GetJsonObjectSignedNumberItem, bool (const cJSON *, const char * const, int *));
MOCK_METHOD(int, BleGattsAddService, (int, BtUuid, bool, int), (override));
MOCK_METHOD(int, BleGattcUnRegister, (int), (override));
MOCK_METHOD(int, BleGattcSetPriority, (int, const BdAddr *, BtGattPriority), (override));
};
} // namespace OHOS
#endif // CONNECTION_BLE_MOCK_H

View File

@ -66,21 +66,5 @@ char *cJSON_PrintUnformatted(const cJSON *json)
{
return GetConnectionBleTransInterface()->cJSON_PrintUnformatted(json);
}
int32_t ConnStartActionAsync(void *arg, void *(*runnable)(void *), const char *taskName)
{
return GetConnectionBleTransInterface()->ConnStartActionAsync(arg, runnable, taskName);
}
int32_t GetMsg(ConnectionQueue *queue, void **msg, bool *isFull, QueuePriority leastPriority)
{
return GetConnectionBleTransInterface()->GetMsg(queue, msg, isFull, leastPriority);
}
int32_t WaitQueueLength(const LockFreeQueue *lockFreeQueue, uint32_t maxLen, uint32_t diffLen, SoftBusCond *cond,
SoftBusMutex *mutex)
{
return GetConnectionBleTransInterface()->WaitQueueLength(lockFreeQueue, maxLen, diffLen, cond, mutex);
}
}
}

View File

@ -33,10 +33,6 @@ public:
virtual cJSON *cJSON_CreateObject() = 0;
virtual bool AddNumber16ToJsonObject(cJSON *json, const char *const string, uint16_t num) = 0;
virtual char *cJSON_PrintUnformatted(const cJSON *json) = 0;
virtual int32_t ConnStartActionAsync(void *arg, void *(*runnable)(void *), const char *taskName) = 0;
virtual int32_t GetMsg(ConnectionQueue *queue, void **msg, bool *isFull, QueuePriority leastPriority) = 0;
virtual int32_t WaitQueueLength(const LockFreeQueue *lockFreeQueue, uint32_t maxLen, uint32_t diffLen,
SoftBusCond *cond, SoftBusMutex *mutex) = 0;
};
class ConnectionBleTransInterfaceMock : public ConnectionBleTransInterface {
@ -50,10 +46,6 @@ public:
MOCK_METHOD(cJSON *, cJSON_CreateObject, (), (override));
MOCK_METHOD(bool, AddNumber16ToJsonObject, (cJSON *, const char *const, uint16_t), (override));
MOCK_METHOD(char *, cJSON_PrintUnformatted, (const cJSON *), (override));
MOCK_METHOD(int32_t, ConnStartActionAsync, (void *, void *(*)(void *), const char *), (override));
MOCK_METHOD(int32_t, GetMsg, (ConnectionQueue *, void **, bool *, QueuePriority), (override));
MOCK_METHOD(int32_t, WaitQueueLength, (const LockFreeQueue *, uint32_t, uint32_t, SoftBusCond *, SoftBusMutex *),
(override));
};
} // namespace OHOS
#endif // CONNECTION_BLE_TRANS_MOCK_H