1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-09-16 09:06:18 +02:00

Add lstClear() to List object.

This commit is contained in:
David Steele
2019-07-14 15:42:55 -04:00
parent e10577d0b0
commit c836c483dc
3 changed files with 32 additions and 1 deletions

View File

@@ -67,6 +67,33 @@ lstAdd(List *this, const void *item)
FUNCTION_TEST_RETURN(this);
}
/***********************************************************************************************************************************
Clear items from a list
***********************************************************************************************************************************/
List *
lstClear(List *this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(LIST, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
if (this->list != NULL)
{
MEM_CONTEXT_BEGIN(this->memContext)
{
memFree(this->list);
}
MEM_CONTEXT_END();
this->listSize = 0;
this->listSizeMax = 0;
}
FUNCTION_TEST_RETURN(this);
}
/***********************************************************************************************************************************
Get an item from the list
***********************************************************************************************************************************/

View File

@@ -25,6 +25,7 @@ Functions
***********************************************************************************************************************************/
List *lstNew(size_t itemSize);
List *lstAdd(List *this, const void *item);
List *lstClear(List *this);
void *lstGet(const List *this, unsigned int listIdx);
List *lstInsert(List *this, unsigned int listIdx, const void *item);
List *lstRemove(List *this, unsigned int listIdx);

View File

@@ -37,12 +37,15 @@ testRun(void)
TEST_RESULT_INT(list->listSize, 0, "list size");
TEST_RESULT_INT(list->listSizeMax, 0, "list size max");
TEST_RESULT_PTR(lstMemContext(list), list->memContext, "list mem context");
TEST_RESULT_VOID(lstClear(list), "clear list");
void *ptr = NULL;
TEST_RESULT_PTR(lstAdd(list, &ptr), list, "add item");
TEST_RESULT_STR(strPtr(lstToLog(list)), "{size: 1}", "check log");
TEST_RESULT_VOID(lstClear(list), "clear list");
TEST_RESULT_STR(strPtr(lstToLog(list)), "{size: 0}", "check log after clear");
TEST_RESULT_VOID(lstFree(list), "free list");
TEST_RESULT_VOID(lstFree(lstNew(1)), "free empty list");
TEST_RESULT_VOID(lstFree(NULL), "free null list");