diff --git a/src/BRSRC13/CORE/FW/brlists.c b/src/BRSRC13/CORE/FW/brlists.c index d2f4ae5a..19cca364 100644 --- a/src/BRSRC13/CORE/FW/brlists.c +++ b/src/BRSRC13/CORE/FW/brlists.c @@ -1,5 +1,6 @@ #include "brlists.h" +#include #include char rscid[49]; @@ -53,10 +54,13 @@ void BrSimpleNewList(br_simple_list* list) { // Offset: 628 // Size: 76 void BrSimpleAddHead(br_simple_list* list, br_simple_node* node) { + printf("BrSimpleAddHead %p\n", &node); node->next = list->head; - node->prev = &list->head; + printf("setting me %p ->prev = %p\n", node, &list->head); + node->prev = list; if (node->next) { - node->next->prev = &node; + printf("setting %p ->prev = %p\n", node->next, node); + node->next->prev = node; } list->head = node; } diff --git a/src/BRSRC13/br_types.h b/src/BRSRC13/br_types.h index 3427cbd3..a63a78d0 100644 --- a/src/BRSRC13/br_types.h +++ b/src/BRSRC13/br_types.h @@ -1456,7 +1456,7 @@ typedef struct br_list { typedef struct br_simple_node br_simple_node; typedef struct br_simple_node { br_simple_node* next; - br_simple_node** prev; + br_simple_node* prev; } br_simple_node; typedef struct br_simple_list { diff --git a/test/BRSRC13/test_brlists.c b/test/BRSRC13/test_brlists.c index ad6c57f6..ac5e7bfa 100644 --- a/test/BRSRC13/test_brlists.c +++ b/test/BRSRC13/test_brlists.c @@ -1,40 +1,48 @@ #include "framework/unity.h" #include "CORE/FW/brlists.h" +#include #include void test_brlists_BrSimpleList() { - br_simple_list list; - br_simple_node one; - br_simple_node two; - br_simple_node three; + br_simple_list* list = calloc(1, sizeof(br_simple_list)); + br_simple_node* one = calloc(1, sizeof(br_simple_node)); + br_simple_node* two = calloc(1, sizeof(br_simple_node)); + br_simple_node* three = calloc(1, sizeof(br_simple_node)); - BrSimpleNewList(&list); - TEST_ASSERT_NULL(list.head); + printf("lisr %p, 1 %p, 2 %p, 3 %p\n", list, one, two, three); - BrSimpleAddHead(&list, &one); - TEST_ASSERT_EQUAL_PTR(&one, list.head); - TEST_ASSERT_NULL(list.head->next); + BrSimpleNewList(list); + TEST_ASSERT_NULL(list->head); - //TODO: should be null? - TEST_ASSERT_EQUAL_PTR(&one, *list.head->prev); + BrSimpleAddHead(list, one); + TEST_ASSERT_EQUAL_PTR(one, list->head); + TEST_ASSERT_NULL(one->next); + TEST_ASSERT_EQUAL_PTR(list, one->prev); - BrSimpleAddHead(&list, &two); - TEST_ASSERT_EQUAL_PTR(&two, list.head); - TEST_ASSERT_EQUAL_PTR(&one, list.head->next); + BrSimpleAddHead(list, two); + // expected 2->1 + TEST_ASSERT_EQUAL_PTR(two, list->head); + TEST_ASSERT_EQUAL_PTR(one, two->next); + TEST_ASSERT_EQUAL_PTR(list, two->prev); - //TODO: this should be "2" IMO - TEST_ASSERT_EQUAL_PTR(&one, *list.head->next->prev); + TEST_ASSERT_EQUAL_PTR(two, one->prev); + TEST_ASSERT_NULL(one->next); - BrSimpleAddHead(&list, &three); - TEST_ASSERT_EQUAL_PTR(&three, list.head); - TEST_ASSERT_EQUAL_PTR(&two, list.head->next); - TEST_ASSERT_EQUAL_PTR(&one, list.head->next->next); + BrSimpleAddHead(list, three); + // expected 3->2->1 + //printf("prevs: %p, %p, %p\n", one.prev, two.prev, three.prev); + TEST_ASSERT_EQUAL_PTR(two, one->prev); - //TODO: this doesnt look right - //TEST_ASSERT_EQUAL_PTR(&three, *list.head->prev); - TEST_ASSERT_EQUAL_PTR(&one, *list.head->next->prev); - TEST_ASSERT_EQUAL_PTR(&one, *list.head->next->next->prev); + TEST_ASSERT_EQUAL_PTR(three, list->head); + TEST_ASSERT_EQUAL_PTR(two, three->next); + TEST_ASSERT_EQUAL_PTR(list, three->prev); + + TEST_ASSERT_EQUAL_PTR(three, two->prev); + TEST_ASSERT_EQUAL_PTR(one, two->next); + + TEST_ASSERT_EQUAL_PTR(two, one->prev); + TEST_ASSERT_NULL(one->next); } void test_brlists_suite() {