WORD32 packetShadowDelete(SDDM_LPP_PACKET_KEY* pPacketKey, SDDM_LPP_PACKET* pPacketValue) { WORD32 dwRet = ROSNG_PARAM_ERROR; WORD32 so_desc = 0; WORD32 tcp_index = 0; if((NULL == pPacketKey) || (NULL == pPacketValue)) { ROSNG_TRACE_WARNING("Invalid para!!!\n"); goto error; } so_desc = pPacketValue->so_desc; tcp_index = pPacketValue->sddm_tcp_packet_cb.index; if((TCP_RECV_QUEUE == pPacketValue->pkt_queue) && (0 != so_desc)) { if(ROSNG_SUCCESS != packetShadowDeletePkt(&gSocketTable.packetRecvAvlTree,pPacketKey,pPacketValue,so_desc)) { ROSNG_TRACE_WARNING("packetShadowDeletePkt fail\n"); goto error; } } else if((TCP_SEND_QUEUE == pPacketValue->pkt_queue) && (0 != tcp_index)) { if(ROSNG_SUCCESS != packetShadowDeletePkt(&tcp_config.packetSendAvlTree,pPacketKey,pPacketValue,tcp_index)) { ROSNG_TRACE_WARNING("packetShadowDeletePkt fail\n"); goto error; } } else { XOS_ASSERT(0); goto error; } dwRet = ROSNG_SUCCESS; error: return dwRet; } 用c语言写一个ft测试用例
时间: 2024-03-12 08:49:40 浏览: 63
以下是一个简单的ft测试用例,测试packetShadowDelete函数是否能够正常处理输入参数并返回正确的结果。
```c
#include <stdio.h>
#include <assert.h>
typedef unsigned int WORD32;
typedef struct {
WORD32 index;
} SDDM_TCP_PACKET_CB;
typedef struct {
WORD32 so_desc;
SDDM_TCP_PACKET_CB sddm_tcp_packet_cb;
WORD32 pkt_queue;
} SDDM_LPP_PACKET;
typedef struct {
// some fields
} SDDM_LPP_PACKET_KEY;
#define TCP_RECV_QUEUE 0
#define TCP_SEND_QUEUE 1
#define ROSNG_SUCCESS 0
#define ROSNG_PARAM_ERROR -1
#define ROSNG_TRACE_WARNING(...) printf(__VA_ARGS__)
#define XOS_ASSERT(...) assert(__VA_ARGS__)
typedef struct {
// some fields
} PacketAvlTree;
PacketAvlTree packetRecvAvlTree;
PacketAvlTree packetSendAvlTree;
WORD32 packetShadowDeletePkt(PacketAvlTree* tree, SDDM_LPP_PACKET_KEY* key, SDDM_LPP_PACKET* value, WORD32 index) {
// some implementation
return ROSNG_SUCCESS;
}
WORD32 packetShadowDelete(SDDM_LPP_PACKET_KEY* pPacketKey, SDDM_LPP_PACKET* pPacketValue) {
WORD32 dwRet = ROSNG_PARAM_ERROR;
WORD32 so_desc = 0;
WORD32 tcp_index = 0;
if((NULL == pPacketKey) || (NULL == pPacketValue))
{
ROSNG_TRACE_WARNING("Invalid para!!!\n");
goto error;
}
so_desc = pPacketValue->so_desc;
tcp_index = pPacketValue->sddm_tcp_packet_cb.index;
if((TCP_RECV_QUEUE == pPacketValue->pkt_queue) && (0 != so_desc))
{
if(ROSNG_SUCCESS != packetShadowDeletePkt(&packetRecvAvlTree,pPacketKey,pPacketValue,so_desc))
{
ROSNG_TRACE_WARNING("packetShadowDeletePkt fail\n");
goto error;
}
}
else if((TCP_SEND_QUEUE == pPacketValue->pkt_queue) && (0 != tcp_index))
{
if(ROSNG_SUCCESS != packetShadowDeletePkt(&packetSendAvlTree,pPacketKey,pPacketValue,tcp_index))
{
ROSNG_TRACE_WARNING("packetShadowDeletePkt fail\n");
goto error;
}
}
else
{
XOS_ASSERT(0);
goto error;
}
dwRet = ROSNG_SUCCESS;
error:
return dwRet;
}
int main() {
SDDM_LPP_PACKET_KEY key;
key.some_field = 123;
SDDM_LPP_PACKET value;
value.so_desc = 456;
value.sddm_tcp_packet_cb.index = 789;
value.pkt_queue = TCP_RECV_QUEUE;
WORD32 ret = packetShadowDelete(&key, &value);
assert(ret == ROSNG_SUCCESS);
return 0;
}
```
阅读全文