mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-01 00:28:18 +00:00
linked_list: add tests for linked_list_count and fix off-by one
This commit is contained in:
parent
9620f7c419
commit
a2908aa0e7
@ -118,7 +118,7 @@ int btstack_linked_list_remove(btstack_linked_list_t * list, btstack_linked_ite
|
||||
int btstack_linked_list_count(btstack_linked_list_t * list){
|
||||
btstack_linked_item_t *it;
|
||||
int counter = 0;
|
||||
for (it = (btstack_linked_item_t *) list; it ; it = it->next) {
|
||||
for (it = (btstack_linked_item_t *) list; it->next ; it = it->next) {
|
||||
counter++;
|
||||
}
|
||||
return counter;
|
||||
|
@ -8,6 +8,16 @@ btstack_linked_item_t itemB;
|
||||
btstack_linked_item_t itemC;
|
||||
btstack_linked_item_t itemD;
|
||||
|
||||
TEST_GROUP(LinkedListEmpty){
|
||||
void setup(void){
|
||||
testList = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
TEST(LinkedListEmpty, CountAll){
|
||||
CHECK_EQUAL(0, btstack_linked_list_count(&testList));
|
||||
}
|
||||
|
||||
TEST_GROUP(LinkedList){
|
||||
void setup(void){
|
||||
testList = NULL;
|
||||
@ -18,6 +28,10 @@ TEST_GROUP(LinkedList){
|
||||
}
|
||||
};
|
||||
|
||||
TEST(LinkedList, CountAll){
|
||||
CHECK_EQUAL(4, btstack_linked_list_count(&testList));
|
||||
}
|
||||
|
||||
TEST(LinkedList, Iterator){
|
||||
btstack_linked_list_iterator_t it;
|
||||
btstack_linked_list_iterator_init(&it, &testList);
|
||||
|
Loading…
Reference in New Issue
Block a user