Work in progress
This commit is contained in:
@@ -27,21 +27,6 @@
|
||||
#include "list.h"
|
||||
|
||||
|
||||
typedef struct list_node_s {
|
||||
void *data;
|
||||
list_node_t *next;
|
||||
} list_node_t;
|
||||
|
||||
|
||||
typedef struct list_s {
|
||||
int logicalLength;
|
||||
size_t elementSize;
|
||||
list_node_t *head;
|
||||
list_node_t *tail;
|
||||
freeFunction freeFn;
|
||||
} list_t;
|
||||
|
||||
|
||||
list_t *create_list(size_t elementSize, freeFunction freeFn)
|
||||
{
|
||||
list_t *list;
|
||||
|
||||
@@ -25,12 +25,22 @@ extern "C" {
|
||||
|
||||
// a common function used to free malloc'd objects
|
||||
typedef void(*freeFunction)(void *);
|
||||
typedef bool (*listIterator)(void *);
|
||||
typedef bool(*listIterator)(void *);
|
||||
|
||||
|
||||
// forward declarations
|
||||
typedef struct list_node_s list_node_t;
|
||||
typedef struct list_s list_t;
|
||||
typedef struct list_node_s {
|
||||
void *data;
|
||||
struct list_node_s *next;
|
||||
} list_node_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
int logicalLength;
|
||||
size_t elementSize;
|
||||
list_node_t *head;
|
||||
list_node_t *tail;
|
||||
freeFunction freeFn;
|
||||
} list_t;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -164,6 +164,8 @@ bool iterate_test_data(void *data)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_struct_list){
|
||||
|
||||
list_t *list = NULL;
|
||||
@@ -182,10 +184,18 @@ BOOST_AUTO_TEST_CASE(test_struct_list){
|
||||
|
||||
BOOST_CHECK(size_list(list) == 3);
|
||||
|
||||
for_each_list(list, iterate_test_data);
|
||||
//for_each_list(list, iterate_test_data);
|
||||
|
||||
// Expose list abstraction and loop over it
|
||||
list_node_t *lnode;
|
||||
for (lnode = list->head; lnode != NULL; lnode = lnode->next) {
|
||||
test_data_t *test_data = *(test_data_t **)lnode->data;
|
||||
printf("Found number: %i name: %s\n", test_data->num, test_data->name);
|
||||
}
|
||||
|
||||
delete_list(list);
|
||||
}
|
||||
|
||||
// TODO: search for an index and return data
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user