Add unit tests and correct bugs detected by the tests

This commit is contained in:
DanyLE
2023-01-25 17:01:01 +01:00
parent d4bb12c6b5
commit 7711526a7c
29 changed files with 1814 additions and 1024 deletions

View File

@ -14,15 +14,43 @@
#define SLICE "slice"
typedef struct {
size_t magic;
size_t len;
uint8_t* data;
} slice_t;
#ifndef LUA_SLICE_MAGIC
/**
* @brief Send data to the server via fastCGI protocol
* This function is defined by the luad fcgi server
*
* @param fd the socket fd
* @param id the request id
* @param ptr data pointer
* @param size data size
* @return int
*/
int fcgi_send_slice(int fd, uint16_t id, uint8_t* ptr, size_t size);
/**
* @brief Get the magic number of the slice
* This value is defined by the luad fastCGI server
*
* @return size_t
*/
size_t lua_slice_magic();
#else
#define lua_slice_magic() (LUA_SLICE_MAGIC)
#define fcgi_send_slice(fd,id,ptr,size) (-1)
#endif
void lua_new_slice(lua_State*L, int n)
{
size_t nbytes = sizeof(slice_t) + n * 1U;
slice_t *a = (slice_t *)lua_newuserdata(L, nbytes);
a->data = &((char *)a)[sizeof(slice_t)];
a->magic = lua_slice_magic();
luaL_getmetatable(L, SLICE);
lua_setmetatable(L, -2);