summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2007-09-22 12:33:28 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2007-09-22 12:33:28 +0000
commit08e48355841946cf804510a24ea1f8df72e23d2f (patch)
treee9b6f87f33b38bd0b9749667c85a0ba424580215 /test
parent7071feef82182cd1ae386fd01c0c21ce8891c64d (diff)
downloadlibdom-08e48355841946cf804510a24ea1f8df72e23d2f.tar.gz
libdom-08e48355841946cf804510a24ea1f8df72e23d2f.tar.bz2
s/malloc.h/stdlib.h/ (malloc.h is non-standard, though common)
Sprinkle some assertions about so as to catch malloc failure at the earliest opportunity. Pedantic line length and brace position changes. svn path=/trunk/dom/; revision=3563
Diffstat (limited to 'test')
-rw-r--r--test/list.c25
-rw-r--r--test/list.h6
2 files changed, 22 insertions, 9 deletions
diff --git a/test/list.c b/test/list.c
index 3204237..f94b408 100644
--- a/test/list.c
+++ b/test/list.c
@@ -5,21 +5,26 @@
* Copyright 2007 James Shaw <jshaw@netsurf-browser.org>
*/
-#include <malloc.h>
-#include <stdio.h>
+#include <assert.h>
+
#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
#include "list.h"
-struct list* list_new(void) {
+struct list* list_new(void)
+{
struct list* list = malloc(sizeof(struct list));
+ assert(list != NULL);
list->size = 0;
list->head = NULL;
list->tail = NULL;
return list;
}
-void list_destroy(struct list* list) {
+void list_destroy(struct list* list)
+{
struct list_elt* elt = list->head;
while (elt != NULL) {
struct list_elt* nextElt = elt->next;
@@ -29,8 +34,10 @@ void list_destroy(struct list* list) {
free(list);
}
-void list_add(struct list* list, void* data) {
+void list_add(struct list* list, void* data)
+{
struct list_elt* elt = malloc(sizeof(struct list_elt));
+ assert(elt != NULL);
elt->data = data;
elt->next = NULL;
struct list_elt* tail = list->tail;
@@ -51,7 +58,9 @@ void list_add(struct list* list, void* data) {
list->size++;
}
-bool list_contains(struct list* list, void* data, int (*comparator)(const void* a, const void* b)) {
+bool list_contains(struct list* list, void* data,
+ int (*comparator)(const void* a, const void* b))
+{
struct list_elt* elt = list->head;
while (elt != NULL) {
if (comparator(elt->data, data) == 0) {
@@ -62,7 +71,9 @@ bool list_contains(struct list* list, void* data, int (*comparator)(const void*
return false;
}
-bool list_contains_all(struct list* superList, struct list* subList, int (*comparator)(const void* a, const void* b)) {
+bool list_contains_all(struct list* superList, struct list* subList,
+ int (*comparator)(const void* a, const void* b))
+{
struct list_elt* elt = subList->head;
while (elt != NULL) {
if (!list_contains(superList, elt->data, comparator)) {
diff --git a/test/list.h b/test/list.h
index 5732032..7b5bcc0 100644
--- a/test/list.h
+++ b/test/list.h
@@ -30,11 +30,13 @@ void list_add(struct list* list, void* data);
/**
* Tests if data is equal to any element in the list.
*/
-bool list_contains(struct list* list, void* data, int (*comparator)(const void* a, const void* b));
+bool list_contains(struct list* list, void* data,
+ int (*comparator)(const void* a, const void* b));
/**
* Tests if superlist contains all elements in sublist. Order is not important.
*/
-bool list_contains_all(struct list* superList, struct list* subList, int (*comparator)(const void* a, const void* b));
+bool list_contains_all(struct list* superList, struct list* subList,
+ int (*comparator)(const void* a, const void* b));
#endif