Kernel list.c Unit Test (#497)
* Test: List.c Unit Test * Test: test list.h macros * Test: Fix UT bug * Remove unecessary statement from Makefile * Update list_utest.c * Update list_utest.c Co-authored-by: Cobus van Eeden <35851496+cobusve@users.noreply.github.com>pull/501/head^2
parent
c4839ecda3
commit
cd92c42b52
@ -0,0 +1,72 @@
|
|||||||
|
# Change according to what your unit test directory is.
|
||||||
|
# For example if testing queue.c your directory should be called queue
|
||||||
|
# and the project name should be queue
|
||||||
|
# if testing list.c your directory should be called list
|
||||||
|
# and the project name should be list
|
||||||
|
PROJECT := list
|
||||||
|
|
||||||
|
# List the dependency files you wish to mock
|
||||||
|
MOCK_FILES_FP :=
|
||||||
|
|
||||||
|
|
||||||
|
# List the options the compilation would need
|
||||||
|
CPPFLAGS += -DportUSING_MPU_WRAPPERS=0
|
||||||
|
|
||||||
|
# Try not to edit beyond this line
|
||||||
|
MOCK_FILES := $(notdir $(MOCK_FILES_FP))
|
||||||
|
MOCK_OBJ := $(addprefix mock_,$(MOCK_FILES:.h=.o))
|
||||||
|
MOCK_SRC := $(addprefix mock_,$(MOCK_FILES:.h=.c))
|
||||||
|
EXEC := $(PROJECT)_utest
|
||||||
|
PROJECT_DIR := $(abspath .)
|
||||||
|
SCRATCH_DIR := $(GENERATED_DIR)/$(PROJECT)
|
||||||
|
PROJ_LIB_DIR := $(SCRATCH_DIR)/lib
|
||||||
|
MOCK_OBJ_LIST := $(addprefix $(PROJ_LIB_DIR)/,$(MOCK_OBJ))
|
||||||
|
MOCKS_DIR := $(SCRATCH_DIR)/mocks
|
||||||
|
MOCK_SRC_LIST := $(addprefix $(MOCKS_DIR)/,$(MOCK_SRC))
|
||||||
|
CFLAGS += -I$(MOCKS_DIR)
|
||||||
|
COVERAGE_OPTS := -fprofile-arcs -ftest-coverage -fprofile-generate
|
||||||
|
|
||||||
|
ifeq ($(MOCK_FILES_FP),)
|
||||||
|
$(shell mkdir -p $(MOCKS_DIR))
|
||||||
|
$(shell touch -a $(MOCKS_DIR)/mock_dummy.c)
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(MOCKS_DIR)/mock_%.c : Makefile $(PROJECT_DIR)/$(PROJECT).yml | directories
|
||||||
|
cd $(SCRATCH_DIR) && \
|
||||||
|
ruby $(CMOCK_EXEC_DIR)/cmock.rb -o$(PROJECT_DIR)/$(PROJECT).yml \
|
||||||
|
$(MOCK_FILES_FP)
|
||||||
|
|
||||||
|
$(PROJ_LIB_DIR)/mock_%.o : $(MOCKS_DIR)/mock_%.c
|
||||||
|
$(CC) -c $< -fPIC $(CFLAGS) -o $@
|
||||||
|
|
||||||
|
$(BIN_DIR)/$(EXEC) : $(SCRATCH_DIR)/test_runner.o \
|
||||||
|
$(SCRATCH_DIR)/$(PROJECT).o \
|
||||||
|
$(SCRATCH_DIR)/$(PROJECT)_utest.o \
|
||||||
|
$(MOCK_OBJ_LIST)
|
||||||
|
$(CC) $+ $(LDFLAGS) -o $@
|
||||||
|
|
||||||
|
$(SCRATCH_DIR)/test_runner.o : $(SCRATCH_DIR)/test_runner.c \
|
||||||
|
$(SCRATCH_DIR)/$(PROJECT).o
|
||||||
|
$(CC) -c $< $(CPPFLAGS) $(CFLAGS) -o $@
|
||||||
|
|
||||||
|
$(SCRATCH_DIR)/$(PROJECT)_utest.o : $(PROJECT_DIR)/$(PROJECT)_utest.c \
|
||||||
|
$(MOCKS_DIR)/mock_*.c \
|
||||||
|
| directories
|
||||||
|
$(CC) -c $< $(CPPFLAGS) $(CFLAGS) -o $@
|
||||||
|
|
||||||
|
$(SCRATCH_DIR)/$(PROJECT).o : $(KERNEL_DIR)/$(PROJECT).c
|
||||||
|
$(CC) -c $< $(CPPFLAGS) $(CFLAGS) $(COVERAGE_OPTS) -o $@
|
||||||
|
|
||||||
|
$(SCRATCH_DIR)/test_runner.c : $(SCRATCH_DIR)/$(PROJECT)_utest.o \
|
||||||
|
Makefile | directories
|
||||||
|
ruby $(UNITY_BIN_DIR)/generate_test_runner.rb $(EXEC).c \
|
||||||
|
$(PROJECT_DIR)/$(PROJECT).yml $@
|
||||||
|
|
||||||
|
.PHONY: directories
|
||||||
|
directories :
|
||||||
|
-mkdir $(SCRATCH_DIR)
|
||||||
|
-mkdir $(MOCKS_DIR)
|
||||||
|
-mkdir $(PROJ_LIB_DIR)
|
||||||
|
|
||||||
|
# prevent deletion by chain of implicit rules
|
||||||
|
NO_DELETE: $(MOCK_SRC_LIST)
|
@ -0,0 +1,32 @@
|
|||||||
|
:cmock:
|
||||||
|
:mock_prefix: mock_
|
||||||
|
:when_no_prototypes: :warn
|
||||||
|
:treat_externs: :include
|
||||||
|
:enforce_strict_ordering: TRUE
|
||||||
|
:plugins:
|
||||||
|
- :ignore
|
||||||
|
- :ignore_arg
|
||||||
|
- :expect_any_args
|
||||||
|
- :array
|
||||||
|
- :callback
|
||||||
|
- :return_thru_ptr
|
||||||
|
:callback_include_count: true # include a count arg when calling the callback
|
||||||
|
:callback_after_arg_check: false # check arguments before calling the callback
|
||||||
|
:treat_as:
|
||||||
|
uint8: HEX8
|
||||||
|
uint16: HEX16
|
||||||
|
uint32: UINT32
|
||||||
|
int8: INT8
|
||||||
|
bool: UINT8
|
||||||
|
:includes: # This will add these includes to each mock.
|
||||||
|
- <stdbool.h>
|
||||||
|
- "FreeRTOS.h"
|
||||||
|
:treat_externs: :exclude # Now the extern-ed functions will be mocked.
|
||||||
|
:weak: __attribute__((weak))
|
||||||
|
:verbosity: 3
|
||||||
|
:attributes:
|
||||||
|
- PRIVILEGED_FUNCTION
|
||||||
|
:strippables:
|
||||||
|
- PRIVILEGED_FUNCTION
|
||||||
|
- portDONT_DISCARD
|
||||||
|
:treat_externs: :include
|
@ -0,0 +1,953 @@
|
|||||||
|
/*
|
||||||
|
* FreeRTOS V202012.00
|
||||||
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* https://www.FreeRTOS.org
|
||||||
|
* https://github.com/FreeRTOS
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/*! @file list_utest.c */
|
||||||
|
|
||||||
|
/* C runtime includes. */
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
/* List includes */
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
#include "FreeRTOSConfig.h"
|
||||||
|
#include "list.h"
|
||||||
|
|
||||||
|
/* Test includes. */
|
||||||
|
#include "unity.h"
|
||||||
|
|
||||||
|
/* =========================== DEFINES CONSTANTS ========================== */
|
||||||
|
#define MAX_ITEMS 5000 /*!< number of items for a few testcases*/
|
||||||
|
|
||||||
|
/* =========================== GLOBAL VARIABLES =========================== */
|
||||||
|
|
||||||
|
|
||||||
|
/* ============================ Unity Fixtures ============================ */
|
||||||
|
/*! called before each testcase */
|
||||||
|
void setUp( void )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! called after each testcase */
|
||||||
|
void tearDown( void )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! called at the beginning of the whole suite */
|
||||||
|
void suiteSetUp()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! called at the end of the whole suite */
|
||||||
|
int suiteTearDown( int numFailures )
|
||||||
|
{
|
||||||
|
return numFailures;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================== Static Functions =========================== */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief initilize a preallocated list of ListItems_t
|
||||||
|
* @param listItems list to initilize
|
||||||
|
* @param count the number of listItems in the list
|
||||||
|
*/
|
||||||
|
static void initialise_list_items( ListItem_t * listItems,
|
||||||
|
int count )
|
||||||
|
{
|
||||||
|
for( int i = 0; i < count; i++ )
|
||||||
|
{
|
||||||
|
vListInitialiseItem( &listItems[ i ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief initilize a preallocated list of ListItems_t initializing each ones
|
||||||
|
* value to its position value
|
||||||
|
* @param listItems list to initilize
|
||||||
|
* @param count the number of listItems in the list
|
||||||
|
*/
|
||||||
|
static void initialise_list_items_with_position( ListItem_t * listItems,
|
||||||
|
int count )
|
||||||
|
{
|
||||||
|
for( int i = 0; i < count; i++ )
|
||||||
|
{
|
||||||
|
/*listItems[ i ].xItemValue = i; */
|
||||||
|
listSET_LIST_ITEM_VALUE( &listItems[ i ], i );
|
||||||
|
vListInitialiseItem( &listItems[ i ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief validate a list when it is empty
|
||||||
|
* @param pxList a list object
|
||||||
|
*/
|
||||||
|
static void validate_empty_list( const List_t * const pxList )
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL( 0U, listCURRENT_LIST_LENGTH( pxList ) );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( &pxList->xListEnd, pxList->pxIndex );
|
||||||
|
TEST_ASSERT_EQUAL( portMAX_DELAY, pxList->xListEnd.xItemValue );
|
||||||
|
TEST_ASSERT_EQUAL( &pxList->xListEnd, pxList->xListEnd.pxNext );
|
||||||
|
TEST_ASSERT_EQUAL( &pxList->xListEnd, pxList->xListEnd.pxPrevious );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ============================== Test Cases ============================== */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief validate the initilization function of a list
|
||||||
|
*/
|
||||||
|
void test_vListInitialisee_Success( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
validate_empty_list( &pxList );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief validate the initializatiom function of a list item
|
||||||
|
*/
|
||||||
|
void test_vListInitialiseItem_Sucess( void )
|
||||||
|
{
|
||||||
|
ListItem_t pxItem;
|
||||||
|
|
||||||
|
vListInitialiseItem( &pxItem );
|
||||||
|
TEST_ASSERT_EQUAL( NULL, pxItem.pxContainer );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test vListIntertEnd successful case with only 1 item
|
||||||
|
* @details This test ensures the list is sane when 1 item is inserted
|
||||||
|
*/
|
||||||
|
void test_vListInsertEnd_Success_1_item( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem;
|
||||||
|
MiniListItem_t * miniListEnd;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
vListInitialiseItem( &pxNewListItem );
|
||||||
|
miniListEnd = ( MiniListItem_t * ) pxList.pxIndex;
|
||||||
|
|
||||||
|
vListInsertEnd( &pxList, &pxNewListItem );
|
||||||
|
/* List contains 1 item */
|
||||||
|
TEST_ASSERT_EQUAL( 1U, pxList.uxNumberOfItems );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( &pxList.xListEnd, miniListEnd );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem.pxNext, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem.pxPrevious, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem.pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxNext, &pxNewListItem );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxPrevious, &pxNewListItem );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->xItemValue, portMAX_DELAY );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test vListIntertEnd successful case with only 2 items
|
||||||
|
* @details This test ensures the list is sane when 2 items are inserted
|
||||||
|
*/
|
||||||
|
void test_vListInsertEnd_Success_2_items( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 2 ];
|
||||||
|
MiniListItem_t * miniListEnd;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
vListInitialiseItem( &pxNewListItem[ 0 ] );
|
||||||
|
vListInitialiseItem( &pxNewListItem[ 1 ] );
|
||||||
|
miniListEnd = ( MiniListItem_t * ) pxList.pxIndex;
|
||||||
|
|
||||||
|
vListInsertEnd( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsertEnd( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
/* List contains 2 items */
|
||||||
|
TEST_ASSERT_EQUAL( 2U, pxList.uxNumberOfItems );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxNext, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxPrevious, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxNext, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxPrevious, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxNext, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxPrevious, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->xItemValue, portMAX_DELAY );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test vListIntertEnd successful case with only 3 items
|
||||||
|
* @details This test ensures the list is sane when 3 items are inserted
|
||||||
|
*/
|
||||||
|
void test_vListInsertEnd_Success_3_items( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
|
||||||
|
ListItem_t pxNewListItem[ 3 ];
|
||||||
|
MiniListItem_t * miniListEnd;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 3 );
|
||||||
|
|
||||||
|
miniListEnd = ( MiniListItem_t * ) pxList.pxIndex;
|
||||||
|
|
||||||
|
vListInsertEnd( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsertEnd( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
vListInsertEnd( &pxList, &pxNewListItem[ 2 ] );
|
||||||
|
/* List contains 3 items */
|
||||||
|
TEST_ASSERT_EQUAL( 3U, pxList.uxNumberOfItems );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxNext, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxPrevious, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxNext, &pxNewListItem[ 2 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxPrevious, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxNext, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxPrevious, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxNext, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxPrevious, &pxNewListItem[ 2 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->xItemValue, portMAX_DELAY );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test vListIntertEnd successful case with multiple items (5000)
|
||||||
|
* @details This test ensures the list is sane when 5000 items are inserted
|
||||||
|
*/
|
||||||
|
void test_vListInsertEnd_success_multiple_items( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ MAX_ITEMS ];
|
||||||
|
MiniListItem_t * miniListEnd;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, MAX_ITEMS );
|
||||||
|
miniListEnd = ( MiniListItem_t * ) pxList.pxIndex;
|
||||||
|
|
||||||
|
for( int i = 0; i < MAX_ITEMS; i++ )
|
||||||
|
{
|
||||||
|
vListInsertEnd( &pxList, &pxNewListItem[ i ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* List contains 5000 items */
|
||||||
|
TEST_ASSERT_EQUAL( MAX_ITEMS, pxList.uxNumberOfItems );
|
||||||
|
|
||||||
|
/* Validate all elements except first and last */
|
||||||
|
for( int i = 1; i < MAX_ITEMS - 1; i++ )
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ i ].pxNext, &pxNewListItem[ i + 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ i ].pxPrevious, &pxNewListItem[ i - 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ i ].pxContainer, &pxList );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Validate first element */
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxNext, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxPrevious, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
/* Validate last element */
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ MAX_ITEMS - 1 ].pxNext, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ MAX_ITEMS - 1 ].pxPrevious, &pxNewListItem[ MAX_ITEMS - 2 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ MAX_ITEMS - 1 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
/* Validate end marker */
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxNext, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxPrevious, &pxNewListItem[ MAX_ITEMS - 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->xItemValue, portMAX_DELAY );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test vListIntert successful case with 1 item
|
||||||
|
* @details This test ensures the list is sane when 1 item is inserted
|
||||||
|
*/
|
||||||
|
void test_vListInsert_sucess_1_item( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem;
|
||||||
|
MiniListItem_t * miniListEnd;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
vListInitialiseItem( &pxNewListItem );
|
||||||
|
miniListEnd = ( MiniListItem_t * ) pxList.pxIndex;
|
||||||
|
vListInsert( &pxList, &pxNewListItem );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL( 1U, pxList.uxNumberOfItems );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( &pxList.xListEnd, miniListEnd );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem.pxNext, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem.pxPrevious, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem.pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxNext, &pxNewListItem );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxPrevious, &pxNewListItem );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->xItemValue, portMAX_DELAY );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test vListIntert successful case with 2 items
|
||||||
|
* @details This test ensures the list is sane when 2 items are inserted
|
||||||
|
*/
|
||||||
|
void test_vListInsert_sucess_2_items( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 2 ];
|
||||||
|
MiniListItem_t * miniListEnd;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 2 );
|
||||||
|
miniListEnd = ( MiniListItem_t * ) pxList.pxIndex;
|
||||||
|
|
||||||
|
pxNewListItem[ 0 ].xItemValue = 0;
|
||||||
|
pxNewListItem[ 1 ].xItemValue = 1;
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL( 2U, pxList.uxNumberOfItems );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( &pxList.xListEnd, miniListEnd );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxNext, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxPrevious, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxNext, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxPrevious, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxNext, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxPrevious, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->xItemValue, portMAX_DELAY );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test vListIntert successful case with 3 items
|
||||||
|
* @details This test ensures the list is sane when 3 items are inserted
|
||||||
|
*/
|
||||||
|
void test_vListInsert_sucess_3_items( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 3 ];
|
||||||
|
MiniListItem_t * miniListEnd;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 2 );
|
||||||
|
miniListEnd = ( MiniListItem_t * ) pxList.pxIndex;
|
||||||
|
|
||||||
|
pxNewListItem[ 0 ].xItemValue = 0;
|
||||||
|
pxNewListItem[ 1 ].xItemValue = 1;
|
||||||
|
pxNewListItem[ 2 ].xItemValue = 2;
|
||||||
|
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 2 ] );
|
||||||
|
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxNext, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxPrevious, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxNext, &pxNewListItem[ 2 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxPrevious, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxNext, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxPrevious, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxNext, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxPrevious, &pxNewListItem[ 2 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->xItemValue, portMAX_DELAY );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test vListIntert successful case with multiple items (5000)
|
||||||
|
* @details This test ensures the list is sane when multiple items are inserted
|
||||||
|
*/
|
||||||
|
void test_vListInsert_success_multiple_items( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ MAX_ITEMS ];
|
||||||
|
MiniListItem_t * miniListEnd;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items_with_position( pxNewListItem, MAX_ITEMS );
|
||||||
|
miniListEnd = ( MiniListItem_t * ) pxList.pxIndex;
|
||||||
|
|
||||||
|
for( int i = 0; i < MAX_ITEMS; i++ )
|
||||||
|
{
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ i ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* List contains 5000 items */
|
||||||
|
TEST_ASSERT_EQUAL( MAX_ITEMS, pxList.uxNumberOfItems );
|
||||||
|
|
||||||
|
/* Validate all elements except first and last */
|
||||||
|
for( int i = 1; i < MAX_ITEMS - 1; i++ )
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ i ].pxNext, &pxNewListItem[ i + 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ i ].pxPrevious, &pxNewListItem[ i - 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ i ].pxContainer, &pxList );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Validate first element */
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxNext, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxPrevious, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
/* Validate last element */
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ MAX_ITEMS - 1 ].pxNext, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ MAX_ITEMS - 1 ].pxPrevious,
|
||||||
|
&pxNewListItem[ MAX_ITEMS - 2 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ MAX_ITEMS - 1 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
/* Validate end marker */
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxNext, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxPrevious, &pxNewListItem[ MAX_ITEMS - 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->xItemValue, portMAX_DELAY );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test uxListRemove successful case with 1 item
|
||||||
|
* @details This test ensures the list is sane when 1 item is removed
|
||||||
|
*/
|
||||||
|
void test_vListInsert_success_vportMAXDELAY( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 2 ];
|
||||||
|
MiniListItem_t * miniListEnd;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 2 );
|
||||||
|
miniListEnd = ( MiniListItem_t * ) pxList.pxIndex;
|
||||||
|
|
||||||
|
pxNewListItem[ 0 ].xItemValue = 1;
|
||||||
|
pxNewListItem[ 1 ].xItemValue = portMAX_DELAY;
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL( 2U, pxList.uxNumberOfItems );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( &pxList.xListEnd, miniListEnd );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxNext, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxPrevious, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxNext, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxPrevious, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxNext, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxPrevious, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->xItemValue, portMAX_DELAY );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test uxListRemove successful case with 1 item
|
||||||
|
* @details This test ensures the list is sane when 1 item is removed
|
||||||
|
*/
|
||||||
|
void test_uxListRemove_sucesss( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem;
|
||||||
|
MiniListItem_t * miniListEnd;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
vListInitialiseItem( &pxNewListItem );
|
||||||
|
miniListEnd = ( MiniListItem_t * ) pxList.pxIndex;
|
||||||
|
vListInsert( &pxList, &pxNewListItem );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL( 1U, pxList.uxNumberOfItems );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( &pxList.xListEnd, miniListEnd );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem.pxNext, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem.pxPrevious, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem.pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxNext, &pxNewListItem );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxPrevious, &pxNewListItem );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->xItemValue, portMAX_DELAY );
|
||||||
|
|
||||||
|
uxListRemove( &pxNewListItem );
|
||||||
|
|
||||||
|
validate_empty_list( &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL( 0U, pxList.uxNumberOfItems );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( &pxList.xListEnd, pxList.pxIndex );
|
||||||
|
TEST_ASSERT_EQUAL( portMAX_DELAY, pxList.xListEnd.xItemValue );
|
||||||
|
TEST_ASSERT_EQUAL( &pxList.xListEnd, pxList.xListEnd.pxNext );
|
||||||
|
TEST_ASSERT_EQUAL( &pxList.xListEnd, pxList.xListEnd.pxPrevious );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test uxListRemove successful case with 2 items
|
||||||
|
* @details This test ensures the list is sane when 2 items are removed
|
||||||
|
*/
|
||||||
|
void test_uxListRemove_multiple( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 3 ];
|
||||||
|
MiniListItem_t * miniListEnd;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 3 );
|
||||||
|
miniListEnd = ( MiniListItem_t * ) pxList.pxIndex;
|
||||||
|
|
||||||
|
pxNewListItem[ 0 ].xItemValue = 0;
|
||||||
|
pxNewListItem[ 1 ].xItemValue = 1;
|
||||||
|
pxNewListItem[ 2 ].xItemValue = portMAX_DELAY;
|
||||||
|
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 2 ] );
|
||||||
|
|
||||||
|
uxListRemove( &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL( 2U, pxList.uxNumberOfItems );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxNext, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxPrevious, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxNext, &pxNewListItem[ 2 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxPrevious, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxNext, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxPrevious, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxNext, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxPrevious, &pxNewListItem[ 2 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->xItemValue, portMAX_DELAY );
|
||||||
|
|
||||||
|
uxListRemove( &pxNewListItem[ 2 ] );
|
||||||
|
TEST_ASSERT_EQUAL( 2U, pxList.uxNumberOfItems );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 2 ] );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxNext, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxPrevious, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxNext, &pxNewListItem[ 2 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxPrevious, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxNext, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxPrevious, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxNext, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxPrevious, &pxNewListItem[ 2 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->xItemValue, portMAX_DELAY );
|
||||||
|
|
||||||
|
uxListRemove( &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL( 2U, listCURRENT_LIST_LENGTH( &pxList ) );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxNext, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxPrevious, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 0 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxNext, &pxNewListItem[ 2 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxPrevious, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 1 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxNext, miniListEnd );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxPrevious, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxNewListItem[ 2 ].pxContainer, &pxList );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxNext, &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->pxPrevious, &pxNewListItem[ 2 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( miniListEnd->xItemValue, portMAX_DELAY );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test uxListRemove when the index pointed to by pxList->pxIndex is
|
||||||
|
* being removed
|
||||||
|
* @details This test ensures that the function uxListRemove reassigns the
|
||||||
|
* index to the previous element of the one being removed
|
||||||
|
*/
|
||||||
|
void test_uxListRemove_index_item( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 2 ];
|
||||||
|
void * owner1 = ( void * ) 0;
|
||||||
|
void * owner2 = ( void * ) 8;
|
||||||
|
void * nextOwner;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items_with_position( pxNewListItem, 2 );
|
||||||
|
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
listSET_LIST_ITEM_OWNER( &pxNewListItem[ 0 ], owner1 );
|
||||||
|
listSET_LIST_ITEM_OWNER( &pxNewListItem[ 1 ], owner2 );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( &pxList.xListEnd, pxList.pxIndex );
|
||||||
|
|
||||||
|
listGET_OWNER_OF_NEXT_ENTRY( nextOwner, ( List_t * const ) &pxList );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( nextOwner, owner1 );
|
||||||
|
listGET_OWNER_OF_NEXT_ENTRY( nextOwner, ( List_t * const ) &pxList );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( nextOwner, owner2 );
|
||||||
|
|
||||||
|
uxListRemove( &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_EQUAL( &pxNewListItem[ 0 ], pxList.pxIndex );
|
||||||
|
uxListRemove( &pxNewListItem[ 0 ] );
|
||||||
|
validate_empty_list( &pxList );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macros listSET_LIST_ITEM_VALUE and listGET_LIST_ITEM_VALUE
|
||||||
|
* @details This test ensures that the macros are setting and getting the exact
|
||||||
|
* values stored in the list items
|
||||||
|
*/
|
||||||
|
void test_macro_listSET_GET_LIST_ITEM_VALUE( void )
|
||||||
|
{
|
||||||
|
ListItem_t pxNewListItem;
|
||||||
|
int initial_value = 10;
|
||||||
|
int get_value;
|
||||||
|
|
||||||
|
listSET_LIST_ITEM_VALUE( &pxNewListItem, initial_value );
|
||||||
|
get_value = listGET_LIST_ITEM_VALUE( &pxNewListItem );
|
||||||
|
TEST_ASSERT_EQUAL( get_value, initial_value );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macro listCURRENT_LIST_LENGTH
|
||||||
|
* @details This test ensures that the macro is returning the actual number
|
||||||
|
* of items in the list
|
||||||
|
*/
|
||||||
|
void test_macro_listCURRENT_LIST_LENGTH( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 3 ];
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 3 );
|
||||||
|
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 2 ] );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL( 3U, pxList.uxNumberOfItems );
|
||||||
|
TEST_ASSERT_EQUAL( 3U, listCURRENT_LIST_LENGTH( &pxList ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macro listGET_LIST_ITEM_OWNER and listSET_LIST_ITEM_OWNER
|
||||||
|
* @details This test ensures that the macros set and get the same owner from
|
||||||
|
* the ListItem_t
|
||||||
|
*/
|
||||||
|
void test_macros_list_SET_GET_LIST_ITEM_OWNER( void )
|
||||||
|
{
|
||||||
|
ListItem_t pxNewListItem;
|
||||||
|
void * owner = ( void * ) 0;
|
||||||
|
void * saved_owner;
|
||||||
|
|
||||||
|
listSET_LIST_ITEM_OWNER( &pxNewListItem, owner );
|
||||||
|
saved_owner = listGET_LIST_ITEM_OWNER( &pxNewListItem );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( saved_owner, owner );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macro listGET_OWNER_OF_NEXT_ENTRY
|
||||||
|
* @details This test ensures that the macro is circling correctly through the list
|
||||||
|
*/
|
||||||
|
void test_macro_listGET_OWNER_OF_NEXT_ENTRY( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 3 ];
|
||||||
|
void * owner1 = ( void * ) 0;
|
||||||
|
void * owner2 = ( void * ) 8;
|
||||||
|
void * owner3 = ( void * ) 16;
|
||||||
|
void * nextOwner;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 3 );
|
||||||
|
|
||||||
|
pxNewListItem[ 0 ].xItemValue = 0;
|
||||||
|
pxNewListItem[ 1 ].xItemValue = 1;
|
||||||
|
pxNewListItem[ 2 ].xItemValue = portMAX_DELAY;
|
||||||
|
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 2 ] );
|
||||||
|
|
||||||
|
listSET_LIST_ITEM_OWNER( &pxNewListItem[ 0 ], owner1 );
|
||||||
|
listSET_LIST_ITEM_OWNER( &pxNewListItem[ 1 ], owner2 );
|
||||||
|
listSET_LIST_ITEM_OWNER( &pxNewListItem[ 2 ], owner3 );
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_PTR( &pxList.xListEnd, pxList.pxIndex );
|
||||||
|
|
||||||
|
listGET_OWNER_OF_NEXT_ENTRY( nextOwner, ( List_t * const ) &pxList );
|
||||||
|
TEST_ASSERT_NOT_EQUAL_UINT64( &pxList.xListEnd, pxList.pxIndex );
|
||||||
|
TEST_ASSERT_EQUAL( pxList.pxIndex->pvOwner, owner1 );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( nextOwner, owner1 );
|
||||||
|
|
||||||
|
listGET_OWNER_OF_NEXT_ENTRY( nextOwner, ( List_t * const ) &pxList );
|
||||||
|
TEST_ASSERT_NOT_EQUAL_UINT64( &pxList.xListEnd, pxList.pxIndex );
|
||||||
|
TEST_ASSERT_EQUAL( pxList.pxIndex->pvOwner, owner2 );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( nextOwner, owner2 );
|
||||||
|
|
||||||
|
listGET_OWNER_OF_NEXT_ENTRY( nextOwner, ( List_t * const ) &pxList );
|
||||||
|
TEST_ASSERT_NOT_EQUAL_UINT64( &pxList.xListEnd, pxList.pxIndex );
|
||||||
|
TEST_ASSERT_EQUAL( pxList.pxIndex->pvOwner, owner3 );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( nextOwner, owner3 );
|
||||||
|
|
||||||
|
/* back to the first owner */
|
||||||
|
listGET_OWNER_OF_NEXT_ENTRY( nextOwner, ( List_t * const ) &pxList );
|
||||||
|
TEST_ASSERT_NOT_EQUAL_UINT64( &pxList.xListEnd, pxList.pxIndex );
|
||||||
|
TEST_ASSERT_EQUAL( pxList.pxIndex->pvOwner, owner1 );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( nextOwner, owner1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macro listGET_ITEM_VALUE_OF_HEAD_ENTRY normal case
|
||||||
|
* @details This test ensures that the macro is returning the correct value of
|
||||||
|
* the head entry from pxList
|
||||||
|
*/
|
||||||
|
void test_macro_listGET_ITEM_VALUE_OF_HEAD_ENTRY( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 2 ];
|
||||||
|
TickType_t saved_item_value;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 2 );
|
||||||
|
|
||||||
|
pxNewListItem[ 0 ].xItemValue = 0;
|
||||||
|
pxNewListItem[ 2 ].xItemValue = 2;
|
||||||
|
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
saved_item_value = listGET_ITEM_VALUE_OF_HEAD_ENTRY( &pxList );
|
||||||
|
TEST_ASSERT_EQUAL( saved_item_value, pxNewListItem[ 0 ].xItemValue );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macro listGET_HEAD_ENTRY normal case
|
||||||
|
* @details This test ensures that the macro is returning the head entry
|
||||||
|
*/
|
||||||
|
void test_macro_listGET_HEAD_ENTRY( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 2 ];
|
||||||
|
ListItem_t * saved_head_entry;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 2 );
|
||||||
|
|
||||||
|
pxNewListItem[ 0 ].xItemValue = 0;
|
||||||
|
pxNewListItem[ 2 ].xItemValue = 2;
|
||||||
|
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
saved_head_entry = listGET_HEAD_ENTRY( &pxList );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( saved_head_entry, &pxNewListItem[ 0 ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macro listGET_NEXT normal case
|
||||||
|
* @details This test ensures that the macro is returning the next list item
|
||||||
|
*/
|
||||||
|
void test_macro_listGET_NEXT( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 2 ];
|
||||||
|
ListItem_t * pxNextListItem;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 2 );
|
||||||
|
|
||||||
|
pxNewListItem[ 0 ].xItemValue = 0;
|
||||||
|
pxNewListItem[ 2 ].xItemValue = 2;
|
||||||
|
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
|
||||||
|
pxNextListItem = listGET_NEXT( &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( &pxNewListItem[ 1 ], pxNextListItem );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macro listGET_END_MARKER normal case
|
||||||
|
* @details This test ensures that the macro is returning the last item
|
||||||
|
* (MiniListItem_t)
|
||||||
|
*/
|
||||||
|
void test_macro_listGET_END_MARKER( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 2 ];
|
||||||
|
MiniListItem_t * endList;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 2 );
|
||||||
|
|
||||||
|
pxNewListItem[ 0 ].xItemValue = 0;
|
||||||
|
pxNewListItem[ 2 ].xItemValue = 2;
|
||||||
|
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
|
||||||
|
endList = ( MiniListItem_t * ) listGET_END_MARKER( &pxList );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( &pxList.xListEnd, endList );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macro listLIST_IS_EMPTY normal case
|
||||||
|
* @details This test ensures that the macro is returning if the list is empty
|
||||||
|
* or not
|
||||||
|
*/
|
||||||
|
void test_macro_listLIST_IS_EMPTY( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 2 ];
|
||||||
|
bool is_list_empty;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 2 );
|
||||||
|
is_list_empty = listLIST_IS_EMPTY( &pxList );
|
||||||
|
TEST_ASSERT_TRUE( is_list_empty );
|
||||||
|
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
is_list_empty = listLIST_IS_EMPTY( &pxList );
|
||||||
|
TEST_ASSERT_FALSE( is_list_empty );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
is_list_empty = listLIST_IS_EMPTY( &pxList );
|
||||||
|
TEST_ASSERT_FALSE( is_list_empty );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macro listGET_OWNER_OF_HEAD_ENTRY normal case
|
||||||
|
* @details This test ensures that the macro is returning the owner of he head
|
||||||
|
* entry
|
||||||
|
*/
|
||||||
|
void test_macro_listGET_OWNER_OF_HEAD_ENTRY( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 2 ];
|
||||||
|
void * owner1 = ( void * ) 0;
|
||||||
|
void * owner2 = ( void * ) 8;
|
||||||
|
void * saved_owner;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 2 );
|
||||||
|
|
||||||
|
pxNewListItem[ 0 ].xItemValue = 0;
|
||||||
|
pxNewListItem[ 2 ].xItemValue = 2;
|
||||||
|
|
||||||
|
listSET_LIST_ITEM_OWNER( &pxNewListItem[ 0 ], owner1 );
|
||||||
|
listSET_LIST_ITEM_OWNER( &pxNewListItem[ 1 ], owner2 );
|
||||||
|
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsert( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
|
||||||
|
saved_owner = listGET_OWNER_OF_HEAD_ENTRY( &pxList );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( saved_owner, owner1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macro listIS_CONTAINED_WITHIN normal case
|
||||||
|
* @details This test ensures that the macro is returning whether the list item
|
||||||
|
* is contained witin the list
|
||||||
|
*/
|
||||||
|
void test_macro_listIS_CONTAINED_WITHIN( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 2 ];
|
||||||
|
bool is_contained;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 2 );
|
||||||
|
|
||||||
|
|
||||||
|
vListInsertEnd( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
is_contained = listIS_CONTAINED_WITHIN( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_FALSE( is_contained );
|
||||||
|
|
||||||
|
vListInsertEnd( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
/* List contains 2 items */
|
||||||
|
TEST_ASSERT_EQUAL( 2U, pxList.uxNumberOfItems );
|
||||||
|
is_contained = listIS_CONTAINED_WITHIN( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_TRUE( is_contained );
|
||||||
|
uxListRemove( &pxNewListItem[ 1 ] );
|
||||||
|
is_contained = listIS_CONTAINED_WITHIN( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
TEST_ASSERT_FALSE( is_contained );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macro listLIST_ITEM_CONTAINER normal case
|
||||||
|
* @details This test ensures that the macro is returning the item container
|
||||||
|
* list
|
||||||
|
*/
|
||||||
|
void test_macro_listLIST_ITEM_CONTAINER( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
ListItem_t pxNewListItem[ 2 ];
|
||||||
|
List_t * pxListContainer;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
initialise_list_items( pxNewListItem, 2 );
|
||||||
|
|
||||||
|
|
||||||
|
vListInsertEnd( &pxList, &pxNewListItem[ 0 ] );
|
||||||
|
vListInsertEnd( &pxList, &pxNewListItem[ 1 ] );
|
||||||
|
/* List contains 2 items */
|
||||||
|
TEST_ASSERT_EQUAL( 2U, pxList.uxNumberOfItems );
|
||||||
|
pxListContainer = listLIST_ITEM_CONTAINER( &pxNewListItem[ 0 ] );
|
||||||
|
TEST_ASSERT_EQUAL_PTR( pxListContainer, &pxList );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macro listLIST_IS_INITIALISED normal case
|
||||||
|
* @details This test ensures that the macro is returning true when the list is
|
||||||
|
* initialised
|
||||||
|
*/
|
||||||
|
void test_macro_listLIST_IS_INITIALISED_success( void )
|
||||||
|
{
|
||||||
|
List_t pxList;
|
||||||
|
bool is_initialised;
|
||||||
|
|
||||||
|
vListInitialise( &pxList );
|
||||||
|
|
||||||
|
is_initialised = listLIST_IS_INITIALISED( &pxList );
|
||||||
|
TEST_ASSERT_TRUE( is_initialised );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief test macro listLIST_ITEM_CONTAINER normal case
|
||||||
|
* @details This test ensures that the macro is returning false when the list is
|
||||||
|
* not initialised
|
||||||
|
*/
|
||||||
|
void test_macro_listLIST_IS_INITIALISED_fail( void )
|
||||||
|
{
|
||||||
|
List_t pxList = { 0 };
|
||||||
|
bool is_initialised;
|
||||||
|
|
||||||
|
is_initialised = listLIST_IS_INITIALISED( &pxList );
|
||||||
|
TEST_ASSERT_FALSE( is_initialised );
|
||||||
|
}
|
Loading…
Reference in New Issue