tests pass with *prev
This commit is contained in:
parent
25eeef2010
commit
53de41f556
|
|
@ -1,5 +1,6 @@
|
|||
#include "brlists.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -1,40 +1,48 @@
|
|||
#include "framework/unity.h"
|
||||
|
||||
#include "CORE/FW/brlists.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
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() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue